Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510
unity.c
00001 /* ========================================================================= 00002 Unity Project - A Test Framework for C 00003 Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams 00004 [Released under MIT License. Please refer to license.txt for details] 00005 ============================================================================ */ 00006 00007 #include "unity/unity.h" 00008 #include "utest/unity_handler.h" 00009 #include <stddef.h> 00010 00011 /* If omitted from header, declare overrideable prototypes here so they're ready for use */ 00012 #ifdef UNITY_OMIT_OUTPUT_CHAR_HEADER_DECLARATION 00013 int UNITY_OUTPUT_CHAR(int); 00014 #endif 00015 #ifdef UNITY_OMIT_OUTPUT_FLUSH_HEADER_DECLARATION 00016 int UNITY_OUTPUT_FLUSH(void); 00017 #endif 00018 00019 /* Helpful macros for us to use here */ 00020 #define UNITY_FAIL_AND_BAIL { UNITY_OUTPUT_CHAR('\n'); utest_unity_assert_failure(); } 00021 #define UNITY_IGNORE_AND_BAIL { UNITY_OUTPUT_CHAR('\n'); utest_unity_ignore_failure(); } 00022 00023 /* return prematurely if we are already in failure or ignore state */ 00024 #define UNITY_SKIP_EXECUTION { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} } 00025 00026 struct _Unity Unity; 00027 00028 static const char UnityStrOk[] = "OK"; 00029 static const char UnityStrPass[] = "PASS"; 00030 static const char UnityStrFail[] = "FAIL"; 00031 static const char UnityStrIgnore[] = "IGNORE"; 00032 static const char UnityStrNull[] = "NULL"; 00033 static const char UnityStrSpacer[] = ". "; 00034 static const char UnityStrExpected[] = " Expected "; 00035 static const char UnityStrWas[] = " Was "; 00036 static const char UnityStrElement[] = " Element "; 00037 static const char UnityStrByte[] = " Byte "; 00038 static const char UnityStrMemory[] = " Memory Mismatch."; 00039 static const char UnityStrDelta[] = " Values Not Within Delta "; 00040 static const char UnityStrPointless[] = " You Asked Me To Compare Nothing, Which Was Pointless."; 00041 static const char UnityStrNullPointerForExpected[] = " Expected pointer to be NULL"; 00042 static const char UnityStrNullPointerForActual[] = " Actual pointer was NULL"; 00043 static const char UnityStrNot[] = "Not "; 00044 static const char UnityStrInf[] = "Infinity"; 00045 static const char UnityStrNegInf[] = "Negative Infinity"; 00046 static const char UnityStrNaN[] = "NaN"; 00047 static const char UnityStrDet[] = "Determinate"; 00048 static const char UnityStrInvalidFloatTrait[] = "Invalid Float Trait"; 00049 const char UnityStrErrFloat[] = "Unity Floating Point Disabled"; 00050 const char UnityStrErrDouble[] = "Unity Double Precision Disabled"; 00051 const char UnityStrErr64[] = "Unity 64-bit Support Disabled"; 00052 static const char UnityStrBreaker[] = "-----------------------"; 00053 static const char UnityStrResultsTests[] = " Tests "; 00054 static const char UnityStrResultsFailures[] = " Failures "; 00055 static const char UnityStrResultsIgnored[] = " Ignored "; 00056 static const char UnityStrDetail1Name[] = UNITY_DETAIL1_NAME " "; 00057 static const char UnityStrDetail2Name[] = " " UNITY_DETAIL2_NAME " "; 00058 00059 #ifdef UNITY_FLOAT_NEEDS_ZERO 00060 /* Dividing by these constants produces +/- infinity. 00061 * The rationale is given in UnityAssertFloatIsInf's body. */ 00062 static const _UF f_zero = 0.0f; 00063 #endif 00064 00065 /* compiler-generic print formatting masks */ 00066 static const _U_UINT UnitySizeMask[] = 00067 { 00068 255u, /* 0xFF */ 00069 65535u, /* 0xFFFF */ 00070 65535u, 00071 4294967295u, /* 0xFFFFFFFF */ 00072 4294967295u, 00073 4294967295u, 00074 4294967295u 00075 #ifdef UNITY_SUPPORT_64 00076 ,0xFFFFFFFFFFFFFFFFull 00077 #endif 00078 }; 00079 00080 /*----------------------------------------------- 00081 * Pretty Printers & Test Result Output Handlers 00082 *-----------------------------------------------*/ 00083 00084 void UnityPrint(const char* string) 00085 { 00086 const char* pch = string; 00087 00088 if (pch != NULL) 00089 { 00090 while (*pch) 00091 { 00092 /* printable characters plus CR & LF are printed */ 00093 if ((*pch <= 126) && (*pch >= 32)) 00094 { 00095 UNITY_OUTPUT_CHAR(*pch); 00096 } 00097 /* write escaped carriage returns */ 00098 else if (*pch == 13) 00099 { 00100 UNITY_OUTPUT_CHAR('\\'); 00101 UNITY_OUTPUT_CHAR('r'); 00102 } 00103 /* write escaped line feeds */ 00104 else if (*pch == 10) 00105 { 00106 UNITY_OUTPUT_CHAR('\\'); 00107 UNITY_OUTPUT_CHAR('n'); 00108 } 00109 /* unprintable characters are shown as codes */ 00110 else 00111 { 00112 UNITY_OUTPUT_CHAR('\\'); 00113 UnityPrintNumberHex((_U_UINT)*pch, 2); 00114 } 00115 pch++; 00116 } 00117 } 00118 } 00119 00120 void UnityPrintLen(const char* string, const _UU32 length); 00121 void UnityPrintLen(const char* string, const _UU32 length) 00122 { 00123 const char* pch = string; 00124 00125 if (pch != NULL) 00126 { 00127 while (*pch && (_UU32)(pch - string) < length) 00128 { 00129 /* printable characters plus CR & LF are printed */ 00130 if ((*pch <= 126) && (*pch >= 32)) 00131 { 00132 UNITY_OUTPUT_CHAR(*pch); 00133 } 00134 /* write escaped carriage returns */ 00135 else if (*pch == 13) 00136 { 00137 UNITY_OUTPUT_CHAR('\\'); 00138 UNITY_OUTPUT_CHAR('r'); 00139 } 00140 /* write escaped line feeds */ 00141 else if (*pch == 10) 00142 { 00143 UNITY_OUTPUT_CHAR('\\'); 00144 UNITY_OUTPUT_CHAR('n'); 00145 } 00146 /* unprintable characters are shown as codes */ 00147 else 00148 { 00149 UNITY_OUTPUT_CHAR('\\'); 00150 UnityPrintNumberHex((_U_UINT)*pch, 2); 00151 } 00152 pch++; 00153 } 00154 } 00155 } 00156 00157 /*-----------------------------------------------*/ 00158 void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style) 00159 { 00160 if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) 00161 { 00162 UnityPrintNumber(number); 00163 } 00164 else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT) 00165 { 00166 UnityPrintNumberUnsigned( (_U_UINT)number & UnitySizeMask[((_U_UINT)style & (_U_UINT)0x0F) - 1] ); 00167 } 00168 else 00169 { 00170 UnityPrintNumberHex((_U_UINT)number, (char)((style & 0x000F) << 1)); 00171 } 00172 } 00173 00174 /*-----------------------------------------------*/ 00175 void UnityPrintNumber(const _U_SINT number_to_print) 00176 { 00177 _U_UINT number = (_U_UINT)number_to_print; 00178 00179 if (number_to_print < 0) 00180 { 00181 /* A negative number, including MIN negative */ 00182 UNITY_OUTPUT_CHAR('-'); 00183 number = (_U_UINT)(-number_to_print); 00184 } 00185 UnityPrintNumberUnsigned(number); 00186 } 00187 00188 /*----------------------------------------------- 00189 * basically do an itoa using as little ram as possible */ 00190 void UnityPrintNumberUnsigned(const _U_UINT number) 00191 { 00192 _U_UINT divisor = 1; 00193 00194 /* figure out initial divisor */ 00195 while (number / divisor > 9) 00196 { 00197 divisor *= 10; 00198 } 00199 00200 /* now mod and print, then divide divisor */ 00201 do 00202 { 00203 UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10))); 00204 divisor /= 10; 00205 } 00206 while (divisor > 0); 00207 } 00208 00209 /*-----------------------------------------------*/ 00210 void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print) 00211 { 00212 _U_UINT nibble; 00213 char nibbles = nibbles_to_print; 00214 UNITY_OUTPUT_CHAR('0'); 00215 UNITY_OUTPUT_CHAR('x'); 00216 00217 while (nibbles > 0) 00218 { 00219 nibble = (number >> (--nibbles << 2)) & 0x0000000F; 00220 if (nibble <= 9) 00221 { 00222 UNITY_OUTPUT_CHAR((char)('0' + nibble)); 00223 } 00224 else 00225 { 00226 UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble)); 00227 } 00228 } 00229 } 00230 00231 /*-----------------------------------------------*/ 00232 void UnityPrintMask(const _U_UINT mask, const _U_UINT number) 00233 { 00234 _U_UINT current_bit = (_U_UINT)1 << (UNITY_INT_WIDTH - 1); 00235 _US32 i; 00236 00237 for (i = 0; i < UNITY_INT_WIDTH; i++) 00238 { 00239 if (current_bit & mask) 00240 { 00241 if (current_bit & number) 00242 { 00243 UNITY_OUTPUT_CHAR('1'); 00244 } 00245 else 00246 { 00247 UNITY_OUTPUT_CHAR('0'); 00248 } 00249 } 00250 else 00251 { 00252 UNITY_OUTPUT_CHAR('.'); 00253 } 00254 current_bit = current_bit >> 1; 00255 } 00256 } 00257 00258 /*-----------------------------------------------*/ 00259 #ifdef UNITY_FLOAT_VERBOSE 00260 #include <stdio.h> 00261 00262 #ifndef UNITY_VERBOSE_NUMBER_MAX_LENGTH 00263 # ifdef UNITY_DOUBLE_VERBOSE 00264 # define UNITY_VERBOSE_NUMBER_MAX_LENGTH 317 00265 # else 00266 # define UNITY_VERBOSE_NUMBER_MAX_LENGTH 47 00267 # endif 00268 #endif 00269 00270 void UnityPrintFloat(_UF number) 00271 { 00272 char TempBuffer[UNITY_VERBOSE_NUMBER_MAX_LENGTH + 1]; 00273 snprintf(TempBuffer, sizeof(TempBuffer), "%.6f", number); 00274 UnityPrint(TempBuffer); 00275 } 00276 #endif 00277 00278 /*-----------------------------------------------*/ 00279 00280 void UnityPrintFail(void); 00281 void UnityPrintFail(void) 00282 { 00283 UnityPrint(UnityStrFail); 00284 } 00285 00286 void UnityPrintOk(void); 00287 void UnityPrintOk(void) 00288 { 00289 UnityPrint(UnityStrOk); 00290 } 00291 00292 /*-----------------------------------------------*/ 00293 static void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line); 00294 static void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line) 00295 { 00296 #ifndef UNITY_FIXTURES 00297 UnityPrint(file); 00298 UNITY_OUTPUT_CHAR(':'); 00299 UnityPrintNumber((_U_SINT)line); 00300 UNITY_OUTPUT_CHAR(':'); 00301 UnityPrint(Unity.CurrentTestName); 00302 UNITY_OUTPUT_CHAR(':'); 00303 #else 00304 UNITY_UNUSED(file); 00305 UNITY_UNUSED(line); 00306 #endif 00307 } 00308 00309 /*-----------------------------------------------*/ 00310 static void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line); 00311 static void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line) 00312 { 00313 #ifndef UNITY_FIXTURES 00314 UnityTestResultsBegin(Unity.TestFile, line); 00315 #else 00316 UNITY_UNUSED(line); 00317 #endif 00318 UnityPrint(UnityStrFail); 00319 UNITY_OUTPUT_CHAR(':'); 00320 } 00321 00322 /*-----------------------------------------------*/ 00323 void UnityConcludeTest(void) 00324 { 00325 if (Unity.CurrentTestIgnored) 00326 { 00327 Unity.TestIgnores++; 00328 } 00329 else if (!Unity.CurrentTestFailed) 00330 { 00331 UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber); 00332 UnityPrint(UnityStrPass); 00333 } 00334 else 00335 { 00336 Unity.TestFailures++; 00337 } 00338 00339 Unity.CurrentTestFailed = 0; 00340 Unity.CurrentTestIgnored = 0; 00341 UNITY_PRINT_EOL(); 00342 UNITY_OUTPUT_FLUSH(); 00343 } 00344 00345 /*-----------------------------------------------*/ 00346 static void UnityAddMsgIfSpecified(const char* msg); 00347 static void UnityAddMsgIfSpecified(const char* msg) 00348 { 00349 if (msg) 00350 { 00351 UnityPrint(UnityStrSpacer); 00352 #ifndef UNITY_EXCLUDE_DETAILS 00353 if (Unity.CurrentDetail1) 00354 { 00355 UnityPrint(UnityStrDetail1Name); 00356 UnityPrint(Unity.CurrentDetail1); 00357 if (Unity.CurrentDetail2) 00358 { 00359 UnityPrint(UnityStrDetail2Name); 00360 UnityPrint(Unity.CurrentDetail2); 00361 } 00362 UnityPrint(UnityStrSpacer); 00363 } 00364 #endif 00365 UnityPrint(msg); 00366 } 00367 } 00368 00369 /*-----------------------------------------------*/ 00370 static void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual); 00371 static void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual) 00372 { 00373 UnityPrint(UnityStrExpected); 00374 if (expected != NULL) 00375 { 00376 UNITY_OUTPUT_CHAR('\''); 00377 UnityPrint(expected); 00378 UNITY_OUTPUT_CHAR('\''); 00379 } 00380 else 00381 { 00382 UnityPrint(UnityStrNull); 00383 } 00384 UnityPrint(UnityStrWas); 00385 if (actual != NULL) 00386 { 00387 UNITY_OUTPUT_CHAR('\''); 00388 UnityPrint(actual); 00389 UNITY_OUTPUT_CHAR('\''); 00390 } 00391 else 00392 { 00393 UnityPrint(UnityStrNull); 00394 } 00395 } 00396 00397 /*-----------------------------------------------*/ 00398 static void UnityPrintExpectedAndActualStringsLen(const char* expected, const char* actual, const _UU32 length) 00399 { 00400 UnityPrint(UnityStrExpected); 00401 if (expected != NULL) 00402 { 00403 UNITY_OUTPUT_CHAR('\''); 00404 UnityPrintLen(expected, length); 00405 UNITY_OUTPUT_CHAR('\''); 00406 } 00407 else 00408 { 00409 UnityPrint(UnityStrNull); 00410 } 00411 UnityPrint(UnityStrWas); 00412 if (actual != NULL) 00413 { 00414 UNITY_OUTPUT_CHAR('\''); 00415 UnityPrintLen(actual, length); 00416 UNITY_OUTPUT_CHAR('\''); 00417 } 00418 else 00419 { 00420 UnityPrint(UnityStrNull); 00421 } 00422 } 00423 00424 00425 00426 /*----------------------------------------------- 00427 * Assertion & Control Helpers 00428 *-----------------------------------------------*/ 00429 00430 static int UnityCheckArraysForNull(UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_PTR actual, const UNITY_LINE_TYPE lineNumber, const char* msg) 00431 { 00432 /* return true if they are both NULL */ 00433 if ((expected == NULL) && (actual == NULL)) 00434 return 1; 00435 00436 /* throw error if just expected is NULL */ 00437 if (expected == NULL) 00438 { 00439 UnityTestResultsFailBegin(lineNumber); 00440 UnityPrint(UnityStrNullPointerForExpected); 00441 UnityAddMsgIfSpecified(msg); 00442 UNITY_FAIL_AND_BAIL; 00443 } 00444 00445 /* throw error if just actual is NULL */ 00446 if (actual == NULL) 00447 { 00448 UnityTestResultsFailBegin(lineNumber); 00449 UnityPrint(UnityStrNullPointerForActual); 00450 UnityAddMsgIfSpecified(msg); 00451 UNITY_FAIL_AND_BAIL; 00452 } 00453 00454 /* return false if neither is NULL */ 00455 return 0; 00456 } 00457 00458 /*----------------------------------------------- 00459 * Assertion Functions 00460 *-----------------------------------------------*/ 00461 00462 void UnityAssertBits(const _U_SINT mask, 00463 const _U_SINT expected, 00464 const _U_SINT actual, 00465 const char* msg, 00466 const UNITY_LINE_TYPE lineNumber) 00467 { 00468 UNITY_SKIP_EXECUTION; 00469 00470 if ((mask & expected) != (mask & actual)) 00471 { 00472 UnityTestResultsFailBegin(lineNumber); 00473 UnityPrint(UnityStrExpected); 00474 UnityPrintMask((_U_UINT)mask, (_U_UINT)expected); 00475 UnityPrint(UnityStrWas); 00476 UnityPrintMask((_U_UINT)mask, (_U_UINT)actual); 00477 UnityAddMsgIfSpecified(msg); 00478 UNITY_FAIL_AND_BAIL; 00479 } 00480 } 00481 00482 /*-----------------------------------------------*/ 00483 void UnityAssertEqualNumber(const _U_SINT expected, 00484 const _U_SINT actual, 00485 const char* msg, 00486 const UNITY_LINE_TYPE lineNumber, 00487 const UNITY_DISPLAY_STYLE_T style) 00488 { 00489 UNITY_SKIP_EXECUTION; 00490 00491 if (expected != actual) 00492 { 00493 UnityTestResultsFailBegin(lineNumber); 00494 UnityPrint(UnityStrExpected); 00495 UnityPrintNumberByStyle(expected, style); 00496 UnityPrint(UnityStrWas); 00497 UnityPrintNumberByStyle(actual, style); 00498 UnityAddMsgIfSpecified(msg); 00499 UNITY_FAIL_AND_BAIL; 00500 } 00501 } 00502 00503 #define UnityPrintPointlessAndBail() \ 00504 { \ 00505 UnityTestResultsFailBegin(lineNumber); \ 00506 UnityPrint(UnityStrPointless); \ 00507 UnityAddMsgIfSpecified(msg); \ 00508 UNITY_FAIL_AND_BAIL; } 00509 00510 /*-----------------------------------------------*/ 00511 void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, 00512 UNITY_INTERNAL_PTR actual, 00513 const _UU32 num_elements, 00514 const char* msg, 00515 const UNITY_LINE_TYPE lineNumber, 00516 const UNITY_DISPLAY_STYLE_T style) 00517 { 00518 _UU32 elements = num_elements; 00519 UNITY_INTERNAL_PTR ptr_exp = (UNITY_INTERNAL_PTR)expected; 00520 UNITY_INTERNAL_PTR ptr_act = (UNITY_INTERNAL_PTR)actual; 00521 00522 UNITY_SKIP_EXECUTION; 00523 00524 if (elements == 0) 00525 { 00526 UnityPrintPointlessAndBail(); 00527 } 00528 00529 if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1) 00530 return; 00531 00532 /* If style is UNITY_DISPLAY_STYLE_INT, we'll fall into the default case rather than the INT16 or INT32 (etc) case 00533 * as UNITY_DISPLAY_STYLE_INT includes a flag for UNITY_DISPLAY_RANGE_AUTO, which the width-specific 00534 * variants do not. Therefore remove this flag. */ 00535 switch(style & (UNITY_DISPLAY_STYLE_T)(~UNITY_DISPLAY_RANGE_AUTO)) 00536 { 00537 case UNITY_DISPLAY_STYLE_HEX8: 00538 case UNITY_DISPLAY_STYLE_INT8: 00539 case UNITY_DISPLAY_STYLE_UINT8: 00540 while (elements--) 00541 { 00542 if (*(UNITY_PTR_ATTRIBUTE const _US8*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US8*)ptr_act) 00543 { 00544 UnityTestResultsFailBegin(lineNumber); 00545 UnityPrint(UnityStrElement); 00546 UnityPrintNumberUnsigned(num_elements - elements - 1); 00547 UnityPrint(UnityStrExpected); 00548 UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US8*)ptr_exp, style); 00549 UnityPrint(UnityStrWas); 00550 UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US8*)ptr_act, style); 00551 UnityAddMsgIfSpecified(msg); 00552 UNITY_FAIL_AND_BAIL; 00553 } 00554 ptr_exp = (UNITY_INTERNAL_PTR)((_UP)ptr_exp + 1); 00555 ptr_act = (UNITY_INTERNAL_PTR)((_UP)ptr_act + 1); 00556 } 00557 break; 00558 case UNITY_DISPLAY_STYLE_HEX16: 00559 case UNITY_DISPLAY_STYLE_INT16: 00560 case UNITY_DISPLAY_STYLE_UINT16: 00561 while (elements--) 00562 { 00563 if (*(UNITY_PTR_ATTRIBUTE const _US16*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US16*)ptr_act) 00564 { 00565 UnityTestResultsFailBegin(lineNumber); 00566 UnityPrint(UnityStrElement); 00567 UnityPrintNumberUnsigned(num_elements - elements - 1); 00568 UnityPrint(UnityStrExpected); 00569 UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US16*)ptr_exp, style); 00570 UnityPrint(UnityStrWas); 00571 UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US16*)ptr_act, style); 00572 UnityAddMsgIfSpecified(msg); 00573 UNITY_FAIL_AND_BAIL; 00574 } 00575 ptr_exp = (UNITY_INTERNAL_PTR)((_UP)ptr_exp + 2); 00576 ptr_act = (UNITY_INTERNAL_PTR)((_UP)ptr_act + 2); 00577 } 00578 break; 00579 #ifdef UNITY_SUPPORT_64 00580 case UNITY_DISPLAY_STYLE_HEX64: 00581 case UNITY_DISPLAY_STYLE_INT64: 00582 case UNITY_DISPLAY_STYLE_UINT64: 00583 while (elements--) 00584 { 00585 if (*(UNITY_PTR_ATTRIBUTE const _US64*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US64*)ptr_act) 00586 { 00587 UnityTestResultsFailBegin(lineNumber); 00588 UnityPrint(UnityStrElement); 00589 UnityPrintNumberUnsigned(num_elements - elements - 1); 00590 UnityPrint(UnityStrExpected); 00591 UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US64*)ptr_exp, style); 00592 UnityPrint(UnityStrWas); 00593 UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US64*)ptr_act, style); 00594 UnityAddMsgIfSpecified(msg); 00595 UNITY_FAIL_AND_BAIL; 00596 } 00597 ptr_exp = (UNITY_INTERNAL_PTR)((_UP)ptr_exp + 8); 00598 ptr_act = (UNITY_INTERNAL_PTR)((_UP)ptr_act + 8); 00599 } 00600 break; 00601 #endif 00602 default: 00603 while (elements--) 00604 { 00605 if (*(UNITY_PTR_ATTRIBUTE const _US32*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US32*)ptr_act) 00606 { 00607 UnityTestResultsFailBegin(lineNumber); 00608 UnityPrint(UnityStrElement); 00609 UnityPrintNumberUnsigned(num_elements - elements - 1); 00610 UnityPrint(UnityStrExpected); 00611 UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US32*)ptr_exp, style); 00612 UnityPrint(UnityStrWas); 00613 UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US32*)ptr_act, style); 00614 UnityAddMsgIfSpecified(msg); 00615 UNITY_FAIL_AND_BAIL; 00616 } 00617 ptr_exp = (UNITY_INTERNAL_PTR)((_UP)ptr_exp + 4); 00618 ptr_act = (UNITY_INTERNAL_PTR)((_UP)ptr_act + 4); 00619 } 00620 break; 00621 } 00622 } 00623 00624 /*-----------------------------------------------*/ 00625 #ifndef UNITY_EXCLUDE_FLOAT 00626 void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected, 00627 UNITY_PTR_ATTRIBUTE const _UF* actual, 00628 const _UU32 num_elements, 00629 const char* msg, 00630 const UNITY_LINE_TYPE lineNumber) 00631 { 00632 _UU32 elements = num_elements; 00633 UNITY_PTR_ATTRIBUTE const _UF* ptr_expected = expected; 00634 UNITY_PTR_ATTRIBUTE const _UF* ptr_actual = actual; 00635 _UF diff, tol; 00636 00637 UNITY_SKIP_EXECUTION; 00638 00639 if (elements == 0) 00640 { 00641 UnityPrintPointlessAndBail(); 00642 } 00643 00644 if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1) 00645 return; 00646 00647 while (elements--) 00648 { 00649 diff = *ptr_expected - *ptr_actual; 00650 if (diff < 0.0f) 00651 diff = 0.0f - diff; 00652 tol = UNITY_FLOAT_PRECISION * *ptr_expected; 00653 if (tol < 0.0f) 00654 tol = 0.0f - tol; 00655 00656 /* This first part of this condition will catch any NaN or Infinite values */ 00657 if (isnan(diff) || isinf(diff) || (diff > tol)) 00658 { 00659 UnityTestResultsFailBegin(lineNumber); 00660 UnityPrint(UnityStrElement); 00661 UnityPrintNumberUnsigned(num_elements - elements - 1); 00662 #ifdef UNITY_FLOAT_VERBOSE 00663 UnityPrint(UnityStrExpected); 00664 UnityPrintFloat(*ptr_expected); 00665 UnityPrint(UnityStrWas); 00666 UnityPrintFloat(*ptr_actual); 00667 #else 00668 UnityPrint(UnityStrDelta); 00669 #endif 00670 UnityAddMsgIfSpecified(msg); 00671 UNITY_FAIL_AND_BAIL; 00672 } 00673 ptr_expected++; 00674 ptr_actual++; 00675 } 00676 } 00677 00678 /*-----------------------------------------------*/ 00679 void UnityAssertFloatsWithin(const _UF delta, 00680 const _UF expected, 00681 const _UF actual, 00682 const char* msg, 00683 const UNITY_LINE_TYPE lineNumber) 00684 { 00685 _UF diff = actual - expected; 00686 _UF pos_delta = delta; 00687 00688 UNITY_SKIP_EXECUTION; 00689 00690 if (diff < 0.0f) 00691 { 00692 diff = 0.0f - diff; 00693 } 00694 if (pos_delta < 0.0f) 00695 { 00696 pos_delta = 0.0f - pos_delta; 00697 } 00698 00699 /* This first part of this condition will catch any NaN or Infinite values */ 00700 if (isnan(diff) || isinf(diff) || (pos_delta < diff)) 00701 { 00702 UnityTestResultsFailBegin(lineNumber); 00703 #ifdef UNITY_FLOAT_VERBOSE 00704 UnityPrint(UnityStrExpected); 00705 UnityPrintFloat(expected); 00706 UnityPrint(UnityStrWas); 00707 UnityPrintFloat(actual); 00708 #else 00709 UnityPrint(UnityStrDelta); 00710 #endif 00711 UnityAddMsgIfSpecified(msg); 00712 UNITY_FAIL_AND_BAIL; 00713 } 00714 } 00715 00716 /*-----------------------------------------------*/ 00717 void UnityAssertFloatSpecial(const _UF actual, 00718 const char* msg, 00719 const UNITY_LINE_TYPE lineNumber, 00720 const UNITY_FLOAT_TRAIT_T style) 00721 { 00722 const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet }; 00723 _U_SINT should_be_trait = ((_U_SINT)style & 1); 00724 _U_SINT is_trait = !should_be_trait; 00725 _U_SINT trait_index = (_U_SINT)(style >> 1); 00726 00727 UNITY_SKIP_EXECUTION; 00728 00729 switch(style) 00730 { 00731 /* To determine Inf / Neg Inf, we compare to an Inf / Neg Inf value we create on the fly 00732 * We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise */ 00733 case UNITY_FLOAT_IS_INF: 00734 case UNITY_FLOAT_IS_NOT_INF: 00735 is_trait = isinf(actual) & ispos(actual); 00736 break; 00737 case UNITY_FLOAT_IS_NEG_INF: 00738 case UNITY_FLOAT_IS_NOT_NEG_INF: 00739 is_trait = isinf(actual) & isneg(actual); 00740 break; 00741 00742 /* NaN is the only floating point value that does NOT equal itself. Therefore if Actual == Actual, then it is NOT NaN. */ 00743 case UNITY_FLOAT_IS_NAN: 00744 case UNITY_FLOAT_IS_NOT_NAN: 00745 is_trait = isnan(actual); 00746 break; 00747 00748 /* A determinate number is non infinite and not NaN. (therefore the opposite of the two above) */ 00749 case UNITY_FLOAT_IS_DET: 00750 case UNITY_FLOAT_IS_NOT_DET: 00751 if (isinf(actual) | isnan(actual)) 00752 is_trait = 0; 00753 else 00754 is_trait = 1; 00755 break; 00756 00757 default: 00758 trait_index = 0; 00759 trait_names[0] = UnityStrInvalidFloatTrait; 00760 break; 00761 } 00762 00763 if (is_trait != should_be_trait) 00764 { 00765 UnityTestResultsFailBegin(lineNumber); 00766 UnityPrint(UnityStrExpected); 00767 if (!should_be_trait) 00768 UnityPrint(UnityStrNot); 00769 UnityPrint(trait_names[trait_index]); 00770 UnityPrint(UnityStrWas); 00771 #ifdef UNITY_FLOAT_VERBOSE 00772 UnityPrintFloat(actual); 00773 #else 00774 if (should_be_trait) 00775 UnityPrint(UnityStrNot); 00776 UnityPrint(trait_names[trait_index]); 00777 #endif 00778 UnityAddMsgIfSpecified(msg); 00779 UNITY_FAIL_AND_BAIL; 00780 } 00781 } 00782 00783 #endif /* not UNITY_EXCLUDE_FLOAT */ 00784 00785 /*-----------------------------------------------*/ 00786 #ifndef UNITY_EXCLUDE_DOUBLE 00787 void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected, 00788 UNITY_PTR_ATTRIBUTE const _UD* actual, 00789 const _UU32 num_elements, 00790 const char* msg, 00791 const UNITY_LINE_TYPE lineNumber) 00792 { 00793 _UU32 elements = num_elements; 00794 UNITY_PTR_ATTRIBUTE const _UD* ptr_expected = expected; 00795 UNITY_PTR_ATTRIBUTE const _UD* ptr_actual = actual; 00796 _UD diff, tol; 00797 00798 UNITY_SKIP_EXECUTION; 00799 00800 if (elements == 0) 00801 { 00802 UnityPrintPointlessAndBail(); 00803 } 00804 00805 if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1) 00806 return; 00807 00808 while (elements--) 00809 { 00810 diff = *ptr_expected - *ptr_actual; 00811 if (diff < 0.0) 00812 diff = 0.0 - diff; 00813 tol = UNITY_DOUBLE_PRECISION * *ptr_expected; 00814 if (tol < 0.0) 00815 tol = 0.0 - tol; 00816 00817 /* This first part of this condition will catch any NaN or Infinite values */ 00818 if (isnan(diff) || isinf(diff) || (diff > tol)) 00819 { 00820 UnityTestResultsFailBegin(lineNumber); 00821 UnityPrint(UnityStrElement); 00822 UnityPrintNumberUnsigned(num_elements - elements - 1); 00823 #ifdef UNITY_DOUBLE_VERBOSE 00824 UnityPrint(UnityStrExpected); 00825 UnityPrintFloat((float)(*ptr_expected)); 00826 UnityPrint(UnityStrWas); 00827 UnityPrintFloat((float)(*ptr_actual)); 00828 #else 00829 UnityPrint(UnityStrDelta); 00830 #endif 00831 UnityAddMsgIfSpecified(msg); 00832 UNITY_FAIL_AND_BAIL; 00833 } 00834 ptr_expected++; 00835 ptr_actual++; 00836 } 00837 } 00838 00839 /*-----------------------------------------------*/ 00840 void UnityAssertDoublesWithin(const _UD delta, 00841 const _UD expected, 00842 const _UD actual, 00843 const char* msg, 00844 const UNITY_LINE_TYPE lineNumber) 00845 { 00846 _UD diff = actual - expected; 00847 _UD pos_delta = delta; 00848 00849 UNITY_SKIP_EXECUTION; 00850 00851 if (diff < 0.0) 00852 { 00853 diff = 0.0 - diff; 00854 } 00855 if (pos_delta < 0.0) 00856 { 00857 pos_delta = 0.0 - pos_delta; 00858 } 00859 00860 /* This first part of this condition will catch any NaN or Infinite values */ 00861 if (isnan(diff) || isinf(diff) || (pos_delta < diff)) 00862 { 00863 UnityTestResultsFailBegin(lineNumber); 00864 #ifdef UNITY_DOUBLE_VERBOSE 00865 UnityPrint(UnityStrExpected); 00866 UnityPrintFloat((float)expected); 00867 UnityPrint(UnityStrWas); 00868 UnityPrintFloat((float)actual); 00869 #else 00870 UnityPrint(UnityStrDelta); 00871 #endif 00872 UnityAddMsgIfSpecified(msg); 00873 UNITY_FAIL_AND_BAIL; 00874 } 00875 } 00876 00877 /*-----------------------------------------------*/ 00878 00879 void UnityAssertDoubleSpecial(const _UD actual, 00880 const char* msg, 00881 const UNITY_LINE_TYPE lineNumber, 00882 const UNITY_FLOAT_TRAIT_T style) 00883 { 00884 const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet }; 00885 _U_SINT should_be_trait = ((_U_SINT)style & 1); 00886 _U_SINT is_trait = !should_be_trait; 00887 _U_SINT trait_index = (_U_SINT)(style >> 1); 00888 00889 UNITY_SKIP_EXECUTION; 00890 00891 switch(style) 00892 { 00893 /* To determine Inf / Neg Inf, we compare to an Inf / Neg Inf value we create on the fly 00894 * We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise */ 00895 case UNITY_FLOAT_IS_INF: 00896 case UNITY_FLOAT_IS_NOT_INF: 00897 is_trait = isinf(actual) & ispos(actual); 00898 break; 00899 case UNITY_FLOAT_IS_NEG_INF: 00900 case UNITY_FLOAT_IS_NOT_NEG_INF: 00901 is_trait = isinf(actual) & isneg(actual); 00902 break; 00903 00904 /* NaN is the only floating point value that does NOT equal itself. Therefore if Actual == Actual, then it is NOT NaN. */ 00905 case UNITY_FLOAT_IS_NAN: 00906 case UNITY_FLOAT_IS_NOT_NAN: 00907 is_trait = isnan(actual); 00908 break; 00909 00910 /* A determinate number is non infinite and not NaN. (therefore the opposite of the two above) */ 00911 case UNITY_FLOAT_IS_DET: 00912 case UNITY_FLOAT_IS_NOT_DET: 00913 if (isinf(actual) | isnan(actual)) 00914 is_trait = 0; 00915 else 00916 is_trait = 1; 00917 break; 00918 00919 default: 00920 trait_index = 0; 00921 trait_names[0] = UnityStrInvalidFloatTrait; 00922 break; 00923 } 00924 00925 if (is_trait != should_be_trait) 00926 { 00927 UnityTestResultsFailBegin(lineNumber); 00928 UnityPrint(UnityStrExpected); 00929 if (!should_be_trait) 00930 UnityPrint(UnityStrNot); 00931 UnityPrint(trait_names[trait_index]); 00932 UnityPrint(UnityStrWas); 00933 #ifdef UNITY_DOUBLE_VERBOSE 00934 UnityPrintFloat(actual); 00935 #else 00936 if (should_be_trait) 00937 UnityPrint(UnityStrNot); 00938 UnityPrint(trait_names[trait_index]); 00939 #endif 00940 UnityAddMsgIfSpecified(msg); 00941 UNITY_FAIL_AND_BAIL; 00942 } 00943 } 00944 00945 00946 #endif /* not UNITY_EXCLUDE_DOUBLE */ 00947 00948 /*-----------------------------------------------*/ 00949 void UnityAssertNumbersWithin( const _U_UINT delta, 00950 const _U_SINT expected, 00951 const _U_SINT actual, 00952 const char* msg, 00953 const UNITY_LINE_TYPE lineNumber, 00954 const UNITY_DISPLAY_STYLE_T style) 00955 { 00956 UNITY_SKIP_EXECUTION; 00957 00958 if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) 00959 { 00960 if (actual > expected) 00961 Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > delta); 00962 else 00963 Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > delta); 00964 } 00965 else 00966 { 00967 if ((_U_UINT)actual > (_U_UINT)expected) 00968 Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > delta); 00969 else 00970 Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > delta); 00971 } 00972 00973 if (Unity.CurrentTestFailed) 00974 { 00975 UnityTestResultsFailBegin(lineNumber); 00976 UnityPrint(UnityStrDelta); 00977 UnityPrintNumberByStyle((_U_SINT)delta, style); 00978 UnityPrint(UnityStrExpected); 00979 UnityPrintNumberByStyle(expected, style); 00980 UnityPrint(UnityStrWas); 00981 UnityPrintNumberByStyle(actual, style); 00982 UnityAddMsgIfSpecified(msg); 00983 UNITY_FAIL_AND_BAIL; 00984 } 00985 } 00986 00987 /*-----------------------------------------------*/ 00988 void UnityAssertEqualString(const char* expected, 00989 const char* actual, 00990 const char* msg, 00991 const UNITY_LINE_TYPE lineNumber) 00992 { 00993 _UU32 i; 00994 00995 UNITY_SKIP_EXECUTION; 00996 00997 /* if both pointers not null compare the strings */ 00998 if (expected && actual) 00999 { 01000 for (i = 0; expected[i] || actual[i]; i++) 01001 { 01002 if (expected[i] != actual[i]) 01003 { 01004 Unity.CurrentTestFailed = 1; 01005 break; 01006 } 01007 } 01008 } 01009 else 01010 { /* handle case of one pointers being null (if both null, test should pass) */ 01011 if (expected != actual) 01012 { 01013 Unity.CurrentTestFailed = 1; 01014 } 01015 } 01016 01017 if (Unity.CurrentTestFailed) 01018 { 01019 UnityTestResultsFailBegin(lineNumber); 01020 UnityPrintExpectedAndActualStrings(expected, actual); 01021 UnityAddMsgIfSpecified(msg); 01022 UNITY_FAIL_AND_BAIL; 01023 } 01024 } 01025 01026 /*-----------------------------------------------*/ 01027 void UnityAssertEqualStringLen(const char* expected, 01028 const char* actual, 01029 const _UU32 length, 01030 const char* msg, 01031 const UNITY_LINE_TYPE lineNumber) 01032 { 01033 _UU32 i; 01034 01035 UNITY_SKIP_EXECUTION; 01036 01037 /* if both pointers not null compare the strings */ 01038 if (expected && actual) 01039 { 01040 for (i = 0; (expected[i] || actual[i]) && i < length; i++) 01041 { 01042 if (expected[i] != actual[i]) 01043 { 01044 Unity.CurrentTestFailed = 1; 01045 break; 01046 } 01047 } 01048 } 01049 else 01050 { /* handle case of one pointers being null (if both null, test should pass) */ 01051 if (expected != actual) 01052 { 01053 Unity.CurrentTestFailed = 1; 01054 } 01055 } 01056 01057 if (Unity.CurrentTestFailed) 01058 { 01059 UnityTestResultsFailBegin(lineNumber); 01060 UnityPrintExpectedAndActualStringsLen(expected, actual, length); 01061 UnityAddMsgIfSpecified(msg); 01062 UNITY_FAIL_AND_BAIL; 01063 } 01064 } 01065 01066 01067 /*-----------------------------------------------*/ 01068 void UnityAssertEqualStringArray( const char** expected, 01069 const char** actual, 01070 const _UU32 num_elements, 01071 const char* msg, 01072 const UNITY_LINE_TYPE lineNumber) 01073 { 01074 _UU32 i, j = 0; 01075 01076 UNITY_SKIP_EXECUTION; 01077 01078 /* if no elements, it's an error */ 01079 if (num_elements == 0) 01080 { 01081 UnityPrintPointlessAndBail(); 01082 } 01083 01084 if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1) 01085 return; 01086 01087 do 01088 { 01089 /* if both pointers not null compare the strings */ 01090 if (expected[j] && actual[j]) 01091 { 01092 for (i = 0; expected[j][i] || actual[j][i]; i++) 01093 { 01094 if (expected[j][i] != actual[j][i]) 01095 { 01096 Unity.CurrentTestFailed = 1; 01097 break; 01098 } 01099 } 01100 } 01101 else 01102 { /* handle case of one pointers being null (if both null, test should pass) */ 01103 if (expected[j] != actual[j]) 01104 { 01105 Unity.CurrentTestFailed = 1; 01106 } 01107 } 01108 01109 if (Unity.CurrentTestFailed) 01110 { 01111 UnityTestResultsFailBegin(lineNumber); 01112 if (num_elements > 1) 01113 { 01114 UnityPrint(UnityStrElement); 01115 UnityPrintNumberUnsigned(j); 01116 } 01117 UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j])); 01118 UnityAddMsgIfSpecified(msg); 01119 UNITY_FAIL_AND_BAIL; 01120 } 01121 } while (++j < num_elements); 01122 } 01123 01124 /*-----------------------------------------------*/ 01125 void UnityAssertEqualMemory( UNITY_INTERNAL_PTR expected, 01126 UNITY_INTERNAL_PTR actual, 01127 const _UU32 length, 01128 const _UU32 num_elements, 01129 const char* msg, 01130 const UNITY_LINE_TYPE lineNumber) 01131 { 01132 UNITY_PTR_ATTRIBUTE const unsigned char* ptr_exp = (UNITY_PTR_ATTRIBUTE const unsigned char*)expected; 01133 UNITY_PTR_ATTRIBUTE const unsigned char* ptr_act = (UNITY_PTR_ATTRIBUTE const unsigned char*)actual; 01134 _UU32 elements = num_elements; 01135 _UU32 bytes; 01136 01137 UNITY_SKIP_EXECUTION; 01138 01139 if ((elements == 0) || (length == 0)) 01140 { 01141 UnityPrintPointlessAndBail(); 01142 } 01143 01144 if (UnityCheckArraysForNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg) == 1) 01145 return; 01146 01147 while (elements--) 01148 { 01149 /* /////////////////////////////////// */ 01150 bytes = length; 01151 while (bytes--) 01152 { 01153 if (*ptr_exp != *ptr_act) 01154 { 01155 UnityTestResultsFailBegin(lineNumber); 01156 UnityPrint(UnityStrMemory); 01157 if (num_elements > 1) 01158 { 01159 UnityPrint(UnityStrElement); 01160 UnityPrintNumberUnsigned(num_elements - elements - 1); 01161 } 01162 UnityPrint(UnityStrByte); 01163 UnityPrintNumberUnsigned(length - bytes - 1); 01164 UnityPrint(UnityStrExpected); 01165 UnityPrintNumberByStyle(*ptr_exp, UNITY_DISPLAY_STYLE_HEX8); 01166 UnityPrint(UnityStrWas); 01167 UnityPrintNumberByStyle(*ptr_act, UNITY_DISPLAY_STYLE_HEX8); 01168 UnityAddMsgIfSpecified(msg); 01169 UNITY_FAIL_AND_BAIL; 01170 } 01171 ptr_exp = (UNITY_INTERNAL_PTR)((_UP)ptr_exp + 1); 01172 ptr_act = (UNITY_INTERNAL_PTR)((_UP)ptr_act + 1); 01173 } 01174 /* /////////////////////////////////// */ 01175 01176 } 01177 } 01178 01179 /*----------------------------------------------- 01180 * Control Functions 01181 *-----------------------------------------------*/ 01182 01183 void UnityFail(const char* msg, const UNITY_LINE_TYPE line) 01184 { 01185 UNITY_SKIP_EXECUTION; 01186 01187 UnityTestResultsBegin(Unity.TestFile, line); 01188 UnityPrintFail(); 01189 if (msg != NULL) 01190 { 01191 UNITY_OUTPUT_CHAR(':'); 01192 01193 #ifndef UNITY_EXCLUDE_DETAILS 01194 if (Unity.CurrentDetail1) 01195 { 01196 UnityPrint(UnityStrDetail1Name); 01197 UnityPrint(Unity.CurrentDetail1); 01198 if (Unity.CurrentDetail2) 01199 { 01200 UnityPrint(UnityStrDetail2Name); 01201 UnityPrint(Unity.CurrentDetail2); 01202 } 01203 UnityPrint(UnityStrSpacer); 01204 } 01205 #endif 01206 if (msg[0] != ' ') 01207 { 01208 UNITY_OUTPUT_CHAR(' '); 01209 } 01210 UnityPrint(msg); 01211 } 01212 UNITY_FAIL_AND_BAIL; 01213 } 01214 01215 /*-----------------------------------------------*/ 01216 void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line) 01217 { 01218 UNITY_SKIP_EXECUTION; 01219 01220 UnityTestResultsBegin(Unity.TestFile, line); 01221 UnityPrint(UnityStrIgnore); 01222 if (msg != NULL) 01223 { 01224 UNITY_OUTPUT_CHAR(':'); 01225 UNITY_OUTPUT_CHAR(' '); 01226 UnityPrint(msg); 01227 } 01228 UNITY_IGNORE_AND_BAIL; 01229 } 01230 01231 /*-----------------------------------------------*/ 01232 #if defined(UNITY_WEAK_ATTRIBUTE) 01233 UNITY_WEAK_ATTRIBUTE void setUp(void) { } 01234 UNITY_WEAK_ATTRIBUTE void tearDown(void) { } 01235 #elif defined(UNITY_WEAK_PRAGMA) 01236 # pragma weak setUp 01237 void setUp(void) { } 01238 # pragma weak tearDown 01239 void tearDown(void) { } 01240 #endif 01241 /*-----------------------------------------------*/ 01242 void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum) 01243 { 01244 Unity.CurrentTestName = FuncName; 01245 Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)FuncLineNum; 01246 Unity.NumberOfTests++; 01247 UNITY_CLR_DETAILS(); 01248 if (TEST_PROTECT()) 01249 { 01250 setUp(); 01251 Func(); 01252 } 01253 if (TEST_PROTECT() && !(Unity.CurrentTestIgnored)) 01254 { 01255 tearDown(); 01256 } 01257 UnityConcludeTest(); 01258 } 01259 01260 /*-----------------------------------------------*/ 01261 void UnityBegin(const char* filename) 01262 { 01263 Unity.TestFile = filename; 01264 Unity.CurrentTestName = NULL; 01265 Unity.CurrentTestLineNumber = 0; 01266 Unity.NumberOfTests = 0; 01267 Unity.TestFailures = 0; 01268 Unity.TestIgnores = 0; 01269 Unity.CurrentTestFailed = 0; 01270 Unity.CurrentTestIgnored = 0; 01271 01272 UNITY_CLR_DETAILS(); 01273 UNITY_OUTPUT_START(); 01274 } 01275 01276 /*-----------------------------------------------*/ 01277 int UnityEnd(void) 01278 { 01279 UNITY_PRINT_EOL(); 01280 UnityPrint(UnityStrBreaker); 01281 UNITY_PRINT_EOL(); 01282 UnityPrintNumber((_U_SINT)(Unity.NumberOfTests)); 01283 UnityPrint(UnityStrResultsTests); 01284 UnityPrintNumber((_U_SINT)(Unity.TestFailures)); 01285 UnityPrint(UnityStrResultsFailures); 01286 UnityPrintNumber((_U_SINT)(Unity.TestIgnores)); 01287 UnityPrint(UnityStrResultsIgnored); 01288 UNITY_PRINT_EOL(); 01289 if (Unity.TestFailures == 0U) 01290 { 01291 UnityPrintOk(); 01292 } 01293 else 01294 { 01295 UnityPrintFail(); 01296 #ifdef UNITY_DIFFERENTIATE_FINAL_FAIL 01297 UNITY_OUTPUT_CHAR('E'); UNITY_OUTPUT_CHAR('D'); 01298 #endif 01299 } 01300 UNITY_PRINT_EOL(); 01301 UNITY_OUTPUT_FLUSH(); 01302 UNITY_OUTPUT_COMPLETE(); 01303 return (int)(Unity.TestFailures); 01304 } 01305 01306 /*-----------------------------------------------*/
Generated on Tue Jul 12 2022 11:02:57 by
