00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00029 #ifndef CPPTEST_ASSERT_H
00030 #define CPPTEST_ASSERT_H
00031
00056 #define TEST_FAIL(msg) \
00057 { \
00058 assertment(::Test::Source(__FILE__, __LINE__, (msg) != 0 ? #msg : "")); \
00059 if (!continue_after_failure()) return; \
00060 }
00061
00084 #define TEST_ASSERT(expr) \
00085 { \
00086 if (!(expr)) \
00087 { \
00088 assertment(::Test::Source(__FILE__, __LINE__, #expr)); \
00089 if (!continue_after_failure()) return; \
00090 } \
00091 }
00092
00104 #define TEST_ASSERT_MSG(expr, msg) \
00105 { \
00106 if (!(expr)) \
00107 { \
00108 assertment(::Test::Source(__FILE__, __LINE__, msg)); \
00109 if (!continue_after_failure()) return; \
00110 } \
00111 }
00112
00126 #define TEST_ASSERT_DELTA(a, b, delta) \
00127 { \
00128 if (((b) < (a) - (delta)) || ((b) > (a) + (delta))) \
00129 { \
00130 assertment(::Test::Source(__FILE__, __LINE__, \
00131 "delta(" #a ", " #b ", " #delta ")" )); \
00132 if (!continue_after_failure()) return; \
00133 } \
00134 }
00135
00150 #define TEST_ASSERT_DELTA_MSG(a, b, delta, msg) \
00151 { \
00152 if (((b) < (a) - (delta)) || ((b) > (a) + (delta))) \
00153 { \
00154 assertment(::Test::Source(__FILE__, __LINE__, msg)); \
00155 if (!continue_after_failure()) return; \
00156 } \
00157 }
00158
00171 #define TEST_THROWS(expr, x) \
00172 { \
00173 bool __expected = false; \
00174 try { expr; } \
00175 catch (x) { __expected = true; } \
00176 catch (...) {} \
00177 if (!__expected) \
00178 { \
00179 assertment(::Test::Source(__FILE__, __LINE__, #expr)); \
00180 if (!continue_after_failure()) return; \
00181 } \
00182 }
00183
00197 #define TEST_THROWS_MSG(expr, x, msg) \
00198 { \
00199 bool __expected = false; \
00200 try { expr; } \
00201 catch (x) { __expected = true; } \
00202 catch (...) {} \
00203 if (!__expected) \
00204 { \
00205 assertment(::Test::Source(__FILE__, __LINE__, msg)); \
00206 if (!continue_after_failure()) return; \
00207 } \
00208 }
00209
00221 #define TEST_THROWS_ANYTHING(expr) \
00222 { \
00223 bool __expected = false; \
00224 try { expr; } \
00225 catch (...) { __expected = true; } \
00226 if (!__expected) \
00227 { \
00228 assertment(::Test::Source(__FILE__, __LINE__, #expr)); \
00229 if (!continue_after_failure()) return; \
00230 } \
00231 }
00232
00245 #define TEST_THROWS_ANYTHING_MSG(expr, msg) \
00246 { \
00247 bool __expected = false; \
00248 try { expr; } \
00249 catch (...) { __expected = true; } \
00250 if (!__expected) \
00251 { \
00252 assertment(::Test::Source(__FILE__, __LINE__, msg)); \
00253 if (!continue_after_failure()) return; \
00254 } \
00255 }
00256
00268 #define TEST_THROWS_NOTHING(expr) \
00269 { \
00270 bool __expected = true; \
00271 try { expr; } \
00272 catch (...) { __expected = false; } \
00273 if (!__expected) \
00274 { \
00275 assertment(::Test::Source(__FILE__, __LINE__, #expr)); \
00276 if (!continue_after_failure()) return; \
00277 } \
00278 }
00279
00292 #define TEST_THROWS_NOTHING_MSG(expr, msg) \
00293 { \
00294 bool __expected = true; \
00295 try { expr; } \
00296 catch (...) { __expected = false; } \
00297 if (!__expected) \
00298 { \
00299 assertment(::Test::Source(__FILE__, __LINE__, msg)); \
00300 if (!continue_after_failure()) return; \
00301 } \
00302 }
00303
00329
00330 #endif // #ifndef CPPTEST_ASSERT_H
00331