home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tlx501.zip / DEBUG / TESTABLE.H < prev    next >
C/C++ Source or Header  |  1996-01-05  |  3KB  |  111 lines

  1. /****************************************************************************
  2.     $Id: testable.h 501.0 1995/03/07 12:26:50 RON Exp $
  3.  
  4.     Copyright (c) 1991-95 Tarma Software Research. All rights reserved.
  5.  
  6.     Project:    Tarma Library for C++ V5.0
  7.     Author:    Ron van der Wal
  8.  
  9.     Declarations for testing functions and classes:
  10.  
  11.     TLTestable    - (virtual) base class for all testable classes
  12.  
  13.     $Log: testable.h $
  14.     Revision 501.0  1995/03/07 12:26:50  RON
  15.     Updated for TLX 5.01
  16.     Revision 1.2  1995/01/31 16:29:00  RON
  17.     Update for release 012
  18.     Added partial support for SunPro C++ compiler
  19.     Revision 1.1  1995/01/05  15:36:00  ron
  20.     Initial revision
  21.  
  22.     Revision 1.1  1994/10/05  18:25:06  ron
  23.     Initial revision
  24.  
  25. ****************************************************************************/
  26.  
  27. #ifndef _TLX_TESTABLE_H
  28. #define    _TLX_TESTABLE_H
  29.  
  30. #ifndef _TLX_TLX_H
  31. #include <tlx\501\tlx.h>
  32. #endif
  33.  
  34. /*---------------------------------------------------------------------------
  35.     Macros to enable/disable testability
  36. ---------------------------------------------------------------------------*/
  37.  
  38. #ifdef NDEBUG        //-----    No testing
  39.  
  40. #define TESTABLE        public TLNull
  41. #define TEST_INTERFACE(Class)
  42.  
  43. #else            //-----    Testing version
  44.  
  45. #define TESTABLE        public virtual TLTestable
  46.  
  47. #define TEST_INTERFACE(Class)    \
  48.     virtual void        _TstSetState(const char *);    \
  49.     virtual void        _TstResetState();               \
  50.     virtual void        _TstReportState();              \
  51.     virtual void        _TstCheckState();
  52.  
  53. #endif
  54.  
  55. /*---------------------------------------------------------------------------
  56.     TLNull -
  57.  
  58.     Empty class, used as a substitute for TLTestable when its functions
  59.     are disabled in a non-debugging build.
  60. ---------------------------------------------------------------------------*/
  61.  
  62. class _TLXCLASS TLNull {};
  63.  
  64. /*---------------------------------------------------------------------------
  65.     TLTestable -
  66.  
  67.     (Virtual) base class for all testable classes. It contains a generic
  68.     interface to allow access to built-in class tests. Use it as follows:
  69.  
  70.     class YourClass: public FirstBase,...,TESTABLE
  71.     {
  72.     private:
  73.     TEST_INTERFACE(YourClass)
  74.     };
  75.  
  76. ---------------------------------------------------------------------------*/
  77.  
  78. class _TLXCLASS TLTestable {
  79. public:
  80.     virtual ~TLTestable();
  81.  
  82.     // Standard testing interface. These functions should be overridden as
  83.     // appropriate for derived classes. For output, they should use the
  84.     // TLX_TRACE macros.
  85.  
  86.     virtual void        _TstSetState(const char *);
  87.     virtual void        _TstResetState();
  88.     virtual void        _TstReportState();
  89.     virtual void        _TstCheckState();
  90. };
  91.  
  92. ************* Alternative:
  93.  
  94. class Tester {
  95. public:
  96.     virtual void        _TstSetState(const char *);
  97.     virtual void        _TstResetState();
  98.     virtual void        _TstReportState();
  99.     virtual void        _TstCheckState();
  100. };
  101.  
  102. class Testable {
  103. public:
  104.     virtual Tester *    CreateTester() = 0;
  105. };
  106.  
  107. This would move the actual testing code outside the CUT proper, just as
  108. with iterators. Result: less impact on the class under test.
  109.  
  110. #endif    // _TLX_TESTABLE_H
  111.