• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 // Copyright 2006-2009 Daniel James.
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #include "./containers.hpp"
7 
8 #include "../helpers/input_iterator.hpp"
9 #include "../helpers/invariants.hpp"
10 #include "../helpers/random_values.hpp"
11 #include "../helpers/tracker.hpp"
12 
avoid_unused_warning(T const &)13 template <typename T> inline void avoid_unused_warning(T const&) {}
14 
15 test::seed_t initialize_seed(91274);
16 
17 struct objects
18 {
19   test::exception::object obj;
20   test::exception::hash hash;
21   test::exception::equal_to equal_to;
22   test::exception::allocator<test::exception::object> allocator;
23 };
24 
25 template <class T> struct construct_test1 : public objects, test::exception_base
26 {
runconstruct_test127   void run() const
28   {
29     T x;
30 
31     DISABLE_EXCEPTIONS;
32     BOOST_TEST(x.empty());
33     test::check_equivalent_keys(x);
34   }
35 };
36 
37 template <class T> struct construct_test2 : public objects, test::exception_base
38 {
runconstruct_test239   void run() const
40   {
41     T x(300);
42 
43     DISABLE_EXCEPTIONS;
44     BOOST_TEST(x.empty());
45     test::check_equivalent_keys(x);
46   }
47 };
48 
49 template <class T> struct construct_test3 : public objects, test::exception_base
50 {
runconstruct_test351   void run() const
52   {
53     T x(0, hash);
54 
55     DISABLE_EXCEPTIONS;
56     BOOST_TEST(x.empty());
57     test::check_equivalent_keys(x);
58   }
59 };
60 
61 template <class T> struct construct_test4 : public objects, test::exception_base
62 {
runconstruct_test463   void run() const
64   {
65     T x(0, hash, equal_to);
66 
67     DISABLE_EXCEPTIONS;
68     BOOST_TEST(x.empty());
69     test::check_equivalent_keys(x);
70   }
71 };
72 
73 template <class T> struct construct_test5 : public objects, test::exception_base
74 {
runconstruct_test575   void run() const
76   {
77     T x(50, hash, equal_to, allocator);
78 
79     DISABLE_EXCEPTIONS;
80     BOOST_TEST(x.empty());
81     test::check_equivalent_keys(x);
82   }
83 };
84 
85 template <class T> struct construct_test6 : public objects, test::exception_base
86 {
runconstruct_test687   void run() const
88   {
89     T x(allocator);
90 
91     DISABLE_EXCEPTIONS;
92     BOOST_TEST(x.empty());
93     test::check_equivalent_keys(x);
94   }
95 };
96 
97 template <class T> struct range : public test::exception_base
98 {
99   test::random_values<T> values;
100 
rangerange101   range() : values(5, test::limited_range) {}
rangerange102   range(unsigned int count) : values(count, test::limited_range) {}
103 };
104 
105 template <class T> struct range_construct_test1 : public range<T>, objects
106 {
runrange_construct_test1107   void run() const
108   {
109     T x(this->values.begin(), this->values.end());
110 
111     DISABLE_EXCEPTIONS;
112     test::check_container(x, this->values);
113     test::check_equivalent_keys(x);
114   }
115 };
116 
117 template <class T> struct range_construct_test2 : public range<T>, objects
118 {
runrange_construct_test2119   void run() const
120   {
121     T x(this->values.begin(), this->values.end(), 0);
122 
123     DISABLE_EXCEPTIONS;
124     test::check_container(x, this->values);
125     test::check_equivalent_keys(x);
126   }
127 };
128 
129 template <class T> struct range_construct_test3 : public range<T>, objects
130 {
runrange_construct_test3131   void run() const
132   {
133     T x(this->values.begin(), this->values.end(), 0, hash);
134 
135     DISABLE_EXCEPTIONS;
136     test::check_container(x, this->values);
137     test::check_equivalent_keys(x);
138   }
139 };
140 
141 template <class T> struct range_construct_test4 : public range<T>, objects
142 {
runrange_construct_test4143   void run() const
144   {
145     T x(this->values.begin(), this->values.end(), 100, hash, equal_to);
146 
147     DISABLE_EXCEPTIONS;
148     test::check_container(x, this->values);
149     test::check_equivalent_keys(x);
150   }
151 };
152 
153 // Need to run at least one test with a fairly large number
154 // of objects in case it triggers a rehash.
155 template <class T> struct range_construct_test5 : public range<T>, objects
156 {
range_construct_test5range_construct_test5157   range_construct_test5() : range<T>(60) {}
158 
runrange_construct_test5159   void run() const
160   {
161     T x(this->values.begin(), this->values.end(), 0, hash, equal_to, allocator);
162 
163     DISABLE_EXCEPTIONS;
164     test::check_container(x, this->values);
165     test::check_equivalent_keys(x);
166   }
167 };
168 
169 template <class T> struct input_range_construct_test : public range<T>, objects
170 {
input_range_construct_testinput_range_construct_test171   input_range_construct_test() : range<T>(60) {}
172 
runinput_range_construct_test173   void run() const
174   {
175     typename test::random_values<T>::const_iterator begin =
176                                                       this->values.begin(),
177                                                     end = this->values.end();
178     T x(test::input_iterator(begin), test::input_iterator(end), 0, hash,
179       equal_to, allocator);
180 
181     DISABLE_EXCEPTIONS;
182     test::check_container(x, this->values);
183     test::check_equivalent_keys(x);
184   }
185 };
186 
187 template <class T> struct copy_range_construct_test : public range<T>, objects
188 {
copy_range_construct_testcopy_range_construct_test189   copy_range_construct_test() : range<T>(60) {}
190 
runcopy_range_construct_test191   void run() const
192   {
193     T x(test::copy_iterator(this->values.begin()),
194       test::copy_iterator(this->values.end()), 0, hash, equal_to, allocator);
195 
196     DISABLE_EXCEPTIONS;
197     test::check_container(x, this->values);
198     test::check_equivalent_keys(x);
199   }
200 };
201 
202 // clang-format off
203 EXCEPTION_TESTS(
204   (construct_test1)(construct_test2)(construct_test3)(construct_test4)
205   (construct_test5)(construct_test6)(range_construct_test1)
206   (range_construct_test2)(range_construct_test3)(range_construct_test4)
207   (range_construct_test5)(input_range_construct_test)
208   (copy_range_construct_test),
209   CONTAINER_SEQ)
210 // clang-format on
211 
212 RUN_TESTS()
213