Protocol tests

Protocol tests allow you to test an entire tree of classes if those classes adhere to the same protocol. The Test framework contains five ready-made protocol tests:

These tests are template classes derived from abstract base classes. The abstract classes define the protocol used by their associated template classes. These abstract base classes are derived from TBaseComparisonTest, which defines the protocol for a test that compares two objects using a comparator.

Protocol tests leverage testing effort because they allow you to test an entire tree of classes with a single test. The Test framework uses template classes to implement the protocol tests. Figure 6 represents the class hierarchy of
these classes.


The Test framework provides a set of macros that you can use in most cases to create protocol tests. The macros let you create a test in one or two lines of code. For specific information, refer to "Testing object protocols" on page 50.

TCopyTestOf, a template class derived from TBaseCopyTest, tests the copying of the target using the global Copy function. You can use TCopyTestOf directly only if the target and comparator are set outside the test, with SetTarget and AdoptComparator respectively, before running the test. Otherwise, derive your class from TCopyTestOf and overload the SetupComparator member function (to specify which comparator to use for the test) and the CreateNewTarget member function (to create the target).

TFlattenResurrectTestOf, a template class derived from TBaseFlattenResurrectTest, tests the flattening and resurrecting of the target using the global Flatten and Resurrect functions. You can use TFlattenResurrectTestOf directly only if the target and comparator are set outside the test, with SetTarget and AdoptComparator respectively, before running the test. Otherwise, you should derive your class from TFlattenResurrectTestOf and overload the SetupComparator member function (to specify which comparator to use for the test) and the CreateNewTarget member function (to create the target).

TStreamTestOf, a template class derived from TBaseStreamTest, tests the streaming of the target object using a streamer, TAbstractStreamer. You can use TStreamTestOf directly only if the target, comparator, and streamer are set outside the test, with SetTarget, AdoptComparator, and AdoptStreamer respectively, before running the test. Otherwise, derive your class from TStreamTestOf and overload the SetupComparator member function (to specify which comparator to use for the test), the SetupStreamer member function (to specify which streamer to use for the test), and the CreateNewTarget member function (to create the target).

TPrimitiveComparisonTestOf, a template class derived from TBasePrimitiveComparisonTest, tests the canonical member functions: constructor, destructor, copy constructor, and assignment operator. You can use TPrimitiveComparisonTestOf directly only if the target and comparator are set outside the test, with SetTarget and AdoptComparator respectively, before running the test. Otherwise, derive your class from TPrimitiveComparisonTestOf and overload the SetupComparator member function (to specify which comparator to use for the test) and the CreateNewTarget member function to (create the target). You can also override CreateEqualTarget and CreateUnequalTarget to create the objects used to check equality and inequality.

TWellBehavedObjectTestOf, a template class derived from TBaseWellBehavedObjectTest, tests the copying, flattening, and streaming of the target by creating TCopyTestOf, TFlattenResurrectTestOf, and TStreamTestOf tests for the target and by running the tests. The test also does all the testing done by TBasePrimitiveComparisonTest.

To perform all of the tests, you create a derived class of TWellBehavedObjectTestOf. TWellBehavedObjectTestOf uses the template classes TCopyTestOf, TFlattenResurrectTestOf, and TStreamTestOf to do the actual testing of copying, flattening, and streaming respectively. TWellBehavedObjectTestOf uses the template class TPrimitiveComparisonTestOf to test the copy constructor, assignment operator, and destructor.

You can also use TCopyTestOf, TFlattenResurrectTestOf, TStreamTestOf, and TPrimitiveComparisonTestOf individually to test a specific protocol.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker