 |
NetBurner 3.1
|
28 #ifndef D_UTestMacros_h 29 #define D_UTestMacros_h 31 #include "CppUTest/config.h" 41 #include "CppUTest/SimpleString.h" 42 extern SimpleString gSystemOut;
45 #define TEST_GROUP_BASE(testGroup, baseclass) \ 46 extern int externTestGroup##testGroup; \ 47 int externTestGroup##testGroup = 0; \ 48 struct TEST_GROUP_##CppUTestGroup##testGroup : public baseclass 50 #define TEST_BASE(testBaseClass) \ 51 struct testBaseClass : public Utest 53 #define TEST_GROUP(testGroup) \ 54 TEST_GROUP_BASE(testGroup, Utest) 56 #define TEST_SETUP() \ 59 #define TEST_TEARDOWN() \ 60 virtual void teardown() 63 #define TEST(testGroup, testName) TEST_PLATFORM( testGroup, testName, SB800EX_ ) 64 #elif defined MOD5441X 65 #define TEST(testGroup, testName) TEST_PLATFORM( testGroup, testName, MOD5441X_ ) 67 #define TEST(testGroup, testName) TEST_PLATFORM( testGroup, testName, SB70LC_ ) 68 #elif defined MODM7AE70 69 #define TEST(testGroup, testName) TEST_PLATFORM( testGroup, testName, MODM7AE70_ ) 71 #define TEST(testGroup, testName) TEST_PLATFORM( testGroup, testName, UNKNOWN_ ) 74 #define TEST_PLATFORM(testGroup, testName, platform) \ 76 class TEST_##platform####testGroup##_##testName##_TestShell; \ 77 extern TEST_##platform####testGroup##_##testName##_TestShell TEST_##platform####testGroup##_##testName##_TestShell_instance; \ 79 class TEST_##platform####testGroup##_##testName##_Test : public TEST_GROUP_##CppUTestGroup##testGroup \ 80 { public: TEST_##platform####testGroup##_##testName##_Test () : TEST_GROUP_##CppUTestGroup##testGroup () {} \ 82 class TEST_##platform####testGroup##_##testName##_TestShell : public UtestShell { \ 83 virtual Utest* createTest() _override { return new TEST_##platform####testGroup##_##testName##_Test; } \ 84 } TEST_##platform####testGroup##_##testName##_TestShell_instance; \ 85 static TestInstaller TEST_##platform####testGroup##_##testName##_Installer(TEST_##platform####testGroup##_##testName##_TestShell_instance, #platform#testGroup, #testName, __FILE__,__LINE__); \ 86 void TEST_##platform####testGroup##_##testName##_Test::testBody() 88 #define IGNORE_TEST(testGroup, testName)\ 90 class IGNORE##testGroup##_##testName##_TestShell; \ 91 extern IGNORE##testGroup##_##testName##_TestShell IGNORE##testGroup##_##testName##_TestShell_instance; \ 93 class IGNORE##testGroup##_##testName##_Test : public TEST_GROUP_##CppUTestGroup##testGroup \ 94 { public: IGNORE##testGroup##_##testName##_Test () : TEST_GROUP_##CppUTestGroup##testGroup () {} \ 95 public: void testBody (); }; \ 96 class IGNORE##testGroup##_##testName##_TestShell : public IgnoredUtestShell { \ 97 virtual Utest* createTest() _override { return new IGNORE##testGroup##_##testName##_Test; } \ 98 } IGNORE##testGroup##_##testName##_TestShell_instance; \ 99 static TestInstaller TEST_##testGroup##testName##_Installer(IGNORE##testGroup##_##testName##_TestShell_instance, #testGroup, #testName, __FILE__,__LINE__); \ 100 void IGNORE##testGroup##_##testName##_Test::testBody () 102 #define IMPORT_TEST_GROUP(testGroup) \ 103 extern int externTestGroup##testGroup;\ 104 extern int* p##testGroup; \ 105 int* p##testGroup = &externTestGroup##testGroup 107 #define CPPUTEST_DEFAULT_MAIN \ 109 int main(int argc, char** argv) \ 111 return CommandLineTestRunner::RunAllTests(argc, argv); \ 117 #define CHECK(condition)\ 118 CHECK_TRUE_LOCATION(condition, "CHECK", #condition, NULL, __FILE__, __LINE__) 120 #define CHECK_TEXT(condition, text) \ 121 CHECK_TRUE_LOCATION(condition, "CHECK", #condition, text, __FILE__, __LINE__) 123 #define CHECK_TRUE(condition)\ 124 CHECK_TRUE_LOCATION(condition, "CHECK_TRUE", #condition, NULL, __FILE__, __LINE__) 126 #define CHECK_TRUE_TEXT(condition, text)\ 127 CHECK_TRUE_LOCATION(condition, "CHECK_TRUE", #condition, text, __FILE__, __LINE__) 129 #define CHECK_FALSE(condition)\ 130 CHECK_FALSE_LOCATION(condition, "CHECK_FALSE", #condition, NULL, __FILE__, __LINE__) 132 #define CHECK_FALSE_TEXT(condition, text)\ 133 CHECK_FALSE_LOCATION(condition, "CHECK_FALSE", #condition, text, __FILE__, __LINE__) 135 #define CHECK_TRUE_LOCATION(condition, checkString, conditionString, text, file, line)\ 136 { UtestShell::getCurrent()->assertTrue((condition) != 0, checkString, conditionString, text, file, line); } 138 #define CHECK_FALSE_LOCATION(condition, checkString, conditionString, text, file, line)\ 139 { UtestShell::getCurrent()->assertTrue((condition) == 0, checkString, conditionString, text, file, line); } 142 #define CHECK_EQUAL(expected, actual)\ 143 CHECK_EQUAL_LOCATION(expected, actual, NULL, __FILE__, __LINE__) 145 #define CHECK_EQUAL_TEXT(expected, actual, text)\ 146 CHECK_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__) 148 #define CHECK_EQUAL_LOCATION(expected, actual, text, file, line)\ 149 { if ((expected) != (actual)) { \ 150 if ((actual) != (actual)) \ 151 UtestShell::getCurrent()->print("WARNING:\n\tThe \"Actual Parameter\" parameter is evaluated multiple times resulting in different values.\n\tThus the value in the error message is probably incorrect.", file, line); \ 152 if ((expected) != (expected)) \ 153 UtestShell::getCurrent()->print("WARNING:\n\tThe \"Expected Parameter\" parameter is evaluated multiple times resulting in different values.\n\tThus the value in the error message is probably incorrect.", file, line); \ 154 UtestShell::getCurrent()->assertEquals(true, StringFrom(expected).asCharString(), StringFrom(actual).asCharString(), text, file, line); \ 158 UtestShell::getCurrent()->assertLongsEqual((long)0, (long)0, NULL, file, line); \ 163 #define STRCMP_EQUAL(expected, actual)\ 164 STRCMP_EQUAL_LOCATION(expected, actual, NULL, __FILE__, __LINE__) 166 #define STRCMP_EQUAL_TEXT(expected, actual, text)\ 167 STRCMP_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__) 169 #define STRCMP_EQUAL_LOCATION(expected, actual, text, file, line)\ 170 { UtestShell::getCurrent()->assertCstrEqual(expected, actual, text, file, line); } 172 #define STRNCMP_EQUAL(expected, actual, length)\ 173 STRNCMP_EQUAL_LOCATION(expected, actual, length, NULL, __FILE__, __LINE__) 175 #define STRNCMP_EQUAL_TEXT(expected, actual, length, text)\ 176 STRNCMP_EQUAL_LOCATION(expected, actual, length, text, __FILE__, __LINE__) 178 #define STRNCMP_EQUAL_LOCATION(expected, actual, length, text, file, line)\ 179 { UtestShell::getCurrent()->assertCstrNEqual(expected, actual, length, text, file, line); } 181 #define STRCMP_NOCASE_EQUAL(expected, actual)\ 182 STRCMP_NOCASE_EQUAL_LOCATION(expected, actual, NULL, __FILE__, __LINE__) 184 #define STRCMP_NOCASE_EQUAL_TEXT(expected, actual, text)\ 185 STRCMP_NOCASE_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__) 187 #define STRCMP_NOCASE_EQUAL_LOCATION(expected, actual, text, file, line)\ 188 { UtestShell::getCurrent()->assertCstrNoCaseEqual(expected, actual, text, file, line); } 190 #define STRCMP_CONTAINS(expected, actual)\ 191 STRCMP_CONTAINS_LOCATION(expected, actual, NULL, __FILE__, __LINE__) 193 #define STRCMP_CONTAINS_TEXT(expected, actual, text)\ 194 STRCMP_CONTAINS_LOCATION(expected, actual, text, __FILE__, __LINE__) 196 #define STRCMP_CONTAINS_LOCATION(expected, actual, text, file, line)\ 197 { UtestShell::getCurrent()->assertCstrContains(expected, actual, text, file, line); } 199 #define STRCMP_NOCASE_CONTAINS(expected, actual)\ 200 STRCMP_NOCASE_CONTAINS_LOCATION(expected, actual, NULL, __FILE__, __LINE__) 202 #define STRCMP_NOCASE_CONTAINS_TEXT(expected, actual, text)\ 203 STRCMP_NOCASE_CONTAINS_LOCATION(expected, actual, text, __FILE__, __LINE__) 205 #define STRCMP_NOCASE_CONTAINS_LOCATION(expected, actual, text, file, line)\ 206 { UtestShell::getCurrent()->assertCstrNoCaseContains(expected, actual, text, file, line); } 209 #define LONGS_EQUAL(expected, actual)\ 210 LONGS_EQUAL_LOCATION((expected), (actual), "LONGS_EQUAL(" #expected ", " #actual ") failed", __FILE__, __LINE__) 212 #define LONGS_EQUAL_TEXT(expected, actual, text)\ 213 LONGS_EQUAL_LOCATION((expected), (actual), text, __FILE__, __LINE__) 215 #define UNSIGNED_LONGS_EQUAL(expected, actual)\ 216 UNSIGNED_LONGS_EQUAL_LOCATION((expected), (actual), NULL, __FILE__, __LINE__) 218 #define UNSIGNED_LONGS_EQUAL_TEXT(expected, actual, text)\ 219 UNSIGNED_LONGS_EQUAL_LOCATION((expected), (actual), text, __FILE__, __LINE__) 221 #define LONGS_EQUAL_LOCATION(expected, actual, text, file, line)\ 222 { UtestShell::getCurrent()->assertLongsEqual((long)expected, (long)actual, text, file, line); } 224 #define UNSIGNED_LONGS_EQUAL_LOCATION(expected, actual, text, file, line)\ 225 { UtestShell::getCurrent()->assertUnsignedLongsEqual((unsigned long)expected, (unsigned long)actual, text, file, line); } 227 #define LONGLONGS_EQUAL(expected, actual)\ 228 LONGLONGS_EQUAL_LOCATION(expected, actual, NULL, __FILE__, __LINE__) 230 #define LONGLONGS_EQUAL_TEXT(expected, actual, text)\ 231 LONGLONGS_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__) 233 #define UNSIGNED_LONGLONGS_EQUAL(expected, actual)\ 234 UNSIGNED_LONGLONGS_EQUAL_LOCATION(expected, actual, NULL, __FILE__, __LINE__) 236 #define UNSIGNED_LONGLONGS_EQUAL_TEXT(expected, actual, text)\ 237 UNSIGNED_LONGLONGS_EQUAL_LOCATION(expected, actual, text, __FILE__, __LINE__) 239 #define LONGLONGS_EQUAL_LOCATION(expected, actual, text, file, line)\ 240 { UtestShell::getCurrent()->assertLongLongsEqual(expected, actual, text, file, line); } 242 #define UNSIGNED_LONGLONGS_EQUAL_LOCATION(expected, actual, text, file, line)\ 243 { UtestShell::getCurrent()->assertUnsignedLongLongsEqual(expected, actual, text, file, line); } 245 #define BYTES_EQUAL(expected, actual)\ 246 LONGS_EQUAL((expected) & 0xff,(actual) & 0xff) 248 #define BYTES_EQUAL_TEXT(expected, actual, text)\ 249 LONGS_EQUAL_TEXT((expected) & 0xff, (actual) & 0xff, text) 251 #define SIGNED_BYTES_EQUAL(expected, actual)\ 252 SIGNED_BYTES_EQUAL_LOCATION(expected, actual, __FILE__, __LINE__) 254 #define SIGNED_BYTES_EQUAL_LOCATION(expected, actual, file, line) \ 255 { UtestShell::getCurrent()->assertSignedBytesEqual(expected, actual, NULL, file, line); } 257 #define SIGNED_BYTES_EQUAL_TEXT(expected, actual, text)\ 258 SIGNED_BYTES_EQUAL_TEXT_LOCATION(expected, actual, text, __FILE__, __LINE__) 260 #define SIGNED_BYTES_EQUAL_TEXT_LOCATION(expected, actual, text, file, line) \ 261 { UtestShell::getCurrent()->assertSignedBytesEqual(expected, actual, text, file, line); } 263 #define POINTERS_EQUAL(expected, actual)\ 264 POINTERS_EQUAL_LOCATION((expected), (actual), NULL, __FILE__, __LINE__) 266 #define POINTERS_EQUAL_TEXT(expected, actual, text)\ 267 POINTERS_EQUAL_LOCATION((expected), (actual), text, __FILE__, __LINE__) 269 #define POINTERS_EQUAL_LOCATION(expected, actual, text, file, line)\ 270 { UtestShell::getCurrent()->assertPointersEqual((void *)expected, (void *)actual, text, file, line); } 272 #define FUNCTIONPOINTERS_EQUAL(expected, actual)\ 273 FUNCTIONPOINTERS_EQUAL_LOCATION((expected), (actual), NULL, __FILE__, __LINE__) 275 #define FUNCTIONPOINTERS_EQUAL_TEXT(expected, actual, text)\ 276 FUNCTIONPOINTERS_EQUAL_LOCATION((expected), (actual), text, __FILE__, __LINE__) 278 #define FUNCTIONPOINTERS_EQUAL_LOCATION(expected, actual, text, file, line)\ 279 { UtestShell::getCurrent()->assertFunctionPointersEqual((void (*)())expected, (void (*)())actual, text, file, line); } 282 #define DOUBLES_EQUAL(expected, actual, threshold)\ 283 DOUBLES_EQUAL_LOCATION(expected, actual, threshold, NULL, __FILE__, __LINE__) 285 #define DOUBLES_EQUAL_TEXT(expected, actual, threshold, text)\ 286 DOUBLES_EQUAL_LOCATION(expected, actual, threshold, text, __FILE__, __LINE__) 288 #define DOUBLES_EQUAL_LOCATION(expected, actual, threshold, text, file, line)\ 289 { UtestShell::getCurrent()->assertDoublesEqual(expected, actual, threshold, text, file, line); } 291 #define MEMCMP_EQUAL(expected, actual, size)\ 292 MEMCMP_EQUAL_LOCATION(expected, actual, size, NULL, __FILE__, __LINE__) 294 #define MEMCMP_EQUAL_TEXT(expected, actual, size, text)\ 295 MEMCMP_EQUAL_LOCATION(expected, actual, size, text, __FILE__, __LINE__) 297 #define MEMCMP_EQUAL_LOCATION(expected, actual, size, text, file, line)\ 298 { UtestShell::getCurrent()->assertBinaryEqual(expected, actual, size, text, file, line); } 300 #define BITS_EQUAL(expected, actual, mask)\ 301 BITS_LOCATION(expected, actual, mask, NULL, __FILE__, __LINE__) 303 #define BITS_EQUAL_TEXT(expected, actual, mask, text)\ 304 BITS_LOCATION(expected, actual, mask, text, __FILE__, __LINE__) 306 #define BITS_LOCATION(expected, actual, mask, text, file, line)\ 307 { UtestShell::getCurrent()->assertBitsEqual(expected, actual, mask, sizeof(actual), text, file, line); } 313 FAIL_LOCATION(text, __FILE__,__LINE__) 315 #define FAIL_LOCATION(text, file, line)\ 316 { UtestShell::getCurrent()->fail(text, file, line); } 319 #define FAIL_TEST(text)\ 320 FAIL_TEST_LOCATION(text, __FILE__,__LINE__) 322 #define FAIL_TEST_LOCATION(text, file,line)\ 323 { UtestShell::getCurrent()->fail(text, file, line); } 326 { UtestShell::getCurrent()->exitTest(); } 328 #define UT_PRINT_LOCATION(text, file, line) \ 329 { UtestShell::getCurrent()->print(text, file, line); } 331 #define UT_PRINT(text) \ 332 UT_PRINT_LOCATION(text, __FILE__, __LINE__) 335 #define UT_MEASURE_DOUBLE(key,value) \ 337 double val = value; \ 338 SimpleString buff = StringFromFormat( "<measurement><name>%s</name><value>%f</value></measurement>", key, val ); \ 339 gSystemOut += buff; \ 341 #define UT_MEASURE_INT(key,value) \ 345 snprintf(buffer,120,"<measurement><name>%s</name><value>%d</value></measurement>",key,val); \ 346 UT_PRINT_LOCATION(buffer, __FILE__, __LINE__); \ 349 #define UT_MEASURE_DOUBLE(key,value) \ 351 double val = value; \ 353 snprintf(buffer,120,"\n%s: %f\n",key,val); \ 354 UT_PRINT_LOCATION(buffer, __FILE__, __LINE__); \ 356 #define UT_MEASURE_INT(key,value) \ 360 snprintf(buffer,120,"\n%s: %d\n",key,val); \ 361 UT_PRINT_LOCATION(buffer, __FILE__, __LINE__); \ 365 #if CPPUTEST_USE_STD_CPP_LIB 366 #define CHECK_THROWS(expected, expression) \ 368 SimpleString failure_msg("expected to throw "#expected "\nbut threw nothing"); \ 369 bool caught_expected = false; \ 372 } catch(const expected &) { \ 373 caught_expected = true; \ 375 failure_msg = "expected to throw " #expected "\nbut threw a different type"; \ 377 if (!caught_expected) { \ 378 UtestShell::getCurrent()->fail(failure_msg.asCharString(), __FILE__, __LINE__); \ 381 UtestShell::getCurrent()->countCheck(); \ 386 #define UT_CRASH() { UtestShell::crash(); } 387 #define RUN_ALL_TESTS(ac, av) CommandLineTestRunner::RunAllTests(ac, av)