annotate DEPENDENCIES/generic/include/boost/test/test_tools.hpp @ 133:4acb5d8d80b6 tip

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