constructor_exception_tests.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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/input_iterator.hpp"
  6. #include "../helpers/invariants.hpp"
  7. #include "../helpers/random_values.hpp"
  8. #include "../helpers/tracker.hpp"
  9. template <typename T> inline void avoid_unused_warning(T const&) {}
  10. test::seed_t initialize_seed(91274);
  11. struct objects
  12. {
  13. test::exception::object obj;
  14. test::exception::hash hash;
  15. test::exception::equal_to equal_to;
  16. test::exception::allocator<test::exception::object> allocator;
  17. };
  18. template <class T> struct construct_test1 : public objects, test::exception_base
  19. {
  20. void run() const
  21. {
  22. T x;
  23. DISABLE_EXCEPTIONS;
  24. BOOST_TEST(x.empty());
  25. test::check_equivalent_keys(x);
  26. }
  27. };
  28. template <class T> struct construct_test2 : public objects, test::exception_base
  29. {
  30. void run() const
  31. {
  32. T x(300);
  33. DISABLE_EXCEPTIONS;
  34. BOOST_TEST(x.empty());
  35. test::check_equivalent_keys(x);
  36. }
  37. };
  38. template <class T> struct construct_test3 : public objects, test::exception_base
  39. {
  40. void run() const
  41. {
  42. T x(0, hash);
  43. DISABLE_EXCEPTIONS;
  44. BOOST_TEST(x.empty());
  45. test::check_equivalent_keys(x);
  46. }
  47. };
  48. template <class T> struct construct_test4 : public objects, test::exception_base
  49. {
  50. void run() const
  51. {
  52. T x(0, hash, equal_to);
  53. DISABLE_EXCEPTIONS;
  54. BOOST_TEST(x.empty());
  55. test::check_equivalent_keys(x);
  56. }
  57. };
  58. template <class T> struct construct_test5 : public objects, test::exception_base
  59. {
  60. void run() const
  61. {
  62. T x(50, hash, equal_to, allocator);
  63. DISABLE_EXCEPTIONS;
  64. BOOST_TEST(x.empty());
  65. test::check_equivalent_keys(x);
  66. }
  67. };
  68. template <class T> struct construct_test6 : public objects, test::exception_base
  69. {
  70. void run() const
  71. {
  72. T x(allocator);
  73. DISABLE_EXCEPTIONS;
  74. BOOST_TEST(x.empty());
  75. test::check_equivalent_keys(x);
  76. }
  77. };
  78. template <class T> struct range : public test::exception_base
  79. {
  80. test::random_values<T> values;
  81. range() : values(5, test::limited_range) {}
  82. range(unsigned int count) : values(count, test::limited_range) {}
  83. };
  84. template <class T> struct range_construct_test1 : public range<T>, objects
  85. {
  86. void run() const
  87. {
  88. T x(this->values.begin(), this->values.end());
  89. DISABLE_EXCEPTIONS;
  90. test::check_container(x, this->values);
  91. test::check_equivalent_keys(x);
  92. }
  93. };
  94. template <class T> struct range_construct_test2 : public range<T>, objects
  95. {
  96. void run() const
  97. {
  98. T x(this->values.begin(), this->values.end(), 0);
  99. DISABLE_EXCEPTIONS;
  100. test::check_container(x, this->values);
  101. test::check_equivalent_keys(x);
  102. }
  103. };
  104. template <class T> struct range_construct_test3 : public range<T>, objects
  105. {
  106. void run() const
  107. {
  108. T x(this->values.begin(), this->values.end(), 0, hash);
  109. DISABLE_EXCEPTIONS;
  110. test::check_container(x, this->values);
  111. test::check_equivalent_keys(x);
  112. }
  113. };
  114. template <class T> struct range_construct_test4 : public range<T>, objects
  115. {
  116. void run() const
  117. {
  118. T x(this->values.begin(), this->values.end(), 100, hash, equal_to);
  119. DISABLE_EXCEPTIONS;
  120. test::check_container(x, this->values);
  121. test::check_equivalent_keys(x);
  122. }
  123. };
  124. // Need to run at least one test with a fairly large number
  125. // of objects in case it triggers a rehash.
  126. template <class T> struct range_construct_test5 : public range<T>, objects
  127. {
  128. range_construct_test5() : range<T>(60) {}
  129. void run() const
  130. {
  131. T x(this->values.begin(), this->values.end(), 0, hash, equal_to, allocator);
  132. DISABLE_EXCEPTIONS;
  133. test::check_container(x, this->values);
  134. test::check_equivalent_keys(x);
  135. }
  136. };
  137. template <class T> struct input_range_construct_test : public range<T>, objects
  138. {
  139. input_range_construct_test() : range<T>(60) {}
  140. void run() const
  141. {
  142. typename test::random_values<T>::const_iterator begin =
  143. this->values.begin(),
  144. end = this->values.end();
  145. T x(test::input_iterator(begin), test::input_iterator(end), 0, hash,
  146. equal_to, allocator);
  147. DISABLE_EXCEPTIONS;
  148. test::check_container(x, this->values);
  149. test::check_equivalent_keys(x);
  150. }
  151. };
  152. template <class T> struct copy_range_construct_test : public range<T>, objects
  153. {
  154. copy_range_construct_test() : range<T>(60) {}
  155. void run() const
  156. {
  157. T x(test::copy_iterator(this->values.begin()),
  158. test::copy_iterator(this->values.end()), 0, hash, equal_to, allocator);
  159. DISABLE_EXCEPTIONS;
  160. test::check_container(x, this->values);
  161. test::check_equivalent_keys(x);
  162. }
  163. };
  164. // clang-format off
  165. EXCEPTION_TESTS(
  166. (construct_test1)(construct_test2)(construct_test3)(construct_test4)
  167. (construct_test5)(construct_test6)(range_construct_test1)
  168. (range_construct_test2)(range_construct_test3)(range_construct_test4)
  169. (range_construct_test5)(input_range_construct_test)
  170. (copy_range_construct_test),
  171. CONTAINER_SEQ)
  172. // clang-format on
  173. RUN_TESTS()