1 // (C) Copyright Gennadiy Rozental 2001-2008.
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)
6 // See http://www.boost.org/libs/test for the library home page.
10 // Version : $Revision$
12 // Description : contains definition for all test tools in test toolbox
13 // ***************************************************************************
15 #ifndef BOOST_TEST_TEST_TOOLS_HPP_012705GER
16 #define BOOST_TEST_TEST_TOOLS_HPP_012705GER
19 #include <boost/test/predicate_result.hpp>
20 #include <boost/test/unit_test_log.hpp>
21 #include <boost/test/floating_point_comparison.hpp>
23 #include <boost/test/detail/config.hpp>
24 #include <boost/test/detail/global_typedef.hpp>
25 #include <boost/test/detail/workaround.hpp>
27 #include <boost/test/utils/wrap_stringstream.hpp>
28 #include <boost/test/utils/basic_cstring/io.hpp>
29 #include <boost/test/utils/lazy_ostream.hpp>
32 #include <boost/preprocessor/seq/for_each.hpp>
33 #include <boost/preprocessor/seq/size.hpp>
34 #include <boost/preprocessor/seq/enum.hpp>
35 #include <boost/preprocessor/repetition/repeat.hpp>
36 #include <boost/preprocessor/punctuation/comma_if.hpp>
37 #include <boost/preprocessor/arithmetic/add.hpp>
39 #include <boost/limits.hpp>
41 #include <boost/type_traits/is_array.hpp>
42 #include <boost/type_traits/is_function.hpp>
43 #include <boost/type_traits/is_abstract.hpp>
45 #include <boost/mpl/or.hpp>
48 #include <cstddef> // for std::size_t
50 #include <ios> // for std::boolalpha
51 #include <climits> // for CHAR_BIT
54 # pragma warning(disable: 4127) // conditional expression is constant
57 #include <boost/test/detail/suppress_warnings.hpp>
59 //____________________________________________________________________________//
61 // ************************************************************************** //
62 // ************** TOOL BOX ************** //
63 // ************************************************************************** //
65 // In macros below following argument abbreviations are used:
74 // ARGS - arguments list
76 #define BOOST_TEST_TOOL_IMPL( func, P, check_descr, TL, CT ) \
77 ::boost::test_tools::tt_detail::func( \
79 ::boost::unit_test::lazy_ostream::instance() << check_descr, \
80 BOOST_TEST_L(__FILE__), \
81 (std::size_t)__LINE__, \
82 ::boost::test_tools::tt_detail::TL, \
83 ::boost::test_tools::tt_detail::CT \
86 //____________________________________________________________________________//
88 #define BOOST_CHECK_IMPL( P, check_descr, TL, CT ) \
90 BOOST_TEST_PASSPOINT(); \
91 BOOST_TEST_TOOL_IMPL( check_impl, P, check_descr, TL, CT ), 0 );\
92 } while( ::boost::test_tools::dummy_cond ) \
95 //____________________________________________________________________________//
97 #define BOOST_TEST_PASS_ARG_INFO( r, data, arg ) , arg, BOOST_STRINGIZE( arg )
99 #define BOOST_CHECK_WITH_ARGS_IMPL( P, check_descr, TL, CT, ARGS ) \
101 BOOST_TEST_PASSPOINT(); \
102 BOOST_TEST_TOOL_IMPL( check_frwd, P, check_descr, TL, CT ) \
103 BOOST_PP_SEQ_FOR_EACH( BOOST_TEST_PASS_ARG_INFO, '_', ARGS ) ); \
104 } while( ::boost::test_tools::dummy_cond ) \
107 //____________________________________________________________________________//
109 #define BOOST_WARN( P ) BOOST_CHECK_IMPL( (P), BOOST_TEST_STRINGIZE( P ), WARN, CHECK_PRED )
110 #define BOOST_CHECK( P ) BOOST_CHECK_IMPL( (P), BOOST_TEST_STRINGIZE( P ), CHECK, CHECK_PRED )
111 #define BOOST_REQUIRE( P ) BOOST_CHECK_IMPL( (P), BOOST_TEST_STRINGIZE( P ), REQUIRE, CHECK_PRED )
113 //____________________________________________________________________________//
115 #define BOOST_WARN_MESSAGE( P, M ) BOOST_CHECK_IMPL( (P), M, WARN, CHECK_MSG )
116 #define BOOST_CHECK_MESSAGE( P, M ) BOOST_CHECK_IMPL( (P), M, CHECK, CHECK_MSG )
117 #define BOOST_REQUIRE_MESSAGE( P, M ) BOOST_CHECK_IMPL( (P), M, REQUIRE, CHECK_MSG )
119 //____________________________________________________________________________//
121 #define BOOST_ERROR( M ) BOOST_CHECK_MESSAGE( false, M )
122 #define BOOST_FAIL( M ) BOOST_REQUIRE_MESSAGE( false, M )
124 //____________________________________________________________________________//
126 #define BOOST_CHECK_THROW_IMPL( S, E, P, prefix, TL ) \
128 BOOST_TEST_PASSPOINT(); \
130 BOOST_CHECK_IMPL( false, "exception " BOOST_STRINGIZE( E ) " is expected", TL, CHECK_MSG ); } \
131 catch( E const& ex ) { \
132 ::boost::unit_test::ut_detail::ignore_unused_variable_warning( ex ); \
133 BOOST_CHECK_IMPL( P, prefix BOOST_STRINGIZE( E ) " is caught", TL, CHECK_MSG ); \
137 //____________________________________________________________________________//
139 #define BOOST_WARN_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "exception ", WARN )
140 #define BOOST_CHECK_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "exception ", CHECK )
141 #define BOOST_REQUIRE_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "exception ", REQUIRE )
143 //____________________________________________________________________________//
145 #define BOOST_WARN_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), "incorrect exception ", WARN )
146 #define BOOST_CHECK_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), "incorrect exception ", CHECK )
147 #define BOOST_REQUIRE_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), "incorrect exception ", REQUIRE )
149 //____________________________________________________________________________//
151 #define BOOST_CHECK_NO_THROW_IMPL( S, TL ) \
154 BOOST_CHECK_IMPL( true, "no exceptions thrown by " BOOST_STRINGIZE( S ), TL, CHECK_MSG ); } \
156 BOOST_CHECK_IMPL( false, "exception thrown by " BOOST_STRINGIZE( S ), TL, CHECK_MSG ); \
160 #define BOOST_WARN_NO_THROW( S ) BOOST_CHECK_NO_THROW_IMPL( S, WARN )
161 #define BOOST_CHECK_NO_THROW( S ) BOOST_CHECK_NO_THROW_IMPL( S, CHECK )
162 #define BOOST_REQUIRE_NO_THROW( S ) BOOST_CHECK_NO_THROW_IMPL( S, REQUIRE )
164 //____________________________________________________________________________//
166 #define BOOST_WARN_EQUAL( L, R ) \
167 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::equal_impl_frwd(), "", WARN, CHECK_EQUAL, (L)(R) )
168 #define BOOST_CHECK_EQUAL( L, R ) \
169 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::equal_impl_frwd(), "", CHECK, CHECK_EQUAL, (L)(R) )
170 #define BOOST_REQUIRE_EQUAL( L, R ) \
171 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::equal_impl_frwd(), "", REQUIRE, CHECK_EQUAL, (L)(R) )
173 //____________________________________________________________________________//
175 #define BOOST_WARN_NE( L, R ) \
176 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::ne_impl(), "", WARN, CHECK_NE, (L)(R) )
177 #define BOOST_CHECK_NE( L, R ) \
178 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::ne_impl(), "", CHECK, CHECK_NE, (L)(R) )
179 #define BOOST_REQUIRE_NE( L, R ) \
180 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::ne_impl(), "", REQUIRE, CHECK_NE, (L)(R) )
182 //____________________________________________________________________________//
184 #define BOOST_WARN_LT( L, R ) \
185 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::lt_impl(), "", WARN, CHECK_LT, (L)(R) )
186 #define BOOST_CHECK_LT( L, R ) \
187 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::lt_impl(), "", CHECK, CHECK_LT, (L)(R) )
188 #define BOOST_REQUIRE_LT( L, R ) \
189 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::lt_impl(), "", REQUIRE, CHECK_LT, (L)(R) )
191 //____________________________________________________________________________//
193 #define BOOST_WARN_LE( L, R ) \
194 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::le_impl(), "", WARN, CHECK_LE, (L)(R) )
195 #define BOOST_CHECK_LE( L, R ) \
196 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::le_impl(), "", CHECK, CHECK_LE, (L)(R) )
197 #define BOOST_REQUIRE_LE( L, R ) \
198 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::le_impl(), "", REQUIRE, CHECK_LE, (L)(R) )
200 //____________________________________________________________________________//
202 #define BOOST_WARN_GT( L, R ) \
203 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::gt_impl(), "", WARN, CHECK_GT, (L)(R) )
204 #define BOOST_CHECK_GT( L, R ) \
205 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::gt_impl(), "", CHECK, CHECK_GT, (L)(R) )
206 #define BOOST_REQUIRE_GT( L, R ) \
207 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::gt_impl(), "", REQUIRE, CHECK_GT, (L)(R) )
209 //____________________________________________________________________________//
211 #define BOOST_WARN_GE( L, R ) \
212 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::ge_impl(), "", WARN, CHECK_GE, (L)(R) )
213 #define BOOST_CHECK_GE( L, R ) \
214 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::ge_impl(), "", CHECK, CHECK_GE, (L)(R) )
215 #define BOOST_REQUIRE_GE( L, R ) \
216 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::ge_impl(), "", REQUIRE, CHECK_GE, (L)(R) )
218 //____________________________________________________________________________//
220 #define BOOST_WARN_CLOSE( L, R, T ) \
221 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", WARN, CHECK_CLOSE, \
222 (L)(R)(::boost::test_tools::percent_tolerance(T)) )
223 #define BOOST_CHECK_CLOSE( L, R, T ) \
224 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", CHECK, CHECK_CLOSE, \
225 (L)(R)(::boost::test_tools::percent_tolerance(T)) )
226 #define BOOST_REQUIRE_CLOSE( L, R, T ) \
227 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", REQUIRE, CHECK_CLOSE, \
228 (L)(R)(::boost::test_tools::percent_tolerance(T)) )
230 //____________________________________________________________________________//
232 #define BOOST_WARN_CLOSE_FRACTION( L, R, T ) \
233 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", WARN, CHECK_CLOSE_FRACTION, \
234 (L)(R)(::boost::test_tools::fraction_tolerance(T)) )
235 #define BOOST_CHECK_CLOSE_FRACTION( L, R, T ) \
236 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", CHECK, CHECK_CLOSE_FRACTION, \
237 (L)(R)(::boost::test_tools::fraction_tolerance(T)) )
238 #define BOOST_REQUIRE_CLOSE_FRACTION( L, R, T ) \
239 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", REQUIRE, CHECK_CLOSE_FRACTION, \
240 (L)(R)(::boost::test_tools::fraction_tolerance(T)) )
242 //____________________________________________________________________________//
244 #define BOOST_WARN_SMALL( FPV, T ) \
245 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_small, "", WARN, CHECK_SMALL, (FPV)(T) )
246 #define BOOST_CHECK_SMALL( FPV, T ) \
247 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_small, "", CHECK, CHECK_SMALL, (FPV)(T) )
248 #define BOOST_REQUIRE_SMALL( FPV, T ) \
249 BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_small, "", REQUIRE, CHECK_SMALL, (FPV)(T) )
251 //____________________________________________________________________________//
253 #define BOOST_WARN_PREDICATE( P, ARGS ) \
254 BOOST_CHECK_WITH_ARGS_IMPL( P, BOOST_TEST_STRINGIZE( P ), WARN, CHECK_PRED_WITH_ARGS, ARGS )
255 #define BOOST_CHECK_PREDICATE( P, ARGS ) \
256 BOOST_CHECK_WITH_ARGS_IMPL( P, BOOST_TEST_STRINGIZE( P ), CHECK, CHECK_PRED_WITH_ARGS, ARGS )
257 #define BOOST_REQUIRE_PREDICATE( P, ARGS ) \
258 BOOST_CHECK_WITH_ARGS_IMPL( P, BOOST_TEST_STRINGIZE( P ), REQUIRE, CHECK_PRED_WITH_ARGS, ARGS )
260 //____________________________________________________________________________//
262 #define BOOST_EQUAL_COLLECTIONS_IMPL( L_begin, L_end, R_begin, R_end, TL ) \
263 BOOST_TEST_TOOL_IMPL( check_impl, ::boost::test_tools::tt_detail::equal_coll_impl( \
264 (L_begin), (L_end), (R_begin), (R_end) ), "", TL, CHECK_EQUAL_COLL ), \
266 BOOST_STRINGIZE( L_begin ), BOOST_STRINGIZE( L_end ), \
267 BOOST_STRINGIZE( R_begin ), BOOST_STRINGIZE( R_end ) ) \
270 #define BOOST_WARN_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
271 BOOST_EQUAL_COLLECTIONS_IMPL( L_begin, L_end, R_begin, R_end, WARN )
272 #define BOOST_CHECK_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
273 BOOST_EQUAL_COLLECTIONS_IMPL( L_begin, L_end, R_begin, R_end, CHECK )
274 #define BOOST_REQUIRE_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
275 BOOST_EQUAL_COLLECTIONS_IMPL( L_begin, L_end, R_begin, R_end, REQUIRE )
277 //____________________________________________________________________________//
279 #define BOOST_BITWISE_EQUAL_IMPL( L, R, TL ) \
280 BOOST_TEST_TOOL_IMPL( check_impl, \
281 ::boost::test_tools::tt_detail::bitwise_equal_impl( (L), (R) ), \
282 "", TL, CHECK_BITWISE_EQUAL ), \
283 2, BOOST_STRINGIZE( L ), BOOST_STRINGIZE( R ) ) \
286 #define BOOST_WARN_BITWISE_EQUAL( L, R ) BOOST_BITWISE_EQUAL_IMPL( L, R, WARN )
287 #define BOOST_CHECK_BITWISE_EQUAL( L, R ) BOOST_BITWISE_EQUAL_IMPL( L, R, CHECK )
288 #define BOOST_REQUIRE_BITWISE_EQUAL( L, R ) BOOST_BITWISE_EQUAL_IMPL( L, R, REQUIRE )
290 //____________________________________________________________________________//
292 #define BOOST_IS_DEFINED( symb ) ::boost::test_tools::tt_detail::is_defined_impl( #symb, BOOST_STRINGIZE(= symb) )
294 //____________________________________________________________________________//
296 // ***************************** //
297 // deprecated interface
299 #define BOOST_BITWISE_EQUAL( L, R ) BOOST_CHECK_BITWISE_EQUAL( L, R )
300 #define BOOST_MESSAGE( M ) BOOST_TEST_MESSAGE( M )
301 #define BOOST_CHECKPOINT( M ) BOOST_TEST_CHECKPOINT( M )
305 namespace test_tools
{
307 typedef unit_test::const_string const_string
;
309 namespace { bool const dummy_cond
= false; }
311 // ************************************************************************** //
312 // ************** print_log_value ************** //
313 // ************************************************************************** //
316 struct print_log_value
{
317 void operator()( std::ostream
& ostr
, T
const& t
)
319 // avoid warning: 'boost::test_tools::<unnamed>::dummy_cond' defined but not used
320 if (::boost::test_tools::dummy_cond
) {}
322 typedef typename
mpl::or_
<is_array
<T
>,is_function
<T
>,is_abstract
<T
> >::type cant_use_nl
;
324 set_precision( ostr
, cant_use_nl() );
326 ostr
<< t
; // by default print the value
329 void set_precision( std::ostream
& ostr
, mpl::false_
)
331 if( std::numeric_limits
<T
>::is_specialized
&& std::numeric_limits
<T
>::radix
== 2 )
332 ostr
.precision( 2 + std::numeric_limits
<T
>::digits
* 301/1000 );
335 void set_precision( std::ostream
&, mpl::true_
) {}
338 //____________________________________________________________________________//
340 #define BOOST_TEST_DONT_PRINT_LOG_VALUE( the_type ) \
341 namespace boost { namespace test_tools { \
343 struct print_log_value<the_type > { \
344 void operator()( std::ostream&, the_type const& ) {} \
349 //____________________________________________________________________________//
351 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
352 template<typename T
, std::size_t N
>
353 struct print_log_value
< T
[N
] > {
354 void operator()( std::ostream
& ostr
, T
const* t
)
361 //____________________________________________________________________________//
364 struct BOOST_TEST_DECL print_log_value
<bool> {
365 void operator()( std::ostream
& ostr
, bool t
)
367 ostr
<< std::boolalpha
<< t
;
371 //____________________________________________________________________________//
374 struct BOOST_TEST_DECL print_log_value
<char> {
375 void operator()( std::ostream
& ostr
, char t
);
378 //____________________________________________________________________________//
381 struct BOOST_TEST_DECL print_log_value
<unsigned char> {
382 void operator()( std::ostream
& ostr
, unsigned char t
);
385 //____________________________________________________________________________//
388 struct BOOST_TEST_DECL print_log_value
<char const*> {
389 void operator()( std::ostream
& ostr
, char const* t
);
392 //____________________________________________________________________________//
395 struct BOOST_TEST_DECL print_log_value
<wchar_t const*> {
396 void operator()( std::ostream
& ostr
, wchar_t const* t
);
399 //____________________________________________________________________________//
401 namespace tt_detail
{
403 // ************************************************************************** //
404 // ************** tools classification ************** //
405 // ************************************************************************** //
417 CHECK_CLOSE_FRACTION
,
420 CHECK_PRED_WITH_ARGS
,
425 WARN
, CHECK
, REQUIRE
, PASS
428 // ************************************************************************** //
429 // ************** print_helper ************** //
430 // ************************************************************************** //
431 // Adds level of indirection to the output operation, allowing us to customize
432 // it for types that do not support operator << directly or for any other reason
435 struct print_helper_t
{
436 explicit print_helper_t( T
const& t
) : m_t( t
) {}
441 //____________________________________________________________________________//
443 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
444 // Borland suffers premature pointer decay passing arrays by reference
445 template<typename T
, std::size_t N
>
446 struct print_helper_t
< T
[N
] > {
447 explicit print_helper_t( T
const * t
) : m_t( t
) {}
453 //____________________________________________________________________________//
456 inline print_helper_t
<T
> print_helper( T
const& t
)
458 return print_helper_t
<T
>( t
);
461 //____________________________________________________________________________//
465 operator<<( std::ostream
& ostr
, print_helper_t
<T
> const& ph
)
467 print_log_value
<T
>()( ostr
, ph
.m_t
);
472 //____________________________________________________________________________//
474 // ************************************************************************** //
475 // ************** TOOL BOX Implementation ************** //
476 // ************************************************************************** //
479 bool check_impl( predicate_result
const& pr
, ::boost::unit_test::lazy_ostream
const& check_descr
,
480 const_string file_name
, std::size_t line_num
,
481 tool_level tl
, check_type ct
,
482 std::size_t num_args
, ... );
484 //____________________________________________________________________________//
486 #define TEMPL_PARAMS( z, m, dummy ) , typename BOOST_JOIN( Arg, m )
487 #define FUNC_PARAMS( z, m, dummy ) \
488 , BOOST_JOIN( Arg, m ) const& BOOST_JOIN( arg, m ) \
489 , char const* BOOST_JOIN( BOOST_JOIN( arg, m ), _descr ) \
492 #define PRED_PARAMS( z, m, dummy ) BOOST_PP_COMMA_IF( m ) BOOST_JOIN( arg, m )
494 #define ARG_INFO( z, m, dummy ) \
495 , BOOST_JOIN( BOOST_JOIN( arg, m ), _descr ) \
496 , &(const unit_test::lazy_ostream&)(unit_test::lazy_ostream::instance() \
497 << ::boost::test_tools::tt_detail::print_helper( BOOST_JOIN( arg, m ) )) \
500 #define IMPL_FRWD( z, n, dummy ) \
501 template<typename Pred \
502 BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), TEMPL_PARAMS, _ )> \
504 check_frwd( Pred P, unit_test::lazy_ostream const& check_descr, \
505 const_string file_name, std::size_t line_num, \
506 tool_level tl, check_type ct \
507 BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), FUNC_PARAMS, _ ) \
511 check_impl( P( BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), PRED_PARAMS, _ ) ), \
512 check_descr, file_name, line_num, tl, ct, \
513 BOOST_PP_ADD( n, 1 ) \
514 BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), ARG_INFO, _ ) \
519 #ifndef BOOST_TEST_MAX_PREDICATE_ARITY
520 #define BOOST_TEST_MAX_PREDICATE_ARITY 5
523 BOOST_PP_REPEAT( BOOST_TEST_MAX_PREDICATE_ARITY
, IMPL_FRWD
, _
)
531 //____________________________________________________________________________//
533 template <class Left
, class Right
>
534 predicate_result
equal_impl( Left
const& left
, Right
const& right
)
536 return left
== right
;
539 //____________________________________________________________________________//
541 predicate_result BOOST_TEST_DECL
equal_impl( char const* left
, char const* right
);
542 inline predicate_result
equal_impl( char* left
, char const* right
) { return equal_impl( (char const*)left
, (char const*)right
); }
543 inline predicate_result
equal_impl( char const* left
, char* right
) { return equal_impl( (char const*)left
, (char const*)right
); }
544 inline predicate_result
equal_impl( char* left
, char* right
) { return equal_impl( (char const*)left
, (char const*)right
); }
546 #if !defined( BOOST_NO_CWCHAR )
547 predicate_result BOOST_TEST_DECL
equal_impl( wchar_t const* left
, wchar_t const* right
);
548 inline predicate_result
equal_impl( wchar_t* left
, wchar_t const* right
) { return equal_impl( (wchar_t const*)left
, (wchar_t const*)right
); }
549 inline predicate_result
equal_impl( wchar_t const* left
, wchar_t* right
) { return equal_impl( (wchar_t const*)left
, (wchar_t const*)right
); }
550 inline predicate_result
equal_impl( wchar_t* left
, wchar_t* right
) { return equal_impl( (wchar_t const*)left
, (wchar_t const*)right
); }
553 //____________________________________________________________________________//
555 struct equal_impl_frwd
{
556 template <typename Left
, typename Right
>
557 inline predicate_result
558 call_impl( Left
const& left
, Right
const& right
, mpl::false_
) const
560 return equal_impl( left
, right
);
563 template <typename Left
, typename Right
>
564 inline predicate_result
565 call_impl( Left
const& left
, Right
const& right
, mpl::true_
) const
567 return (*this)( right
, &left
[0] );
570 template <typename Left
, typename Right
>
571 inline predicate_result
572 operator()( Left
const& left
, Right
const& right
) const
574 typedef typename is_array
<Left
>::type left_is_array
;
575 return call_impl( left
, right
, left_is_array() );
579 //____________________________________________________________________________//
582 template <class Left
, class Right
>
583 predicate_result
operator()( Left
const& left
, Right
const& right
)
585 return !equal_impl_frwd()( left
, right
);
589 //____________________________________________________________________________//
592 template <class Left
, class Right
>
593 predicate_result
operator()( Left
const& left
, Right
const& right
)
599 //____________________________________________________________________________//
602 template <class Left
, class Right
>
603 predicate_result
operator()( Left
const& left
, Right
const& right
)
605 return left
<= right
;
609 //____________________________________________________________________________//
612 template <class Left
, class Right
>
613 predicate_result
operator()( Left
const& left
, Right
const& right
)
619 //____________________________________________________________________________//
622 template <class Left
, class Right
>
623 predicate_result
operator()( Left
const& left
, Right
const& right
)
625 return left
>= right
;
629 //____________________________________________________________________________//
631 template <typename Left
, typename Right
>
632 inline predicate_result
633 equal_coll_impl( Left left_begin
, Left left_end
, Right right_begin
, Right right_end
)
635 predicate_result
res( true );
638 for( ; left_begin
!= left_end
&& right_begin
!= right_end
; ++left_begin
, ++right_begin
, ++pos
) {
639 if( *left_begin
!= *right_begin
) {
641 res
.message() << "\nMismatch in a position " << pos
<< ": " << *left_begin
<< " != " << *right_begin
;
645 if( left_begin
!= left_end
) {
646 std::size_t r_size
= pos
;
647 while( left_begin
!= left_end
) {
653 res
.message() << "\nCollections size mismatch: " << pos
<< " != " << r_size
;
656 if( right_begin
!= right_end
) {
657 std::size_t l_size
= pos
;
658 while( right_begin
!= right_end
) {
664 res
.message() << "\nCollections size mismatch: " << l_size
<< " != " << pos
;
670 //____________________________________________________________________________//
672 template <class Left
, class Right
>
673 inline predicate_result
674 bitwise_equal_impl( Left
const& left
, Right
const& right
)
676 predicate_result
res( true );
678 std::size_t left_bit_size
= sizeof(Left
)*CHAR_BIT
;
679 std::size_t right_bit_size
= sizeof(Right
)*CHAR_BIT
;
681 static Left
const leftOne( 1 );
682 static Right
const rightOne( 1 );
684 std::size_t total_bits
= left_bit_size
< right_bit_size
? left_bit_size
: right_bit_size
;
686 for( std::size_t counter
= 0; counter
< total_bits
; ++counter
) {
687 if( ( left
& ( leftOne
<< counter
) ) != ( right
& ( rightOne
<< counter
) ) ) {
689 res
.message() << "\nMismatch in a position " << counter
;
693 if( left_bit_size
!= right_bit_size
) {
695 res
.message() << "\nOperands bit sizes mismatch: " << left_bit_size
<< " != " << right_bit_size
;
701 //____________________________________________________________________________//
703 bool BOOST_TEST_DECL
is_defined_impl( const_string symbol_name
, const_string symbol_value
);
705 //____________________________________________________________________________//
707 } // namespace tt_detail
709 } // namespace test_tools
711 namespace test_toolbox
= test_tools
;
715 //____________________________________________________________________________//
717 #include <boost/test/detail/enable_warnings.hpp>
719 #endif // BOOST_TEST_TEST_TOOLS_HPP_012705GER