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