1276da39aSCy Schubert /* ========================================================================= 2276da39aSCy Schubert Unity Project - A Test Framework for C 3276da39aSCy Schubert Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams 4276da39aSCy Schubert [Released under MIT License. Please refer to license.txt for details] 5276da39aSCy Schubert ============================================================================ */ 6276da39aSCy Schubert 7276da39aSCy Schubert #include "unity.h" 8276da39aSCy Schubert 9276da39aSCy Schubert #define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; longjmp(Unity.AbortFrame, 1); } 10276da39aSCy Schubert #define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; longjmp(Unity.AbortFrame, 1); } 11276da39aSCy Schubert /// return prematurely if we are already in failure or ignore state 12276da39aSCy Schubert #define UNITY_SKIP_EXECUTION { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} } 13276da39aSCy Schubert #define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\n'); } 14276da39aSCy Schubert 15276da39aSCy Schubert struct _Unity Unity; 16276da39aSCy Schubert 17276da39aSCy Schubert const char UnityStrOk[] = "OK"; 18276da39aSCy Schubert const char UnityStrPass[] = "PASS"; 19276da39aSCy Schubert const char UnityStrFail[] = "FAIL"; 20276da39aSCy Schubert const char UnityStrIgnore[] = "IGNORE"; 21276da39aSCy Schubert const char UnityStrXPASS[] = "XPASS"; 22276da39aSCy Schubert const char UnityStrXFAIL[] = "XFAIL"; 23276da39aSCy Schubert const char UnityStrNull[] = "NULL"; 24276da39aSCy Schubert const char UnityStrSpacer[] = ". "; 25276da39aSCy Schubert const char UnityStrExpected[] = " Expected "; 26276da39aSCy Schubert const char UnityStrWas[] = " Was "; 27276da39aSCy Schubert const char UnityStrTo[] = " To "; 28276da39aSCy Schubert const char UnityStrElement[] = " Element "; 29276da39aSCy Schubert const char UnityStrByte[] = " Byte "; 30276da39aSCy Schubert const char UnityStrMemory[] = " Memory Mismatch."; 31276da39aSCy Schubert const char UnityStrDelta[] = " Values Not Within Delta "; 32276da39aSCy Schubert const char UnityStrPointless[] = " You Asked Me To Compare Nothing, Which Was Pointless."; 33276da39aSCy Schubert const char UnityStrNullPointerForExpected[] = " Expected pointer to be NULL"; 34276da39aSCy Schubert const char UnityStrNullPointerForActual[] = " Actual pointer was NULL"; 35276da39aSCy Schubert const char UnityStrNot[] = "Not "; 36276da39aSCy Schubert const char UnityStrInf[] = "Infinity"; 37276da39aSCy Schubert const char UnityStrNegInf[] = "Negative Infinity"; 38276da39aSCy Schubert const char UnityStrNaN[] = "NaN"; 39276da39aSCy Schubert const char UnityStrDet[] = "Determinate"; 40276da39aSCy Schubert const char UnityStrErrFloat[] = "Unity Floating Point Disabled"; 41276da39aSCy Schubert const char UnityStrErrDouble[] = "Unity Double Precision Disabled"; 42276da39aSCy Schubert const char UnityStrErr64[] = "Unity 64-bit Support Disabled"; 43276da39aSCy Schubert const char UnityStrBreaker[] = "-----------------------"; 44276da39aSCy Schubert const char UnityStrResultsTests[] = " Tests: "; 45276da39aSCy Schubert const char UnityStrResultsFailures[] = " Failures "; 46276da39aSCy Schubert const char UnityStrResultsIgnored[] = " Ignored "; 47276da39aSCy Schubert const char UnityStrResultsXFAIL[] = " XFAIL "; 48276da39aSCy Schubert const char UnityStrResultsXPASS[] = " XPASS "; 49276da39aSCy Schubert const char UnityStrResultsPass[] = " PASS "; 50276da39aSCy Schubert 51276da39aSCy Schubert 52276da39aSCy Schubert #ifndef UNITY_EXCLUDE_FLOAT 53276da39aSCy Schubert // Dividing by these constants produces +/- infinity. 54276da39aSCy Schubert // The rationale is given in UnityAssertFloatIsInf's body. 55276da39aSCy Schubert static const _UF f_zero = 0.0f; 56276da39aSCy Schubert #ifndef UNITY_EXCLUDE_DOUBLE 57276da39aSCy Schubert static const _UD d_zero = 0.0; 58276da39aSCy Schubert #endif 59276da39aSCy Schubert #endif 60276da39aSCy Schubert 61276da39aSCy Schubert // compiler-generic print formatting masks 62276da39aSCy Schubert const _U_UINT UnitySizeMask[] = 63276da39aSCy Schubert { 64276da39aSCy Schubert 255u, // 0xFF 65276da39aSCy Schubert 65535u, // 0xFFFF 66276da39aSCy Schubert 65535u, 67276da39aSCy Schubert 4294967295u, // 0xFFFFFFFF 68276da39aSCy Schubert 4294967295u, 69276da39aSCy Schubert 4294967295u, 70276da39aSCy Schubert 4294967295u 71276da39aSCy Schubert #ifdef UNITY_SUPPORT_64 72276da39aSCy Schubert ,0xFFFFFFFFFFFFFFFF 73276da39aSCy Schubert #endif 74276da39aSCy Schubert }; 75276da39aSCy Schubert 76276da39aSCy Schubert void UnityPrintFail(void); 77276da39aSCy Schubert void UnityPrintOk(void); 78276da39aSCy Schubert 79276da39aSCy Schubert //----------------------------------------------- 80276da39aSCy Schubert // Pretty Printers & Test Result Output Handlers 81276da39aSCy Schubert //----------------------------------------------- 82276da39aSCy Schubert 83276da39aSCy Schubert void UnityPrint(const char* string) 84276da39aSCy Schubert { 85276da39aSCy Schubert const char* pch = string; 86276da39aSCy Schubert 87276da39aSCy Schubert if (pch != NULL) 88276da39aSCy Schubert { 89276da39aSCy Schubert while (*pch) 90276da39aSCy Schubert { 91276da39aSCy Schubert // printable characters plus CR & LF are printed 92276da39aSCy Schubert if ((*pch <= 126) && (*pch >= 32)) 93276da39aSCy Schubert { 94276da39aSCy Schubert UNITY_OUTPUT_CHAR(*pch); 95276da39aSCy Schubert } 96276da39aSCy Schubert //write escaped carriage returns 97276da39aSCy Schubert else if (*pch == 13) 98276da39aSCy Schubert { 99276da39aSCy Schubert UNITY_OUTPUT_CHAR('\\'); 100276da39aSCy Schubert UNITY_OUTPUT_CHAR('r'); 101276da39aSCy Schubert } 102276da39aSCy Schubert //write escaped line feeds 103276da39aSCy Schubert else if (*pch == 10) 104276da39aSCy Schubert { 105276da39aSCy Schubert UNITY_OUTPUT_CHAR('\\'); 106276da39aSCy Schubert UNITY_OUTPUT_CHAR('n'); 107276da39aSCy Schubert } 108276da39aSCy Schubert // unprintable characters are shown as codes 109276da39aSCy Schubert else 110276da39aSCy Schubert { 111276da39aSCy Schubert UNITY_OUTPUT_CHAR('\\'); 112276da39aSCy Schubert UnityPrintNumberHex((_U_UINT)*pch, 2); 113276da39aSCy Schubert } 114276da39aSCy Schubert pch++; 115276da39aSCy Schubert } 116276da39aSCy Schubert } 117276da39aSCy Schubert } 118276da39aSCy Schubert 119276da39aSCy Schubert //----------------------------------------------- 120276da39aSCy Schubert void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style) 121276da39aSCy Schubert { 122276da39aSCy Schubert if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) 123276da39aSCy Schubert { 124276da39aSCy Schubert UnityPrintNumber(number); 125276da39aSCy Schubert } 126276da39aSCy Schubert else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT) 127276da39aSCy Schubert { 128276da39aSCy Schubert UnityPrintNumberUnsigned( (_U_UINT)number & UnitySizeMask[((_U_UINT)style & (_U_UINT)0x0F) - 1] ); 129276da39aSCy Schubert } 130276da39aSCy Schubert else 131276da39aSCy Schubert { 132276da39aSCy Schubert UnityPrintNumberHex((_U_UINT)number, (char)((style & 0x000F) << 1)); 133276da39aSCy Schubert } 134276da39aSCy Schubert } 135276da39aSCy Schubert 136276da39aSCy Schubert //----------------------------------------------- 137276da39aSCy Schubert /// basically do an itoa using as little ram as possible 138276da39aSCy Schubert void UnityPrintNumber(const _U_SINT number_to_print) 139276da39aSCy Schubert { 140276da39aSCy Schubert _U_SINT divisor = 1; 141276da39aSCy Schubert _U_SINT next_divisor; 142276da39aSCy Schubert _U_UINT number; 143276da39aSCy Schubert 144276da39aSCy Schubert if (number_to_print == (1l << (UNITY_LONG_WIDTH-1))) 145276da39aSCy Schubert { 146276da39aSCy Schubert //The largest representable negative number 147276da39aSCy Schubert UNITY_OUTPUT_CHAR('-'); 148276da39aSCy Schubert number = (1ul << (UNITY_LONG_WIDTH-1)); 149276da39aSCy Schubert } 150276da39aSCy Schubert else if (number_to_print < 0) 151276da39aSCy Schubert { 152276da39aSCy Schubert //Some other negative number 153276da39aSCy Schubert UNITY_OUTPUT_CHAR('-'); 154276da39aSCy Schubert number = (_U_UINT)(-number_to_print); 155276da39aSCy Schubert } 156276da39aSCy Schubert else 157276da39aSCy Schubert { 158276da39aSCy Schubert //Positive number 159276da39aSCy Schubert number = (_U_UINT)number_to_print; 160276da39aSCy Schubert } 161276da39aSCy Schubert 162276da39aSCy Schubert // figure out initial divisor 163276da39aSCy Schubert while (number / divisor > 9) 164276da39aSCy Schubert { 165276da39aSCy Schubert next_divisor = divisor * 10; 166276da39aSCy Schubert if (next_divisor > divisor) 167276da39aSCy Schubert divisor = next_divisor; 168276da39aSCy Schubert else 169276da39aSCy Schubert break; 170276da39aSCy Schubert } 171276da39aSCy Schubert 172276da39aSCy Schubert // now mod and print, then divide divisor 173276da39aSCy Schubert do 174276da39aSCy Schubert { 175276da39aSCy Schubert UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10))); 176276da39aSCy Schubert divisor /= 10; 177276da39aSCy Schubert } 178276da39aSCy Schubert while (divisor > 0); 179276da39aSCy Schubert } 180276da39aSCy Schubert 181276da39aSCy Schubert //----------------------------------------------- 182276da39aSCy Schubert /// basically do an itoa using as little ram as possible 183276da39aSCy Schubert void UnityPrintNumberUnsigned(const _U_UINT number) 184276da39aSCy Schubert { 185276da39aSCy Schubert _U_UINT divisor = 1; 186276da39aSCy Schubert _U_UINT next_divisor; 187276da39aSCy Schubert 188276da39aSCy Schubert // figure out initial divisor 189276da39aSCy Schubert while (number / divisor > 9) 190276da39aSCy Schubert { 191276da39aSCy Schubert next_divisor = divisor * 10; 192276da39aSCy Schubert if (next_divisor > divisor) 193276da39aSCy Schubert divisor = next_divisor; 194276da39aSCy Schubert else 195276da39aSCy Schubert break; 196276da39aSCy Schubert } 197276da39aSCy Schubert 198276da39aSCy Schubert // now mod and print, then divide divisor 199276da39aSCy Schubert do 200276da39aSCy Schubert { 201276da39aSCy Schubert UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10))); 202276da39aSCy Schubert divisor /= 10; 203276da39aSCy Schubert } 204276da39aSCy Schubert while (divisor > 0); 205276da39aSCy Schubert } 206276da39aSCy Schubert 207276da39aSCy Schubert //----------------------------------------------- 208276da39aSCy Schubert void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print) 209276da39aSCy Schubert { 210276da39aSCy Schubert _U_UINT nibble; 211276da39aSCy Schubert char nibbles = nibbles_to_print; 212276da39aSCy Schubert UNITY_OUTPUT_CHAR('0'); 213276da39aSCy Schubert UNITY_OUTPUT_CHAR('x'); 214276da39aSCy Schubert 215276da39aSCy Schubert while (nibbles > 0) 216276da39aSCy Schubert { 217276da39aSCy Schubert nibble = (number >> (--nibbles << 2)) & 0x0000000F; 218276da39aSCy Schubert if (nibble <= 9) 219276da39aSCy Schubert { 220276da39aSCy Schubert UNITY_OUTPUT_CHAR((char)('0' + nibble)); 221276da39aSCy Schubert } 222276da39aSCy Schubert else 223276da39aSCy Schubert { 224276da39aSCy Schubert UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble)); 225276da39aSCy Schubert } 226276da39aSCy Schubert } 227276da39aSCy Schubert } 228276da39aSCy Schubert 229276da39aSCy Schubert //----------------------------------------------- 230276da39aSCy Schubert void UnityPrintMask(const _U_UINT mask, const _U_UINT number) 231276da39aSCy Schubert { 232276da39aSCy Schubert _U_UINT current_bit = (_U_UINT)1 << (UNITY_INT_WIDTH - 1); 233276da39aSCy Schubert _US32 i; 234276da39aSCy Schubert 235276da39aSCy Schubert for (i = 0; i < UNITY_INT_WIDTH; i++) 236276da39aSCy Schubert { 237276da39aSCy Schubert if (current_bit & mask) 238276da39aSCy Schubert { 239276da39aSCy Schubert if (current_bit & number) 240276da39aSCy Schubert { 241276da39aSCy Schubert UNITY_OUTPUT_CHAR('1'); 242276da39aSCy Schubert } 243276da39aSCy Schubert else 244276da39aSCy Schubert { 245276da39aSCy Schubert UNITY_OUTPUT_CHAR('0'); 246276da39aSCy Schubert } 247276da39aSCy Schubert } 248276da39aSCy Schubert else 249276da39aSCy Schubert { 250276da39aSCy Schubert UNITY_OUTPUT_CHAR('X'); 251276da39aSCy Schubert } 252276da39aSCy Schubert current_bit = current_bit >> 1; 253276da39aSCy Schubert } 254276da39aSCy Schubert } 255276da39aSCy Schubert 256276da39aSCy Schubert //----------------------------------------------- 257276da39aSCy Schubert #ifdef UNITY_FLOAT_VERBOSE 258276da39aSCy Schubert #include <string.h> 259276da39aSCy Schubert void UnityPrintFloat(_UF number) 260276da39aSCy Schubert { 261276da39aSCy Schubert char TempBuffer[32]; 262276da39aSCy Schubert sprintf(TempBuffer, "%.6f", number); 263276da39aSCy Schubert UnityPrint(TempBuffer); 264276da39aSCy Schubert } 265276da39aSCy Schubert #endif 266276da39aSCy Schubert 267276da39aSCy Schubert //----------------------------------------------- 268276da39aSCy Schubert 269276da39aSCy Schubert void UnityPrintFail(void) 270276da39aSCy Schubert { 271276da39aSCy Schubert UnityPrint(UnityStrFail); 272276da39aSCy Schubert } 273276da39aSCy Schubert 274276da39aSCy Schubert void UnityPrintOk(void) 275276da39aSCy Schubert { 276276da39aSCy Schubert UnityPrint(UnityStrOk); 277276da39aSCy Schubert } 278276da39aSCy Schubert 279276da39aSCy Schubert //----------------------------------------------- 280276da39aSCy Schubert static void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line) 281276da39aSCy Schubert { 282276da39aSCy Schubert UnityPrint(file); 283276da39aSCy Schubert UNITY_OUTPUT_CHAR(':'); 284276da39aSCy Schubert UnityPrintNumber((_U_SINT)line); 285276da39aSCy Schubert UNITY_OUTPUT_CHAR(':'); 286276da39aSCy Schubert UnityPrint(Unity.CurrentTestName); 287276da39aSCy Schubert UNITY_OUTPUT_CHAR(':'); 288276da39aSCy Schubert } 289276da39aSCy Schubert 290276da39aSCy Schubert //----------------------------------------------- 291276da39aSCy Schubert static void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line) 292276da39aSCy Schubert { 293276da39aSCy Schubert UnityTestResultsBegin(Unity.TestFile, line); 294276da39aSCy Schubert if (Unity.isExpectingFail) 295276da39aSCy Schubert { 296276da39aSCy Schubert UnityPrint(UnityStrXFAIL); 297276da39aSCy Schubert } 298276da39aSCy Schubert else 299276da39aSCy Schubert { 300276da39aSCy Schubert UnityPrint(UnityStrFail); 301276da39aSCy Schubert } 302276da39aSCy Schubert 303276da39aSCy Schubert UNITY_OUTPUT_CHAR(':'); 304276da39aSCy Schubert } 305276da39aSCy Schubert 306276da39aSCy Schubert //----------------------------------------------- 307276da39aSCy Schubert void UnityConcludeTest(void) 308276da39aSCy Schubert { 309276da39aSCy Schubert #if 0 310276da39aSCy Schubert if (Unity.isExpectingFail == 1 && Unity.CurrentTestFailed == 0) 311276da39aSCy Schubert { 312276da39aSCy Schubert printf("FAIL WAS EXPECTED, BUT IT DIDN'T HAPPEN?!"); 313276da39aSCy Schubert Unity.TestXPASSES++; 314276da39aSCy Schubert } 315276da39aSCy Schubert 316276da39aSCy Schubert else 317276da39aSCy Schubert #endif 318276da39aSCy Schubert //cant be ignored and accepting fail at the same time! 319276da39aSCy Schubert if (Unity.isExpectingFail == 1 && Unity.CurrentTestFailed == 1) 320276da39aSCy Schubert { 321276da39aSCy Schubert Unity.TestXFAILS++; //error message?! 322276da39aSCy Schubert if (Unity.XFAILMessage != NULL) 323276da39aSCy Schubert { 324276da39aSCy Schubert if (Unity.XFAILMessage[0] != ' ') 325276da39aSCy Schubert { 326276da39aSCy Schubert printf(" "); 327276da39aSCy Schubert } 328276da39aSCy Schubert 329276da39aSCy Schubert printf("| "); 330*9034852cSGleb Smirnoff printf("%s", Unity.XFAILMessage); 331276da39aSCy Schubert Unity.XFAILMessage = NULL; 332276da39aSCy Schubert } 333276da39aSCy Schubert else 334276da39aSCy Schubert { 335276da39aSCy Schubert printf(" - EXPECTED FAIL!"); 336276da39aSCy Schubert } 337276da39aSCy Schubert } 338276da39aSCy Schubert else 339276da39aSCy Schubert 340276da39aSCy Schubert if (Unity.CurrentTestIgnored) 341276da39aSCy Schubert { 342276da39aSCy Schubert Unity.TestIgnores++; 343276da39aSCy Schubert } 344276da39aSCy Schubert else if (!Unity.CurrentTestFailed) 345276da39aSCy Schubert { 346276da39aSCy Schubert if(Unity.isExpectingFail == 0) { 347276da39aSCy Schubert UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber); 348276da39aSCy Schubert UnityPrint(UnityStrPass); 349276da39aSCy Schubert Unity.TestPasses++; 350276da39aSCy Schubert } 351276da39aSCy Schubert 352276da39aSCy Schubert //probably should remove the if... part 353276da39aSCy Schubert else if (Unity.isExpectingFail == 1 && Unity.CurrentTestFailed == 0) 354276da39aSCy Schubert { 355276da39aSCy Schubert 356276da39aSCy Schubert UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber); 357276da39aSCy Schubert UnityPrint(UnityStrXPASS); 358276da39aSCy Schubert Unity.TestXPASSES++; 359276da39aSCy Schubert 360276da39aSCy Schubert printf(" - FAIL WAS EXPECTED, BUT DIDN'T HAPPEN?!"); 361276da39aSCy Schubert //if (Unity.TestPasses > 0) { Unity.TestPasses--; } 362276da39aSCy Schubert } 363276da39aSCy Schubert } 364276da39aSCy Schubert else 365276da39aSCy Schubert { 366276da39aSCy Schubert Unity.TestFailures++; 367276da39aSCy Schubert } 368276da39aSCy Schubert 369276da39aSCy Schubert Unity.CurrentTestFailed = 0; 370276da39aSCy Schubert Unity.CurrentTestIgnored = 0; 371276da39aSCy Schubert Unity.isExpectingFail = 0; 372276da39aSCy Schubert 373276da39aSCy Schubert UNITY_PRINT_EOL; 374276da39aSCy Schubert } 375276da39aSCy Schubert 376276da39aSCy Schubert //----------------------------------------------- 377276da39aSCy Schubert static void UnityAddMsgIfSpecified(const char* msg) 378276da39aSCy Schubert { 379276da39aSCy Schubert if (msg) 380276da39aSCy Schubert { 381276da39aSCy Schubert UnityPrint(UnityStrSpacer); 382276da39aSCy Schubert UnityPrint(msg); 383276da39aSCy Schubert } 384276da39aSCy Schubert } 385276da39aSCy Schubert 386276da39aSCy Schubert //----------------------------------------------- 387276da39aSCy Schubert static void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual) 388276da39aSCy Schubert { 389276da39aSCy Schubert UnityPrint(UnityStrExpected); 390276da39aSCy Schubert if (expected != NULL) 391276da39aSCy Schubert { 392276da39aSCy Schubert UNITY_OUTPUT_CHAR('\''); 393276da39aSCy Schubert UnityPrint(expected); 394276da39aSCy Schubert UNITY_OUTPUT_CHAR('\''); 395276da39aSCy Schubert } 396276da39aSCy Schubert else 397276da39aSCy Schubert { 398276da39aSCy Schubert UnityPrint(UnityStrNull); 399276da39aSCy Schubert } 400276da39aSCy Schubert UnityPrint(UnityStrWas); 401276da39aSCy Schubert if (actual != NULL) 402276da39aSCy Schubert { 403276da39aSCy Schubert UNITY_OUTPUT_CHAR('\''); 404276da39aSCy Schubert UnityPrint(actual); 405276da39aSCy Schubert UNITY_OUTPUT_CHAR('\''); 406276da39aSCy Schubert } 407276da39aSCy Schubert else 408276da39aSCy Schubert { 409276da39aSCy Schubert UnityPrint(UnityStrNull); 410276da39aSCy Schubert } 411276da39aSCy Schubert } 412276da39aSCy Schubert 413276da39aSCy Schubert //----------------------------------------------- 414276da39aSCy Schubert // Assertion & Control Helpers 415276da39aSCy Schubert //----------------------------------------------- 416276da39aSCy Schubert 417276da39aSCy Schubert static int UnityCheckArraysForNull(UNITY_PTR_ATTRIBUTE const void* expected, UNITY_PTR_ATTRIBUTE const void* actual, const UNITY_LINE_TYPE lineNumber, const char* msg) 418276da39aSCy Schubert { 419276da39aSCy Schubert //return true if they are both NULL 420276da39aSCy Schubert if ((expected == NULL) && (actual == NULL)) 421276da39aSCy Schubert return 1; 422276da39aSCy Schubert 423276da39aSCy Schubert //throw error if just expected is NULL 424276da39aSCy Schubert if (expected == NULL) 425276da39aSCy Schubert { 426276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 427276da39aSCy Schubert UnityPrint(UnityStrNullPointerForExpected); 428276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 429276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 430276da39aSCy Schubert } 431276da39aSCy Schubert 432276da39aSCy Schubert //throw error if just actual is NULL 433276da39aSCy Schubert if (actual == NULL) 434276da39aSCy Schubert { 435276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 436276da39aSCy Schubert UnityPrint(UnityStrNullPointerForActual); 437276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 438276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 439276da39aSCy Schubert } 440276da39aSCy Schubert 441276da39aSCy Schubert //return false if neither is NULL 442276da39aSCy Schubert return 0; 443276da39aSCy Schubert } 444276da39aSCy Schubert 445276da39aSCy Schubert //----------------------------------------------- 446276da39aSCy Schubert // Assertion Functions 447276da39aSCy Schubert //----------------------------------------------- 448276da39aSCy Schubert 449276da39aSCy Schubert void UnityAssertBits(const _U_SINT mask, 450276da39aSCy Schubert const _U_SINT expected, 451276da39aSCy Schubert const _U_SINT actual, 452276da39aSCy Schubert const char* msg, 453276da39aSCy Schubert const UNITY_LINE_TYPE lineNumber) 454276da39aSCy Schubert { 455276da39aSCy Schubert UNITY_SKIP_EXECUTION; 456276da39aSCy Schubert 457276da39aSCy Schubert if ((mask & expected) != (mask & actual)) 458276da39aSCy Schubert { 459276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 460276da39aSCy Schubert UnityPrint(UnityStrExpected); 461276da39aSCy Schubert UnityPrintMask((_U_UINT)mask, (_U_UINT)expected); 462276da39aSCy Schubert UnityPrint(UnityStrWas); 463276da39aSCy Schubert UnityPrintMask((_U_UINT)mask, (_U_UINT)actual); 464276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 465276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 466276da39aSCy Schubert } 467276da39aSCy Schubert } 468276da39aSCy Schubert 469276da39aSCy Schubert //----------------------------------------------- 470276da39aSCy Schubert void UnityAssertEqualNumber(const _U_SINT expected, 471276da39aSCy Schubert const _U_SINT actual, 472276da39aSCy Schubert const char* msg, 473276da39aSCy Schubert const UNITY_LINE_TYPE lineNumber, 474276da39aSCy Schubert const UNITY_DISPLAY_STYLE_T style) 475276da39aSCy Schubert { 476276da39aSCy Schubert UNITY_SKIP_EXECUTION; 477276da39aSCy Schubert 478276da39aSCy Schubert if (expected != actual) 479276da39aSCy Schubert { 480276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 481276da39aSCy Schubert UnityPrint(UnityStrExpected); 482276da39aSCy Schubert UnityPrintNumberByStyle(expected, style); 483276da39aSCy Schubert UnityPrint(UnityStrWas); 484276da39aSCy Schubert UnityPrintNumberByStyle(actual, style); 485276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 486276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 487276da39aSCy Schubert } 488276da39aSCy Schubert } 489276da39aSCy Schubert 490276da39aSCy Schubert //----------------------------------------------- 491276da39aSCy Schubert void UnityAssertEqualIntArray(UNITY_PTR_ATTRIBUTE const void* expected, 492276da39aSCy Schubert UNITY_PTR_ATTRIBUTE const void* actual, 493276da39aSCy Schubert const _UU32 num_elements, 494276da39aSCy Schubert const char* msg, 495276da39aSCy Schubert const UNITY_LINE_TYPE lineNumber, 496276da39aSCy Schubert const UNITY_DISPLAY_STYLE_T style) 497276da39aSCy Schubert { 498276da39aSCy Schubert _UU32 elements = num_elements; 499276da39aSCy Schubert UNITY_PTR_ATTRIBUTE const _US8* ptr_exp = (UNITY_PTR_ATTRIBUTE const _US8*)expected; 500276da39aSCy Schubert UNITY_PTR_ATTRIBUTE const _US8* ptr_act = (UNITY_PTR_ATTRIBUTE const _US8*)actual; 501276da39aSCy Schubert 502276da39aSCy Schubert UNITY_SKIP_EXECUTION; 503276da39aSCy Schubert 504276da39aSCy Schubert if (elements == 0) 505276da39aSCy Schubert { 506276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 507276da39aSCy Schubert UnityPrint(UnityStrPointless); 508276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 509276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 510276da39aSCy Schubert } 511276da39aSCy Schubert 512276da39aSCy Schubert if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE const void*)expected, (UNITY_PTR_ATTRIBUTE const void*)actual, lineNumber, msg) == 1) 513276da39aSCy Schubert return; 514276da39aSCy Schubert 515276da39aSCy Schubert // If style is UNITY_DISPLAY_STYLE_INT, we'll fall into the default case rather than the INT16 or INT32 (etc) case 516276da39aSCy Schubert // as UNITY_DISPLAY_STYLE_INT includes a flag for UNITY_DISPLAY_RANGE_AUTO, which the width-specific 517276da39aSCy Schubert // variants do not. Therefore remove this flag. 518276da39aSCy Schubert switch(style & (UNITY_DISPLAY_STYLE_T)(~UNITY_DISPLAY_RANGE_AUTO)) 519276da39aSCy Schubert { 520276da39aSCy Schubert case UNITY_DISPLAY_STYLE_HEX8: 521276da39aSCy Schubert case UNITY_DISPLAY_STYLE_INT8: 522276da39aSCy Schubert case UNITY_DISPLAY_STYLE_UINT8: 523276da39aSCy Schubert while (elements--) 524276da39aSCy Schubert { 525276da39aSCy Schubert if (*ptr_exp != *ptr_act) 526276da39aSCy Schubert { 527276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 528276da39aSCy Schubert UnityPrint(UnityStrElement); 529276da39aSCy Schubert UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); 530276da39aSCy Schubert UnityPrint(UnityStrExpected); 531276da39aSCy Schubert UnityPrintNumberByStyle(*ptr_exp, style); 532276da39aSCy Schubert UnityPrint(UnityStrWas); 533276da39aSCy Schubert UnityPrintNumberByStyle(*ptr_act, style); 534276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 535276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 536276da39aSCy Schubert } 537276da39aSCy Schubert ptr_exp += 1; 538276da39aSCy Schubert ptr_act += 1; 539276da39aSCy Schubert } 540276da39aSCy Schubert break; 541276da39aSCy Schubert case UNITY_DISPLAY_STYLE_HEX16: 542276da39aSCy Schubert case UNITY_DISPLAY_STYLE_INT16: 543276da39aSCy Schubert case UNITY_DISPLAY_STYLE_UINT16: 544276da39aSCy Schubert while (elements--) 545276da39aSCy Schubert { 546276da39aSCy Schubert if (*(UNITY_PTR_ATTRIBUTE const _US16*)(void*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US16*)(void*)ptr_act) 547276da39aSCy Schubert { 548276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 549276da39aSCy Schubert UnityPrint(UnityStrElement); 550276da39aSCy Schubert UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); 551276da39aSCy Schubert UnityPrint(UnityStrExpected); 552276da39aSCy Schubert UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US16*)(void*)ptr_exp, style); 553276da39aSCy Schubert UnityPrint(UnityStrWas); 554276da39aSCy Schubert UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US16*)(void*)ptr_act, style); 555276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 556276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 557276da39aSCy Schubert } 558276da39aSCy Schubert ptr_exp += 2; 559276da39aSCy Schubert ptr_act += 2; 560276da39aSCy Schubert } 561276da39aSCy Schubert break; 562276da39aSCy Schubert #ifdef UNITY_SUPPORT_64 563276da39aSCy Schubert case UNITY_DISPLAY_STYLE_HEX64: 564276da39aSCy Schubert case UNITY_DISPLAY_STYLE_INT64: 565276da39aSCy Schubert case UNITY_DISPLAY_STYLE_UINT64: 566276da39aSCy Schubert while (elements--) 567276da39aSCy Schubert { 568276da39aSCy Schubert if (*(UNITY_PTR_ATTRIBUTE const _US64*)(void*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US64*)(void*)ptr_act) 569276da39aSCy Schubert { 570276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 571276da39aSCy Schubert UnityPrint(UnityStrElement); 572276da39aSCy Schubert UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); 573276da39aSCy Schubert UnityPrint(UnityStrExpected); 574276da39aSCy Schubert UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US64*)(void*)ptr_exp, style); 575276da39aSCy Schubert UnityPrint(UnityStrWas); 576276da39aSCy Schubert UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US64*)(void*)ptr_act, style); 577276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 578276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 579276da39aSCy Schubert } 580276da39aSCy Schubert ptr_exp += 8; 581276da39aSCy Schubert ptr_act += 8; 582276da39aSCy Schubert } 583276da39aSCy Schubert break; 584276da39aSCy Schubert #endif 585276da39aSCy Schubert default: 586276da39aSCy Schubert while (elements--) 587276da39aSCy Schubert { 588276da39aSCy Schubert if (*(UNITY_PTR_ATTRIBUTE const _US32*)(void*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US32*)(void*)ptr_act) 589276da39aSCy Schubert { 590276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 591276da39aSCy Schubert UnityPrint(UnityStrElement); 592276da39aSCy Schubert UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); 593276da39aSCy Schubert UnityPrint(UnityStrExpected); 594276da39aSCy Schubert UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US32*)(void*)ptr_exp, style); 595276da39aSCy Schubert UnityPrint(UnityStrWas); 596276da39aSCy Schubert UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US32*)(void*)ptr_act, style); 597276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 598276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 599276da39aSCy Schubert } 600276da39aSCy Schubert ptr_exp += 4; 601276da39aSCy Schubert ptr_act += 4; 602276da39aSCy Schubert } 603276da39aSCy Schubert break; 604276da39aSCy Schubert } 605276da39aSCy Schubert } 606276da39aSCy Schubert 607276da39aSCy Schubert //----------------------------------------------- 608276da39aSCy Schubert #ifndef UNITY_EXCLUDE_FLOAT 609276da39aSCy Schubert void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected, 610276da39aSCy Schubert UNITY_PTR_ATTRIBUTE const _UF* actual, 611276da39aSCy Schubert const _UU32 num_elements, 612276da39aSCy Schubert const char* msg, 613276da39aSCy Schubert const UNITY_LINE_TYPE lineNumber) 614276da39aSCy Schubert { 615276da39aSCy Schubert _UU32 elements = num_elements; 616276da39aSCy Schubert UNITY_PTR_ATTRIBUTE const _UF* ptr_expected = expected; 617276da39aSCy Schubert UNITY_PTR_ATTRIBUTE const _UF* ptr_actual = actual; 618276da39aSCy Schubert _UF diff, tol; 619276da39aSCy Schubert 620276da39aSCy Schubert UNITY_SKIP_EXECUTION; 621276da39aSCy Schubert 622276da39aSCy Schubert if (elements == 0) 623276da39aSCy Schubert { 624276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 625276da39aSCy Schubert UnityPrint(UnityStrPointless); 626276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 627276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 628276da39aSCy Schubert } 629276da39aSCy Schubert 630276da39aSCy Schubert if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE const void*)expected, (UNITY_PTR_ATTRIBUTE const void*)actual, lineNumber, msg) == 1) 631276da39aSCy Schubert return; 632276da39aSCy Schubert 633276da39aSCy Schubert while (elements--) 634276da39aSCy Schubert { 635276da39aSCy Schubert diff = *ptr_expected - *ptr_actual; 636276da39aSCy Schubert if (diff < 0.0f) 637276da39aSCy Schubert diff = 0.0f - diff; 638276da39aSCy Schubert tol = UNITY_FLOAT_PRECISION * *ptr_expected; 639276da39aSCy Schubert if (tol < 0.0f) 640276da39aSCy Schubert tol = 0.0f - tol; 641276da39aSCy Schubert 642276da39aSCy Schubert //This first part of this condition will catch any NaN or Infinite values 643276da39aSCy Schubert if ((diff * 0.0f != 0.0f) || (diff > tol)) 644276da39aSCy Schubert { 645276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 646276da39aSCy Schubert UnityPrint(UnityStrElement); 647276da39aSCy Schubert UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); 648276da39aSCy Schubert #ifdef UNITY_FLOAT_VERBOSE 649276da39aSCy Schubert UnityPrint(UnityStrExpected); 650276da39aSCy Schubert UnityPrintFloat(*ptr_expected); 651276da39aSCy Schubert UnityPrint(UnityStrWas); 652276da39aSCy Schubert UnityPrintFloat(*ptr_actual); 653276da39aSCy Schubert #else 654276da39aSCy Schubert UnityPrint(UnityStrDelta); 655276da39aSCy Schubert #endif 656276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 657276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 658276da39aSCy Schubert } 659276da39aSCy Schubert ptr_expected++; 660276da39aSCy Schubert ptr_actual++; 661276da39aSCy Schubert } 662276da39aSCy Schubert } 663276da39aSCy Schubert 664276da39aSCy Schubert //----------------------------------------------- 665276da39aSCy Schubert void UnityAssertFloatsWithin(const _UF delta, 666276da39aSCy Schubert const _UF expected, 667276da39aSCy Schubert const _UF actual, 668276da39aSCy Schubert const char* msg, 669276da39aSCy Schubert const UNITY_LINE_TYPE lineNumber) 670276da39aSCy Schubert { 671276da39aSCy Schubert _UF diff = actual - expected; 672276da39aSCy Schubert _UF pos_delta = delta; 673276da39aSCy Schubert 674276da39aSCy Schubert UNITY_SKIP_EXECUTION; 675276da39aSCy Schubert 676276da39aSCy Schubert if (diff < 0.0f) 677276da39aSCy Schubert { 678276da39aSCy Schubert diff = 0.0f - diff; 679276da39aSCy Schubert } 680276da39aSCy Schubert if (pos_delta < 0.0f) 681276da39aSCy Schubert { 682276da39aSCy Schubert pos_delta = 0.0f - pos_delta; 683276da39aSCy Schubert } 684276da39aSCy Schubert 685276da39aSCy Schubert //This first part of this condition will catch any NaN or Infinite values 686276da39aSCy Schubert if ((diff * 0.0f != 0.0f) || (pos_delta < diff)) 687276da39aSCy Schubert { 688276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 689276da39aSCy Schubert #ifdef UNITY_FLOAT_VERBOSE 690276da39aSCy Schubert UnityPrint(UnityStrExpected); 691276da39aSCy Schubert UnityPrintFloat(expected); 692276da39aSCy Schubert UnityPrint(UnityStrWas); 693276da39aSCy Schubert UnityPrintFloat(actual); 694276da39aSCy Schubert #else 695276da39aSCy Schubert UnityPrint(UnityStrDelta); 696276da39aSCy Schubert #endif 697276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 698276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 699276da39aSCy Schubert } 700276da39aSCy Schubert } 701276da39aSCy Schubert 702276da39aSCy Schubert //----------------------------------------------- 703276da39aSCy Schubert void UnityAssertFloatSpecial(const _UF actual, 704276da39aSCy Schubert const char* msg, 705276da39aSCy Schubert const UNITY_LINE_TYPE lineNumber, 706276da39aSCy Schubert const UNITY_FLOAT_TRAIT_T style) 707276da39aSCy Schubert { 708276da39aSCy Schubert const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet }; 709276da39aSCy Schubert _U_SINT should_be_trait = ((_U_SINT)style & 1); 710276da39aSCy Schubert _U_SINT is_trait = !should_be_trait; 711276da39aSCy Schubert _U_SINT trait_index = style >> 1; 712276da39aSCy Schubert 713276da39aSCy Schubert UNITY_SKIP_EXECUTION; 714276da39aSCy Schubert 715276da39aSCy Schubert switch(style) 716276da39aSCy Schubert { 717276da39aSCy Schubert //To determine Inf / Neg Inf, we compare to an Inf / Neg Inf value we create on the fly 718276da39aSCy Schubert //We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise 719276da39aSCy Schubert case UNITY_FLOAT_IS_INF: 720276da39aSCy Schubert case UNITY_FLOAT_IS_NOT_INF: 721276da39aSCy Schubert is_trait = ((1.0f / f_zero) == actual) ? 1 : 0; 722276da39aSCy Schubert break; 723276da39aSCy Schubert case UNITY_FLOAT_IS_NEG_INF: 724276da39aSCy Schubert case UNITY_FLOAT_IS_NOT_NEG_INF: 725276da39aSCy Schubert is_trait = ((-1.0f / f_zero) == actual) ? 1 : 0; 726276da39aSCy Schubert break; 727276da39aSCy Schubert 728276da39aSCy Schubert //NaN is the only floating point value that does NOT equal itself. Therefore if Actual == Actual, then it is NOT NaN. 729276da39aSCy Schubert case UNITY_FLOAT_IS_NAN: 730276da39aSCy Schubert case UNITY_FLOAT_IS_NOT_NAN: 731276da39aSCy Schubert is_trait = (actual == actual) ? 0 : 1; 732276da39aSCy Schubert break; 733276da39aSCy Schubert 734276da39aSCy Schubert //A determinate number is non infinite and not NaN. (therefore the opposite of the two above) 735276da39aSCy Schubert case UNITY_FLOAT_IS_DET: 736276da39aSCy Schubert case UNITY_FLOAT_IS_NOT_DET: 737276da39aSCy Schubert if ( (actual != actual) || ((1.0f / f_zero) == actual) || ((-1.0f / f_zero) == actual) ) 738276da39aSCy Schubert is_trait = 0; 739276da39aSCy Schubert else 740276da39aSCy Schubert is_trait = 1; 741276da39aSCy Schubert break; 742276da39aSCy Schubert default: 743276da39aSCy Schubert ; 744276da39aSCy Schubert } 745276da39aSCy Schubert 746276da39aSCy Schubert if (is_trait != should_be_trait) 747276da39aSCy Schubert { 748276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 749276da39aSCy Schubert UnityPrint(UnityStrExpected); 750276da39aSCy Schubert if (!should_be_trait) 751276da39aSCy Schubert UnityPrint(UnityStrNot); 752276da39aSCy Schubert UnityPrint(trait_names[trait_index]); 753276da39aSCy Schubert UnityPrint(UnityStrWas); 754276da39aSCy Schubert #ifdef UNITY_FLOAT_VERBOSE 755276da39aSCy Schubert UnityPrintFloat(actual); 756276da39aSCy Schubert #else 757276da39aSCy Schubert if (should_be_trait) 758276da39aSCy Schubert UnityPrint(UnityStrNot); 759276da39aSCy Schubert UnityPrint(trait_names[trait_index]); 760276da39aSCy Schubert #endif 761276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 762276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 763276da39aSCy Schubert } 764276da39aSCy Schubert } 765276da39aSCy Schubert 766276da39aSCy Schubert #endif //not UNITY_EXCLUDE_FLOAT 767276da39aSCy Schubert 768276da39aSCy Schubert //----------------------------------------------- 769276da39aSCy Schubert #ifndef UNITY_EXCLUDE_DOUBLE 770276da39aSCy Schubert void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected, 771276da39aSCy Schubert UNITY_PTR_ATTRIBUTE const _UD* actual, 772276da39aSCy Schubert const _UU32 num_elements, 773276da39aSCy Schubert const char* msg, 774276da39aSCy Schubert const UNITY_LINE_TYPE lineNumber) 775276da39aSCy Schubert { 776276da39aSCy Schubert _UU32 elements = num_elements; 777276da39aSCy Schubert UNITY_PTR_ATTRIBUTE const _UD* ptr_expected = expected; 778276da39aSCy Schubert UNITY_PTR_ATTRIBUTE const _UD* ptr_actual = actual; 779276da39aSCy Schubert _UD diff, tol; 780276da39aSCy Schubert 781276da39aSCy Schubert UNITY_SKIP_EXECUTION; 782276da39aSCy Schubert 783276da39aSCy Schubert if (elements == 0) 784276da39aSCy Schubert { 785276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 786276da39aSCy Schubert UnityPrint(UnityStrPointless); 787276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 788276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 789276da39aSCy Schubert } 790276da39aSCy Schubert 791276da39aSCy Schubert if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1) 792276da39aSCy Schubert return; 793276da39aSCy Schubert 794276da39aSCy Schubert while (elements--) 795276da39aSCy Schubert { 796276da39aSCy Schubert diff = *ptr_expected - *ptr_actual; 797276da39aSCy Schubert if (diff < 0.0) 798276da39aSCy Schubert diff = 0.0 - diff; 799276da39aSCy Schubert tol = UNITY_DOUBLE_PRECISION * *ptr_expected; 800276da39aSCy Schubert if (tol < 0.0) 801276da39aSCy Schubert tol = 0.0 - tol; 802276da39aSCy Schubert 803276da39aSCy Schubert //This first part of this condition will catch any NaN or Infinite values 804276da39aSCy Schubert if ((diff * 0.0 != 0.0) || (diff > tol)) 805276da39aSCy Schubert { 806276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 807276da39aSCy Schubert UnityPrint(UnityStrElement); 808276da39aSCy Schubert UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); 809276da39aSCy Schubert #ifdef UNITY_DOUBLE_VERBOSE 810276da39aSCy Schubert UnityPrint(UnityStrExpected); 811276da39aSCy Schubert UnityPrintFloat((float)(*ptr_expected)); 812276da39aSCy Schubert UnityPrint(UnityStrWas); 813276da39aSCy Schubert UnityPrintFloat((float)(*ptr_actual)); 814276da39aSCy Schubert #else 815276da39aSCy Schubert UnityPrint(UnityStrDelta); 816276da39aSCy Schubert #endif 817276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 818276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 819276da39aSCy Schubert } 820276da39aSCy Schubert ptr_expected++; 821276da39aSCy Schubert ptr_actual++; 822276da39aSCy Schubert } 823276da39aSCy Schubert } 824276da39aSCy Schubert 825276da39aSCy Schubert //----------------------------------------------- 826276da39aSCy Schubert void UnityAssertDoublesWithin(const _UD delta, 827276da39aSCy Schubert const _UD expected, 828276da39aSCy Schubert const _UD actual, 829276da39aSCy Schubert const char* msg, 830276da39aSCy Schubert const UNITY_LINE_TYPE lineNumber) 831276da39aSCy Schubert { 832276da39aSCy Schubert _UD diff = actual - expected; 833276da39aSCy Schubert _UD pos_delta = delta; 834276da39aSCy Schubert 835276da39aSCy Schubert UNITY_SKIP_EXECUTION; 836276da39aSCy Schubert 837276da39aSCy Schubert if (diff < 0.0) 838276da39aSCy Schubert { 839276da39aSCy Schubert diff = 0.0 - diff; 840276da39aSCy Schubert } 841276da39aSCy Schubert if (pos_delta < 0.0) 842276da39aSCy Schubert { 843276da39aSCy Schubert pos_delta = 0.0 - pos_delta; 844276da39aSCy Schubert } 845276da39aSCy Schubert 846276da39aSCy Schubert //This first part of this condition will catch any NaN or Infinite values 847276da39aSCy Schubert if ((diff * 0.0 != 0.0) || (pos_delta < diff)) 848276da39aSCy Schubert { 849276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 850276da39aSCy Schubert #ifdef UNITY_DOUBLE_VERBOSE 851276da39aSCy Schubert UnityPrint(UnityStrExpected); 852276da39aSCy Schubert UnityPrintFloat((float)expected); 853276da39aSCy Schubert UnityPrint(UnityStrWas); 854276da39aSCy Schubert UnityPrintFloat((float)actual); 855276da39aSCy Schubert #else 856276da39aSCy Schubert UnityPrint(UnityStrDelta); 857276da39aSCy Schubert #endif 858276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 859276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 860276da39aSCy Schubert } 861276da39aSCy Schubert } 862276da39aSCy Schubert 863276da39aSCy Schubert //----------------------------------------------- 864276da39aSCy Schubert 865276da39aSCy Schubert void UnityAssertDoubleSpecial(const _UD actual, 866276da39aSCy Schubert const char* msg, 867276da39aSCy Schubert const UNITY_LINE_TYPE lineNumber, 868276da39aSCy Schubert const UNITY_FLOAT_TRAIT_T style) 869276da39aSCy Schubert { 870276da39aSCy Schubert const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet }; 871276da39aSCy Schubert _U_SINT should_be_trait = ((_U_SINT)style & 1); 872276da39aSCy Schubert _U_SINT is_trait = !should_be_trait; 873276da39aSCy Schubert _U_SINT trait_index = style >> 1; 874276da39aSCy Schubert 875276da39aSCy Schubert UNITY_SKIP_EXECUTION; 876276da39aSCy Schubert 877276da39aSCy Schubert switch(style) 878276da39aSCy Schubert { 879276da39aSCy Schubert //To determine Inf / Neg Inf, we compare to an Inf / Neg Inf value we create on the fly 880276da39aSCy Schubert //We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise 881276da39aSCy Schubert case UNITY_FLOAT_IS_INF: 882276da39aSCy Schubert case UNITY_FLOAT_IS_NOT_INF: 883276da39aSCy Schubert is_trait = ((1.0 / d_zero) == actual) ? 1 : 0; 884276da39aSCy Schubert break; 885276da39aSCy Schubert case UNITY_FLOAT_IS_NEG_INF: 886276da39aSCy Schubert case UNITY_FLOAT_IS_NOT_NEG_INF: 887276da39aSCy Schubert is_trait = ((-1.0 / d_zero) == actual) ? 1 : 0; 888276da39aSCy Schubert break; 889276da39aSCy Schubert 890276da39aSCy Schubert //NaN is the only floating point value that does NOT equal itself. Therefore if Actual == Actual, then it is NOT NaN. 891276da39aSCy Schubert case UNITY_FLOAT_IS_NAN: 892276da39aSCy Schubert case UNITY_FLOAT_IS_NOT_NAN: 893276da39aSCy Schubert is_trait = (actual == actual) ? 0 : 1; 894276da39aSCy Schubert break; 895276da39aSCy Schubert 896276da39aSCy Schubert //A determinate number is non infinite and not NaN. (therefore the opposite of the two above) 897276da39aSCy Schubert case UNITY_FLOAT_IS_DET: 898276da39aSCy Schubert case UNITY_FLOAT_IS_NOT_DET: 899276da39aSCy Schubert if ( (actual != actual) || ((1.0 / d_zero) == actual) || ((-1.0 / d_zero) == actual) ) 900276da39aSCy Schubert is_trait = 0; 901276da39aSCy Schubert else 902276da39aSCy Schubert is_trait = 1; 903276da39aSCy Schubert break; 904276da39aSCy Schubert default: 905276da39aSCy Schubert ; 906276da39aSCy Schubert } 907276da39aSCy Schubert 908276da39aSCy Schubert if (is_trait != should_be_trait) 909276da39aSCy Schubert { 910276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 911276da39aSCy Schubert UnityPrint(UnityStrExpected); 912276da39aSCy Schubert if (!should_be_trait) 913276da39aSCy Schubert UnityPrint(UnityStrNot); 914276da39aSCy Schubert UnityPrint(trait_names[trait_index]); 915276da39aSCy Schubert UnityPrint(UnityStrWas); 916276da39aSCy Schubert #ifdef UNITY_DOUBLE_VERBOSE 917276da39aSCy Schubert UnityPrintFloat(actual); 918276da39aSCy Schubert #else 919276da39aSCy Schubert if (should_be_trait) 920276da39aSCy Schubert UnityPrint(UnityStrNot); 921276da39aSCy Schubert UnityPrint(trait_names[trait_index]); 922276da39aSCy Schubert #endif 923276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 924276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 925276da39aSCy Schubert } 926276da39aSCy Schubert } 927276da39aSCy Schubert 928276da39aSCy Schubert 929276da39aSCy Schubert #endif // not UNITY_EXCLUDE_DOUBLE 930276da39aSCy Schubert 931276da39aSCy Schubert //----------------------------------------------- 932276da39aSCy Schubert void UnityAssertNumbersWithin( const _U_SINT delta, 933276da39aSCy Schubert const _U_SINT expected, 934276da39aSCy Schubert const _U_SINT actual, 935276da39aSCy Schubert const char* msg, 936276da39aSCy Schubert const UNITY_LINE_TYPE lineNumber, 937276da39aSCy Schubert const UNITY_DISPLAY_STYLE_T style) 938276da39aSCy Schubert { 939276da39aSCy Schubert UNITY_SKIP_EXECUTION; 940276da39aSCy Schubert 941276da39aSCy Schubert if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) 942276da39aSCy Schubert { 943276da39aSCy Schubert if (actual > expected) 944276da39aSCy Schubert Unity.CurrentTestFailed = ((actual - expected) > delta); 945276da39aSCy Schubert else 946276da39aSCy Schubert Unity.CurrentTestFailed = ((expected - actual) > delta); 947276da39aSCy Schubert } 948276da39aSCy Schubert else 949276da39aSCy Schubert { 950276da39aSCy Schubert if ((_U_UINT)actual > (_U_UINT)expected) 951276da39aSCy Schubert Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > (_U_UINT)delta); 952276da39aSCy Schubert else 953276da39aSCy Schubert Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > (_U_UINT)delta); 954276da39aSCy Schubert } 955276da39aSCy Schubert 956276da39aSCy Schubert if (Unity.CurrentTestFailed) 957276da39aSCy Schubert { 958276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 959276da39aSCy Schubert UnityPrint(UnityStrDelta); 960276da39aSCy Schubert UnityPrintNumberByStyle(delta, style); 961276da39aSCy Schubert UnityPrint(UnityStrExpected); 962276da39aSCy Schubert UnityPrintNumberByStyle(expected, style); 963276da39aSCy Schubert UnityPrint(UnityStrWas); 964276da39aSCy Schubert UnityPrintNumberByStyle(actual, style); 965276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 966276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 967276da39aSCy Schubert } 968276da39aSCy Schubert } 969276da39aSCy Schubert 970276da39aSCy Schubert //----------------------------------------------- 971276da39aSCy Schubert void UnityAssertEqualString(const char* expected, 972276da39aSCy Schubert const char* actual, 973276da39aSCy Schubert const char* msg, 974276da39aSCy Schubert const UNITY_LINE_TYPE lineNumber) 975276da39aSCy Schubert { 976276da39aSCy Schubert _UU32 i; 977276da39aSCy Schubert 978276da39aSCy Schubert UNITY_SKIP_EXECUTION; 979276da39aSCy Schubert 980276da39aSCy Schubert // if both pointers not null compare the strings 981276da39aSCy Schubert if (expected && actual) 982276da39aSCy Schubert { 983276da39aSCy Schubert for (i = 0; expected[i] || actual[i]; i++) 984276da39aSCy Schubert { 985276da39aSCy Schubert if (expected[i] != actual[i]) 986276da39aSCy Schubert { 987276da39aSCy Schubert Unity.CurrentTestFailed = 1; 988276da39aSCy Schubert break; 989276da39aSCy Schubert } 990276da39aSCy Schubert } 991276da39aSCy Schubert } 992276da39aSCy Schubert else 993276da39aSCy Schubert { // handle case of one pointers being null (if both null, test should pass) 994276da39aSCy Schubert if (expected != actual) 995276da39aSCy Schubert { 996276da39aSCy Schubert Unity.CurrentTestFailed = 1; 997276da39aSCy Schubert } 998276da39aSCy Schubert } 999276da39aSCy Schubert 1000276da39aSCy Schubert if (Unity.CurrentTestFailed) 1001276da39aSCy Schubert { 1002276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 1003276da39aSCy Schubert UnityPrintExpectedAndActualStrings(expected, actual); 1004276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 1005276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 1006276da39aSCy Schubert } 1007276da39aSCy Schubert } 1008276da39aSCy Schubert 1009276da39aSCy Schubert //----------------------------------------------- 1010276da39aSCy Schubert void UnityAssertEqualStringArray( const char** expected, 1011276da39aSCy Schubert const char** actual, 1012276da39aSCy Schubert const _UU32 num_elements, 1013276da39aSCy Schubert const char* msg, 1014276da39aSCy Schubert const UNITY_LINE_TYPE lineNumber) 1015276da39aSCy Schubert { 1016276da39aSCy Schubert _UU32 i, j = 0; 1017276da39aSCy Schubert 1018276da39aSCy Schubert UNITY_SKIP_EXECUTION; 1019276da39aSCy Schubert 1020276da39aSCy Schubert // if no elements, it's an error 1021276da39aSCy Schubert if (num_elements == 0) 1022276da39aSCy Schubert { 1023276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 1024276da39aSCy Schubert UnityPrint(UnityStrPointless); 1025276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 1026276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 1027276da39aSCy Schubert } 1028276da39aSCy Schubert 1029276da39aSCy Schubert if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1) 1030276da39aSCy Schubert return; 1031276da39aSCy Schubert 1032276da39aSCy Schubert do 1033276da39aSCy Schubert { 1034276da39aSCy Schubert // if both pointers not null compare the strings 1035276da39aSCy Schubert if (expected[j] && actual[j]) 1036276da39aSCy Schubert { 1037276da39aSCy Schubert for (i = 0; expected[j][i] || actual[j][i]; i++) 1038276da39aSCy Schubert { 1039276da39aSCy Schubert if (expected[j][i] != actual[j][i]) 1040276da39aSCy Schubert { 1041276da39aSCy Schubert Unity.CurrentTestFailed = 1; 1042276da39aSCy Schubert break; 1043276da39aSCy Schubert } 1044276da39aSCy Schubert } 1045276da39aSCy Schubert } 1046276da39aSCy Schubert else 1047276da39aSCy Schubert { // handle case of one pointers being null (if both null, test should pass) 1048276da39aSCy Schubert if (expected[j] != actual[j]) 1049276da39aSCy Schubert { 1050276da39aSCy Schubert Unity.CurrentTestFailed = 1; 1051276da39aSCy Schubert } 1052276da39aSCy Schubert } 1053276da39aSCy Schubert 1054276da39aSCy Schubert if (Unity.CurrentTestFailed) 1055276da39aSCy Schubert { 1056276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 1057276da39aSCy Schubert if (num_elements > 1) 1058276da39aSCy Schubert { 1059276da39aSCy Schubert UnityPrint(UnityStrElement); 1060276da39aSCy Schubert UnityPrintNumberByStyle((j), UNITY_DISPLAY_STYLE_UINT); 1061276da39aSCy Schubert } 1062276da39aSCy Schubert UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j])); 1063276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 1064276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 1065276da39aSCy Schubert } 1066276da39aSCy Schubert } while (++j < num_elements); 1067276da39aSCy Schubert } 1068276da39aSCy Schubert 1069276da39aSCy Schubert //----------------------------------------------- 1070276da39aSCy Schubert void UnityAssertEqualMemory( UNITY_PTR_ATTRIBUTE const void* expected, 1071276da39aSCy Schubert UNITY_PTR_ATTRIBUTE const void* actual, 1072276da39aSCy Schubert const _UU32 length, 1073276da39aSCy Schubert const _UU32 num_elements, 1074276da39aSCy Schubert const char* msg, 1075276da39aSCy Schubert const UNITY_LINE_TYPE lineNumber) 1076276da39aSCy Schubert { 1077276da39aSCy Schubert UNITY_PTR_ATTRIBUTE const unsigned char* ptr_exp = (UNITY_PTR_ATTRIBUTE const unsigned char*)expected; 1078276da39aSCy Schubert UNITY_PTR_ATTRIBUTE const unsigned char* ptr_act = (UNITY_PTR_ATTRIBUTE const unsigned char*)actual; 1079276da39aSCy Schubert _UU32 elements = num_elements; 1080276da39aSCy Schubert _UU32 bytes; 1081276da39aSCy Schubert 1082276da39aSCy Schubert UNITY_SKIP_EXECUTION; 1083276da39aSCy Schubert 1084276da39aSCy Schubert if ((elements == 0) || (length == 0)) 1085276da39aSCy Schubert { 1086276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 1087276da39aSCy Schubert UnityPrint(UnityStrPointless); 1088276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 1089276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 1090276da39aSCy Schubert } 1091276da39aSCy Schubert 1092276da39aSCy Schubert if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE const void*)expected, (UNITY_PTR_ATTRIBUTE const void*)actual, lineNumber, msg) == 1) 1093276da39aSCy Schubert return; 1094276da39aSCy Schubert 1095276da39aSCy Schubert while (elements--) 1096276da39aSCy Schubert { 1097276da39aSCy Schubert ///////////////////////////////////// 1098276da39aSCy Schubert bytes = length; 1099276da39aSCy Schubert while (bytes--) 1100276da39aSCy Schubert { 1101276da39aSCy Schubert if (*ptr_exp != *ptr_act) 1102276da39aSCy Schubert { 1103276da39aSCy Schubert UnityTestResultsFailBegin(lineNumber); 1104276da39aSCy Schubert UnityPrint(UnityStrMemory); 1105276da39aSCy Schubert if (num_elements > 1) 1106276da39aSCy Schubert { 1107276da39aSCy Schubert UnityPrint(UnityStrElement); 1108276da39aSCy Schubert UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT); 1109276da39aSCy Schubert } 1110276da39aSCy Schubert UnityPrint(UnityStrByte); 1111276da39aSCy Schubert UnityPrintNumberByStyle((length - bytes - 1), UNITY_DISPLAY_STYLE_UINT); 1112276da39aSCy Schubert UnityPrint(UnityStrExpected); 1113276da39aSCy Schubert UnityPrintNumberByStyle(*ptr_exp, UNITY_DISPLAY_STYLE_HEX8); 1114276da39aSCy Schubert UnityPrint(UnityStrWas); 1115276da39aSCy Schubert UnityPrintNumberByStyle(*ptr_act, UNITY_DISPLAY_STYLE_HEX8); 1116276da39aSCy Schubert UnityAddMsgIfSpecified(msg); 1117276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 1118276da39aSCy Schubert } 1119276da39aSCy Schubert ptr_exp += 1; 1120276da39aSCy Schubert ptr_act += 1; 1121276da39aSCy Schubert } 1122276da39aSCy Schubert ///////////////////////////////////// 1123276da39aSCy Schubert 1124276da39aSCy Schubert } 1125276da39aSCy Schubert } 1126276da39aSCy Schubert 1127276da39aSCy Schubert //----------------------------------------------- 1128276da39aSCy Schubert // Control Functions 1129276da39aSCy Schubert //----------------------------------------------- 1130276da39aSCy Schubert 1131276da39aSCy Schubert void UnityFail(const char* msg, const UNITY_LINE_TYPE line) 1132276da39aSCy Schubert { 1133276da39aSCy Schubert UNITY_SKIP_EXECUTION; 1134276da39aSCy Schubert 1135276da39aSCy Schubert UnityTestResultsBegin(Unity.TestFile, line); 1136276da39aSCy Schubert UnityPrintFail(); 1137276da39aSCy Schubert if (msg != NULL) 1138276da39aSCy Schubert { 1139276da39aSCy Schubert UNITY_OUTPUT_CHAR(':'); 1140276da39aSCy Schubert if (msg[0] != ' ') 1141276da39aSCy Schubert { 1142276da39aSCy Schubert UNITY_OUTPUT_CHAR(' '); 1143276da39aSCy Schubert } 1144276da39aSCy Schubert UnityPrint(msg); 1145276da39aSCy Schubert } 1146276da39aSCy Schubert UNITY_FAIL_AND_BAIL; 1147276da39aSCy Schubert } 1148276da39aSCy Schubert 1149276da39aSCy Schubert //----------------------------------------------- 1150276da39aSCy Schubert void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line) 1151276da39aSCy Schubert { 1152276da39aSCy Schubert UNITY_SKIP_EXECUTION; 1153276da39aSCy Schubert 1154276da39aSCy Schubert UnityTestResultsBegin(Unity.TestFile, line); 1155276da39aSCy Schubert UnityPrint(UnityStrIgnore); 1156276da39aSCy Schubert if (msg != NULL) 1157276da39aSCy Schubert { 1158276da39aSCy Schubert UNITY_OUTPUT_CHAR(':'); 1159276da39aSCy Schubert UNITY_OUTPUT_CHAR(' '); 1160276da39aSCy Schubert UnityPrint(msg); 1161276da39aSCy Schubert } 1162276da39aSCy Schubert UNITY_IGNORE_AND_BAIL; 1163276da39aSCy Schubert } 1164276da39aSCy Schubert 1165276da39aSCy Schubert //---------------------------------------------- 1166276da39aSCy Schubert 1167276da39aSCy Schubert void UnityExpectFail(){ 1168276da39aSCy Schubert 1169276da39aSCy Schubert Unity.isExpectingFail = 1; 1170276da39aSCy Schubert 1171276da39aSCy Schubert } 1172276da39aSCy Schubert 1173276da39aSCy Schubert void UnityExpectFailMessage(const char* msg, const UNITY_LINE_TYPE line ){ 1174276da39aSCy Schubert 1175276da39aSCy Schubert Unity.isExpectingFail = 1; 1176276da39aSCy Schubert if (msg != NULL) 1177276da39aSCy Schubert { 1178276da39aSCy Schubert Unity.XFAILMessage = msg; 1179276da39aSCy Schubert } 1180276da39aSCy Schubert } 1181276da39aSCy Schubert 1182276da39aSCy Schubert //----------------------------------------------- 1183276da39aSCy Schubert #if defined(UNITY_WEAK_ATTRIBUTE) 1184276da39aSCy Schubert void setUp(void); 1185276da39aSCy Schubert void tearDown(void); 1186276da39aSCy Schubert UNITY_WEAK_ATTRIBUTE void setUp(void) { } 1187276da39aSCy Schubert UNITY_WEAK_ATTRIBUTE void tearDown(void) { } 1188276da39aSCy Schubert #elif defined(UNITY_WEAK_PRAGMA) 1189276da39aSCy Schubert # pragma weak setUp 1190276da39aSCy Schubert void setUp(void); 1191276da39aSCy Schubert # pragma weak tearDown 1192276da39aSCy Schubert void tearDown(void); 1193276da39aSCy Schubert #else 1194276da39aSCy Schubert void setUp(void); 1195276da39aSCy Schubert void tearDown(void); 1196276da39aSCy Schubert #endif 1197276da39aSCy Schubert 1198276da39aSCy Schubert //----------------------------------------------- 1199276da39aSCy Schubert void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum) 1200276da39aSCy Schubert { 1201276da39aSCy Schubert Unity.CurrentTestName = FuncName; 1202276da39aSCy Schubert Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)FuncLineNum; 1203276da39aSCy Schubert Unity.NumberOfTests++; 1204276da39aSCy Schubert 1205276da39aSCy Schubert if (TEST_PROTECT()) 1206276da39aSCy Schubert { 1207276da39aSCy Schubert setUp(); 1208276da39aSCy Schubert Func(); 1209276da39aSCy Schubert } 1210276da39aSCy Schubert if (TEST_PROTECT() && !(Unity.CurrentTestIgnored)) 1211276da39aSCy Schubert { 1212276da39aSCy Schubert tearDown(); 1213276da39aSCy Schubert } 1214276da39aSCy Schubert 1215276da39aSCy Schubert UnityConcludeTest(); 1216276da39aSCy Schubert } 1217276da39aSCy Schubert 1218276da39aSCy Schubert 1219276da39aSCy Schubert //----------------------------------------------- 1220276da39aSCy Schubert void UnityBegin(const char* filename) 1221276da39aSCy Schubert { 1222276da39aSCy Schubert Unity.TestFile = filename; 1223276da39aSCy Schubert Unity.CurrentTestName = NULL; 1224276da39aSCy Schubert Unity.CurrentTestLineNumber = 0; 1225276da39aSCy Schubert Unity.NumberOfTests = 0; 1226276da39aSCy Schubert Unity.TestFailures = 0; 1227276da39aSCy Schubert Unity.TestIgnores = 0; 1228276da39aSCy Schubert Unity.CurrentTestFailed = 0; 1229276da39aSCy Schubert Unity.CurrentTestIgnored = 0; 1230276da39aSCy Schubert Unity.TestXFAILS = 0; 1231276da39aSCy Schubert Unity.isExpectingFail = 0; 1232276da39aSCy Schubert Unity.TestPasses = 0; 1233276da39aSCy Schubert Unity.TestXPASSES = 0; 1234276da39aSCy Schubert Unity.XFAILMessage = NULL; 1235276da39aSCy Schubert 1236276da39aSCy Schubert UNITY_OUTPUT_START(); 1237276da39aSCy Schubert } 1238276da39aSCy Schubert 1239276da39aSCy Schubert 1240276da39aSCy Schubert //----------------------------------------------- 1241276da39aSCy Schubert int UnityEnd(void) 1242276da39aSCy Schubert { 1243276da39aSCy Schubert UNITY_PRINT_EOL; 1244276da39aSCy Schubert UnityPrint(UnityStrBreaker); 1245276da39aSCy Schubert UNITY_PRINT_EOL; 1246276da39aSCy Schubert UnityPrintNumber((_U_SINT)(Unity.NumberOfTests)); 1247276da39aSCy Schubert UnityPrint(UnityStrResultsTests); 1248276da39aSCy Schubert UNITY_PRINT_EOL; 1249276da39aSCy Schubert UnityPrintNumber((_U_SINT)(Unity.TestPasses)); 1250276da39aSCy Schubert UnityPrint(UnityStrResultsPass); 1251276da39aSCy Schubert UNITY_PRINT_EOL; 1252276da39aSCy Schubert UnityPrintNumber((_U_SINT)(Unity.TestXFAILS)); 1253276da39aSCy Schubert UnityPrint(UnityStrResultsXFAIL); 1254276da39aSCy Schubert UNITY_PRINT_EOL; 1255276da39aSCy Schubert UnityPrintNumber((_U_SINT)(Unity.TestFailures)); 1256276da39aSCy Schubert UnityPrint(UnityStrResultsFailures); 1257276da39aSCy Schubert UNITY_PRINT_EOL; 1258276da39aSCy Schubert UnityPrintNumber((_U_SINT)(Unity.TestXPASSES)); 1259276da39aSCy Schubert UnityPrint(UnityStrResultsXPASS); 1260276da39aSCy Schubert UNITY_PRINT_EOL; 1261276da39aSCy Schubert UnityPrintNumber((_U_SINT)(Unity.TestIgnores)); 1262276da39aSCy Schubert UnityPrint(UnityStrResultsIgnored); 1263276da39aSCy Schubert UNITY_PRINT_EOL; 1264276da39aSCy Schubert 1265276da39aSCy Schubert UNITY_PRINT_EOL; 1266276da39aSCy Schubert if (Unity.TestFailures == 0U && Unity.TestXPASSES == 0U) 1267276da39aSCy Schubert { 1268276da39aSCy Schubert UnityPrintOk(); 1269276da39aSCy Schubert } 1270276da39aSCy Schubert else 1271276da39aSCy Schubert { 1272276da39aSCy Schubert UnityPrintFail(); 1273276da39aSCy Schubert } 1274276da39aSCy Schubert UNITY_PRINT_EOL; 1275276da39aSCy Schubert UNITY_OUTPUT_COMPLETE(); 1276276da39aSCy Schubert return (int)(Unity.TestFailures); 1277276da39aSCy Schubert } 1278276da39aSCy Schubert 1279276da39aSCy Schubert 1280276da39aSCy Schubert //----------------------------------------------- 1281