]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
7c673cae | 6 | #include "./containers.hpp" |
b32b8144 | 7 | |
7c673cae | 8 | #include "../helpers/invariants.hpp" |
b32b8144 FG |
9 | #include "../helpers/random_values.hpp" |
10 | #include "../helpers/tracker.hpp" | |
7c673cae FG |
11 | |
12 | #if defined(BOOST_MSVC) | |
b32b8144 FG |
13 | #pragma warning( \ |
14 | disable : 4512) // move_assignment operator could not be generated | |
7c673cae FG |
15 | #endif |
16 | ||
17 | test::seed_t initialize_seed(12847); | |
18 | ||
b32b8144 | 19 | template <class T> struct move_assign_base : public test::exception_base |
7c673cae | 20 | { |
b32b8144 FG |
21 | test::random_values<T> x_values, y_values; |
22 | T x, y; | |
7c673cae | 23 | |
11fdf7f2 TL |
24 | typedef typename T::hasher hasher; |
25 | typedef typename T::key_equal key_equal; | |
26 | typedef typename T::allocator_type allocator_type; | |
7c673cae | 27 | |
b32b8144 FG |
28 | move_assign_base(int tag1, int tag2, float mlf1 = 1.0, float mlf2 = 1.0) |
29 | : x_values(), y_values(), | |
7c673cae FG |
30 | x(0, hasher(tag1), key_equal(tag1), allocator_type(tag1)), |
31 | y(0, hasher(tag2), key_equal(tag2), allocator_type(tag2)) | |
b32b8144 FG |
32 | { |
33 | x.max_load_factor(mlf1); | |
34 | y.max_load_factor(mlf2); | |
35 | } | |
36 | ||
37 | typedef T data_type; | |
38 | T init() const { return T(x); } | |
39 | void run(T& x1) const | |
40 | { | |
41 | test::exceptions_enable disable_exceptions(false); | |
42 | T y1 = y; | |
43 | disable_exceptions.release(); | |
44 | x1 = boost::move(y1); | |
45 | ||
46 | DISABLE_EXCEPTIONS; | |
47 | test::check_container(x1, y_values); | |
48 | test::check_equivalent_keys(x1); | |
49 | } | |
50 | ||
51 | void check BOOST_PREVENT_MACRO_SUBSTITUTION(T const& x1) const | |
52 | { | |
53 | test::check_equivalent_keys(x1); | |
54 | ||
55 | // If the container is empty at the point of the exception, the | |
56 | // internal structure is hidden, this exposes it, at the cost of | |
57 | // messing up the data. | |
58 | if (x_values.size()) { | |
59 | T& x2 = const_cast<T&>(x1); | |
60 | x2.emplace(*x_values.begin()); | |
61 | test::check_equivalent_keys(x2); | |
7c673cae | 62 | } |
b32b8144 | 63 | } |
7c673cae FG |
64 | }; |
65 | ||
b32b8144 | 66 | template <class T> struct move_assign_values : move_assign_base<T> |
7c673cae | 67 | { |
b32b8144 FG |
68 | move_assign_values(unsigned int count1, unsigned int count2, int tag1, |
69 | int tag2, float mlf1 = 1.0, float mlf2 = 1.0) | |
70 | : move_assign_base<T>(tag1, tag2, mlf1, mlf2) | |
71 | { | |
72 | this->x_values.fill(count1, test::limited_range); | |
73 | this->y_values.fill(count2, test::limited_range); | |
74 | this->x.insert(this->x_values.begin(), this->x_values.end()); | |
75 | this->y.insert(this->y_values.begin(), this->y_values.end()); | |
76 | } | |
7c673cae FG |
77 | }; |
78 | ||
b32b8144 | 79 | template <class T> struct move_assign_test1 : move_assign_values<T> |
7c673cae | 80 | { |
b32b8144 | 81 | move_assign_test1() : move_assign_values<T>(0, 0, 0, 0) {} |
7c673cae FG |
82 | }; |
83 | ||
b32b8144 | 84 | template <class T> struct move_assign_test2 : move_assign_values<T> |
7c673cae | 85 | { |
b32b8144 | 86 | move_assign_test2() : move_assign_values<T>(60, 0, 0, 0) {} |
7c673cae FG |
87 | }; |
88 | ||
b32b8144 | 89 | template <class T> struct move_assign_test3 : move_assign_values<T> |
7c673cae | 90 | { |
b32b8144 | 91 | move_assign_test3() : move_assign_values<T>(0, 60, 0, 0) {} |
7c673cae FG |
92 | }; |
93 | ||
b32b8144 | 94 | template <class T> struct move_assign_test4 : move_assign_values<T> |
7c673cae | 95 | { |
b32b8144 | 96 | move_assign_test4() : move_assign_values<T>(10, 10, 1, 2) {} |
7c673cae FG |
97 | }; |
98 | ||
b32b8144 | 99 | template <class T> struct move_assign_test4a : move_assign_values<T> |
7c673cae | 100 | { |
b32b8144 | 101 | move_assign_test4a() : move_assign_values<T>(10, 100, 1, 2) {} |
7c673cae FG |
102 | }; |
103 | ||
b32b8144 | 104 | template <class T> struct move_assign_test5 : move_assign_values<T> |
7c673cae | 105 | { |
b32b8144 | 106 | move_assign_test5() : move_assign_values<T>(5, 60, 0, 0, 1.0f, 0.1f) {} |
7c673cae FG |
107 | }; |
108 | ||
b32b8144 | 109 | template <class T> struct equivalent_test1 : move_assign_base<T> |
7c673cae | 110 | { |
b32b8144 FG |
111 | equivalent_test1() : move_assign_base<T>(0, 0) |
112 | { | |
113 | test::random_values<T> x_values2(10, test::limited_range); | |
114 | this->x_values.insert(x_values2.begin(), x_values2.end()); | |
115 | this->x_values.insert(x_values2.begin(), x_values2.end()); | |
116 | test::random_values<T> y_values2(10, test::limited_range); | |
117 | this->y_values.insert(y_values2.begin(), y_values2.end()); | |
118 | this->y_values.insert(y_values2.begin(), y_values2.end()); | |
119 | this->x.insert(this->x_values.begin(), this->x_values.end()); | |
120 | this->y.insert(this->y_values.begin(), this->y_values.end()); | |
121 | } | |
7c673cae FG |
122 | }; |
123 | ||
b32b8144 | 124 | // clang-format off |
7c673cae | 125 | EXCEPTION_TESTS( |
b32b8144 FG |
126 | (move_assign_test1)(move_assign_test2)(move_assign_test3) |
127 | (move_assign_test4)(move_assign_test4a)(move_assign_test5) | |
128 | (equivalent_test1), | |
129 | CONTAINER_SEQ) | |
130 | // clang-format on | |
131 | ||
7c673cae | 132 | RUN_TESTS() |