mirror of
https://github.com/boostorg/conversion.git
synced 2025-07-30 04:27:24 +02:00
Use lightweight_test.hpp instead of asserts in tests
This commit is contained in:
16
test/cast_test.cpp
Normal file → Executable file
16
test/cast_test.cpp
Normal file → Executable 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
|
||||
|
Reference in New Issue
Block a user