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_ASSERTMO_H
00031 #define MOCKPP_ASSERTMO_H
00032
00033 #include <mockpp/mockpp.h>
00034
00035 #include <mockpp/compat/Asserter.h>
00036 #include <mockpp/compat/Formatter.h>
00037
00038
00039 MOCKPP_NS_START
00040
00041
00042 class Verifiable;
00043
00053 MOCKPP_API_DECL(void) assertExcludes(unsigned srcline, const char* srcfile,
00054 const String &description,
00055 const MOCKPP_STL::string &excludeString,
00056 const MOCKPP_STL::string &targetString);
00057
00058 #ifdef MOCKPP_UNICODE
00059
00069 MOCKPP_API_DECL(void) assertExcludes(unsigned srcline, const char* srcfile,
00070 const String &description,
00071 const MOCKPP_STL::basic_string<wchar_t> &excludeString,
00072 const MOCKPP_STL::basic_string<wchar_t> &targetString);
00073
00074 #endif
00075
00085 MOCKPP_API_DECL(void) assertIncludes(unsigned srcline, const char* srcfile,
00086 const String &description,
00087 const MOCKPP_STL::string &includeString,
00088 const MOCKPP_STL::string &targetString);
00089
00090 #ifdef MOCKPP_UNICODE
00091
00101 MOCKPP_API_DECL(void) assertIncludes(unsigned srcline, const char* srcfile,
00102 const String &description,
00103 const MOCKPP_STL::basic_string<wchar_t> &includeString,
00104 const MOCKPP_STL::basic_string<wchar_t> &targetString);
00105
00106 #endif
00107
00117 MOCKPP_API_DECL(void) assertStartsWith(unsigned srcline, const char* srcfile,
00118 const String &description,
00119 const MOCKPP_STL::string &startString,
00120 const MOCKPP_STL::string &targetString);
00121
00122 #ifdef MOCKPP_UNICODE
00123
00133 MOCKPP_API_DECL(void) assertStartsWith(unsigned srcline, const char* srcfile,
00134 const String &description,
00135 const MOCKPP_STL::basic_string<wchar_t> &startString,
00136 const MOCKPP_STL::basic_string<wchar_t> &targetString);
00137
00138 #endif
00139
00147 MOCKPP_API_DECL(void) assertVerifyFails(unsigned srcline, const char* srcfile,
00148 Verifiable *aVerifiable);
00149
00157 MOCKPP_API_DECL(void) notImplemented(unsigned srcline, const char* srcfile,
00158 const String &mockName);
00159
00160
00161 MOCKPP_NS_END
00162
00163
00171 #define MOCKPP_ASSERT_INCLUDES_MESSAGE(msg, a, b) MOCKPP_NS::assertIncludes(__LINE__, __FILE__, msg, a, b)
00172
00182 # define MOCKPP_ASSERT_INCLUDES(a, b) MOCKPP_NS::assertIncludes(__LINE__, __FILE__, MOCKPP_PCHAR(#a) MOCKPP_PCHAR(" <in> ") MOCKPP_PCHAR(#b), a, b)
00183
00191 #define MOCKPP_ASSERT_EXCLUDES_MESSAGE(msg, a, b) MOCKPP_NS::assertExcludes(__LINE__, __FILE__, msg, a, b)
00192
00202 #define MOCKPP_ASSERT_EXCLUDES(a, b) MOCKPP_NS::assertExcludes(__LINE__, __FILE__, MOCKPP_PCHAR(#a) MOCKPP_PCHAR(" <!in> ") MOCKPP_PCHAR(#b), a, b)
00203
00211 #define MOCKPP_ASSERT_STARTSWITH_MESSAGE(msg, a, b) MOCKPP_NS::assertStartsWith(__LINE__, __FILE__, msg, a, b)
00212
00222 #define MOCKPP_ASSERT_STARTSWITH(a, b) MOCKPP_NS::assertStartsWith(__LINE__, __FILE__, MOCKPP_PCHAR(#a) MOCKPP_PCHAR(" <starts> ") MOCKPP_PCHAR(#b), a, b)
00223
00229 #define MOCKPP_ASSERT_VERIFYFAILS(obj) MOCKPP_NS::assertVerifyFails(__LINE__, __FILE__, obj)
00230
00236 #define MOCKPP_NOT_IMPLEMENTED(msg) MOCKPP_NS::notImplemented(__LINE__, __FILE__, msg)
00237
00238
00253 #define MOCKPP_ASSERT_THROWING(action, action_name, except, except_data) \
00254 try \
00255 { \
00256 action; \
00257 MOCKPP_FAIL(MOCKPP_PCHAR("Did not throw the exception: ") + MOCKPP_STRING(action_name)); \
00258 } \
00259 catch(except &exception_object) \
00260 { \
00261 MOCKPP_ASSERT_TRUE(exception_object == except_data); \
00262 } \
00263 catch(MOCKPP_STD_NS::exception &ex) \
00264 { \
00265 MOCKPP_ASSERT_TRUE_MESSAGE(MOCKPP_GET_STRING(ex.what()), false); \
00266 } \
00267 catch(...) \
00268 { \
00269 MOCKPP_FAIL(MOCKPP_PCHAR("Caught unknown exception: ") + MOCKPP_STRING(action_name)); \
00270 }
00271
00287 #define MOCKPP_ASSERT_THROWING_COND(action, action_name, except, condition) \
00288 try \
00289 { \
00290 action; \
00291 MOCKPP_FAIL(MOCKPP_PCHAR("Did not throw the exception: ") + MOCKPP_STRING(action_name)); \
00292 } \
00293 catch(except &exception_object) \
00294 { \
00295 MOCKPP_ASSERT_TRUE(condition); \
00296 } \
00297 catch(MOCKPP_STD_NS::exception &ex) \
00298 { \
00299 MOCKPP_ASSERT_TRUE_MESSAGE(MOCKPP_GET_STRING(ex.what()), false); \
00300 } \
00301 catch(...) \
00302 { \
00303 MOCKPP_FAIL(MOCKPP_PCHAR("Caught unknown exception: ") + MOCKPP_STRING(action_name)); \
00304 }
00305
00306
00324 #define MOCKPP_ASSERT_THROWING_EQUALS(action, action_name, except, expected, actual) \
00325 try \
00326 { \
00327 action; \
00328 MOCKPP_FAIL(MOCKPP_PCHAR("Did not throw the exception: ") + MOCKPP_STRING(action_name)); \
00329 } \
00330 catch(except &exception_object) \
00331 { \
00332 MOCKPP_ASSERT_EQUALS(expected, actual); \
00333 } \
00334 catch(std::exception &ex) \
00335 { \
00336 MOCKPP_ASSERT_TRUE_MESSAGE(MOCKPP_GET_STRING(ex.what()), false); \
00337 } \
00338 catch(...) \
00339 { \
00340 MOCKPP_FAIL(MOCKPP_PCHAR("Caught unknown exception: ") + MOCKPP_STRING(action_name)); \
00341 }
00342
00343
00344 #endif // MOCKPP_ASSERTMO_H