summaryrefslogtreecommitdiff
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
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
-rw-r--r--Jamroot.jam11
-rw-r--r--iwyu.json32
-rw-r--r--test/Jamfile.jam12
-rw-r--r--test/test-collection.cpp62
-rw-r--r--utility/collection.hpp9
5 files changed, 121 insertions, 5 deletions
diff --git a/Jamroot.jam b/Jamroot.jam
index 0c030aa..043ac4f 100644
--- a/Jamroot.jam
+++ b/Jamroot.jam
@@ -49,13 +49,10 @@ exe iliketrains :
application/main.cpp
:
<library>ilt
- <include>.
- <include>utility
- <include>lib
;
lib ilt :
- [ glob-tree *.cpp *.c *.vs *.fs : bin ]
+ [ glob-tree *.cpp *.c *.vs *.fs : bin test ]
:
<variant>release:<link>static
<include>.
@@ -65,4 +62,10 @@ lib ilt :
<library>glew/<link>shared
<library>pthread/<link>shared
<use>stb
+ : :
+ <include>.
+ <include>utility
+ <include>lib
;
+
+build-project test ;
diff --git a/iwyu.json b/iwyu.json
index ee63d1c..8bfa310 100644
--- a/iwyu.json
+++ b/iwyu.json
@@ -39,6 +39,38 @@
"public"
]
},
+ {
+ "include": [
+ "<boost/test/unit_test_suite.hpp>",
+ "private",
+ "<boost/test/unit_test.hpp>",
+ "public"
+ ]
+ },
+ {
+ "include": [
+ "@<boost/test/utils/.*>",
+ "private",
+ "<boost/test/unit_test.hpp>",
+ "public"
+ ]
+ },
+ {
+ "include": [
+ "@<boost/test/tools/.*>",
+ "private",
+ "<boost/test/unit_test.hpp>",
+ "public"
+ ]
+ },
+ {
+ "include": [
+ "@<boost/preprocessor/.*>",
+ "private",
+ "<boost/test/unit_test.hpp>",
+ "public"
+ ]
+ },
{
"symbol": [
"std::__atomic_wait",
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();
diff --git a/utility/collection.hpp b/utility/collection.hpp
index a9ddb78..48eae0e 100644
--- a/utility/collection.hpp
+++ b/utility/collection.hpp
@@ -7,7 +7,8 @@
template<typename Object> class Collection {
public:
using Ptr = std::shared_ptr<Object>;
- std::vector<Ptr> objects;
+ using Objects = std::vector<Ptr>;
+ Objects objects;
template<typename T = Object, typename... Params>
auto
@@ -53,6 +54,12 @@ public:
}),
objects.end());
}
+
+ auto
+ end() const
+ {
+ return objects.end();
+ }
};
#endif