From a8fdf19c9131534b29a6494ebd61797a7b2e6060 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Tue, 16 Aug 2011 18:08:23 +0000 Subject: [PATCH] Unordered: Test types that are only destructible. [SVN r73820] --- test/objects/minimal.hpp | 36 ++++++++++++++++--------- test/unordered/compile_map.cpp | 20 +++++++------- test/unordered/compile_set.cpp | 45 ++++++++++++++++++++++++------- test/unordered/compile_tests.hpp | 46 ++++++++++++++++++++++++++------ 4 files changed, 107 insertions(+), 40 deletions(-) diff --git a/test/objects/minimal.hpp b/test/objects/minimal.hpp index 65779032..fc344b21 100644 --- a/test/objects/minimal.hpp +++ b/test/objects/minimal.hpp @@ -21,6 +21,7 @@ namespace test { namespace minimal { + class destructible; class copy_constructible; class copy_constructible_equality_comparable; class default_copy_constructible; @@ -35,10 +36,25 @@ namespace minimal template class allocator; template class cxx11_allocator; + struct constructor_param + { + operator int() const { return 0; } + }; + + class destructible + { + public: + destructible(constructor_param const&) {} + ~destructible() {} + private: + destructible(destructible const&); + destructible& operator=(destructible const&); + }; + class copy_constructible { public: - static copy_constructible create() { return copy_constructible(); } + copy_constructible(constructor_param const&) {} copy_constructible(copy_constructible const&) {} ~copy_constructible() {} private: @@ -49,9 +65,7 @@ namespace minimal class copy_constructible_equality_comparable { public: - static copy_constructible_equality_comparable create() { - return copy_constructible_equality_comparable(); - } + copy_constructible_equality_comparable(constructor_param const&) {} copy_constructible_equality_comparable( copy_constructible_equality_comparable const&) @@ -86,10 +100,7 @@ namespace minimal class default_copy_constructible { public: - static default_copy_constructible create() - { - return default_copy_constructible(); - } + default_copy_constructible(constructor_param const&) {} default_copy_constructible() { @@ -106,13 +117,14 @@ namespace minimal private: default_copy_constructible& operator=( default_copy_constructible const&); - ampersand_operator_used operator&() const { return ampersand_operator_used(); } + ampersand_operator_used operator&() const { + return ampersand_operator_used(); } }; class assignable { public: - static assignable create() { return assignable(); } + assignable(constructor_param const&) {} assignable(assignable const&) {} assignable& operator=(assignable const&) { return *this; } ~assignable() {} @@ -127,7 +139,7 @@ namespace minimal class hash { public: - static hash create() { return hash(); } + hash(constructor_param const&) {} hash() {} hash(hash const&) {} hash& operator=(hash const&) { return *this; } @@ -142,7 +154,7 @@ namespace minimal class equal_to { public: - static equal_to create() { return equal_to(); } + equal_to(constructor_param const&) {} equal_to() {} equal_to(equal_to const&) {} equal_to& operator=(equal_to const&) { return *this; } diff --git a/test/unordered/compile_map.cpp b/test/unordered/compile_map.cpp index a30e14b4..d215d805 100644 --- a/test/unordered/compile_map.cpp +++ b/test/unordered/compile_map.cpp @@ -45,11 +45,11 @@ template class boost::unordered_multimap< UNORDERED_AUTO_TEST(test0) { + test::minimal::constructor_param x; + typedef std::pair value_type; - value_type value( - test::minimal::assignable::create(), - test::minimal::copy_constructible::create()); + value_type value(x, x); std::cout<<"Test unordered_map.\n"; @@ -179,14 +179,12 @@ UNORDERED_AUTO_TEST(test1) { UNORDERED_AUTO_TEST(test2) { - test::minimal::assignable assignable - = test::minimal::assignable::create(); - test::minimal::copy_constructible copy_constructible - = test::minimal::copy_constructible::create(); - test::minimal::hash hash - = test::minimal::hash::create(); - test::minimal::equal_to equal_to - = test::minimal::equal_to::create(); + test::minimal::constructor_param x; + + test::minimal::assignable assignable(x); + test::minimal::copy_constructible copy_constructible(x); + test::minimal::hash hash(x); + test::minimal::equal_to equal_to(x); typedef std::pair map_value_type; diff --git a/test/unordered/compile_set.cpp b/test/unordered/compile_set.cpp index 62efc272..569f58e7 100644 --- a/test/unordered/compile_set.cpp +++ b/test/unordered/compile_set.cpp @@ -41,7 +41,9 @@ template class boost::unordered_multiset< UNORDERED_AUTO_TEST(test0) { - test::minimal::assignable assignable = test::minimal::assignable::create(); + test::minimal::constructor_param x; + + test::minimal::assignable assignable(x); std::cout<<"Test unordered_set.\n"; @@ -163,14 +165,12 @@ UNORDERED_AUTO_TEST(test1) UNORDERED_AUTO_TEST(test2) { - test::minimal::assignable assignable - = test::minimal::assignable::create(); - test::minimal::copy_constructible copy_constructible - = test::minimal::copy_constructible::create(); - test::minimal::hash hash - = test::minimal::hash::create(); - test::minimal::equal_to equal_to - = test::minimal::equal_to::create(); + test::minimal::constructor_param x; + + test::minimal::assignable assignable(x); + test::minimal::copy_constructible copy_constructible(x); + test::minimal::hash hash(x); + test::minimal::equal_to equal_to(x); std::cout<<"Test unordered_set.\n"; @@ -197,4 +197,31 @@ UNORDERED_AUTO_TEST(test2) unordered_test(multiset, assignable, assignable, hash, equal_to); } +UNORDERED_AUTO_TEST(destructible_tests) +{ + test::minimal::constructor_param x; + + test::minimal::destructible destructible(x); + test::minimal::hash hash(x); + test::minimal::equal_to equal_to(x); + + std::cout<<"Test unordered_set.\n"; + + boost::unordered_set< + test::minimal::destructible, + test::minimal::hash, + test::minimal::equal_to > set; + + unordered_destructible_test(set); + + std::cout<<"Test unordered_multiset.\n"; + + boost::unordered_multiset< + test::minimal::destructible, + test::minimal::hash, + test::minimal::equal_to > multiset; + + unordered_destructible_test(multiset); +} + RUN_TESTS() diff --git a/test/unordered/compile_tests.hpp b/test/unordered/compile_tests.hpp index 8d06e7d1..ce6ca3ac 100644 --- a/test/unordered/compile_tests.hpp +++ b/test/unordered/compile_tests.hpp @@ -28,6 +28,7 @@ typedef long double comparison_type; template void sink(T const&) {} template T rvalue(T const& v) { return v; } +template T rvalue_default() { return T(); } template void container_test(X& r, T const&) @@ -109,15 +110,48 @@ void container_test(X& r, T const&) BOOST_TEST(X().size() == 0); X a,b; + X a_const; sink(X(a)); X u2(a); X u3 = a; + a.swap(b); + boost::swap(a, b); + test::check_return_type::equals_ref(r = a); + + // Allocator + + typedef BOOST_DEDUCED_TYPENAME X::allocator_type allocator_type; + test::check_return_type::equals(a_const.get_allocator()); + + // Avoid unused variable warnings: + + sink(u); + sink(u2); + sink(u3); +} + +template +void unordered_destructible_test(X&) +{ + typedef BOOST_DEDUCED_TYPENAME X::iterator iterator; + typedef BOOST_DEDUCED_TYPENAME X::const_iterator const_iterator; + typedef BOOST_DEDUCED_TYPENAME X::size_type size_type; + + X x1; + +#if !defined(BOOST_NO_RVALUE_REFERENCES) + X x2(rvalue_default()); + X x3 = rvalue_default(); + x2 = rvalue_default(); +#endif + X* ptr = new X(); X& a1 = *ptr; (&a1)->~X(); + X a,b; X const a_const; test::check_return_type::equals(a.begin()); test::check_return_type::equals(a_const.begin()); @@ -130,7 +164,7 @@ void container_test(X& r, T const&) a.swap(b); boost::swap(a, b); - test::check_return_type::equals_ref(r = a); + test::check_return_type::equals(a.size()); test::check_return_type::equals(a.max_size()); test::check_return_type::convertible(a.empty()); @@ -139,12 +173,6 @@ void container_test(X& r, T const&) typedef BOOST_DEDUCED_TYPENAME X::allocator_type allocator_type; test::check_return_type::equals(a_const.get_allocator()); - - // Avoid unused variable warnings: - - sink(u); - sink(u2); - sink(u3); } template @@ -215,8 +243,10 @@ void unordered_map_functions(X&, Key const& k, T const&) } template -void unordered_test(X&, Key& k, T& t, Hash& hf, Pred& eq) +void unordered_test(X& x, Key& k, T& t, Hash& hf, Pred& eq) { + unordered_destructible_test(x); + typedef BOOST_DEDUCED_TYPENAME X::key_type key_type; typedef BOOST_DEDUCED_TYPENAME X::hasher hasher; typedef BOOST_DEDUCED_TYPENAME X::key_equal key_equal;