summaryrefslogtreecommitdiff
path: root/test/test-collection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'test/test-collection.cpp')
-rw-r--r--test/test-collection.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/test/test-collection.cpp b/test/test-collection.cpp
new file mode 100644
index 0000000..0e05526
--- /dev/null
+++ b/test/test-collection.cpp
@@ -0,0 +1,62 @@
+#define BOOST_TEST_MODULE test_collection
+
+#include <boost/test/unit_test.hpp>
+
+#include <collection.hpp>
+#include <memory>
+#include <vector>
+
+class Base {
+public:
+ virtual bool
+ add()
+ {
+ total += 1;
+ return false;
+ }
+ unsigned int total {0};
+};
+
+class Sub : public Base {
+public:
+ bool
+ add() override
+ {
+ total += 2;
+ return true;
+ }
+};
+
+using TestCollection = Collection<Base>;
+
+BOOST_TEST_DONT_PRINT_LOG_VALUE(Collection<Base>::Objects::const_iterator);
+
+BOOST_FIXTURE_TEST_SUITE(tc, TestCollection);
+
+BOOST_AUTO_TEST_CASE(empty)
+{
+ BOOST_REQUIRE(!apply(&Base::add));
+ const auto i = applyOne(&Base::add);
+ BOOST_CHECK_EQUAL(i, end());
+}
+
+BOOST_AUTO_TEST_CASE(a_base)
+{
+ auto b = create<Base>();
+ BOOST_REQUIRE(apply(&Base::add));
+ BOOST_CHECK_EQUAL(b->total, 1);
+ const auto i = applyOne(&Base::add);
+ BOOST_CHECK_EQUAL(i, end());
+}
+
+BOOST_AUTO_TEST_CASE(a_sub)
+{
+ auto s = create<Sub>();
+ BOOST_REQUIRE(apply(&Base::add));
+ BOOST_CHECK_EQUAL(s->total, 2);
+ const auto i = applyOne(&Base::add);
+ BOOST_CHECK_NE(i, end());
+ BOOST_CHECK_EQUAL(*i, s);
+}
+
+BOOST_AUTO_TEST_SUITE_END();