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