[Cppunit-cvs] cppunit2/include/cpput assert.h,1.4,1.5 testinfo.h,1.3,1.4
Brought to you by:
blep
From: Baptiste L. <bl...@us...> - 2004-11-20 12:18:02
|
Update of /cvsroot/cppunit/cppunit2/include/cpput In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16247/include/cpput Modified Files: assert.h testinfo.h Log Message: * moved the assertion implementation to using TestInfo. * added assertion (tested/failed) counter to TestInfo. Index: testinfo.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpput/testinfo.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** testinfo.h 19 Nov 2004 23:05:20 -0000 1.3 --- testinfo.h 20 Nov 2004 12:17:50 -0000 1.4 *************** *** 45,48 **** --- 45,59 ---- namespace TestInfo { + class CPPUT_API ScopedContextOverride + { + public: + ScopedContextOverride(); + + ~ScopedContextOverride(); + + private: + TestInfoDataPtr context_; + }; + void CPPUT_API setTestResultUpdater( const TestResultUpdaterPtr &updater ); *************** *** 69,72 **** --- 80,89 ---- 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(); + void CPPUT_API mergeInResult( const OpenTest::Properties &result ); Index: assert.h =================================================================== RCS file: /cvsroot/cppunit/cppunit2/include/cpput/assert.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** assert.h 4 Aug 2004 08:42:22 -0000 1.4 --- assert.h 20 Nov 2004 12:17:50 -0000 1.5 *************** *** 7,10 **** --- 7,11 ---- # include <cpput/message.h> # include <cpput/stringize.h> + # include <cpput/testinfo.h> # include <cpput/translate.h> # include <cpput/typehelper.h> *************** *** 12,23 **** namespace CppUT { ! void CPPUT_API setCheckPointLocation( const Location &location ); ! Location CPPUT_API getCheckPointLocation(); void CPPUT_API fail( const Message &message = translate( "Assertion failed." ) ); - void CPPUT_API succeed( const Message &message ); - void CPPUT_API checkTrue( bool shouldBeTrue, const Message &message = Message() ); --- 13,28 ---- namespace CppUT { ! class CPPUT_API ExpressionWrapper ! { ! public: ! virtual ~ExpressionWrapper() ! { ! } ! virtual void run() const = 0; ! }; void CPPUT_API fail( const Message &message = translate( "Assertion failed." ) ); void CPPUT_API checkTrue( bool shouldBeTrue, const Message &message = Message() ); *************** *** 26,29 **** --- 31,40 ---- const Message &message = Message() ); + void CPPUT_API checkAssertionFail( bool assertionFailed, + const Message &message = Message() ); + + void CPPUT_API checkAssertionPass( bool assertionFailed, + const Message &message = Message() ); + Message CPPUT_API buildEqualityFailedMessage( const std::string &expected, const std::string &actual, *************** *** 113,118 **** ! # define CPPUT_CHECK_POINT() \ ! ::CppUT::setCheckPointLocation( CPPUT_MAKE_CURRENT_LOCATION() ) # define CPPUT_BEGIN_ASSERTION_MACRO() \ --- 124,130 ---- ! # define CPPUT_CHECK_POINT() \ ! ::CppUT::TestInfo::newAssertion(), \ ! ::CppUT::TestInfo::setAssertionLocation( __FILE__, __LINE__ ) # define CPPUT_BEGIN_ASSERTION_MACRO() \ *************** *** 125,132 **** ::CppUT::fail - # define CPPUT_SUCCEED \ - CPPUT_BEGIN_ASSERTION_MACRO() \ - ::CppUT::succeed - # define CPPUT_ASSERT \ CPPUT_BEGIN_ASSERTION_MACRO() \ --- 137,140 ---- *************** *** 181,189 **** } # define CPPUT_ASSERT_ASSERTION_FAIL( assertion ) \ ! CPPUT_ASSERT_THROW( assertion, ::CppUT::AssertException ) # define CPPUT_ASSERT_ASSERTION_PASS( assertion ) \ ! CPPUT_ASSERT_NO_THROW( assertion ) --- 189,251 ---- } + # define CPPUT_EXPRESSION_WRAPPER( expression, variable ) \ + class Wrapper : public ::CppUT::ExpressionWrapper \ + { \ + public: /* overridden from ExpressionWrapper */ \ + void run() const \ + { \ + expression; \ + } \ + } variable + + // Notes: implementing that assertion checking is a bit tricky since all the state + // about the current test/assertions is stored in a "static" and + // we don't want the tested assertion to polute the test result + // of the current test. + // TestInfo::ScopedContextOverride is used to create a temporary + // context for the tested assertion. After the assertion, the + // result of the assertion (did it failed), and the test result + // properties are captured for later introspection. + # define CPPUT_ASSERT_ASSERTION_FAIL_MESSAGE( assertion, message ) \ + { \ + CPPUT_CHECK_POINT(); \ + 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 ); \ + } + # define CPPUT_ASSERT_ASSERTION_FAIL( assertion ) \ ! CPPUT_ASSERT_ASSERTION_FAIL_MESSAGE( assertion, ::CppUT::Message() ) ! ! # define CPPUT_ASSERT_ASSERTION_PASS_MESSAGE( assertion, message ) \ ! { \ ! CPPUT_CHECK_POINT(); \ ! 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 ); \ ! } # define CPPUT_ASSERT_ASSERTION_PASS( assertion ) \ ! CPPUT_ASSERT_ASSERTION_PASS_MESSAGE( assertion, ::CppUT::Message() ) |