home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / utassert.h < prev    next >
C/C++ Source or Header  |  1998-04-25  |  3KB  |  106 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. #define __UTAssert_H__
  28.  
  29. #include <stdio.h>
  30.  
  31. typedef unsigned short    WORD;
  32. typedef unsigned long    DWORD;
  33.  
  34.  
  35. #ifndef    _DEBUG
  36.  
  37.     #define DeclAssertFile
  38.     #define Assert(exp)        ((void)1)
  39. #ifndef Verify
  40.     #define Verify(exp)        (exp)
  41. #endif
  42.     #define ExpAssert(exp)        ((void)1)
  43.     #define AssertSz(exp, sz)    ((void)1)
  44.     #define AssertEq(exp, exp2)    (exp)
  45.     #define AssertGe(exp, exp2)    (exp)
  46.     #define AssertNe(exp, exp2)    (exp)
  47.  
  48. #else    //Debug
  49.  
  50.     #define DTCAssertNone    0x0000        /* None */
  51.     #define DTCAssertExit    0x0001        /* Exit the application */
  52.     #define DTCAssertBreak     0x0002        /* Break to debugger */
  53.     #define DTCAssertMsgBox    0x0004        /* Display message box */
  54.     #define DTCAssertStop    0x0008        /* Alert and stop */
  55.     #define DTCAssertStack    0x0010        /* Stack trace */
  56.     #define DTCAssertLog    0x0020        /* Log assert to file only */
  57.  
  58.     #ifdef __cplusplus
  59.     extern "C" {
  60.     #endif
  61.  
  62.     void AssertSzFail(const char *sz, const char *szFilename, unsigned Line);
  63.     void AssertFail(const char  *szFilename, unsigned Line);
  64.  
  65.     static WORD z_wAssertAction = DTCAssertNone; // default to None
  66.  
  67.     static const char szAssertFile[] = "assert.txt";
  68.     static const char szAssertHdr[] = "Assertion Failure: ";
  69.     static const char szMsgHdr[] = ": ";
  70.     static const char szLineHdr[] = ", Line ";
  71.     static const char szAssertEnd[] = "\r\n";
  72.     static const char szAssertCaption[] = "Assertion Failure";
  73.     
  74.     #ifdef __cplusplus
  75.     }
  76.     #endif
  77.  
  78.  
  79.  
  80.     #define DeclAssertFile static const char szAssertFilename[] = __FILE__
  81.  
  82.  
  83.     #define AssertSz(exp, sz) { \
  84.             static char szMsg[] = sz; \
  85.             (exp) ? (void) 0 : AssertSzFail(szMsg, szAssertFilename, __LINE__); \
  86.         }
  87.  
  88.     #define Assert(exp) \
  89.         ( (exp) ? (void) 0 : AssertFail(szAssertFilename, __LINE__) )
  90.  
  91. #ifndef Verify
  92.     #define Verify(exp)        Assert(exp)
  93. #endif
  94.         
  95.     #define ExpAssert(exp)        Assert(exp)
  96.  
  97.     #define AssertEq(exp, exp2)    Assert((exp) == (exp2))
  98.     #define AssertGe(exp, exp2)    Assert((exp) >= (exp2))
  99.     #define AssertNe(exp, exp2)    Assert((exp) != (exp2))
  100.  
  101.  
  102. #endif    //!def _DEBUG
  103.  
  104.  
  105. #endif //__UTAssert_H__
  106.