]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/unordered/test/exception/assign_exception_tests.cpp
bump version to 12.2.12-pve1
[ceph.git] / ceph / src / boost / libs / unordered / test / exception / assign_exception_tests.cpp
CommitLineData
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
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 13#pragma warning(disable : 4512) // assignment operator could not be generated
7c673cae
FG
14#endif
15
16test::seed_t initialize_seed(12847);
17
b32b8144 18template <class T> struct self_assign_base : public test::exception_base
7c673cae 19{
b32b8144
FG
20 test::random_values<T> values;
21 self_assign_base(std::size_t count = 0) : values(count, test::limited_range)
22 {
23 }
24
25 typedef T data_type;
26 T init() const { return T(values.begin(), values.end()); }
27
28 void run(T& x) const
29 {
30 x = x;
31
32 DISABLE_EXCEPTIONS;
33 test::check_container(x, values);
34 test::check_equivalent_keys(x);
35 }
36
37 void check BOOST_PREVENT_MACRO_SUBSTITUTION(T const& x) const
38 {
39 test::check_equivalent_keys(x);
40 }
7c673cae
FG
41};
42
b32b8144
FG
43template <class T> struct self_assign_test1 : self_assign_base<T>
44{
45};
7c673cae 46
b32b8144 47template <class T> struct self_assign_test2 : self_assign_base<T>
7c673cae 48{
b32b8144 49 self_assign_test2() : self_assign_base<T>(100) {}
7c673cae
FG
50};
51
b32b8144 52template <class T> struct assign_base : public test::exception_base
7c673cae 53{
b32b8144
FG
54 test::random_values<T> x_values, y_values;
55 T x, y;
7c673cae 56
b32b8144
FG
57 typedef BOOST_DEDUCED_TYPENAME T::hasher hasher;
58 typedef BOOST_DEDUCED_TYPENAME T::key_equal key_equal;
59 typedef BOOST_DEDUCED_TYPENAME T::allocator_type allocator_type;
7c673cae 60
b32b8144
FG
61 assign_base(int tag1, int tag2, float mlf1 = 1.0, float mlf2 = 1.0)
62 : x_values(), y_values(),
7c673cae
FG
63 x(0, hasher(tag1), key_equal(tag1), allocator_type(tag1)),
64 y(0, hasher(tag2), key_equal(tag2), allocator_type(tag2))
b32b8144
FG
65 {
66 x.max_load_factor(mlf1);
67 y.max_load_factor(mlf2);
68 }
69
70 typedef T data_type;
71 T init() const { return T(x); }
72
73 void run(T& x1) const
74 {
75 x1 = y;
76
77 DISABLE_EXCEPTIONS;
78 test::check_container(x1, y_values);
79 test::check_equivalent_keys(x1);
80 }
81
82 void check BOOST_PREVENT_MACRO_SUBSTITUTION(T const& x1) const
83 {
84 test::check_equivalent_keys(x1);
85
86 // If the container is empty at the point of the exception, the
87 // internal structure is hidden, this exposes it, at the cost of
88 // messing up the data.
89 if (x_values.size()) {
90 T& x2 = const_cast<T&>(x1);
91 x2.emplace(*x_values.begin());
92 test::check_equivalent_keys(x2);
7c673cae 93 }
b32b8144
FG
94 }
95};
7c673cae 96
b32b8144
FG
97template <class T> struct assign_values : assign_base<T>
98{
99 assign_values(unsigned int count1, unsigned int count2, int tag1, int tag2,
100 test::random_generator gen = test::default_generator, float mlf1 = 1.0,
101 float mlf2 = 1.0)
102 : assign_base<T>(tag1, tag2, mlf1, mlf2)
103 {
104 this->x_values.fill(count1, gen);
105 this->y_values.fill(count2, gen);
106 this->x.insert(this->x_values.begin(), this->x_values.end());
107 this->y.insert(this->y_values.begin(), this->y_values.end());
108 }
7c673cae
FG
109};
110
b32b8144 111template <class T> struct assign_test1 : assign_values<T>
7c673cae 112{
b32b8144 113 assign_test1() : assign_values<T>(0, 0, 0, 0) {}
7c673cae
FG
114};
115
b32b8144 116template <class T> struct assign_test2 : assign_values<T>
7c673cae 117{
b32b8144 118 assign_test2() : assign_values<T>(60, 0, 0, 0) {}
7c673cae
FG
119};
120
b32b8144 121template <class T> struct assign_test2a : assign_values<T>
7c673cae 122{
b32b8144 123 assign_test2a() : assign_values<T>(60, 0, 0, 0, test::limited_range) {}
7c673cae
FG
124};
125
b32b8144 126template <class T> struct assign_test3 : assign_values<T>
7c673cae 127{
b32b8144 128 assign_test3() : assign_values<T>(0, 60, 0, 0) {}
7c673cae
FG
129};
130
b32b8144 131template <class T> struct assign_test3a : assign_values<T>
7c673cae 132{
b32b8144 133 assign_test3a() : assign_values<T>(0, 60, 0, 0, test::limited_range) {}
7c673cae
FG
134};
135
b32b8144 136template <class T> struct assign_test4 : assign_values<T>
7c673cae 137{
b32b8144 138 assign_test4() : assign_values<T>(10, 10, 1, 2) {}
7c673cae
FG
139};
140
b32b8144 141template <class T> struct assign_test4a : assign_values<T>
7c673cae 142{
b32b8144 143 assign_test4a() : assign_values<T>(10, 100, 1, 2) {}
7c673cae
FG
144};
145
b32b8144 146template <class T> struct assign_test4b : assign_values<T>
7c673cae 147{
b32b8144
FG
148 assign_test4b() : assign_values<T>(10, 100, 1, 2, test::limited_range) {}
149};
150
151template <class T> struct assign_test5 : assign_values<T>
152{
153 assign_test5()
154 : assign_values<T>(5, 60, 0, 0, test::default_generator, 1.0f, 0.1f)
155 {
156 }
7c673cae
FG
157};
158
b32b8144
FG
159template <class T> struct equivalent_test1 : assign_base<T>
160{
161 equivalent_test1() : assign_base<T>(0, 0)
162 {
163 test::random_values<T> x_values2(10);
164 this->x_values.insert(x_values2.begin(), x_values2.end());
165 this->x_values.insert(x_values2.begin(), x_values2.end());
166 test::random_values<T> y_values2(10);
167 this->y_values.insert(y_values2.begin(), y_values2.end());
168 this->y_values.insert(y_values2.begin(), y_values2.end());
169 this->x.insert(this->x_values.begin(), this->x_values.end());
170 this->y.insert(this->y_values.begin(), this->y_values.end());
171 }
172};
173
174// clang-format off
175EXCEPTION_TESTS_REPEAT(5,
7c673cae 176 (self_assign_test1)(self_assign_test2)
b32b8144
FG
177 (assign_test1)(assign_test2)(assign_test2a)
178 (assign_test3)(assign_test3a)
179 (assign_test4)(assign_test4a)(assign_test4b)
180 (assign_test5)
7c673cae
FG
181 (equivalent_test1),
182 CONTAINER_SEQ)
b32b8144
FG
183// clang-format on
184
7c673cae 185RUN_TESTS()