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( BOOST_JOIN( end_suite, __LINE__ ) )( 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 entry."); \
148 BOOST_TEST_CHECKPOINT('"' << #test_name << "\" entry."); \
150 BOOST_TEST_CHECKPOINT('"' << #test_name << "\" exit."); \
153 struct BOOST_AUTO_TC_UNIQUE_ID( test_name ) {}; \
155 BOOST_AUTO_TU_REGISTRAR( test_name )( \
156 boost::unit_test::make_test_case( \
157 &BOOST_AUTO_TC_INVOKER( test_name ), \
158 #test_name, __FILE__, __LINE__ ), \
161 void test_name::test_method() \
164 #define BOOST_FIXTURE_TEST_CASE_NO_DECOR( test_name, F ) \
165 BOOST_FIXTURE_TEST_CASE_WITH_DECOR( test_name, F, \
166 boost::unit_test::decorator::collector::instance() ) \
169 #if BOOST_PP_VARIADICS
171 #define BOOST_FIXTURE_TEST_CASE( ... ) \
172 BOOST_TEST_INVOKE_IF_N_ARGS( 2, \
173 BOOST_FIXTURE_TEST_CASE_NO_DECOR, \
174 BOOST_FIXTURE_TEST_CASE_WITH_DECOR, \
178 #else /* BOOST_PP_VARIADICS */
180 #define BOOST_FIXTURE_TEST_CASE( test_name, F ) \
181 BOOST_FIXTURE_TEST_CASE_NO_DECOR(test_name, F) \
185 #endif /* BOOST_PP_VARIADICS */
187 // ************************************************************************** //
188 // ************** BOOST_AUTO_TEST_CASE ************** //
189 // ************************************************************************** //
191 #define BOOST_AUTO_TEST_CASE_NO_DECOR( test_name ) \
192 BOOST_FIXTURE_TEST_CASE_NO_DECOR( test_name, \
193 BOOST_AUTO_TEST_CASE_FIXTURE ) \
196 #define BOOST_AUTO_TEST_CASE_WITH_DECOR( test_name, decorators ) \
197 BOOST_FIXTURE_TEST_CASE_WITH_DECOR( test_name, \
198 BOOST_AUTO_TEST_CASE_FIXTURE, decorators ) \
201 #if BOOST_PP_VARIADICS
203 #define BOOST_AUTO_TEST_CASE( ... ) \
204 BOOST_TEST_INVOKE_IF_N_ARGS( 1, \
205 BOOST_AUTO_TEST_CASE_NO_DECOR, \
206 BOOST_AUTO_TEST_CASE_WITH_DECOR, \
210 #else /* BOOST_PP_VARIADICS */
212 #define BOOST_AUTO_TEST_CASE( test_name ) \
213 BOOST_AUTO_TEST_CASE_NO_DECOR( test_name ) \
217 #endif /* BOOST_PP_VARIADICS */
219 // ************************************************************************** //
220 // ************** BOOST_FIXTURE_TEST_CASE_TEMPLATE ************** //
221 // ************************************************************************** //
223 #define BOOST_FIXTURE_TEST_CASE_TEMPLATE( test_name, type_name, TL, F ) \
224 template<typename type_name> \
225 struct test_name : public F \
226 { void test_method(); }; \
228 struct BOOST_AUTO_TC_INVOKER( test_name ) { \
229 template<typename TestType> \
230 static void run( boost::type<TestType>* = 0 ) \
232 BOOST_TEST_CHECKPOINT('"' << #test_name <<"\" fixture entry."); \
233 test_name<TestType> t; \
234 BOOST_TEST_CHECKPOINT('"' << #test_name << "\" entry."); \
236 BOOST_TEST_CHECKPOINT('"' << #test_name << "\" exit."); \
240 BOOST_AUTO_TU_REGISTRAR( test_name )( \
241 boost::unit_test::ut_detail::template_test_case_gen< \
242 BOOST_AUTO_TC_INVOKER( test_name ),TL >( \
243 BOOST_STRINGIZE( test_name ), __FILE__, __LINE__ ), \
244 boost::unit_test::decorator::collector::instance() ); \
246 template<typename type_name> \
247 void test_name<type_name>::test_method() \
250 // ************************************************************************** //
251 // ************** BOOST_AUTO_TEST_CASE_TEMPLATE ************** //
252 // ************************************************************************** //
254 #define BOOST_AUTO_TEST_CASE_TEMPLATE( test_name, type_name, TL ) \
255 BOOST_FIXTURE_TEST_CASE_TEMPLATE( test_name, type_name, TL, \
256 BOOST_AUTO_TEST_CASE_FIXTURE ) \
259 // ************************************************************************** //
260 // ************** BOOST_TEST_CASE_TEMPLATE ************** //
261 // ************************************************************************** //
263 #define BOOST_TEST_CASE_TEMPLATE( name, typelist ) \
264 boost::unit_test::ut_detail::template_test_case_gen<name,typelist>( \
265 BOOST_TEST_STRINGIZE( name ), __FILE__, __LINE__ ) \
268 // ************************************************************************** //
269 // ************** BOOST_TEST_CASE_TEMPLATE_FUNCTION ************** //
270 // ************************************************************************** //
272 #define BOOST_TEST_CASE_TEMPLATE_FUNCTION( name, type_name ) \
273 template<typename type_name> \
274 void BOOST_JOIN( name, _impl )( boost::type<type_name>* ); \
277 template<typename TestType> \
278 static void run( boost::type<TestType>* frwrd = 0 ) \
280 BOOST_JOIN( name, _impl )( frwrd ); \
284 template<typename type_name> \
285 void BOOST_JOIN( name, _impl )( boost::type<type_name>* ) \
288 // ************************************************************************** //
289 // ************** BOOST_GLOBAL_FIXTURE ************** //
290 // ************************************************************************** //
292 #define BOOST_GLOBAL_FIXTURE( F ) \
293 static boost::unit_test::ut_detail::global_fixture_impl<F> BOOST_JOIN( gf_, F ) \
296 // ************************************************************************** //
297 // ************** BOOST_TEST_DECORATOR ************** //
298 // ************************************************************************** //
300 #define BOOST_TEST_DECORATOR( D ) \
301 static boost::unit_test::decorator::collector const& \
302 BOOST_JOIN(decorator_collector,__LINE__) = D; \
305 // ************************************************************************** //
306 // ************** BOOST_AUTO_TEST_CASE_FIXTURE ************** //
307 // ************************************************************************** //
309 namespace boost { namespace unit_test { namespace ut_detail {
313 } // namespace ut_detail
317 // Intentionally is in global namespace, so that FIXTURE_TEST_SUITE can reset it in user code.
318 typedef ::boost::unit_test::ut_detail::nil_t BOOST_AUTO_TEST_CASE_FIXTURE;
320 // ************************************************************************** //
321 // ************** Auto registration facility helper macros ************** //
322 // ************************************************************************** //
324 #define BOOST_AUTO_TU_REGISTRAR( test_name ) \
325 static boost::unit_test::ut_detail::auto_test_unit_registrar \
326 BOOST_JOIN( BOOST_JOIN( test_name, _registrar ), __LINE__ ) \
328 #define BOOST_AUTO_TC_INVOKER( test_name ) BOOST_JOIN( test_name, _invoker )
329 #define BOOST_AUTO_TC_UNIQUE_ID( test_name ) BOOST_JOIN( test_name, _id )
331 // ************************************************************************** //
332 // ************** BOOST_TEST_MAIN ************** //
333 // ************************************************************************** //
335 #if defined(BOOST_TEST_MAIN)
337 #ifdef BOOST_TEST_ALTERNATIVE_INIT_API
338 bool init_unit_test() {
340 ::boost::unit_test::test_suite*
341 init_unit_test_suite( int, char* [] ) {
344 #ifdef BOOST_TEST_MODULE
345 using namespace ::boost::unit_test;
346 assign_op( framework::master_test_suite().p_name.value, BOOST_TEST_STRINGIZE( BOOST_TEST_MODULE ).trim( "\"" ), 0 );
350 #ifdef BOOST_TEST_ALTERNATIVE_INIT_API
360 //____________________________________________________________________________//
362 #include <boost/test/detail/enable_warnings.hpp>
365 #endif // BOOST_TEST_UNIT_TEST_SUITE_HPP_071894GER