For example, this is the header for a class with a constructor that requires
an object:
// File ProtocolTarget.h
// Copyright (C) 1995 Taligent, Inc. All rights reserved.
#ifndef TaligentSamples_PROTOCOLTARGET
#define TaligentSamples_PROTOCOLTARGET
// For MCollectible, UniChar (in PrimitiveTypes.h)
#ifndef Taligent_COREPRIMITIVECLASSES
#include <Taligent/CorePrimitiveClasses.h>
#endif
class TTextObject : public MCollectible {
public:
MCollectibleDeclarationsMacro(TTextObject);
TTextObject(const TStandardText& name);
TTextObject(const TToken& name);
TTextObject(const TTextObject& other);
virtual ~TTextObject();
TTextObject& operator=(const TTextObject& rhs);
bool operator==(const TTextObject& other)const;
bool operator!=(const TTextObject& other)const;
virtual TStream& operator<<=(TStream& fromWhere);
virtual TStream& operator>>=(TStream& toWhere) const;
virtual long Hash() const;
private:
TTextObject(); // disallow use of the empty constructor.
UniChar* fText;
unsigned long fLength;
unsigned long fMaxLength;
enum EVersion { kOriginalVersion };
};
Line numbers 18 through 32 are the test class declaration.
Line numbers 34 through 71 show the implementation for the necessary member functions.
1 // File ProtocolTest.C
2 // Copyright (C) 1995 Taligent, Inc. All rights reserved.
3 #ifndef TaligentSamples_PROTOCOLTEST
4 #define TaligentSamples_PROTOCOLTEST
5
6 #ifndef Taligent_TEST
7 #include <Taligent/Test.h>
8 #endif
9
10 #ifndef Taligent_WELLBEHAVEDOBJECTTEST
11 #include <Taligent/WellBehavedObjectTest.h> // for TWellBehavedObjectTest
12 #endif
13
14 #ifndef TaligentSamples_PROTOCOLTARGET
15 #include "../ProtocolTarget.h"
16 #endif
17
18 class TWellBehavedTextObjectTest : public TWellBehavedObjectTestOf<TTextObject>
19 {
20 public:
21 TWellBehavedTextObjectTest();
22 virtual ~TWellBehavedTextObjectTest();
23
24 virtual void *CreateNewTarget() const;
25 virtual void *CreateEqualTarget() const;
26 virtual void *CreateUnequalTarget() const;
27
28 virtual void SetupComparator();
29 virtual void SetupStreamer();
30
31 MCollectibleDeclarationsMacro(TWellBehavedTextObjectTest);
32 };
33
34 MCollectibleDefinitionsMacro(TWellBehavedTextObjectTest, 0);
35
36 TWellBehavedTextObjectTest::TWellBehavedTextObjectTest() {}
37
38 TWellBehavedTextObjectTest::~TWellBehavedTextObjectTest() {}
39
40 void *TWellBehavedTextObjectTest::CreateNewTarget() const
41 // Create target object. Do not delete the target object.
42 {
43 TStandardText text("Hello world");
44 return (new (TAllocationHeap(this)) TTextObject(text));
45 }
46
47 void *TWellBehavedTextObjectTest::CreateEqualTarget() const
48 // Create TTextObject object that is equal to the one created in CreateNewTarget.
49 // Do not delete the target object.
50 {
51 TToken token("Hello world");
52 return (new (TAllocationHeap(this)) TTextObject(token));
53 }
54
55 void *TWellBehavedTextObjectTest::CreateUnequalTarget() const
56 // Create a TTextObject object that is NOT equal to the one created in CreateNewTarget. Do not delete the target object.
57 {
58 TStandardText text("Goodbye world");
59 return (new (TAllocationHeap(this)) TTextObject(text));
60 }
61
62 void TWellBehavedTextObjectTest::SetupComparator()
63 // Creates comparator that is used in the test.
64 {
65 AdoptComparator(new (TAllocationHeap(this)) TOperatorComparator<TTextObject>);
66 }
67
68 void TWellBehavedTextObjectTest::SetupStreamer()
69 // Creates streamer that is used in the test.
70 {
71 AdoptStreamer(new (TAllocationHeap(this)) TPolymorphicStreamer<TTextObject>);
72 }
| Base class | Functions to override | |
| TCopyTestOf | SetupComparator CreateNewTarget | |
| TFlattenResurrectTestOf | SetupComparator CreateNewTarget | |
| TStreamTestOf | SetupComparator SetupStreamer CreateNewTarget | |
| TPrimitiveComparisonTestOf | SetupComparator CreateNewTarget CreateEqualTarget (optional) CreateUnequalTarget (optional) | |
| TWellBehavedObjectTestOf | SetupComparator SetupStreamer CreateEqualTarget (optional) CreateUnequalTarget (optional) |