Use lightweight_test.hpp instead of asserts in tests

This commit is contained in:
Antony Polukhin
2015-12-30 00:07:48 +03:00
parent b6e9403ef0
commit a7b9f42b9a

16
test/cast_test.cpp Normal file → Executable file
View File

@ -15,6 +15,7 @@
#include <iostream>
#include <boost/polymorphic_cast.hpp>
#include <boost/core/lightweight_test.hpp>
using namespace boost;
using std::cout;
@ -54,16 +55,15 @@ int main( int argc, char * argv[] )
Derived derived_instance;
Base * base = &derived_instance;
Derived * derived = polymorphic_downcast<Derived*>( base ); // downcast
assert( derived->kind() == 'D' );
BOOST_TEST( derived->kind() == 'D' );
derived = polymorphic_cast<Derived*>( base ); // downcast, throw on error
assert( derived->kind() == 'D' );
BOOST_TEST( derived->kind() == 'D' );
Base2 * base2 = polymorphic_cast<Base2*>( base ); // crosscast
assert( base2->kind2() == '2' );
BOOST_TEST( base2->kind2() == '2' );
// tests which should result in errors being detected
int err_count = 0;
Base base_instance;
base = &base_instance;
@ -74,11 +74,9 @@ int main( int argc, char * argv[] )
try { derived = polymorphic_cast<Derived*>( base ); }
catch (std::bad_cast)
{ cout<<"caught bad_cast\n"; caught_exception = true; }
if ( !caught_exception ) ++err_count;
BOOST_TEST( caught_exception );
// the following is just so generated code can be inspected
if ( derived->kind() == 'B' ) ++err_count;
BOOST_TEST( derived->kind() != 'B' );
cout << err_count << " errors detected\nTest "
<< (err_count==0 ? "passed\n" : "failed\n");
return err_count;
return boost::report_errors();
} // main