copy_exception_tests.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // Copyright 2006-2009 Daniel James.
  2. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include "./containers.hpp"
  5. #include "../helpers/invariants.hpp"
  6. #include "../helpers/random_values.hpp"
  7. #include "../helpers/tracker.hpp"
  8. template <typename T> inline void avoid_unused_warning(T const&) {}
  9. test::seed_t initialize_seed(73041);
  10. template <class T> struct copy_test1 : public test::exception_base
  11. {
  12. T x;
  13. void run() const
  14. {
  15. T y(x);
  16. DISABLE_EXCEPTIONS;
  17. BOOST_TEST(y.empty());
  18. test::check_equivalent_keys(y);
  19. }
  20. };
  21. template <class T> struct copy_test2 : public test::exception_base
  22. {
  23. test::random_values<T> values;
  24. T x;
  25. copy_test2() : values(5, test::limited_range), x(values.begin(), values.end())
  26. {
  27. }
  28. void run() const
  29. {
  30. T y(x);
  31. DISABLE_EXCEPTIONS;
  32. test::check_container(y, this->values);
  33. test::check_equivalent_keys(y);
  34. }
  35. };
  36. template <class T> struct copy_test3 : public test::exception_base
  37. {
  38. test::random_values<T> values;
  39. T x;
  40. copy_test3() : values(100), x(values.begin(), values.end()) {}
  41. void run() const
  42. {
  43. T y(x);
  44. DISABLE_EXCEPTIONS;
  45. test::check_container(y, this->values);
  46. test::check_equivalent_keys(y);
  47. }
  48. };
  49. template <class T> struct copy_test3a : public test::exception_base
  50. {
  51. test::random_values<T> values;
  52. T x;
  53. copy_test3a()
  54. : values(100, test::limited_range), x(values.begin(), values.end())
  55. {
  56. }
  57. void run() const
  58. {
  59. T y(x);
  60. DISABLE_EXCEPTIONS;
  61. test::check_container(y, this->values);
  62. test::check_equivalent_keys(y);
  63. }
  64. };
  65. template <class T> struct copy_with_allocator_test : public test::exception_base
  66. {
  67. test::random_values<T> values;
  68. T x;
  69. test::exception::allocator<test::exception::object> allocator;
  70. copy_with_allocator_test() : values(100), x(values.begin(), values.end()) {}
  71. void run() const
  72. {
  73. T y(x, allocator);
  74. DISABLE_EXCEPTIONS;
  75. test::check_container(y, this->values);
  76. test::check_equivalent_keys(y);
  77. }
  78. };
  79. // clang-format off
  80. EXCEPTION_TESTS(
  81. (copy_test1)(copy_test2)(copy_test3)(copy_test3a)(copy_with_allocator_test),
  82. CONTAINER_SEQ)
  83. // clang-format on
  84. RUN_TESTS()