00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #define MOCKPP_NEED_EXPORTS
00031 #include <mockpp/mockpp.h>
00032
00033 #include <cmath>
00034 #include <cstring>
00035
00036 #ifdef HAVE_CWCHAR
00037 #include <cwchar>
00038 #endif
00039
00040
00041
00042 #if !defined(HAVE_WCSCMP) && defined(MOCKPP_UNICODE)
00043
00044 namespace {
00045
00046
00047
00048
00049 static int
00050 wcscmp (const wchar_t *s1, const wchar_t *s2)
00051 {
00052 wchar_t c1, c2;
00053
00054 do
00055 {
00056 c1 = *s1++;
00057 c2 = *s2++;
00058 if (c1 == L'\0')
00059 return c1 - c2;
00060 }
00061 while (c1 == c2);
00062
00063 return c1 - c2;
00064 }
00065
00066 }
00067
00068 #endif // HAVE_WCSCMP
00069
00070
00071 #include <mockpp/compat/Asserter.h>
00072
00073
00074 MOCKPP_NS_START
00075
00076
00077 MOCKPP_API_IMPL(void) assertTrue(unsigned srcline, const char* srcfile,
00078 const String &message, bool condition)
00079 {
00080 if (!condition)
00081 fail(srcline, srcfile, message);
00082 }
00083
00084
00085 MOCKPP_API_IMPL(void) assertTrue(unsigned srcline, const char* srcfile,
00086 bool condition)
00087 {
00088 assertTrue(srcline, srcfile, MOCKPP_PCHAR(""), condition);
00089 }
00090
00091
00092 MOCKPP_API_IMPL(void) assertFalse(unsigned srcline, const char* srcfile,
00093 const String &message, bool condition)
00094 {
00095 assertTrue(srcline, srcfile, message, !condition);
00096 }
00097
00098
00099 MOCKPP_API_IMPL(void) assertFalse(unsigned srcline, const char* srcfile,
00100 bool condition)
00101 {
00102 assertFalse(srcline, srcfile, MOCKPP_PCHAR(""), condition);
00103 }
00104
00105
00106 MOCKPP_API_IMPL(void) fail(unsigned srcline, const char* srcfile,
00107 const String &message)
00108 {
00109 assertionFailed(srcline, srcfile, message);
00110 }
00111
00112
00113 MOCKPP_API_IMPL(void) fail(unsigned srcline, const char* srcfile)
00114 {
00115 fail(srcline, srcfile, MOCKPP_PCHAR(""));
00116 }
00117
00118
00119 MOCKPP_API_IMPL(void) assertEquals(unsigned srcline, const char* srcfile,
00120 const char *expected, const char *actual)
00121 {
00122 assertEquals(srcline, srcfile, MOCKPP_PCHAR(""), expected, actual);
00123 }
00124
00125
00126 MOCKPP_API_IMPL(void) assertEquals(unsigned srcline, const char* srcfile,
00127 const String &message,
00128 const char *expected,
00129 const char *actual)
00130 {
00131 #if defined(_MSC_VER)
00132 if (strcmp(expected, actual) != 0)
00133 #else
00134 if (MOCKPP_STD_NS::strcmp(expected, actual) != 0)
00135 #endif
00136 fail(srcline, srcfile, message);
00137 }
00138
00139
00140 #ifdef MOCKPP_UNICODE
00141
00142 MOCKPP_API_IMPL(void) assertEquals(unsigned srcline, const char* srcfile,
00143 const wchar_t *expected, const wchar_t *actual)
00144 {
00145 assertEquals(srcline, srcfile, MOCKPP_PCHAR(""), expected, actual);
00146 }
00147
00148
00149 MOCKPP_API_IMPL(void) assertEquals(unsigned srcline, const char* srcfile,
00150 const String &message,
00151 const wchar_t *expected,
00152 const wchar_t *actual)
00153 {
00154 #if !defined(HAVE_STD_WCSCMP)
00155 if (wcscmp(expected, actual) != 0)
00156 #else
00157 if (MOCKPP_STD_NS::wcscmp(expected, actual) != 0)
00158 #endif
00159 fail(srcline, srcfile, message);
00160 }
00161
00162 #endif
00163
00164 MOCKPP_API_IMPL(void) assertDelta(unsigned srcline, const char* srcfile,
00165 const String &message,
00166 double expected, double actual, double delta)
00167 {
00168
00169
00170
00171
00172 #ifdef HAVE_LIMITS
00173 if (expected == MOCKPP_STD_NS::numeric_limits<double>::infinity())
00174 {
00175 if (!(expected == actual))
00176 fail(srcline, srcfile, message);
00177 }
00178 else
00179 #endif
00180 #if defined(_MSC_VER)
00181 if (!(fabs(expected-actual) <= fabs(delta)))
00182 #else
00183 if (!(MOCKPP_STD_NS::fabs(expected-actual) <= MOCKPP_STD_NS::fabs(delta)))
00184 #endif
00185 fail(srcline, srcfile, message);
00186 }
00187
00188
00189 MOCKPP_API_IMPL(void) assertDelta(unsigned srcline, const char* srcfile,
00190 double expected, double actual, double delta)
00191 {
00192 assertDelta(srcline, srcfile, MOCKPP_PCHAR(""), expected, actual, delta);
00193 }
00194
00195
00196 MOCKPP_API_IMPL(void) assertDelta(unsigned srcline, const char* srcfile,
00197 const String &message, float expected, float actual, float delta)
00198 {
00199
00200
00201
00202 #ifdef HAVE_LIMITS
00203 if (expected == MOCKPP_STD_NS::numeric_limits<float>::infinity())
00204 {
00205 if (!(expected == actual))
00206 fail(srcline, srcfile, message);
00207 }
00208 else
00209 #endif
00210
00211 #if defined(_MSC_VER)
00212 if (!(fabs(expected-actual) <= fabs(delta)))
00213 #else
00214 if (!(MOCKPP_STD_NS::fabs(expected-actual) <= MOCKPP_STD_NS::fabs(delta)))
00215 #endif
00216 fail(srcline, srcfile, message);
00217 }
00218
00219
00220 MOCKPP_API_IMPL(void) assertDelta(unsigned srcline, const char* srcfile,
00221 float expected, float actual, float delta)
00222 {
00223 assertDelta(srcline, srcfile, MOCKPP_PCHAR(""), expected, actual, delta);
00224 }
00225
00226
00227 MOCKPP_NS_END