IComparisonTestOf

IComparisonTestOf tests the constructor, copy constructor and assignment operator of the target class. This is a good way to leverage testing effort since it allows you to test classes if those classes are expected to adhere to some protocol. This protocol test is implemented using a template class.

Clients can either create a subclass or directly use this class.

IComparisonTestOf tests the following operations of its target class:

    - copy constructed stack object
    - operator= assigned stack object
    - operator= self-assigned stack object
    - copy constructed heap object
    - operator= assigned heap object
    - operator= self-assigned heap object
    - Separately constructed unequal object of the unequal target is given

Target class must have operator== defined.

The best was to use the IComparisonTest framework is to use the protocol macros ComparisonTestMacro and ComparisonTestEqualOnlyMacro.

These macros do everything you need in one line. They write the entire header and the entire implementation, including construtors and destructors. Just supply the names of the test class, target class, comparator, the parameter list for the constructor that creates the target, and (optionally) the unequal target. The parameter list may be left blank to indicate that the empty constructor is to be used to create the target or unequal target. If the test is only testing equal targets, then use the "EqualOnly" macros.

Usage:

Example: ISample is the target class which we want to test. ISample has a constructor, a copy constructor, an operator=, and an operator== defined:

comparisonTestMacro(ISampleTest, ISample, (1), (2));

Example: Example for a class which creates the target object using the empty constructor:

comparisonTestMacro(ISampleTest, ISample, , (2));

Now you can run ISampleTest with the following command:

runTestImplementationMacro(ISampleTest);

If you do not want to test your target against an unequal object of the same type, do the following:

comparisonTestEqualOnlyMacro(ISampleTest, ISample, (1));

Or you can use this global function which creates and returns an instance of IComparisonTestOf:

createComparisonTest(new ISample(1), new ISample(2));

which can be used with the adoptTest method (see the ITestCollection class).


IComparisonTestOf - Member Functions and Data by Group

Constructors & Destructor

Class constructors and destructors.


[view class]
~IComparisonTestOf
public:
virtual ~IComparisonTestOf()
Destructor

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
IComparisonTestOf
Use these to construct obejcts of this class.


Overload 1
public:
IComparisonTestOf(const IComparisonTestOf < AType >& that)
Copy constructor.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


Overload 2
public:
IComparisonTestOf(AType* target, AType* unequalTarget = 0)
Constructor which accepts the following arguments:.
target
Target object to perform tests on.
unequalTarget
Unequal object to use for comparison.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
operator =
public:
IComparisonTestOf < AType >& operator =( const IComparisonTestOf < AType >& that )
Standard assignment operator.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


Test Methods

Class member functions used to by the IComparison tests. Some need to be overridden by the user and some should NOT be overridden. See each member function for details.


[view class]
copyInfo
public:
virtual void copyInfo()
Within copyInfo, IComparisonTestOf calls the inherited implementation (e.g., IDerived::copyInfo should call IBase::copyInfo). Then copyInfo should add key/value pairs to infoMap by calling the addInfo method.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
targetClassNameAsString
protected:
virtual const char* targetClassNameAsString() const
Returns the name of the target class. By default, it returns NULL.

You must override this method if you want the target class name reported in the test output.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


[view class]
test
protected:
virtual void test()
Tests the constructor, copy constructor, and assignment operator of the target class.

Note: Do NOT override the method. Do NOT call this method directly. The best was to use the IComparisonTest framework is to use the protocol macros: ComparisonTestMacro and ComparisonTestEqualOnlyMacro.

Supported Platforms

Windows OS/2 AIX
Yes Yes Yes


IComparisonTestOf - Inherited Member Functions and Data

Inherited Public Functions

ITest

Inherited Public Data

ITest

Inherited Protected Functions

ITest

Inherited Protected Data