Using the protocol test macros

The easiest way to perform protocol tests on objects that can be streamed, flattened, or copied and that require specialized comparators or streamers is to use the protocol test macros. This example shows how to use the macros to create a TWellBehavedObjectTestOf test:

  1. Call the TWellBehavedObjectTestOfInterfaceMacro.
    You must specify the test class and the target class.
  2. Call the TWellBehavedObjectTestOfImplementationMacro.
    You must specify these items:
    1. The test class name.
    2. The target class name.
    3. The comparator class used for comparing the target and the streamed object.
    4. The streamer class used for streaming the target.
    5. The list of parameters for the constructor of the target class, including parentheses. Leave the argument blank if you use the empty constructor to create the target.
    6. A second set of parameters with different values from the first set of parameters. The test uses the second set of parameters to create an object unequal to the object created with the first set of parameters.
    1  TWellBehavedObjectTestOfInterfaceMacro(TSampleObjectWellBehavedObjectTest, TSampleObject);
    2  
    3  TWellBehavedObjectTestOfImplementationMacro( TSampleObjectWellBehavedObjectTest,  
    4          TSampleObject, TOperatorComparator, TPolymorphicStreamer, (1), (2));
Line number 1 shows the call to the Interface macro.

Line numbers 3 and 4 show the call to the implementation macro. The constructor for TSampleObject requires a single numeric value. The (1) on line 4 represents the parameter for the first TSampleObject object. The (2) on line 4 represents the parameter for the second TSampleObject object.

NOTE Compilers sometimes automatically define the empty constructor, copy constructor, and assignment operators. If you define these member functions as private, you will not be able to use TWellBehavedObjectTestOf because the template cannot be created.

The following table lists the protocol test macros syntax and shows an example of each macro.

Protocol test macro Description
TCopyTestOf
Tests copying of the target class using the global Copy function.
TCopyTestOfInterfaceMacro(testClass, targetClass)
Example:
    TCopyTestOfInterfaceMacro(TSampleObjectCopyTest, TSampleObject);
TCopyTestOfImplementationMacro(testClass, targetClass, comparatorClass, parameterList)
Example:
      TCopyTestOfImplementationMacro(TSampleObjectCopyTest,TSampleObject, TOrderedOperatorComparator, (1));
TFlattenResurectTestOf
Tests the flattening and resurrecting of the target object using the global Flatten and Resurrect functions.
TFlattenRessurectTestOfInterfaceMacro(testClass, targetClass)
Example: TFlattenResurrectTestOfInterfaceMacro(TSampleObjectFlattenResurrectTest, TSampleObject);
TFlattenRessurectTestOfImplementationMacro(testClass, targetClass, comparatorClass, parameterList)
Example:
      TFlattenResurrectTestOfImplementationMacro(TSampleObjectFlattenResurrectTest, TSampleObject, TOrderedOperatorComparator, (1));
      
    
You can leave the parameter empty if your class uses an empty constructor.
      TFlattenResurrectTestOfImplementationMacro(TSampleObjectFlattenResurrectTest, TSampleObject, TOrderedOperatorComparator,);
TStreamTestOf
Tests streaming of the target object.
TStreamTestOfInterfaceMacro(testClass, targetClass)
Example: TStreamTestOfInterfaceMacro(TSampleObjectStreamTest, TSampleObject);
TStreamTestOfImplementationMacro(testClass, targetClass, comparatorClass, streamerClass, parameterList)
Example: TStreamTestOfImplementationMacro(TSampleObjectStreamTest, TSampleObject, TOperatorComparator, TPolymorphicStreamer, (1));
You can leave the parameter empty if your class uses an empty constructor. TStreamTestOfImplementationMacro( TSampleObjectStreamTest, TSampleObject, TOperatorComparator, TPolymorphicStreamer,);
TPrimitiveComparisonTestOf
Tests the constructor, destructor, copy constructor, and assignment operator for a concrete class only.
TPrimitiveComparisonTestOfInterfaceMacro(testClass, targetClass)
Example: TPrimitiveComparisonTestOfInterfaceMacro(TSampleObjectPrimitiveComparisonTest, TSampleObject);
TPrimitiveComparisonTestOfImplementationMacro(testClass, targetClass, comparatorClass, parameterList, unequalParameterList)
Example: TPrimitiveComparisonTestOfImplementationMacro( TSampleObjectPrimitiveComparisonTest, TSampleObject, TOrderedOperatorComparator, (1), (2));
You can leave the first parameter empty if your class uses an empty constructor. TPrimitiveComparisonTestOfImplementationMacro( TSampleObjectPrimitiveComparisonTest, TSampleObject, TOrderedOperatorComparator,, (2));
TPrimitiveComparisonTestOfEqualOnly
Tests the constructor, destructor, copy constructor, and assignment operator. This macro does not test the target against an unequal object of the same type.
TPrimitiveComparisonTestOfEqualOnlyInterfaceMacro(testClass, targetClass)
Example: TPrimitiveComparisonTestOfEqualOnlyInterfaceMacro (TSampleObjectPrimitiveComparisonTestEqualOnly, TSampleObject);
TPrimitiveComparisonTestOfEqualOnlyImplementationMacro(testClass, targetClass, comparatorClass, parameterList)
Example: TPrimitiveComparisonTestOfImplementationMacro( TSampleObjectPrimitiveComparisonTest, TSampleObject, TOrderedOperatorComparator, (1));
You can leave the parameter empty if your class uses an empty constructor.
    TPrimitiveComparisonTestOfImplementationMacro( TSampleObjectPrimitiveComparisonTest, TSampleObject, TOrderedOperatorComparator,);
TWellBehavedObjectTestOf
Creates and performs the TCopyTestOf, TStreamTestOf, TFlattenResurrectTestOf, and TPrimitiveComparisonTestOf. Turn off the TPrimitiveComparisonTestOf by specifying -p after the -o option when you use RunTest.
TWellBehavedObjectTestOfInterfaceMacro(testClass, targetClass)
Example:
    TWellBehavedObjectTestOfInterfaceMacro(TSampleObjectWellBehavedObjectTest, TSampleObject);
TWellBehavedObjectTestOfImplementationMacro(testClass, targetClass, comparatorClass, streamerClass, parameterList, unequalParameterList)
Example:
      TWellBehavedObjectTestOfImplementationMacro( TSampleObjectWellBehavedObjectTest,  TSampleObject, TOrderedOperatorComparator,TPolymorphicStreamer, (1), (2));
      
    
You can leave the first parameter empty if your class uses an empty constructor.
      TWellBehavedObjectTestOfImplementationMacro(TSampleObjectWellBehavedObjectTest,  TSampleObject, TOrderedOperatorComparator, TPolymorphicStreamer,, (2));
TWellBehavedObjectTestOfEqualOnly
Creates and performs the TCopyTestOf, TStreamTestOf, TFlattenResurrectTestOf, and TPrimitiveComparisonTestOf. This macro does not test the target against an unequal object of the same type.
TWellBehavedObjectTestOfEqualOnlyInterfaceMacro(testClass, targetClass)
Example:
    TWellBehavedObjectTestOfEqualOnlyInterfaceMacro (TSampleObjectWellBehavedObjectTestEqualOnly, TSampleObject);
TWellBehavedObjectTestOfEqualOnlyImplementationMacro(testClass, targetClass, comparatorClass, streamerClass, parameterList, unequalParameterList)
Example:
      TWellBehavedObjectTestOfEqualOnlyImplementationMacro (TSampleObjectWellBehavedObjectTestEqualOnly, TSampleObject, TOrderedOperatorComparator, TPolymorphicStreamer, (1), (2));


[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