zassert.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Asserts
  4. //
  5. //////////////////////////////////////////////////////////////////////////////
  6. #ifndef _assert_h_
  7. #define _assert_h_
  8. #include "crtdbg.h"
  9. //////////////////////////////////////////////////////////////////////////////
  10. //
  11. // Make sure we didn't include some other assert mechanism
  12. //
  13. //////////////////////////////////////////////////////////////////////////////
  14. #ifdef assert
  15. #error Don't use assert.h, zlib provides assert functionality.
  16. #endif
  17. //////////////////////////////////////////////////////////////////////////////
  18. //
  19. // Asserts
  20. //
  21. //////////////////////////////////////////////////////////////////////////////
  22. void ZAssertImpl(bool bSucceeded, const char* psz, const char* pszFile, int line, const char* pszModule);
  23. #define ZRetailAssert(bCond) ZAssertImpl((bCond) ? true : false, #bCond, __FILE__, __LINE__, __MODULE__)
  24. void retailf(const char* , ...);
  25. extern bool g_bOutput;
  26. #ifdef _DEBUG
  27. //
  28. // These are implemented in Win32app.cpp
  29. //
  30. inline void ZDebugBreak() { DebugBreak(); }
  31. void debugf(const char* , ...);
  32. void ZWarningImpl(bool bSucceeded, const char* psz, const char* pszFile, int line, const char* pszModule);
  33. bool ZFailedImpl(HRESULT hr, const char* pszFile, int line, const char* pszModule);
  34. bool ZSucceededImpl(HRESULT hr, const char* pszFile, int line, const char* pszModule);
  35. void ZDebugOutputImpl(const char* psz);
  36. #define ZAssert(bCond) ZAssertImpl((bCond) ? true : false, #bCond, __FILE__, __LINE__, __MODULE__)
  37. #define ZVerify(bCond) ZAssert(bCond)
  38. #define ZWarning(bCond) ZWarningImpl((bCond) ? true : false, #bCond, __FILE__, __LINE__, __MODULE__)
  39. #define ZError(psz) ZAssertImpl(false, psz, __FILE__, __LINE__, __MODULE__)
  40. #define ZBadCase() ZError("Bad case in switch statement"); break;
  41. #define ZFailed(hr) ZFailedImpl(hr, __FILE__, __LINE__, __MODULE__)
  42. #define ZSucceeded(hr) ZSucceededImpl(hr, __FILE__, __LINE__, __MODULE__)
  43. #define ZDebugOutput(str) ZDebugOutputImpl(str)
  44. #else
  45. inline void debugf(...) {}
  46. #define ZDebugBreak()
  47. #define ZAssert(bCond)
  48. #define ZWarning(str)
  49. #define ZVerify(bCond) (bCond)
  50. #define ZError(str)
  51. #define ZBadCase() break;
  52. #define ZFailed(hr) FAILED(hr)
  53. #define ZSucceeded(hr) SUCCEEDED(hr)
  54. #define ZDebugOutput(str)
  55. #endif
  56. #define ZUnimplemented() ZError("Unimplemented member called")
  57. #define assert(exp) ZAssert(exp)
  58. #define ShouldBe(exp) ZWarning(exp)
  59. #define VerifyHR(exp) ZSucceeded(exp)
  60. #define BreakOnError(expr) if (ZFailed(expr)) break;
  61. //////////////////////////////////////////////////////////////////////////////
  62. //
  63. // Tracing
  64. //
  65. //////////////////////////////////////////////////////////////////////////////
  66. #if (defined(_TRACE) && defined(_DEBUG))
  67. void ZEnterImpl(const char* pcc);
  68. void ZExitImpl(const char* pcc);
  69. void ZTraceImpl(const char* pcc);
  70. void ZStartTraceImpl(const char* pcc);
  71. #define ZEnter(str) ZEnterImpl(str)
  72. #define ZExit(str) ZExitImpl(str)
  73. #define ZTrace(str) ZTraceImpl(str)
  74. #define ZStartTrace(str) ZStartTraceImpl(str)
  75. #else
  76. #define ZEnter(str)
  77. #define ZExit(str)
  78. #define ZTrace(str)
  79. #define ZStartTrace(str)
  80. #endif
  81. #endif