Selectively writing test output to a log file

TTieredTextBuffer sends output to the console and saves the text with the test. This is useful for evaluating the test after resurrecting it from a log. However, saving all text to a log can cause a problem if it uses too much memory.

To cause some messages to display to the console but not be saved, use the special tier kEphemeral. The Test framework displays text in this tier to the console but does not save it in the text buffer. Note that this capability is simply a special case of the usual tier mechanism:

      void TSampleObjectOutputLogTest::Test()
      {
          bool success = true;    // Always set 'success' to false if any test fails.
          // Always check to see that 'success' is true before beginning subsequent
          // tests.
      
      // This will be recorded in the test:
          OutputTextStream() << "\nThis is information about the test.\n\n";
          
          // Subsequent text will go to the console but not to the test log.
          OutputTextStream() << PushTier(TTieredText::kEphemeral);
          for (short i=0; i<10; i++) {
              OutputTextStream() << "Loop cycle " << i << " \n";
          }
          
          // Start recording to log again
          OutputTextStream() << PopTier() << "Loop completed " << i << " cycles.\n";
          
          SetSuccess(success);    // *** NEVER DELETE THIS
      }
This code displays the following output to the console:

      This is information about the test.
      
      Loop cycle 0 
      Loop cycle 1 
      Loop cycle 2 
      Loop cycle 3 
      Loop cycle 4 
      Loop cycle 5 
      Loop cycle 6 
      Loop cycle 7 
      Loop cycle 8 
      Loop cycle 9 
      Loop completed 10 cycles.
      Test TSampleObjectOutputLogTest ( Pass ) {}
The same test writes the following information to the test log:

      Test TSampleObjectOutputLogTest ( Pass ) {
      This is information about the test.
      
      Loop completed 10 cycles.

[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