diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-05-02 00:48:09 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2018-05-23 21:16:03 +0100 |
commit | 9c3800374b63e578f9ab8bf7aae26ed38d1bb34b (patch) | |
tree | 172a0a6b26e19428b1bdf2d98f662bd4fd6e436c | |
parent | Make testDependAll more generic ready for other things (diff) | |
download | gentoobrowse-api-9c3800374b63e578f9ab8bf7aae26ed38d1bb34b.tar.bz2 gentoobrowse-api-9c3800374b63e578f9ab8bf7aae26ed38d1bb34b.tar.xz gentoobrowse-api-9c3800374b63e578f9ab8bf7aae26ed38d1bb34b.zip |
Add testProcessAll case for processing news
And update news processor with string_view interface.
-rw-r--r-- | gentoobrowse-api/service/maintenance/newsProcessor.cpp | 2 | ||||
-rw-r--r-- | gentoobrowse-api/service/news.cpp | 4 | ||||
-rw-r--r-- | gentoobrowse-api/service/news.h | 6 | ||||
-rw-r--r-- | gentoobrowse-api/unittests/Jamfile.jam | 5 | ||||
-rw-r--r-- | gentoobrowse-api/unittests/testNews.cpp | 4 | ||||
-rw-r--r-- | gentoobrowse-api/unittests/testProcessAll.cpp | 18 |
6 files changed, 30 insertions, 9 deletions
diff --git a/gentoobrowse-api/service/maintenance/newsProcessor.cpp b/gentoobrowse-api/service/maintenance/newsProcessor.cpp index 68e2b57..e416eea 100644 --- a/gentoobrowse-api/service/maintenance/newsProcessor.cpp +++ b/gentoobrowse-api/service/maintenance/newsProcessor.cpp @@ -34,7 +34,7 @@ namespace Gentoo { NewsProcessor::importNews(DB::Connection * dbc, const boost::filesystem::path & path) { AdHoc::FileUtils::MemMap m(path); - auto news = Portage::Utils::News::parse(reinterpret_cast<const gchar *>(m.data), m.getStat().st_size); + auto news = Portage::Utils::News::parse(m.sv<gchar>()); news->newsid = path.parent_path().leaf().string(); Slicer::SerializeAny<Serializer>(news, dbc, "gentoobrowse.news"); } diff --git a/gentoobrowse-api/service/news.cpp b/gentoobrowse-api/service/news.cpp index be4d53e..3bc7aa8 100644 --- a/gentoobrowse-api/service/news.cpp +++ b/gentoobrowse-api/service/news.cpp @@ -81,10 +81,10 @@ namespace Portage { } Gentoo::NewsItemPtr - News::parse(const gchar * str, size_t len) + News::parse(const std::basic_string_view<gchar> & str) { News d; - d.extract(str, len); + d.extract(str.data(), str.length()); d.news->body.erase( std::remove_if(d.news->body.begin(), d.news->body.end(), [](const auto & s) { return s.empty(); }), d.news->body.end()); diff --git a/gentoobrowse-api/service/news.h b/gentoobrowse-api/service/news.h index 7c7b495..0d2e26f 100644 --- a/gentoobrowse-api/service/news.h +++ b/gentoobrowse-api/service/news.h @@ -1,5 +1,5 @@ -#ifndef GENTOOBROWSE_SERVICE_DEPEND_H -#define GENTOOBROWSE_SERVICE_DEPEND_H +#ifndef GENTOOBROWSE_SERVICE_NEWS_H +#define GENTOOBROWSE_SERVICE_NEWS_H #include <istream> #include <vector> @@ -14,7 +14,7 @@ namespace Portage { public: Gentoo::NewsItemPtr news; - static Gentoo::NewsItemPtr parse(const gchar * string, size_t length); + static Gentoo::NewsItemPtr parse(const std::basic_string_view<gchar> &); }; } } diff --git a/gentoobrowse-api/unittests/Jamfile.jam b/gentoobrowse-api/unittests/Jamfile.jam index 94f2b89..2fd9f79 100644 --- a/gentoobrowse-api/unittests/Jamfile.jam +++ b/gentoobrowse-api/unittests/Jamfile.jam @@ -71,7 +71,10 @@ run explicit testProcessAll ; run - testProcessAll.cpp ../service/utils/ebuildCacheParser.cpp ../service/depend.cpp + testProcessAll.cpp + ../service/utils/ebuildCacheParser.cpp + ../service/depend.cpp + ../service/news.cpp : : : <define>BOOST_TEST_DYN_LINK <library>testCommon diff --git a/gentoobrowse-api/unittests/testNews.cpp b/gentoobrowse-api/unittests/testNews.cpp index 291f49c..b2c8a78 100644 --- a/gentoobrowse-api/unittests/testNews.cpp +++ b/gentoobrowse-api/unittests/testNews.cpp @@ -8,7 +8,7 @@ BOOST_AUTO_TEST_CASE( news_2016_04_07_kde_plasma5_stable ) { AdHoc::FileUtils::MemMap m(rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d" / "metadata" / "news" / "2016-04-07-kde-plasma5-stable" / "2016-04-07-kde-plasma5-stable.en.txt"); - auto news = Portage::Utils::News::parse(reinterpret_cast<const gchar *>(m.data), m.getStat().st_size); + auto news = Portage::Utils::News::parse(m.sv()); BOOST_REQUIRE_EQUAL(news->title, "KDE Plasma 5 Upgrade"); BOOST_REQUIRE(news->authorname); BOOST_REQUIRE_EQUAL(*news->authorname, "Michael Palimaka"); @@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE( news_2016_04_07_kde_plasma5_stable ) BOOST_AUTO_TEST_CASE( news_2010_03_23_new_subprofiles ) { AdHoc::FileUtils::MemMap m(rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d" / "metadata" / "news" / "2010-03-23-new-subprofiles" / "2010-03-23-new-subprofiles.en.txt"); - auto news = Portage::Utils::News::parse(reinterpret_cast<const gchar *>(m.data), m.getStat().st_size); + auto news = Portage::Utils::News::parse(m.sv()); BOOST_REQUIRE_EQUAL(news->title, "New desktop subprofiles for GNOME and KDE"); BOOST_REQUIRE(news->authorname); BOOST_REQUIRE_EQUAL(*news->authorname, "Theo Chatzimichos"); diff --git a/gentoobrowse-api/unittests/testProcessAll.cpp b/gentoobrowse-api/unittests/testProcessAll.cpp index cd72a8c..b06ad23 100644 --- a/gentoobrowse-api/unittests/testProcessAll.cpp +++ b/gentoobrowse-api/unittests/testProcessAll.cpp @@ -3,6 +3,7 @@ #include <boost/test/data/test_case.hpp> #include <depend.h> +#include <news.h> #include <utils/ebuildCacheParser.h> #include <boost/filesystem/path.hpp> #include <boost/filesystem/convenience.hpp> @@ -35,3 +36,20 @@ BOOST_DATA_TEST_CASE( ebuildCacheDependencies, boost::unit_test::data::make( testDependRange(ecp.getRange("PDEPEND")); } +BOOST_DATA_TEST_CASE( news, boost::unit_test::data::make( + getFileList("/usr/portage/metadata/news", boost::filesystem::is_regular_file)), + path ) +{ + AdHoc::FileUtils::MemMap n(path); + auto news = Portage::Utils::News::parse(n.sv<gchar>()); + BOOST_REQUIRE(news); + BOOST_CHECK(news->authoremail); + BOOST_CHECK(!news->authoremail->empty()); + BOOST_CHECK(news->authorname); + BOOST_CHECK(!news->authorname->empty()); + BOOST_CHECK(!news->body.empty()); + BOOST_CHECK(!news->title.empty()); + BOOST_CHECK_EQUAL(news->posted.length(), 10); + BOOST_CHECK(news->newsid.empty()); // From file name, not handled by parser +} + |