From e416cafd491f00778abfbf4518b9c70bdde52723 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 1 Jan 2017 18:35:50 +0000 Subject: [PATCH] Count instances constructed/destructed in exception tests --- test/helpers/exception_test.hpp | 2 ++ test/objects/exception.hpp | 42 +++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/test/helpers/exception_test.hpp b/test/helpers/exception_test.hpp index d1bc1317..ad7ae7ea 100644 --- a/test/helpers/exception_test.hpp +++ b/test/helpers/exception_test.hpp @@ -7,6 +7,7 @@ #define BOOST_UNORDERED_EXCEPTION_TEST_HEADER #include "./test.hpp" +#include "./count.hpp" #include #include @@ -187,6 +188,7 @@ namespace test { test_runner(Test const& t) : test_(t), exception_in_check_(false) {} void run() { DISABLE_EXCEPTIONS; + test::check_instances check; test::scope = ""; BOOST_DEDUCED_TYPENAME Test::data_type x(test_.init()); BOOST_DEDUCED_TYPENAME Test::strong_type strong; diff --git a/test/objects/exception.hpp b/test/objects/exception.hpp index 0e0aa869..2cd2ce11 100644 --- a/test/objects/exception.hpp +++ b/test/objects/exception.hpp @@ -13,6 +13,7 @@ #include #include #include "../helpers/fwd.hpp" +#include "../helpers/count.hpp" #include "../helpers/memory.hpp" namespace test @@ -24,6 +25,7 @@ namespace exception class equal_to; template class allocator; object generate(object const*, random_generator); + std::pair generate(std::pair const*, random_generator); struct true_type { @@ -35,7 +37,7 @@ namespace exception enum { value = false }; }; - class object + class object : private counted_object { public: int tag1_, tag2_; @@ -55,7 +57,7 @@ namespace exception } object(object const& x) - : tag1_(x.tag1_), tag2_(x.tag2_) + : counted_object(x), tag1_(x.tag1_), tag2_(x.tag2_) { UNORDERED_SCOPE(object::object(object)) { UNORDERED_EPOINT("Mock object copy constructor."); @@ -106,6 +108,13 @@ namespace exception return object(::test::generate(x, g), ::test::generate(x, g)); } + friend std::pair generate(std::pair const*, random_generator g) { + int* x = 0; + return std::make_pair( + object(::test::generate(x, g), ::test::generate(x, g)), + object(::test::generate(x, g), ::test::generate(x, g))); + } + friend std::ostream& operator<<(std::ostream& out, object const& o) { return out<<"("< const& x) const { + UNORDERED_SCOPE(hash::operator()(std::pair)) { + UNORDERED_EPOINT("Mock hash pair function."); + } + + return hash_impl(x.first) * 193ul + hash_impl(x.second) * 97ul + 29ul; + } + + std::size_t hash_impl(object const& x) const { int result; switch(tag_) { case 1: @@ -209,6 +230,18 @@ namespace exception UNORDERED_EPOINT("Mock equal_to function."); } + return equal_impl(x1, x2); + } + + bool operator()(std::pair const& x1, std::pair const& x2) const { + UNORDERED_SCOPE(equal_to::operator()(std::pair, std::pair)) { + UNORDERED_EPOINT("Mock equal_to function."); + } + + return equal_impl(x1.first, x2.first) && equal_impl(x1.second, x2.second); + } + + bool equal_impl(object const& x1, object const& x2) const { switch(tag_) { case 1: return x1.tag1_ == x2.tag1_; @@ -596,6 +629,11 @@ namespace test random_generator g) { return test::exception::generate(x, g); } + + std::pair generate(std::pair const* x, + random_generator g) { + return test::exception::generate(x, g); + } } #endif