SynchronizedObject::ExclusiveZone

   
SynchronizedObject::ExclusiveZone

Description

The class ExclusiveZone (see Figure C-14) is a nested class belonging to SynchronizedObject . It locks a SynchronizationObject (mutex) upon construction and unlocks it upon destruction, thus providing protection during the scope of its existence.

ExclusiveZone belongs to the namespace CppUnit . It is declared and implemented in SynchronizedObject.h .

Figure C-14. The nested class SynchronizedObject::ExclusiveZone
figs/utf_ac14.gif

Declaration

 class ExclusiveZone 

Constructors/Destructors


ExclusiveZone(SynchronizationObject *syncObject)

Constructs ExclusiveZone and locks syncObject .


~ExclusiveZone( )

Destroys ExclusiveZone and unlocks syncObject .

Public Methods

None.

Protected/Private Methods

None.

Attributes


SynchronizationObject *m_syncObject

A pointer to the SynchronizationObject for this ExclusiveZone ( public ).

   
SynchronizedObject::SynchronizationObject

Description

The class SynchronizationObject (see Figure C-15) is a nested class belonging to SynchronizedObject . It acts as the mutex for a SynchronizedObject and so can be locked or unlocked.

SynchronizationObject belongs to the namespace CppUnit . It is declared and implemented in SynchronizedObject.h.

Figure C-15. The nested class SynchronizationObject
figs/utf_ac15.gif

Declaration

 class SynchronizationObject 

Constructors/Destructors


SynchronizationObject( )

A constructor.


~SynchronizationObject( )

A destructor.

Public Methods


virtual void lock( )

Locks the SynchronizationObject .


virtual void unlock( )

Unlocks the SynchronizationObject .

Protected/Private Methods

None.

Attributes

None.

   
Test

Description

The abstract class Test (see Figure C-16) is the central design element of CppUnit, as in other versions of xUnit. It is the base class for all test objects. A Test may consist of a single unit test or of a collection of Test s. When a Test is run, a TestResult collects its results.

All of Test 's methods are virtual and should be overridden by descendant classes.

Test belongs to the namespace CppUnit . It is declared in Test.h and implemented in Test.cpp .

Figure C-16. The abstract class Test
figs/utf_ac16.gif

Declaration

 class Test 

Constructors/Destructors


virtual ~Test( )

A destructor.

Public Methods


virtual int countTestCases( ) const = 0

Returns the number of test cases to be run by this Test .


virtual string getName( ) const = 0

Returns the name of this Test .


virtual void run(TestResult *result) = 0

Runs Test and collects the results in result .


virtual string toString( ) const = 0

Returns a short description of this Test , generally incorporating the name and Test type.

Protected/Private Methods

None.

Attributes

None.

   
TestCaller

Description

The template class TestCaller (see Figure C-17) is used to create and run a TestCase containing a TestMethod , usually in the context of a TestFixture . This is useful when a TestFixture has multiple test methods but only one of them should be run, or when test methods are being run by name . A TestMethod must take no arguments and return void to be invoked using TestCaller .

When TestCaller is specialized and instantiated , the type Fixture should be TestFixture or a subclass of it. The type ExpectedException defaults to NoExceptionExpected , meaning that an Exception is not expected when the TestMethod is run, and the test fails if one is thrown. An Exception type can be provided when TestCaller is specialized, so that it is expected when the TestCase is run. In this case, the test fails if the ExpectedException is not thrown.

TestCaller belongs to the namespace CppUnit . It is declared and implemented in TestCaller.h .

Figure C-17. The template class TestCaller
figs/utf_ac17.gif

Declaration

 template<typename Fixture, typename ExpectedException = 

NoExceptionExpected>   class TestCaller : public TestCase 

Constructors/Destructors


TestCaller(string name, TestMethod test)

A constructor used when a TestFixture is not provided. In this case, the TestMethod is run in a new, default TestFixture owned by the TestCaller .


TestCaller(string name, TestMethod test, Fixture& fixture)

A constructor taking a TestMethod and a reference to a TestFixture . The TestCaller does not own the TestFixture in this case.


TestCaller(string name, TestMethod test, Fixture *fixture)

A constructor taking a TestMethod and a pointer to a TestFixture . When a TestCaller is constructed this way, it owns the TestFixture .


~TestCaller( )

A destructor. If the TestCaller owns the TestFixture , it deletes it.

Public Methods

None.

Protected/Private Methods


void runTest( )

A Protected method that runs the TestMethod .


void setUp( )

A Protected method that sets up the Fixture by calling its setUp( ) method.


void tearDown( )

A Protected method that tears down the Fixture by calling its tearDown( ) method.


string toString( ) const

A Protected method returning a string representation of this TestCaller .


TestCaller(const TestCaller &other)

A copy constructor declared private to prevent its use.


TestCaller& operator=(const TestCaller &other)

A copy operator declared private to prevent its use.

Attributes


Fixture *m_fixture

A pointer to Fixture ( private ).


bool m_ownFixture

If TRUE , TestCaller owns Fixture and deletes it in its destructor ( private ).


TestMethod m_test

The TestMethod that this TestCaller will run ( private ).