]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/unordered/test/exception/swap_exception_tests.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / unordered / test / exception / swap_exception_tests.cpp
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/invariants.hpp"
9 #include "../helpers/random_values.hpp"
10 #include "../helpers/tracker.hpp"
11
12 #if defined(BOOST_MSVC)
13 #pragma warning(disable : 4512) // assignment operator could not be generated
14 #endif
15
16 test::seed_t initialize_seed(9387);
17
18 template <class T> struct self_swap_base : public test::exception_base
19 {
20 test::random_values<T> values;
21 self_swap_base(std::size_t count = 0) : values(count, test::limited_range) {}
22
23 typedef T data_type;
24 T init() const { return T(values.begin(), values.end()); }
25
26 void run(T& x) const
27 {
28 x.swap(x);
29
30 DISABLE_EXCEPTIONS;
31 test::check_container(x, this->values);
32 test::check_equivalent_keys(x);
33 }
34
35 void check BOOST_PREVENT_MACRO_SUBSTITUTION(T const& x) const
36 {
37 std::string scope(test::scope);
38
39 // TODO: In C++11 exceptions are only allowed in the swap function.
40 BOOST_TEST(scope == "hash::hash(hash)" ||
41 scope == "hash::operator=(hash)" ||
42 scope == "equal_to::equal_to(equal_to)" ||
43 scope == "equal_to::operator=(equal_to)");
44
45 test::check_equivalent_keys(x);
46 }
47 };
48
49 template <class T> struct self_swap_test1 : self_swap_base<T>
50 {
51 };
52
53 template <class T> struct self_swap_test2 : self_swap_base<T>
54 {
55 self_swap_test2() : self_swap_base<T>(100) {}
56 };
57
58 template <class T> struct swap_base : public test::exception_base
59 {
60 const test::random_values<T> x_values, y_values;
61 const T initial_x, initial_y;
62
63 typedef BOOST_DEDUCED_TYPENAME T::hasher hasher;
64 typedef BOOST_DEDUCED_TYPENAME T::key_equal key_equal;
65 typedef BOOST_DEDUCED_TYPENAME T::allocator_type allocator_type;
66
67 swap_base(unsigned int count1, unsigned int count2, int tag1, int tag2)
68 : x_values(count1, test::limited_range),
69 y_values(count2, test::limited_range),
70 initial_x(x_values.begin(), x_values.end(), 0, hasher(tag1),
71 key_equal(tag1), allocator_type(tag1)),
72 initial_y(y_values.begin(), y_values.end(), 0, hasher(tag2),
73 key_equal(tag2),
74 allocator_type(T::allocator_type::propagate_on_container_swap::value
75 ? tag2
76 : tag1))
77 {
78 }
79
80 struct data_type
81 {
82 data_type(T const& x_, T const& y_) : x(x_), y(y_) {}
83
84 T x, y;
85 };
86
87 data_type init() const { return data_type(initial_x, initial_y); }
88
89 void run(data_type& d) const
90 {
91 try {
92 d.x.swap(d.y);
93 } catch (std::runtime_error) {
94 }
95
96 DISABLE_EXCEPTIONS;
97 test::check_container(d.x, this->y_values);
98 test::check_equivalent_keys(d.x);
99 test::check_container(d.y, this->x_values);
100 test::check_equivalent_keys(d.y);
101 }
102
103 void check BOOST_PREVENT_MACRO_SUBSTITUTION(data_type const& d) const
104 {
105 std::string scope(test::scope);
106
107 // TODO: In C++11 exceptions are only allowed in the swap function.
108 BOOST_TEST(scope == "hash::hash(hash)" ||
109 scope == "hash::operator=(hash)" ||
110 scope == "equal_to::equal_to(equal_to)" ||
111 scope == "equal_to::operator=(equal_to)");
112
113 test::check_equivalent_keys(d.x);
114 test::check_equivalent_keys(d.y);
115 }
116 };
117
118 template <class T> struct swap_test1 : swap_base<T>
119 {
120 swap_test1() : swap_base<T>(0, 0, 0, 0) {}
121 };
122
123 template <class T> struct swap_test2 : swap_base<T>
124 {
125 swap_test2() : swap_base<T>(60, 0, 0, 0) {}
126 };
127
128 template <class T> struct swap_test3 : swap_base<T>
129 {
130 swap_test3() : swap_base<T>(0, 60, 0, 0) {}
131 };
132
133 template <class T> struct swap_test4 : swap_base<T>
134 {
135 swap_test4() : swap_base<T>(10, 10, 1, 2) {}
136 };
137
138 // clang-format off
139 EXCEPTION_TESTS(
140 (self_swap_test1)(self_swap_test2)
141 (swap_test1)(swap_test2)(swap_test3)(swap_test4),
142 CONTAINER_SEQ)
143 // clang-format on
144
145 RUN_TESTS()