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

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