CppUnit project page FAQ

Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
TestResult Class Reference

Manages TestListener. More...

#include <TestResult.h>

Inheritance diagram for TestResult:
Inheritance graph
[legend]
Collaboration diagram for TestResult:
Collaboration graph
[legend]

Public Member Functions

 TestResult (SynchronizationObject *syncObject=0)
 Construct a TestResult. More...
 
virtual ~TestResult ()
 Destroys a test result. More...
 
virtual void addListener (TestListener *listener)
 
virtual void removeListener (TestListener *listener)
 
virtual void reset ()
 Resets the stop flag. More...
 
virtual void stop ()
 Stop testing. More...
 
virtual bool shouldStop () const
 Returns whether testing should be stopped. More...
 
virtual void startTest (Test *test)
 Informs TestListener that a test will be started. More...
 
virtual void addError (Test *test, Exception *e)
 Adds an error to the list of errors. The passed in exception caused the error. More...
 
virtual void addFailure (Test *test, Exception *e)
 Adds a failure to the list of failures. The passed in exception caused the failure. More...
 
virtual void endTest (Test *test)
 Informs TestListener that a test was completed. More...
 
virtual void startSuite (Test *test)
 Informs TestListener that a test suite will be started. More...
 
virtual void endSuite (Test *test)
 Informs TestListener that a test suite was completed. More...
 
virtual void runTest (Test *test)
 Run the specified test. More...
 
virtual bool protect (const Functor &functor, Test *test, const std::string &shortDescription=std::string(""))
 Protects a call to the specified functor. More...
 
virtual void pushProtector (Protector *protector)
 Adds the specified protector to the protector chain. More...
 
virtual void popProtector ()
 Removes the last protector from the protector chain. More...
 

Protected Types

typedef std::deque< TestListener * > TestListeners
 

Protected Member Functions

void addFailure (const TestFailure &failure)
 Called to add a failure to the list of failures. More...
 
virtual void startTestRun (Test *test)
 
virtual void endTestRun (Test *test)
 
- Protected Member Functions inherited from SynchronizedObject
virtual void setSynchronizationObject (SynchronizationObject *syncObject)
 Accept a new synchronization object for protection of this instance TestResult assumes ownership of the object. More...
 
 SynchronizedObject (SynchronizationObject *syncObject=0)
 
virtual ~SynchronizedObject ()
 Destructor. More...
 

Protected Attributes

TestListeners m_listeners
 
ProtectorChainm_protectorChain
 
bool m_stop
 
- Protected Attributes inherited from SynchronizedObject
SynchronizationObjectm_syncObject
 

Private Member Functions

 TestResult (const TestResult &other)
 
TestResultoperator= (const TestResult &other)
 

Detailed Description

Manages TestListener.

A single instance of this class is used when running the test. It is usually created by the test runner (TestRunner).

This class shouldn't have to be inherited from. Use a TestListener or one of its subclasses to be informed of the ongoing tests. Use a Outputter to receive a test summary once it has finished

TestResult supplies a template method 'setSynchronizationObject()' so that subclasses can provide mutual exclusion in the face of multiple threads. This can be useful when tests execute in one thread and they fill a subclass of TestResult which effects change in another thread. To have mutual exclusion, override setSynchronizationObject() and make sure that you create an instance of ExclusiveZone at the beginning of each method.

See also
Test, TestListener, TestResultCollector, Outputter.

Member Typedef Documentation

◆ TestListeners

typedef std::deque<TestListener *> TestResult::TestListeners
protected

Constructor & Destructor Documentation

◆ TestResult() [1/2]

CPPUNIT_NS_BEGIN TestResult::TestResult ( SynchronizationObject syncObject = 0)

Construct a TestResult.

◆ ~TestResult()

TestResult::~TestResult ( )
virtual

Destroys a test result.

◆ TestResult() [2/2]

TestResult::TestResult ( const TestResult other)
private

Member Function Documentation

◆ addError()

void TestResult::addError ( Test test,
Exception e 
)
virtual

Adds an error to the list of errors. The passed in exception caused the error.

◆ addFailure() [1/2]

void TestResult::addFailure ( const TestFailure failure)
protected

Called to add a failure to the list of failures.

◆ addFailure() [2/2]

void TestResult::addFailure ( Test test,
Exception e 
)
virtual

Adds a failure to the list of failures. The passed in exception caused the failure.

◆ addListener()

void TestResult::addListener ( TestListener listener)
virtual

◆ endSuite()

void TestResult::endSuite ( Test test)
virtual

Informs TestListener that a test suite was completed.

◆ endTest()

void TestResult::endTest ( Test test)
virtual

Informs TestListener that a test was completed.

◆ endTestRun()

void TestResult::endTestRun ( Test test)
protectedvirtual

◆ operator=()

TestResult& TestResult::operator= ( const TestResult other)
private

◆ popProtector()

void TestResult::popProtector ( )
virtual

Removes the last protector from the protector chain.

◆ protect()

bool TestResult::protect ( const Functor functor,
Test test,
const std::string &  shortDescription = std::string("") 
)
virtual

Protects a call to the specified functor.

See Protector to understand how protector works. A default protector is always present. It captures CppUnit::Exception, std::exception and any other exceptions, retrieving as much as possible information about the exception as possible.

Additional Protector can be added to the chain to support other exception types using pushProtector() and popProtector().

Parameters
functorFunctor to call (typically a call to setUp(), runTest() or tearDown().
testTest the functor is associated to (used for failure reporting).
shortDescriptionShort description override for the failure message.

◆ pushProtector()

void TestResult::pushProtector ( Protector protector)
virtual

Adds the specified protector to the protector chain.

◆ removeListener()

void TestResult::removeListener ( TestListener listener)
virtual

◆ reset()

void TestResult::reset ( )
virtual

Resets the stop flag.

◆ runTest()

void TestResult::runTest ( Test test)
virtual

Run the specified test.

Calls startTestRun(), test->run(this), and finally endTestRun().

◆ shouldStop()

bool TestResult::shouldStop ( ) const
virtual

Returns whether testing should be stopped.

◆ startSuite()

void TestResult::startSuite ( Test test)
virtual

Informs TestListener that a test suite will be started.

◆ startTest()

void TestResult::startTest ( Test test)
virtual

Informs TestListener that a test will be started.

Reimplemented in TextTestResult.

◆ startTestRun()

void TestResult::startTestRun ( Test test)
protectedvirtual

◆ stop()

void TestResult::stop ( )
virtual

Stop testing.

Member Data Documentation

◆ m_listeners

TestListeners TestResult::m_listeners
protected

◆ m_protectorChain

ProtectorChain* TestResult::m_protectorChain
protected

◆ m_stop

bool TestResult::m_stop
protected

The documentation for this class was generated from the following files:

Send comments to:
CppUnit Developers