[Cppunit-cvs] cppunit2/include/cpput assert.h,1.10,1.11 lighttestrunner.h,1.2,1.3 message.h,1.8,1.9
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2005-08-10 03:05:47
|
Update of /cvsroot/cppunit/cppunit2/include/cpput In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31446/include/cpput Modified Files: assert.h lighttestrunner.h message.h testinfo.h Log Message: Rewrote failure reporting during test. It now provides more structure while still providing some flexibility. Index: testinfo.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpput/testinfo.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** testinfo.h 2 Jul 2005 20:27:35 -0000 1.10 --- testinfo.h 8 Aug 2005 22:10:20 -0000 1.11 *************** *** 3,6 **** --- 3,7 ---- # include <cpput/forwards.h> + # include <cpput/message.h> # include <opentest/properties.h> *************** *** 18,21 **** --- 19,125 ---- }; + class SourceLocation + { + public: + SourceLocation( const char *file = 0, + unsigned int line =0, + const char *function = 0 ) + : file_( file ) + , line_( line ) + , function_( function ) + { + } + + void clear() + { + file_ = 0; + function_ = 0; + line_ = 0; + } + + bool isValid() const + { + return file_ != 0; + } + + const char *file_; + const char *function_; + unsigned int line_; + }; + + class CPPUT_API Assertion + { + public: + enum Kind + { + fault = 1, + assertion = 2 + }; + + Assertion( Kind kind = assertion, + const SourceLocation &sourceLocation = SourceLocation() ); + + void setLocation( const SourceLocation &location ); + const SourceLocation &location() const; + + void setKind( Kind kind_ ); + Kind kind() const; + + void setMessages( const Message &messages ); + const Message &messages() const; + + void setTestDataType( const CppTL::ConstString &type ); + const CppTL::ConstString &testDataType() const; + + void setTestData( const CppTL::ConstString &name, + const OpenTest::Value &value, + const CppTL::ConstString &type = "basic" ); + + const OpenTest::Properties &testData() const; + + CppTL::ConstString toString() const; + + private: + Message messages_; + OpenTest::Properties testData_; + CppTL::ConstString testDataType_; + SourceLocation location_; + Kind kind_; + }; + + + + class CPPUT_API TestStatus + { + public: + enum Status + { + passed = 1, + skipped, + failed + }; + + TestStatus( Status status = passed ); + + void setStatus( Status status ); + + Status status() const; + + bool hasFailed() const; + + void setStatistics( const CppTL::ConstString &name, + const OpenTest::Value &value ); + //OpenTest::Value getStatistics( const CppTL::ConstString &name ); + + void addSpecific( const CppTL::ConstString &type, + const OpenTest::Value &value ); + private: + OpenTest::Properties statistics_; + OpenTest::Properties specifics_; + Status status_; + }; + + + class CPPUT_API TestResultUpdater { *************** *** 25,35 **** } ! virtual void mergeInResult( const OpenTest::Properties &result ) = 0; ! virtual void mergeInResult( const OpenTest::PropertyPath &path, ! const OpenTest::Value &value ) = 0; ! virtual void appendToResult( const OpenTest::PropertyPath &path, ! const OpenTest::Value &value ) = 0; }; --- 129,137 ---- } ! virtual void addResultLog( const OpenTest::Value &log ) = 0; ! virtual void addResultAssertion( const Assertion &assertion ) = 0; ! virtual void setTestStatus( const TestStatus &status ) = 0; }; *************** *** 58,69 **** }; - void CPPUT_API setTestResultUpdater( TestResultUpdater &updater ); - void CPPUT_API startNewTest(); ! // Flush test statistics ! void CPPUT_API updateTestStatistics(); ! OpenTest::PropertiesAccessor CPPUT_API result(); void CPPUT_API newAssertion( AssertionType type, --- 160,168 ---- }; ! void CPPUT_API setTestResultUpdater( TestResultUpdater &updater ); ! void CPPUT_API startNewTest(); void CPPUT_API newAssertion( AssertionType type, *************** *** 72,82 **** const char *functionName = 0 ); ! void CPPUT_API setAssertionType( AssertionType type ); ! ! AssertionType CPPUT_API assertionType(); ! OpenTest::Properties &CPPUT_API currentAssertion(); ! OpenTest::Properties &CPPUT_API currentAssertionActual(); ! OpenTest::Properties &CPPUT_API currentAssertionExpected(); /// Realize the current assertion. --- 171,177 ---- const char *functionName = 0 ); ! Assertion &CPPUT_API currentAssertion(); ! void CPPUT_API handleUnexpectedException( const Assertion &fault ); /// Realize the current assertion. *************** *** 86,112 **** void CPPUT_API realizeAssertion(); ! /// Returns the number of assertions done by the test ! unsigned int CPPUT_API assertionCount(); ! ! /// Returns the number of assertions that failed done by the test ! unsigned int CPPUT_API failedAssertionCount(); ! ! /// Returns the number of faults that occurred ! unsigned int CPPUT_API faultCount(); ! ! /// Returns true if an assertion failed or a fault occured. ! bool CPPUT_API testHasFailed(); ! ! void CPPUT_API log( const CppTL::ConstString &text ); ! ! void CPPUT_API appendFaultToResult( const OpenTest::Properties &fault ); ! ! void CPPUT_API mergeInResult( const OpenTest::Properties &result ); ! ! void CPPUT_API mergeInResult( const OpenTest::PropertyPath &path, ! const OpenTest::Value &value ); ! void CPPUT_API appendToResult( const OpenTest::PropertyPath &path, ! const OpenTest::Value &value ); /// Only for using for unit test of the framework itself --- 181,187 ---- void CPPUT_API realizeAssertion(); ! TestStatus &CPPUT_API getUpdatedTestStatus(); ! void CPPUT_API log( const OpenTest::Value &log ); /// Only for using for unit test of the framework itself Index: message.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpput/message.h,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** message.h 5 Mar 2005 12:21:07 -0000 1.8 --- message.h 8 Aug 2005 22:10:20 -0000 1.9 *************** *** 4,7 **** --- 4,8 ---- # include <cpput/config.h> # include <cpptl/conststring.h> + # include <opentest/properties.h> # include <vector> *************** *** 88,92 **** CppTL::ConstString toString() const { ! CppTL::ConstString message; Details::const_iterator it = details_.begin(); Details::const_iterator itEnd = details_.end(); --- 89,93 ---- CppTL::ConstString toString() const { ! CppTL::StringBuffer message; Details::const_iterator it = details_.begin(); Details::const_iterator itEnd = details_.end(); *************** *** 104,135 **** } ! //Properties &properties() ! //{ ! // return properties_; ! //} ! ! //const Properties &properties() const ! //{ ! // return properties_; ! //} ! ! //void setStatus( bool succeeded ) ! //{ ! // properties().set( "cpput.status", succeeded ); ! //} ! ! //void setResultType( const CppTL::ConstString &resultType ) ! //{ ! // properties().set( "cpput.result_type", resultType ); ! //} ! ! //bool hasResultType() const ! //{ ! // return properties().has( "cpput.result_type" ); ! //} private: - //Properties properties_; - typedef std::vector<CppTL::ConstString> Details; Details details_; --- 105,117 ---- } ! OpenTest::Properties asProperties() const ! { ! OpenTest::Properties messages; ! for ( int index =0; index < details_.size(); ++index ) ! messages.append( details_[index] ); ! return messages; ! } private: typedef std::vector<CppTL::ConstString> Details; Details details_; Index: assert.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpput/assert.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** assert.h 6 Mar 2005 18:38:03 -0000 1.10 --- assert.h 8 Aug 2005 22:10:20 -0000 1.11 *************** *** 228,246 **** // properties are captured for later inspection. # define _CPPUT_ASSERT_ASSERTION_FAIL_MESSAGE_IMPL( assertionType, assertion, message ) \ ! { \ ! CPPUT_CHECK_POINT( assertionType ); \ ! OpenTest::Properties result; \ ! bool assertionFailed = false; \ ! { \ ! ::CppUT::TestInfo::ScopedContextOverride contextSwitch; \ ! try { \ ! assertion; \ ! } catch ( const ::CppUT::AbortingAssertionException & ) { \ ! } \ ! assertionFailed = ::CppUT::TestInfo::failedAssertionCount() != 0; \ ! if ( ::CppUT::TestInfo::result().isValid() ) \ ! result = ::CppUT::TestInfo::result().properties(); \ ! } \ ! ::CppUT::checkAssertionFail( assertionFailed, message ); \ } --- 228,243 ---- // properties are captured for later inspection. # define _CPPUT_ASSERT_ASSERTION_FAIL_MESSAGE_IMPL( assertionType, assertion, message ) \ ! { \ ! CPPUT_CHECK_POINT( assertionType ); \ ! bool assertionFailed = false; \ ! { \ ! ::CppUT::TestInfo::ScopedContextOverride contextSwitch; \ ! try { \ ! assertion; \ ! } catch ( const ::CppUT::AbortingAssertionException & ) { \ ! } \ ! assertionFailed = ::CppUT::TestInfo::getUpdatedTestStatus().hasFailed(); \ ! } \ ! ::CppUT::checkAssertionFail( assertionFailed, message ); \ } *************** *** 258,276 **** # define _CPPUT_ASSERT_ASSERTION_PASS_MESSAGE_IMPL( assertionType, assertion, message ) \ ! { \ ! CPPUT_CHECK_POINT( assertionType ); \ ! OpenTest::Properties result; \ ! bool assertionFailed = false; \ ! { \ ! ::CppUT::TestInfo::ScopedContextOverride contextSwitch; \ ! try { \ ! assertion; \ ! } catch ( const ::CppUT::AbortingAssertionException & ) { \ ! } \ ! assertionFailed = ::CppUT::TestInfo::failedAssertionCount() != 0; \ ! if ( ::CppUT::TestInfo::result().isValid() ) \ ! result = ::CppUT::TestInfo::result().properties(); \ ! } \ ! ::CppUT::checkAssertionPass( assertionFailed, message ); \ } --- 255,270 ---- # define _CPPUT_ASSERT_ASSERTION_PASS_MESSAGE_IMPL( assertionType, assertion, message ) \ ! { \ ! CPPUT_CHECK_POINT( assertionType ); \ ! bool assertionFailed = false; \ ! { \ ! ::CppUT::TestInfo::ScopedContextOverride contextSwitch; \ ! try { \ ! assertion; \ ! } catch ( const ::CppUT::AbortingAssertionException & ) { \ ! } \ ! assertionFailed = ::CppUT::TestInfo::getUpdatedTestStatus().hasFailed(); \ ! } \ ! ::CppUT::checkAssertionPass( assertionFailed, message ); \ } Index: lighttestrunner.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpput/lighttestrunner.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** lighttestrunner.h 20 Jul 2005 21:06:49 -0000 1.2 --- lighttestrunner.h 8 Aug 2005 22:10:20 -0000 1.3 *************** *** 24,34 **** private: // overridden from TestResultUpdater ! virtual void mergeInResult( const OpenTest::Properties &result ); ! virtual void mergeInResult( const OpenTest::PropertyPath &path, ! const OpenTest::Value &value ); ! virtual void appendToResult( const OpenTest::PropertyPath &path, ! const OpenTest::Value &value ); private: --- 24,32 ---- private: // overridden from TestResultUpdater ! virtual void addResultLog( const OpenTest::Value &log ); ! virtual void addResultAssertion( const Assertion &assertion ); ! virtual void setTestStatus( const TestStatus &status ); private: *************** *** 37,42 **** void runTestCase( const AbstractTestCasePtr &testCase ); CppTL::ConstString getTestPath() const; ! void reportFailure( const OpenTest::Properties &failure, ! bool isAssertion ); typedef std::deque<TestPtr> Tests; --- 35,39 ---- void runTestCase( const AbstractTestCasePtr &testCase ); CppTL::ConstString getTestPath() const; ! void reportFailure( const Assertion &failure ); typedef std::deque<TestPtr> Tests; *************** *** 45,49 **** TestPath testPath_; CppTL::StringBuffer report_; ! OpenTest::Properties result_; unsigned int testRun_; unsigned int testFailed_; --- 42,47 ---- TestPath testPath_; CppTL::StringBuffer report_; ! typedef std::deque<Assertion> Assertions; ! Assertions assertions_; unsigned int testRun_; unsigned int testFailed_; |