Switch from deprecated test to Lightweight Test

This commit is contained in:
Glen Fernandes
2021-06-09 16:25:49 -04:00
parent 1bc71b7971
commit db44689f4f
10 changed files with 70 additions and 140 deletions

View File

@@ -32,17 +32,11 @@ void test_bounds( T expected_lowest, T expected_highest, T expected_smallest )
T highest = bounds<T>::highest () ;
T smallest = bounds<T>::smallest() ;
BOOST_CHECK_MESSAGE ( lowest == expected_lowest,
"bounds<" << typeid(T).name() << ">::lowest() = " << printable(lowest) << ". Expected " << printable(expected_lowest)
) ;
BOOST_TEST_EQ(lowest, expected_lowest);
BOOST_CHECK_MESSAGE ( highest == expected_highest,
"bounds<" << typeid(T).name() << ">::highest() = " << printable(highest) << ". Expected " << printable(expected_highest)
) ;
BOOST_TEST_EQ(highest, expected_highest);
BOOST_CHECK_MESSAGE ( smallest == expected_smallest,
"bounds<" << typeid(T).name() << ">::smallest() = " << printable(smallest) << ". Expected " << printable(expected_smallest)
) ;
BOOST_TEST_EQ(smallest, expected_smallest);
}
@@ -90,12 +84,12 @@ void test_bounds()
}
int test_main( int, char * [] )
int main( )
{
cout << setprecision( std::numeric_limits<long double>::digits10 ) ;
test_bounds();
return 0;
return boost::report_errors();
}

View File

@@ -16,7 +16,6 @@
#include <boost/preprocessor/tuple/elem.hpp>
#include <boost/preprocessor/seq/elem.hpp>
#include <boost/preprocessor/seq/size.hpp>
#include <boost/test/minimal.hpp>
//! Generate default traits for the specified source and target.
#define BOOST_NUMERIC_CONVERSION_GENERATE_CAST_TRAITS(r, state) \
@@ -109,12 +108,6 @@ namespace boost { namespace numeric {
#endif
}}//namespace boost::numeric;
int test_main( int argc, char * argv[] )
{
//! This test should not compile.
return 1;
}
#undef BOOST_NUMERIC_CONVERSION_GENERATE_BUILTIN_CAST_TRAITS
#undef BOOST_NUMERIC_CONVERSION_GENERATE_CAST_TARGET_STEP
#undef BOOST_NUMERIC_CONVERSION_INC_OP

View File

@@ -368,7 +368,7 @@ void test_round_style( MATCH_FNTPL_ARG(T), MATCH_FNTPL_ARG(S) )
void test_round_even( double n, double x )
{
double r = boost::numeric::RoundEven<double>::nearbyint(n);
BOOST_CHECK( r == x ) ;
BOOST_TEST( r == x ) ;
}
void test_round_even()
@@ -419,7 +419,7 @@ void test_converter_as_function_object()
// Match 'w' and 'i' which should be equal.
bool double_to_int_OK = std::equal(W.begin(),W.end(),I.begin()) ;
BOOST_CHECK_MESSAGE(double_to_int_OK, "converter (int,double) as function object");
BOOST_TEST(double_to_int_OK);
// Create a sequence of double values from s using a default numeric::converter (which should be the trivial conv).
std::vector<double> D ;
@@ -431,7 +431,7 @@ void test_converter_as_function_object()
// Match 's' and 'd' which should be equal.
bool double_to_double_OK = std::equal(S.begin(),S.end(),D.begin()) ;
BOOST_CHECK_MESSAGE(double_to_double_OK, "converter (double,double) as function object");
BOOST_TEST(double_to_double_OK);
}
#if BOOST_WORKAROUND(__IBMCPP__, <= 600 ) // VCAPP6
@@ -545,7 +545,7 @@ void test_optimizations()
//---------------------------------
}
int test_main( int, char* argv[] )
int main()
{
std::cout << std::setprecision( std::numeric_limits<long double>::digits10 ) ;
@@ -556,7 +556,7 @@ int test_main( int, char* argv[] )
test_converter_as_function_object();
test_optimizations() ;
return 0;
return boost::report_errors();
}
//---------------------------------------------------------------------------

