00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef MOCKPP_ASSERT_H
00031 #define MOCKPP_ASSERT_H
00032
00033 #include <mockpp/mockpp.h>
00034
00035 #include <mockpp/compat/AssertionFailedError.h>
00036
00037
00038 MOCKPP_NS_START
00039
00040
00049 MOCKPP_API_DECL(void) assertTrue(unsigned srcline, const char* srcfile,
00050 const String &message, bool condition);
00051
00059 MOCKPP_API_DECL(void) assertTrue(unsigned srcline, const char* srcfile,
00060 bool condition);
00061
00070 MOCKPP_API_DECL(void) assertFalse(unsigned srcline, const char* srcfile,
00071 const String &message, bool condition);
00072
00080 MOCKPP_API_DECL(void) assertFalse(unsigned srcline, const char* srcfile,
00081 bool condition);
00082
00089 MOCKPP_API_DECL(void) fail(unsigned srcline, const char* srcfile,
00090 const String &message);
00091
00097 MOCKPP_API_DECL(void) fail(unsigned srcline, const char* srcfile);
00098
00110 MOCKPP_API_DECL(void) assertDelta(unsigned srcline, const char* srcfile,
00111 const String &message,
00112 double expected, double actual, double delta);
00113
00123 MOCKPP_API_DECL(void) assertDelta(unsigned srcline, const char* srcfile,
00124 double expected, double actual, double delta);
00125
00137 MOCKPP_API_DECL(void) assertDelta(unsigned srcline, const char* srcfile,
00138 const String &message,
00139 float expected, float actual, float delta);
00140
00141
00151 MOCKPP_API_DECL(void) assertDelta(unsigned srcline, const char* srcfile,
00152 float expected, float actual, float delta);
00153
00163 MOCKPP_API_DECL(void) assertEquals(unsigned srcline, const char* srcfile,
00164 const String &message,
00165 const char *expected, const char *actual);
00166
00174 MOCKPP_API_DECL(void) assertEquals(unsigned srcline, const char* srcfile,
00175 const char *expected, const char *actual);
00176
00177 #ifdef MOCKPP_UNICODE
00178
00188 MOCKPP_API_DECL(void)
00189 assertEquals(unsigned srcline, const char* srcfile,
00190 const String &message,
00191 const wchar_t *expected, const wchar_t *actual);
00192
00200 MOCKPP_API_DECL(void)
00201 assertEquals(unsigned srcline, const char* srcfile,
00202 const wchar_t *expected, const wchar_t *actual);
00203
00204 #endif
00205
00214 template <class T>
00215 void assertEquals(unsigned srcline, const char* srcfile,
00216 const String &message, const T &expected, const T &actual)
00217 {
00218 if (expected != actual)
00219 fail(srcline, srcfile, message);
00220 }
00221
00222
00230 template <class T>
00231 void assertEquals(unsigned srcline, const char* srcfile,
00232 const T &expected, const T &actual)
00233 {
00234 assertEquals(srcline, srcfile, MOCKPP_PCHAR(""), expected, actual);
00235 }
00236
00237
00248 template <class T>
00249 void assertDelta(unsigned srcline, const char* srcfile,
00250 const String &message,
00251 const T &expected, const T &actual, const T &delta)
00252 {
00253 T diff = expected < actual
00254 ? actual - expected
00255 : expected - actual;
00256 if (diff > delta)
00257 fail(srcline, srcfile, message);
00258 }
00259
00260
00269 template <class T>
00270 void assertDelta(unsigned srcline, const char* srcfile,
00271 const T &expected, const T &actual, const T &delta)
00272 {
00273 assertDelta(srcline, srcfile, MOCKPP_PCHAR(""), expected, actual, delta);
00274 }
00275
00276
00286 template <class T>
00287 void assertBoundary(unsigned srcline, const char* srcfile,
00288 const String &message,
00289 const T &lo, const T &up, const T &actual)
00290 {
00291 if ((actual < lo) || (up < actual))
00292 fail(srcline, srcfile, message);
00293 }
00294
00295
00304 template <class T>
00305 void assertBoundary(unsigned srcline, const char* srcfile,
00306 const T &lo, const T &up, const T &actual)
00307 {
00308 assertBoundary(srcline, srcfile, MOCKPP_PCHAR(""), lo, up, actual);
00309 }
00310
00311
00312 MOCKPP_NS_END
00313
00314
00321 #define MOCKPP_ASSERT_EQUALS_MESSAGE(msg, a, b) MOCKPP_NS::assertEquals(__LINE__, __FILE__, msg, a, b)
00322
00331 #define MOCKPP_ASSERT_EQUALS(a, b) MOCKPP_NS::assertEquals(__LINE__, __FILE__, MOCKPP_PCHAR("invalid: ") \
00332 MOCKPP_PCHAR(#a) MOCKPP_PCHAR(" == ") MOCKPP_PCHAR(#b), a, b)
00333
00341 #define MOCKPP_ASSERT_DELTA_MESSAGE(msg, a, b, delta) MOCKPP_NS::assertDelta(__LINE__, __FILE__, msg, a, b, delta)
00342
00352 # define MOCKPP_ASSERT_DELTA(a, b, delta) MOCKPP_NS::assertDelta(__LINE__, __FILE__, MOCKPP_PCHAR("invalid: ") \
00353 MOCKPP_PCHAR(#a) MOCKPP_PCHAR(" +- ") MOCKPP_PCHAR(#delta) \
00354 MOCKPP_PCHAR(" == ") MOCKPP_PCHAR(#b), a, b, delta)
00355
00363 #define MOCKPP_ASSERT_BOUNDARY_MESSAGE(msg, lo, up, a) MOCKPP_NS::assertBoundary(__LINE__, __FILE__, msg, lo, up, a)
00364
00374 # define MOCKPP_ASSERT_BOUNDARY(lo, up, a) MOCKPP_NS::assertBoundary(__LINE__, __FILE__, MOCKPP_PCHAR("invalid: ") \
00375 MOCKPP_PCHAR(#lo) MOCKPP_PCHAR(" < ") MOCKPP_PCHAR(#a) \
00376 MOCKPP_PCHAR(" < ") MOCKPP_PCHAR(#up), lo, up, a)
00377
00383 #define MOCKPP_ASSERT_TRUE_MESSAGE(msg, cond) MOCKPP_NS::assertTrue(__LINE__, __FILE__, msg, cond)
00384
00392 # define MOCKPP_ASSERT_TRUE(cond) MOCKPP_NS::assertTrue(__LINE__, __FILE__, MOCKPP_PCHAR("!true: ") MOCKPP_PCHAR(#cond), cond)
00393
00399 #define MOCKPP_ASSERT_FALSE_MESSAGE(msg, cond) MOCKPP_NS::assertFalse(__LINE__, __FILE__, msg, cond)
00400
00408 # define MOCKPP_ASSERT_FALSE(cond) MOCKPP_NS::assertFalse(__LINE__, __FILE__, MOCKPP_PCHAR("!false: ") MOCKPP_PCHAR(#cond), cond)
00409
00414 #define MOCKPP_FAIL(msg) MOCKPP_NS::fail(__LINE__, __FILE__, msg)
00415
00416
00417 #endif // MOCKPP_ASSERT_H
00418