00001
00002
00003
00004
00005
00006 #ifndef UT_ASSERT_H_INCLUDED
00007 #define UT_ASSERT_H_INCLUDED
00008
00009 #include "UT_API.h"
00010 #define UT_ASSERT_LEVEL_NONE 0
00011 #define UT_ASSERT_LEVEL_NORMAL 1
00012 #define UT_ASSERT_LEVEL_PARANOID 2
00013 #define UT_ASSERT_LEVEL_SLOW 3
00014
00015 #ifndef UT_ASSERT_LEVEL
00016 #define UT_ASSERT_LEVEL UT_ASSERT_LEVEL_NONE
00017 #endif
00018
00019
00020 UT_API void UT_Assert( const char *file, int linenum, const char *function,
00021 const char *condition, const char *reason, int &ignoreflag);
00022
00023
00024
00025 UT_API void UTdisableInteractiveAssertsOn();
00026 UT_API void UTdisableInteractiveAssertsOff();
00027
00028 #if defined(__GNUC__)
00029 # define UT_ASSERT_FUNC __PRETTY_FUNCTION__
00030 #elif defined(_MSC_VER) || defined(__FUNCTION__)
00031 # define UT_ASSERT_FUNC __FUNCTION__ "()"
00032 #else
00033 # define UT_ASSERT_FUNC ((char *)0)
00034 #endif
00035
00036 #if (UT_ASSERT_LEVEL > UT_ASSERT_LEVEL_NONE)
00037 #ifdef UT_INTERNAL_ASSERT
00038 #error UT_INTERNAL_UT_ASSERT is already defined!
00039 #endif
00040 #define UT_INTERNAL_ASSERT(ZZ, MM) \
00041 do { \
00042 static int ignore = 0; \
00043 if( !ignore && !(ZZ) ) \
00044 UT_Assert( __FILE__, __LINE__, UT_ASSERT_FUNC, #ZZ, MM, \
00045 ignore); \
00046 } while (false)
00047 #endif
00048
00049 #ifdef UT_ASSERT_P
00050 #error UT_ASSERT_P is already defined!
00051 #endif
00052 #ifdef UT_ASSERT_SLOW
00053 #error UT_ASSERT_SLOW is already defined!
00054 #endif
00055 #ifdef UT_ASSERT
00056 #error UT_ASSERT is already defined!
00057 #endif
00058
00059
00060 #if (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_SLOW)
00061 #define UT_ASSERT_SLOW(ZZ) UT_INTERNAL_ASSERT(ZZ, 0)
00062 #define UT_ASSERT_P(ZZ) UT_INTERNAL_ASSERT(ZZ, 0)
00063 #define UT_ASSERT(ZZ) UT_INTERNAL_ASSERT(ZZ, 0)
00064 #define UT_ASSERT_MSG_SLOW(ZZ, MM) UT_INTERNAL_ASSERT(ZZ, MM)
00065 #define UT_ASSERT_MSG_P(ZZ, MM) UT_INTERNAL_ASSERT(ZZ, MM)
00066 #define UT_ASSERT_MSG(ZZ, MM) UT_INTERNAL_ASSERT(ZZ, MM)
00067 #elif (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_PARANOID)
00068 #define UT_ASSERT_SLOW(ZZ) ((void)0)
00069 #define UT_ASSERT_P(ZZ) UT_INTERNAL_ASSERT(ZZ, 0)
00070 #define UT_ASSERT(ZZ) UT_INTERNAL_ASSERT(ZZ, 0)
00071 #define UT_ASSERT_MSG_SLOW(ZZ, MM) ((void)0)
00072 #define UT_ASSERT_MSG_P(ZZ, MM) UT_INTERNAL_ASSERT(ZZ, MM)
00073 #define UT_ASSERT_MSG(ZZ, MM) UT_INTERNAL_ASSERT(ZZ, MM)
00074 #elif (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_NORMAL)
00075 #define UT_ASSERT_SLOW(ZZ) ((void)0)
00076 #define UT_ASSERT_P(ZZ) ((void)0)
00077 #define UT_ASSERT(ZZ) UT_INTERNAL_ASSERT(ZZ, 0)
00078 #define UT_ASSERT_MSG_SLOW(ZZ, MM) ((void)0)
00079 #define UT_ASSERT_MSG_P(ZZ, MM) ((void)0)
00080 #define UT_ASSERT_MSG(ZZ, MM) UT_INTERNAL_ASSERT(ZZ, MM)
00081 #else // if (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_NONE)
00082 #define UT_ASSERT_SLOW(ZZ) ((void)0)
00083 #define UT_ASSERT_P(ZZ) ((void)0)
00084 #define UT_ASSERT(ZZ) ((void)0)
00085 #define UT_ASSERT_MSG_SLOW(ZZ, MM) ((void)0)
00086 #define UT_ASSERT_MSG_P(ZZ, MM) ((void)0)
00087 #define UT_ASSERT_MSG(ZZ, MM) ((void)0)
00088 #endif
00089
00090
00091 #if defined(IRIX6)
00092 #define UT_ASSERT_COMPILETIME(expr)
00093 #else
00094 template<bool> struct CompileTimeError;
00095 template<> struct CompileTimeError<true> {};
00096 #define UT_ASSERT_COMPILETIME(expr) \
00097 CompileTimeError<(expr) != 0>()
00098 #endif
00099
00100
00101
00102
00103
00104
00105 #if UT_ASSERT_LEVEL >= 1
00106 #define UT_IF_ASSERT(ZZ) ZZ
00107 #define UT_IFNOT_ASSERT(ZZ)
00108 #else
00109 #define UT_IF_ASSERT(ZZ)
00110 #define UT_IFNOT_ASSERT(ZZ) ZZ
00111 #endif
00112
00113
00114
00115 #if UT_ASSERT_LEVEL >= 1
00116 #define UT_VERIFY(expr) UT_ASSERT(expr)
00117 #else
00118 #define UT_VERIFY(expr) ((void)(expr))
00119 #endif
00120
00121 enum UT_AssertResponse
00122 {
00123 UT_ASSERT_RESPONSE_DEBUG,
00124 UT_ASSERT_RESPONSE_IGNORE,
00125 UT_ASSERT_RESPONSE_IGNORE_ALL,
00126 UT_ASSERT_RESPONSE_TRACE,
00127 UT_ASSERT_RESPONSE_ERROR
00128 };
00129
00130 #endif // UT_ASSERT_H_INCLUDED