sl@0: // (C) Copyright Gennadiy Rozental 2001-2005. sl@0: // Distributed under the Boost Software License, Version 1.0. sl@0: // (See accompanying file LICENSE_1_0.txt or copy at sl@0: // http://www.boost.org/LICENSE_1_0.txt) sl@0: sl@0: // See http://www.boost.org/libs/test for the library home page. sl@0: // sl@0: // File : $RCSfile: test_tools.hpp,v $ sl@0: // sl@0: // Version : $Revision: 1.60.2.7 $ sl@0: // sl@0: // Description : contains definition for all test tools in test toolbox sl@0: // *************************************************************************** sl@0: sl@0: #ifndef BOOST_TEST_TEST_TOOLS_HPP_012705GER sl@0: #define BOOST_TEST_TEST_TOOLS_HPP_012705GER sl@0: sl@0: // Boost.Test sl@0: #include sl@0: #include sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include sl@0: #include sl@0: sl@0: // Boost sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include sl@0: sl@0: // STL sl@0: #include // for std::size_t sl@0: #include sl@0: sl@0: #include sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: // ************************************************************************** // sl@0: // ************** TOOL BOX ************** // sl@0: // ************************************************************************** // sl@0: sl@0: // In macros below following argument abbreviations are used: sl@0: // P - predicate sl@0: // M - message sl@0: // S - statement sl@0: // E - exception sl@0: // L - left argument sl@0: // R - right argument sl@0: // TL - tool level sl@0: // CT - check type sl@0: // ARGS - arguments list sl@0: sl@0: #define BOOST_TEST_TOOL_IMPL( func, P, check_descr, TL, CT ) \ sl@0: ::boost::test_tools::tt_detail::func( \ sl@0: P, \ sl@0: ::boost::wrap_stringstream().ref() << check_descr, \ sl@0: BOOST_TEST_L(__FILE__), \ sl@0: (std::size_t)__LINE__, \ sl@0: ::boost::test_tools::tt_detail::TL, \ sl@0: ::boost::test_tools::tt_detail::CT \ sl@0: /**/ sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #define BOOST_CHECK_IMPL( P, check_descr, TL, CT ) \ sl@0: do { \ sl@0: BOOST_TEST_PASSPOINT(); \ sl@0: BOOST_TEST_TOOL_IMPL( check_impl, P, check_descr, TL, CT ), 0 );\ sl@0: } while( ::boost::test_tools::dummy_cond ) \ sl@0: /**/ sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #define BOOST_TEST_PASS_ARG_INFO( r, data, arg ) , arg, BOOST_STRINGIZE( arg ) sl@0: sl@0: #define BOOST_CHECK_WITH_ARGS_IMPL( P, check_descr, TL, CT, ARGS ) \ sl@0: do { \ sl@0: BOOST_TEST_PASSPOINT(); \ sl@0: BOOST_TEST_TOOL_IMPL( check_frwd, P, check_descr, TL, CT ) \ sl@0: BOOST_PP_SEQ_FOR_EACH( BOOST_TEST_PASS_ARG_INFO, '_', ARGS ) ); \ sl@0: } while( ::boost::test_tools::dummy_cond ) \ sl@0: /**/ sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #define BOOST_WARN( P ) BOOST_CHECK_IMPL( (P), BOOST_TEST_STRINGIZE( P ), WARN, CHECK_PRED ) sl@0: #define BOOST_CHECK( P ) BOOST_CHECK_IMPL( (P), BOOST_TEST_STRINGIZE( P ), CHECK, CHECK_PRED ) sl@0: #define BOOST_REQUIRE( P ) BOOST_CHECK_IMPL( (P), BOOST_TEST_STRINGIZE( P ), REQUIRE, CHECK_PRED ) sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #define BOOST_WARN_MESSAGE( P, M ) BOOST_CHECK_IMPL( (P), M, WARN, CHECK_MSG ) sl@0: #define BOOST_CHECK_MESSAGE( P, M ) BOOST_CHECK_IMPL( (P), M, CHECK, CHECK_MSG ) sl@0: #define BOOST_REQUIRE_MESSAGE( P, M ) BOOST_CHECK_IMPL( (P), M, REQUIRE, CHECK_MSG ) sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #define BOOST_ERROR( M ) BOOST_CHECK_MESSAGE( false, M ) sl@0: #define BOOST_FAIL( M ) BOOST_REQUIRE_MESSAGE( false, M ) sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #define BOOST_CHECK_THROW_IMPL( S, E, P, prefix, TL ) \ sl@0: try { \ sl@0: BOOST_TEST_PASSPOINT(); \ sl@0: S; \ sl@0: BOOST_CHECK_IMPL( false, "exception " BOOST_STRINGIZE( E ) " is expected", TL, CHECK_MSG ); } \ sl@0: catch( E const& ex ) { \ sl@0: ::boost::unit_test::ut_detail::ignore_unused_variable_warning( ex ); \ sl@0: BOOST_CHECK_IMPL( P, prefix BOOST_STRINGIZE( E ) " is caught", TL, CHECK_MSG ); \ sl@0: } \ sl@0: /**/ sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #define BOOST_WARN_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "exception ", WARN ) sl@0: #define BOOST_CHECK_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "exception ", CHECK ) sl@0: #define BOOST_REQUIRE_THROW( S, E ) BOOST_CHECK_THROW_IMPL( S, E, true, "exception ", REQUIRE ) sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #define BOOST_WARN_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), "incorrect exception ", WARN ) sl@0: #define BOOST_CHECK_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), "incorrect exception ", CHECK ) sl@0: #define BOOST_REQUIRE_EXCEPTION( S, E, P ) BOOST_CHECK_THROW_IMPL( S, E, P( ex ), "incorrect exception ", REQUIRE ) sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #define BOOST_CHECK_NO_THROW_IMPL( S, TL ) \ sl@0: try { \ sl@0: S; \ sl@0: BOOST_CHECK_IMPL( true, "no exceptions thrown by " BOOST_STRINGIZE( S ), TL, CHECK_MSG ); } \ sl@0: catch( ... ) { \ sl@0: BOOST_CHECK_IMPL( false, "exception thrown by " BOOST_STRINGIZE( S ), TL, CHECK_MSG ); \ sl@0: } \ sl@0: /**/ sl@0: sl@0: #define BOOST_WARN_NO_THROW( S ) BOOST_CHECK_NO_THROW_IMPL( S, WARN ) sl@0: #define BOOST_CHECK_NO_THROW( S ) BOOST_CHECK_NO_THROW_IMPL( S, CHECK ) sl@0: #define BOOST_REQUIRE_NO_THROW( S ) BOOST_CHECK_NO_THROW_IMPL( S, REQUIRE ) sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: // The argument version of the following macros are causing "Internal Compiler Errors" sl@0: // on MSVC 6.5 when inlining is turned on (i.e. usually in release builds) sl@0: #if BOOST_WORKAROUND(BOOST_MSVC, <=1200) && defined(NDEBUG) sl@0: #define BOOST_WARN_EQUAL( L, R ) BOOST_WARN( (L) == (R) ) sl@0: #define BOOST_CHECK_EQUAL( L, R ) BOOST_CHECK( (L) == (R) ) sl@0: #define BOOST_REQUIRE_EQUAL( L, R ) BOOST_REQUIRE( (L) == (R) ) sl@0: #else sl@0: #define BOOST_WARN_EQUAL( L, R ) \ sl@0: BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::equal_impl_frwd(), "", WARN, CHECK_EQUAL, (L)(R) ) sl@0: #define BOOST_CHECK_EQUAL( L, R ) \ sl@0: BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::equal_impl_frwd(), "", CHECK, CHECK_EQUAL, (L)(R) ) sl@0: #define BOOST_REQUIRE_EQUAL( L, R ) \ sl@0: BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::tt_detail::equal_impl_frwd(), "", REQUIRE, CHECK_EQUAL, (L)(R) ) sl@0: #endif sl@0: //____________________________________________________________________________// sl@0: sl@0: #define BOOST_WARN_CLOSE( L, R, T ) \ sl@0: BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", WARN, CHECK_CLOSE, \ sl@0: (L)(R)(::boost::test_tools::percent_tolerance(T)) ) sl@0: #define BOOST_CHECK_CLOSE( L, R, T ) \ sl@0: BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", CHECK, CHECK_CLOSE, \ sl@0: (L)(R)(::boost::test_tools::percent_tolerance(T)) ) sl@0: #define BOOST_REQUIRE_CLOSE( L, R, T ) \ sl@0: BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", REQUIRE, CHECK_CLOSE, \ sl@0: (L)(R)(::boost::test_tools::percent_tolerance(T)) ) sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #define BOOST_WARN_CLOSE_FRACTION( L, R, T ) \ sl@0: BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", WARN, CHECK_CLOSE_FRACTION, \ sl@0: (L)(R)(::boost::test_tools::fraction_tolerance(T)) ) sl@0: #define BOOST_CHECK_CLOSE_FRACTION( L, R, T ) \ sl@0: BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", CHECK, CHECK_CLOSE_FRACTION, \ sl@0: (L)(R)(::boost::test_tools::fraction_tolerance(T)) ) sl@0: #define BOOST_REQUIRE_CLOSE_FRACTION( L, R, T ) \ sl@0: BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_close, "", REQUIRE, CHECK_CLOSE_FRACTION, \ sl@0: (L)(R)(::boost::test_tools::fraction_tolerance(T)) ) sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #define BOOST_WARN_SMALL( FPV, T ) \ sl@0: BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_small, "", WARN, CHECK_SMALL, (FPV)(T) ) sl@0: #define BOOST_CHECK_SMALL( FPV, T ) \ sl@0: BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_small, "", CHECK, CHECK_SMALL, (FPV)(T) ) sl@0: #define BOOST_REQUIRE_SMALL( FPV, T ) \ sl@0: BOOST_CHECK_WITH_ARGS_IMPL( ::boost::test_tools::check_is_small, "", REQUIRE, CHECK_SMALL, (FPV)(T) ) sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #define BOOST_WARN_PREDICATE( P, ARGS ) \ sl@0: BOOST_CHECK_WITH_ARGS_IMPL( P, BOOST_TEST_STRINGIZE( P ), WARN, CHECK_PRED_WITH_ARGS, ARGS ) sl@0: #define BOOST_CHECK_PREDICATE( P, ARGS ) \ sl@0: BOOST_CHECK_WITH_ARGS_IMPL( P, BOOST_TEST_STRINGIZE( P ), CHECK, CHECK_PRED_WITH_ARGS, ARGS ) sl@0: #define BOOST_REQUIRE_PREDICATE( P, ARGS ) \ sl@0: BOOST_CHECK_WITH_ARGS_IMPL( P, BOOST_TEST_STRINGIZE( P ), REQUIRE, CHECK_PRED_WITH_ARGS, ARGS ) sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #define BOOST_EQUAL_COLLECTIONS_IMPL( L_begin, L_end, R_begin, R_end, TL ) \ sl@0: BOOST_TEST_TOOL_IMPL( check_impl, ::boost::test_tools::tt_detail::equal_coll_impl( \ sl@0: (L_begin), (L_end), (R_begin), (R_end) ), "", TL, CHECK_EQUAL_COLL ), \ sl@0: 4, \ sl@0: BOOST_STRINGIZE( L_begin ), BOOST_STRINGIZE( L_end ), \ sl@0: BOOST_STRINGIZE( R_begin ), BOOST_STRINGIZE( R_end ) ) \ sl@0: /**/ sl@0: sl@0: #define BOOST_WARN_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \ sl@0: BOOST_EQUAL_COLLECTIONS_IMPL( L_begin, L_end, R_begin, R_end, WARN ) sl@0: #define BOOST_CHECK_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \ sl@0: BOOST_EQUAL_COLLECTIONS_IMPL( L_begin, L_end, R_begin, R_end, CHECK ) sl@0: #define BOOST_REQUIRE_EQUAL_COLLECTIONS( L_begin, L_end, R_begin, R_end ) \ sl@0: BOOST_EQUAL_COLLECTIONS_IMPL( L_begin, L_end, R_begin, R_end, REQUIRE ) sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #define BOOST_BITWISE_EQUAL_IMPL( L, R, TL ) \ sl@0: BOOST_TEST_TOOL_IMPL( check_impl, \ sl@0: ::boost::test_tools::tt_detail::bitwise_equal_impl( (L), (R) ), \ sl@0: "", TL, CHECK_BITWISE_EQUAL ), \ sl@0: 2, BOOST_STRINGIZE( L ), BOOST_STRINGIZE( R ) ) \ sl@0: /**/ sl@0: sl@0: #define BOOST_WARN_BITWISE_EQUAL( L, R ) BOOST_BITWISE_EQUAL_IMPL( L, R, WARN ) sl@0: #define BOOST_CHECK_BITWISE_EQUAL( L, R ) BOOST_BITWISE_EQUAL_IMPL( L, R, CHECK ) sl@0: #define BOOST_REQUIRE_BITWISE_EQUAL( L, R ) BOOST_BITWISE_EQUAL_IMPL( L, R, REQUIRE ) sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #define BOOST_IS_DEFINED( symb ) ::boost::test_tools::tt_detail::is_defined_impl( #symb, BOOST_STRINGIZE(= symb) ) sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: // ***************************** // sl@0: // deprecated interface sl@0: sl@0: #define BOOST_BITWISE_EQUAL( L, R ) BOOST_CHECK_BITWISE_EQUAL( L, R ) sl@0: #define BOOST_MESSAGE( M ) BOOST_TEST_MESSAGE( M ) sl@0: #define BOOST_CHECKPOINT( M ) BOOST_TEST_CHECKPOINT( M ) sl@0: sl@0: namespace boost { sl@0: sl@0: namespace test_tools { sl@0: sl@0: typedef unit_test::const_string const_string; sl@0: sl@0: namespace { bool dummy_cond = false; } sl@0: sl@0: namespace tt_detail { sl@0: sl@0: // ************************************************************************** // sl@0: // ************** tools classification ************** // sl@0: // ************************************************************************** // sl@0: sl@0: enum check_type { sl@0: CHECK_PRED, sl@0: CHECK_MSG, sl@0: CHECK_EQUAL, sl@0: CHECK_CLOSE, sl@0: CHECK_CLOSE_FRACTION, sl@0: CHECK_SMALL, sl@0: CHECK_BITWISE_EQUAL, sl@0: CHECK_PRED_WITH_ARGS, sl@0: CHECK_EQUAL_COLL sl@0: }; sl@0: sl@0: enum tool_level { sl@0: WARN, CHECK, REQUIRE, PASS sl@0: }; sl@0: sl@0: // ************************************************************************** // sl@0: // ************** log print helper ************** // sl@0: // ************************************************************************** // sl@0: sl@0: template sl@0: struct print_log_value { sl@0: void operator()( std::ostream& ostr, T const& t ) sl@0: { sl@0: typedef typename mpl::or_,is_function,is_abstract >::type couldnt_use_nl; sl@0: sl@0: set_precision( ostr, couldnt_use_nl() ); sl@0: sl@0: ostr << t; // by default print the value sl@0: } sl@0: sl@0: void set_precision( std::ostream& ostr, mpl::false_ ) sl@0: { sl@0: if( std::numeric_limits::is_specialized && std::numeric_limits::radix == 2 ) sl@0: ostr.precision( 2 + std::numeric_limits::digits * 301/1000 ); sl@0: } sl@0: sl@0: void set_precision( std::ostream&, mpl::true_ ) {} sl@0: }; sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #define BOOST_TEST_DONT_PRINT_LOG_VALUE( the_type ) \ sl@0: namespace boost { namespace test_tools { namespace tt_detail { \ sl@0: template<> \ sl@0: struct print_log_value { \ sl@0: void operator()( std::ostream& ostr, the_type const& t ) {} \ sl@0: }; \ sl@0: }}} \ sl@0: /**/ sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) sl@0: template sl@0: struct print_log_value< T[N] > { sl@0: void operator()( std::ostream& ostr, T const* t ) sl@0: { sl@0: ostr << t; sl@0: } sl@0: }; sl@0: #endif sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: template<> sl@0: struct BOOST_TEST_DECL print_log_value { sl@0: void operator()( std::ostream& ostr, char t ); sl@0: }; sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: template<> sl@0: struct BOOST_TEST_DECL print_log_value { sl@0: void operator()( std::ostream& ostr, unsigned char t ); sl@0: }; sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: template<> sl@0: struct BOOST_TEST_DECL print_log_value { sl@0: void operator()( std::ostream& ostr, char const* t ); sl@0: }; sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: template<> sl@0: struct BOOST_TEST_DECL print_log_value { sl@0: void operator()( std::ostream& ostr, wchar_t const* t ); sl@0: }; sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: template sl@0: struct print_helper_t { sl@0: explicit print_helper_t( T const& t ) : m_t( t ) {} sl@0: sl@0: T const& m_t; sl@0: }; sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) sl@0: // Borland suffers premature pointer decay passing arrays by reference sl@0: template sl@0: struct print_helper_t< T[N] > { sl@0: explicit print_helper_t( T const * t ) : m_t( t ) {} sl@0: sl@0: T const * m_t; sl@0: }; sl@0: #endif sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: template sl@0: inline print_helper_t print_helper( T const& t ) sl@0: { sl@0: return print_helper_t( t ); sl@0: } sl@0: sl@0: #if BOOST_WORKAROUND(__SUNPRO_CC, < 0x580) sl@0: template sl@0: inline print_helper_t print_helper( T (&t)[N] ) sl@0: { sl@0: return print_helper_t( &t[0] ); sl@0: } sl@0: #endif sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: template sl@0: inline std::ostream& sl@0: operator<<( std::ostream& ostr, print_helper_t const& ph ) sl@0: { sl@0: print_log_value()( ostr, ph.m_t ); sl@0: sl@0: return ostr; sl@0: } sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: // ************************************************************************** // sl@0: // ************** TOOL BOX Implementation ************** // sl@0: // ************************************************************************** // sl@0: sl@0: BOOST_TEST_DECL sl@0: void check_impl( predicate_result const& pr, wrap_stringstream& check_descr, sl@0: const_string file_name, std::size_t line_num, sl@0: tool_level tl, check_type ct, sl@0: std::size_t num_args, ... ); sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #define TEMPL_PARAMS( z, m, dummy ) , typename BOOST_JOIN( Arg, m ) sl@0: #define FUNC_PARAMS( z, m, dummy ) \ sl@0: , BOOST_JOIN( Arg, m ) const& BOOST_JOIN( arg, m ) \ sl@0: , char const* BOOST_JOIN( BOOST_JOIN( arg, m ), _descr ) \ sl@0: /**/ sl@0: sl@0: #define PRED_PARAMS( z, m, dummy ) BOOST_PP_COMMA_IF( m ) BOOST_JOIN( arg, m ) sl@0: sl@0: #define ARG_INFO( z, m, dummy ) \ sl@0: , BOOST_JOIN( BOOST_JOIN( arg, m ), _descr ) \ sl@0: , (boost::wrap_stringstream().ref() \ sl@0: << ::boost::test_tools::tt_detail:: \ sl@0: print_helper( BOOST_JOIN( arg, m ) )).str().c_str() \ sl@0: /**/ sl@0: sl@0: #define IMPL_FRWD( z, n, dummy ) \ sl@0: template \ sl@0: inline void \ sl@0: check_frwd( Pred P, wrap_stringstream& check_descr, \ sl@0: const_string file_name, std::size_t line_num, \ sl@0: tool_level tl, check_type ct \ sl@0: BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), FUNC_PARAMS, _ ) \ sl@0: ) \ sl@0: { \ sl@0: check_impl( P( BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), PRED_PARAMS, _ ) ), \ sl@0: check_descr, file_name, line_num, tl, ct, \ sl@0: BOOST_PP_ADD( n, 1 ) \ sl@0: BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), ARG_INFO, _ ) \ sl@0: ); \ sl@0: } \ sl@0: /**/ sl@0: sl@0: #ifndef BOOST_TEST_MAX_PREDICATE_ARITY sl@0: #define BOOST_TEST_MAX_PREDICATE_ARITY 5 sl@0: #endif sl@0: sl@0: BOOST_PP_REPEAT( BOOST_TEST_MAX_PREDICATE_ARITY, IMPL_FRWD, _ ) sl@0: sl@0: #undef TEMPL_PARAMS sl@0: #undef FUNC_PARAMS sl@0: #undef PRED_INFO sl@0: #undef ARG_INFO sl@0: #undef IMPL_FRWD sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: template sl@0: predicate_result equal_impl( Left const& left, Right const& right ) sl@0: { sl@0: return left == right; sl@0: } sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: predicate_result BOOST_TEST_DECL equal_impl( char const* left, char const* right ); sl@0: inline predicate_result BOOST_TEST_DECL equal_impl( char* left, char const* right ) { return equal_impl( (char const*)left, (char const*)right ); } sl@0: inline predicate_result BOOST_TEST_DECL equal_impl( char const* left, char* right ) { return equal_impl( (char const*)left, (char const*)right ); } sl@0: inline predicate_result BOOST_TEST_DECL equal_impl( char* left, char* right ) { return equal_impl( (char const*)left, (char const*)right ); } sl@0: sl@0: #if !defined( BOOST_NO_CWCHAR ) sl@0: predicate_result equal_impl( wchar_t const* left, wchar_t const* right ); sl@0: inline predicate_result equal_impl( wchar_t* left, wchar_t const* right ) { return equal_impl( (wchar_t const*)left, (wchar_t const*)right ); } sl@0: inline predicate_result equal_impl( wchar_t const* left, wchar_t* right ) { return equal_impl( (wchar_t const*)left, (wchar_t const*)right ); } sl@0: inline predicate_result equal_impl( wchar_t* left, wchar_t* right ) { return equal_impl( (wchar_t const*)left, (wchar_t const*)right ); } sl@0: #endif sl@0: sl@0: //____________________________________________________________________________// sl@0: // sl@0: // Declaring this class as exported causes linker errors when building sl@0: // the serialisation tests with VC6, disable this for now. (JM 2006/10/30) sl@0: struct /*BOOST_TEST_DECL*/ equal_impl_frwd { sl@0: template sl@0: inline predicate_result sl@0: call_impl( Left const& left, Right const& right, mpl::false_ ) const sl@0: { sl@0: return equal_impl( left, right ); sl@0: } sl@0: sl@0: template sl@0: inline predicate_result sl@0: call_impl( Left const& left, Right const& right, mpl::true_ ) const sl@0: { sl@0: return (*this)( right, &left[0] ); sl@0: } sl@0: sl@0: template sl@0: inline predicate_result sl@0: operator()( Left const& left, Right const& right ) const sl@0: { sl@0: typedef typename is_array::type left_is_array; sl@0: return call_impl( left, right, left_is_array() ); sl@0: } sl@0: }; sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: template sl@0: inline predicate_result sl@0: equal_coll_impl( Left left_begin, Left left_end, Right right_begin, Right right_end ) sl@0: { sl@0: predicate_result res( true ); sl@0: std::size_t pos = 0; sl@0: sl@0: for( ; left_begin != left_end && right_begin != right_end; ++left_begin, ++right_begin, ++pos ) { sl@0: if( *left_begin != *right_begin ) { sl@0: res = false; sl@0: res.message() << "\nMismatch in a position " << pos << ": " << *left_begin << " != " << *right_begin; sl@0: } sl@0: } sl@0: sl@0: if( left_begin != left_end ) { sl@0: std::size_t r_size = pos; sl@0: while( left_begin != left_end ) { sl@0: ++pos; sl@0: ++left_begin; sl@0: } sl@0: sl@0: res = false; sl@0: res.message() << "\nCollections size mismatch: " << pos << " != " << r_size; sl@0: } sl@0: sl@0: if( right_begin != right_end ) { sl@0: std::size_t l_size = pos; sl@0: while( right_begin != right_end ) { sl@0: ++pos; sl@0: ++right_begin; sl@0: } sl@0: sl@0: res = false; sl@0: res.message() << "\nCollections size mismatch: " << l_size << " != " << pos; sl@0: } sl@0: sl@0: return res; sl@0: } sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: template sl@0: inline predicate_result sl@0: bitwise_equal_impl( Left const& left, Right const& right ) sl@0: { sl@0: predicate_result res( true ); sl@0: sl@0: std::size_t left_bit_size = sizeof(Left)*CHAR_BIT; sl@0: std::size_t right_bit_size = sizeof(Right)*CHAR_BIT; sl@0: sl@0: static Left const L1( 1 ); sl@0: static Right const R1( 1 ); sl@0: sl@0: std::size_t total_bits = left_bit_size < right_bit_size ? left_bit_size : right_bit_size; sl@0: sl@0: for( std::size_t counter = 0; counter < total_bits; ++counter ) { sl@0: if( ( left & ( L1 << counter ) ) != ( right & ( R1 << counter ) ) ) { sl@0: res = false; sl@0: res.message() << "\nMismatch in a position " << counter; sl@0: } sl@0: } sl@0: sl@0: if( left_bit_size != right_bit_size ) { sl@0: res = false; sl@0: res.message() << "\nOperands bit sizes mismatch: " << left_bit_size << " != " << right_bit_size; sl@0: } sl@0: sl@0: return res; sl@0: } sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: bool BOOST_TEST_DECL is_defined_impl( const_string symbol_name, const_string symbol_value ); sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: } // namespace tt_detail sl@0: sl@0: } // namespace test_tools sl@0: sl@0: namespace test_toolbox = test_tools; sl@0: sl@0: } // namespace boost sl@0: sl@0: //____________________________________________________________________________// sl@0: sl@0: #include sl@0: sl@0: // *************************************************************************** sl@0: // Revision History : sl@0: // sl@0: // $Log: test_tools.hpp,v $ sl@0: // Revision 1.60.2.7 2007/02/22 17:57:29 speedsnail sl@0: // Make the msvc-6.5 hack even more specific, i.e. apply only in release builds. sl@0: // sl@0: // Revision 1.60.2.6 2006/12/16 15:02:16 speedsnail sl@0: // Merged from HEAD sl@0: // sl@0: // Revision 1.60.2.5 2006/11/14 21:33:26 jhunold sl@0: // Merge from HEAD: Add missing export macros for print_log_value<> sl@0: // sl@0: // Revision 1.60.2.4 2006/11/14 07:35:43 jhunold sl@0: // Merge from HEAD: Removed wrong export declarations. sl@0: // sl@0: // Revision 1.60.2.3 2006/11/13 20:06:57 jhunold sl@0: // Merge from HEAD: sl@0: // Added missing export declarations. sl@0: // sl@0: // Revision 1.60.2.2 2006/10/30 18:37:36 johnmaddock sl@0: // Patch for serialisation test failures. sl@0: // sl@0: // Revision 1.60.2.1 2006/07/24 00:43:17 gennaro_prota sl@0: // Tentative fix for Sun C++ 5.8 (don't add more specialized print_helper function template) sl@0: // sl@0: // Revision 1.60 2006/03/19 07:27:11 rogeeff sl@0: // avoid warning sl@0: // sl@0: // Revision 1.59 2006/03/03 17:39:46 rogeeff sl@0: // paaspoint added to check throw sl@0: // sl@0: // Revision 1.58 2006/02/06 10:04:55 rogeeff sl@0: // BOOST_TEST_MODULE - master test suite name sl@0: // sl@0: // Revision 1.57 2006/01/28 07:00:47 rogeeff sl@0: // sunpro port sl@0: // sl@0: // Revision 1.56 2005/12/19 03:08:30 rogeeff sl@0: // added is_abstract to guard numeric_limits instantiation sl@0: // sl@0: // Revision 1.55 2005/12/14 05:20:41 rogeeff sl@0: // dll support introduced sl@0: // BOOST_TEST_PASSPOINT() introduced sl@0: // BOOST_MESSAGE depricated. Use BOOST_TEST_MESSAGE instead sl@0: // BOOST_CHECKPOINT is depricated. Use BOOST_TEST_CHECKPOINT intead sl@0: // sl@0: // Revision 1.54 2005/06/07 04:38:20 rogeeff sl@0: // borland fix sl@0: // sl@0: // Revision 1.53 2005/05/11 04:51:14 rogeeff sl@0: // borlard portability fix sl@0: // sl@0: // Revision 1.52 2005/03/22 07:08:47 rogeeff sl@0: // string comparisons streamlined sl@0: // precision settings made portable sl@0: // sl@0: // Revision 1.51 2005/02/21 10:23:54 rogeeff sl@0: // major issue with TT redesign causing TT to reevaluate it's arguments fixed sl@0: // FP precision extended sl@0: // sl@0: // Revision 1.50 2005/02/20 08:27:06 rogeeff sl@0: // This a major update for Boost.Test framework. See release docs for complete list of fixes/updates sl@0: // sl@0: // Revision 1.49 2005/02/01 06:40:06 rogeeff sl@0: // copyright update sl@0: // old log entries removed sl@0: // minor stylistic changes sl@0: // deprecated tools removed sl@0: // sl@0: // Revision 1.48 2005/01/30 03:32:57 rogeeff sl@0: // Test Tools completely reworked: sl@0: // interfaces streamlined to provide 3 version for each tool sl@0: // implementation reworked to use single vararg formatter function sl@0: // CHECK_COLLECTION now expect 4 arguments sl@0: // BITWISE_EQUAL renamed to CHECK_BITWISE_EQUAL but still provided as deprecated sl@0: // CHECK_COLLECTION interface changed to use PP_SEQ and as a result support arbitrary number of predicate arguments sl@0: // most of templates eliminated sl@0: // deprecated tools removed sl@0: // print_helper object generator added sl@0: // sl@0: // *************************************************************************** sl@0: sl@0: #endif // BOOST_TEST_TEST_TOOLS_HPP_012705GER sl@0: