6 #ifndef UT_ASSERT_H_INCLUDED
7 #define UT_ASSERT_H_INCLUDED
11 #define UT_ASSERT_LEVEL_NONE 0
12 #define UT_ASSERT_LEVEL_NORMAL 1
13 #define UT_ASSERT_LEVEL_PARANOID 2
14 #define UT_ASSERT_LEVEL_SLOW 3
16 #ifndef UT_ASSERT_LEVEL
17 #define UT_ASSERT_LEVEL UT_ASSERT_LEVEL_NONE
21 UT_API void UT_Assert(
const char *file,
int linenum,
const char *
function,
22 const char *
condition,
const char *reason,
int &ignoreflag);
26 const char *
function,
const char *
condition,
int &ignoreflag,
27 const char *reason_fmt...);
57 const char *
what()
const noexcept {
return myWhat; }
65 # define UT_ASSERT_FUNC __PRETTY_FUNCTION__
66 #elif defined(_MSC_VER)
67 # define UT_ASSERT_FUNC __FUNCSIG__
68 #elif defined(__FUNCTION__)
69 # define UT_ASSERT_FUNC __FUNCTION__ "()"
71 # define UT_ASSERT_FUNC ((char *)0)
74 #if (UT_ASSERT_LEVEL > UT_ASSERT_LEVEL_NONE)
75 #ifdef UT_INTERNAL_ASSERT
76 #error UT_INTERNAL_UT_ASSERT is already defined!
78 #define UT_INTERNAL_ASSERT(ZZ, ...) \
80 static int ignore = 0; \
81 if( !ignore && !(ZZ) ) \
82 UT_AssertFormat( __FILE__, __LINE__, UT_ASSERT_FUNC, \
83 #ZZ, ignore, __VA_ARGS__); \
85 #define UT_INTERNAL_VERIFY(ZZ, ...) \
87 static int ignore = 0; \
89 if( !(ZZ) && !ignore ) \
90 UT_AssertFormat( __FILE__, __LINE__, UT_ASSERT_FUNC, \
91 #ZZ, ignore, __VA_ARGS__); \
94 #define UT_INTERNAL_VERIFY_RETURN(ZZ, RV) \
97 static int ignore = 0; \
99 UT_Assert( __FILE__, __LINE__, UT_ASSERT_FUNC, #ZZ, 0, \
103 #define UT_INTERNAL_ASSERT_EXPR(ZZ,MM) \
106 static int ignore = 0; \
108 UT_Assert( __FILE__, __LINE__, UT_ASSERT_FUNC, #ZZ, MM, \
113 #ifdef UT_ASSERT_EXPR_P
114 #error UT_ASSERT_EXPR_P is already defined!
116 #ifdef UT_ASSERT_EXPR
117 #error UT_ASSERT_EXPR is already defined!
119 #ifdef UT_ASSERT_SLOW
120 #error UT_ASSERT_SLOW is already defined!
123 #error UT_ASSERT_P is already defined!
126 #error UT_ASSERT is already defined!
128 #ifdef UT_ASSERT_MSG_SLOW
129 #error UT_ASSERT_MSG_SLOW is already defined!
131 #ifdef UT_ASSERT_MSG_P
132 #error UT_ASSERT_MSG_P is already defined!
135 #error UT_ASSERT_MSG is already defined!
139 #if (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_SLOW)
140 #define UT_ASSERT_EXPR_P(ZZ) UT_INTERNAL_ASSERT_EXPR(ZZ, 0)
141 #define UT_ASSERT_EXPR(ZZ) UT_INTERNAL_ASSERT_EXPR(ZZ, 0)
142 #define UT_ASSERT_SLOW(ZZ) UT_INTERNAL_ASSERT(ZZ, 0)
143 #define UT_ASSERT_P(ZZ) UT_INTERNAL_ASSERT(ZZ, 0)
144 #define UT_ASSERT(ZZ) UT_INTERNAL_ASSERT(ZZ, 0)
145 #define UT_ASSERT_MSG_SLOW(ZZ, ...) UT_INTERNAL_ASSERT(ZZ, __VA_ARGS__)
146 #define UT_ASSERT_MSG_P(ZZ, ...) UT_INTERNAL_ASSERT(ZZ, __VA_ARGS__)
147 #define UT_ASSERT_MSG(ZZ, ...) UT_INTERNAL_ASSERT(ZZ, __VA_ARGS__)
148 #elif (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_PARANOID)
149 #define UT_ASSERT_EXPR_P(ZZ) UT_INTERNAL_ASSERT_EXPR(ZZ, 0)
150 #define UT_ASSERT_EXPR(ZZ) UT_INTERNAL_ASSERT_EXPR(ZZ, 0)
151 #define UT_ASSERT_SLOW(ZZ) ((void)0)
152 #define UT_ASSERT_P(ZZ) UT_INTERNAL_ASSERT(ZZ, 0)
153 #define UT_ASSERT(ZZ) UT_INTERNAL_ASSERT(ZZ, 0)
154 #define UT_ASSERT_MSG_SLOW(ZZ, ...) ((void)0)
155 #define UT_ASSERT_MSG_P(ZZ, ...) UT_INTERNAL_ASSERT(ZZ, __VA_ARGS__)
156 #define UT_ASSERT_MSG(ZZ, ...) UT_INTERNAL_ASSERT(ZZ, __VA_ARGS__)
157 #elif (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_NORMAL)
158 #define UT_ASSERT_EXPR_P(ZZ) ((void)0)
159 #define UT_ASSERT_EXPR(ZZ) UT_INTERNAL_ASSERT_EXPR(ZZ, 0)
160 #define UT_ASSERT_SLOW(ZZ) ((void)0)
161 #define UT_ASSERT_P(ZZ) ((void)0)
162 #define UT_ASSERT(ZZ) UT_INTERNAL_ASSERT(ZZ, 0)
163 #define UT_ASSERT_MSG_SLOW(ZZ, ...) ((void)0)
164 #define UT_ASSERT_MSG_P(ZZ, ...) ((void)0)
165 #define UT_ASSERT_MSG(ZZ, ...) UT_INTERNAL_ASSERT(ZZ, __VA_ARGS__)
166 #else // if (UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_NONE)
167 #define UT_ASSERT_EXPR_P(ZZ) ((void)0)
168 #define UT_ASSERT_EXPR(ZZ) ((void)0)
169 #define UT_ASSERT_SLOW(ZZ) ((void)0)
170 #define UT_ASSERT_P(ZZ) ((void)0)
171 #define UT_ASSERT(ZZ) ((void)0)
172 #define UT_ASSERT_MSG_SLOW(ZZ, ...) ((void)0)
173 #define UT_ASSERT_MSG_P(ZZ, ...) ((void)0)
174 #define UT_ASSERT_MSG(ZZ, ...) ((void)0)
178 #define UT_ASSERT_COMPILETIME(expr) SYS_STATIC_ASSERT(expr)
185 #if UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_NORMAL
186 #define UT_IF_ASSERT(ZZ) ZZ
187 #define UT_IFNOT_ASSERT(ZZ)
189 #define UT_IF_ASSERT(ZZ)
190 #define UT_IFNOT_ASSERT(ZZ) ZZ
193 #if UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_PARANOID
194 #define UT_IF_ASSERT_P(ZZ) ZZ
195 #define UT_IFNOT_ASSERT_P(ZZ)
197 #define UT_IF_ASSERT_P(ZZ)
198 #define UT_IFNOT_ASSERT_P(ZZ) ZZ
201 #if UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_SLOW
202 #define UT_IF_ASSERT_SLOW(ZZ) ZZ
203 #define UT_IFNOT_ASSERT_SLOW(ZZ)
205 #define UT_IF_ASSERT_SLOW(ZZ)
206 #define UT_IFNOT_ASSERT_SLOW(ZZ) ZZ
211 #if UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_NORMAL
212 #define UT_VERIFY(expr) UT_INTERNAL_VERIFY(expr, 0)
213 #define UT_VERIFY_MSG(expr, ...) UT_INTERNAL_VERIFY(expr, __VA_ARGS__)
214 #define UT_VERIFY_RETURN(ZZ, RV) UT_INTERNAL_VERIFY_RETURN(ZZ, RV)
215 #define UT_VERIFY_RETURN_VOID(ZZ) UT_INTERNAL_VERIFY_RETURN(ZZ,)
217 #define UT_VERIFY(expr) ((void)(expr))
218 #define UT_VERIFY_MSG(expr, ...) ((void)(expr))
219 #define UT_VERIFY_RETURN(ZZ, RV) if (!(ZZ)) { return RV; }
220 #define UT_VERIFY_RETURN_VOID(ZZ) if (!(ZZ)) { return; }
222 #if UT_ASSERT_LEVEL >= UT_ASSERT_LEVEL_PARANOID
223 #define UT_VERIFY_P(expr) UT_INTERNAL_VERIFY(expr, 0)
225 #define UT_VERIFY_P(expr) ((void)(expr))
242 template <
typename TO_T,
typename FROM_T>
246 UT_ASSERT_P(dynamic_cast<TO_T>(from) == from &&
"Invalid static cast");
247 return static_cast<TO_T
>(from);
255 #endif // UT_ASSERT_H_INCLUDED
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
UT_API void UTsubclassResponsibility(const char *classname, const char *member)
UT_API void UTdisableInteractiveAssertsOff()
const char * what() const noexcept
UT_API void UT_Assert(const char *file, int linenum, const char *function, const char *condition, const char *reason, int &ignoreflag)
UT_API void UT_AssertFormat(const char *file, int linenum, const char *function, const char *condition, int &ignoreflag, const char *reason_fmt...)
UT_API void UTdisableInteractiveAssertsOn()