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
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00058 #ifndef _CUNIT_CUNIT_H
00059 #define _CUNIT_CUNIT_H
00060
00061 #include <string.h>
00062 #include <math.h>
00063
00064 #include "CUError.h"
00065 #include "TestDB.h"
00066
00067 #ifdef __cplusplus
00068 extern "C" {
00069 #endif
00070
00071
00073 #define MAX_TEST_NAME_LENGTH 256
00074
00075 #define MAX_SUITE_NAME_LENGTH 256
00076
00077
00078 #ifndef BOOL
00079
00080 #define BOOL int
00081 #endif
00082
00083 #ifndef TRUE
00084
00085 #define TRUE 1
00086 #endif
00087
00088 #ifndef FALSE
00089
00090 #define FALSE 0
00091 #endif
00092
00093 #ifndef CU_UNREFERENCED_PARAMETER
00094
00095 #define CU_UNREFERENCED_PARAMETER(x) (void)x
00096 #endif
00097
00098 #include "TestRun.h"
00099
00101 #define CU_PASS(msg) \
00102 { CU_assertImplementation(TRUE, __LINE__, ("CU_PASS(" #msg ")"), __FILE__, "", FALSE); }
00103
00107 #define CU_ASSERT(value) \
00108 { CU_assertImplementation((value), __LINE__, #value, __FILE__, "", FALSE); }
00109
00113 #define CU_ASSERT_FATAL(value) \
00114 { CU_assertImplementation((value), __LINE__, #value, __FILE__, "", TRUE); }
00115
00119 #define CU_TEST(value) \
00120 { CU_assertImplementation((value), __LINE__, #value, __FILE__, "", FALSE); }
00121
00125 #define CU_TEST_FATAL(value) \
00126 { CU_assertImplementation((value), __LINE__, #value, __FILE__, "", TRUE); }
00127
00129 #define CU_FAIL(msg) \
00130 { CU_assertImplementation(FALSE, __LINE__, ("CU_FAIL(" #msg ")"), __FILE__, "", FALSE); }
00131
00133 #define CU_FAIL_FATAL(msg) \
00134 { CU_assertImplementation(FALSE, __LINE__, ("CU_FAIL_FATAL(" #msg ")"), __FILE__, "", TRUE); }
00135
00139 #define CU_ASSERT_TRUE(value) \
00140 { CU_assertImplementation((value), __LINE__, ("CU_ASSERT_TRUE(" #value ")"), __FILE__, "", FALSE); }
00141
00145 #define CU_ASSERT_TRUE_FATAL(value) \
00146 { CU_assertImplementation((value), __LINE__, ("CU_ASSERT_TRUE_FATAL(" #value ")"), __FILE__, "", TRUE); }
00147
00151 #define CU_ASSERT_FALSE(value) \
00152 { CU_assertImplementation(!(value), __LINE__, ("CU_ASSERT_FALSE(" #value ")"), __FILE__, "", FALSE); }
00153
00157 #define CU_ASSERT_FALSE_FATAL(value) \
00158 { CU_assertImplementation(!(value), __LINE__, ("CU_ASSERT_FALSE_FATAL(" #value ")"), __FILE__, "", TRUE); }
00159
00163 #define CU_ASSERT_EQUAL(actual, expected) \
00164 { CU_assertImplementation(((actual) == (expected)), __LINE__, ("CU_ASSERT_EQUAL(" #actual "," #expected ")"), __FILE__, "", FALSE); }
00165
00169 #define CU_ASSERT_EQUAL_FATAL(actual, expected) \
00170 { CU_assertImplementation(((actual) == (expected)), __LINE__, ("CU_ASSERT_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, "", TRUE); }
00171
00175 #define CU_ASSERT_NOT_EQUAL(actual, expected) \
00176 { CU_assertImplementation(((actual) != (expected)), __LINE__, ("CU_ASSERT_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, "", FALSE); }
00177
00181 #define CU_ASSERT_NOT_EQUAL_FATAL(actual, expected) \
00182 { CU_assertImplementation(((actual) != (expected)), __LINE__, ("CU_ASSERT_NOT_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, "", TRUE); }
00183
00187 #define CU_ASSERT_PTR_EQUAL(actual, expected) \
00188 { CU_assertImplementation(((void*)(actual) == (void*)(expected)), __LINE__, ("CU_ASSERT_PTR_EQUAL(" #actual "," #expected ")"), __FILE__, "", FALSE); }
00189
00193 #define CU_ASSERT_PTR_EQUAL_FATAL(actual, expected) \
00194 { CU_assertImplementation(((void*)(actual) == (void*)(expected)), __LINE__, ("CU_ASSERT_PTR_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, "", TRUE); }
00195
00199 #define CU_ASSERT_PTR_NOT_EQUAL(actual, expected) \
00200 { CU_assertImplementation(((void*)(actual) != (void*)(expected)), __LINE__, ("CU_ASSERT_PTR_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, "", FALSE); }
00201
00205 #define CU_ASSERT_PTR_NOT_EQUAL_FATAL(actual, expected) \
00206 { CU_assertImplementation(((void*)(actual) != (void*)(expected)), __LINE__, ("CU_ASSERT_PTR_NOT_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, "", TRUE); }
00207
00211 #define CU_ASSERT_PTR_NULL(value) \
00212 { CU_assertImplementation((NULL == (void*)(value)), __LINE__, ("CU_ASSERT_PTR_NULL(" #value")"), __FILE__, "", FALSE); }
00213
00217 #define CU_ASSERT_PTR_NULL_FATAL(value) \
00218 { CU_assertImplementation((NULL == (void*)(value)), __LINE__, ("CU_ASSERT_PTR_NULL_FATAL(" #value")"), __FILE__, "", TRUE); }
00219
00223 #define CU_ASSERT_PTR_NOT_NULL(value) \
00224 { CU_assertImplementation((NULL != (void*)(value)), __LINE__, ("CU_ASSERT_PTR_NOT_NULL(" #value")"), __FILE__, "", FALSE); }
00225
00229 #define CU_ASSERT_PTR_NOT_NULL_FATAL(value) \
00230 { CU_assertImplementation((NULL != (void*)(value)), __LINE__, ("CU_ASSERT_PTR_NOT_NULL_FATAL(" #value")"), __FILE__, "", TRUE); }
00231
00235 #define CU_ASSERT_STRING_EQUAL(actual, expected) \
00236 { CU_assertImplementation(!(strcmp((const char*)(actual), (const char*)(expected))), __LINE__, ("CU_ASSERT_STRING_EQUAL(" #actual "," #expected ")"), __FILE__, "", FALSE); }
00237
00241 #define CU_ASSERT_STRING_EQUAL_FATAL(actual, expected) \
00242 { CU_assertImplementation(!(strcmp((const char*)(actual), (const char*)(expected))), __LINE__, ("CU_ASSERT_STRING_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, "", TRUE); }
00243
00247 #define CU_ASSERT_STRING_NOT_EQUAL(actual, expected) \
00248 { CU_assertImplementation((strcmp((const char*)(actual), (const char*)(expected))), __LINE__, ("CU_ASSERT_STRING_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, "", FALSE); }
00249
00253 #define CU_ASSERT_STRING_NOT_EQUAL_FATAL(actual, expected) \
00254 { CU_assertImplementation((strcmp((const char*)(actual), (const char*)(expected))), __LINE__, ("CU_ASSERT_STRING_NOT_EQUAL_FATAL(" #actual "," #expected ")"), __FILE__, "", TRUE); }
00255
00260 #define CU_ASSERT_NSTRING_EQUAL(actual, expected, count) \
00261 { CU_assertImplementation(!(strncmp((const char*)(actual), (const char*)(expected), (size_t)(count))), __LINE__, ("CU_ASSERT_NSTRING_EQUAL(" #actual "," #expected "," #count ")"), __FILE__, "", FALSE); }
00262
00267 #define CU_ASSERT_NSTRING_EQUAL_FATAL(actual, expected, count) \
00268 { CU_assertImplementation(!(strncmp((const char*)(actual), (const char*)(expected), (size_t)(count))), __LINE__, ("CU_ASSERT_NSTRING_EQUAL_FATAL(" #actual "," #expected "," #count ")"), __FILE__, "", TRUE); }
00269
00274 #define CU_ASSERT_NSTRING_NOT_EQUAL(actual, expected, count) \
00275 { CU_assertImplementation((strncmp((const char*)(actual), (const char*)(expected), (size_t)(count))), __LINE__, ("CU_ASSERT_NSTRING_NOT_EQUAL(" #actual "," #expected "," #count ")"), __FILE__, "", FALSE); }
00276
00281 #define CU_ASSERT_NSTRING_NOT_EQUAL_FATAL(actual, expected, count) \
00282 { CU_assertImplementation((strncmp((const char*)(actual), (const char*)(expected), (size_t)(count))), __LINE__, ("CU_ASSERT_NSTRING_NOT_EQUAL_FATAL(" #actual "," #expected "," #count ")"), __FILE__, "", TRUE); }
00283
00288 #define CU_ASSERT_DOUBLE_EQUAL(actual, expected, granularity) \
00289 { CU_assertImplementation(((fabs((double)(actual) - (expected)) <= fabs((double)(granularity)))), __LINE__, ("CU_ASSERT_DOUBLE_EQUAL(" #actual "," #expected "," #granularity ")"), __FILE__, "", FALSE); }
00290
00295 #define CU_ASSERT_DOUBLE_EQUAL_FATAL(actual, expected, granularity) \
00296 { CU_assertImplementation(((fabs((double)(actual) - (expected)) <= fabs((double)(granularity)))), __LINE__, ("CU_ASSERT_DOUBLE_EQUAL_FATAL(" #actual "," #expected "," #granularity ")"), __FILE__, "", TRUE); }
00297
00302 #define CU_ASSERT_DOUBLE_NOT_EQUAL(actual, expected, granularity) \
00303 { CU_assertImplementation(((fabs((double)(actual) - (expected)) > fabs((double)(granularity)))), __LINE__, ("CU_ASSERT_DOUBLE_NOT_EQUAL(" #actual "," #expected "," #granularity ")"), __FILE__, "", FALSE); }
00304
00309 #define CU_ASSERT_DOUBLE_NOT_EQUAL_FATAL(actual, expected, granularity) \
00310 { CU_assertImplementation(((fabs((double)(actual) - (expected)) > fabs((double)(granularity)))), __LINE__, ("CU_ASSERT_DOUBLE_NOT_EQUAL_FATAL(" #actual "," #expected "," #granularity ")"), __FILE__, "", TRUE); }
00311
00312 #ifdef __cplusplus
00313 }
00314 #endif
00315
00316 #ifdef USE_DEPRECATED_CUNIT_NAMES
00317
00318 #define ASSERT(value) { if (FALSE == (int)(value)) { CU_assertImplementation((BOOL)value, __LINE__, #value, __FILE__, "", FALSE); return; }}
00319
00320 #define ASSERT_TRUE(value) { if (FALSE == (value)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_TRUE(" #value ")"), __FILE__, "", FALSE); return; }}
00321
00322 #define ASSERT_FALSE(value) { if (FALSE != (value)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_FALSE(" #value ")"), __FILE__, "", FALSE); return; }}
00323
00324 #define ASSERT_EQUAL(actual, expected) { if ((actual) != (expected)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_EQUAL(" #actual "," #expected ")"), __FILE__, "", FALSE); return; }}
00325
00326 #define ASSERT_NOT_EQUAL(actual, expected) { if ((void*)(actual) == (void*)(expected)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, "", FALSE); return; }}
00327
00328 #define ASSERT_PTR_EQUAL(actual, expected) { if ((void*)(actual) != (void*)(expected)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_PTR_EQUAL(" #actual "," #expected ")"), __FILE__, "", FALSE); return; }}
00329
00330 #define ASSERT_PTR_NOT_EQUAL(actual, expected) { if ((void*)(actual) == (void*)(expected)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_PTR_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, "", FALSE); return; }}
00331
00332 #define ASSERT_PTR_NULL(value) { if (NULL != (void*)(value)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_PTR_NULL(" #value")"), __FILE__, "", FALSE); return; }}
00333
00334 #define ASSERT_PTR_NOT_NULL(value) { if (NULL == (void*)(value)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_PTR_NOT_NULL(" #value")"), __FILE__, "", FALSE); return; }}
00335
00336 #define ASSERT_STRING_EQUAL(actual, expected) { if (strcmp((const char*)actual, (const char*)expected)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_STRING_EQUAL(" #actual "," #expected ")"), __FILE__, "", FALSE); return; }}
00337
00338 #define ASSERT_STRING_NOT_EQUAL(actual, expected) { if (!strcmp((const char*)actual, (const char*)expected)) { CU_assertImplementation(TRUE, __LINE__, ("ASSERT_STRING_NOT_EQUAL(" #actual "," #expected ")"), __FILE__, "", FALSE); return; }}
00339
00340 #define ASSERT_NSTRING_EQUAL(actual, expected, count) { if (strncmp((const char*)actual, (const char*)expected, (size_t)count)) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_NSTRING_EQUAL(" #actual "," #expected "," #count ")"), __FILE__, "", FALSE); return; }}
00341
00342 #define ASSERT_NSTRING_NOT_EQUAL(actual, expected, count) { if (!strncmp((const char*)actual, (const char*)expected, (size_t)count)) { CU_assertImplementation(TRUE, __LINE__, ("ASSERT_NSTRING_NOT_EQUAL(" #actual "," #expected "," #count ")"), __FILE__, "", FALSE); return; }}
00343
00344 #define ASSERT_DOUBLE_EQUAL(actual, expected, granularity) { if ((fabs((double)actual - expected) > fabs((double)granularity))) { CU_assertImplementation(FALSE, __LINE__, ("ASSERT_DOUBLE_EQUAL(" #actual "," #expected "," #granularity ")"), __FILE__, "", FALSE); return; }}
00345
00346 #define ASSERT_DOUBLE_NOT_EQUAL(actual, expected, granularity) { if ((fabs((double)actual - expected) <= fabs((double)granularity))) { CU_assertImplementation(TRUE, __LINE__, ("ASSERT_DOUBLE_NOT_EQUAL(" #actual "," #expected "," #granularity ")"), __FILE__, "", FALSE); return; }}
00347 #endif
00348
00349 #endif
00350