Skip to content

Commit

Permalink
Fix test_extreme_bucket_count_value_construction test on some platforms
Browse files Browse the repository at this point in the history
Both std::bad_alloc or std::length_error excpetions can be thrown depending on the platform memory overcommit behaviour and total memory
  • Loading branch information
Tessil committed Apr 17, 2022
1 parent 0c3c858 commit 59a3b7d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
23 changes: 13 additions & 10 deletions tests/robin_map_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,41 +745,44 @@ BOOST_AUTO_TEST_CASE(test_modify_value_through_iterator_with_const_qualifier) {
/**
* constructor
*/

BOOST_AUTO_TEST_CASE(test_extreme_bucket_count_value_construction) {
TSL_RH_CHECK_THROW(
// std::bad_alloc or std::length_error will be thrown depending on the
// platform overcommit
TSL_RH_CHECK_THROW_EITHER(
(tsl::robin_map<int, int, std::hash<int>, std::equal_to<int>,
std::allocator<std::pair<int, int>>, false,
tsl::rh::power_of_two_growth_policy<2>>(
std::numeric_limits<std::size_t>::max())),
std::length_error);
std::bad_alloc, std::length_error);

TSL_RH_CHECK_THROW(
TSL_RH_CHECK_THROW_EITHER(
(tsl::robin_map<int, int, std::hash<int>, std::equal_to<int>,
std::allocator<std::pair<int, int>>, false,
tsl::rh::power_of_two_growth_policy<2>>(
std::numeric_limits<std::size_t>::max() / 2 + 1)),
std::length_error);
std::bad_alloc, std::length_error);

TSL_RH_CHECK_THROW(
TSL_RH_CHECK_THROW_EITHER(
(tsl::robin_map<int, int, std::hash<int>, std::equal_to<int>,
std::allocator<std::pair<int, int>>, false,
tsl::rh::prime_growth_policy>(
std::numeric_limits<std::size_t>::max())),
std::length_error);
std::bad_alloc, std::length_error);

TSL_RH_CHECK_THROW(
TSL_RH_CHECK_THROW_EITHER(
(tsl::robin_map<int, int, std::hash<int>, std::equal_to<int>,
std::allocator<std::pair<int, int>>, false,
tsl::rh::prime_growth_policy>(
std::numeric_limits<std::size_t>::max() / 2)),
std::length_error);
std::bad_alloc, std::length_error);

TSL_RH_CHECK_THROW(
TSL_RH_CHECK_THROW_EITHER(
(tsl::robin_map<int, int, std::hash<int>, std::equal_to<int>,
std::allocator<std::pair<int, int>>, false,
tsl::rh::mod_growth_policy<>>(
std::numeric_limits<std::size_t>::max())),
std::length_error);
std::bad_alloc, std::length_error);
}

BOOST_AUTO_TEST_CASE(test_range_construct) {
Expand Down
10 changes: 10 additions & 0 deletions tests/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,18 @@

#ifdef TSL_RH_NO_EXCEPTIONS
#define TSL_RH_CHECK_THROW(S, E)
#define TSL_RH_CHECK_THROW_EITHER(S, E1, E2)
#else
#define TSL_RH_CHECK_THROW(S, E) BOOST_CHECK_THROW(S, E)
#define TSL_RH_CHECK_THROW_EITHER(S, E1, E2) \
do { \
try { \
S; \
BOOST_CHECK(false); \
} catch (const E1&) { \
} catch (const E2&) { \
} \
} while (0)
#endif

template <typename T>
Expand Down

0 comments on commit 59a3b7d

Please sign in to comment.