File indexing completed on 2025-01-18 09:52:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef BOOST_TEST_TOOLS_OLD_IMPL_HPP_012705GER
0016 #define BOOST_TEST_TOOLS_OLD_IMPL_HPP_012705GER
0017
0018
0019 #include <boost/test/unit_test_log.hpp>
0020 #include <boost/test/tools/assertion_result.hpp>
0021 #include <boost/test/tools/floating_point_comparison.hpp>
0022
0023 #include <boost/test/tools/detail/fwd.hpp>
0024 #include <boost/test/tools/detail/print_helper.hpp>
0025
0026
0027 #include <boost/limits.hpp>
0028 #include <boost/numeric/conversion/conversion_traits.hpp> // for numeric::conversion_traits
0029 #include <boost/type_traits/is_array.hpp>
0030
0031 #include <boost/preprocessor/repetition/repeat.hpp>
0032 #include <boost/preprocessor/arithmetic/add.hpp>
0033
0034
0035 #include <cstddef> // for std::size_t
0036 #include <climits> // for CHAR_BIT
0037
0038 #include <boost/test/detail/suppress_warnings.hpp>
0039
0040
0041
0042 namespace boost {
0043 namespace test_tools {
0044 namespace tt_detail {
0045
0046
0047
0048
0049
0050
0051
0052
0053 #ifndef BOOST_TEST_PROD
0054 #define TEMPL_PARAMS( z, m, dummy ) , typename BOOST_JOIN( Arg, m )
0055
0056 #define FUNC_PARAMS( z, m, dummy ) \
0057 , BOOST_JOIN( Arg, m ) const& BOOST_JOIN( arg, m ) \
0058 , char const* BOOST_JOIN( BOOST_JOIN( arg, m ), _descr ) \
0059
0060
0061 #define PRED_PARAMS( z, m, dummy ) BOOST_PP_COMMA_IF( m ) BOOST_JOIN( arg, m )
0062
0063 #define ARG_INFO( z, m, dummy ) \
0064 , BOOST_JOIN( BOOST_JOIN( arg, m ), _descr ) \
0065 , &static_cast<const unit_test::lazy_ostream&>(unit_test::lazy_ostream::instance() \
0066 << ::boost::test_tools::tt_detail::print_helper( BOOST_JOIN( arg, m ) )) \
0067
0068
0069 #define IMPL_FRWD( z, n, dummy ) \
0070 template<typename Pred \
0071 BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), TEMPL_PARAMS, _ )> \
0072 inline bool \
0073 check_frwd( Pred P, unit_test::lazy_ostream const& assertion_descr, \
0074 const_string file_name, std::size_t line_num, \
0075 tool_level tl, check_type ct \
0076 BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), FUNC_PARAMS, _ ) \
0077 ) \
0078 { \
0079 return \
0080 report_assertion( P( BOOST_PP_REPEAT_ ## z(BOOST_PP_ADD(n, 1), PRED_PARAMS,_) ),\
0081 assertion_descr, file_name, line_num, tl, ct, \
0082 BOOST_PP_ADD( n, 1 ) \
0083 BOOST_PP_REPEAT_ ## z( BOOST_PP_ADD( n, 1 ), ARG_INFO, _ ) \
0084 ); \
0085 } \
0086
0087
0088 #ifndef BOOST_TEST_MAX_PREDICATE_ARITY
0089 #define BOOST_TEST_MAX_PREDICATE_ARITY 5
0090 #endif
0091
0092 BOOST_PP_REPEAT( BOOST_TEST_MAX_PREDICATE_ARITY, IMPL_FRWD, _ )
0093
0094 #undef TEMPL_PARAMS
0095 #undef FUNC_PARAMS
0096 #undef PRED_INFO
0097 #undef ARG_INFO
0098 #undef IMPL_FRWD
0099
0100 #endif
0101
0102
0103
0104 template <class Left, class Right>
0105 inline assertion_result equal_impl( Left const& left, Right const& right )
0106 {
0107 return left == right;
0108 }
0109
0110
0111
0112 inline assertion_result equal_impl( char* left, char const* right ) { return equal_impl( static_cast<char const*>(left), static_cast<char const*>(right) ); }
0113 inline assertion_result equal_impl( char const* left, char* right ) { return equal_impl( static_cast<char const*>(left), static_cast<char const*>(right) ); }
0114 inline assertion_result equal_impl( char* left, char* right ) { return equal_impl( static_cast<char const*>(left), static_cast<char const*>(right) ); }
0115
0116 #if !defined( BOOST_NO_CWCHAR )
0117 BOOST_TEST_DECL assertion_result equal_impl( wchar_t const* left, wchar_t const* right );
0118 inline assertion_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) ); }
0119 inline assertion_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) ); }
0120 inline assertion_result equal_impl( wchar_t* left, wchar_t* right ) { return equal_impl( static_cast<wchar_t const*>(left), static_cast<wchar_t const*>(right) ); }
0121 #endif
0122
0123
0124
0125 struct equal_impl_frwd {
0126 template <typename Left, typename Right>
0127 inline assertion_result
0128 call_impl( Left const& left, Right const& right, mpl::false_ ) const
0129 {
0130 return equal_impl( left, right );
0131 }
0132
0133 template <typename Left, typename Right>
0134 inline assertion_result
0135 call_impl( Left const& left, Right const& right, mpl::true_ ) const
0136 {
0137 return (*this)( right, &left[0] );
0138 }
0139
0140 template <typename Left, typename Right>
0141 inline assertion_result
0142 operator()( Left const& left, Right const& right ) const
0143 {
0144 typedef typename is_array<Left>::type left_is_array;
0145 return call_impl( left, right, left_is_array() );
0146 }
0147 };
0148
0149
0150
0151 struct ne_impl {
0152 template <class Left, class Right>
0153 assertion_result operator()( Left const& left, Right const& right )
0154 {
0155 return !equal_impl_frwd()( left, right );
0156 }
0157 };
0158
0159
0160
0161 struct lt_impl {
0162 template <class Left, class Right>
0163 assertion_result operator()( Left const& left, Right const& right )
0164 {
0165 return left < right;
0166 }
0167 };
0168
0169
0170
0171 struct le_impl {
0172 template <class Left, class Right>
0173 assertion_result operator()( Left const& left, Right const& right )
0174 {
0175 return left <= right;
0176 }
0177 };
0178
0179
0180
0181 struct gt_impl {
0182 template <class Left, class Right>
0183 assertion_result operator()( Left const& left, Right const& right )
0184 {
0185 return left > right;
0186 }
0187 };
0188
0189
0190
0191 struct ge_impl {
0192 template <class Left, class Right>
0193 assertion_result operator()( Left const& left, Right const& right )
0194 {
0195 return left >= right;
0196 }
0197 };
0198
0199
0200
0201 struct equal_coll_impl {
0202 template <typename Left, typename Right>
0203 assertion_result operator()( Left left_begin, Left left_end, Right right_begin, Right right_end )
0204 {
0205 assertion_result pr( true );
0206 std::size_t pos = 0;
0207
0208 for( ; left_begin != left_end && right_begin != right_end; ++left_begin, ++right_begin, ++pos ) {
0209 if( *left_begin != *right_begin ) {
0210 pr = false;
0211 pr.message() << "\nMismatch at position " << pos << ": "
0212 << ::boost::test_tools::tt_detail::print_helper(*left_begin)
0213 << " != "
0214 << ::boost::test_tools::tt_detail::print_helper(*right_begin);
0215 }
0216 }
0217
0218 if( left_begin != left_end ) {
0219 std::size_t r_size = pos;
0220 while( left_begin != left_end ) {
0221 ++pos;
0222 ++left_begin;
0223 }
0224
0225 pr = false;
0226 pr.message() << "\nCollections size mismatch: " << pos << " != " << r_size;
0227 }
0228
0229 if( right_begin != right_end ) {
0230 std::size_t l_size = pos;
0231 while( right_begin != right_end ) {
0232 ++pos;
0233 ++right_begin;
0234 }
0235
0236 pr = false;
0237 pr.message() << "\nCollections size mismatch: " << l_size << " != " << pos;
0238 }
0239
0240 return pr;
0241 }
0242 };
0243
0244
0245
0246 struct bitwise_equal_impl {
0247 template <class Left, class Right>
0248 assertion_result operator()( Left const& left, Right const& right )
0249 {
0250 assertion_result pr( true );
0251
0252 std::size_t left_bit_size = sizeof(Left)*CHAR_BIT;
0253 std::size_t right_bit_size = sizeof(Right)*CHAR_BIT;
0254
0255 static Left const leftOne( 1 );
0256 static Right const rightOne( 1 );
0257
0258 std::size_t total_bits = left_bit_size < right_bit_size ? left_bit_size : right_bit_size;
0259
0260 for( std::size_t counter = 0; counter < total_bits; ++counter ) {
0261 if( ( left & ( leftOne << counter ) ) != ( right & ( rightOne << counter ) ) ) {
0262 pr = false;
0263 pr.message() << "\nMismatch at position " << counter;
0264 }
0265 }
0266
0267 if( left_bit_size != right_bit_size ) {
0268 pr = false;
0269 pr.message() << "\nOperands bit sizes mismatch: " << left_bit_size << " != " << right_bit_size;
0270 }
0271
0272 return pr;
0273 }
0274 };
0275
0276
0277
0278 template<typename FPT1, typename FPT2>
0279 struct comp_supertype {
0280
0281
0282
0283
0284 typedef typename numeric::conversion_traits<FPT1,FPT2>::supertype type;
0285 BOOST_STATIC_ASSERT_MSG( !is_integral<type>::value, "Only floating-point types can be compared!");
0286 };
0287
0288 }
0289
0290 namespace fpc = math::fpc;
0291
0292
0293
0294
0295
0296 struct BOOST_TEST_DECL check_is_close_t {
0297
0298 typedef assertion_result result_type;
0299
0300 template<typename FPT1, typename FPT2, typename ToleranceType>
0301 assertion_result
0302 operator()( FPT1 left, FPT2 right, ToleranceType tolerance ) const
0303 {
0304 typedef typename tt_detail::comp_supertype<FPT1,FPT2>::type super_type;
0305 fpc::close_at_tolerance<super_type> pred( tolerance, fpc::FPC_STRONG );
0306
0307 assertion_result ar( pred( static_cast<super_type>(left), static_cast<super_type>(right) ) );
0308
0309 if( !ar )
0310 ar.message() << pred.tested_rel_diff();
0311
0312 return ar;
0313 }
0314 };
0315
0316
0317
0318 template<typename FPT1, typename FPT2, typename ToleranceType>
0319 inline assertion_result
0320 check_is_close( FPT1 left, FPT2 right, ToleranceType tolerance )
0321 {
0322 return check_is_close_t()( left, right, tolerance );
0323 }
0324
0325
0326
0327
0328
0329
0330
0331 struct BOOST_TEST_DECL check_is_small_t {
0332
0333 typedef bool result_type;
0334
0335 template<typename FPT>
0336 bool
0337 operator()( FPT fpv, FPT tolerance ) const
0338 {
0339 return fpc::is_small( fpv, tolerance );
0340 }
0341 };
0342
0343
0344
0345 template<typename FPT>
0346 inline bool
0347 check_is_small( FPT fpv, FPT tolerance )
0348 {
0349 return fpc::is_small( fpv, tolerance );
0350 }
0351
0352
0353
0354 }
0355 }
0356
0357 #include <boost/test/detail/enable_warnings.hpp>
0358
0359 #endif