forked from boostorg/unordered
Unordered: Fix some portability issues in tests.
- Simplify mechanism for detecting traits of test allocators. There were some portability issues, but rather than fix them I've just gone for a simpler mechanism. Does mean that the relevant tests can't be run for other allocators. - Fix a couple of unnecessary_copy_tests, whose results were the wrong way round. - It appears that Visual C++ only implements RVO for implicitly defined copy constructors in debug mode, so adjust a move_test to account for the extra copies now that the copy constructors are explicitly defined. [SVN r73798]
This commit is contained in:
@@ -99,7 +99,7 @@ void assign_tests2(T*,
|
||||
x2 = x1;
|
||||
BOOST_TEST(test::equivalent(x2.hash_function(), hf1));
|
||||
BOOST_TEST(test::equivalent(x2.key_eq(), eq1));
|
||||
if (test::is_propagate_on_assign<allocator_type>::value) {
|
||||
if (allocator_type::is_propagate_on_assign) {
|
||||
BOOST_TEST(test::equivalent(x2.get_allocator(), al1));
|
||||
BOOST_TEST(!test::equivalent(x2.get_allocator(), al2));
|
||||
}
|
||||
@@ -161,6 +161,19 @@ boost::unordered_multimap<test::object, test::object,
|
||||
using test::default_generator;
|
||||
using test::generate_collisions;
|
||||
|
||||
template <typename T>
|
||||
bool is_propagate(T*)
|
||||
{
|
||||
return T::allocator_type::is_propagate_on_assign;
|
||||
}
|
||||
|
||||
UNORDERED_AUTO_TEST(check_traits)
|
||||
{
|
||||
BOOST_TEST(!is_propagate(test_set));
|
||||
BOOST_TEST(is_propagate(test_set_prop_assign));
|
||||
BOOST_TEST(!is_propagate(test_set_no_prop_assign));
|
||||
}
|
||||
|
||||
UNORDERED_TEST(assign_tests1, (
|
||||
(test_set)(test_multiset)(test_map)(test_multimap)
|
||||
(test_set_prop_assign)(test_multiset_prop_assign)(test_map_prop_assign)(test_multimap_prop_assign)
|
||||
|
||||
@@ -41,7 +41,7 @@ void copy_construct_tests1(T*,
|
||||
BOOST_TEST(test::equivalent(y.get_allocator(), al));
|
||||
BOOST_TEST(x.max_load_factor() == y.max_load_factor());
|
||||
BOOST_TEST(test::selected_count(y.get_allocator()) ==
|
||||
(test::is_select_on_copy<allocator_type>::value ? 1 : 0));
|
||||
(allocator_type::is_select_on_copy));
|
||||
test::check_equivalent_keys(y);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ void copy_construct_tests1(T*,
|
||||
test::unordered_equivalence_tester<T> equivalent(x);
|
||||
BOOST_TEST(equivalent(y));
|
||||
BOOST_TEST(test::selected_count(y.get_allocator()) ==
|
||||
(test::is_select_on_copy<allocator_type>::value ? 1 : 0));
|
||||
(allocator_type::is_select_on_copy));
|
||||
test::check_equivalent_keys(y);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ void copy_construct_tests1(T*,
|
||||
// This isn't guaranteed:
|
||||
BOOST_TEST(y.load_factor() < y.max_load_factor());
|
||||
BOOST_TEST(test::selected_count(y.get_allocator()) ==
|
||||
(test::is_select_on_copy<allocator_type>::value ? 1 : 0));
|
||||
(allocator_type::is_select_on_copy));
|
||||
test::check_equivalent_keys(y);
|
||||
}
|
||||
}
|
||||
@@ -104,7 +104,7 @@ void copy_construct_tests2(T* ptr,
|
||||
BOOST_TEST(test::equivalent(y.get_allocator(), al));
|
||||
BOOST_TEST(x.max_load_factor() == y.max_load_factor());
|
||||
BOOST_TEST(test::selected_count(y.get_allocator()) ==
|
||||
(test::is_select_on_copy<allocator_type>::value ? 1 : 0));
|
||||
(allocator_type::is_select_on_copy));
|
||||
test::check_equivalent_keys(y);
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ void copy_construct_tests2(T* ptr,
|
||||
BOOST_TEST(equivalent(y));
|
||||
test::check_equivalent_keys(y);
|
||||
BOOST_TEST(test::selected_count(y.get_allocator()) ==
|
||||
(test::is_select_on_copy<allocator_type>::value ? 1 : 0));
|
||||
(allocator_type::is_select_on_copy));
|
||||
BOOST_TEST(test::equivalent(y.get_allocator(), al));
|
||||
}
|
||||
|
||||
|
||||
@@ -153,11 +153,16 @@ namespace move_tests
|
||||
T y(create(v, count, hf, eq, al, 1.0), al);
|
||||
#if !defined(BOOST_NO_RVALUE_REFERENCES)
|
||||
BOOST_TEST(count == test::global_object_count);
|
||||
#else
|
||||
#elif defined(BOOST_HAS_NRVO)
|
||||
BOOST_TEST(
|
||||
test::global_object_count.constructions - count.constructions <=
|
||||
(test::is_map<T>::value ? 50 : 25));
|
||||
BOOST_TEST(count.instances == test::global_object_count.instances);
|
||||
#else
|
||||
BOOST_TEST(
|
||||
test::global_object_count.constructions - count.constructions <=
|
||||
(test::is_map<T>::value ? 100 : 50));
|
||||
BOOST_TEST(count.instances == test::global_object_count.instances);
|
||||
#endif
|
||||
test::check_container(y, v);
|
||||
BOOST_TEST(test::equivalent(y.hash_function(), hf));
|
||||
@@ -188,7 +193,7 @@ namespace move_tests
|
||||
test::check_container(y, v2);
|
||||
test::check_equivalent_keys(y);
|
||||
BOOST_TEST(y.max_load_factor() == 2.0);
|
||||
if (test::is_propagate_on_move<allocator_type>::value) {
|
||||
if (allocator_type::is_propagate_on_move) {
|
||||
BOOST_TEST(test::equivalent(y.get_allocator(), al2));
|
||||
}
|
||||
else {
|
||||
@@ -202,14 +207,14 @@ namespace move_tests
|
||||
T y(0, hf, eq, al1);
|
||||
y = create(v, count, hf, eq, al2, 0.5);
|
||||
#if defined(BOOST_HAS_NRVO)
|
||||
if (test::is_propagate_on_move<allocator_type>::value) {
|
||||
if (allocator_type::is_propagate_on_move) {
|
||||
BOOST_TEST(count == test::global_object_count);
|
||||
}
|
||||
#endif
|
||||
test::check_container(y, v);
|
||||
test::check_equivalent_keys(y);
|
||||
BOOST_TEST(y.max_load_factor() == 0.5);
|
||||
if (test::is_propagate_on_move<allocator_type>::value) {
|
||||
if (allocator_type::is_propagate_on_move) {
|
||||
BOOST_TEST(test::equivalent(y.get_allocator(), al2));
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -113,14 +113,14 @@ void swap_tests2(X* ptr = 0,
|
||||
|
||||
{
|
||||
test::force_equal_allocator force_(
|
||||
!test::is_propagate_on_swap<allocator_type>::value);
|
||||
!allocator_type::is_propagate_on_swap);
|
||||
test::check_instances check_;
|
||||
|
||||
test::random_values<X> vx(50, generator), vy(100, generator);
|
||||
X x(vx.begin(), vx.end(), 0, hasher(), key_equal(), allocator_type(1));
|
||||
X y(vy.begin(), vy.end(), 0, hasher(), key_equal(), allocator_type(2));
|
||||
|
||||
if (test::is_propagate_on_swap<allocator_type>::value ||
|
||||
if (allocator_type::is_propagate_on_swap ||
|
||||
x.get_allocator() == y.get_allocator())
|
||||
{
|
||||
swap_test_impl(x, y);
|
||||
@@ -129,7 +129,7 @@ void swap_tests2(X* ptr = 0,
|
||||
|
||||
{
|
||||
test::force_equal_allocator force_(
|
||||
!test::is_propagate_on_swap<allocator_type>::value);
|
||||
!allocator_type::is_propagate_on_swap);
|
||||
test::check_instances check_;
|
||||
|
||||
test::random_values<X> vx(100, generator), vy(100, generator);
|
||||
@@ -138,7 +138,7 @@ void swap_tests2(X* ptr = 0,
|
||||
X y(vy.begin(), vy.end(), 0, hasher(2), key_equal(2),
|
||||
allocator_type(2));
|
||||
|
||||
if (test::is_propagate_on_swap<allocator_type>::value ||
|
||||
if (allocator_type::is_propagate_on_swap ||
|
||||
x.get_allocator() == y.get_allocator())
|
||||
{
|
||||
swap_test_impl(x, y);
|
||||
@@ -194,6 +194,19 @@ boost::unordered_multimap<test::object, test::object,
|
||||
test::cxx11_allocator<test::object, test::no_propagate_swap> >*
|
||||
test_multimap_no_prop_swap;
|
||||
|
||||
template <typename T>
|
||||
bool is_propagate(T*)
|
||||
{
|
||||
return T::allocator_type::is_propagate_on_swap;
|
||||
}
|
||||
|
||||
UNORDERED_AUTO_TEST(check_traits)
|
||||
{
|
||||
BOOST_TEST(!is_propagate(test_set));
|
||||
BOOST_TEST(is_propagate(test_set_prop_swap));
|
||||
BOOST_TEST(!is_propagate(test_set_no_prop_swap));
|
||||
}
|
||||
|
||||
UNORDERED_TEST(swap_tests1, (
|
||||
(test_set)(test_multiset)(test_map)(test_multimap)
|
||||
(test_set_prop_swap)(test_multiset_prop_swap)(test_map_prop_swap)(test_multimap_prop_swap)
|
||||
|
||||
@@ -201,9 +201,9 @@ namespace unnecessary_copy_tests
|
||||
COPY_COUNT(1); MOVE_COUNT(0);
|
||||
x.emplace(boost::move(a));
|
||||
#if defined(BOOST_NO_RVALUE_REFERENCES)
|
||||
COPY_COUNT(1); MOVE_COUNT(1);
|
||||
#else
|
||||
COPY_COUNT(2); MOVE_COUNT(0);
|
||||
#else
|
||||
COPY_COUNT(1); MOVE_COUNT(1);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -227,11 +227,11 @@ namespace unnecessary_copy_tests
|
||||
reset();
|
||||
x.emplace();
|
||||
#if defined(BOOST_UNORDERED_STD_FORWARD_MOVE)
|
||||
COPY_COUNT(1); MOVE_COUNT(0);
|
||||
#else
|
||||
// TODO: I think that in this case the move could be delayed until
|
||||
// after checking for a collision, giving MOVE_COUNT(0).
|
||||
COPY_COUNT(1); MOVE_COUNT(1);
|
||||
#else
|
||||
COPY_COUNT(1); MOVE_COUNT(0);
|
||||
#endif
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user