]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/index/test/rtree/exceptions/test_exceptions.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / index / test / rtree / exceptions / test_exceptions.hpp
1 // Boost.Geometry Index
2 //
3 // R-tree nodes based on runtime-polymorphism, storing static-size containers
4 // test version throwing exceptions on creation
5 //
6 // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
7 //
8 // Use, modification and distribution is subject to the Boost Software License,
9 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
11
12 #ifndef BOOST_GEOMETRY_INDEX_TEST_RTREE_EXCEPTIONS_HPP
13 #define BOOST_GEOMETRY_INDEX_TEST_RTREE_EXCEPTIONS_HPP
14
15 #include <rtree/test_rtree.hpp>
16
17 #include <rtree/exceptions/test_throwing.hpp>
18 #include <rtree/exceptions/test_throwing_node.hpp>
19
20 #include <boost/geometry/geometries/point.hpp>
21 #include <boost/geometry/geometries/box.hpp>
22
23 // test value exceptions
24 template <typename Parameters>
25 void test_rtree_value_exceptions(Parameters const& parameters = Parameters())
26 {
27 typedef std::pair<bg::model::point<float, 2, bg::cs::cartesian>, throwing_value> Value;
28 typedef bgi::rtree<Value, Parameters> Tree;
29 typedef typename Tree::bounds_type B;
30
31 throwing_value::reset_calls_counter();
32 throwing_value::set_max_calls((std::numeric_limits<size_t>::max)());
33 std::vector<Value> input;
34 B qbox;
35 generate::input<2>::apply(input, qbox);
36
37 for ( size_t i = 0 ; i < 50 ; i += 2 )
38 {
39 throwing_value::reset_calls_counter();
40 throwing_value::set_max_calls(10000);
41
42 Tree tree(parameters);
43
44 throwing_value::reset_calls_counter();
45 throwing_value::set_max_calls(i);
46
47 BOOST_CHECK_THROW( tree.insert(input.begin(), input.end()), throwing_value_copy_exception );
48 }
49
50 for ( size_t i = 0 ; i < 20 ; i += 1 )
51 {
52 throwing_value::reset_calls_counter();
53 throwing_value::set_max_calls(i);
54
55 BOOST_CHECK_THROW( Tree tree(input.begin(), input.end(), parameters), throwing_value_copy_exception );
56 }
57
58 for ( size_t i = 0 ; i < 10 ; i += 1 )
59 {
60 throwing_value::reset_calls_counter();
61 throwing_value::set_max_calls(10000);
62
63 Tree tree(parameters);
64
65 tree.insert(input.begin(), input.end());
66
67 throwing_value::reset_calls_counter();
68 throwing_value::set_max_calls(i);
69
70 BOOST_CHECK_THROW( tree.remove(input.begin(), input.end()), throwing_value_copy_exception );
71 }
72
73 for ( size_t i = 0 ; i < 20 ; i += 2 )
74 {
75 throwing_value::reset_calls_counter();
76 throwing_value::set_max_calls(10000);
77
78 Tree tree(parameters);
79
80 tree.insert(input.begin(), input.end());
81
82 throwing_value::reset_calls_counter();
83 throwing_value::set_max_calls(i);
84
85 BOOST_CHECK_THROW( Tree tree2(tree), throwing_value_copy_exception );
86 }
87
88 for ( size_t i = 0 ; i < 20 ; i += 2 )
89 {
90 throwing_value::reset_calls_counter();
91 throwing_value::set_max_calls(10000);
92
93 Tree tree(parameters);
94 Tree tree2(parameters);
95
96 tree.insert(input.begin(), input.end());
97
98 throwing_value::reset_calls_counter();
99 throwing_value::set_max_calls(i);
100
101 BOOST_CHECK_THROW(tree2 = tree, throwing_value_copy_exception );
102 }
103 }
104
105 // test value exceptions
106 template <typename Parameters>
107 void test_rtree_elements_exceptions(Parameters const& parameters = Parameters())
108 {
109 typedef std::pair<bg::model::point<float, 2, bg::cs::cartesian>, throwing_value> Value;
110 typedef bgi::rtree<Value, Parameters> Tree;
111 typedef typename Tree::bounds_type B;
112
113 throwing_value::reset_calls_counter();
114 throwing_value::set_max_calls((std::numeric_limits<size_t>::max)());
115
116 std::vector<Value> input;
117 B qbox;
118 generate::input<2>::apply(input, qbox, 2);
119
120 for ( size_t i = 0 ; i < 100 ; i += 2 )
121 {
122 throwing_varray_settings::reset_calls_counter();
123 throwing_varray_settings::set_max_calls(10000);
124
125 Tree tree(parameters);
126
127 throwing_varray_settings::reset_calls_counter();
128 throwing_varray_settings::set_max_calls(i);
129
130 BOOST_CHECK_THROW( tree.insert(input.begin(), input.end()), throwing_varray_exception );
131 }
132
133 for ( size_t i = 0 ; i < 100 ; i += 2 )
134 {
135 throwing_varray_settings::reset_calls_counter();
136 throwing_varray_settings::set_max_calls(i);
137
138 throwing_nodes_stats::reset_counters();
139
140 BOOST_CHECK_THROW( Tree tree(input.begin(), input.end(), parameters), throwing_varray_exception );
141
142 BOOST_CHECK_EQUAL(throwing_nodes_stats::internal_nodes_count(), 0u);
143 BOOST_CHECK_EQUAL(throwing_nodes_stats::leafs_count(), 0u);
144 }
145
146 for ( size_t i = 0 ; i < 50 ; i += 2 )
147 {
148 throwing_varray_settings::reset_calls_counter();
149 throwing_varray_settings::set_max_calls(10000);
150
151 Tree tree(parameters);
152
153 tree.insert(input.begin(), input.end());
154
155 throwing_varray_settings::reset_calls_counter();
156 throwing_varray_settings::set_max_calls(i);
157
158 BOOST_CHECK_THROW( tree.remove(input.begin(), input.end()), throwing_varray_exception );
159 }
160
161 for ( size_t i = 0 ; i < 50 ; i += 2 )
162 {
163 throwing_varray_settings::reset_calls_counter();
164 throwing_varray_settings::set_max_calls(10000);
165
166 Tree tree(parameters);
167
168 tree.insert(input.begin(), input.end());
169
170 throwing_varray_settings::reset_calls_counter();
171 throwing_varray_settings::set_max_calls(i);
172
173 BOOST_CHECK_THROW( Tree tree2(tree), throwing_varray_exception );
174 }
175
176 for ( size_t i = 0 ; i < 50 ; i += 2 )
177 {
178 throwing_varray_settings::reset_calls_counter();
179 throwing_varray_settings::set_max_calls(10000);
180
181 Tree tree(parameters);
182 Tree tree2(parameters);
183
184 tree.insert(input.begin(), input.end());
185
186 throwing_varray_settings::reset_calls_counter();
187 throwing_varray_settings::set_max_calls(i);
188
189 BOOST_CHECK_THROW(tree2 = tree, throwing_varray_exception );
190 }
191 }
192
193 #endif // BOOST_GEOMETRY_INDEX_TEST_RTREE_EXCEPTIONS_HPP