summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
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();