1 /* ========================================== 2 Unity Project - A Test Framework for C 3 Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams 4 [Released under MIT License. Please refer to license.txt for details] 5 ========================================== */ 6 7 #ifndef UNITY_INTERNALS_H 8 #define UNITY_INTERNALS_H 9 10 #include <stdio.h> 11 #include <setjmp.h> 12 13 // Unity attempts to determine sizeof(various types) 14 // based on UINT_MAX, ULONG_MAX, etc. These are typically 15 // defined in limits.h. 16 #ifdef UNITY_USE_LIMITS_H 17 #include <limits.h> 18 #endif 19 // As a fallback, hope that including stdint.h will 20 // provide this information. 21 #ifndef UNITY_EXCLUDE_STDINT_H 22 #include <stdint.h> 23 #endif 24 25 //------------------------------------------------------- 26 // Guess Widths If Not Specified 27 //------------------------------------------------------- 28 29 // Determine the size of an int, if not already specificied. 30 // We cannot use sizeof(int), because it is not yet defined 31 // at this stage in the trnslation of the C program. 32 // Therefore, infer it from UINT_MAX if possible. 33 #ifndef UNITY_INT_WIDTH 34 #ifdef UINT_MAX 35 #if (UINT_MAX == 0xFFFF) 36 #define UNITY_INT_WIDTH (16) 37 #elif (UINT_MAX == 0xFFFFFFFF) 38 #define UNITY_INT_WIDTH (32) 39 #elif (UINT_MAX == 0xFFFFFFFFFFFFFFFF) 40 #define UNITY_INT_WIDTH (64) 41 #ifndef UNITY_SUPPORT_64 42 #define UNITY_SUPPORT_64 43 #endif 44 #endif 45 #endif 46 #endif 47 #ifndef UNITY_INT_WIDTH 48 #define UNITY_INT_WIDTH (32) 49 #endif 50 51 // Determine the size of a long, if not already specified, 52 // by following the process used above to define 53 // UNITY_INT_WIDTH. 54 #ifndef UNITY_LONG_WIDTH 55 #ifdef ULONG_MAX 56 #if (ULONG_MAX == 0xFFFF) 57 #define UNITY_LONG_WIDTH (16) 58 #elif (ULONG_MAX == 0xFFFFFFFF) 59 #define UNITY_LONG_WIDTH (32) 60 #elif (ULONG_MAX == 0xFFFFFFFFFFFFFFFF) 61 #define UNITY_LONG_WIDTH (64) 62 #ifndef UNITY_SUPPORT_64 63 #define UNITY_SUPPORT_64 64 #endif 65 #endif 66 #endif 67 #endif 68 #ifndef UNITY_LONG_WIDTH 69 #define UNITY_LONG_WIDTH (32) 70 #endif 71 72 // Determine the size of a pointer, if not already specified, 73 // by following the process used above to define 74 // UNITY_INT_WIDTH. 75 #ifndef UNITY_POINTER_WIDTH 76 #ifdef UINTPTR_MAX 77 #if (UINTPTR_MAX <= 0xFFFF) 78 #define UNITY_POINTER_WIDTH (16) 79 #elif (UINTPTR_MAX <= 0xFFFFFFFF) 80 #define UNITY_POINTER_WIDTH (32) 81 #elif (UINTPTR_MAX <= 0xFFFFFFFFFFFFFFFF) 82 #define UNITY_POINTER_WIDTH (64) 83 #ifndef UNITY_SUPPORT_64 84 #define UNITY_SUPPORT_64 85 #endif 86 #endif 87 #endif 88 #endif 89 #ifndef UNITY_POINTER_WIDTH 90 #ifdef INTPTR_MAX 91 #if (INTPTR_MAX <= 0x7FFF) 92 #define UNITY_POINTER_WIDTH (16) 93 #elif (INTPTR_MAX <= 0x7FFFFFFF) 94 #define UNITY_POINTER_WIDTH (32) 95 #elif (INTPTR_MAX <= 0x7FFFFFFFFFFFFFFF) 96 #define UNITY_POINTER_WIDTH (64) 97 #ifndef UNITY_SUPPORT_64 98 #define UNITY_SUPPORT_64 99 #endif 100 #endif 101 #endif 102 #endif 103 #ifndef UNITY_POINTER_WIDTH 104 #define UNITY_POINTER_WIDTH (32) 105 #endif 106 107 #ifdef UNITY_CONTINUE_CUR_TEST_IF_ASSERT_FAIL 108 #define IS_CONTINUE_CUR_TEST_IF_ASSERT_FAIL 1 109 #else 110 #define IS_CONTINUE_CUR_TEST_IF_ASSERT_FAIL 0 111 #endif 112 113 //------------------------------------------------------- 114 // Int Support 115 //------------------------------------------------------- 116 117 #if (UNITY_INT_WIDTH == 32) 118 typedef unsigned char _UU8; 119 typedef unsigned short _UU16; 120 typedef unsigned int _UU32; 121 typedef signed char _US8; 122 typedef signed short _US16; 123 typedef signed int _US32; 124 #elif (UNITY_INT_WIDTH == 16) 125 typedef unsigned char _UU8; 126 typedef unsigned int _UU16; 127 typedef unsigned long _UU32; 128 typedef signed char _US8; 129 typedef signed int _US16; 130 typedef signed long _US32; 131 #else 132 #error Invalid UNITY_INT_WIDTH specified! (16 or 32 are supported) 133 #endif 134 135 //------------------------------------------------------- 136 // 64-bit Support 137 //------------------------------------------------------- 138 139 #ifndef UNITY_SUPPORT_64 140 141 // No 64-bit Support 142 typedef _UU32 _U_UINT; 143 typedef _US32 _U_SINT; 144 145 #else 146 147 // 64-bit Support 148 #if (UNITY_LONG_WIDTH == 32) 149 typedef unsigned long long _UU64; 150 typedef signed long long _US64; 151 #elif (UNITY_LONG_WIDTH == 64) 152 typedef unsigned long _UU64; 153 typedef signed long _US64; 154 #else 155 #error Invalid UNITY_LONG_WIDTH specified! (32 or 64 are supported) 156 #endif 157 typedef _UU64 _U_UINT; 158 typedef _US64 _U_SINT; 159 160 #endif 161 162 //------------------------------------------------------- 163 // Pointer Support 164 //------------------------------------------------------- 165 166 #if (UNITY_POINTER_WIDTH == 32) 167 typedef _UU32 _UP; 168 #define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX32 169 #elif (UNITY_POINTER_WIDTH == 64) 170 #ifndef UNITY_SUPPORT_64 171 #error "You've Specified 64-bit pointers without enabling 64-bit Support. Define UNITY_SUPPORT_64" 172 #endif 173 typedef _UU64 _UP; 174 #define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX64 175 #elif (UNITY_POINTER_WIDTH == 16) 176 typedef _UU16 _UP; 177 #define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX16 178 #else 179 #error Invalid UNITY_POINTER_WIDTH specified! (16, 32 or 64 are supported) 180 #endif 181 182 //------------------------------------------------------- 183 // Float Support 184 //------------------------------------------------------- 185 186 #ifdef UNITY_EXCLUDE_FLOAT 187 188 //------------------------------------------------------- 189 // Error[Pm081]: #undef should not be used (MISRA C 2004 rule 19.6) 190 // Need manual control defined symbols by generator projects 191 //------------------------------------------------------- 192 193 // No Floating Point Support 194 //#undef UNITY_FLOAT_PRECISION 195 //#undef UNITY_FLOAT_TYPE 196 //#undef UNITY_FLOAT_VERBOSE 197 198 #else 199 200 // Floating Point Support 201 #ifndef UNITY_FLOAT_PRECISION 202 #define UNITY_FLOAT_PRECISION (0.00001f) 203 #endif 204 #ifndef UNITY_FLOAT_TYPE 205 #define UNITY_FLOAT_TYPE float 206 #endif 207 typedef UNITY_FLOAT_TYPE _UF; 208 209 #endif 210 211 //------------------------------------------------------- 212 // Double Float Support 213 //------------------------------------------------------- 214 215 // unlike FLOAT, we DON'T include by default 216 #ifndef UNITY_EXCLUDE_DOUBLE 217 #ifndef UNITY_INCLUDE_DOUBLE 218 #define UNITY_EXCLUDE_DOUBLE 219 #endif 220 #endif 221 222 #ifdef UNITY_EXCLUDE_DOUBLE 223 224 //------------------------------------------------------- 225 // Error[Pm081]: #undef should not be used (MISRA C 2004 rule 19.6) 226 // Need manual control defined symbols by generator projects 227 //------------------------------------------------------- 228 229 // No Floating Point Support 230 //#undef UNITY_DOUBLE_PRECISION 231 //#undef UNITY_DOUBLE_TYPE 232 //#undef UNITY_DOUBLE_VERBOSE 233 234 #else 235 236 // Floating Point Support 237 #ifndef UNITY_DOUBLE_PRECISION 238 #define UNITY_DOUBLE_PRECISION (1e-12f) 239 #endif 240 #ifndef UNITY_DOUBLE_TYPE 241 #define UNITY_DOUBLE_TYPE double 242 #endif 243 typedef UNITY_DOUBLE_TYPE _UD; 244 245 #endif 246 247 //------------------------------------------------------- 248 // Output Method 249 //------------------------------------------------------- 250 #ifdef UNITY_NOT_PRINT_LOG 251 /* add do {} while(0) because of MISRA C 2014 rule 14.3 issue*/ 252 #define UNITY_OUTPUT_CHAR(a) \ 253 do \ 254 { \ 255 } while (0) 256 #else 257 #ifdef UNITY_CUSTOM_OUTPUT_CHAR 258 // If defined as something else, make sure we declare it here so it's ready for use 259 #include "fsl_debug_console.h" 260 #define UNITY_OUTPUT_CHAR(a) PUTCHAR(a) 261 #else 262 // Default to using putchar, which is defined in stdio.h above 263 #define UNITY_OUTPUT_CHAR(a) putchar(a) 264 #endif 265 #endif 266 267 //------------------------------------------------------- 268 // Footprint 269 //------------------------------------------------------- 270 271 #ifndef UNITY_LINE_TYPE 272 #define UNITY_LINE_TYPE _U_UINT 273 #endif 274 275 #ifndef UNITY_COUNTER_TYPE 276 #define UNITY_COUNTER_TYPE _U_UINT 277 #endif 278 279 //------------------------------------------------------- 280 // Internal Structs Needed 281 //------------------------------------------------------- 282 typedef void (*UnityTestSetUpFunction)(void); 283 typedef void (*UnityTestFunction)(void); 284 typedef void (*UnityTestTearDownFunction)(void); 285 286 #define UNITY_DISPLAY_RANGE_INT (0x10U) 287 #define UNITY_DISPLAY_RANGE_UINT (0x20U) 288 #define UNITY_DISPLAY_RANGE_HEX (0x40U) 289 #define UNITY_DISPLAY_RANGE_AUTO (0x80U) 290 #define UNITY_DISPLAY_RANGE_UNKNOWN (0xffU) 291 292 typedef enum 293 { 294 #if (UNITY_INT_WIDTH == 16) 295 UNITY_DISPLAY_STYLE_INT = 2 + UNITY_DISPLAY_RANGE_INT + UNITY_DISPLAY_RANGE_AUTO, 296 #elif (UNITY_INT_WIDTH == 32) 297 UNITY_DISPLAY_STYLE_INT = 4 + UNITY_DISPLAY_RANGE_INT + UNITY_DISPLAY_RANGE_AUTO, 298 #elif (UNITY_INT_WIDTH == 64) 299 UNITY_DISPLAY_STYLE_INT = 8 + UNITY_DISPLAY_RANGE_INT + UNITY_DISPLAY_RANGE_AUTO, 300 #endif 301 UNITY_DISPLAY_STYLE_INT8 = 1 + UNITY_DISPLAY_RANGE_INT, 302 UNITY_DISPLAY_STYLE_INT16 = 2 + UNITY_DISPLAY_RANGE_INT, 303 UNITY_DISPLAY_STYLE_INT32 = 4 + UNITY_DISPLAY_RANGE_INT, 304 #ifdef UNITY_SUPPORT_64 305 UNITY_DISPLAY_STYLE_INT64 = 8 + UNITY_DISPLAY_RANGE_INT, 306 #endif 307 308 #if (UNITY_INT_WIDTH == 16) 309 UNITY_DISPLAY_STYLE_UINT = 2 + UNITY_DISPLAY_RANGE_UINT + UNITY_DISPLAY_RANGE_AUTO, 310 #elif (UNITY_INT_WIDTH == 32) 311 UNITY_DISPLAY_STYLE_UINT = 4 + UNITY_DISPLAY_RANGE_UINT + UNITY_DISPLAY_RANGE_AUTO, 312 #elif (UNITY_INT_WIDTH == 64) 313 UNITY_DISPLAY_STYLE_UINT = 8 + UNITY_DISPLAY_RANGE_UINT + UNITY_DISPLAY_RANGE_AUTO, 314 #endif 315 UNITY_DISPLAY_STYLE_UINT8 = 1 + UNITY_DISPLAY_RANGE_UINT, 316 UNITY_DISPLAY_STYLE_UINT16 = 2 + UNITY_DISPLAY_RANGE_UINT, 317 UNITY_DISPLAY_STYLE_UINT32 = 4 + UNITY_DISPLAY_RANGE_UINT, 318 #ifdef UNITY_SUPPORT_64 319 UNITY_DISPLAY_STYLE_UINT64 = 8 + UNITY_DISPLAY_RANGE_UINT, 320 #endif 321 UNITY_DISPLAY_STYLE_HEX8 = 1 + UNITY_DISPLAY_RANGE_HEX, 322 UNITY_DISPLAY_STYLE_HEX16 = 2 + UNITY_DISPLAY_RANGE_HEX, 323 UNITY_DISPLAY_STYLE_HEX32 = 4 + UNITY_DISPLAY_RANGE_HEX, 324 #ifdef UNITY_SUPPORT_64 325 UNITY_DISPLAY_STYLE_HEX64 = 8 + UNITY_DISPLAY_RANGE_HEX, 326 #endif 327 UNITY_DISPLAY_STYLE_UNKNOWN = UNITY_DISPLAY_RANGE_UNKNOWN, 328 } UNITY_DISPLAY_STYLE_T; 329 330 struct _Unity 331 { 332 const char *TestFile; 333 const char *CurrentTestName; 334 UNITY_LINE_TYPE CurrentTestId; 335 UNITY_LINE_TYPE CurrentTestLineNumber; 336 UNITY_COUNTER_TYPE NumberOfTests; 337 UNITY_COUNTER_TYPE TestFailures; 338 UNITY_COUNTER_TYPE TestIgnores; 339 UNITY_COUNTER_TYPE CurrentTestFailed; 340 UNITY_COUNTER_TYPE CurrentTestIgnored; 341 UNITY_COUNTER_TYPE ContinueCurTestIfAssertFail; 342 jmp_buf AbortFrame; 343 }; 344 345 //------------------------------------------------------- 346 // Test Suite Management 347 //------------------------------------------------------- 348 void setUp(void); 349 void tearDown(void); 350 351 void UnityBegin(void); 352 int UnityEnd(void); 353 354 #ifdef UNITY_DUMP_RESULT 355 void UnityMemDumpEntry(void); 356 #endif 357 358 void UnityConcludeTest(void); 359 #ifdef UNITY_SHOW_TEST_FILE_PATH 360 void UnityDefaultTestRun(UnityTestSetUpFunction SetUpFunc, 361 UnityTestFunction Func, 362 UnityTestTearDownFunction TearDownFunc, 363 const char *FuncName, 364 const int CaseId, 365 const char *TestFile); 366 #else 367 void UnityDefaultTestRun(UnityTestSetUpFunction SetUpFunc, 368 UnityTestFunction Func, 369 UnityTestTearDownFunction TearDownFunc, 370 const char *FuncName, 371 const int CaseId); 372 #endif 373 void UnityContinueCurTestIfAssertFail(int enabled); 374 375 //------------------------------------------------------- 376 // Test Output 377 //------------------------------------------------------- 378 379 #ifdef UNITY_NOT_PRINT_LOG 380 // define empty macro 381 /* add do {} while(0) because of MISRA C 2014 rule 14.3 issue*/ 382 #define UnityPrintf(a...) \ 383 do \ 384 { \ 385 } while (0) 386 #define UnityPrint(a) \ 387 do \ 388 { \ 389 } while (0) 390 #define UnityPrintMask(a, b) \ 391 do \ 392 { \ 393 } while (0) 394 #define UnityPrintNumber(a) \ 395 do \ 396 { \ 397 } while (0) 398 #define UnityPrintNumberUnsigned(a) \ 399 do \ 400 { \ 401 } while (0) 402 #define UnityPrintNumberHex(a) \ 403 do \ 404 { \ 405 } while (0) 406 #define UnityPrintFloat(a) \ 407 do \ 408 { \ 409 } while (0) 410 #define UnityPrintNumberByStyle(a, b) \ 411 do \ 412 { \ 413 } while (0) 414 #else 415 #define MAX_CMD_CHAR_CNT (128) 416 void UnityPrintf(const char *format, ...); 417 void UnityPrint(const char *string); 418 void UnityPrintMask(const _U_UINT mask, const _U_UINT number); 419 void UnityPrintNumber(const _U_SINT number_to_print); 420 void UnityPrintNumberUnsigned(const _U_UINT number); 421 void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print); 422 #ifdef UNITY_FLOAT_VERBOSE 423 void UnityPrintFloat(const _UF number); 424 #endif 425 #endif // UNITY_NOT_PRINT_LOG 426 427 //------------------------------------------------------- 428 // Test Assertion Fuctions 429 //------------------------------------------------------- 430 // Use the macros below this section instead of calling 431 // these directly. The macros have a consistent naming 432 // convention and will pull in file and line information 433 // for you. 434 435 void UnityAssertEqualNumber(const _U_SINT expected, 436 const _U_SINT actual, 437 const char *msg, 438 const UNITY_LINE_TYPE lineNumber, 439 const UNITY_DISPLAY_STYLE_T style); 440 441 void UnityAssertEqualIntArray(const _U_SINT *expected, 442 const _U_SINT *actual, 443 const _UU32 num_elements, 444 const char *msg, 445 const UNITY_LINE_TYPE lineNumber, 446 const UNITY_DISPLAY_STYLE_T style); 447 448 void UnityAssertBits(const _U_UINT mask, 449 const _U_UINT expected, 450 const _U_UINT actual, 451 const char *msg, 452 const UNITY_LINE_TYPE lineNumber); 453 454 void UnityAssertEqualString(const char *expected, 455 const char *actual, 456 const char *msg, 457 const UNITY_LINE_TYPE lineNumber); 458 459 void UnityAssertEqualStringArray(const char **expected, 460 const char **actual, 461 const _UU32 num_elements, 462 const char *msg, 463 const UNITY_LINE_TYPE lineNumber); 464 465 void UnityAssertEqualMemory(unsigned char *expected, 466 unsigned char *actual, 467 const _UU32 length, 468 const _UU32 num_elements, 469 const char *msg, 470 const UNITY_LINE_TYPE lineNumber); 471 472 void UnityAssertNumbersWithin(const _U_SINT delta, 473 const _U_SINT expected, 474 const _U_SINT actual, 475 const char *msg, 476 const UNITY_LINE_TYPE lineNumber, 477 const UNITY_DISPLAY_STYLE_T style); 478 479 void UnityFail(const char *msg, const UNITY_LINE_TYPE line); 480 481 void UnityIgnore(const char *msg, const UNITY_LINE_TYPE line); 482 483 #ifndef UNITY_EXCLUDE_FLOAT 484 void UnityAssertFloatsWithin( 485 const _UF delta, const _UF expected, const _UF actual, const char *msg, const UNITY_LINE_TYPE lineNumber); 486 487 void UnityAssertEqualFloatArray(const _UF *expected, 488 const _UF *actual, 489 const _UU32 num_elements, 490 const char *msg, 491 const UNITY_LINE_TYPE lineNumber); 492 /* 493 Error[Pm046]: floating point values shall not be tested for exact equality or inequality (MISRA C 2004 rule 13.3) 494 void UnityAssertFloatIsInf(const _UF actual, 495 const char* msg, 496 const UNITY_LINE_TYPE lineNumber); 497 498 void UnityAssertFloatIsNegInf(const _UF actual, 499 const char* msg, 500 const UNITY_LINE_TYPE lineNumber); 501 502 void UnityAssertFloatIsNaN(const _UF actual, 503 const char* msg, 504 const UNITY_LINE_TYPE lineNumber); 505 */ 506 #endif 507 508 #ifndef UNITY_EXCLUDE_DOUBLE 509 void UnityAssertDoublesWithin( 510 const _UD delta, const _UD expected, const _UD actual, const char *msg, const UNITY_LINE_TYPE lineNumber); 511 512 void UnityAssertEqualDoubleArray(const _UD *expected, 513 const _UD *actual, 514 const _UU32 num_elements, 515 const char *msg, 516 const UNITY_LINE_TYPE lineNumber); 517 518 void UnityAssertDoubleIsInf(const _UD actual, const char *msg, const UNITY_LINE_TYPE lineNumber); 519 520 void UnityAssertDoubleIsNegInf(const _UD actual, const char *msg, const UNITY_LINE_TYPE lineNumber); 521 522 void UnityAssertDoubleIsNaN(const _UD actual, const char *msg, const UNITY_LINE_TYPE lineNumber); 523 #endif 524 525 #ifdef UNITY_DUMP_RESULT 526 #define DUMP_RESULT_TEST_RESULT_IGNORE 0x00U 527 #define DUMP_RESULT_TEST_RESULT_PASS 0x01U 528 #define DUMP_RESULT_TEST_RESULT_FAIL 0x02U 529 #define DUMP_RESULT_TEST_RESULT_SUMMARY 0x03U 530 531 #define DUMP_RESULT_TEST_RESULT_MASK 0x03U 532 #define DUMP_RESULT_BIT_NUM 2U 533 534 #ifdef UNITY_DUMP_COMPATIBLE_WITH_EU 535 void setIndepAssertId(const UNITY_LINE_TYPE indepAssertId); 536 #define INDEP_ASSERT_ID(func, line) INDEP_ASSERT_AT_TEST_##func##_##line 537 /* add do {} while(0) because of MISRA C 2014 rule 14.3 issue*/ 538 #define SET_INDEP_ASSERT_ID(func, line) \ 539 do \ 540 { \ 541 setIndepAssertId((UNITY_LINE_TYPE)INDEP_ASSERT_ID(func, line)); \ 542 } while (0) 543 #define UnityDumpCaseResult(a, b) \ 544 do \ 545 { \ 546 } while (0) 547 void UnityDumpAssertResult(const _UU8 result, const UNITY_LINE_TYPE lineNumber); 548 #else 549 /* add do {} while(0) because of MISRA C 2014 rule 14.3 issue*/ 550 #define SET_INDEP_ASSERT_ID(func, line) \ 551 do \ 552 { \ 553 } while (0) 554 #define UnityDumpAssertResult(a, b) \ 555 do \ 556 { \ 557 } while (0) 558 void UnityDumpCaseResult(const _UU8 result, const UNITY_LINE_TYPE lineNumber); 559 #endif 560 #else 561 // empty define 562 /* add do {} while(0) because of MISRA C 2014 rule 14.3 issue*/ 563 #define UnityDumpAssertResult(a, b) \ 564 do \ 565 { \ 566 } while (0) 567 #define UnityDumpCaseResult(a, b) \ 568 do \ 569 { \ 570 } while (0) 571 #define SET_INDEP_ASSERT_ID(func, line) \ 572 do \ 573 { \ 574 } while (0) 575 #endif 576 577 //------------------------------------------------------- 578 // Basic Fail and Ignore 579 //------------------------------------------------------- 580 581 #define UNITY_TEST_FAIL(line, message) UnityFail((message), (UNITY_LINE_TYPE)line) 582 #define UNITY_TEST_IGNORE(line, message) UnityIgnore((message), (UNITY_LINE_TYPE)line) 583 //------------------------------------------------------- 584 // Test Asserts 585 //------------------------------------------------------- 586 // return false if neither is NULL 587 #ifdef UNITY_DUMP_RESULT 588 #ifdef UNITY_DUMP_COMPATIBLE_WITH_EU 589 /* add do {} while(0) because of MISRA C 2014 rule 14.3 issue*/ 590 #define UNITY_TEST_ASSERT(condition, line, message) \ 591 do \ 592 { \ 593 if (condition) \ 594 { \ 595 UnityDumpAssertResult(DUMP_RESULT_TEST_RESULT_PASS, (UNITY_LINE_TYPE)line); \ 596 } \ 597 else \ 598 { \ 599 UNITY_TEST_FAIL(line, message); \ 600 } \ 601 } while (0) 602 #else 603 #define UNITY_TEST_ASSERT(condition, line, message) \ 604 do \ 605 { \ 606 if (!condition) \ 607 { \ 608 UNITY_TEST_FAIL(line, message); \ 609 } \ 610 } while (0) 611 #endif 612 #else 613 #define UNITY_TEST_ASSERT(condition, line, message) \ 614 do \ 615 { \ 616 if (!condition) \ 617 { \ 618 UNITY_TEST_FAIL(line, message); \ 619 } \ 620 } while (0) 621 #endif 622 #define UNITY_TEST_ASSERT_NULL(pointer, line, message) \ 623 UNITY_TEST_ASSERT(((pointer) == NULL), (UNITY_LINE_TYPE)line, message) 624 #define UNITY_TEST_ASSERT_NOT_NULL(pointer, line, message) \ 625 UNITY_TEST_ASSERT(((pointer) != NULL), (UNITY_LINE_TYPE)line, message) 626 627 #define UNITY_TEST_ASSERT_EQUAL_INT(expected, actual, line, message) \ 628 UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, \ 629 UNITY_DISPLAY_STYLE_INT) 630 #define UNITY_TEST_ASSERT_EQUAL_INT8(expected, actual, line, message) \ 631 UnityAssertEqualNumber((_U_SINT)(_US8)(expected), (_U_SINT)(_US8)(actual), (message), (UNITY_LINE_TYPE)line, \ 632 UNITY_DISPLAY_STYLE_INT) 633 #define UNITY_TEST_ASSERT_EQUAL_INT16(expected, actual, line, message) \ 634 UnityAssertEqualNumber((_U_SINT)(_US16)(expected), (_U_SINT)(_US16)(actual), (message), (UNITY_LINE_TYPE)line, \ 635 UNITY_DISPLAY_STYLE_INT) 636 #define UNITY_TEST_ASSERT_EQUAL_INT32(expected, actual, line, message) \ 637 UnityAssertEqualNumber((_U_SINT)(_US32)(expected), (_U_SINT)(_US32)(actual), (message), (UNITY_LINE_TYPE)line, \ 638 UNITY_DISPLAY_STYLE_INT) 639 #define UNITY_TEST_ASSERT_EQUAL_UINT(expected, actual, line, message) \ 640 UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, \ 641 UNITY_DISPLAY_STYLE_UINT) 642 #define UNITY_TEST_ASSERT_EQUAL_UINT8(expected, actual, line, message) \ 643 UnityAssertEqualNumber((_U_SINT)(_US8)(expected), (_U_SINT)(_US8)(actual), (message), (UNITY_LINE_TYPE)line, \ 644 UNITY_DISPLAY_STYLE_UINT) 645 #define UNITY_TEST_ASSERT_EQUAL_UINT16(expected, actual, line, message) \ 646 UnityAssertEqualNumber((_U_SINT)(_US16)(expected), (_U_SINT)(_US16)(actual), (message), (UNITY_LINE_TYPE)line, \ 647 UNITY_DISPLAY_STYLE_UINT) 648 #define UNITY_TEST_ASSERT_EQUAL_UINT32(expected, actual, line, message) \ 649 UnityAssertEqualNumber((_U_SINT)(_US32)(expected), (_U_SINT)(_US32)(actual), (message), (UNITY_LINE_TYPE)line, \ 650 UNITY_DISPLAY_STYLE_UINT) 651 #define UNITY_TEST_ASSERT_EQUAL_HEX8(expected, actual, line, message) \ 652 UnityAssertEqualNumber((_U_SINT)(_US8)(expected), (_U_SINT)(_US8)(actual), (message), (UNITY_LINE_TYPE)line, \ 653 UNITY_DISPLAY_STYLE_HEX8) 654 #define UNITY_TEST_ASSERT_EQUAL_HEX16(expected, actual, line, message) \ 655 UnityAssertEqualNumber((_U_SINT)(_US16)(expected), (_U_SINT)(_US16)(actual), (message), (UNITY_LINE_TYPE)line, \ 656 UNITY_DISPLAY_STYLE_HEX16) 657 #define UNITY_TEST_ASSERT_EQUAL_HEX32(expected, actual, line, message) \ 658 UnityAssertEqualNumber((_U_SINT)(_US32)(expected), (_U_SINT)(_US32)(actual), (message), (UNITY_LINE_TYPE)line, \ 659 UNITY_DISPLAY_STYLE_HEX32) 660 #define UNITY_TEST_ASSERT_BITS(mask, expected, actual, line, message) \ 661 UnityAssertBits((_U_SINT)(mask), (_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line) 662 663 #define UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, line, message) \ 664 UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), (message), \ 665 (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT) 666 #define UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, line, message) \ 667 UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), (message), \ 668 (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT) 669 #define UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, line, message) \ 670 UnityAssertNumbersWithin((_U_SINT)(_U_UINT)(_UU8)(delta), (_U_SINT)(_U_UINT)(_UU8)(expected), \ 671 (_U_SINT)(_U_UINT)(_UU8)(actual), (message), (UNITY_LINE_TYPE)line, \ 672 UNITY_DISPLAY_STYLE_HEX8) 673 #define UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, line, message) \ 674 UnityAssertNumbersWithin((_U_SINT)(_U_UINT)(_UU16)(delta), (_U_SINT)(_U_UINT)(_UU16)(expected), \ 675 (_U_SINT)(_U_UINT)(_UU16)(actual), (message), (UNITY_LINE_TYPE)line, \ 676 UNITY_DISPLAY_STYLE_HEX16) 677 #define UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, line, message) \ 678 UnityAssertNumbersWithin((_U_SINT)(_U_UINT)(_UU32)(delta), (_U_SINT)(_U_UINT)(_UU32)(expected), \ 679 (_U_SINT)(_U_UINT)(_UU32)(actual), (message), (UNITY_LINE_TYPE)line, \ 680 UNITY_DISPLAY_STYLE_HEX32) 681 682 #define UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, line, message) \ 683 UnityAssertEqualNumber((_U_SINT)(_UP)(expected), (_U_SINT)(_UP)(actual), (message), (UNITY_LINE_TYPE)line, \ 684 UNITY_DISPLAY_STYLE_POINTER) 685 #define UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, line, message) \ 686 UnityAssertEqualString((const char *)(expected), (const char *)(actual), (message), (UNITY_LINE_TYPE)line) 687 #define UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, line, message) \ 688 UnityAssertEqualMemory((void *)(expected), (void *)(actual), (_UU32)(len), 1, (message), (UNITY_LINE_TYPE)line) 689 690 #define UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, line, message) \ 691 UnityAssertEqualIntArray((const _U_SINT *)(expected), (const _U_SINT *)(actual), (_UU32)(num_elements), (message), \ 692 (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT) 693 #define UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, line, message) \ 694 UnityAssertEqualIntArray((const _U_SINT *)(expected), (const _U_SINT *)(actual), (_UU32)(num_elements), (message), \ 695 (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT8) 696 #define UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, line, message) \ 697 UnityAssertEqualIntArray((const _U_SINT *)(expected), (const _U_SINT *)(actual), (_UU32)(num_elements), (message), \ 698 (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT16) 699 #define UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, line, message) \ 700 UnityAssertEqualIntArray((const _U_SINT *)(expected), (const _U_SINT *)(actual), (_UU32)(num_elements), (message), \ 701 (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT32) 702 #define UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, line, message) \ 703 UnityAssertEqualIntArray((const _U_SINT *)(expected), (const _U_SINT *)(actual), (_UU32)(num_elements), (message), \ 704 (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT) 705 #define UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, line, message) \ 706 UnityAssertEqualIntArray((const _U_SINT *)(expected), (const _U_SINT *)(actual), (_UU32)(num_elements), (message), \ 707 (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT8) 708 #define UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, line, message) \ 709 UnityAssertEqualIntArray((const _U_SINT *)(expected), (const _U_SINT *)(actual), (_UU32)(num_elements), (message), \ 710 (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT16) 711 #define UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, line, message) \ 712 UnityAssertEqualIntArray((const _U_SINT *)(expected), (const _U_SINT *)(actual), (_UU32)(num_elements), (message), \ 713 (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT32) 714 #define UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, line, message) \ 715 UnityAssertEqualIntArray((const _U_SINT *)(expected), (const _U_SINT *)(actual), (_UU32)(num_elements), (message), \ 716 (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8) 717 #define UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, line, message) \ 718 UnityAssertEqualIntArray((const _U_SINT *)(expected), (const _U_SINT *)(actual), (_UU32)(num_elements), (message), \ 719 (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16) 720 #define UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, line, message) \ 721 UnityAssertEqualIntArray((const _U_SINT *)(expected), (const _U_SINT *)(actual), (_UU32)(num_elements), (message), \ 722 (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32) 723 #define UNITY_TEST_ASSERT_EQUAL_PTR_ARRAY(expected, actual, num_elements, line, message) \ 724 UnityAssertEqualIntArray((const _U_SINT *)(_UP *)(expected), (const _U_SINT *)(_UP *)(actual), \ 725 (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_POINTER) 726 #define UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, line, message) \ 727 UnityAssertEqualStringArray((const char **)(expected), (const char **)(actual), (_UU32)(num_elements), (message), \ 728 (UNITY_LINE_TYPE)line) 729 #define UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, line, message) \ 730 UnityAssertEqualMemory((void *)(expected), (void *)(actual), (_UU32)(len), (_UU32)(num_elements), (message), \ 731 (UNITY_LINE_TYPE)line) 732 733 #ifdef UNITY_SUPPORT_64 734 #define UNITY_TEST_ASSERT_EQUAL_INT64(expected, actual, line, message) \ 735 UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, \ 736 UNITY_DISPLAY_STYLE_INT64) 737 #define UNITY_TEST_ASSERT_EQUAL_UINT64(expected, actual, line, message) \ 738 UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, \ 739 UNITY_DISPLAY_STYLE_UINT64) 740 #define UNITY_TEST_ASSERT_EQUAL_HEX64(expected, actual, line, message) \ 741 UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, \ 742 UNITY_DISPLAY_STYLE_HEX64) 743 #define UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, line, message) \ 744 UnityAssertEqualIntArray((const _U_SINT *)(expected), (const _U_SINT *)(actual), (_UU32)(num_elements), (message), \ 745 (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT64) 746 #define UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, line, message) \ 747 UnityAssertEqualIntArray((const _U_SINT *)(expected), (const _U_SINT *)(actual), (_UU32)(num_elements), (message), \ 748 (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT64) 749 #define UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, line, message) \ 750 UnityAssertEqualIntArray((const _U_SINT *)(expected), (const _U_SINT *)(actual), (_UU32)(num_elements), (message), \ 751 (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64) 752 #define UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, line, message) \ 753 UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, \ 754 UNITY_DISPLAY_STYLE_HEX64) 755 #endif 756 757 #ifdef UNITY_EXCLUDE_FLOAT 758 #define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) \ 759 UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") 760 #define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) \ 761 UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") 762 #define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) \ 763 UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") 764 #define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) \ 765 UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") 766 #define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) \ 767 UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") 768 #define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) \ 769 UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled") 770 #else 771 #define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) \ 772 UnityAssertFloatsWithin((_UF)(delta), (_UF)(expected), (_UF)(actual), (message), (UNITY_LINE_TYPE)line) 773 #define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) \ 774 UNITY_TEST_ASSERT_FLOAT_WITHIN((_UF)(expected) * (_UF)UNITY_FLOAT_PRECISION, (_UF)expected, (_UF)actual, \ 775 (UNITY_LINE_TYPE)line, message) 776 #define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) \ 777 UnityAssertEqualFloatArray((_UF *)(expected), (_UF *)(actual), (_UU32)(num_elements), (message), \ 778 (UNITY_LINE_TYPE)line) 779 #define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) \ 780 UnityAssertFloatIsInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line) 781 #define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) \ 782 UnityAssertFloatIsNegInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line) 783 #define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) \ 784 UnityAssertFloatIsNaN((_UF)(actual), (message), (UNITY_LINE_TYPE)line) 785 #endif 786 787 #ifdef UNITY_EXCLUDE_DOUBLE 788 #define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) \ 789 UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") 790 #define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) \ 791 UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") 792 #define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) \ 793 UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") 794 #define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) \ 795 UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") 796 #define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) \ 797 UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") 798 #define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) \ 799 UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Double Precision Disabled") 800 #else 801 #define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) \ 802 UnityAssertDoublesWithin((_UD)(delta), (_UD)(expected), (_UD)(actual), (message), (UNITY_LINE_TYPE)line) 803 #define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) \ 804 UNITY_TEST_ASSERT_DOUBLE_WITHIN((_UF)(expected) * (_UD)UNITY_DOUBLE_PRECISION, (_UD)expected, (_UD)actual, \ 805 (UNITY_LINE_TYPE)line, message) 806 #define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) \ 807 UnityAssertEqualDoubleArray((_UD *)(expected), (_UD *)(actual), (_UU32)(num_elements), (message), \ 808 (UNITY_LINE_TYPE)line) 809 #define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) \ 810 UnityAssertFloatIsInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line) 811 #define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) \ 812 UnityAssertFloatIsNegInf((_UF)(actual), (message), (UNITY_LINE_TYPE)line) 813 #define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) \ 814 UnityAssertFloatIsNaN((_UF)(actual), (message), (UNITY_LINE_TYPE)line) 815 #endif 816 817 #endif 818