mirror of
https://github.com/boostorg/unordered.git
synced 2025-07-31 03:47:16 +02:00
Count instances constructed/destructed in exception tests
This commit is contained in:
@ -7,6 +7,7 @@
|
|||||||
#define BOOST_UNORDERED_EXCEPTION_TEST_HEADER
|
#define BOOST_UNORDERED_EXCEPTION_TEST_HEADER
|
||||||
|
|
||||||
#include "./test.hpp"
|
#include "./test.hpp"
|
||||||
|
#include "./count.hpp"
|
||||||
|
|
||||||
#include <boost/preprocessor/seq/for_each_product.hpp>
|
#include <boost/preprocessor/seq/for_each_product.hpp>
|
||||||
#include <boost/preprocessor/seq/elem.hpp>
|
#include <boost/preprocessor/seq/elem.hpp>
|
||||||
@ -187,6 +188,7 @@ namespace test {
|
|||||||
test_runner(Test const& t) : test_(t), exception_in_check_(false) {}
|
test_runner(Test const& t) : test_(t), exception_in_check_(false) {}
|
||||||
void run() {
|
void run() {
|
||||||
DISABLE_EXCEPTIONS;
|
DISABLE_EXCEPTIONS;
|
||||||
|
test::check_instances check;
|
||||||
test::scope = "";
|
test::scope = "";
|
||||||
BOOST_DEDUCED_TYPENAME Test::data_type x(test_.init());
|
BOOST_DEDUCED_TYPENAME Test::data_type x(test_.init());
|
||||||
BOOST_DEDUCED_TYPENAME Test::strong_type strong;
|
BOOST_DEDUCED_TYPENAME Test::strong_type strong;
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include <boost/limits.hpp>
|
#include <boost/limits.hpp>
|
||||||
#include <new>
|
#include <new>
|
||||||
#include "../helpers/fwd.hpp"
|
#include "../helpers/fwd.hpp"
|
||||||
|
#include "../helpers/count.hpp"
|
||||||
#include "../helpers/memory.hpp"
|
#include "../helpers/memory.hpp"
|
||||||
|
|
||||||
namespace test
|
namespace test
|
||||||
@ -24,6 +25,7 @@ namespace exception
|
|||||||
class equal_to;
|
class equal_to;
|
||||||
template <class T> class allocator;
|
template <class T> class allocator;
|
||||||
object generate(object const*, random_generator);
|
object generate(object const*, random_generator);
|
||||||
|
std::pair<object, object> generate(std::pair<object, object> const*, random_generator);
|
||||||
|
|
||||||
struct true_type
|
struct true_type
|
||||||
{
|
{
|
||||||
@ -35,7 +37,7 @@ namespace exception
|
|||||||
enum { value = false };
|
enum { value = false };
|
||||||
};
|
};
|
||||||
|
|
||||||
class object
|
class object : private counted_object
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
int tag1_, tag2_;
|
int tag1_, tag2_;
|
||||||
@ -55,7 +57,7 @@ namespace exception
|
|||||||
}
|
}
|
||||||
|
|
||||||
object(object const& x)
|
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_SCOPE(object::object(object)) {
|
||||||
UNORDERED_EPOINT("Mock object copy constructor.");
|
UNORDERED_EPOINT("Mock object copy constructor.");
|
||||||
@ -106,6 +108,13 @@ namespace exception
|
|||||||
return object(::test::generate(x, g), ::test::generate(x, g));
|
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)
|
friend std::ostream& operator<<(std::ostream& out, object const& o)
|
||||||
{
|
{
|
||||||
return out<<"("<<o.tag1_<<","<<o.tag2_<<")";
|
return out<<"("<<o.tag1_<<","<<o.tag2_<<")";
|
||||||
@ -146,6 +155,18 @@ namespace exception
|
|||||||
UNORDERED_EPOINT("Mock hash function.");
|
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;
|
int result;
|
||||||
switch(tag_) {
|
switch(tag_) {
|
||||||
case 1:
|
case 1:
|
||||||
@ -209,6 +230,18 @@ namespace exception
|
|||||||
UNORDERED_EPOINT("Mock equal_to function.");
|
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_) {
|
switch(tag_) {
|
||||||
case 1:
|
case 1:
|
||||||
return x1.tag1_ == x2.tag1_;
|
return x1.tag1_ == x2.tag1_;
|
||||||
@ -596,6 +629,11 @@ namespace test
|
|||||||
random_generator g) {
|
random_generator g) {
|
||||||
return test::exception::generate(x, 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
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user