[Cppunit-cvs] cppunit2/src/cpputtest testexceptionguard.cpp,NONE,1.1 cpputtest.vcproj,1.16,1.17 test
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-02-28 20:43:13
|
Update of /cvsroot/cppunit/cppunit2/src/cpputtest In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2779/src/cpputtest Modified Files: cpputtest.vcproj Added Files: testexceptionguard.cpp Removed Files: testtestcontext.cpp Log Message: * added testexceptionguard.cpp which replaces testtestcontext.cpp --- NEW FILE: testexceptionguard.cpp --- #include <cpput/assert.h> #include <cpput/exceptionguard.h> #include <cpptl/functor.h> #include <stdio.h> static void increment( int *value ) { ++*value; } static void throwStdException() { throw std::exception(); } namespace { struct CustomException { }; struct AnyException { }; } static void throwAnyException() { throw AnyException(); } static void throwCustomException() { throw CustomException(); } static void testExceptionGuardRunFunctor() { int value = 1; CppUT::ExceptionGuard guard; bool result = guard.protect( CppTL::bind_cfn( &increment, &value ) ); CPPUT_ASSERT_EQUAL( 2, value ); CPPUT_ASSERT_EQUAL( true, result ); } static void testExceptionGuardCatchStandardException() { CppUT::ExceptionGuard guard; bool result = guard.protect( CppTL::cfn0( &throwStdException ) ); CPPUT_ASSERT_EQUAL( false, result ); } static void testExceptionGuardCatchAnyException() { CppUT::ExceptionGuard guard; bool result = guard.protect( CppTL::cfn0( &throwAnyException ) ); CPPUT_ASSERT_EQUAL( false, result ); } static void customExceptionTranslation( const CustomException &e, int *value ) { ++*value; } static void testExceptionGuardAddCustomHandler() { int value = 1; CppUT::ExceptionGuard guard; // check that the exception translator is called CppUT::registerExceptionTranslation( guard, CppTL::bind2( CppTL::cfn2( &customExceptionTranslation ), &value ), CppTL::Type<CustomException>() ); bool result = guard.protect( CppTL::cfn0( &throwCustomException ) ); CPPUT_ASSERT_EQUAL( false, result ); CPPUT_ASSERT_EQUAL( 2, value ); // check that standard and ... catch handler are still active. result = guard.protect( CppTL::cfn0( &throwStdException ) ); CPPUT_ASSERT_EQUAL( false, result ); CPPUT_ASSERT_EQUAL( 2, value ); result = guard.protect( CppTL::cfn0( &throwAnyException ) ); CPPUT_ASSERT_EQUAL( false, result ); guard.removeLast(); // check that standard and ... catch handler are still active, // but not the custom exception handler. result = guard.protect( CppTL::cfn0( &throwCustomException ) ); CPPUT_ASSERT_EQUAL( false, result ); CPPUT_ASSERT_EQUAL( 2, value ); result = guard.protect( CppTL::cfn0( &throwStdException ) ); CPPUT_ASSERT_EQUAL( false, result ); } bool testExceptionGuard() { printf( "Running bootstrap test: testExceptionGuard()...\n" ); try { CppUT::TestInfo::startNewTest(); testExceptionGuardRunFunctor(); testExceptionGuardCatchStandardException(); testExceptionGuardCatchAnyException(); testExceptionGuardAddCustomHandler(); } catch ( const CppUT::AbortingAssertionException &e ) { printf( "testExceptionGuard() failed: %s\n", e.what() ); return false; } catch ( ... ) { printf( "testExceptionGuard() failed (uncaught exception).\n" ); return false; } return true; } Index: cpputtest.vcproj =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpputtest/cpputtest.vcproj,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** cpputtest.vcproj 27 Feb 2005 17:42:32 -0000 1.16 --- cpputtest.vcproj 28 Feb 2005 20:43:02 -0000 1.17 *************** *** 188,194 **** </File> <File - RelativePath=".\mocktestlistener.h"> - </File> - <File RelativePath=".\mocktestvisitor.h"> </File> --- 188,191 ---- --- testtestcontext.cpp DELETED --- |