From 2a31073734be6e44e477079699578820282b7345 Mon Sep 17 00:00:00 2001 From: Baptiste Lepilleur Date: Tue, 16 Jul 2002 21:59:22 +0000 Subject: Include/cppunit/Protector. include/cppunit/Protector.h: * src/cppunit/Protector.cpp: added. Base class for protectors. * src/cppunit/DefaultProtector.h: * src/cppunit/DefaultProtector.cpp: added. Implementation of the default protector used to catch std::exception and any other exception. * src/cppunit/ProtectorChain.h: * src/cppunit/ProtectorChain.cpp: added. Implementation of a chain of protector, allowing catching custom exception and implementation of expected exception. * src/cppunit/TestCase.cpp: * src/cppunit/TestResult.cpp: updated to use protector. --- src/cppunit/DefaultProtector.cpp | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/cppunit/DefaultProtector.cpp (limited to 'src/cppunit/DefaultProtector.cpp') diff --git a/src/cppunit/DefaultProtector.cpp b/src/cppunit/DefaultProtector.cpp new file mode 100644 index 0000000..4c8a3ab --- /dev/null +++ b/src/cppunit/DefaultProtector.cpp @@ -0,0 +1,44 @@ +#include +#include +#include "DefaultProtector.h" + + +CPPUNIT_NS_BEGIN + + +bool +DefaultProtector::protect( const Functor &functor, + const ProtectorContext &context ) +{ + try + { + functor(); + return true; + } + catch ( Exception &failure ) + { + reportTestFailure( failure.message(), context, false ); + } + catch ( std::exception &e ) + { + std::string shortDescription( "uncaught exception of type " ); +#if CPPUNIT_USE_TYPEINFO_NAME + shortDescription += TypeInfoHelper::getClassName( typeid(e) ); +#else + shortDescription += "std::exception (or derived)." +#endif + Message message( shortDescription, e.what() ); + reportTestFailure( message, context, true ); + } + catch ( ... ) + { + reportTestFailure( Message( "uncaught exception of unknown type"), + context, + true ); + } + + return false; +} + + +CPPUNIT_NS_END -- cgit v1.2.1