diff options
| author | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-08-03 14:50:09 +0000 |
|---|---|---|
| committer | Baptiste Lepilleur <gaiacrtn@free.fr> | 2002-08-03 14:50:09 +0000 |
| commit | e82ccd481800f8f0d36af5310c535b83a6cec788 (patch) | |
| tree | 2b312dbac05563f3ed7baf63ddbd1fcdcbefc686 /include/cppunit/Protector.h | |
| parent | 2a31073734be6e44e477079699578820282b7345 (diff) | |
| download | cppunit-e82ccd481800f8f0d36af5310c535b83a6cec788.tar.gz | |
Include/cppunit/Exception.
include/cppunit/Exception.h:
* src/cppunit/Exception.h: added setMessage().
* include/cppunit/Protector.h:
* src/cppunit/Protector.cpp: added class ProtectorGuard. Change the
reportXXX() method to support Exception passing and SourceLine.
* include/cppunit/TestCaller.h: removed 'expect exception' features.
It is now handled by ExceptionTestCaseDecorator and TestCaller no
longer need default template argument support.
* include/cppunit/TestCase.h:
* include/cppunit/extensions/TestCaller.h: runTest() is now public
instead of protected, so that it can be decorated.
* include/cppunit/TestResult.h:
* src/cppunit/TestResult.h: added pushProtector() and popProtector()
methods. This allow user to specify their own exception trap when
running test case.
* include/cppunit/extensions/TestDecorator.h:
* src/cppunit/TestDecorator.cpp: added. Extracted from TestDecorator.h.
The test passed to the constructor is now owned by the decorator.
* include/cppunit/extensions/TestCaseDecorator.h:
* src/cppunit/TestCaseDecorator.cpp: added. Decorator for TestCase
setUp(), tearDown() and runTest().
* include/cppunit/extensions/ExceptionTestCaseDecorator.h: added.
TestCaseDecorator to expect that a specific exception is thrown.
* include/cppunit/extensions/HelperMacros.h: updated against TestCaller
change.
* src/cppunit/DefaultFunctor.h: fixed bug (did not return underlying
test return code).
* src/cppunit/ProtectorChain.cpp: fixed bug in chaing return code.
* src/cppunit/DefaultFunctor.h: fixed bug.
* src/msvc6/testrunner/ActiveTest.h:
* src/msvc6/testrunner/ActiveTest.cpp: updated against
TestCaseDecorator ownership policy change. Moved inline functions
to .cpp.
* examples/cppunittest/TestSetUpTest.cpp: updated to use MockTestCase
and against the new ownership policy.
* examples/cppunittest/TestDecoratorTest.cpp:
* examples/cppunittest/RepeatedTestTest.cpp: updated against
TestDecorator ownership policy change.
* examples/cppunittest/ExceptionTestCaseDecoratorTest.h:
* examples/cppunittest/ExceptionTestCaseDecoratorTest.cpp: added. Unit
tests for ExceptionTestCaseDecoratorTest.
Diffstat (limited to 'include/cppunit/Protector.h')
| -rw-r--r-- | include/cppunit/Protector.h | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/include/cppunit/Protector.h b/include/cppunit/Protector.h index f6073a2..f854878 100644 --- a/include/cppunit/Protector.h +++ b/include/cppunit/Protector.h @@ -1,13 +1,14 @@ #ifndef CPPUNIT_PROTECTOR_H #define CPPUNIT_PROTECTOR_H -#include <cppunit/Portability.h> +#include <cppunit/SourceLine.h> CPPUNIT_NS_BEGIN - +class Exception; class Message; class ProtectorContext; +class TestResult; class CPPUNIT_API Functor @@ -19,6 +20,30 @@ public: }; +/*! \brief Protects one or more test case run. + * + * Protector are used to globably 'decorate' a test case. The most common + * usage of Protector is to catch exception that do not subclass std::exception, + * such as MFC CException class or Rogue Wave RWXMsg class, and capture the + * message associated to the exception. In fact, CppUnit capture message from + * Exception and std::exception using a Protector. + * + * Protector are chained. When you add a Protector using + * TestResult::pushProtector(), your protector is in fact passed as a Functor + * to the first protector of the chain. + * + * TestCase protects call to setUp(), runTest() and tearDown() by calling + * TestResult::protect(). + * + * Because the protector chain is handled by TestResult, a protector can be + * active for a single test, or a complete test run. + * + * Here are some possible usages: + * - run all test case in a separate thread and assumes the test failed if it + * did not finish in a given time (infinite loop work around) + * - performance tracing : time only the runTest() time. + * \sa TestResult, TestCase, TestListener. + */ class CPPUNIT_API Protector { public: @@ -28,9 +53,30 @@ public: const ProtectorContext &context ) =0; protected: - void reportTestFailure( const Message &message, - const ProtectorContext &context, - bool isError ); + void reportError( const ProtectorContext &context, + const Exception &error ) const; + + void reportError( const ProtectorContext &context, + const Message &message, + const SourceLine &sourceLine = SourceLine() ) const; + + void reportFailure( const ProtectorContext &context, + const Exception &failure ) const; + + Message actualMessage( const Message &message, + const ProtectorContext &context ) const; +}; + + +class CPPUNIT_API ProtectorGuard +{ +public: + ProtectorGuard( TestResult *result, + Protector *protector ); + ~ProtectorGuard(); + +private: + TestResult *m_result; }; CPPUNIT_NS_END |
