From a27bf76eec4ec37e9c41690ea4787d0388055b05 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 20 Mar 2018 21:03:51 +0000 Subject: Add a simple unit test over the existing mask lexer --- gentoobrowse-api/unittests/Jamfile.jam | 7 +++++ gentoobrowse-api/unittests/testMasks.cpp | 52 ++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 gentoobrowse-api/unittests/testMasks.cpp diff --git a/gentoobrowse-api/unittests/Jamfile.jam b/gentoobrowse-api/unittests/Jamfile.jam index a53781e..ead573a 100644 --- a/gentoobrowse-api/unittests/Jamfile.jam +++ b/gentoobrowse-api/unittests/Jamfile.jam @@ -64,6 +64,13 @@ run testCommon : testDepend ; +run + testMasks.cpp ../service/mask.cpp + : : : + BOOST_TEST_DYN_LINK + testCommon + : testMasks ; + explicit testDependAll ; run testDependAll.cpp ../service/utils/ebuildCacheParser.cpp ../service/depend.cpp diff --git a/gentoobrowse-api/unittests/testMasks.cpp b/gentoobrowse-api/unittests/testMasks.cpp new file mode 100644 index 0000000..8aba4ea --- /dev/null +++ b/gentoobrowse-api/unittests/testMasks.cpp @@ -0,0 +1,52 @@ +#define BOOST_TEST_MODULE Masks +#include + +#include +#include +#include +#include +#include +#include + +class MaskTester : public Portage::Utils::Masks { + protected: + void consume() const override + { + if (email && person) { + masks.push_back(new Gentoo::Mask(n, *person, *email, date, + boost::algorithm::join(message, " "), + Gentoo::StringList(atoms.begin(), atoms.end()))); + } + } + + public: + mutable Gentoo::Masks masks; +}; + +#define BOOST_CHECK_EQUAL_COLLECTION(a, ...) { \ + auto __list__ = { __VA_ARGS__ }; \ + BOOST_CHECK_EQUAL_COLLECTIONS(a.begin(), a.end(), __list__.begin(), __list__.end()); \ +} + +BOOST_FIXTURE_TEST_SUITE(mt, MaskTester) + +BOOST_AUTO_TEST_CASE(f1) +{ + AdHoc::FileUtils::MemMap f(rootDir / "fixtures" / "4156eb45cf3b0ce1d7125b84efd8688c2d6e831d" / "profiles" / "package.mask"); + extract((const gchar *)f.data, f.getStat().st_size); + BOOST_CHECK_EQUAL(masks.size(), 151); + auto m = masks.front(); + BOOST_CHECK(m->person); + BOOST_CHECK_EQUAL("James Le Cuirot", *m->person); + BOOST_CHECK(m->email); + BOOST_CHECK_EQUAL("chewi@gentoo.org", *m->email); + BOOST_CHECK_EQUAL("25 Apr 1016", m->dateadded); + BOOST_CHECK_EQUAL("Long dead upstream and no longer needed. Removal in 30 days.", m->message); + BOOST_CHECK_EQUAL_COLLECTION(m->atomspec, + "dev-java/charva", + "dev-java/jakarta-slide-webdavclient", + "dev-java/xml-im-exporter"); +} + +BOOST_AUTO_TEST_SUITE_END() + -- cgit v1.2.3