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 old test toolbox
13// ***************************************************************************
14
15#ifndef BOOST_TEST_TOOLS_OLD_INTERFACE_HPP_111712GER
16#define BOOST_TEST_TOOLS_OLD_INTERFACE_HPP_111712GER
17
18// Boost
19#include <boost/preprocessor/seq/for_each.hpp>
20#include <boost/preprocessor/seq/size.hpp>
21#include <boost/preprocessor/seq/to_tuple.hpp>
22
23#include <boost/test/detail/suppress_warnings.hpp>
24
25//____________________________________________________________________________//
26
27// ************************************************************************** //
28// ************** TOOL BOX ************** //
29// ************************************************************************** //
30
31// In macros below following argument abbreviations are used:
32// P - predicate
33// M - message
34// S - statement
35// E - exception
36// L - left argument
37// R - right argument
38// TL - tool level
39// CT - check type
40// ARGS - arguments list (as PP sequence)
41
42// frwd_type:
43// 0 - args exists and need to be forwarded; call check_frwd
44// 1 - args exists, but do not need to be forwarded; call report_assertion directly
45// 2 - no arguments; call report_assertion directly
46
47#define BOOST_TEST_TOOL_PASS_PRED0( P, ARGS ) P
48#define BOOST_TEST_TOOL_PASS_PRED1( P, ARGS ) P BOOST_PP_SEQ_TO_TUPLE(ARGS)
49#define BOOST_TEST_TOOL_PASS_PRED2( P, ARGS ) P
50
51#define BOOST_TEST_TOOL_PASS_ARG( r, _, arg ) , arg, BOOST_STRINGIZE( arg )
52#define BOOST_TEST_TOOL_PASS_ARG_DSCR( r, _, arg ) , BOOST_STRINGIZE( arg )
53
54#define BOOST_TEST_TOOL_PASS_ARGS0( ARGS ) \
55 BOOST_PP_SEQ_FOR_EACH( BOOST_TEST_TOOL_PASS_ARG, _, ARGS )
56#define BOOST_TEST_TOOL_PASS_ARGS1( ARGS ) \
57 , BOOST_PP_SEQ_SIZE(ARGS) BOOST_PP_SEQ_FOR_EACH( BOOST_TEST_TOOL_PASS_ARG_DSCR, _, ARGS )
58#define BOOST_TEST_TOOL_PASS_ARGS2( ARGS ) \
59 , 0
60
61#define BOOST_TEST_TOOL_IMPL( frwd_type, P, assertion_descr, TL, CT, ARGS ) \
62do { \
63 BOOST_TEST_PASSPOINT(); \
64 ::boost::test_tools::tt_detail:: \
65 BOOST_PP_IF( frwd_type, report_assertion, check_frwd ) ( \
66 BOOST_JOIN( BOOST_TEST_TOOL_PASS_PRED, frwd_type )( P, ARGS ), \
67 BOOST_TEST_LAZY_MSG( assertion_descr ), \
68 BOOST_TEST_L(__FILE__), \
69 static_cast<std::size_t>(__LINE__), \
70 ::boost::test_tools::tt_detail::TL, \
71 ::boost::test_tools::tt_detail::CT \
72 BOOST_JOIN( BOOST_TEST_TOOL_PASS_ARGS, frwd_type )( ARGS ) ); \
73} while( ::boost::test_tools::tt_detail::dummy_cond() ) \
74/**/
75
76//____________________________________________________________________________//
77
78#define BOOST_WARN( P ) BOOST_TEST_TOOL_IMPL( 2, \
79 (P), BOOST_TEST_STRINGIZE( P ), WARN, CHECK_PRED, _ )
80#define BOOST_CHECK( P ) BOOST_TEST_TOOL_IMPL( 2, \
81 (P), BOOST_TEST_STRINGIZE( P ), CHECK, CHECK_PRED, _ )
82#define BOOST_REQUIRE( P ) BOOST_TEST_TOOL_IMPL( 2, \
83 (P), BOOST_TEST_STRINGIZE( P ), REQUIRE, CHECK_PRED, _ )
84
85//____________________________________________________________________________//
86
87#define BOOST_WARN_MESSAGE( P, M ) BOOST_TEST_TOOL_IMPL( 2, (P), M, WARN, CHECK_MSG, _ )
88#define BOOST_CHECK_MESSAGE( P, M ) BOOST_TEST_TOOL_IMPL( 2, (P), M, CHECK, CHECK_MSG, _ )
89#define BOOST_REQUIRE_MESSAGE( P, M ) BOOST_TEST_TOOL_IMPL( 2, (P), M, REQUIRE, CHECK_MSG, _ )
90
91//____________________________________________________________________________//
92
93#define BOOST_ERROR( M ) BOOST_CHECK_MESSAGE( false, M )
94#define BOOST_FAIL( M ) BOOST_REQUIRE_MESSAGE( false, M )
95
96//____________________________________________________________________________//
97
98#define BOOST_CHECK_THROW_IMPL( S, E, P, postfix, TL ) \
99do { \
100 try { \
101 BOOST_TEST_PASSPOINT(); \
102 S; \
103 BOOST_TEST_TOOL_IMPL( 2, false, "exception " BOOST_STRINGIZE(E) " expected but not raised", \
104 TL, CHECK_MSG, _ ); \
105 } catch( E const& ex ) { \
106 ::boost::unit_test::ut_detail::ignore_unused_variable_warning( ex ); \
107 BOOST_TEST_TOOL_IMPL( 2, P, \
108 "exception \"" BOOST_STRINGIZE( E )"\" raised as expected" postfix, \
109 TL, CHECK_MSG, _ ); \
110 } \
111} while( ::boost::test_tools::tt_detail::dummy_cond() ) \
112/**/
113
114//____________________________________________________________________________//
115
116#define BOOST_WARN_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "", WARN )
117#define BOOST_CHECK_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "", CHECK )
118#define BOOST_REQUIRE_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "", REQUIRE )
119
120//____________________________________________________________________________//
121
122#define BOOST_WARN_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), \
123 ": validation on the raised exception through predicate \"" BOOST_STRINGIZE(P) "\"", WARN )
124#define BOOST_CHECK_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), \
125 ": validation on the raised exception through predicate \"" BOOST_STRINGIZE(P) "\"", CHECK )
126#define BOOST_REQUIRE_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), \
127 ": validation on the raised exception through predicate \"" BOOST_STRINGIZE(P) "\"", REQUIRE )
128
129//____________________________________________________________________________//
130
131#define BOOST_CHECK_NO_THROW_IMPL( S, TL ) \
132do { \
133 try { \
134 S; \
135 BOOST_TEST_TOOL_IMPL( 2, true, "no exceptions thrown by " BOOST_STRINGIZE( S ), \
136 TL, CHECK_MSG, _ ); \
137 } catch( ... ) { \
138 BOOST_TEST_TOOL_IMPL( 2, false, "unexpected exception thrown by " BOOST_STRINGIZE( S ), \
139 TL, CHECK_MSG, _ ); \
140 } \
141} while( ::boost::test_tools::tt_detail::dummy_cond() ) \
142/**/
143
144#define BOOST_WARN_NO_THROW( S ) BOOST_CHECK_NO_THROW_IMPL( S, WARN )
145#define BOOST_CHECK_NO_THROW( S ) BOOST_CHECK_NO_THROW_IMPL( S, CHECK )
146#define BOOST_REQUIRE_NO_THROW( S ) BOOST_CHECK_NO_THROW_IMPL( S, REQUIRE )
147
148//____________________________________________________________________________//
149
150#define BOOST_WARN_EQUAL( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
151 ::boost::test_tools::tt_detail::equal_impl_frwd(), "", WARN, CHECK_EQUAL, (L)(R) )
152#define BOOST_CHECK_EQUAL( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
153 ::boost::test_tools::tt_detail::equal_impl_frwd(), "", CHECK, CHECK_EQUAL, (L)(R) )
154#define BOOST_REQUIRE_EQUAL( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
155 ::boost::test_tools::tt_detail::equal_impl_frwd(), "", REQUIRE, CHECK_EQUAL, (L)(R) )
156
157//____________________________________________________________________________//
158
159#define BOOST_WARN_NE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
160 ::boost::test_tools::tt_detail::ne_impl(), "", WARN, CHECK_NE, (L)(R) )
161#define BOOST_CHECK_NE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
162 ::boost::test_tools::tt_detail::ne_impl(), "", CHECK, CHECK_NE, (L)(R) )
163#define BOOST_REQUIRE_NE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
164 ::boost::test_tools::tt_detail::ne_impl(), "", REQUIRE, CHECK_NE, (L)(R) )
165
166//____________________________________________________________________________//
167
168#define BOOST_WARN_LT( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
169 ::boost::test_tools::tt_detail::lt_impl(), "", WARN, CHECK_LT, (L)(R) )
170#define BOOST_CHECK_LT( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
171 ::boost::test_tools::tt_detail::lt_impl(), "", CHECK, CHECK_LT, (L)(R) )
172#define BOOST_REQUIRE_LT( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
173 ::boost::test_tools::tt_detail::lt_impl(), "", REQUIRE, CHECK_LT, (L)(R) )
174
175//____________________________________________________________________________//
176
177#define BOOST_WARN_LE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
178 ::boost::test_tools::tt_detail::le_impl(), "", WARN, CHECK_LE, (L)(R) )
179#define BOOST_CHECK_LE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
180 ::boost::test_tools::tt_detail::le_impl(), "", CHECK, CHECK_LE, (L)(R) )
181#define BOOST_REQUIRE_LE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
182 ::boost::test_tools::tt_detail::le_impl(), "", REQUIRE, CHECK_LE, (L)(R) )
183
184//____________________________________________________________________________//
185
186#define BOOST_WARN_GT( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
187 ::boost::test_tools::tt_detail::gt_impl(), "", WARN, CHECK_GT, (L)(R) )
188#define BOOST_CHECK_GT( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
189 ::boost::test_tools::tt_detail::gt_impl(), "", CHECK, CHECK_GT, (L)(R) )
190#define BOOST_REQUIRE_GT( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
191 ::boost::test_tools::tt_detail::gt_impl(), "", REQUIRE, CHECK_GT, (L)(R) )
192
193//____________________________________________________________________________//
194
195#define BOOST_WARN_GE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
196 ::boost::test_tools::tt_detail::ge_impl(), "", WARN, CHECK_GE, (L)(R) )
197#define BOOST_CHECK_GE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
198 ::boost::test_tools::tt_detail::ge_impl(), "", CHECK, CHECK_GE, (L)(R) )
199#define BOOST_REQUIRE_GE( L, R ) BOOST_TEST_TOOL_IMPL( 0, \
200 ::boost::test_tools::tt_detail::ge_impl(), "", REQUIRE, CHECK_GE, (L)(R) )
201
202//____________________________________________________________________________//
203
204#define BOOST_WARN_CLOSE( L, R, T ) BOOST_TEST_TOOL_IMPL( 0, \
205 ::boost::test_tools::check_is_close_t(), "", WARN, CHECK_CLOSE, (L)(R)(::boost::math::fpc::percent_tolerance(T)) )
206#define BOOST_CHECK_CLOSE( L, R, T ) BOOST_TEST_TOOL_IMPL( 0, \
207 ::boost::test_tools::check_is_close_t(), "", CHECK, CHECK_CLOSE, (L)(R)(::boost::math::fpc::percent_tolerance(T)) )
208#define BOOST_REQUIRE_CLOSE( L, R, T ) BOOST_TEST_TOOL_IMPL( 0, \
209 ::boost::test_tools::check_is_close_t(), "", REQUIRE, CHECK_CLOSE, (L)(R)(::boost::math::fpc::percent_tolerance(T)) )
210
211//____________________________________________________________________________//
212
213#define BOOST_WARN_CLOSE_FRACTION(L, R, T) BOOST_TEST_TOOL_IMPL( 0, \
214 ::boost::test_tools::check_is_close_t(), "", WARN, CHECK_CLOSE_FRACTION, (L)(R)(T) )
215#define BOOST_CHECK_CLOSE_FRACTION(L, R, T) BOOST_TEST_TOOL_IMPL( 0, \
216 ::boost::test_tools::check_is_close_t(), "", CHECK, CHECK_CLOSE_FRACTION, (L)(R)(T) )
217#define BOOST_REQUIRE_CLOSE_FRACTION(L,R,T) BOOST_TEST_TOOL_IMPL( 0, \
218 ::boost::test_tools::check_is_close_t(), "", REQUIRE, CHECK_CLOSE_FRACTION, (L)(R)(T) )
219
220//____________________________________________________________________________//
221
222#define BOOST_WARN_SMALL( FPV, T ) BOOST_TEST_TOOL_IMPL( 0, \
223 ::boost::test_tools::check_is_small_t(), "", WARN, CHECK_SMALL, (FPV)(T) )
224#define BOOST_CHECK_SMALL( FPV, T ) BOOST_TEST_TOOL_IMPL( 0, \
225 ::boost::test_tools::check_is_small_t(), "", CHECK, CHECK_SMALL, (FPV)(T) )
226#define BOOST_REQUIRE_SMALL( FPV, T ) BOOST_TEST_TOOL_IMPL( 0, \
227 ::boost::test_tools::check_is_small_t(), "", REQUIRE, CHECK_SMALL, (FPV)(T) )
228
229//____________________________________________________________________________//
230
231#define BOOST_WARN_PREDICATE( P, ARGS ) BOOST_TEST_TOOL_IMPL( 0, \
232 P, BOOST_TEST_STRINGIZE( P ), WARN, CHECK_PRED_WITH_ARGS, ARGS )
233#define BOOST_CHECK_PREDICATE( P, ARGS ) BOOST_TEST_TOOL_IMPL( 0, \
234 P, BOOST_TEST_STRINGIZE( P ), CHECK, CHECK_PRED_WITH_ARGS, ARGS )
235#define BOOST_REQUIRE_PREDICATE( P, ARGS ) BOOST_TEST_TOOL_IMPL( 0, \
236 P, BOOST_TEST_STRINGIZE( P ), REQUIRE, CHECK_PRED_WITH_ARGS, ARGS )
237
238//____________________________________________________________________________//
239
240#define BOOST_WARN_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
241 BOOST_TEST_TOOL_IMPL( 1, ::boost::test_tools::tt_detail::equal_coll_impl(), \
242 "", WARN, CHECK_EQUAL_COLL, (L_begin)(L_end)(R_begin)(R_end) ) \
243/**/
244#define BOOST_CHECK_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
245 BOOST_TEST_TOOL_IMPL( 1, ::boost::test_tools::tt_detail::equal_coll_impl(), \
246 "", CHECK, CHECK_EQUAL_COLL, (L_begin)(L_end)(R_begin)(R_end) ) \
247/**/
248#define BOOST_REQUIRE_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
249 BOOST_TEST_TOOL_IMPL( 1, ::boost::test_tools::tt_detail::equal_coll_impl(), \
250 "", REQUIRE, CHECK_EQUAL_COLL, (L_begin)(L_end)(R_begin)(R_end) ) \
251/**/
252
253//____________________________________________________________________________//
254
255#define BOOST_WARN_BITWISE_EQUAL( L, R ) BOOST_TEST_TOOL_IMPL( 1, \
256 ::boost::test_tools::tt_detail::bitwise_equal_impl(), "", WARN, CHECK_BITWISE_EQUAL, (L)(R) )
257#define BOOST_CHECK_BITWISE_EQUAL( L, R ) BOOST_TEST_TOOL_IMPL( 1, \
258 ::boost::test_tools::tt_detail::bitwise_equal_impl(), "", CHECK, CHECK_BITWISE_EQUAL, (L)(R) )
259#define BOOST_REQUIRE_BITWISE_EQUAL( L, R ) BOOST_TEST_TOOL_IMPL( 1, \
260 ::boost::test_tools::tt_detail::bitwise_equal_impl(), "", REQUIRE, CHECK_BITWISE_EQUAL, (L)(R) )
261
262//____________________________________________________________________________//
263
264#define BOOST_IS_DEFINED( symb ) ::boost::test_tools::tt_detail::is_defined_impl( #symb, BOOST_STRINGIZE(= symb) )
265
266//____________________________________________________________________________//
267
268#ifdef BOOST_TEST_NO_NEW_TOOLS
269
270#define BOOST_TEST_WARN( P ) BOOST_WARN( P )
271#define BOOST_TEST_CHECK( P ) BOOST_CHECK( P )
272#define BOOST_TEST_REQUIRE( P ) BOOST_REQUIRE( P )
273
274#define BOOST_TEST( P ) BOOST_CHECK( P )
275
276#endif
277
278//____________________________________________________________________________//
279
280#include <boost/test/detail/enable_warnings.hpp>
281
282#endif // BOOST_TEST_TOOLS_OLD_INTERFACE_HPP_111712GER
283