|
Packit Service |
e31359 |
#ifndef CPPUNIT_PROTECTOR_H
|
|
Packit Service |
e31359 |
#define CPPUNIT_PROTECTOR_H
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
#include <cppunit/SourceLine.h>
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
CPPUNIT_NS_BEGIN
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
class Exception;
|
|
Packit Service |
e31359 |
class Message;
|
|
Packit Service |
e31359 |
class ProtectorContext;
|
|
Packit Service |
e31359 |
class TestResult;
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
class CPPUNIT_API Functor
|
|
Packit Service |
e31359 |
{
|
|
Packit Service |
e31359 |
public:
|
|
Packit Service |
e31359 |
virtual ~Functor();
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
virtual bool operator()() const =0;
|
|
Packit Service |
e31359 |
};
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
/*! \brief Protects one or more test case run.
|
|
Packit Service |
e31359 |
*
|
|
Packit Service |
e31359 |
* Protector are used to globably 'decorate' a test case. The most common
|
|
Packit Service |
e31359 |
* usage of Protector is to catch exception that do not subclass std::exception,
|
|
Packit Service |
e31359 |
* such as MFC CException class or Rogue Wave RWXMsg class, and capture the
|
|
Packit Service |
e31359 |
* message associated to the exception. In fact, CppUnit capture message from
|
|
Packit Service |
e31359 |
* Exception and std::exception using a Protector.
|
|
Packit Service |
e31359 |
*
|
|
Packit Service |
e31359 |
* Protector are chained. When you add a Protector using
|
|
Packit Service |
e31359 |
* TestResult::pushProtector(), your protector is in fact passed as a Functor
|
|
Packit Service |
e31359 |
* to the first protector of the chain.
|
|
Packit Service |
e31359 |
*
|
|
Packit Service |
e31359 |
* TestCase protects call to setUp(), runTest() and tearDown() by calling
|
|
Packit Service |
e31359 |
* TestResult::protect().
|
|
Packit Service |
e31359 |
*
|
|
Packit Service |
e31359 |
* Because the protector chain is handled by TestResult, a protector can be
|
|
Packit Service |
e31359 |
* active for a single test, or a complete test run.
|
|
Packit Service |
e31359 |
*
|
|
Packit Service |
e31359 |
* Here are some possible usages:
|
|
Packit Service |
e31359 |
* - run all test case in a separate thread and assumes the test failed if it
|
|
Packit Service |
e31359 |
* did not finish in a given time (infinite loop work around)
|
|
Packit Service |
e31359 |
* - performance tracing : time only the runTest() time.
|
|
Packit Service |
e31359 |
* \sa TestResult, TestCase, TestListener.
|
|
Packit Service |
e31359 |
*/
|
|
Packit Service |
e31359 |
class CPPUNIT_API Protector
|
|
Packit Service |
e31359 |
{
|
|
Packit Service |
e31359 |
public:
|
|
Packit Service |
e31359 |
virtual ~Protector();
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
virtual bool protect( const Functor &functor,
|
|
Packit Service |
e31359 |
const ProtectorContext &context ) =0;
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
protected:
|
|
Packit Service |
e31359 |
void reportError( const ProtectorContext &context,
|
|
Packit Service |
e31359 |
const Exception &error ) const;
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
void reportError( const ProtectorContext &context,
|
|
Packit Service |
e31359 |
const Message &message,
|
|
Packit Service |
e31359 |
const SourceLine &sourceLine = SourceLine() ) const;
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
void reportFailure( const ProtectorContext &context,
|
|
Packit Service |
e31359 |
const Exception &failure ) const;
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
Message actualMessage( const Message &message,
|
|
Packit Service |
e31359 |
const ProtectorContext &context ) const;
|
|
Packit Service |
e31359 |
};
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
/*! \brief Scoped protector push to TestResult.
|
|
Packit Service |
e31359 |
*
|
|
Packit Service |
e31359 |
* Adds the specified Protector to the specified TestResult for the object
|
|
Packit Service |
e31359 |
* life-time.
|
|
Packit Service |
e31359 |
*/
|
|
Packit Service |
e31359 |
class CPPUNIT_API ProtectorGuard
|
|
Packit Service |
e31359 |
{
|
|
Packit Service |
e31359 |
public:
|
|
Packit Service |
e31359 |
/// Pushes the specified protector.
|
|
Packit Service |
e31359 |
ProtectorGuard( TestResult *result,
|
|
Packit Service |
e31359 |
Protector *protector );
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
/// Pops the protector.
|
|
Packit Service |
e31359 |
~ProtectorGuard();
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
private:
|
|
Packit Service |
e31359 |
ProtectorGuard( const ProtectorGuard& ); /* not copyable */
|
|
Packit Service |
e31359 |
ProtectorGuard& operator=( const ProtectorGuard& ); /* not assignable */
|
|
Packit Service |
e31359 |
TestResult *m_result;
|
|
Packit Service |
e31359 |
};
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
CPPUNIT_NS_END
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
|
|
Packit Service |
e31359 |
#endif // CPPUNIT_PROTECTOR_H
|
|
Packit Service |
e31359 |
|