home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 May / PCP163A.iso / Runimage / Cbuilder4 / Include / UTASSERT.H < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-26  |  3.0 KB  |  108 lines

  1. /* ----------------------------------------------------------------------------
  2.     Microsoft Transaction Server 1.0                                        
  3.     Copyright 1994 - 1996 Microsoft Corporation.  All Rights Reserved.    
  4.  
  5. @doc
  6.  
  7. @module UTAssert.H.h  |
  8.  
  9.     This file contains some macros for asserts.
  10.  
  11.     Following are the Assert macros with a brief definition of them
  12.     DeclAssertFile                Should be added at the begining of each .C/.CPP
  13.     Assert(exp)                    Simple Assert with an expression
  14.     Verify(exp)                    Assert whose exp has side effects and is
  15.                                  always evaluated, even !_DEBUG.
  16.     ExpAssert(exp)                Same as Assert, just a more convenient name.
  17.     AssertSz(exp, sz)            The assert will dump the sz passed to it
  18.     AssertEq(exp, exp2)            Assert that exp == exp2
  19.     AssertGe(exp, exp2)            Assert that exp >= exp2
  20.     AssertNe(exp, exp2)            Assert that exp <= exp2
  21.  
  22. @devnote None
  23.  
  24. *******************************************************************************/
  25.  
  26. #ifndef __UTAssert_H__
  27. #pragma option push -b -a8 -pc -A- /*P_O_Push_S*/
  28. #define __UTAssert_H__
  29.  
  30. #include <stdio.h>
  31.  
  32. typedef unsigned short    WORD;
  33. typedef unsigned long    DWORD;
  34.  
  35.  
  36. #ifndef    _DEBUG
  37.  
  38.     #define DeclAssertFile
  39.     #define Assert(exp)        ((void)1)
  40. #ifndef Verify
  41.     #define Verify(exp)        (exp)
  42. #endif
  43.     #define ExpAssert(exp)        ((void)1)
  44.     #define AssertSz(exp, sz)    ((void)1)
  45.     #define AssertEq(exp, exp2)    (exp)
  46.     #define AssertGe(exp, exp2)    (exp)
  47.     #define AssertNe(exp, exp2)    (exp)
  48.  
  49. #else    //Debug
  50.  
  51.     #define DTCAssertNone    0x0000        /* None */
  52.     #define DTCAssertExit    0x0001        /* Exit the application */
  53.     #define DTCAssertBreak     0x0002        /* Break to debugger */
  54.     #define DTCAssertMsgBox    0x0004        /* Display message box */
  55.     #define DTCAssertStop    0x0008        /* Alert and stop */
  56.     #define DTCAssertStack    0x0010        /* Stack trace */
  57.     #define DTCAssertLog    0x0020        /* Log assert to file only */
  58.  
  59.     #ifdef __cplusplus
  60.     extern "C" {
  61.     #endif
  62.  
  63.     void AssertSzFail(const char *sz, const char *szFilename, unsigned Line);
  64.     void AssertFail(const char  *szFilename, unsigned Line);
  65.  
  66.     static WORD z_wAssertAction = DTCAssertNone; // default to None
  67.  
  68.     static const char szAssertFile[] = "assert.txt";
  69.     static const char szAssertHdr[] = "Assertion Failure: ";
  70.     static const char szMsgHdr[] = ": ";
  71.     static const char szLineHdr[] = ", Line ";
  72.     static const char szAssertEnd[] = "\r\n";
  73.     static const char szAssertCaption[] = "Assertion Failure";
  74.     
  75.     #ifdef __cplusplus
  76.     }
  77.     #endif
  78.  
  79.  
  80.  
  81.     #define DeclAssertFile static const char szAssertFilename[] = __FILE__
  82.  
  83.  
  84.     #define AssertSz(exp, sz) { \
  85.             static char szMsg[] = sz; \
  86.             (exp) ? (void) 0 : AssertSzFail(szMsg, szAssertFilename, __LINE__); \
  87.         }
  88.  
  89.     #define Assert(exp) \
  90.         ( (exp) ? (void) 0 : AssertFail(szAssertFilename, __LINE__) )
  91.  
  92. #ifndef Verify
  93.     #define Verify(exp)        Assert(exp)
  94. #endif
  95.         
  96.     #define ExpAssert(exp)        Assert(exp)
  97.  
  98.     #define AssertEq(exp, exp2)    Assert((exp) == (exp2))
  99.     #define AssertGe(exp, exp2)    Assert((exp) >= (exp2))
  100.     #define AssertNe(exp, exp2)    Assert((exp) != (exp2))
  101.  
  102.  
  103. #endif    //!def _DEBUG
  104.  
  105.  
  106. #pragma option pop /*P_O_Pop*/
  107. #endif //__UTAssert_H__
  108.