Writing text to the console

To write out diagnostic text from a test, use the member function OutputTextStream, which recognizes the standard C++ << operator for all built-in types. Text output produced with OuptutTextStream displays to the console and is also saved in a TTieredTextBuffer within the test. You can then log the test, including the text buffer. If a test fails, you can retrieve the associated diagnostic text to determine the cause of the failure.

OutputTextStream returns a pointer to a TTieredTextBuffer object that contains the text. Objects of the class TTieredTextBuffer act like C++ ostream objects. They support << operators for all built-in types and for some basic CommonPoint application system types.

TTieredTextBuffer has some additional functionality beyond that of ostream to support retrieving textual information for later analysis:

Most text occupies the tier kNormal. Important information that should not be missed occupies tier kGeneral or kHeadline. Detailed information that can usually be ignored occupies tier kDetail or kDebug.

A special tier, kEphemeral, indicates text that appears on the console once, but is not saved with the object. This tier is useful for status messages that do not need to be seen later or messages that may take up excessive memory.

This is a list of available tiers in order of least detailed to most detailed:

This example shows how to assign tiers to text you write to the console.

      void TSampleObjectOutputTest::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.
      
          OutputTextStream() << "\nThis is written with default setting.\n";
          OutputTextStream() << PushTier(TTieredText::kTop);
          OutputTextStream() << "This is at tier kTop.\n";
          OutputTextStream() << PushTier(TTieredText::kHeadline);
          OutputTextStream() << "This is at tier kHeadline.\n";
          OutputTextStream() << PushTier(TTieredText::kGeneral);
          OutputTextStream() << "This is at tier kGeneral.\n";
          OutputTextStream() << PushTier(TTieredText::kEphemeral);
          OutputTextStream() << "This is at tier kEphemeral and does not go to the test log.\n";
          OutputTextStream() << PushTier(TTieredText::kNormal);
          OutputTextStream() << "This is at tier kNormal.\n";
          OutputTextStream() << PushTier(TTieredText::kDetail);
          OutputTextStream() << "Tier kDetail and does not print at default settings.\n";
          OutputTextStream() << PushTier(TTieredText::kDebug);
          OutputTextStream() << "Tier kDebug and does not print at default settings.\n";
          OutputTextStream() << PushTier(TTieredText::kBottom);
          OutputTextStream() << "Tier kBottom and does not print at default settings.\n";
          OutputTextStream() << PopTier() ; // return back to kDebug
          OutputTextStream() << PopTier() ; // return back to kDetail
          OutputTextStream() << PopTier() ; // return back to kNormal
          OutputTextStream() << PopTier() ; // return back to kEphemeral
          OutputTextStream() << PopTier() ; // return back to kGeneral
          OutputTextStream() << PopTier() ; // return back to kHeadline
          OutputTextStream() << PopTier() ; // return back to kTop
          OutputTextStream() << "Back to normal.\n";
              
          SetSuccess(success); 
      } 

[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