From 0489069419bc96f7d86a857cdc654baecd706c3b Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sat, 6 May 2017 04:47:59 +0100 Subject: [PATCH] Use 'limited_range' to catch error in exception tests This would have caught the error fixed in 3fe259a79e5. --- test/exception/assign_exception_tests.cpp | 44 +++++++++++++++---- .../exception/constructor_exception_tests.cpp | 4 +- test/exception/copy_exception_tests.cpp | 31 ++++++++++++- test/exception/erase_exception_tests.cpp | 4 +- .../exception/move_assign_exception_tests.cpp | 8 ++-- test/exception/rehash_exception_tests.cpp | 2 +- test/exception/swap_exception_tests.cpp | 7 ++- 7 files changed, 80 insertions(+), 20 deletions(-) diff --git a/test/exception/assign_exception_tests.cpp b/test/exception/assign_exception_tests.cpp index b6b580ad..cad7fb35 100644 --- a/test/exception/assign_exception_tests.cpp +++ b/test/exception/assign_exception_tests.cpp @@ -18,7 +18,9 @@ test::seed_t initialize_seed(12847); template struct self_assign_base : public test::exception_base { test::random_values values; - self_assign_base(std::size_t count = 0) : values(count) {} + self_assign_base(std::size_t count = 0) : values(count, test::limited_range) + { + } typedef T data_type; T init() const { return T(values.begin(), values.end()); } @@ -95,11 +97,12 @@ template struct assign_base : public test::exception_base template struct assign_values : assign_base { assign_values(unsigned int count1, unsigned int count2, int tag1, int tag2, - float mlf1 = 1.0, float mlf2 = 1.0) + test::random_generator gen = test::default_generator, float mlf1 = 1.0, + float mlf2 = 1.0) : assign_base(tag1, tag2, mlf1, mlf2) { - this->x_values.fill(count1); - this->y_values.fill(count2); + this->x_values.fill(count1, gen); + this->y_values.fill(count2, gen); this->x.insert(this->x_values.begin(), this->x_values.end()); this->y.insert(this->y_values.begin(), this->y_values.end()); } @@ -115,11 +118,21 @@ template struct assign_test2 : assign_values assign_test2() : assign_values(60, 0, 0, 0) {} }; +template struct assign_test2a : assign_values +{ + assign_test2a() : assign_values(60, 0, 0, 0, test::limited_range) {} +}; + template struct assign_test3 : assign_values { assign_test3() : assign_values(0, 60, 0, 0) {} }; +template struct assign_test3a : assign_values +{ + assign_test3a() : assign_values(0, 60, 0, 0, test::limited_range) {} +}; + template struct assign_test4 : assign_values { assign_test4() : assign_values(10, 10, 1, 2) {} @@ -130,9 +143,17 @@ template struct assign_test4a : assign_values assign_test4a() : assign_values(10, 100, 1, 2) {} }; +template struct assign_test4b : assign_values +{ + assign_test4b() : assign_values(10, 100, 1, 2, test::limited_range) {} +}; + template struct assign_test5 : assign_values { - assign_test5() : assign_values(5, 60, 0, 0, 1.0f, 0.1f) {} + assign_test5() + : assign_values(5, 60, 0, 0, test::default_generator, 1.0f, 0.1f) + { + } }; template struct equivalent_test1 : assign_base @@ -150,8 +171,15 @@ template struct equivalent_test1 : assign_base } }; -EXCEPTION_TESTS_REPEAT(5, (self_assign_test1)(self_assign_test2)(assign_test1)( - assign_test2)(assign_test3)(assign_test4)( - assign_test4a)(assign_test5)(equivalent_test1), +// clang-format off +EXCEPTION_TESTS_REPEAT(5, + (self_assign_test1)(self_assign_test2) + (assign_test1)(assign_test2)(assign_test2a) + (assign_test3)(assign_test3a) + (assign_test4)(assign_test4a)(assign_test4b) + (assign_test5) + (equivalent_test1), CONTAINER_SEQ) +// clang-format on + RUN_TESTS() diff --git a/test/exception/constructor_exception_tests.cpp b/test/exception/constructor_exception_tests.cpp index 503cce0e..39468054 100644 --- a/test/exception/constructor_exception_tests.cpp +++ b/test/exception/constructor_exception_tests.cpp @@ -98,8 +98,8 @@ template struct range : public test::exception_base { test::random_values values; - range() : values(5) {} - range(unsigned int count) : values(count) {} + range() : values(5, test::limited_range) {} + range(unsigned int count) : values(count, test::limited_range) {} }; template struct range_construct_test1 : public range, objects diff --git a/test/exception/copy_exception_tests.cpp b/test/exception/copy_exception_tests.cpp index 1e57872c..ba6b2bcf 100644 --- a/test/exception/copy_exception_tests.cpp +++ b/test/exception/copy_exception_tests.cpp @@ -32,7 +32,10 @@ template struct copy_test2 : public test::exception_base test::random_values values; T x; - copy_test2() : values(5), x(values.begin(), values.end()) {} + copy_test2() + : values(5, test::limited_range), x(values.begin(), values.end()) + { + } void run() const { @@ -61,6 +64,26 @@ template struct copy_test3 : public test::exception_base } }; +template struct copy_test3a : public test::exception_base +{ + test::random_values values; + T x; + + copy_test3a() + : values(100, test::limited_range), x(values.begin(), values.end()) + { + } + + void run() const + { + T y(x); + + DISABLE_EXCEPTIONS; + test::check_container(y, this->values); + test::check_equivalent_keys(y); + } +}; + template struct copy_with_allocator_test : public test::exception_base { test::random_values values; @@ -79,6 +102,10 @@ template struct copy_with_allocator_test : public test::exception_base } }; -EXCEPTION_TESTS((copy_test1)(copy_test2)(copy_test3)(copy_with_allocator_test), +// clang-format off +EXCEPTION_TESTS( + (copy_test1)(copy_test2)(copy_test3)(copy_test3a)(copy_with_allocator_test), CONTAINER_SEQ) +// clang-format on + RUN_TESTS() diff --git a/test/exception/erase_exception_tests.cpp b/test/exception/erase_exception_tests.cpp index f400bdd9..93e09439 100644 --- a/test/exception/erase_exception_tests.cpp +++ b/test/exception/erase_exception_tests.cpp @@ -14,7 +14,9 @@ test::seed_t initialize_seed(835193); template struct erase_test_base : public test::exception_base { test::random_values values; - erase_test_base(unsigned int count = 5) : values(count) {} + erase_test_base(unsigned int count = 5) : values(count, test::limited_range) + { + } typedef T data_type; diff --git a/test/exception/move_assign_exception_tests.cpp b/test/exception/move_assign_exception_tests.cpp index ac0eaf1c..8e363f89 100644 --- a/test/exception/move_assign_exception_tests.cpp +++ b/test/exception/move_assign_exception_tests.cpp @@ -70,8 +70,8 @@ template struct move_assign_values : move_assign_base int tag2, float mlf1 = 1.0, float mlf2 = 1.0) : move_assign_base(tag1, tag2, mlf1, mlf2) { - this->x_values.fill(count1); - this->y_values.fill(count2); + this->x_values.fill(count1, test::limited_range); + this->y_values.fill(count2, test::limited_range); this->x.insert(this->x_values.begin(), this->x_values.end()); this->y.insert(this->y_values.begin(), this->y_values.end()); } @@ -111,10 +111,10 @@ template struct equivalent_test1 : move_assign_base { equivalent_test1() : move_assign_base(0, 0) { - test::random_values x_values2(10); + test::random_values x_values2(10, test::limited_range); this->x_values.insert(x_values2.begin(), x_values2.end()); this->x_values.insert(x_values2.begin(), x_values2.end()); - test::random_values y_values2(10); + test::random_values y_values2(10, test::limited_range); this->y_values.insert(y_values2.begin(), y_values2.end()); this->y_values.insert(y_values2.begin(), y_values2.end()); this->x.insert(this->x_values.begin(), this->x_values.end()); diff --git a/test/exception/rehash_exception_tests.cpp b/test/exception/rehash_exception_tests.cpp index 6781508b..c6355071 100644 --- a/test/exception/rehash_exception_tests.cpp +++ b/test/exception/rehash_exception_tests.cpp @@ -20,7 +20,7 @@ template struct rehash_test_base : public test::exception_base test::random_values values; unsigned int n; rehash_test_base(unsigned int count = 100, unsigned int n_ = 0) - : values(count), n(n_) + : values(count, test::limited_range), n(n_) { } diff --git a/test/exception/swap_exception_tests.cpp b/test/exception/swap_exception_tests.cpp index 341e67d5..d8b81128 100644 --- a/test/exception/swap_exception_tests.cpp +++ b/test/exception/swap_exception_tests.cpp @@ -18,7 +18,9 @@ test::seed_t initialize_seed(9387); template struct self_swap_base : public test::exception_base { test::random_values values; - self_swap_base(std::size_t count = 0) : values(count) {} + self_swap_base(std::size_t count = 0) : values(count, test::limited_range) + { + } typedef T data_type; T init() const { return T(values.begin(), values.end()); } @@ -65,7 +67,8 @@ template struct swap_base : public test::exception_base typedef BOOST_DEDUCED_TYPENAME T::allocator_type allocator_type; swap_base(unsigned int count1, unsigned int count2, int tag1, int tag2) - : x_values(count1), y_values(count2), + : x_values(count1, test::limited_range), + y_values(count2, test::limited_range), initial_x(x_values.begin(), x_values.end(), 0, hasher(tag1), key_equal(tag1), allocator_type(tag1)), initial_y(