SampleObjectTest.C

This is the implementation for the TSampleObject test classes.

    1  // File SampleObjectTest.C
    2  // Copyright (C) 1995 Taligent, Inc. All rights reserved.
    3  #ifndef TaligentSamples_SAMPLEOBJECTTEST
    4  #include "SampleObjectTest.h"
    5  #endif
    6  
    7  #ifndef TaligentSamples_TESTSTRING
    8  #include "../TestString.h"
    9  #endif
    10  
    11  MCollectibleDefinitionsMacro(TSampleObjectSimpleTest,0)
    12  
    13  //----------------------------------------------------------------------------
    14  // TSampleObjectSimpleTest member functions
    15  //----------------------------------------------------------------------------
    16  TSampleObjectSimpleTest::TSampleObjectSimpleTest() { }
    17  
    18  //----------------------------------------------------------------------------
    19  TSampleObjectSimpleTest::~TSampleObjectSimpleTest() { }
    20  //----------------------------------------------------------------------------
    21  void TSampleObjectSimpleTest::Test()
    22  {
    23      bool success = true;    // Always set 'success' to false if any test fails.
    24      // Always check to see that 'success' is true before beginning subsequent
    25      // tests.
    26  
    27      unsigned long    maxLength ;        
    28      int              correctLength = 256;
    29      
    30      TSampleObject sample(correctLength);
    31      maxLength = sample.GetMaxLength();
    32  
    33          OutputTextStream() << "\nThis is a simple test.\n";
    34          OutputTextStream() << "correctLength = " << correctLength << ".\n";
    35          OutputTextStream() << "maxLength = " << maxLength << ".\n";
    36  
    37      
    38      if (maxLength != correctLength)  {
    39          OutputTextStream() << "\n Length does not match";
    40          success = false;
    41      }
    42  
    43      SetSuccess(success); 
    44  }    
Line number 8: Include the header file for the class you are testing.

Line numbers 21 through 44: Your class must override the Test member function. In your test function you must call SetSuccess with the result of your decision function.

When you run the test, it displays the following output to the console:

    1  This is a simple test.
    2  correctLength = 256.
    3  maxLength = 256.
    4  Test TSampleObjectSimpleTest ( Pass ) {}
Line numbers 1 through 3: The OutputTextStream messages. The Test framework displays line 4 to show the outcome of the test.


[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