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