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)
6 // See http://www.boost.org/libs/test for the library home page.
9 /// @brief Defines Unit Test Framework public API
10 // ***************************************************************************
12 #ifndef BOOST_TEST_UNIT_TEST_SUITE_HPP_071894GER
13 #define BOOST_TEST_UNIT_TEST_SUITE_HPP_071894GER
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>
22 #include <boost/test/detail/suppress_warnings.hpp>
25 #include <boost/test/detail/pp_variadic.hpp>
29 //____________________________________________________________________________//
31 // ************************************************************************** //
32 // ************** Non-auto (explicit) test case interface ************** //
33 // ************************************************************************** //
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 ), \
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 )
44 // ************************************************************************** //
45 // ************** BOOST_TEST_SUITE ************** //
46 // ************************************************************************** //
48 #define BOOST_TEST_SUITE( testsuite_name ) \
49 ( new boost::unit_test::test_suite( testsuite_name, __FILE__, __LINE__ ) )
51 // ************************************************************************** //
52 // ************** BOOST_AUTO_TEST_SUITE ************** //
53 // ************************************************************************** //
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 ), \
63 #define BOOST_AUTO_TEST_SUITE_NO_DECOR( suite_name ) \
64 BOOST_AUTO_TEST_SUITE_WITH_DECOR( \
66 boost::unit_test::decorator::collector::instance() ) \
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, \
77 #else /* BOOST_PP_VARIADICS */
79 #define BOOST_AUTO_TEST_SUITE( suite_name ) \
80 BOOST_AUTO_TEST_SUITE_NO_DECOR( suite_name ) \
84 #endif /* BOOST_PP_VARIADICS */
86 // ************************************************************************** //
87 // ************** BOOST_FIXTURE_TEST_SUITE ************** //
88 // ************************************************************************** //
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; \
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; \
100 #if BOOST_PP_VARIADICS
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, \
109 #else /* BOOST_PP_VARIADICS */
111 #define BOOST_FIXTURE_TEST_SUITE( suite_name, F ) \
112 BOOST_FIXTURE_TEST_SUITE_NO_DECOR( suite_name, F ) \
116 #endif /* BOOST_PP_VARIADICS */
119 // ************************************************************************** //
120 // ************** BOOST_AUTO_TEST_SUITE_END ************** //
121 // ************************************************************************** //
123 #define BOOST_AUTO_TEST_SUITE_END() \
124 BOOST_AUTO_TU_REGISTRAR( end_suite )( 1 ); \
128 // ************************************************************************** //
129 // ************** BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES ************** //
130 // ************************************************************************** //
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 ) ) \
137 // ************************************************************************** //
138 // ************** BOOST_FIXTURE_TEST_CASE ************** //
139 // ************************************************************************** //
141 #define BOOST_FIXTURE_TEST_CASE_WITH_DECOR( test_name, F, decorators ) \
142 struct test_name : public F { void test_method(); }; \
144 static void BOOST_AUTO_TC_INVOKER( test_name )() \
146 BOOST_TEST_CHECKPOINT('"' << #test_name << "\" fixture ctor"); \
148 BOOST_TEST_CHECKPOINT('"' << #test_name << "\" fixture setup"); \
149 boost::unit_test::setup_conditional(t); \
150 BOOST_TEST_CHECKPOINT('"' << #test_name << "\" test entry"); \
152 BOOST_TEST_CHECKPOINT('"' << #test_name << "\" fixture teardown"); \
153 boost::unit_test::teardown_conditional(t); \
154 BOOST_TEST_CHECKPOINT('"' << #test_name << "\" fixture dtor"); \
157 struct BOOST_AUTO_TC_UNIQUE_ID( test_name ) {}; \
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__ ), \
165 void test_name::test_method() \
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() ) \
173 #if BOOST_PP_VARIADICS
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, \
182 #else /* BOOST_PP_VARIADICS */
184 #define BOOST_FIXTURE_TEST_CASE( test_name, F ) \
185 BOOST_FIXTURE_TEST_CASE_NO_DECOR(test_name, F) \
189 #endif /* BOOST_PP_VARIADICS */
191 // ************************************************************************** //
192 // ************** BOOST_AUTO_TEST_CASE ************** //
193 // ************************************************************************** //
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 ) \
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 ) \
205 #if BOOST_PP_VARIADICS
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, \
214 #else /* BOOST_PP_VARIADICS */
216 #define BOOST_AUTO_TEST_CASE( test_name ) \
217 BOOST_AUTO_TEST_CASE_NO_DECOR( test_name ) \
221 #endif /* BOOST_PP_VARIADICS */
223 // ************************************************************************** //
224 // ************** BOOST_FIXTURE_TEST_CASE_TEMPLATE ************** //
225 // ************************************************************************** //
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(); }; \
232 struct BOOST_AUTO_TC_INVOKER( test_name ) { \
233 template<typename TestType> \
234 static void run( boost::type<TestType>* = 0 ) \
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."); \
240 BOOST_TEST_CHECKPOINT('"' << #test_name << "\" exit."); \
241 boost::unit_test::teardown_conditional(t); \
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() ); \
251 template<typename type_name> \
252 void test_name<type_name>::test_method() \
255 // ************************************************************************** //
256 // ************** BOOST_AUTO_TEST_CASE_TEMPLATE ************** //
257 // ************************************************************************** //
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 ) \
264 // ************************************************************************** //
265 // ************** BOOST_TEST_CASE_TEMPLATE ************** //
266 // ************************************************************************** //
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__ ) \
273 // ************************************************************************** //
274 // ************** BOOST_TEST_CASE_TEMPLATE_FUNCTION ************** //
275 // ************************************************************************** //
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>* ); \
282 template<typename TestType> \
283 static void run( boost::type<TestType>* frwrd = 0 ) \
285 BOOST_JOIN( name, _impl )( frwrd ); \
289 template<typename type_name> \
290 void BOOST_JOIN( name, _impl )( boost::type<type_name>* ) \
293 // ************************************************************************** //
294 // ************** BOOST_GLOBAL_FIXTURE ************** //
295 // ************************************************************************** //
297 #define BOOST_GLOBAL_FIXTURE( F ) \
298 static boost::unit_test::ut_detail::global_configuration_impl<F> BOOST_JOIN( gf_, F ) \
301 // ************************************************************************** //
302 // ************** BOOST_TEST_GLOBAL_CONFIGURATION ************** //
303 // ************************************************************************** //
305 #define BOOST_TEST_GLOBAL_CONFIGURATION( F ) \
306 static boost::unit_test::ut_detail::global_configuration_impl<F> BOOST_JOIN( gf_, F ) \
309 // ************************************************************************** //
310 // ************** BOOST_TEST_GLOBAL_FIXTURE ************** //
311 // ************************************************************************** //
313 #define BOOST_TEST_GLOBAL_FIXTURE( F ) \
314 static boost::unit_test::ut_detail::global_fixture_impl<F> BOOST_JOIN( gf_, F ) \
317 // ************************************************************************** //
318 // ************** BOOST_TEST_DECORATOR ************** //
319 // ************************************************************************** //
321 #define BOOST_TEST_DECORATOR( D ) \
322 static boost::unit_test::decorator::collector const& \
323 BOOST_TEST_APPEND_UNIQUE_ID(decorator_collector) = D; \
326 // ************************************************************************** //
327 // ************** BOOST_AUTO_TEST_CASE_FIXTURE ************** //
328 // ************************************************************************** //
330 namespace boost { namespace unit_test { namespace ut_detail {
334 } // namespace ut_detail
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;
341 // ************************************************************************** //
342 // ************** Auto registration facility helper macros ************** //
343 // ************************************************************************** //
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
350 #if defined(BOOST_TEST_INTERNAL_HAS_COUNTER)
351 #define BOOST_TEST_APPEND_UNIQUE_ID( name ) \
352 BOOST_JOIN( BOOST_JOIN( name, __LINE__ ), __COUNTER__)
355 #define BOOST_TEST_APPEND_UNIQUE_ID( name ) \
356 BOOST_JOIN( name, __LINE__ )
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 ) ) \
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 )
368 // ************************************************************************** //
369 // ************** BOOST_TEST_MAIN ************** //
370 // ************************************************************************** //
372 #if defined(BOOST_TEST_MAIN)
374 #ifdef BOOST_TEST_ALTERNATIVE_INIT_API
375 bool init_unit_test() {
377 ::boost::unit_test::test_suite*
378 init_unit_test_suite( int, char* [] ) {
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 );
387 #ifdef BOOST_TEST_ALTERNATIVE_INIT_API
397 //____________________________________________________________________________//
399 #include <boost/test/detail/enable_warnings.hpp>
402 #endif // BOOST_TEST_UNIT_TEST_SUITE_HPP_071894GER