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

  1. /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  2.  
  3.   tests.cpp
  4.   Copyright (c) 1995, 1996 Borland International
  5.   $Revision:   1.19  $
  6.   $Header:   Y:\admin\bride\addon\deliver\examples\tests.cpv   1.19   19 Nov 1996 11:21:42   JDOUGLAS  $
  7.   
  8.   To add a new test:
  9.   - Derive your test class from TestObject and implement pure virtual methods
  10.     (see option.h and option.cpp for a simple example)
  11.   - Include its header here
  12.   - Add a new instance to the _testObjArray in Tests::setup(), 
  13.    
  14. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/  
  15.  
  16.  
  17.  
  18. #ifndef __AOEXPCH_H
  19.   #include "aoexpch.h"
  20. #endif
  21.  
  22. #pragma hdrstop
  23.  
  24. #include <string.h>   // strcmp()
  25. #include <assert.h>
  26.  
  27. #include "tests.h"
  28. #include "option.h"
  29. #include "project.h"
  30. #include "project2.h"
  31. #include "project3.h"
  32. #include "target.h"
  33. #include "toolsrvr.h"
  34. #include "script.h"
  35. #include "testdlg.h"
  36. #include "edittest.h"
  37. #include "edittst2.h"
  38. #include "maketest.h"
  39. #include "viewtest.h"
  40. #include "filetest.h"
  41. #include "mpdtest.h"
  42. #include "cmdtest.h"
  43. #include "menutest.h"
  44. #include "tool2.h"
  45. #include "edittool.h"
  46. #include "msgtest.h"
  47. #include "prset.h"
  48. #include "msgtest2.h"
  49. #include "msgcli.h"
  50. #include "ideuitst.h"
  51.  
  52. static Tests * TheTests = NULL;
  53.  
  54. //.............................................................................
  55. void Tests::setup() {
  56.   //
  57.   // MAX_TESTS is currently set to 100 in tests.h.
  58.   //
  59.   if ( _setup ) {
  60.     return;
  61.   }
  62.   AddTest( new MpdTest );
  63.   AddTest( new OptionSetTestA );
  64.   AddTest( new TargetTestA );
  65.   AddTest( new ProjectTestA );
  66.   AddTest( new ProjectTestB );
  67.   AddTest( new ProjectTestC );
  68.   AddTest( new ToolTestA );
  69.   AddTest( new ScriptTestA );
  70.   AddTest( new ToolTestB );
  71.   AddTest( new EditTestA );
  72.   AddTest( new MakeTestA );
  73.   AddTest( new ViewTest );
  74.   AddTest( new FileTestA );
  75.   AddTest( new CmdTestA );
  76.   AddTest( new MenuTestA );
  77.   AddTest( new ToolTestC );
  78.   AddTest( new EditToolTest );
  79.   AddTest( new MsgSystemTest);
  80.   AddTest( new EditTestB );
  81.   AddTest( new MenuTestB );
  82.   AddTest( new EditTestC );
  83.   AddTest( new PrinterSettingsTest );
  84.   AddTest( new MsgTest );
  85.   AddTest( new MessageClientTest );
  86.   AddTest( new IdeUITest );
  87.   
  88.   _setup = TRUE;
  89. }
  90. //.............................................................................
  91. Tests::Tests() { 
  92.   memset( _testObjArray, NULL, sizeof( _testObjArray ) );
  93.   _setup = FALSE;
  94.   _theTests = this;
  95. }
  96. //.............................................................................
  97. Tests::~Tests() {
  98.   TestObject * * p = _testObjArray;
  99.   for ( int i = 0; i < MAX_TESTS; ++i, ++p ) {
  100.     if ( *p ) {
  101.       delete (*p);
  102.     }
  103.   }
  104.   _theTests = NULL;
  105. }  
  106. //.............................................................................
  107. Tests * Tests::_theTests;
  108.  
  109. //.............................................................................
  110. Tests * Tests::GetTests() {
  111.   //
  112.   // static method.
  113.   //
  114.   _theTests->setup();
  115.   return _theTests;  
  116. }
  117. //.............................................................................
  118. void Tests::AddTest( TestObject * testObj ) {
  119.   TestObject * * p = _testObjArray;
  120.   for ( int i = 0; i < MAX_TESTS; ++i, ++p ) {
  121.     if ( *p == NULL ) {
  122.       *p = testObj;
  123.       return;
  124.     }
  125.   }
  126.   assert( 1 );    // TOO MANY TESTS!
  127. }
  128. //.............................................................................
  129. void Tests::RegisterOutput( TestOutput * output ) {
  130.   TestObject * * p = _testObjArray;
  131.   for ( int i = 0; i < MAX_TESTS; ++i, ++p ) {
  132.     if ( *p ) {
  133.       (*p)->RegisterOutput( output );
  134.     }
  135.   }
  136. }  
  137. //.............................................................................
  138. int Tests::NumTestObjects() { 
  139.   int count = 0;
  140.   TestObject * * p = _testObjArray;
  141.   for ( int i = 0; i < MAX_TESTS; ++i, ++p ) {
  142.     if ( *p ) {
  143.       ++count;
  144.     }
  145.   }
  146.   return count;
  147. }
  148. //.............................................................................
  149. TestObject * Tests::GetTestObject( int testObjectNum ) {
  150.   return _testObjArray[ testObjectNum ];
  151. }
  152. //.............................................................................
  153. TestObject * Tests::FindTestObject( const char * name ) {
  154.   TestObject * * p = _testObjArray;
  155.   for ( int i = 0; i < MAX_TESTS; ++i, ++p ) {
  156.     if ( *p ) {
  157.       if ( 0 == strcmp( (*p)->GetName(), name ) ) {
  158.         return *p;
  159.       }
  160.     }
  161.   }
  162.   return NULL;
  163. }  
  164. //.............................................................................
  165. const char * TestObject::FormatStr( const char * fmt, ... ) {
  166.   static char buf[ 1024 ];
  167.   va_list va;
  168.   va_start( va, fmt );
  169.   wvsprintf( buf, fmt, va );
  170.   va_end( va );
  171.   return buf; 
  172. }  
  173. //.............................................................................
  174. void TestObject::ShowPolyStr( const char * label, 
  175.                     IPolyString * ps, 
  176.                     BOOL release ) {
  177.   if ( ps ) {
  178.     OutStr( FormatStr( "%s: %s", label, ps->GetCstr() ) );
  179.     if ( release ) {
  180.       ps->Release();
  181.     }
  182.   }
  183. }
  184.  
  185. extern HINSTANCE ghInst = NULL;
  186. //.............................................................................
  187. extern "C" void WINAPI __export
  188. BcwAddOnEntry( IIdeServer * pIdeServer ) {
  189.   if ( pIdeServer ) {       // startup time
  190.     if ( !TheTests ) {
  191.       TheTests = new Tests;
  192.     }       
  193.     SetIdeServer( pIdeServer );
  194.     CreateTestDialog( ghInst );
  195.   }
  196.   else {                // shutdown time
  197.     DestroyTestDialog();
  198.     ReleaseIdeServer();
  199.     if ( TheTests ) {
  200.       delete TheTests;
  201.       TheTests = NULL;
  202.     }      
  203.   }
  204. }
  205. //.............................................................................
  206. extern "C" BOOL WINAPI __export
  207. DllEntryPoint(HINSTANCE hInst, DWORD fdwReason, LPVOID) {
  208.   ghInst = hInst;
  209.   static BOOL oleInit = FALSE;
  210.   switch( fdwReason ) {
  211.     case DLL_PROCESS_ATTACH: 
  212.       if ( FAILED( OleInitialize(NULL) ) ) {
  213.         return FALSE;
  214.       }
  215.       oleInit = TRUE;
  216.       break;
  217.  
  218.     case DLL_PROCESS_DETACH:
  219.       if ( oleInit ) {
  220.         OleUninitialize();
  221.       }
  222.       break;
  223.   }
  224.   return TRUE;
  225. }
  226.  
  227.