]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/test/unit_test_suite.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / test / unit_test_suite.hpp
1 // (C) Copyright Gennadiy Rozental 2001.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5
6 // See http://www.boost.org/libs/test for the library home page.
7 //
8 /// @file
9 /// @brief Defines Unit Test Framework public API
10 // ***************************************************************************
11
12 #ifndef BOOST_TEST_UNIT_TEST_SUITE_HPP_071894GER
13 #define BOOST_TEST_UNIT_TEST_SUITE_HPP_071894GER
14
15 // Boost.Test
16 #include <boost/test/framework.hpp>
17 #include <boost/test/tree/auto_registration.hpp>
18 #include <boost/test/tree/test_case_template.hpp>
19 #include <boost/test/tree/global_fixture.hpp>
20
21
22 #include <boost/test/detail/suppress_warnings.hpp>
23
24
25 #include <boost/test/detail/pp_variadic.hpp>
26
27
28
29 //____________________________________________________________________________//
30
31 // ************************************************************************** //
32 // ************** Non-auto (explicit) test case interface ************** //
33 // ************************************************************************** //
34
35 #define BOOST_TEST_CASE( test_function ) \
36 boost::unit_test::make_test_case( boost::function<void ()>(test_function), \
37 BOOST_TEST_STRINGIZE( test_function ), \
38 __FILE__, __LINE__ )
39 #define BOOST_CLASS_TEST_CASE( test_function, tc_instance ) \
40 boost::unit_test::make_test_case( (test_function), \
41 BOOST_TEST_STRINGIZE( test_function ), \
42 __FILE__, __LINE__, tc_instance )
43
44 // ************************************************************************** //
45 // ************** BOOST_TEST_SUITE ************** //
46 // ************************************************************************** //
47
48 #define BOOST_TEST_SUITE( testsuite_name ) \
49 ( new boost::unit_test::test_suite( testsuite_name, __FILE__, __LINE__ ) )
50
51 // ************************************************************************** //
52 // ************** BOOST_AUTO_TEST_SUITE ************** //
53 // ************************************************************************** //
54
55 #define BOOST_AUTO_TEST_SUITE_WITH_DECOR( suite_name, decorators ) \
56 namespace suite_name { \
57 BOOST_AUTO_TU_REGISTRAR( suite_name )( \
58 BOOST_STRINGIZE( suite_name ), \
59 __FILE__, __LINE__, \
60 decorators ); \
61 /**/
62
63 #define BOOST_AUTO_TEST_SUITE_NO_DECOR( suite_name ) \
64 BOOST_AUTO_TEST_SUITE_WITH_DECOR( \
65 suite_name, \
66 boost::unit_test::decorator::collector::instance() ) \
67 /**/
68
69 #if BOOST_PP_VARIADICS
70 #define BOOST_AUTO_TEST_SUITE( ... ) \
71 BOOST_TEST_INVOKE_IF_N_ARGS( 1, \
72 BOOST_AUTO_TEST_SUITE_NO_DECOR, \
73 BOOST_AUTO_TEST_SUITE_WITH_DECOR, \
74 __VA_ARGS__) \
75 /**/
76
77 #else /* BOOST_PP_VARIADICS */
78
79 #define BOOST_AUTO_TEST_SUITE( suite_name ) \
80 BOOST_AUTO_TEST_SUITE_NO_DECOR( suite_name ) \
81 /**/
82
83
84 #endif /* BOOST_PP_VARIADICS */
85
86 // ************************************************************************** //
87 // ************** BOOST_FIXTURE_TEST_SUITE ************** //
88 // ************************************************************************** //
89
90 #define BOOST_FIXTURE_TEST_SUITE_WITH_DECOR(suite_name, F, decorators) \
91 BOOST_AUTO_TEST_SUITE_WITH_DECOR( suite_name, decorators ) \
92 typedef F BOOST_AUTO_TEST_CASE_FIXTURE; \
93 /**/
94
95 #define BOOST_FIXTURE_TEST_SUITE_NO_DECOR( suite_name, F ) \
96 BOOST_AUTO_TEST_SUITE_NO_DECOR( suite_name ) \
97 typedef F BOOST_AUTO_TEST_CASE_FIXTURE; \
98 /**/
99
100 #if BOOST_PP_VARIADICS
101
102 #define BOOST_FIXTURE_TEST_SUITE( ... ) \
103 BOOST_TEST_INVOKE_IF_N_ARGS( 2, \
104 BOOST_FIXTURE_TEST_SUITE_NO_DECOR, \
105 BOOST_FIXTURE_TEST_SUITE_WITH_DECOR, \
106 __VA_ARGS__) \
107 /**/
108
109 #else /* BOOST_PP_VARIADICS */
110
111 #define BOOST_FIXTURE_TEST_SUITE( suite_name, F ) \
112 BOOST_FIXTURE_TEST_SUITE_NO_DECOR( suite_name, F ) \
113 /**/
114
115
116 #endif /* BOOST_PP_VARIADICS */
117
118
119 // ************************************************************************** //
120 // ************** BOOST_AUTO_TEST_SUITE_END ************** //
121 // ************************************************************************** //
122
123 #define BOOST_AUTO_TEST_SUITE_END() \
124 BOOST_AUTO_TU_REGISTRAR( end_suite )( 1 ); \
125 } \
126 /**/
127
128 // ************************************************************************** //
129 // ************** BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES ************** //
130 // ************************************************************************** //
131
132 /// @deprecated use decorator instead
133 #define BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES( test_name, n ) \
134 BOOST_TEST_DECORATOR( * boost::unit_test::expected_failures( n ) ) \
135 /**/
136
137 // ************************************************************************** //
138 // ************** BOOST_FIXTURE_TEST_CASE ************** //
139 // ************************************************************************** //
140
141 #define BOOST_FIXTURE_TEST_CASE_WITH_DECOR( test_name, F, decorators ) \
142 struct test_name : public F { void test_method(); }; \
143 \
144 static void BOOST_AUTO_TC_INVOKER( test_name )() \
145 { \
146 BOOST_TEST_CHECKPOINT('"' << #test_name << "\" fixture ctor"); \
147 test_name t; \
148 BOOST_TEST_CHECKPOINT('"' << #test_name << "\" fixture setup"); \
149 boost::unit_test::setup_conditional(t); \
150 BOOST_TEST_CHECKPOINT('"' << #test_name << "\" test entry"); \
151 t.test_method(); \
152 BOOST_TEST_CHECKPOINT('"' << #test_name << "\" fixture teardown"); \
153 boost::unit_test::teardown_conditional(t); \
154 BOOST_TEST_CHECKPOINT('"' << #test_name << "\" fixture dtor"); \
155 } \
156 \
157 struct BOOST_AUTO_TC_UNIQUE_ID( test_name ) {}; \
158 \
159 BOOST_AUTO_TU_REGISTRAR( test_name )( \
160 boost::unit_test::make_test_case( \
161 &BOOST_AUTO_TC_INVOKER( test_name ), \
162 #test_name, __FILE__, __LINE__ ), \
163 decorators ); \
164 \
165 void test_name::test_method() \
166 /**/
167
168 #define BOOST_FIXTURE_TEST_CASE_NO_DECOR( test_name, F ) \
169 BOOST_FIXTURE_TEST_CASE_WITH_DECOR( test_name, F, \
170 boost::unit_test::decorator::collector::instance() ) \
171 /**/
172
173 #if BOOST_PP_VARIADICS
174
175 #define BOOST_FIXTURE_TEST_CASE( ... ) \
176 BOOST_TEST_INVOKE_IF_N_ARGS( 2, \
177 BOOST_FIXTURE_TEST_CASE_NO_DECOR, \
178 BOOST_FIXTURE_TEST_CASE_WITH_DECOR, \
179 __VA_ARGS__) \
180 /**/
181
182 #else /* BOOST_PP_VARIADICS */
183
184 #define BOOST_FIXTURE_TEST_CASE( test_name, F ) \
185 BOOST_FIXTURE_TEST_CASE_NO_DECOR(test_name, F) \
186 /**/
187
188
189 #endif /* BOOST_PP_VARIADICS */
190
191 // ************************************************************************** //
192 // ************** BOOST_AUTO_TEST_CASE ************** //
193 // ************************************************************************** //
194
195 #define BOOST_AUTO_TEST_CASE_NO_DECOR( test_name ) \
196 BOOST_FIXTURE_TEST_CASE_NO_DECOR( test_name, \
197 BOOST_AUTO_TEST_CASE_FIXTURE ) \
198 /**/
199
200 #define BOOST_AUTO_TEST_CASE_WITH_DECOR( test_name, decorators ) \
201 BOOST_FIXTURE_TEST_CASE_WITH_DECOR( test_name, \
202 BOOST_AUTO_TEST_CASE_FIXTURE, decorators ) \
203 /**/
204
205 #if BOOST_PP_VARIADICS
206
207 #define BOOST_AUTO_TEST_CASE( ... ) \
208 BOOST_TEST_INVOKE_IF_N_ARGS( 1, \
209 BOOST_AUTO_TEST_CASE_NO_DECOR, \
210 BOOST_AUTO_TEST_CASE_WITH_DECOR, \
211 __VA_ARGS__) \
212 /**/
213
214 #else /* BOOST_PP_VARIADICS */
215
216 #define BOOST_AUTO_TEST_CASE( test_name ) \
217 BOOST_AUTO_TEST_CASE_NO_DECOR( test_name ) \
218 /**/
219
220
221 #endif /* BOOST_PP_VARIADICS */
222
223 // ************************************************************************** //
224 // ************** BOOST_FIXTURE_TEST_CASE_TEMPLATE ************** //
225 // ************************************************************************** //
226
227 #define BOOST_FIXTURE_TEST_CASE_TEMPLATE( test_name, type_name, TL, F ) \
228 template<typename type_name> \
229 struct test_name : public F \
230 { void test_method(); }; \
231 \
232 struct BOOST_AUTO_TC_INVOKER( test_name ) { \
233 template<typename TestType> \
234 static void run( boost::type<TestType>* = 0 ) \
235 { \
236 BOOST_TEST_CHECKPOINT('"' << #test_name <<"\" fixture entry."); \
237 test_name<TestType> t; boost::unit_test::setup_conditional(t); \
238 BOOST_TEST_CHECKPOINT('"' << #test_name << "\" entry."); \
239 t.test_method(); \
240 BOOST_TEST_CHECKPOINT('"' << #test_name << "\" exit."); \
241 boost::unit_test::teardown_conditional(t); \
242 } \
243 }; \
244 \
245 BOOST_AUTO_TU_REGISTRAR( test_name )( \
246 boost::unit_test::ut_detail::template_test_case_gen< \
247 BOOST_AUTO_TC_INVOKER( test_name ),TL >( \
248 BOOST_STRINGIZE( test_name ), __FILE__, __LINE__ ), \
249 boost::unit_test::decorator::collector::instance() ); \
250 \
251 template<typename type_name> \
252 void test_name<type_name>::test_method() \
253 /**/
254
255 // ************************************************************************** //
256 // ************** BOOST_AUTO_TEST_CASE_TEMPLATE ************** //
257 // ************************************************************************** //
258
259 #define BOOST_AUTO_TEST_CASE_TEMPLATE( test_name, type_name, TL ) \
260 BOOST_FIXTURE_TEST_CASE_TEMPLATE( test_name, type_name, TL, \
261 BOOST_AUTO_TEST_CASE_FIXTURE ) \
262 /**/
263
264 // ************************************************************************** //
265 // ************** BOOST_TEST_CASE_TEMPLATE ************** //
266 // ************************************************************************** //
267
268 #define BOOST_TEST_CASE_TEMPLATE( name, typelist ) \
269 boost::unit_test::ut_detail::template_test_case_gen<name,typelist>( \
270 BOOST_TEST_STRINGIZE( name ), __FILE__, __LINE__ ) \
271 /**/
272
273 // ************************************************************************** //
274 // ************** BOOST_TEST_CASE_TEMPLATE_FUNCTION ************** //
275 // ************************************************************************** //
276
277 #define BOOST_TEST_CASE_TEMPLATE_FUNCTION( name, type_name ) \
278 template<typename type_name> \
279 void BOOST_JOIN( name, _impl )( boost::type<type_name>* ); \
280 \
281 struct name { \
282 template<typename TestType> \
283 static void run( boost::type<TestType>* frwrd = 0 ) \
284 { \
285 BOOST_JOIN( name, _impl )( frwrd ); \
286 } \
287 }; \
288 \
289 template<typename type_name> \
290 void BOOST_JOIN( name, _impl )( boost::type<type_name>* ) \
291 /**/
292
293 // ************************************************************************** //
294 // ************** BOOST_GLOBAL_FIXTURE ************** //
295 // ************************************************************************** //
296
297 #define BOOST_GLOBAL_FIXTURE( F ) \
298 static boost::unit_test::ut_detail::global_configuration_impl<F> BOOST_JOIN( gf_, F ) \
299 /**/
300
301 // ************************************************************************** //
302 // ************** BOOST_TEST_GLOBAL_CONFIGURATION ************** //
303 // ************************************************************************** //
304
305 #define BOOST_TEST_GLOBAL_CONFIGURATION( F ) \
306 static boost::unit_test::ut_detail::global_configuration_impl<F> BOOST_JOIN( gf_, F ) \
307 /**/
308
309 // ************************************************************************** //
310 // ************** BOOST_TEST_GLOBAL_FIXTURE ************** //
311 // ************************************************************************** //
312
313 #define BOOST_TEST_GLOBAL_FIXTURE( F ) \
314 static boost::unit_test::ut_detail::global_fixture_impl<F> BOOST_JOIN( gf_, F ) \
315 /**/
316
317 // ************************************************************************** //
318 // ************** BOOST_TEST_DECORATOR ************** //
319 // ************************************************************************** //
320
321 #define BOOST_TEST_DECORATOR( D ) \
322 static boost::unit_test::decorator::collector const& \
323 BOOST_TEST_APPEND_UNIQUE_ID(decorator_collector) = D; \
324 /**/
325
326 // ************************************************************************** //
327 // ************** BOOST_AUTO_TEST_CASE_FIXTURE ************** //
328 // ************************************************************************** //
329
330 namespace boost { namespace unit_test { namespace ut_detail {
331
332 struct nil_t {};
333
334 } // namespace ut_detail
335 } // unit_test
336 } // namespace boost
337
338 // Intentionally is in global namespace, so that FIXTURE_TEST_SUITE can reset it in user code.
339 typedef ::boost::unit_test::ut_detail::nil_t BOOST_AUTO_TEST_CASE_FIXTURE;
340
341 // ************************************************************************** //
342 // ************** Auto registration facility helper macros ************** //
343 // ************************************************************************** //
344
345 // Facility for having a unique name based on __LINE__ and __COUNTER__ (later if available)
346 #if defined(__COUNTER__)
347 #define BOOST_TEST_INTERNAL_HAS_COUNTER
348 #endif
349
350 #if defined(BOOST_TEST_INTERNAL_HAS_COUNTER)
351 #define BOOST_TEST_APPEND_UNIQUE_ID( name ) \
352 BOOST_JOIN( BOOST_JOIN( name, __LINE__ ), __COUNTER__)
353 /**/
354 #else
355 #define BOOST_TEST_APPEND_UNIQUE_ID( name ) \
356 BOOST_JOIN( name, __LINE__ )
357 /**/
358 #endif
359 /**/
360
361 #define BOOST_AUTO_TU_REGISTRAR( test_name ) \
362 static boost::unit_test::ut_detail::auto_test_unit_registrar \
363 BOOST_TEST_APPEND_UNIQUE_ID( BOOST_JOIN( test_name, _registrar ) ) \
364 /**/
365 #define BOOST_AUTO_TC_INVOKER( test_name ) BOOST_JOIN( test_name, _invoker )
366 #define BOOST_AUTO_TC_UNIQUE_ID( test_name ) BOOST_JOIN( test_name, _id )
367
368 // ************************************************************************** //
369 // ************** BOOST_TEST_MAIN ************** //
370 // ************************************************************************** //
371
372 #if defined(BOOST_TEST_MAIN)
373
374 #ifdef BOOST_TEST_ALTERNATIVE_INIT_API
375 bool init_unit_test() {
376 #else
377 ::boost::unit_test::test_suite*
378 init_unit_test_suite( int, char* [] ) {
379 #endif
380
381 #ifdef BOOST_TEST_MODULE
382 using namespace ::boost::unit_test;
383 assign_op( framework::master_test_suite().p_name.value, BOOST_TEST_STRINGIZE( BOOST_TEST_MODULE ).trim( "\"" ), 0 );
384
385 #endif
386
387 #ifdef BOOST_TEST_ALTERNATIVE_INIT_API
388 return true;
389 }
390 #else
391 return 0;
392 }
393 #endif
394
395 #endif
396
397 //____________________________________________________________________________//
398
399 #include <boost/test/detail/enable_warnings.hpp>
400
401
402 #endif // BOOST_TEST_UNIT_TEST_SUITE_HPP_071894GER
403