summaryrefslogtreecommitdiff
path: root/test/test-collection.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-01-30 18:38:27 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-02-04 19:29:46 +0000
commit485445b391f8f342ba7a91cb8c628e4ee9b3003a (patch)
treed59b5af671eec0d7b71f9594769094327bd2ca66 /test/test-collection.cpp
parentSplit into main app and library the rest for testing (diff)
downloadilt-485445b391f8f342ba7a91cb8c628e4ee9b3003a.tar.bz2
ilt-485445b391f8f342ba7a91cb8c628e4ee9b3003a.tar.xz
ilt-485445b391f8f342ba7a91cb8c628e4ee9b3003a.zip
Add some tests over collection
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();