summaryrefslogtreecommitdiff
path: root/test
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
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')
-rw-r--r--test/Jamfile.jam12
-rw-r--r--test/test-collection.cpp62
2 files changed, 74 insertions, 0 deletions
diff --git a/test/Jamfile.jam b/test/Jamfile.jam
new file mode 100644
index 0000000..0dbbc4e
--- /dev/null
+++ b/test/Jamfile.jam
@@ -0,0 +1,12 @@
+import testing ;
+
+lib boost_unit_test_framework ;
+
+project : requirements
+ <define>BOOST_TEST_DYN_LINK
+ <library>boost_unit_test_framework
+ <library>..//ilt
+ <toolset>tidy:<xcheckxx>hicpp-vararg
+ ;
+
+run test-collection.cpp ;
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();