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