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