/usr/include/boost/test/test_tools.hpp is in libboost1.46-dev 1.46.1-7ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 | // (C) Copyright Gennadiy Rozental 2001-2008.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision: 54633 $
//
// Description : contains definition for all test tools in test toolbox
// ***************************************************************************
#ifndef BOOST_TEST_TEST_TOOLS_HPP_012705GER
#define BOOST_TEST_TEST_TOOLS_HPP_012705GER
// Boost.Test
#include <boost/test/predicate_result.hpp>
#include <boost/test/unit_test_log.hpp>
#include <boost/test/floating_point_comparison.hpp>
#include <boost/test/detail/config.hpp>
#include <boost/test/detail/global_typedef.hpp>
#include <boost/test/detail/workaround.hpp>
#include <boost/test/utils/wrap_stringstream.hpp>
#include <boost/test/utils/basic_cstring/io.hpp>
#include <boost/test/utils/lazy_ostream.hpp>
// Boost
#include <boost/preprocessor/seq/for_each.hpp>
#include <boost/preprocessor/seq/size.hpp>
#include <boost/preprocessor/seq/enum.hpp>
#include <boost/preprocessor/repetition/repeat.hpp>
#include <boost/preprocessor/punctuation/comma_if.hpp>
#include <boost/preprocessor/arithmetic/add.hpp>
#include <boost/limits.hpp>
#include <boost/type_traits/is_array.hpp>
#include <boost/type_traits/is_function.hpp>
#include <boost/type_traits/is_abstract.hpp>
#include <boost/mpl/or.hpp>
// STL
#include <cstddef> // for std::size_t
#include <iosfwd>
#include <ios> // for std::boolalpha
#include <climits> // for CHAR_BIT
#ifdef BOOST_MSVC
# pragma warning(disable: 4127) // conditional expression is constant
#endif
#include <boost/test/detail/suppress_warnings.hpp>
//____________________________________________________________________________//
// ************************************************************************** //
// ************** TOOL BOX ************** //
// ************************************************************************** //
// In macros below following argument abbreviations are used:
// P - predicate
// M - message
// S - statement
// E - exception
// L - left argument
// R - right argument
// TL - tool level
// CT - check type
// ARGS - arguments list
#define BOOST_TEST_TOOL_IMPL( func, P, check_descr, TL, CT ) \
::boost::test_tools::tt_detail::func( \
P, \
::boost::unit_test::lazy_ostream::instance() << check_descr, \
BOOST_TEST_L(__FILE__), \
static_cast<std::size_t>(__LINE__), \
::boost::test_tools::tt_detail::TL, \
::boost::test_tools::tt_detail::CT \
/**/
//____________________________________________________________________________//
#define BOOST_CHECK_IMPL( P, check_descr, TL, CT ) \
do { \
BOOST_TEST_PASSPOINT(); \
BOOST_TEST_TOOL_IMPL( check_impl, P, check_descr, TL, CT ), 0 );\
} while( ::boost::test_tools::dummy_cond ) \
/**/
//____________________________________________________________________________//
#define BOOST_TEST_PASS_ARG_INFO( r, data, arg ) , arg, BOOST_STRINGIZE( arg )
#define BOOST_CHECK_WITH_ARGS_IMPL( P, check_descr, TL, CT, ARGS ) \
do { \
BOOST_TEST_PASSPOINT(); \
BOOST_TEST_TOOL_IMPL( check_frwd, P, check_descr, TL, CT ) \
BOOST_PP_SEQ_FOR_EACH( BOOST_TEST_PASS_ARG_INFO, '_', ARGS ) ); \
} while( ::boost::test_tools::dummy_cond ) \
/**/
//____________________________________________________________________________//
#define BOOST_WARN( P ) BOOST_CHECK_IMPL( (P), BOOST_TEST_STRINGIZE( P ), WARN, CHECK_PRED )
#define BOOST_CHECK( P ) BOOST_CHECK_IMPL( (P), BOOST_TEST_STRINGIZE( P ), CHECK, CHECK_PRED )
#define BOOST_REQUIRE( P ) BOOST_CHECK_IMPL( (P), BOOST_TEST_STRINGIZE( P ), REQUIRE, CHECK_PRED )
//____________________________________________________________________________//
#define BOOST_WARN_MESSAGE( P, M ) BOOST_CHECK_IMPL( (P), M, WARN, CHECK_MSG )
#define BOOST_CHECK_MESSAGE( P, M ) BOOST_CHECK_IMPL( (P), M, CHECK, CHECK_MSG )
#define BOOST_REQUIRE_MESSAGE( P, M ) BOOST_CHECK_IMPL( (P), M, REQUIRE, CHECK_MSG )
//____________________________________________________________________________//
#define BOOST_ERROR( M ) BOOST_CHECK_MESSAGE( false, M )
#define BOOST_FAIL( M ) BOOST_REQUIRE_MESSAGE( false, M )
//____________________________________________________________________________//
#define BOOST_CHECK_THROW_IMPL( S, E, P, prefix, TL ) \
try { \
BOOST_TEST_PASSPOINT(); \
S; \
BOOST_CHECK_IMPL( false, "exception " BOOST_STRINGIZE( E ) " is expected", TL, CHECK_MSG ); } \
catch( E const& ex ) { \
::boost::unit_test::ut_detail::ignore_unused_variable_warning( ex ); \
BOOST_CHECK_IMPL( P, prefix BOOST_STRINGIZE( E ) " is caught", TL, CHECK_MSG ); \
} \
/**/
//____________________________________________________________________________//
#define BOOST_WARN_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "exception ", WARN )
#define BOOST_CHECK_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "exception ", CHECK )
#define BOOST_REQUIRE_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "exception ", REQUIRE )
//____________________________________________________________________________//
#define BOOST_WARN_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), "incorrect exception ", WARN )
#define BOOST_CHECK_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), "incorrect exception ", CHECK )
#define BOOST_REQUIRE_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), "incorrect exception ", REQUIRE )
//____________________________________________________________________________//
#define BOOST_CHECK_NO_THROW_IMPL( S, TL ) \
try { \
S; \
BOOST_CHECK_IMPL( true, "no exceptions thrown by " BOOST_STRINGIZE( S ), TL, CHECK_MSG ); } \
catch( ... ) { \
BOOST_CHECK_IMPL( false, "exception thrown by " BOOST_STRINGIZE( S ), TL, CHECK_MSG ); \
} \
/**/
#define BOOST_WARN_NO_THROW( S ) BOOST_CHECK_NO_THROW_IMPL( S, WARN )
#define BOOST_CHECK_NO_THROW( S ) BOOST_CHECK_NO_THROW_IMPL( S, CHECK )
#define BOOST_REQUIRE_NO_THROW( S ) BOOST_CHECK_NO_THROW_IMPL( S, REQUIRE )
//____________________________________________________________________________//
#define BOOST_WARN_EQUAL( L, R ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::equal_impl_frwd(), "", WARN, CHECK_EQUAL, (L)(R) )
#define BOOST_CHECK_EQUAL( L, R ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::equal_impl_frwd(), "", CHECK, CHECK_EQUAL, (L)(R) )
#define BOOST_REQUIRE_EQUAL( L, R ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::equal_impl_frwd(), "", REQUIRE, CHECK_EQUAL, (L)(R) )
//____________________________________________________________________________//
#define BOOST_WARN_NE( L, R ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::ne_impl(), "", WARN, CHECK_NE, (L)(R) )
#define BOOST_CHECK_NE( L, R ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::ne_impl(), "", CHECK, CHECK_NE, (L)(R) )
#define BOOST_REQUIRE_NE( L, R ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::ne_impl(), "", REQUIRE, CHECK_NE, (L)(R) )
//____________________________________________________________________________//
#define BOOST_WARN_LT( L, R ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::lt_impl(), "", WARN, CHECK_LT, (L)(R) )
#define BOOST_CHECK_LT( L, R ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::lt_impl(), "", CHECK, CHECK_LT, (L)(R) )
#define BOOST_REQUIRE_LT( L, R ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::lt_impl(), "", REQUIRE, CHECK_LT, (L)(R) )
//____________________________________________________________________________//
#define BOOST_WARN_LE( L, R ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::le_impl(), "", WARN, CHECK_LE, (L)(R) )
#define BOOST_CHECK_LE( L, R ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::le_impl(), "", CHECK, CHECK_LE, (L)(R) )
#define BOOST_REQUIRE_LE( L, R ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::le_impl(), "", REQUIRE, CHECK_LE, (L)(R) )
//____________________________________________________________________________//
#define BOOST_WARN_GT( L, R ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::gt_impl(), "", WARN, CHECK_GT, (L)(R) )
#define BOOST_CHECK_GT( L, R ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::gt_impl(), "", CHECK, CHECK_GT, (L)(R) )
#define BOOST_REQUIRE_GT( L, R ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::gt_impl(), "", REQUIRE, CHECK_GT, (L)(R) )
//____________________________________________________________________________//
#define BOOST_WARN_GE( L, R ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::ge_impl(), "", WARN, CHECK_GE, (L)(R) )
#define BOOST_CHECK_GE( L, R ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::ge_impl(), "", CHECK, CHECK_GE, (L)(R) )
#define BOOST_REQUIRE_GE( L, R ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::ge_impl(), "", REQUIRE, CHECK_GE, (L)(R) )
//____________________________________________________________________________//
#define BOOST_WARN_CLOSE( L, R, T ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", WARN, CHECK_CLOSE, \
(L)(R)(::boost::test_tools::percent_tolerance(T)) )
#define BOOST_CHECK_CLOSE( L, R, T ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", CHECK, CHECK_CLOSE, \
(L)(R)(::boost::test_tools::percent_tolerance(T)) )
#define BOOST_REQUIRE_CLOSE( L, R, T ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", REQUIRE, CHECK_CLOSE, \
(L)(R)(::boost::test_tools::percent_tolerance(T)) )
//____________________________________________________________________________//
#define BOOST_WARN_CLOSE_FRACTION( L, R, T ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", WARN, CHECK_CLOSE_FRACTION, \
(L)(R)(::boost::test_tools::fraction_tolerance(T)) )
#define BOOST_CHECK_CLOSE_FRACTION( L, R, T ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", CHECK, CHECK_CLOSE_FRACTION, \
(L)(R)(::boost::test_tools::fraction_tolerance(T)) )
#define BOOST_REQUIRE_CLOSE_FRACTION( L, R, T ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", REQUIRE, CHECK_CLOSE_FRACTION, \
(L)(R)(::boost::test_tools::fraction_tolerance(T)) )
//____________________________________________________________________________//
#define BOOST_WARN_SMALL( FPV, T ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_small, "", WARN, CHECK_SMALL, (FPV)(T) )
#define BOOST_CHECK_SMALL( FPV, T ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_small, "", CHECK, CHECK_SMALL, (FPV)(T) )
#define BOOST_REQUIRE_SMALL( FPV, T ) \
BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_small, "", REQUIRE, CHECK_SMALL, (FPV)(T) )
//____________________________________________________________________________//
#define BOOST_WARN_PREDICATE( P, ARGS ) \
BOOST_CHECK_WITH_ARGS_IMPL( P, BOOST_TEST_STRINGIZE( P ), WARN, CHECK_PRED_WITH_ARGS, ARGS )
#define BOOST_CHECK_PREDICATE( P, ARGS ) \
BOOST_CHECK_WITH_ARGS_IMPL( P, BOOST_TEST_STRINGIZE( P ), CHECK, CHECK_PRED_WITH_ARGS, ARGS )
#define BOOST_REQUIRE_PREDICATE( P, ARGS ) \
BOOST_CHECK_WITH_ARGS_IMPL( P, BOOST_TEST_STRINGIZE( P ), REQUIRE, CHECK_PRED_WITH_ARGS, ARGS )
//____________________________________________________________________________//
#define BOOST_EQUAL_COLLECTIONS_IMPL( L_begin, L_end, R_begin, R_end, TL ) \
BOOST_TEST_TOOL_IMPL( check_impl, ::boost::test_tools::tt_detail::equal_coll_impl( \
(L_begin), (L_end), (R_begin), (R_end) ), "", TL, CHECK_EQUAL_COLL ), \
4, \
BOOST_STRINGIZE( L_begin ), BOOST_STRINGIZE( L_end ), \
BOOST_STRINGIZE( R_begin ), BOOST_STRINGIZE( R_end ) ) \
/**/
#define BOOST_WARN_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
BOOST_EQUAL_COLLECTIONS_IMPL( L_begin, L_end, R_begin, R_end, WARN )
#define BOOST_CHECK_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
BOOST_EQUAL_COLLECTIONS_IMPL( L_begin, L_end, R_begin, R_end, CHECK )
#define BOOST_REQUIRE_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \
BOOST_EQUAL_COLLECTIONS_IMPL( L_begin, L_end, R_begin, R_end, REQUIRE )
//____________________________________________________________________________//
#define BOOST_BITWISE_EQUAL_IMPL( L, R, TL ) \
BOOST_TEST_TOOL_IMPL( check_impl, \
::boost::test_tools::tt_detail::bitwise_equal_impl( (L), (R) ), \
"", TL, CHECK_BITWISE_EQUAL ), \
2, BOOST_STRINGIZE( L ), BOOST_STRINGIZE( R ) ) \
/**/
#define BOOST_WARN_BITWISE_EQUAL( L, R ) BOOST_BITWISE_EQUAL_IMPL( L, R, WARN )
#define BOOST_CHECK_BITWISE_EQUAL( L, R ) BOOST_BITWISE_EQUAL_IMPL( L, R, CHECK )
#define BOOST_REQUIRE_BITWISE_EQUAL( L, R ) BOOST_BITWISE_EQUAL_IMPL( L, R, REQUIRE )
//____________________________________________________________________________//
#define BOOST_IS_DEFINED( symb ) ::boost::test_tools::tt_detail::is_defined_impl( #symb, BOOST_STRINGIZE(= symb) )
//____________________________________________________________________________//
// ***************************** //
// deprecated interface
#define BOOST_BITWISE_EQUAL( L, R ) BOOST_CHECK_BITWISE_EQUAL( L, R )
#define BOOST_MESSAGE( M ) BOOST_TEST_MESSAGE( M )
#define BOOST_CHECKPOINT( M ) BOOST_TEST_CHECKPOINT( M )
namespace boost {
namespace test_tools {
typedef unit_test::const_string const_string;
namespace { bool dummy_cond = false; }
// ************************************************************************** //
// ************** print_log_value ************** //
// ************************************************************************** //
template<typename T>
struct print_log_value {
void operator()( std::ostream& ostr, T const& t )
{
// avoid warning: 'boost::test_tools::<unnamed>::dummy_cond' defined but not used
if (::boost::test_tools::dummy_cond) {}
typedef typename mpl::or_<is_array<T>,is_function<T>,is_abstract<T> >::type cant_use_nl;
set_precision( ostr, cant_use_nl() );
ostr << t; // by default print the value
}
void set_precision( std::ostream& ostr, mpl::false_ )
{
if( std::numeric_limits<T>::is_specialized && std::numeric_limits<T>::radix == 2 )
ostr.precision( 2 + std::numeric_limits<T>::digits * 301/1000 );
}
void set_precision( std::ostream&, mpl::true_ ) {}
};
//____________________________________________________________________________//
#define BOOST_TEST_DONT_PRINT_LOG_VALUE( the_type ) \
namespace boost { namespace test_tools { \
template<> \
struct print_log_value<the_type > { \
void operator()( std::ostream&, the_type const& ) {} \
}; \
}} \
/**/
//____________________________________________________________________________//
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
template<typename T, std::size_t N >
struct print_log_value< T[N] > {
void operator()( std::ostream& ostr, T const* t )
{
ostr << t;
}
};
#endif
//____________________________________________________________________________//
template<>
struct BOOST_TEST_DECL print_log_value<bool> {
void operator()( std::ostream& ostr, bool t )
{
ostr << std::boolalpha << t;
}
};
//____________________________________________________________________________//
template<>
struct BOOST_TEST_DECL print_log_value<char> {
void operator()( std::ostream& ostr, char t );
};
//____________________________________________________________________________//
template<>
struct BOOST_TEST_DECL print_log_value<unsigned char> {
void operator()( std::ostream& ostr, unsigned char t );
};
//____________________________________________________________________________//
template<>
struct BOOST_TEST_DECL print_log_value<char const*> {
void operator()( std::ostream& ostr, char const* t );
};
//____________________________________________________________________________//
template<>
struct BOOST_TEST_DECL print_log_value<wchar_t const*> {
void operator()( std::ostream& ostr, wchar_t const* t );
};
//____________________________________________________________________________//
namespace tt_detail {
// ************************************************************************** //
// ************** tools classification ************** //
// ************************************************************************** //
enum check_type {
CHECK_PRED,
CHECK_MSG,
CHECK_EQUAL,
CHECK_NE,
CHECK_LT,
CHECK_LE,
CHECK_GT,
CHECK_GE,
CHECK_CLOSE,
CHECK_CLOSE_FRACTION,
CHECK_SMALL,
CHECK_BITWISE_EQUAL,
CHECK_PRED_WITH_ARGS,
CHECK_EQUAL_COLL
};
enum tool_level {
WARN, CHECK, REQUIRE, PASS
};
// ************************************************************************** //
// ************** print_helper ************** //
// ************************************************************************** //
// Adds level of indirection to the output operation, allowing us to customize
// it for types that do not support operator << directly or for any other reason
template<typename T>
struct print_helper_t {
explicit print_helper_t( T const& t ) : m_t( t ) {}
T const& m_t;
};
//____________________________________________________________________________//
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
// Borland suffers premature pointer decay passing arrays by reference
template<typename T, std::size_t N >
struct print_helper_t< T[N] > {
explicit print_helper_t( T const * t ) : m_t( t ) {}
T const * m_t;
};
#endif
//____________________________________________________________________________//
template<typename T>
inline print_helper_t<T> print_helper( T const& t )
{
return print_helper_t<T>( t );
}
//____________________________________________________________________________//
template<typename T>
inline std::ostream&
operator<<( std::ostream& ostr, print_helper_t<T> const& ph )
{
print_log_value<T>()( ostr, ph.m_t );
return ostr;
}
//____________________________________________________________________________//
// ************************************************************************** //
// ************** TOOL BOX Implementation ************** //
// ************************************************************************** //
BOOST_TEST_DECL
bool check_impl( predicate_result const& pr, ::boost::unit_test::lazy_ostream const& check_descr,
const_string file_name, std::size_t line_num,
tool_level tl, check_type ct,
std::size_t num_args, ... );
//____________________________________________________________________________//
#define TEMPL_PARAMS( z, m, dummy ) , typename BOOST_JOIN( Arg, m )
#define FUNC_PARAMS( z, m, dummy ) \
, BOOST_JOIN( Arg, m ) const& BOOST_JOIN( arg, m ) \
, char const* BOOST_JOIN( BOOST_JOIN( arg, m ), _descr ) \
/**/
#define PRED_PARAMS( z, m, dummy ) BOOST_PP_COMMA_IF( m ) BOOST_JOIN( arg, m )
#define ARG_INFO( z, m, dummy ) \
, BOOST_JOIN( BOOST_JOIN( arg, m ), _descr ) \
, &static_cast<const unit_test::lazy_ostream&>(unit_test::lazy_ostream::instance() \
<< ::boost::test_tools::tt_detail::print_helper( BOOST_JOIN( arg, m ) )) \
/**/
#define IMPL_FRWD( z, n, dummy ) \
template<typename Pred \
BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), TEMPL_PARAMS, _ )> \
inline bool \
check_frwd( Pred P, unit_test::lazy_ostream const& check_descr, \
const_string file_name, std::size_t line_num, \
tool_level tl, check_type ct \
BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), FUNC_PARAMS, _ ) \
) \
{ \
return \
check_impl( P( BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), PRED_PARAMS, _ ) ), \
check_descr, file_name, line_num, tl, ct, \
BOOST_PP_ADD( n, 1 ) \
BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), ARG_INFO, _ ) \
); \
} \
/**/
#ifndef BOOST_TEST_MAX_PREDICATE_ARITY
#define BOOST_TEST_MAX_PREDICATE_ARITY 5
#endif
BOOST_PP_REPEAT( BOOST_TEST_MAX_PREDICATE_ARITY, IMPL_FRWD, _ )
#undef TEMPL_PARAMS
#undef FUNC_PARAMS
#undef PRED_INFO
#undef ARG_INFO
#undef IMPL_FRWD
//____________________________________________________________________________//
template <class Left, class Right>
predicate_result equal_impl( Left const& left, Right const& right )
{
return left == right;
}
//____________________________________________________________________________//
predicate_result BOOST_TEST_DECL equal_impl( char const* left, char const* right );
inline predicate_result equal_impl( char* left, char const* right ) { return equal_impl( static_cast<char const*>(left), static_cast<char const*>(right) ); }
inline predicate_result equal_impl( char const* left, char* right ) { return equal_impl( static_cast<char const*>(left), static_cast<char const*>(right) ); }
inline predicate_result equal_impl( char* left, char* right ) { return equal_impl( static_cast<char const*>(left), static_cast<char const*>(right) ); }
#if !defined( BOOST_NO_CWCHAR )
predicate_result BOOST_TEST_DECL equal_impl( wchar_t const* left, wchar_t const* right );
inline predicate_result equal_impl( wchar_t* left, wchar_t const* right ) { return equal_impl( static_cast<wchar_t const*>(left), static_cast<wchar_t const*>(right) ); }
inline predicate_result equal_impl( wchar_t const* left, wchar_t* right ) { return equal_impl( static_cast<wchar_t const*>(left), static_cast<wchar_t const*>(right) ); }
inline predicate_result equal_impl( wchar_t* left, wchar_t* right ) { return equal_impl( static_cast<wchar_t const*>(left), static_cast<wchar_t const*>(right) ); }
#endif
//____________________________________________________________________________//
struct equal_impl_frwd {
template <typename Left, typename Right>
inline predicate_result
call_impl( Left const& left, Right const& right, mpl::false_ ) const
{
return equal_impl( left, right );
}
template <typename Left, typename Right>
inline predicate_result
call_impl( Left const& left, Right const& right, mpl::true_ ) const
{
return (*this)( right, &left[0] );
}
template <typename Left, typename Right>
inline predicate_result
operator()( Left const& left, Right const& right ) const
{
typedef typename is_array<Left>::type left_is_array;
return call_impl( left, right, left_is_array() );
}
};
//____________________________________________________________________________//
struct ne_impl {
template <class Left, class Right>
predicate_result operator()( Left const& left, Right const& right )
{
return !equal_impl_frwd()( left, right );
}
};
//____________________________________________________________________________//
struct lt_impl {
template <class Left, class Right>
predicate_result operator()( Left const& left, Right const& right )
{
return left < right;
}
};
//____________________________________________________________________________//
struct le_impl {
template <class Left, class Right>
predicate_result operator()( Left const& left, Right const& right )
{
return left <= right;
}
};
//____________________________________________________________________________//
struct gt_impl {
template <class Left, class Right>
predicate_result operator()( Left const& left, Right const& right )
{
return left > right;
}
};
//____________________________________________________________________________//
struct ge_impl {
template <class Left, class Right>
predicate_result operator()( Left const& left, Right const& right )
{
return left >= right;
}
};
//____________________________________________________________________________//
template <typename Left, typename Right>
inline predicate_result
equal_coll_impl( Left left_begin, Left left_end, Right right_begin, Right right_end )
{
predicate_result res( true );
std::size_t pos = 0;
for( ; left_begin != left_end && right_begin != right_end; ++left_begin, ++right_begin, ++pos ) {
if( *left_begin != *right_begin ) {
res = false;
res.message() << "\nMismatch in a position " << pos << ": " << *left_begin << " != " << *right_begin;
}
}
if( left_begin != left_end ) {
std::size_t r_size = pos;
while( left_begin != left_end ) {
++pos;
++left_begin;
}
res = false;
res.message() << "\nCollections size mismatch: " << pos << " != " << r_size;
}
if( right_begin != right_end ) {
std::size_t l_size = pos;
while( right_begin != right_end ) {
++pos;
++right_begin;
}
res = false;
res.message() << "\nCollections size mismatch: " << l_size << " != " << pos;
}
return res;
}
//____________________________________________________________________________//
template <class Left, class Right>
inline predicate_result
bitwise_equal_impl( Left const& left, Right const& right )
{
predicate_result res( true );
std::size_t left_bit_size = sizeof(Left)*CHAR_BIT;
std::size_t right_bit_size = sizeof(Right)*CHAR_BIT;
static Left const leftOne( 1 );
static Right const rightOne( 1 );
std::size_t total_bits = left_bit_size < right_bit_size ? left_bit_size : right_bit_size;
for( std::size_t counter = 0; counter < total_bits; ++counter ) {
if( ( left & ( leftOne << counter ) ) != ( right & ( rightOne << counter ) ) ) {
res = false;
res.message() << "\nMismatch in a position " << counter;
}
}
if( left_bit_size != right_bit_size ) {
res = false;
res.message() << "\nOperands bit sizes mismatch: " << left_bit_size << " != " << right_bit_size;
}
return res;
}
//____________________________________________________________________________//
bool BOOST_TEST_DECL is_defined_impl( const_string symbol_name, const_string symbol_value );
//____________________________________________________________________________//
} // namespace tt_detail
} // namespace test_tools
namespace test_toolbox = test_tools;
} // namespace boost
//____________________________________________________________________________//
#include <boost/test/detail/enable_warnings.hpp>
#endif // BOOST_TEST_TEST_TOOLS_HPP_012705GER
|