View File

@@ -15,7 +15,7 @@
#include <boost/numeric/conversion/cast.hpp>
#include "boost/test/minimal.hpp"
#include <boost/core/lightweight_test.hpp>
# if SCHAR_MAX == LONG_MAX
# error "This test program doesn't work if SCHAR_MAX == LONG_MAX"
@@ -24,7 +24,7 @@
using namespace boost;
using std::cout;
int test_main( int argc, char * argv[] )
int main()
{
# ifdef NDEBUG
@@ -47,51 +47,34 @@ int test_main( int argc, char * argv[] )
c = large_value; // see if compiler generates warning
c = numeric_cast<signed char>( small_value );
BOOST_CHECK( c == 1 );
BOOST_TEST( c == 1 );
c = 0;
c = numeric_cast<signed char>( small_value );
BOOST_CHECK( c == 1 );
BOOST_TEST( c == 1 );
c = 0;
c = numeric_cast<signed char>( small_negative_value );
BOOST_CHECK( c == -1 );
BOOST_TEST( c == -1 );
// These tests courtesy of Joe R NWP Swatosh<joe.r.swatosh@usace.army.mil>
BOOST_CHECK( 0.0f == numeric_cast<float>( 0.0 ) );
BOOST_CHECK( 0.0 == numeric_cast<double>( 0.0 ) );
BOOST_TEST( 0.0f == numeric_cast<float>( 0.0 ) );
BOOST_TEST( 0.0 == numeric_cast<double>( 0.0 ) );
// tests which should result in errors being detected
bool caught_exception = false;
try { c = numeric_cast<signed char>( large_value ); }
catch ( numeric::bad_numeric_cast )
{ cout<<"caught bad_numeric_cast #1\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
BOOST_TEST_THROWS( numeric_cast<signed char>(large_value),
numeric::bad_numeric_cast );
caught_exception = false;
try { c = numeric_cast<signed char>( large_negative_value ); }
catch ( numeric::bad_numeric_cast )
{ cout<<"caught bad_numeric_cast #2\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
BOOST_TEST_THROWS( numeric_cast<signed char>(large_negative_value),
numeric::bad_numeric_cast );
unsigned long ul;
caught_exception = false;
try { ul = numeric_cast<unsigned long>( large_negative_value ); }
catch ( numeric::bad_numeric_cast )
{ cout<<"caught bad_numeric_cast #3\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
BOOST_TEST_THROWS( numeric_cast<signed char>(large_negative_value),
numeric::bad_numeric_cast );
caught_exception = false;
try { ul = numeric_cast<unsigned long>( small_negative_value ); }
catch ( numeric::bad_numeric_cast )
{ cout<<"caught bad_numeric_cast #4\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
BOOST_TEST_THROWS( numeric_cast<unsigned long>(small_negative_value),
numeric::bad_numeric_cast );
caught_exception = false;
try { numeric_cast<int>( DBL_MAX ); }
catch ( numeric::bad_numeric_cast )
{ cout<<"caught bad_numeric_cast #5\n"; caught_exception = true; }
BOOST_CHECK ( caught_exception );
BOOST_TEST_THROWS( numeric_cast<int>(DBL_MAX), numeric::bad_numeric_cast );
return 0 ;
return boost::report_errors() ;
} // main

View File

@@ -12,7 +12,8 @@
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/cstdint.hpp>
#include <boost/test/minimal.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/static_assert.hpp>
//! Define a simple custom number
struct Double
@@ -314,15 +315,11 @@ namespace boost { namespace numeric {
}}//namespace boost::numeric;
#define BOOST_TEST_CATCH_CUSTOM_POSITIVE_OVERFLOW( CastCode ) \
try { CastCode; BOOST_CHECK( false ); } \
catch( custom::positive_overflow& ){} \
catch(...){ BOOST_CHECK( false ); } \
BOOST_TEST_THROWS( CastCode, custom::positive_overflow )
/***/
#define BOOST_TEST_CATCH_CUSTOM_NEGATIVE_OVERFLOW( CastCode ) \
try { CastCode; BOOST_CHECK( false ); } \
catch( custom::negative_overflow& ){} \
catch(...){ BOOST_CHECK( false ); } \
BOOST_TEST_THROWS( CastCode, custom::negative_overflow )
/***/
struct test_cast_traits
@@ -331,9 +328,9 @@ struct test_cast_traits
void operator()(T) const
{
Double d = boost::numeric_cast<Double>( static_cast<T>(50) );
BOOST_CHECK( d.v == 50. );
BOOST_TEST( d.v == 50. );
T v = boost::numeric_cast<T>( d );
BOOST_CHECK( v == 50 );
BOOST_TEST( v == 50 );
}
};
@@ -360,20 +357,20 @@ void test_numeric_cast_traits()
//! Check overflow handler.
Double d( 56.0 );
BOOST_TEST_CATCH_CUSTOM_POSITIVE_OVERFLOW( d = boost::numeric_cast<Double>( 101 ) );
BOOST_CHECK( d.v == 56. );
BOOST_TEST( d.v == 56. );
BOOST_TEST_CATCH_CUSTOM_NEGATIVE_OVERFLOW( d = boost::numeric_cast<Double>( -101 ) );
BOOST_CHECK( d.v == 56.);
BOOST_TEST( d.v == 56.);
//! Check custom round policy.
d = 5.9;
int five = boost::numeric_cast<int>( d );
BOOST_CHECK( five == 5 );
BOOST_TEST( five == 5 );
}
int test_main( int argc, char * argv[] )
int main()
{
test_numeric_cast_traits();
return 0;
return boost::report_errors();
}
#undef BOOST_TEST_CATCH_CUSTOM_POSITIVE_OVERFLOW

View File

@@ -16,7 +16,7 @@
#include "boost/limits.hpp"
#include "boost/utility.hpp"
#include "boost/test/included/test_exec_monitor.hpp"
#include <boost/core/lightweight_test.hpp>
// Convenience macros to help with compilers which don't parse
// explicit template function instantiations (MSVC6)

View File

@@ -69,51 +69,22 @@ void test_conv_base( Instance const& conv )
{
result_type result = converter::convert(source);
if ( conv.post == c_converted )
if (BOOST_TEST_EQ(conv.post, c_converted))
{
BOOST_CHECK_MESSAGE( result == conv.result,
conv.to_string() << printable(source) << ")= " << printable(result) << ". Expected:" << printable(conv.result)
) ;
}
else
{
BOOST_ERROR( conv.to_string() << printable(source) << ") = " << printable(result)
<< ". Expected:" << ( conv.post == c_neg_overflow ? " negative_overflow" : "positive_overflow" )
) ;
BOOST_TEST_EQ(result, conv.result);
}
}
catch ( boost::numeric::negative_overflow const& )
{
if ( conv.post == c_neg_overflow )
{
BOOST_CHECK_MESSAGE( true, conv.to_string() << printable(source) << ") = negative_overflow, as expected" ) ;
}
else
{
BOOST_ERROR( conv.to_string() << printable(source) << ") = negative_overflow. Expected:" << printable(conv.result) ) ;
}
{
BOOST_TEST_EQ(conv.post, c_neg_overflow);
}
catch ( boost::numeric::positive_overflow const& )
{
if ( conv.post == c_pos_overflow )
{
BOOST_CHECK_MESSAGE( true, conv.to_string() << printable(source) << ") = positive_overflow, as expected" ) ;
}
else
{
BOOST_ERROR( conv.to_string() << printable(source) << ") = positive_overflow. Expected:" << printable(conv.result) ) ;
}
BOOST_TEST_EQ(conv.post, c_pos_overflow);
}
catch ( boost::numeric::bad_numeric_cast const& )
{
if ( conv.post == c_overflow )
{
BOOST_CHECK_MESSAGE( true, conv.to_string() << printable(source) << ") = bad_numeric_cast, as expected" ) ;
}
else
{
BOOST_ERROR( conv.to_string() << printable(source) << ") = bad_numeric_cast. Expected:" << printable(conv.result) ) ;
}
BOOST_TEST_EQ(conv.post, c_overflow);
}
}

View File

@@ -258,11 +258,7 @@ struct generate_expected_traits
#define TEST_VALUE_FIELD(Name) \
typedef typename traits::Name BOOST_PP_CAT(t,Name) ; \
typedef typename expected::Name BOOST_PP_CAT(x,Name) ; \
BOOST_CHECK_MESSAGE ( ( BOOST_PP_CAT(t,Name)::value == BOOST_PP_CAT(x,Name)::value ) , \
"conversion_traits<" << typeid(T).name() << "," << typeid(S).name() \
<< ">::" << #Name << " = " << to_string(BOOST_PP_CAT(t,Name)::value) \
<< ". Expected: " << to_string(BOOST_PP_CAT(x,Name)::value) \
) ;
BOOST_TEST( ( BOOST_PP_CAT(t,Name)::value == BOOST_PP_CAT(x,Name)::value ) ) ;
// This macro generates the code that compares a type field
// in numeric::conversion_traits<> with its corresponding field
@@ -271,11 +267,7 @@ struct generate_expected_traits
#define TEST_TYPE_FIELD(Name) \
typedef typename traits::Name BOOST_PP_CAT(t,Name) ; \
typedef typename expected::Name BOOST_PP_CAT(x,Name) ; \
BOOST_CHECK_MESSAGE ( ( typeid(BOOST_PP_CAT(t,Name)) == typeid(BOOST_PP_CAT(x,Name)) ) , \
"conversion_traits<" << typeid(T).name() << "," << typeid(S).name() \
<< ">::" << #Name << " = " << typeid(BOOST_PP_CAT(t,Name)).name() \
<< ". Expected: " << typeid(BOOST_PP_CAT(x,Name)).name() \
) ;
BOOST_TEST ( ( typeid(BOOST_PP_CAT(t,Name)) == typeid(BOOST_PP_CAT(x,Name)) ) ) ;
//
// Test core.
@@ -329,13 +321,13 @@ void test_traits()
test_traits_from( SET_FNTPL_ARG(MyFloat) );
}
int test_main( int, char * [])
int main()
{
std::cout << std::setprecision( std::numeric_limits<long double>::digits10 ) ;
test_traits();
return 0;
return boost::report_errors();
}
//---------------------------------------------------------------------------

View File

@@ -16,7 +16,7 @@
#include<cmath>
#include "boost/test/included/test_exec_monitor.hpp"
#include <boost/core/lightweight_test.hpp>
#include "boost/numeric/conversion/cast.hpp"
@@ -58,13 +58,13 @@ void simplest_case()
//
// conversion_traits<>::udt_builtin_mixture works out of the box as long as boost::is_arithmetic<UDT> yields false
//
BOOST_CHECK( (conversion_traits<double,Double>::udt_builtin_mixture::value == udt_to_builtin) ) ;
BOOST_CHECK( (conversion_traits<Double,double>::udt_builtin_mixture::value == builtin_to_udt) ) ;
BOOST_CHECK( (conversion_traits<Double,Double>::udt_builtin_mixture::value == udt_to_udt ) ) ;
BOOST_TEST( (conversion_traits<double,Double>::udt_builtin_mixture::value == udt_to_builtin) ) ;
BOOST_TEST( (conversion_traits<Double,double>::udt_builtin_mixture::value == builtin_to_udt) ) ;
BOOST_TEST( (conversion_traits<Double,Double>::udt_builtin_mixture::value == udt_to_udt ) ) ;
// BY DEFINITION, a conversion from UDT to Builtin is subranged. No attempt is made to actually compare ranges.
BOOST_CHECK( (conversion_traits<double,Double>::subranged::value) == true ) ;
BOOST_CHECK( (conversion_traits<Double,double>::subranged::value) == false ) ;
BOOST_TEST( (conversion_traits<double,Double>::subranged::value) == true ) ;
BOOST_TEST( (conversion_traits<Double,double>::subranged::value) == false ) ;
@@ -72,18 +72,18 @@ void simplest_case()
// Conversions to/from FLOATING types, if already supported by an UDT
// are also supported out-of-the-box by converter<> in its default configuration.
//
BOOST_CHECK( numeric_cast<double>(Dv) == static_cast<double>(Dv) ) ;
BOOST_CHECK( numeric_cast<Double>(dv) == static_cast<Double>(dv) ) ;
BOOST_TEST( numeric_cast<double>(Dv) == static_cast<double>(Dv) ) ;
BOOST_TEST( numeric_cast<Double>(dv) == static_cast<Double>(dv) ) ;
BOOST_CHECK( numeric_cast<float> (Dv) == static_cast<float> (Dv) ) ;
BOOST_CHECK( numeric_cast<Double>(fv) == static_cast<Double>(fv) ) ;
BOOST_TEST( numeric_cast<float> (Dv) == static_cast<float> (Dv) ) ;
BOOST_TEST( numeric_cast<Double>(fv) == static_cast<Double>(fv) ) ;
//
// Range checking is disabled by default if an UDT is either the source or target of the conversion.
//
BOOST_CHECK( (converter<float,double>::out_of_range(dv) == cPosOverflow) );
BOOST_CHECK( (converter<float,Double>::out_of_range(Dv) == cInRange) );
BOOST_TEST( (converter<float,double>::out_of_range(dv) == cPosOverflow) );
BOOST_TEST( (converter<float,Double>::out_of_range(Dv) == cInRange) );
}
@@ -110,7 +110,7 @@ Double ceil ( Double v ) { return Double(std::ceil (v.mV)) ; }
void rounding()
{
BOOST_CHECK( numeric_cast<int>(Dv) == static_cast<int>(Dv) ) ;
BOOST_TEST( numeric_cast<int>(Dv) == static_cast<int>(Dv) ) ;
}
@@ -135,7 +135,7 @@ void custom_rounding()
>
DoubleToIntConverter ;
BOOST_CHECK( DoubleToIntConverter::convert(Dv) == static_cast<int>(Dv) ) ;
BOOST_TEST( DoubleToIntConverter::convert(Dv) == static_cast<int>(Dv) ) ;
}
//
@@ -187,8 +187,8 @@ void custom_raw_converter()
Int i (12);
Float fi(12);
BOOST_CHECK(numeric_cast<Int> (f).mV == i .mV ) ;
BOOST_CHECK(numeric_cast<Float>(i).mV == fi.mV ) ;
BOOST_TEST(numeric_cast<Int> (f).mV == i .mV ) ;
BOOST_TEST(numeric_cast<Float>(i).mV == fi.mV ) ;
}
//
@@ -219,10 +219,10 @@ void custom_raw_converter2()
>
Float2IntConverter ;
BOOST_CHECK(Float2IntConverter::convert(f).mV == i .mV ) ;
BOOST_TEST(Float2IntConverter::convert(f).mV == i .mV ) ;
}
int test_main( int, char* [] )
int main()
{
cout << setprecision( numeric_limits<long double>::digits10 ) ;
@@ -232,7 +232,7 @@ int test_main( int, char* [] )
custom_raw_converter();
custom_raw_converter2();
return 0;
return boost::report_errors();
}

View File

@@ -292,14 +292,14 @@ void test_udt_conversions_with_custom_range_checking()
}
int test_main( int, char* [] )
int main()
{
cout << setprecision( numeric_limits<long double>::digits10 ) ;
test_udt_conversions_with_defaults();
test_udt_conversions_with_custom_range_checking();
return 0;
return boost::report_errors();
}