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