home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / ADDON.PAK / TESTS.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  4.0 KB  |  126 lines

  1. /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  2.  
  3.   tests.h
  4.   Created: 10/24/95
  5.   Copyright (c) 1995, 1996 Borland International
  6.   $Revision:   1.18  $
  7.    
  8. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/  
  9.  
  10. #ifndef __TESTS_H
  11. #define __TESTS_H
  12.  
  13. #include <ideaddon\ipolystr.h>
  14.  
  15. #define MAX_TESTS  100
  16.  
  17. extern HINSTANCE ghInst;
  18.  
  19. //.............................................................................
  20. class TestOutput {
  21.   //
  22.   // The output implementation will be supplied by the dialog box object
  23.   // through the TestObject::RegisterOutput() method.
  24.   //
  25.  public: 
  26.   virtual void Show( const char * str ) = 0;
  27. };
  28.  
  29. //.............................................................................
  30. //
  31. // A TestObject represents a group of related tests. Many TestObject's can be
  32. // registered to appear in the test dialog box (see tests.cpp for where this
  33. // is done).
  34. // 
  35. // Anything that you need to do at IDE startup time can be done inside a 
  36. // TestObject constructors (see BcwAddOnInit() in tests.cpp to step through
  37. // what happens).
  38. //
  39. // AddOn's should never call CoCreateInstance() inside
  40. // DllEntryPoint on a PROCESS_ATTACH as this will crash under NT. Instead
  41. // do this type of initialization inside BcwAddOnInit().
  42. //
  43. //
  44. class TestObject {
  45.  public:
  46.   //.... interface .....
  47.   //
  48.   // Init() and UnInit() are called when a user clicks the corresponding buttons
  49.   // in the test dialog box.
  50.   //
  51.   virtual BOOL Init() = 0;
  52.   virtual void UnInit() = 0; 
  53.   //
  54.   // GetName() is called by the dialog box to display each test objects name
  55.   // in a list box.
  56.   //
  57.   virtual const char * GetName() = 0;
  58.   //
  59.   // GetTestDescription() is called by the dialog box to get the description
  60.   // of each sub-test of the test object when the user clicks the '?' button
  61.   // next to each test button.
  62.   //
  63.   virtual const char * GetTestDescription( int testNum ) = 0;
  64.   //
  65.   // When the user clicks one of the test buttons, DoTest() is called with
  66.   // the sub-test number.
  67.   //
  68.   virtual void DoTest( int testNum ) = 0;
  69.  
  70.   //.... implementation ....
  71.   TestObject() { _output = NULL; }
  72.   virtual ~TestObject() {}
  73.   //
  74.   // OutStr() calls the registered TestOutput Show() method, which is
  75.   // responsible for displaying the string in the dialog box output window.
  76.   //
  77.   virtual void OutStr( const char * str ) { if ( _output ) _output->Show( str ); }
  78.   //
  79.   // FormatStr is a helper function which does printf style formatting. This 
  80.   // can be called with OutStr, eg. OutStr( FormatStr( ... ) ); It uses a 
  81.   // static char buffer good up to 1024 chars.
  82.   //
  83.   virtual const char * FormatStr( const char * fmt, ... ); 
  84.   //
  85.   // Another output helper function, ShowPolyStr() will display a label
  86.   // followed by a PolyString (see ipolystr.h!). If 'release' is TRUE, 
  87.   // the PolyString object will be released after it is displayed - which 
  88.   // means you better not try and use it again!
  89.   //
  90.   virtual void ShowPolyStr( const char * label, IPolyString * ps, BOOL release = FALSE );
  91.   //
  92.   // This is called by the Tests object to pass in the TestOutput object
  93.   // supplied by the dialog box object.
  94.   //
  95.   virtual void RegisterOutput( TestOutput * output ) { _output = output; }
  96.  
  97.  protected:
  98.   TestOutput * _output;
  99. };
  100.  
  101. //.............................................................................
  102. //
  103. // This object represents the test suite. New tests shouldn't need to know
  104. // anything about this, except how to get registered, which is described
  105. // in test.cpp.
  106. //
  107. class Tests {
  108.  public:
  109.   Tests();
  110.   ~Tests();
  111.   int NumTestObjects();
  112.   TestObject * GetTestObject( int testObjectNum );
  113.   TestObject * FindTestObject( const char * name );
  114.   void RegisterOutput( TestOutput * output );
  115.   static Tests * GetTests();
  116.  protected:
  117.   void setup();
  118.   void AddTest( TestObject * testObj );
  119.   static Tests * _theTests;
  120.   TestObject * _testObjArray[ MAX_TESTS ];
  121.   BOOL _setup;
  122. };
  123.  
  124.  
  125. #endif    // __TESTS_H
  126.