From 3299b31787d188914dbfdb6fbefd97a5da0f47cf Mon Sep 17 00:00:00 2001 From: Christian Mazakas Date: Tue, 15 Aug 2023 13:03:52 -0700 Subject: [PATCH] Update tests to accomodate foa containers allocating groups when the pointer type is fancy --- test/unordered/assign_tests.cpp | 2 - test/unordered/constructor_tests.cpp | 36 +++++++++---- test/unordered/max_load_tests.cpp | 7 ++- test/unordered/move_tests.cpp | 77 +++++++++++++++++++--------- test/unordered/post_move_tests.cpp | 49 ++++++++++++++---- test/unordered/scary_tests.cpp | 2 - 6 files changed, 121 insertions(+), 52 deletions(-) diff --git a/test/unordered/assign_tests.cpp b/test/unordered/assign_tests.cpp index 8340ac20..e75f734d 100644 --- a/test/unordered/assign_tests.cpp +++ b/test/unordered/assign_tests.cpp @@ -41,7 +41,6 @@ namespace assign_tests { BOOST_TEST(x.empty()); BOOST_TEST(test::equivalent(x.hash_function(), hf)); BOOST_TEST(test::equivalent(x.key_eq(), eq)); - BOOST_TEST(test::detail::tracker.count_allocations == 0); } BOOST_LIGHTWEIGHT_TEST_OSTREAM << "assign_tests1.2\n"; @@ -91,7 +90,6 @@ namespace assign_tests { BOOST_TEST(test::equivalent(x1.key_eq(), eq1)); BOOST_TEST(test::equivalent(x2.hash_function(), hf1)); BOOST_TEST(test::equivalent(x2.key_eq(), eq1)); - BOOST_TEST(test::detail::tracker.count_allocations == 0); test::check_container(x1, x2); } diff --git a/test/unordered/constructor_tests.cpp b/test/unordered/constructor_tests.cpp index e65ebfb3..54268a42 100644 --- a/test/unordered/constructor_tests.cpp +++ b/test/unordered/constructor_tests.cpp @@ -6,13 +6,13 @@ #include "../helpers/unordered.hpp" -#include "../helpers/test.hpp" -#include "../objects/test.hpp" -#include "../helpers/random_values.hpp" -#include "../helpers/tracker.hpp" #include "../helpers/equivalent.hpp" #include "../helpers/input_iterator.hpp" #include "../helpers/invariants.hpp" +#include "../helpers/random_values.hpp" +#include "../helpers/test.hpp" +#include "../helpers/tracker.hpp" +#include "../objects/test.hpp" #include @@ -33,7 +33,6 @@ namespace constructor_tests { T x(0, hf, eq); BOOST_TEST(x.empty()); - BOOST_TEST_EQ(x.bucket_count(), 0u); BOOST_TEST(test::equivalent(x.hash_function(), hf)); BOOST_TEST(test::equivalent(x.key_eq(), eq)); BOOST_TEST(test::equivalent(x.get_allocator(), al)); @@ -72,7 +71,6 @@ namespace constructor_tests { T x; BOOST_TEST(x.empty()); - BOOST_TEST_EQ(x.bucket_count(), 0u); BOOST_TEST(test::equivalent(x.hash_function(), hf)); BOOST_TEST(test::equivalent(x.key_eq(), eq)); BOOST_TEST(test::equivalent(x.get_allocator(), al)); @@ -140,7 +138,6 @@ namespace constructor_tests { T x(0, hf, eq, al); BOOST_TEST(x.empty()); - BOOST_TEST_EQ(x.bucket_count(), 0u); BOOST_TEST(test::equivalent(x.hash_function(), hf)); BOOST_TEST(test::equivalent(x.key_eq(), eq)); BOOST_TEST(test::equivalent(x.get_allocator(), al)); @@ -167,7 +164,6 @@ namespace constructor_tests { T x(al); BOOST_TEST(x.empty()); - BOOST_TEST_EQ(x.bucket_count(), 0u); BOOST_TEST(test::equivalent(x.hash_function(), hf)); BOOST_TEST(test::equivalent(x.key_eq(), eq)); BOOST_TEST(test::equivalent(x.get_allocator(), al)); @@ -349,7 +345,6 @@ namespace constructor_tests { { T x(list); BOOST_TEST(x.empty()); - BOOST_TEST_EQ(x.bucket_count(), 0u); BOOST_TEST(test::equivalent(x.hash_function(), hf)); BOOST_TEST(test::equivalent(x.key_eq(), eq)); BOOST_TEST(test::equivalent(x.get_allocator(), al)); @@ -536,6 +531,16 @@ namespace constructor_tests { template void no_alloc_default_construct_test(T*, test::random_generator) { + +#ifdef BOOST_UNORDERED_FOA_TESTS + using allocator_type = typename T::allocator_type; + using value_type = + typename boost::allocator_value_type::type; + using pointer = typename boost::allocator_pointer::type; + static_assert(std::is_same::value, + "only raw pointers for this test"); +#endif + UNORDERED_SUB_TEST("Construct 1") { T x; @@ -653,6 +658,15 @@ namespace constructor_tests { boost::unordered_flat_map >* test_map_std_alloc; + boost::unordered_flat_set >* test_set_raw_ptr; + boost::unordered_node_set >* test_node_set_raw_ptr; + boost::unordered_flat_map >* test_map_raw_ptr; + boost::unordered_node_map >* test_node_map_raw_ptr; + boost::unordered_flat_set >* test_set; boost::unordered_node_set void max_load_tests(X*, test::random_generator generator) test::reset_sequence(); X x; - size_type max_load = x.max_load(); - - BOOST_TEST_EQ(max_load, 0u); x.reserve(1000); - max_load = x.max_load(); + size_type max_load = x.max_load(); + + BOOST_TEST_GT(max_load, 0u); size_type bucket_count = x.bucket_count(); BOOST_TEST_GE(bucket_count, 1000u); diff --git a/test/unordered/move_tests.cpp b/test/unordered/move_tests.cpp index 1ca1d58e..87317fa2 100644 --- a/test/unordered/move_tests.cpp +++ b/test/unordered/move_tests.cpp @@ -6,13 +6,13 @@ #include "../helpers/unordered.hpp" -#include "../helpers/test.hpp" -#include "../objects/test.hpp" -#include "../objects/cxx11_allocator.hpp" -#include "../helpers/random_values.hpp" -#include "../helpers/tracker.hpp" #include "../helpers/equivalent.hpp" #include "../helpers/invariants.hpp" +#include "../helpers/random_values.hpp" +#include "../helpers/test.hpp" +#include "../helpers/tracker.hpp" +#include "../objects/cxx11_allocator.hpp" +#include "../objects/test.hpp" #include #include @@ -75,7 +75,18 @@ namespace move_tests { test::check_equivalent_keys(y); #if defined(BOOST_UNORDERED_USE_MOVE) || \ !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + +#ifdef BOOST_UNORDERED_FOA_TESTS + using allocator_type = typename T::allocator_type; + using value_type = + typename boost::allocator_value_type::type; + using pointer = typename boost::allocator_pointer::type; + if (std::is_same::value) { + BOOST_TEST_EQ(test::detail::tracker.count_allocations, 0u); + } +#else BOOST_TEST_EQ(test::detail::tracker.count_allocations, 0u); +#endif #endif } @@ -117,7 +128,17 @@ namespace move_tests { y = empty(p); #if defined(BOOST_UNORDERED_USE_MOVE) || \ !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) +#ifdef BOOST_UNORDERED_FOA_TESTS + using allocator_type = typename T::allocator_type; + using value_type = + typename boost::allocator_value_type::type; + using pointer = typename boost::allocator_pointer::type; + if (std::is_same::value) { + BOOST_TEST_EQ(test::detail::tracker.count_allocations, 0u); + } +#else BOOST_TEST_EQ(test::detail::tracker.count_allocations, 0u); +#endif #endif test::check_container(y, v); test::check_equivalent_keys(y); @@ -279,12 +300,34 @@ namespace move_tests { T x(0, hf, eq, al2); x.max_load_factor(0.25); +#ifdef BOOST_UNORDERED_FOA_TESTS + { + using value_type = + typename boost::allocator_value_type::type; + using pointer = typename boost::allocator_pointer::type; + if (std::is_same::value) { + BOOST_TEST_EQ(test::detail::tracker.count_allocations, 0u); + } + } +#else BOOST_TEST_EQ(test::detail::tracker.count_allocations, 0u); +#endif y = boost::move(x); #if defined(BOOST_UNORDERED_USE_MOVE) || \ !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) +#ifdef BOOST_UNORDERED_FOA_TESTS + { + using value_type = + typename boost::allocator_value_type::type; + using pointer = typename boost::allocator_pointer::type; + if (std::is_same::value) { + BOOST_TEST_EQ(test::detail::tracker.count_allocations, 0u); + } + } +#else BOOST_TEST_EQ(test::detail::tracker.count_allocations, 0u); +#endif #endif test::check_container(y, v); test::check_equivalent_keys(y); @@ -515,32 +558,18 @@ namespace move_tests { test::no_propagate_move> >* test_multimap_no_prop_move; UNORDERED_TEST(move_construct_tests1, - ((test_map_std_alloc)(test_set)(test_multiset)(test_map)(test_multimap)( - test_set_prop_move)(test_multiset_prop_move)(test_map_prop_move)( - test_multimap_prop_move)(test_set_no_prop_move)( - test_multiset_no_prop_move)(test_map_no_prop_move)( - test_multimap_no_prop_move))( + ((test_map_std_alloc)(test_set)(test_multiset)(test_map)(test_multimap)(test_set_prop_move)(test_multiset_prop_move)(test_map_prop_move)(test_multimap_prop_move)(test_set_no_prop_move)(test_multiset_no_prop_move)(test_map_no_prop_move)(test_multimap_no_prop_move))( (default_generator)(generate_collisions)(limited_range))) UNORDERED_TEST(move_assign_tests1, - ((test_map_std_alloc)(test_set)(test_multiset)(test_map)(test_multimap)( - test_set_prop_move)(test_multiset_prop_move)(test_map_prop_move)( - test_multimap_prop_move)(test_set_no_prop_move)( - test_multiset_no_prop_move)(test_map_no_prop_move)( - test_multimap_no_prop_move))( + ((test_map_std_alloc)(test_set)(test_multiset)(test_map)(test_multimap)(test_set_prop_move)(test_multiset_prop_move)(test_map_prop_move)(test_multimap_prop_move)(test_set_no_prop_move)(test_multiset_no_prop_move)(test_map_no_prop_move)(test_multimap_no_prop_move))( (default_generator)(generate_collisions)(limited_range))) UNORDERED_TEST(move_construct_tests2, - ((test_set)(test_multiset)(test_map)(test_multimap)(test_set_prop_move)( - test_multiset_prop_move)(test_map_prop_move)(test_multimap_prop_move)( - test_set_no_prop_move)(test_multiset_no_prop_move)(test_map_no_prop_move)( - test_multimap_no_prop_move))( + ((test_set)(test_multiset)(test_map)(test_multimap)(test_set_prop_move)(test_multiset_prop_move)(test_map_prop_move)(test_multimap_prop_move)(test_set_no_prop_move)(test_multiset_no_prop_move)(test_map_no_prop_move)(test_multimap_no_prop_move))( (default_generator)(generate_collisions)(limited_range))) UNORDERED_TEST(move_assign_tests2, - ((test_set)(test_multiset)(test_map)(test_multimap)(test_set_prop_move)( - test_multiset_prop_move)(test_map_prop_move)(test_multimap_prop_move)( - test_set_no_prop_move)(test_multiset_no_prop_move)(test_map_no_prop_move)( - test_multimap_no_prop_move))( + ((test_set)(test_multiset)(test_map)(test_multimap)(test_set_prop_move)(test_multiset_prop_move)(test_map_prop_move)(test_multimap_prop_move)(test_set_no_prop_move)(test_multiset_no_prop_move)(test_map_no_prop_move)(test_multimap_no_prop_move))( (default_generator)(generate_collisions)(limited_range))) #endif -} +} // namespace move_tests RUN_TESTS() diff --git a/test/unordered/post_move_tests.cpp b/test/unordered/post_move_tests.cpp index e59c52c7..fd453acd 100644 --- a/test/unordered/post_move_tests.cpp +++ b/test/unordered/post_move_tests.cpp @@ -3,14 +3,14 @@ // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or move at http://www.boost.org/LICENSE_1_0.txt) -#include "../helpers/unordered.hpp" -#include "../helpers/test.hpp" -#include "../objects/test.hpp" -#include "../objects/cxx11_allocator.hpp" -#include "../helpers/random_values.hpp" -#include "../helpers/tracker.hpp" #include "../helpers/equivalent.hpp" #include "../helpers/invariants.hpp" +#include "../helpers/random_values.hpp" +#include "../helpers/test.hpp" +#include "../helpers/tracker.hpp" +#include "../helpers/unordered.hpp" +#include "../objects/cxx11_allocator.hpp" +#include "../objects/test.hpp" #include #include @@ -59,7 +59,8 @@ namespace move_tests { template T const& get_value(T const& t) { return t; } - template K const& get_value(std::pair const& kv) + template + K const& get_value(std::pair const& kv) { return kv.second; } @@ -466,8 +467,23 @@ namespace move_tests { !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) BOOST_TEST(y.empty()); BOOST_TEST(y.begin() == y.end()); + +#ifdef BOOST_UNORDERED_FOA_TESTS + { + using allocator_type = typename T::allocator_type; + using value_type = + typename boost::allocator_value_type::type; + using pointer = typename boost::allocator_pointer::type; + if (std::is_same::value) { + BOOST_TEST_EQ(y.bucket_count(), 0u); + BOOST_TEST_EQ(test::detail::tracker.count_allocations, num_allocs); + } + } +#else BOOST_TEST_EQ(y.bucket_count(), 0u); BOOST_TEST_EQ(test::detail::tracker.count_allocations, num_allocs); +#endif + #endif fps[i](y, v); @@ -520,8 +536,23 @@ namespace move_tests { !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) BOOST_TEST(y.empty()); BOOST_TEST(y.begin() == y.end()); + +#ifdef BOOST_UNORDERED_FOA_TESTS + { + using allocator_type = typename T::allocator_type; + using value_type = + typename boost::allocator_value_type::type; + using pointer = typename boost::allocator_pointer::type; + if (std::is_same::value) { + BOOST_TEST_EQ(y.bucket_count(), 0u); + BOOST_TEST_EQ(test::detail::tracker.count_allocations, num_allocs); + } + } +#else BOOST_TEST_EQ(y.bucket_count(), 0u); BOOST_TEST_EQ(test::detail::tracker.count_allocations, num_allocs); +#endif + #endif fps[i](y, v); @@ -687,7 +718,7 @@ namespace move_tests { test::cxx11_allocator, test::no_propagate_move> >* test_multimap_no_prop_move; -// clang-format off + // clang-format off UNORDERED_TEST(post_move_tests, ((test_set)(test_multiset)(test_map)(test_multimap)(test_set_prop_move)( test_multiset_prop_move)(test_map_prop_move)(test_multimap_prop_move)( @@ -696,6 +727,6 @@ namespace move_tests { (default_generator)(generate_collisions)(limited_range))) // clang-format on #endif -} +} // namespace move_tests RUN_TESTS() diff --git a/test/unordered/scary_tests.cpp b/test/unordered/scary_tests.cpp index ec1bf580..7049424e 100644 --- a/test/unordered/scary_tests.cpp +++ b/test/unordered/scary_tests.cpp @@ -216,8 +216,6 @@ template void scary_test() typename C2::const_iterator cbegin(x.cbegin()); BOOST_TEST(cbegin == x.cend()); - BOOST_TEST_EQ(x.bucket_count(), 0u); - #ifndef BOOST_UNORDERED_FOA_TESTS typename C2::local_iterator lbegin(x.begin(0)); BOOST_TEST(lbegin == x.end(0));