1
#ifndef CPPUNIT_PROTECTOR_H
2
#define CPPUNIT_PROTECTOR_H
4
#include <cppunit/SourceLine.h>
10
class ProtectorContext;
14
class CPPUNIT_API Functor
19
virtual bool operator()() const =0;
23
/*! \brief Protects one or more test case run.
25
* Protector are used to globably 'decorate' a test case. The most common
26
* usage of Protector is to catch exception that do not subclass std::exception,
27
* such as MFC CException class or Rogue Wave RWXMsg class, and capture the
28
* message associated to the exception. In fact, CppUnit capture message from
29
* Exception and std::exception using a Protector.
31
* Protector are chained. When you add a Protector using
32
* TestResult::pushProtector(), your protector is in fact passed as a Functor
33
* to the first protector of the chain.
35
* TestCase protects call to setUp(), runTest() and tearDown() by calling
36
* TestResult::protect().
38
* Because the protector chain is handled by TestResult, a protector can be
39
* active for a single test, or a complete test run.
41
* Here are some possible usages:
42
* - run all test case in a separate thread and assumes the test failed if it
43
* did not finish in a given time (infinite loop work around)
44
* - performance tracing : time only the runTest() time.
45
* \sa TestResult, TestCase, TestListener.
47
class CPPUNIT_API Protector
52
virtual bool protect( const Functor &functor,
53
const ProtectorContext &context ) =0;
56
void reportError( const ProtectorContext &context,
57
const Exception &error ) const;
59
void reportError( const ProtectorContext &context,
60
const Message &message,
61
const SourceLine &sourceLine = SourceLine() ) const;
63
void reportFailure( const ProtectorContext &context,
64
const Exception &failure ) const;
66
Message actualMessage( const Message &message,
67
const ProtectorContext &context ) const;
71
/*! \brief Scoped protector push to TestResult.
73
* Adds the specified Protector to the specified TestResult for the object
76
class CPPUNIT_API ProtectorGuard
79
/// Pushes the specified protector.
80
ProtectorGuard( TestResult *result,
81
Protector *protector );
83
/// Pops the protector.
93
#endif // CPPUNIT_PROTECTOR_H