mirror of
https://github.com/boostorg/unordered.git
synced 2025-07-29 19:07:15 +02:00
Flesh out constructor exception tests
This commit is contained in:
@ -8,8 +8,11 @@
|
||||
|
||||
using allocator_type = stateful_allocator<std::pair<raii const, raii> >;
|
||||
|
||||
using map_type = boost::unordered::concurrent_flat_map<raii, raii,
|
||||
stateful_hash, stateful_key_equal, allocator_type>;
|
||||
using hasher = stateful_hash;
|
||||
using key_equal = stateful_key_equal;
|
||||
|
||||
using map_type = boost::unordered::concurrent_flat_map<raii, raii, hasher,
|
||||
key_equal, allocator_type>;
|
||||
|
||||
namespace {
|
||||
test::seed_t initialize_seed(795610904);
|
||||
@ -32,26 +35,80 @@ namespace {
|
||||
BOOST_TEST(was_thrown);
|
||||
}
|
||||
|
||||
template <class G>
|
||||
void iterator_bucket_count_constructor(G gen, test::random_generator rg)
|
||||
template <class G> void iterator_range(G gen, test::random_generator rg)
|
||||
{
|
||||
auto values = make_random_values(1024 * 16, [&] { return gen(rg); });
|
||||
|
||||
raii::reset_counts();
|
||||
{
|
||||
raii::reset_counts();
|
||||
|
||||
bool was_thrown = false;
|
||||
bool was_thrown = false;
|
||||
|
||||
enable_exceptions();
|
||||
try {
|
||||
map_type x(values.begin(), values.end(), 0, stateful_hash(1),
|
||||
stateful_key_equal(2), allocator_type(3));
|
||||
} catch (...) {
|
||||
was_thrown = true;
|
||||
enable_exceptions();
|
||||
try {
|
||||
map_type x(values.begin(), values.end(), 0, hasher(1), key_equal(2),
|
||||
allocator_type(3));
|
||||
} catch (...) {
|
||||
was_thrown = true;
|
||||
}
|
||||
disable_exceptions();
|
||||
|
||||
BOOST_TEST(was_thrown);
|
||||
check_raii_counts();
|
||||
}
|
||||
disable_exceptions();
|
||||
|
||||
BOOST_TEST(was_thrown);
|
||||
check_raii_counts();
|
||||
{
|
||||
raii::reset_counts();
|
||||
|
||||
bool was_thrown = false;
|
||||
|
||||
enable_exceptions();
|
||||
try {
|
||||
map_type x(values.begin(), values.end(), allocator_type(3));
|
||||
} catch (...) {
|
||||
was_thrown = true;
|
||||
}
|
||||
disable_exceptions();
|
||||
|
||||
BOOST_TEST(was_thrown);
|
||||
check_raii_counts();
|
||||
}
|
||||
|
||||
{
|
||||
raii::reset_counts();
|
||||
|
||||
bool was_thrown = false;
|
||||
|
||||
enable_exceptions();
|
||||
try {
|
||||
map_type x(
|
||||
values.begin(), values.end(), values.size(), allocator_type(3));
|
||||
} catch (...) {
|
||||
was_thrown = true;
|
||||
}
|
||||
disable_exceptions();
|
||||
|
||||
BOOST_TEST(was_thrown);
|
||||
check_raii_counts();
|
||||
}
|
||||
|
||||
{
|
||||
raii::reset_counts();
|
||||
|
||||
bool was_thrown = false;
|
||||
|
||||
enable_exceptions();
|
||||
try {
|
||||
map_type x(values.begin(), values.end(), values.size(), hasher(1),
|
||||
allocator_type(3));
|
||||
} catch (...) {
|
||||
was_thrown = true;
|
||||
}
|
||||
disable_exceptions();
|
||||
|
||||
BOOST_TEST(was_thrown);
|
||||
check_raii_counts();
|
||||
}
|
||||
}
|
||||
|
||||
template <class G> void copy_constructor(G gen, test::random_generator rg)
|
||||
@ -141,6 +198,107 @@ namespace {
|
||||
check_raii_counts();
|
||||
}
|
||||
}
|
||||
|
||||
UNORDERED_AUTO_TEST (initializer_list_bucket_count) {
|
||||
using value_type = typename map_type::value_type;
|
||||
|
||||
std::initializer_list<value_type> values{
|
||||
value_type{raii{0}, raii{0}},
|
||||
value_type{raii{1}, raii{1}},
|
||||
value_type{raii{2}, raii{2}},
|
||||
value_type{raii{3}, raii{3}},
|
||||
value_type{raii{4}, raii{4}},
|
||||
value_type{raii{5}, raii{5}},
|
||||
value_type{raii{6}, raii{6}},
|
||||
value_type{raii{6}, raii{6}},
|
||||
value_type{raii{7}, raii{7}},
|
||||
value_type{raii{8}, raii{8}},
|
||||
value_type{raii{9}, raii{9}},
|
||||
value_type{raii{10}, raii{10}},
|
||||
value_type{raii{9}, raii{9}},
|
||||
value_type{raii{8}, raii{8}},
|
||||
value_type{raii{7}, raii{7}},
|
||||
value_type{raii{6}, raii{6}},
|
||||
value_type{raii{5}, raii{5}},
|
||||
value_type{raii{4}, raii{4}},
|
||||
value_type{raii{3}, raii{3}},
|
||||
value_type{raii{2}, raii{2}},
|
||||
value_type{raii{1}, raii{1}},
|
||||
value_type{raii{0}, raii{0}},
|
||||
};
|
||||
|
||||
{
|
||||
raii::reset_counts();
|
||||
unsigned num_throws = 0;
|
||||
|
||||
enable_exceptions();
|
||||
for (std::size_t i = 0; i < throw_threshold; ++i) {
|
||||
try {
|
||||
map_type x(values, 0, hasher(1), key_equal(2), allocator_type(3));
|
||||
} catch (...) {
|
||||
++num_throws;
|
||||
}
|
||||
}
|
||||
disable_exceptions();
|
||||
|
||||
BOOST_TEST_GT(num_throws, 0u);
|
||||
check_raii_counts();
|
||||
}
|
||||
|
||||
{
|
||||
raii::reset_counts();
|
||||
unsigned num_throws = 0;
|
||||
|
||||
enable_exceptions();
|
||||
for (std::size_t i = 0; i < alloc_throw_threshold * 2; ++i) {
|
||||
try {
|
||||
map_type x(values, allocator_type(3));
|
||||
} catch (...) {
|
||||
++num_throws;
|
||||
}
|
||||
}
|
||||
disable_exceptions();
|
||||
|
||||
BOOST_TEST_GT(num_throws, 0u);
|
||||
check_raii_counts();
|
||||
}
|
||||
|
||||
{
|
||||
raii::reset_counts();
|
||||
unsigned num_throws = 0;
|
||||
|
||||
enable_exceptions();
|
||||
for (std::size_t i = 0; i < alloc_throw_threshold * 2; ++i) {
|
||||
try {
|
||||
map_type x(values, values.size() * 2, allocator_type(3));
|
||||
} catch (...) {
|
||||
++num_throws;
|
||||
}
|
||||
}
|
||||
disable_exceptions();
|
||||
|
||||
BOOST_TEST_GT(num_throws, 0u);
|
||||
check_raii_counts();
|
||||
}
|
||||
|
||||
{
|
||||
raii::reset_counts();
|
||||
unsigned num_throws = 0;
|
||||
|
||||
enable_exceptions();
|
||||
for (std::size_t i = 0; i < throw_threshold; ++i) {
|
||||
try {
|
||||
map_type x(values, values.size() * 2, hasher(1), allocator_type(3));
|
||||
} catch (...) {
|
||||
++num_throws;
|
||||
}
|
||||
}
|
||||
disable_exceptions();
|
||||
|
||||
BOOST_TEST_GT(num_throws, 0u);
|
||||
check_raii_counts();
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
using test::default_generator;
|
||||
@ -149,7 +307,7 @@ using test::sequential;
|
||||
|
||||
// clang-format off
|
||||
UNORDERED_TEST(
|
||||
iterator_bucket_count_constructor,
|
||||
iterator_range,
|
||||
((exception_value_type_generator))
|
||||
((default_generator)(sequential)(limited_range)))
|
||||
|
||||
@ -158,11 +316,6 @@ UNORDERED_TEST(
|
||||
((exception_value_type_generator))
|
||||
((default_generator)(sequential)))
|
||||
|
||||
UNORDERED_TEST(
|
||||
iterator_range_allocator_constructor,
|
||||
((exception_value_type_generator))
|
||||
((default_generator)(sequential)(limited_range)))
|
||||
|
||||
UNORDERED_TEST(
|
||||
move_constructor,
|
||||
((exception_value_type_generator))
|
||||
|
Reference in New Issue
Block a user