A template that creates test cases by applying functor objects to an arbitrary object.
This template generates test cases that use applicables for all phases of a unit test:
Test set-up, execution and tear-down. So a TestAppliance is an extension of a TestGadget.
And also here, the fixture object itself does not need to inherit from TestCase.
Most likely, all the needed applicables are created from member functions of the test fixture class.
They are all owned by the test appliance. So when the appliance is
destroyed, this objects are deleted as well.
The apply template function could be used
to construct Applicable-instances out of member functions of the fly. Note that there also
versions of the apply functions that allow to specify constant parameters for the
member functions.
The test appliance itself could be easily created with the following template functions:
template<class T> inline TestAppliance<T>* makeTestAppliance (
const string& name,
Applicable<T>* testFunc,
Applicable<T>* setUpFunc,
Applicable<T>* tearDownFunc
);
template<class T> inline TestAppliance<T>* makeTestAppliance (
const string& name,
T* object,
Applicable<T>* testFunc,
Applicable<T>* setUpFunc,
Applicable<T>* tearDownFunc,
bool releaseFixture = false
);
template<class T> inline TestAppliance<T>* makeStdTestAppliance (
const string& name,
Applicable<T>* testFunc
);
template<class T> inline TestAppliance<T>* makeStdTestAppliance (
const string& name,
T* object,
Applicable<T>* testFunc,
bool releaseFixture = false
);
The makeStdTestAppliance functions automatically use the member function setUp () and
tearDown () to construct set-up and tear-down applicables, so the fixture class T must have
such member functions. If the fixture object is given as parameter, it is assumed that the instance
is shared between test appliances, so releaseFixture defaults to false.