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 --- test/Jamfile.jam | 12 ++++++++++ test/test-collection.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 test/Jamfile.jam create mode 100644 test/test-collection.cpp (limited to 'test') 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(); -- cgit v1.2.3