[Cppunit-cvs] cppunit2/src/cpput testcase.cpp,1.6,1.7 testfailureguard.cpp,1.12,1.13
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-02-22 21:15:27
|
Update of /cvsroot/cppunit/cppunit2/src/cpput In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23938/src/cpput Modified Files: testcase.cpp testfailureguard.cpp Log Message: * simplified TestExceptionGuard implementation * renamed TestExceptionGuardChain to ExceptionGuard * added facility to easily register an exception translator. Index: testfailureguard.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/testfailureguard.cpp,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** testfailureguard.cpp 20 Nov 2004 15:26:38 -0000 1.12 --- testfailureguard.cpp 22 Feb 2005 21:14:40 -0000 1.13 *************** *** 5,12 **** namespace CppUT { ! // class TestExceptionGuard // ////////////////////////////////////////////////////////////////// void ! TestExceptionGuard::setNextInChain( const TestExceptionGuardPtr &deleguate ) { deleguate_ = deleguate; --- 5,25 ---- namespace CppUT { ! // class ExceptionGuardElement // ////////////////////////////////////////////////////////////////// + + struct ExceptionGuardElement::Context + { + Context( Functor0 test ) + : test_( test ) + { + } + + Functor0 test_; + }; + + + void ! ExceptionGuardElement::setNextInChain( const ExceptionGuardElementPtr &deleguate ) { deleguate_ = deleguate; *************** *** 15,21 **** bool ! TestExceptionGuard::callNextInChain( Context &context ) { ! return deleguate_->protect( context ); } --- 28,37 ---- bool ! ExceptionGuardElement::callNextInChain( Context &context ) { ! if ( deleguate_ ) ! return deleguate_->protect( context ); ! context.test_(); ! return true; } *************** *** 27,33 **** // catch CppUT::AssertionException, std::exception, ... ! class CPPUT_API StandardTestExceptionGuard : public TestExceptionGuard { ! public: // overridden from TestExceptionGuard bool protect( Context &context ) { --- 43,49 ---- // catch CppUT::AssertionException, std::exception, ... ! class CPPUT_API StandardTestExceptionGuard : public ExceptionGuardElement { ! public: // overridden from ExceptionGuardElement bool protect( Context &context ) { *************** *** 80,155 **** }; - - // class Impl::ExecutorTestExceptionGuard - // ////////////////////////////////////////////////////////////////// - - class ExecutorTestExceptionGuard : public TestExceptionGuard - { - public: // overridden from TestExceptionGuard - bool protect( Context &context ) - { - context.test_(); - return true; - } - }; - } // namespace Impl ! // class TestExceptionGuardChain // ////////////////////////////////////////////////////////////////// ! // Order of the guard in the chain: ! // standard <= always the first to be called ! // user 1 ! // user 2 ! // executor ! ! TestExceptionGuardChain::TestExceptionGuardChain() { ! guards_.push_back( TestExceptionGuardPtr( new Impl::StandardTestExceptionGuard() ) ); ! guards_.push_back( TestExceptionGuardPtr( new Impl::ExecutorTestExceptionGuard() ) ); ! connectChain(); } void ! TestExceptionGuardChain::appendGuard( const TestExceptionGuardPtr &guard ) { guards_.insert( guards_.end()-1, guard ); - connectChain(); } void ! TestExceptionGuardChain::removeLastGuard() { ! if ( guards_.size() <= 2 ) // should we throw an exception ? return; ! guards_.erase( guards_.end() - 2 ); ! connectChain(); } bool ! TestExceptionGuardChain::protect( Functor0 test ) const { ! TestExceptionGuard::Context context( test ); return guards_.front()->protect( context ); } - - void - TestExceptionGuardChain::connectChain() - { - unsigned int length = guards_.size(); - if ( length >= 2 ) - guards_[ length-2 ]->setNextInChain( guards_[ length-1 ] ); - if ( length >= 3 ) - guards_[ length-3 ]->setNextInChain( guards_[ length-2 ] ); - } - - } // namespace CppUT --- 96,138 ---- }; } // 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 Index: testcase.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/testcase.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** testcase.cpp 20 Nov 2004 15:26:38 -0000 1.6 --- testcase.cpp 22 Feb 2005 21:14:39 -0000 1.7 *************** *** 38,47 **** AbstractTestCase::runTest() { ! TestExceptionGuardChain guardsChain; return runTest( guardsChain ); } bool ! AbstractTestCase::runTest( const TestExceptionGuardChain &guardsChain ) { bool initialized = guardsChain.protect( makeMemFn0( this, --- 38,47 ---- AbstractTestCase::runTest() { ! ExceptionGuard guardsChain; return runTest( guardsChain ); } bool ! AbstractTestCase::runTest( const ExceptionGuard &guardsChain ) { bool initialized = guardsChain.protect( makeMemFn0( this, |