From 7b44e4f20b91a64b778bcc8b2f00602d4ba13bd2 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 23 Mar 2025 18:46:10 +0000 Subject: Support using typed collections for subclass filtering --- test/test-collection.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'test') diff --git a/test/test-collection.cpp b/test/test-collection.cpp index 5aae9f0..a399845 100644 --- a/test/test-collection.cpp +++ b/test/test-collection.cpp @@ -40,10 +40,15 @@ public: } }; +class Sub1 : public Sub { }; + using TestCollection = SharedCollection; +BOOST_TEST_DONT_PRINT_LOG_VALUE(TestCollection::Objects::iterator) BOOST_TEST_DONT_PRINT_LOG_VALUE(TestCollection::Objects::const_iterator) BOOST_TEST_DONT_PRINT_LOG_VALUE(TestCollection::Objects::const_reverse_iterator) +BOOST_TEST_DONT_PRINT_LOG_VALUE(TestCollection::OtherObjects::iterator) +BOOST_TEST_DONT_PRINT_LOG_VALUE(TestCollection::OtherObjects::const_iterator) BOOST_FIXTURE_TEST_SUITE(tc, TestCollection) @@ -55,6 +60,7 @@ BOOST_AUTO_TEST_CASE(empty) BOOST_CHECK_EQUAL(i, end()); BOOST_CHECK(!find()); BOOST_CHECK(!find()); + BOOST_CHECK(!find()); } BOOST_AUTO_TEST_CASE(a_base) @@ -68,6 +74,7 @@ BOOST_AUTO_TEST_CASE(a_base) BOOST_CHECK_EQUAL(i, end()); BOOST_CHECK_EQUAL(b.get(), find()); BOOST_CHECK(!find()); + BOOST_CHECK(!find()); } BOOST_AUTO_TEST_CASE(emplace_others) @@ -80,6 +87,7 @@ BOOST_AUTO_TEST_CASE(emplace_others) BOOST_CHECK_EQUAL(std::get>(otherObjects).size(), 1); BOOST_CHECK_EQUAL(b.get(), find()); BOOST_CHECK_EQUAL(s.get(), find()); + BOOST_CHECK(!find()); } BOOST_AUTO_TEST_CASE(a_rbase) @@ -103,6 +111,38 @@ BOOST_AUTO_TEST_CASE(a_sub) BOOST_CHECK_EQUAL(*i, s); } +BOOST_AUTO_TEST_CASE(filter) +{ + create(); + BOOST_CHECK_EQUAL(1, apply(&Base::yes)); + BOOST_CHECK_EQUAL(0, apply(&Base::yes)); + BOOST_CHECK_EQUAL(0, apply(&Base::yes)); + BOOST_CHECK_EQUAL(objects.begin(), applyOne(&Base::yes)); + BOOST_CHECK_EQUAL(std::get<0>(otherObjects).end(), applyOne(&Base::yes)); + BOOST_CHECK_EQUAL(std::get<0>(otherObjects).end(), applyOne(&Base::yes)); + create(); + BOOST_CHECK_EQUAL(2, apply(&Base::yes)); + BOOST_CHECK_EQUAL(1, apply(&Base::yes)); + BOOST_CHECK_EQUAL(0, apply(&Base::yes)); + BOOST_CHECK_EQUAL(objects.begin(), applyOne(&Base::yes)); + BOOST_CHECK_EQUAL(std::get<0>(otherObjects).begin(), applyOne(&Base::yes)); + BOOST_CHECK_EQUAL(std::get<0>(otherObjects).end(), applyOne(&Base::yes)); + create(); + BOOST_CHECK_EQUAL(3, apply(&Base::yes)); + BOOST_CHECK_EQUAL(2, apply(&Base::yes)); + BOOST_CHECK_EQUAL(1, apply(&Base::yes)); + BOOST_CHECK_EQUAL(objects.begin(), applyOne(&Base::yes)); + BOOST_CHECK_EQUAL(std::get<0>(otherObjects).begin(), applyOne(&Base::yes)); + BOOST_CHECK_EQUAL(std::get<0>(otherObjects).begin() + 1, applyOne(&Base::yes)); + + BOOST_CHECK_EQUAL(std::get()>(otherObjects).size(), 2); + BOOST_CHECK_EQUAL(std::get()>(otherObjects).size(), 2); + + BOOST_CHECK_EQUAL(&objects, &containerFor()); + BOOST_CHECK_EQUAL(&std::get<0>(otherObjects), &containerFor()); + BOOST_CHECK_EQUAL(&std::get<0>(otherObjects), &containerFor()); +} + BOOST_AUTO_TEST_CASE(begin_end) { BOOST_CHECK_EQUAL(0, std::distance(begin(), end())); @@ -230,6 +270,8 @@ BOOST_AUTO_TEST_CASE(applyOneType) create(); BOOST_CHECK_EQUAL(objects.begin() + 1, applyOne(&Base::yes)); BOOST_CHECK_EQUAL(objects.begin(), applyOne(&Base::yes)); + create(); + BOOST_CHECK_EQUAL(objects.begin() + 2, applyOne(&Base::yes)); } BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3