From 485445b391f8f342ba7a91cb8c628e4ee9b3003a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 30 Jan 2021 18:38:27 +0000 Subject: Add some tests over collection --- Jamroot.jam | 11 +++++---- iwyu.json | 32 +++++++++++++++++++++++++ test/Jamfile.jam | 12 ++++++++++ test/test-collection.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ utility/collection.hpp | 9 ++++++- 5 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 test/Jamfile.jam create mode 100644 test/test-collection.cpp 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 : ilt - . - utility - lib ; lib ilt : - [ glob-tree *.cpp *.c *.vs *.fs : bin ] + [ glob-tree *.cpp *.c *.vs *.fs : bin test ] : release:static . @@ -65,4 +62,10 @@ lib ilt : glew/shared pthread/shared stb + : : + . + utility + lib ; + +build-project test ; diff --git a/iwyu.json b/iwyu.json index ee63d1c..8bfa310 100644 --- a/iwyu.json +++ b/iwyu.json @@ -38,6 +38,38 @@ "", "public" ] + }, + { + "include": [ + "", + "private", + "", + "public" + ] + }, + { + "include": [ + "@", + "private", + "", + "public" + ] + }, + { + "include": [ + "@", + "private", + "", + "public" + ] + }, + { + "include": [ + "@", + "private", + "", + "public" + ] }, { "symbol": [ 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 + BOOST_TEST_DYN_LINK + boost_unit_test_framework + ..//ilt + tidy: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 + +#include +#include +#include + +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; + +BOOST_TEST_DONT_PRINT_LOG_VALUE(Collection::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(); + 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(); + 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 class Collection { public: using Ptr = std::shared_ptr; - std::vector objects; + using Objects = std::vector; + Objects objects; template auto @@ -53,6 +54,12 @@ public: }), objects.end()); } + + auto + end() const + { + return objects.end(); + } }; #endif -- cgit v1.2.3