[Cppunit-cvs] cppunit2/src/cpput assert.cpp,1.4,1.5 cpput.vcproj,1.21,1.22 testinfo.cpp,1.3,1.4 test
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2004-11-20 12:18:02
|
Update of /cvsroot/cppunit/cppunit2/src/cpput In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16247/src/cpput Modified Files: assert.cpp cpput.vcproj testinfo.cpp testrunner.cpp Log Message: * moved the assertion implementation to using TestInfo. * added assertion (tested/failed) counter to TestInfo. Index: assert.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/assert.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** assert.cpp 4 Aug 2004 08:42:27 -0000 1.4 --- assert.cpp 20 Nov 2004 12:17:51 -0000 1.5 *************** *** 12,39 **** { - static ThreadLocalStorage<Location> checkPointLocation; - - - void setCheckPointLocation( const Location &location ) - { - checkPointLocation.set( location ); - } - - Location getCheckPointLocation() - { - return checkPointLocation.get(); - } - void fail( const Message &message ) { ! throw AssertException( message, getCheckPointLocation() ); ! } ! ! void ! succeed( const Message &message ) ! { ! throw SuccessException( message, getCheckPointLocation() ); } --- 12,22 ---- { void fail( const Message &message ) { ! for ( int index =0; index < message.count(); ++index ) ! TestInfo::currentAssertion()["message"].append( message.at(index) ); ! TestInfo::realizeAssertion(); } *************** *** 65,68 **** --- 48,77 ---- + void + checkAssertionFail( bool assertionFailed, + const Message &message ) + { + if ( assertionFailed ) + return; + + Message newMessage( translate( "Assertion expression did not fail as expected." ) ); + newMessage.add( message ); + fail( message ); + } + + + void + checkAssertionPass( bool assertionFailed, + const Message &message ) + { + if ( !assertionFailed ) + return; + + Message newMessage( translate( "Assertion expression did not pass as expected." ) ); + newMessage.add( message ); + fail( message ); + } + + Message buildEqualityFailedMessage( const std::string &expected, Index: testrunner.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/testrunner.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** testrunner.cpp 19 Nov 2004 21:39:14 -0000 1.3 --- testrunner.cpp 20 Nov 2004 12:17:51 -0000 1.4 *************** *** 3,6 **** --- 3,7 ---- #include <cpput/testcase.h> #include <cpput/testcontext.h> + #include <cpput/testinfo.h> #include <cpput/testlistener.h> #include <cpput/testresult.h> *************** *** 151,154 **** --- 152,156 ---- listener.setTestPlanEntry( entry ); tracker.startTest( entry ); + TestInfo::startNewTest(); if ( itTest == tests_.end() ) // protocol error => unknown test { Index: cpput.vcproj =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/cpput.vcproj,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** cpput.vcproj 19 Nov 2004 19:31:38 -0000 1.21 --- cpput.vcproj 20 Nov 2004 12:17:51 -0000 1.22 *************** *** 129,136 **** Filter=""> <File ! RelativePath=".\SConscript"> </File> <File ! RelativePath="..\cpputtest\SConscript"> </File> <File --- 129,136 ---- Filter=""> <File ! RelativePath="..\cpputtest\SConscript"> </File> <File ! RelativePath=".\SConscript"> </File> <File *************** *** 204,207 **** --- 204,210 ---- </File> <File + RelativePath="..\..\include\cpptl\stringtools.h"> + </File> + <File RelativePath="..\..\include\cpptl\typetraits.h"> </File> Index: testinfo.cpp =================================================================== RCS file: /cvsroot/cppunit/cppunit2/src/cpput/testinfo.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** testinfo.cpp 19 Nov 2004 23:05:21 -0000 1.3 --- testinfo.cpp 20 Nov 2004 12:17:51 -0000 1.4 *************** *** 14,17 **** --- 14,24 ---- } + void clear() + { + file_ = 0; + function_ = 0; + line_ = 0; + } + const char *file_; const char *function_; *************** *** 22,25 **** --- 29,39 ---- namespace CppUT { + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // Class TestInfoData + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + + class TestInfoData { *************** *** 27,33 **** --- 41,90 ---- TestInfoData() : assertionType_( abortingAssertion ) + , assertionCount_( 0 ) + , failedAssertionCount_( 0 ) { } + void startNewTest() + { + result_.clear(); + assertion_.clear(); + assertionCount_ = 0; + failedAssertionCount_ = 0; + assertionType_ = abortingAssertion; + assertionLocation_.clear(); + } + + void newAssertion() + { + assertionType_ = abortingAssertion; + assertionLocation_.clear(); + assertion_.clear(); + ++assertionCount_; + } + + void realizeAssertion() + { + ++failedAssertionCount_; + + OpenTest::Properties assertion = assertion_; + if ( assertionLocation_.file_ ) + { + assertion["location"]["file"] = assertionLocation_.file_; + assertion["location"]["line"] = assertionLocation_.line_; + } + if ( assertionLocation_.function_ ) + assertion["location"]["function"] = assertionLocation_.function_; + TestInfo::appendToResult( "assertions", assertion ); // @todo Move appendToResult here + + if ( assertionType_ == abortingAssertion ) + { + std::string message; + if ( abortingAssertionMode_ != fastAbortingAssertion ) + message = result_.toString(); + throw AbortingAssertionException( message ); + } + } + TestResultUpdaterPtr updater_; OpenTest::Properties result_; *************** *** 36,41 **** --- 93,106 ---- CompactLocation assertionLocation_; AbortingAssertionMode abortingAssertionMode_; + unsigned int assertionCount_; + unsigned int failedAssertionCount_; + }; + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // Namespace TestInfo + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// namespace TestInfo { *************** *** 71,75 **** void startNewTest() { ! data().result_.clear(); } --- 136,140 ---- void startNewTest() { ! data().startNewTest(); } *************** *** 81,87 **** void newAssertion() { ! data().assertion_.clear(); ! data().assertionType_ = abortingAssertion; ! data().assertionLocation_ = CompactLocation(); } --- 146,150 ---- void newAssertion() { ! data().newAssertion(); } *************** *** 108,134 **** } - /// Realize the current assertion. - /// Add data about the current assertion to the test result. - /// @exception AbortingAssertionException If assertionType was set to - /// abortingAssertion. void realizeAssertion() { ! OpenTest::Properties assertion = data().assertion_; ! if ( data().assertionLocation_.file_ ) ! { ! assertion["location"]["file"] = data().assertionLocation_.file_; ! assertion["location"]["line"] = data().assertionLocation_.line_; ! } ! if ( data().assertionLocation_.function_ ) ! assertion["location"]["function"] = data().assertionLocation_.function_; ! appendToResult( "assertions", assertion ); ! if ( data().assertionType_ == abortingAssertion ) ! { ! std::string message; ! if ( data().abortingAssertionMode_ != fastAbortingAssertion ) ! message = data().result_.toString(); ! throw AbortingAssertionException( message ); ! } } --- 171,187 ---- } void realizeAssertion() { ! data().realizeAssertion(); ! } ! unsigned int CPPUT_API assertionCount() ! { ! return data().assertionCount_; ! } ! ! unsigned int CPPUT_API failedAssertionCount() ! { ! return data().failedAssertionCount_; } *************** *** 175,178 **** --- 228,248 ---- + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + // Class ScopedContextOverride + // ////////////////////////////////////////////////////////////////// + // ////////////////////////////////////////////////////////////////// + + ScopedContextOverride::ScopedContextOverride() + : context_( saveAndResetContext() ) + { + } + + ScopedContextOverride::~ScopedContextOverride() + { + restoreContext( context_ ); + } + + } // namespace TestInfo |