[Cppunit-cvs] cppunit2/src/cpput exceptionguard.cpp,NONE,1.1 testcase.cpp,1.7,1.8 testfailureguard.c
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-02-22 21:27:03
|
Update of /cvsroot/cppunit/cppunit2/src/cpput In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27352/src/cpput Modified Files: testcase.cpp Added Files: exceptionguard.cpp Removed Files: testfailureguard.cpp Log Message: * renamed testfailureguard.h/cpp to exceptionguard.h/cpp --- testfailureguard.cpp DELETED --- Index: testcase.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/testcase.cpp,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** testcase.cpp 22 Feb 2005 21:14:39 -0000 1.7 --- testcase.cpp 22 Feb 2005 21:26:49 -0000 1.8 *************** *** 3,7 **** #include <cpput/functor.h> #include <cpput/message.h> ! #include <cpput/testfailureguard.h> #include <cpput/testvisitor.h> --- 3,7 ---- #include <cpput/functor.h> #include <cpput/message.h> ! #include <cpput/exceptionguard.h> #include <cpput/testvisitor.h> --- NEW FILE: exceptionguard.cpp --- #include <cpput/exceptionguard.h> #include <cpput/testinfo.h> #include <cpput/typehelper.h> namespace CppUT { // class ExceptionGuardElement // ////////////////////////////////////////////////////////////////// struct ExceptionGuardElement::Context { Context( Functor0 test ) : test_( test ) { } Functor0 test_; }; void ExceptionGuardElement::setNextInChain( const ExceptionGuardElementPtr &deleguate ) { deleguate_ = deleguate; } bool ExceptionGuardElement::callNextInChain( Context &context ) { if ( deleguate_ ) return deleguate_->protect( context ); context.test_(); return true; } namespace Impl { // class StandardTestExceptionGuard // ////////////////////////////////////////////////////////////////// // catch CppUT::AssertionException, std::exception, ... class CPPUT_API StandardTestExceptionGuard : public ExceptionGuardElement { public: // overridden from ExceptionGuardElement bool protect( Context &context ) { try { return callNextInChain( context ); } catch ( const AbortingAssertionException & ) { // Already injected into result } #ifndef CPPTL_NO_RTTI catch ( const std::exception &e ) { addFault( extractObjectType( e, "std::exception" ), e.what() ); } #else // @todo Need to add catch for all standard derived classes. // Warning: => they don't always exist on all platforms. catch ( const std::runtime_error &e ) { addFault( extractObjectType( e, "std::runtime_error" ), e.what() ); } catch ( const std::exception &e ) { addFault( extractObjectType( e, "std::exception" ), e.what() ); } #endif catch ( ... ) { OpenTest::Properties fault; fault["type"] = "unexpected exception"; fault["message"].append( "caught unexpected exception of unknown type." ); TestInfo::appendFaultToResult( fault ); } return false; } private: void addFault( const std::string &exceptionType, const char *what ) { OpenTest::Properties fault; fault["type"] = "unexpected exception"; fault["exception_type"] = exceptionType; fault["message"].append( "caught unexpected exception." ); fault["message"].append( what ); TestInfo::appendFaultToResult( fault ); } }; } // namespace Impl // class ExceptionGuard // ////////////////////////////////////////////////////////////////// ExceptionGuard::ExceptionGuard() { guards_.push_back( ExceptionGuardElementPtr( new Impl::StandardTestExceptionGuard() ) ); } void ExceptionGuard::append( const ExceptionGuardElementPtr &guard ) { guard->setNextInChain( ExceptionGuardElementPtr() ); guards_.back()->setNextInChain( guard ); guards_.insert( guards_.end()-1, guard ); } void ExceptionGuard::removeLast() { if ( guards_.size() == 1 ) // should we throw an exception ? return; guards_.erase( guards_.end() - 1 ); guards_.back()->setNextInChain( ExceptionGuardElementPtr() ); } bool ExceptionGuard::protect( Functor0 test ) const { ExceptionGuardElement::Context context( test ); return guards_.front()->protect( context ); } } // namespace CppUT |