Count instances constructed/destructed in exception tests

This commit is contained in:
Daniel James
2017-01-01 18:35:50 +00:00
parent 0a1c9ad4c5
commit e416cafd49
2 changed files with 42 additions and 2 deletions

View File

@ -7,6 +7,7 @@
#define BOOST_UNORDERED_EXCEPTION_TEST_HEADER
#include "./test.hpp"
#include "./count.hpp"
#include <boost/preprocessor/seq/for_each_product.hpp>
#include <boost/preprocessor/seq/elem.hpp>
@ -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;

View File

@ -13,6 +13,7 @@
#include <boost/limits.hpp>
#include <new>
#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 T> class allocator;
object generate(object const*, random_generator);
std::pair<object, object> generate(std::pair<object, object> 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<object, object> generate(std::pair<object, object> 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<<"("<<o.tag1_<<","<<o.tag2_<<")";
@ -146,6 +155,18 @@ namespace exception
UNORDERED_EPOINT("Mock hash function.");
}
return hash_impl(x);
}
std::size_t operator()(std::pair<object, object> const& x) const {
UNORDERED_SCOPE(hash::operator()(std::pair<object, object>)) {
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<object, object> const& x1, std::pair<object, object> const& x2) const {
UNORDERED_SCOPE(equal_to::operator()(std::pair<object, object>, std::pair<object, object>)) {
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<test::exception::object, test::exception::object> generate(std::pair<test::exception::object, test::exception::object> const* x,
random_generator g) {
return test::exception::generate(x, g);
}
}
#endif