home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / cprog / actlib12.zip / CHECK.H < prev    next >
C/C++ Source or Header  |  1993-01-14  |  2KB  |  101 lines

  1. /***
  2.  *  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)
  3.  *
  4.  *  File        :  check.h
  5.  *
  6.  *  Description :  General macros for testing pre- and post-conditions.
  7.  *
  8.  *  OS/Compiler :  All
  9.  *
  10.  *  Decisions   :  Will use the tracing if defined
  11.  *
  12.  *  Usage       :  - To check a precondition call the function 
  13.  *                   'precond(  string_to_print, expression );'
  14.  *
  15.  *                 - Define 'PRE' to actually perform precondition check.
  16.  *
  17.  *                 - To check a postcondition call the function
  18.  *                   'postcond(  string_to_print, expression );'
  19.  *
  20.  *                 - Define 'POST' to actually perform postcondition check.
  21.  *
  22.  *                 - To check a condition call the function
  23.  *                   'check(  string_to_print, expression );'
  24.  *
  25.  *                 - Define 'CHECK' to actually perform check.
  26.  *
  27.  ***/
  28.  
  29.  
  30. #ifndef __Check_H
  31. #define __Check_H
  32.  
  33. #ifdef TRACE
  34.  
  35. #include "trace.h"
  36. #define ch_trace        trace
  37.  
  38. #else
  39.  
  40. #define ch_trace( args )    printf args
  41.  
  42. #endif
  43.  
  44.         /*  MACROS DEFINITIONS  */
  45.  
  46.  
  47. #ifdef PRE
  48.  
  49. #define precond( test , expr ) \
  50.     if ( ! (expr) )                            \
  51.        { printf( "\n" ) ;                        \
  52.          ch_trace( ("*** " #test " : Precondition failed\n") ) ;    \
  53.          ch_trace( (" ** in file : " __FILE__ "\n") ) ;        \
  54.          ch_trace( (" ** at line : %d\n" , __LINE__) ) ;        \
  55.          ch_trace( (" ** '" #expr "' is false\n\n") ) ;        \
  56.        }
  57.  
  58. #else
  59.  
  60. #define precond( test , expr )
  61.  
  62. #endif
  63.  
  64. #ifdef POST
  65.  
  66. #define postcond( test , expr ) \
  67.     if ( ! (expr) )                            \
  68.        { printf( "\n" ) ;                        \
  69.          ch_trace( ("*** " #test " : Postcondition failed\n") ) ;    \
  70.          ch_trace( (" ** in file : " __FILE__ "\n") ) ;        \
  71.          ch_trace( (" ** at line : %d\n" , __LINE__) ) ;        \
  72.          ch_trace( (" ** '" #expr "' is false\n\n") ) ;        \
  73.        }
  74.  
  75. #else
  76.  
  77. #define postcond( test , expr )
  78.  
  79. #endif
  80.  
  81. #ifdef CHECK
  82.  
  83. #define check( test , expr ) \
  84.     if ( ! (expr) )                            \
  85.        { printf( "\n" ) ;                        \
  86.          ch_trace( ("*** " #test " : Check failed\n") ) ;        \
  87.          ch_trace( (" ** in file : " __FILE__ "\n") ) ;        \
  88.          ch_trace( (" ** at line : %d\n" , __LINE__) ) ;        \
  89.          ch_trace( (" ** '" #expr "' is false\n\n") ) ;        \
  90.        }
  91.  
  92. #else
  93.  
  94. #define check( test , expr )
  95.  
  96. #endif
  97.  
  98.  
  99.  
  100. #endif
  101.