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 : $RCSfile$
9//
10// Version : $Revision: 81247 $
11//
12// Description : contains definition for all test tools in test toolbox
13// ***************************************************************************
14
15#ifndef BOOST_TEST_TOOLS_INTERFACE_HPP_111712GER
16#define BOOST_TEST_TOOLS_INTERFACE_HPP_111712GER
17
18// Boost.Test
19#include <boost/test/unit_test_log.hpp>
20#ifdef BOOST_TEST_TOOLS_DEBUGGABLE
21#include <boost/test/debug.hpp>
22#endif
23
24#include <boost/test/detail/pp_variadic.hpp>
25
26#ifdef BOOST_TEST_NO_OLD_TOOLS
27#include <boost/preprocessor/seq/to_tuple.hpp>
28
29#include <iterator>
30#endif // BOOST_TEST_NO_OLD_TOOLS
31
32#include <boost/test/detail/suppress_warnings.hpp>
33
34//____________________________________________________________________________//
35
36// ************************************************************************** //
37// ************** BOOST_TEST_<level> ************** //
38// ************************************************************************** //
39
40#define BOOST_TEST_BUILD_ASSERTION( P ) \
41 (::boost::test_tools::assertion::seed()->*P) \
42/**/
43
44//____________________________________________________________________________//
45
46// Implementation based on direct predicate evaluation
47#define BOOST_TEST_TOOL_DIRECT_IMPL( P, level, M ) \
48do { \
49 ::boost::test_tools::assertion_result res = (P); \
50 report_assertion( \
51 res, \
52 BOOST_TEST_LAZY_MSG( M ), \
53 BOOST_TEST_L(__FILE__), \
54 static_cast<std::size_t>(__LINE__), \
55 ::boost::test_tools::tt_detail::level, \
56 ::boost::test_tools::tt_detail::CHECK_MSG, \
57 0 ); \
58} while( ::boost::test_tools::tt_detail::dummy_cond() ) \
59/**/
60
61//____________________________________________________________________________//
62
63// Implementation based on expression template construction
64#define BOOST_TEST_TOOL_ET_IMPL( P, level ) \
65do { \
66 BOOST_TEST_PASSPOINT(); \
67 \
68 ::boost::test_tools::tt_detail:: \
69 report_assertion( \
70 BOOST_TEST_BUILD_ASSERTION( P ).evaluate(), \
71 BOOST_TEST_LAZY_MSG( BOOST_TEST_STRINGIZE( P ) ), \
72 BOOST_TEST_L(__FILE__), \
73 static_cast<std::size_t>(__LINE__), \
74 ::boost::test_tools::tt_detail::level, \
75 ::boost::test_tools::tt_detail::CHECK_BUILT_ASSERTION, \
76 0 ); \
77} while( ::boost::test_tools::tt_detail::dummy_cond() ) \
78/**/
79
80//____________________________________________________________________________//
81
82// Implementation based on expression template construction with extra tool arguments
83#define BOOST_TEST_TOOL_ET_IMPL_EX( P, level, arg ) \
84do { \
85 BOOST_TEST_PASSPOINT(); \
86 \
87 ::boost::test_tools::tt_detail:: \
88 report_assertion( \
89 ::boost::test_tools::tt_detail::assertion_evaluate( \
90 BOOST_TEST_BUILD_ASSERTION( P ) ) \
91 << arg, \
92 ::boost::test_tools::tt_detail::assertion_text( \
93 BOOST_TEST_LAZY_MSG( BOOST_TEST_STRINGIZE(P) ), \
94 BOOST_TEST_LAZY_MSG( arg ) ), \
95 BOOST_TEST_L(__FILE__), \
96 static_cast<std::size_t>(__LINE__), \
97 ::boost::test_tools::tt_detail::level, \
98 ::boost::test_tools::tt_detail::assertion_type() \
99 << arg, \
100 0 ); \
101} while( ::boost::test_tools::tt_detail::dummy_cond() ) \
102/**/
103
104//____________________________________________________________________________//
105
106#ifdef BOOST_TEST_TOOLS_UNDER_DEBUGGER
107
108#define BOOST_TEST_TOOL_UNIV( level, P ) \
109 BOOST_TEST_TOOL_DIRECT_IMPL( P, level, BOOST_TEST_STRINGIZE( P ) ) \
110/**/
111
112#define BOOST_TEST_TOOL_UNIV_EX( level, P, ... ) \
113 BOOST_TEST_TOOL_UNIV( level, P ) \
114/**/
115
116#elif defined(BOOST_TEST_TOOLS_DEBUGGABLE)
117
118#define BOOST_TEST_TOOL_UNIV( level, P ) \
119do { \
120 if( ::boost::debug::under_debugger() ) \
121 BOOST_TEST_TOOL_DIRECT_IMPL( P, level, BOOST_TEST_STRINGIZE( P ) ); \
122 else \
123 BOOST_TEST_TOOL_ET_IMPL( P, level ); \
124} while( ::boost::test_tools::tt_detail::dummy_cond() ) \
125/**/
126
127#define BOOST_TEST_TOOL_UNIV_EX( level, P, ... ) \
128 BOOST_TEST_TOOL_UNIV( level, P ) \
129/**/
130
131#else
132
133#define BOOST_TEST_TOOL_UNIV( level, P ) \
134 BOOST_TEST_TOOL_ET_IMPL( P, level ) \
135/**/
136
137#define BOOST_TEST_TOOL_UNIV_EX( level, P, ... ) \
138 BOOST_TEST_TOOL_ET_IMPL_EX( P, level, __VA_ARGS__ ) \
139/**/
140
141#endif
142
143//____________________________________________________________________________//
144
145#define BOOST_TEST_WARN( ... ) BOOST_TEST_INVOKE_IF_N_ARGS( \
146 2, BOOST_TEST_TOOL_UNIV, BOOST_TEST_TOOL_UNIV_EX, WARN, __VA_ARGS__ ) \
147/**/
148#define BOOST_TEST_CHECK( ... ) BOOST_TEST_INVOKE_IF_N_ARGS( \
149 2, BOOST_TEST_TOOL_UNIV, BOOST_TEST_TOOL_UNIV_EX, CHECK, __VA_ARGS__ ) \
150/**/
151#define BOOST_TEST_REQUIRE( ... ) BOOST_TEST_INVOKE_IF_N_ARGS( \
152 2, BOOST_TEST_TOOL_UNIV, BOOST_TEST_TOOL_UNIV_EX, REQUIRE, __VA_ARGS__ )\
153/**/
154
155#define BOOST_TEST( ... ) BOOST_TEST_INVOKE_IF_N_ARGS( \
156 2, BOOST_TEST_TOOL_UNIV, BOOST_TEST_TOOL_UNIV_EX, CHECK, __VA_ARGS__ ) \
157/**/
158
159//____________________________________________________________________________//
160
161#define BOOST_TEST_ERROR( M ) BOOST_CHECK_MESSAGE( false, M )
162#define BOOST_TEST_FAIL( M ) BOOST_REQUIRE_MESSAGE( false, M )
163
164//____________________________________________________________________________//
165
166#define BOOST_TEST_IS_DEFINED( symb ) ::boost::test_tools::tt_detail::is_defined_impl( symb, BOOST_STRINGIZE(= symb) )
167
168//____________________________________________________________________________//
169
170#ifdef BOOST_TEST_NO_OLD_TOOLS
171
172#ifdef BOOST_TEST_TOOLS_UNDER_DEBUGGER
173
174#define BOOST_CHECK_THROW_IMPL(S, E, TL, Ppassed, Mpassed, Pcaught, Mcaught)\
175do { try { \
176 S; \
177 BOOST_TEST_TOOL_DIRECT_IMPL( Ppassed, TL, Mpassed ); \
178} catch( E ) { \
179 BOOST_TEST_TOOL_DIRECT_IMPL( Pcaught, TL, Mcaught ); \
180}} while( ::boost::test_tools::tt_detail::dummy_cond() ) \
181/**/
182
183#elif defined(BOOST_TEST_TOOLS_DEBUGGABLE)
184
185#define BOOST_CHECK_THROW_IMPL(S, E, TL, Ppassed, Mpassed, Pcaught, Mcaught)\
186do { try { \
187 if( ::boost::debug::under_debugger() ) \
188 BOOST_TEST_PASSPOINT(); \
189 S; \
190 BOOST_TEST_TOOL_DIRECT_IMPL( Ppassed, TL, Mpassed ); \
191} catch( E ) { \
192 BOOST_TEST_TOOL_DIRECT_IMPL( Pcaught, TL, Mcaught ); \
193}} while( ::boost::test_tools::tt_detail::dummy_cond() ) \
194/**/
195
196#else
197
198#define BOOST_CHECK_THROW_IMPL(S, E, TL, Ppassed, Mpassed, Pcaught, Mcaught)\
199do { try { \
200 BOOST_TEST_PASSPOINT(); \
201 S; \
202 BOOST_TEST_TOOL_DIRECT_IMPL( Ppassed, TL, Mpassed ); \
203} catch( E ) { \
204 BOOST_TEST_TOOL_DIRECT_IMPL( Pcaught, TL, Mcaught ); \
205}} while( ::boost::test_tools::tt_detail::dummy_cond() ) \
206/**/
207
208#endif
209
210//____________________________________________________________________________//
211
212#define BOOST_WARN_THROW( S, E ) \
213 BOOST_CHECK_THROW_IMPL(S, E const&, WARN, \
214 false, "exception " BOOST_STRINGIZE(E) " is expected", \
215 true , "exception " BOOST_STRINGIZE(E) " is caught" ) \
216/**/
217#define BOOST_CHECK_THROW( S, E ) \
218 BOOST_CHECK_THROW_IMPL(S, E const&, CHECK, \
219 false, "exception " BOOST_STRINGIZE(E) " is expected", \
220 true , "exception " BOOST_STRINGIZE(E) " is caught" ) \
221/**/
222#define BOOST_REQUIRE_THROW( S, E ) \
223 BOOST_CHECK_THROW_IMPL(S, E const&, REQUIRE, \
224 false, "exception " BOOST_STRINGIZE(E) " is expected", \
225 true , "exception " BOOST_STRINGIZE(E) " is caught" ) \
226/**/
227
228//____________________________________________________________________________//
229
230#define BOOST_WARN_EXCEPTION( S, E, P ) \
231 BOOST_CHECK_THROW_IMPL(S, E const& ex, WARN, \
232 false, "exception " BOOST_STRINGIZE(E) " is expected", \
233 P(ex), "incorrect exception " BOOST_STRINGIZE(E) " is caught" ) \
234/**/
235#define BOOST_CHECK_EXCEPTION( S, E, P ) \
236 BOOST_CHECK_THROW_IMPL(S, E const& ex, CHECK, \
237 false, "exception " BOOST_STRINGIZE(E) " is expected", \
238 P(ex), "incorrect exception " BOOST_STRINGIZE(E) " is caught" ) \
239/**/
240#define BOOST_REQUIRE_EXCEPTION( S, E, P ) \
241 BOOST_CHECK_THROW_IMPL(S, E const& ex, REQUIRE, \
242 false, "exception " BOOST_STRINGIZE(E) " is expected", \
243 P(ex), "incorrect exception " BOOST_STRINGIZE(E) " is caught" ) \
244/**/
245
246//____________________________________________________________________________//
247
248#define BOOST_WARN_NO_THROW( S ) \
249 BOOST_CHECK_THROW_IMPL(S, ..., WARN, \
250 true , "no exceptions thrown by " BOOST_STRINGIZE( S ), \
251 false, "exception thrown by " BOOST_STRINGIZE( S ) ) \
252/**/
253#define BOOST_CHECK_NO_THROW( S ) \
254 BOOST_CHECK_THROW_IMPL(S, ..., CHECK, \
255 true , "no exceptions thrown by " BOOST_STRINGIZE( S ), \
256 false, "exception thrown by " BOOST_STRINGIZE( S ) ) \
257/**/
258#define BOOST_REQUIRE_NO_THROW( S ) \
259 BOOST_CHECK_THROW_IMPL(S, ..., REQUIRE, \
260 true , "no exceptions thrown by " BOOST_STRINGIZE( S ), \
261 false, "exception thrown by " BOOST_STRINGIZE( S ) ) \
262/**/
263
264//____________________________________________________________________________//
265
266#define BOOST_WARN_MESSAGE( P, M ) BOOST_TEST_TOOL_DIRECT_IMPL( P, WARN, M )
267#define BOOST_CHECK_MESSAGE( P, M ) BOOST_TEST_TOOL_DIRECT_IMPL( P, CHECK, M )
268#define BOOST_REQUIRE_MESSAGE( P, M ) BOOST_TEST_TOOL_DIRECT_IMPL( P, REQUIRE, M )
269
270//____________________________________________________________________________//
271
272////////////////////////////////////////////////////////////////////////////////
273///////////////////////////// DEPRECATED TOOLS /////////////////////////////
274
275#define BOOST_WARN( P ) BOOST_TEST_WARN( P )
276#define BOOST_CHECK( P ) BOOST_TEST_CHECK( P )
277#define BOOST_REQUIRE( P ) BOOST_TEST_REQUIRE( P )
278
279//____________________________________________________________________________//
280
281#define BOOST_ERROR( M ) BOOST_TEST_ERROR( M )
282#define BOOST_FAIL( M ) BOOST_TEST_FAIL( M )
283
284//____________________________________________________________________________//
285
286#define BOOST_WARN_EQUAL( L, R ) BOOST_TEST_WARN( L == R )
287#define BOOST_CHECK_EQUAL( L, R ) BOOST_TEST_CHECK( L == R )
288#define BOOST_REQUIRE_EQUAL( L, R ) BOOST_TEST_REQUIRE( L == R )
289
290#define BOOST_WARN_NE( L, R ) BOOST_TEST_WARN( L != R )
291#define BOOST_CHECK_NE( L, R ) BOOST_TEST_CHECK( L != R )
292#define BOOST_REQUIRE_NE( L, R ) BOOST_TEST_REQUIRE( L != R )
293
294#define BOOST_WARN_LT( L, R ) BOOST_TEST_WARN( L < R )
295#define BOOST_CHECK_LT( L, R ) BOOST_TEST_CHECK( L < R )
296#define BOOST_REQUIRE_LT( L, R ) BOOST_TEST_REQUIRE( L < R )
297
298#define BOOST_WARN_LE( L, R ) BOOST_TEST_WARN( L <= R )
299#define BOOST_CHECK_LE( L, R ) BOOST_TEST_CHECK( L <= R )
300#define BOOST_REQUIRE_LE( L, R ) BOOST_TEST_REQUIRE( L <= R )
301
302#define BOOST_WARN_GT( L, R ) BOOST_TEST_WARN( L > R )
303#define BOOST_CHECK_GT( L, R ) BOOST_TEST_CHECK( L > R )
304#define BOOST_REQUIRE_GT( L, R ) BOOST_TEST_REQUIRE( L > R )
305
306#define BOOST_WARN_GE( L, R ) BOOST_TEST_WARN( L >= R )
307#define BOOST_CHECK_GE( L, R ) BOOST_TEST_CHECK( L >= R )
308#define BOOST_REQUIRE_GE( L, R ) BOOST_TEST_REQUIRE( L >= R )
309
310//____________________________________________________________________________//
311
312#define BOOST_WARN_CLOSE( L, R, T ) BOOST_TEST_WARN( L == R, T % ::boost::test_tools::tolerance() )
313#define BOOST_CHECK_CLOSE( L, R, T ) BOOST_TEST_CHECK( L == R, T % ::boost::test_tools::tolerance() )
314#define BOOST_REQUIRE_CLOSE( L, R, T ) BOOST_TEST_REQUIRE( L == R, T % ::boost::test_tools::tolerance() )
315
316#define BOOST_WARN_CLOSE_FRACTION(L, R, T) BOOST_TEST_WARN( L == R, ::boost::test_tools::tolerance( T ) )
317#define BOOST_CHECK_CLOSE_FRACTION(L, R, T) BOOST_TEST_CHECK( L == R, ::boost::test_tools::tolerance( T ) )
318#define BOOST_REQUIRE_CLOSE_FRACTION(L,R,T) BOOST_TEST_REQUIRE( L == R, ::boost::test_tools::tolerance( T ) )
319
320#define BOOST_WARN_SMALL( FPV, T ) BOOST_TEST_WARN( FPV == 0., ::boost::test_tools::tolerance( T ) )
321#define BOOST_CHECK_SMALL( FPV, T ) BOOST_TEST_CHECK( FPV == 0., ::boost::test_tools::tolerance( T ) )
322#define BOOST_REQUIRE_SMALL( FPV, T ) BOOST_TEST_REQUIRE( FPV == 0., ::boost::test_tools::tolerance( T ) )
323
324//____________________________________________________________________________//
325
326#define BOOST_WARN_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
327 BOOST_TEST_WARN( ::boost::test_tools::tt_detail::make_it_pair(L_begin, L_end) ==\
328 ::boost::test_tools::tt_detail::make_it_pair(R_begin, R_end), \
329 ::boost::test_tools::per_element() ) \
330/**/
331
332#define BOOST_CHECK_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
333 BOOST_TEST_CHECK( ::boost::test_tools::tt_detail::make_it_pair(L_begin, L_end) ==\
334 ::boost::test_tools::tt_detail::make_it_pair(R_begin, R_end), \
335 ::boost::test_tools::per_element() ) \
336/**/
337
338#define BOOST_REQUIRE_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
339 BOOST_TEST_REQUIRE( ::boost::test_tools::tt_detail::make_it_pair(L_begin, L_end) ==\
340 ::boost::test_tools::tt_detail::make_it_pair(R_begin, R_end), \
341 ::boost::test_tools::per_element() ) \
342/**/
343
344//____________________________________________________________________________//
345
346#define BOOST_WARN_BITWISE_EQUAL( L, R ) BOOST_TEST_WARN( L == R, ::boost::test_tools::bitwise() )
347#define BOOST_CHECK_BITWISE_EQUAL( L, R ) BOOST_TEST_CHECK( L == R, ::boost::test_tools::bitwise() )
348#define BOOST_REQUIRE_BITWISE_EQUAL( L, R ) BOOST_TEST_REQUIRE( L == R, ::boost::test_tools::bitwise() )
349
350//____________________________________________________________________________//
351
352#define BOOST_WARN_PREDICATE( P, ARGS ) BOOST_TEST_WARN( P BOOST_PP_SEQ_TO_TUPLE(ARGS) )
353#define BOOST_CHECK_PREDICATE( P, ARGS ) BOOST_TEST_CHECK( P BOOST_PP_SEQ_TO_TUPLE(ARGS) )
354#define BOOST_REQUIRE_PREDICATE( P, ARGS ) BOOST_TEST_REQUIRE( P BOOST_PP_SEQ_TO_TUPLE(ARGS) )
355
356//____________________________________________________________________________//
357
358#define BOOST_IS_DEFINED( symb ) ::boost::test_tools::tt_detail::is_defined_impl( #symb, BOOST_STRINGIZE(= symb) )
359
360//____________________________________________________________________________//
361
362#endif // BOOST_TEST_NO_OLD_TOOLS
363
364#include <boost/test/detail/enable_warnings.hpp>
365
366#endif // BOOST_TEST_TOOLS_INTERFACE_HPP_111712GER
367

source code of include/boost/test/tools/interface.hpp