unity.c 41.1 KB
Newer Older
1
/* =========================================================================
2
    Unity Project - A Test Framework for C
3
    Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams
4
    [Released under MIT License. Please refer to license.txt for details]
5
============================================================================ */
6

G
greg-williams 已提交
7
#include "unity.h"
8
#include <stddef.h>
G
greg-williams 已提交
9

10 11
#define UNITY_FAIL_AND_BAIL   { Unity.CurrentTestFailed  = 1; longjmp(Unity.AbortFrame, 1); }
#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; longjmp(Unity.AbortFrame, 1); }
12 13
/// return prematurely if we are already in failure or ignore state
#define UNITY_SKIP_EXECUTION  { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} }
M
mvandervoord 已提交
14
#define UNITY_PRINT_EOL       { UNITY_OUTPUT_CHAR('\n'); }
M
mvandervoord 已提交
15

16
struct _Unity Unity;
G
greg-williams 已提交
17

18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
const char UnityStrOk[]                     = "OK";
const char UnityStrPass[]                   = "PASS";
const char UnityStrFail[]                   = "FAIL";
const char UnityStrIgnore[]                 = "IGNORE";
const char UnityStrNull[]                   = "NULL";
const char UnityStrSpacer[]                 = ". ";
const char UnityStrExpected[]               = " Expected ";
const char UnityStrWas[]                    = " Was ";
const char UnityStrTo[]                     = " To ";
const char UnityStrElement[]                = " Element ";
const char UnityStrByte[]                   = " Byte ";
const char UnityStrMemory[]                 = " Memory Mismatch.";
const char UnityStrDelta[]                  = " Values Not Within Delta ";
const char UnityStrPointless[]              = " You Asked Me To Compare Nothing, Which Was Pointless.";
const char UnityStrNullPointerForExpected[] = " Expected pointer to be NULL";
const char UnityStrNullPointerForActual[]   = " Actual pointer was NULL";
const char UnityStrNot[]                    = "Not ";
const char UnityStrInf[]                    = "Infinity";
const char UnityStrNegInf[]                 = "Negative Infinity";
const char UnityStrNaN[]                    = "NaN";
const char UnityStrDet[]                    = "Determinate";
const char UnityStrErrFloat[]               = "Unity Floating Point Disabled";
const char UnityStrErrDouble[]              = "Unity Double Precision Disabled";
const char UnityStrErr64[]                  = "Unity 64-bit Support Disabled";
const char UnityStrBreaker[]                = "-----------------------";
const char UnityStrResultsTests[]           = " Tests ";
const char UnityStrResultsFailures[]        = " Failures ";
const char UnityStrResultsIgnored[]         = " Ignored ";
M
mvandervoord 已提交
46

47
#ifndef UNITY_EXCLUDE_FLOAT
48 49 50 51 52 53
// Dividing by these constants produces +/- infinity.
// The rationale is given in UnityAssertFloatIsInf's body.
static const _UF f_zero = 0.0f;
#ifndef UNITY_EXCLUDE_DOUBLE
static const _UD d_zero = 0.0;
#endif
54
#endif
55

56
// compiler-generic print formatting masks
57
const _U_UINT UnitySizeMask[] =
58
{
59 60
    255u,         // 0xFF
    65535u,       // 0xFFFF
M
 
mvandervoord 已提交
61
    65535u,
62
    4294967295u,  // 0xFFFFFFFF
M
 
mvandervoord 已提交
63 64 65
    4294967295u,
    4294967295u,
    4294967295u
66 67 68 69 70
#ifdef UNITY_SUPPORT_64
    ,0xFFFFFFFFFFFFFFFF
#endif
};

71 72 73
void UnityPrintFail(void);
void UnityPrintOk(void);

M
mvandervoord 已提交
74
//-----------------------------------------------
75
// Pretty Printers & Test Result Output Handlers
M
mvandervoord 已提交
76 77
//-----------------------------------------------

78
void UnityPrint(const char* string)
G
greg-williams 已提交
79
{
80
    const char* pch = string;
G
greg-williams 已提交
81 82 83 84 85

    if (pch != NULL)
    {
        while (*pch)
        {
M
mvandervoord 已提交
86
            // printable characters plus CR & LF are printed
M
mvandervoord 已提交
87
            if ((*pch <= 126) && (*pch >= 32))
M
mvandervoord 已提交
88 89 90
            {
                UNITY_OUTPUT_CHAR(*pch);
            }
M
mvandervoord 已提交
91 92 93 94 95 96 97 98 99 100 101 102
            //write escaped carriage returns
            else if (*pch == 13)
            {
                UNITY_OUTPUT_CHAR('\\');
                UNITY_OUTPUT_CHAR('r');
            }
            //write escaped line feeds
            else if (*pch == 10)
            {
                UNITY_OUTPUT_CHAR('\\');
                UNITY_OUTPUT_CHAR('n');
            }
M
mvandervoord 已提交
103 104 105 106
            // unprintable characters are shown as codes
            else
            {
                UNITY_OUTPUT_CHAR('\\');
107
                UnityPrintNumberHex((_U_UINT)*pch, 2);
M
mvandervoord 已提交
108
            }
G
greg-williams 已提交
109 110 111 112 113
            pch++;
        }
    }
}

M
Mark VanderVoord 已提交
114
void UnityPrintLen(const char* string, const _UU32 length);
115 116 117 118 119 120
void UnityPrintLen(const char* string, const _UU32 length)
{
    const char* pch = string;

    if (pch != NULL)
    {
121
        while (*pch && (_UU32)(pch - string) < length)
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
        {
            // printable characters plus CR & LF are printed
            if ((*pch <= 126) && (*pch >= 32))
            {
                UNITY_OUTPUT_CHAR(*pch);
            }
            //write escaped carriage returns
            else if (*pch == 13)
            {
                UNITY_OUTPUT_CHAR('\\');
                UNITY_OUTPUT_CHAR('r');
            }
            //write escaped line feeds
            else if (*pch == 10)
            {
                UNITY_OUTPUT_CHAR('\\');
                UNITY_OUTPUT_CHAR('n');
            }
            // unprintable characters are shown as codes
            else
            {
                UNITY_OUTPUT_CHAR('\\');
                UnityPrintNumberHex((_U_UINT)*pch, 2);
            }
            pch++;
        }
    }
}

M
mvandervoord 已提交
151
//-----------------------------------------------
M
mvandervoord 已提交
152
void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style)
G
greg-williams 已提交
153
{
M
mvandervoord 已提交
154 155 156 157 158 159
    if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
    {
        UnityPrintNumber(number);
    }
    else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT)
    {
160
        UnityPrintNumberUnsigned(  (_U_UINT)number  &  UnitySizeMask[((_U_UINT)style & (_U_UINT)0x0F) - 1]  );
M
mvandervoord 已提交
161 162
    }
    else
G
greg-williams 已提交
163
    {
164
        UnityPrintNumberHex((_U_UINT)number, (char)((style & 0x000F) << 1));
G
greg-williams 已提交
165 166 167
    }
}

M
mvandervoord 已提交
168
//-----------------------------------------------
G
greg-williams 已提交
169
/// basically do an itoa using as little ram as possible
M
mvandervoord 已提交
170
void UnityPrintNumber(const _U_SINT number_to_print)
G
greg-williams 已提交
171
{
M
mvandervoord 已提交
172 173
    _U_SINT divisor = 1;
    _U_SINT next_divisor;
174 175
    _U_UINT number;

176
    if (number_to_print == (1l << (UNITY_LONG_WIDTH-1)))
G
greg-williams 已提交
177
    {
178
        //The largest representable negative number
179
        UNITY_OUTPUT_CHAR('-');
180
        number = (1ul << (UNITY_LONG_WIDTH-1));
181 182 183 184 185 186
    }
    else if (number_to_print < 0)
    {
        //Some other negative number
        UNITY_OUTPUT_CHAR('-');
        number = (_U_UINT)(-number_to_print);
187 188 189
    }
    else
    {
190 191
        //Positive number
        number = (_U_UINT)number_to_print;
G
greg-williams 已提交
192 193 194
    }

    // figure out initial divisor
M
mvandervoord 已提交
195
    while (number / divisor > 9)
G
greg-williams 已提交
196
    {
M
mvandervoord 已提交
197 198 199 200 201
        next_divisor = divisor * 10;
        if (next_divisor > divisor)
            divisor = next_divisor;
        else
            break;
G
greg-williams 已提交
202 203
    }

M
mvandervoord 已提交
204
    // now mod and print, then divide divisor
G
greg-williams 已提交
205 206
    do
    {
207
        UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
M
mvandervoord 已提交
208
        divisor /= 10;
G
greg-williams 已提交
209
    }
M
mvandervoord 已提交
210
    while (divisor > 0);
G
greg-williams 已提交
211 212
}

M
mvandervoord 已提交
213
//-----------------------------------------------
G
greg-williams 已提交
214
/// basically do an itoa using as little ram as possible
M
mvandervoord 已提交
215
void UnityPrintNumberUnsigned(const _U_UINT number)
G
greg-williams 已提交
216
{
M
mvandervoord 已提交
217 218
    _U_UINT divisor = 1;
    _U_UINT next_divisor;
G
greg-williams 已提交
219 220

    // figure out initial divisor
M
mvandervoord 已提交
221
    while (number / divisor > 9)
G
greg-williams 已提交
222
    {
M
mvandervoord 已提交
223 224 225 226 227
        next_divisor = divisor * 10;
        if (next_divisor > divisor)
            divisor = next_divisor;
        else
            break;
G
greg-williams 已提交
228 229
    }

M
mvandervoord 已提交
230
    // now mod and print, then divide divisor
G
greg-williams 已提交
231 232
    do
    {
233
        UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
M
mvandervoord 已提交
234
        divisor /= 10;
G
greg-williams 已提交
235
    }
M
mvandervoord 已提交
236
    while (divisor > 0);
G
greg-williams 已提交
237 238
}

M
mvandervoord 已提交
239
//-----------------------------------------------
M
mvandervoord 已提交
240
void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print)
G
greg-williams 已提交
241
{
M
mvandervoord 已提交
242
    _U_UINT nibble;
M
mvandervoord 已提交
243
    char nibbles = nibbles_to_print;
244 245
    UNITY_OUTPUT_CHAR('0');
    UNITY_OUTPUT_CHAR('x');
G
greg-williams 已提交
246 247 248 249 250 251

    while (nibbles > 0)
    {
        nibble = (number >> (--nibbles << 2)) & 0x0000000F;
        if (nibble <= 9)
        {
252
            UNITY_OUTPUT_CHAR((char)('0' + nibble));
G
greg-williams 已提交
253 254 255
        }
        else
        {
256
            UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble));
G
greg-williams 已提交
257 258 259 260
        }
    }
}

M
mvandervoord 已提交
261
//-----------------------------------------------
M
mvandervoord 已提交
262
void UnityPrintMask(const _U_UINT mask, const _U_UINT number)
G
greg-williams 已提交
263
{
264
    _U_UINT current_bit = (_U_UINT)1 << (UNITY_INT_WIDTH - 1);
265
    _US32 i;
G
greg-williams 已提交
266

M
mvandervoord 已提交
267
    for (i = 0; i < UNITY_INT_WIDTH; i++)
G
greg-williams 已提交
268
    {
269
        if (current_bit & mask)
G
greg-williams 已提交
270
        {
271
            if (current_bit & number)
G
greg-williams 已提交
272
            {
273
                UNITY_OUTPUT_CHAR('1');
G
greg-williams 已提交
274 275 276
            }
            else
            {
277
                UNITY_OUTPUT_CHAR('0');
G
greg-williams 已提交
278 279 280 281
            }
        }
        else
        {
282
            UNITY_OUTPUT_CHAR('X');
G
greg-williams 已提交
283
        }
284
        current_bit = current_bit >> 1;
G
greg-williams 已提交
285 286 287
    }
}

M
mvandervoord 已提交
288
//-----------------------------------------------
289
#ifdef UNITY_FLOAT_VERBOSE
290
#include <string.h>
291 292 293 294 295 296 297 298
void UnityPrintFloat(_UF number)
{
    char TempBuffer[32];
    sprintf(TempBuffer, "%.6f", number);
    UnityPrint(TempBuffer);
}
#endif

299 300
//-----------------------------------------------

301
void UnityPrintFail(void);
302 303
void UnityPrintFail(void)
{
304
    UnityPrint(UnityStrFail);
305 306
}

307
void UnityPrintOk(void);
308 309
void UnityPrintOk(void)
{
310
    UnityPrint(UnityStrOk);
311 312
}

M
mvandervoord 已提交
313
//-----------------------------------------------
314
static void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line);
315
static void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line)
G
greg-williams 已提交
316
{
317
#ifndef UNITY_FIXTURES
318
    UnityPrint(file);
319
    UNITY_OUTPUT_CHAR(':');
320
    UnityPrintNumber((_U_SINT)line);
321
    UNITY_OUTPUT_CHAR(':');
G
greg-williams 已提交
322
    UnityPrint(Unity.CurrentTestName);
323
    UNITY_OUTPUT_CHAR(':');
324 325 326 327
#else
    UNITY_UNUSED(file);
    UNITY_UNUSED(line);
#endif
G
greg-williams 已提交
328 329
}

M
mvandervoord 已提交
330
//-----------------------------------------------
331
static void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line);
332
static void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line)
333
{
334
#ifndef UNITY_FIXTURES
M
mvandervoord 已提交
335
    UnityTestResultsBegin(Unity.TestFile, line);
336 337 338
#else
    UNITY_UNUSED(line);
#endif
339 340
    UnityPrint(UnityStrFail);
    UNITY_OUTPUT_CHAR(':');
341 342
}

M
mvandervoord 已提交
343
//-----------------------------------------------
344
void UnityConcludeTest(void)
G
greg-williams 已提交
345 346 347 348 349 350 351
{
    if (Unity.CurrentTestIgnored)
    {
        Unity.TestIgnores++;
    }
    else if (!Unity.CurrentTestFailed)
    {
352
        UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
353
        UnityPrint(UnityStrPass);
G
greg-williams 已提交
354 355 356 357 358 359 360 361
    }
    else
    {
        Unity.TestFailures++;
    }

    Unity.CurrentTestFailed = 0;
    Unity.CurrentTestIgnored = 0;
362
    UNITY_PRINT_EOL;
G
greg-williams 已提交
363 364
}

M
mvandervoord 已提交
365
//-----------------------------------------------
366
static void UnityAddMsgIfSpecified(const char* msg);
367
static void UnityAddMsgIfSpecified(const char* msg)
M
mvandervoord 已提交
368 369 370 371 372 373 374 375
{
    if (msg)
    {
        UnityPrint(UnityStrSpacer);
        UnityPrint(msg);
    }
}

376
//-----------------------------------------------
377
static void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual);
378
static void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual)
379
{
M
mvandervoord 已提交
380 381 382 383 384 385 386 387 388
    UnityPrint(UnityStrExpected);
    if (expected != NULL)
    {
        UNITY_OUTPUT_CHAR('\'');
        UnityPrint(expected);
        UNITY_OUTPUT_CHAR('\'');
    }
    else
    {
389
      UnityPrint(UnityStrNull);
M
mvandervoord 已提交
390 391 392 393 394 395 396 397 398 399
    }
    UnityPrint(UnityStrWas);
    if (actual != NULL)
    {
        UNITY_OUTPUT_CHAR('\'');
        UnityPrint(actual);
        UNITY_OUTPUT_CHAR('\'');
    }
    else
    {
400
      UnityPrint(UnityStrNull);
M
mvandervoord 已提交
401
    }
402 403
}

404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
//-----------------------------------------------
static void UnityPrintExpectedAndActualStringsLen(const char* expected, const char* actual, const _UU32 length)
{
    UnityPrint(UnityStrExpected);
    if (expected != NULL)
    {
        UNITY_OUTPUT_CHAR('\'');
        UnityPrintLen(expected, length);
        UNITY_OUTPUT_CHAR('\'');
    }
    else
    {
      UnityPrint(UnityStrNull);
    }
    UnityPrint(UnityStrWas);
    if (actual != NULL)
    {
        UNITY_OUTPUT_CHAR('\'');
        UnityPrintLen(actual, length);
        UNITY_OUTPUT_CHAR('\'');
    }
    else
    {
      UnityPrint(UnityStrNull);
    }
}



433 434 435 436
//-----------------------------------------------
// Assertion & Control Helpers
//-----------------------------------------------

437
static int UnityCheckArraysForNull(UNITY_PTR_ATTRIBUTE const void* expected, UNITY_PTR_ATTRIBUTE const void* actual, const UNITY_LINE_TYPE lineNumber, const char* msg)
438 439 440 441
{
    //return true if they are both NULL
    if ((expected == NULL) && (actual == NULL))
        return 1;
442

443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
    //throw error if just expected is NULL
    if (expected == NULL)
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrNullPointerForExpected);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }

    //throw error if just actual is NULL
    if (actual == NULL)
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrNullPointerForActual);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
460

461 462 463
    //return false if neither is NULL
    return 0;
}
464

M
mvandervoord 已提交
465 466 467 468
//-----------------------------------------------
// Assertion Functions
//-----------------------------------------------

M
mvandervoord 已提交
469 470 471
void UnityAssertBits(const _U_SINT mask,
                     const _U_SINT expected,
                     const _U_SINT actual,
472
                     const char* msg,
M
mvandervoord 已提交
473
                     const UNITY_LINE_TYPE lineNumber)
G
greg-williams 已提交
474
{
475
    UNITY_SKIP_EXECUTION;
476

G
greg-williams 已提交
477 478
    if ((mask & expected) != (mask & actual))
    {
479
        UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
480
        UnityPrint(UnityStrExpected);
481
        UnityPrintMask((_U_UINT)mask, (_U_UINT)expected);
M
mvandervoord 已提交
482
        UnityPrint(UnityStrWas);
483
        UnityPrintMask((_U_UINT)mask, (_U_UINT)actual);
M
mvandervoord 已提交
484 485
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
G
greg-williams 已提交
486 487 488
    }
}

M
mvandervoord 已提交
489
//-----------------------------------------------
M
mvandervoord 已提交
490 491
void UnityAssertEqualNumber(const _U_SINT expected,
                            const _U_SINT actual,
M
mvandervoord 已提交
492 493 494
                            const char* msg,
                            const UNITY_LINE_TYPE lineNumber,
                            const UNITY_DISPLAY_STYLE_T style)
495
{
496 497
    UNITY_SKIP_EXECUTION;

498 499
    if (expected != actual)
    {
500
        UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
501
        UnityPrint(UnityStrExpected);
502
        UnityPrintNumberByStyle(expected, style);
M
mvandervoord 已提交
503
        UnityPrint(UnityStrWas);
504
        UnityPrintNumberByStyle(actual, style);
M
mvandervoord 已提交
505 506
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
507 508 509
    }
}

M
mvandervoord 已提交
510
//-----------------------------------------------
511 512
void UnityAssertEqualIntArray(UNITY_PTR_ATTRIBUTE const void* expected,
                              UNITY_PTR_ATTRIBUTE const void* actual,
513
                              const _UU32 num_elements,
514
                              const char* msg,
M
mvandervoord 已提交
515
                              const UNITY_LINE_TYPE lineNumber,
516 517
                              const UNITY_DISPLAY_STYLE_T style)
{
518
    _UU32 elements = num_elements;
519 520
    UNITY_PTR_ATTRIBUTE const void* ptr_exp = (UNITY_PTR_ATTRIBUTE const void*)expected;
    UNITY_PTR_ATTRIBUTE const void* ptr_act = (UNITY_PTR_ATTRIBUTE const void*)actual;
521

522
    UNITY_SKIP_EXECUTION;
523

524 525 526 527 528 529 530
    if (elements == 0)
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
531

532
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE const void*)expected, (UNITY_PTR_ATTRIBUTE const void*)actual, lineNumber, msg) == 1)
533
        return;
534

535 536 537
    // If style is UNITY_DISPLAY_STYLE_INT, we'll fall into the default case rather than the INT16 or INT32 (etc) case
    // as UNITY_DISPLAY_STYLE_INT includes a flag for UNITY_DISPLAY_RANGE_AUTO, which the width-specific
    // variants do not. Therefore remove this flag.
538
    switch(style & (UNITY_DISPLAY_STYLE_T)(~UNITY_DISPLAY_RANGE_AUTO))
539 540
    {
        case UNITY_DISPLAY_STYLE_HEX8:
M
mvandervoord 已提交
541 542
        case UNITY_DISPLAY_STYLE_INT8:
        case UNITY_DISPLAY_STYLE_UINT8:
543 544
            while (elements--)
            {
545
                if (*(UNITY_PTR_ATTRIBUTE const _US8*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US8*)ptr_act)
546 547 548 549 550
                {
                    UnityTestResultsFailBegin(lineNumber);
                    UnityPrint(UnityStrElement);
                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
                    UnityPrint(UnityStrExpected);
551
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US8*)ptr_exp, style);
552
                    UnityPrint(UnityStrWas);
553
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US8*)ptr_act, style);
554 555 556
                    UnityAddMsgIfSpecified(msg);
                    UNITY_FAIL_AND_BAIL;
                }
557 558
                ptr_exp = (UNITY_PTR_ATTRIBUTE const void*)((_UP)ptr_exp + 1);
                ptr_act = (UNITY_PTR_ATTRIBUTE const void*)((_UP)ptr_act + 1);
559 560 561
            }
            break;
        case UNITY_DISPLAY_STYLE_HEX16:
M
mvandervoord 已提交
562 563
        case UNITY_DISPLAY_STYLE_INT16:
        case UNITY_DISPLAY_STYLE_UINT16:
564 565
            while (elements--)
            {
566
                if (*(UNITY_PTR_ATTRIBUTE const _US16*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US16*)ptr_act)
567 568 569 570 571
                {
                    UnityTestResultsFailBegin(lineNumber);
                    UnityPrint(UnityStrElement);
                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
                    UnityPrint(UnityStrExpected);
572
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US16*)ptr_exp, style);
573
                    UnityPrint(UnityStrWas);
574
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US16*)ptr_act, style);
575 576 577
                    UnityAddMsgIfSpecified(msg);
                    UNITY_FAIL_AND_BAIL;
                }
578 579
                ptr_exp = (UNITY_PTR_ATTRIBUTE const void*)((_UP)ptr_exp + 2);
                ptr_act = (UNITY_PTR_ATTRIBUTE const void*)((_UP)ptr_act + 2);
580 581
            }
            break;
M
mvandervoord 已提交
582 583 584 585 586 587
#ifdef UNITY_SUPPORT_64
        case UNITY_DISPLAY_STYLE_HEX64:
        case UNITY_DISPLAY_STYLE_INT64:
        case UNITY_DISPLAY_STYLE_UINT64:
            while (elements--)
            {
588
                if (*(UNITY_PTR_ATTRIBUTE const _US64*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US64*)ptr_act)
M
mvandervoord 已提交
589 590 591 592 593
                {
                    UnityTestResultsFailBegin(lineNumber);
                    UnityPrint(UnityStrElement);
                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
                    UnityPrint(UnityStrExpected);
594
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US64*)ptr_exp, style);
M
mvandervoord 已提交
595
                    UnityPrint(UnityStrWas);
596
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US64*)ptr_act, style);
M
mvandervoord 已提交
597 598 599
                    UnityAddMsgIfSpecified(msg);
                    UNITY_FAIL_AND_BAIL;
                }
600 601
                ptr_exp = (UNITY_PTR_ATTRIBUTE const void*)((_UP)ptr_exp + 8);
                ptr_act = (UNITY_PTR_ATTRIBUTE const void*)((_UP)ptr_act + 8);
M
mvandervoord 已提交
602 603 604
            }
            break;
#endif
605 606 607
        default:
            while (elements--)
            {
608
                if (*(UNITY_PTR_ATTRIBUTE const _US32*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US32*)ptr_act)
609 610 611 612 613
                {
                    UnityTestResultsFailBegin(lineNumber);
                    UnityPrint(UnityStrElement);
                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
                    UnityPrint(UnityStrExpected);
614
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US32*)ptr_exp, style);
615
                    UnityPrint(UnityStrWas);
616
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US32*)ptr_act, style);
617 618 619
                    UnityAddMsgIfSpecified(msg);
                    UNITY_FAIL_AND_BAIL;
                }
620 621
                ptr_exp = (UNITY_PTR_ATTRIBUTE const void*)((_UP)ptr_exp + 4);
                ptr_act = (UNITY_PTR_ATTRIBUTE const void*)((_UP)ptr_act + 4);
622 623 624 625 626
            }
            break;
    }
}

M
mvandervoord 已提交
627
//-----------------------------------------------
628
#ifndef UNITY_EXCLUDE_FLOAT
629 630
void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected,
                                UNITY_PTR_ATTRIBUTE const _UF* actual,
631
                                const _UU32 num_elements,
632 633 634
                                const char* msg,
                                const UNITY_LINE_TYPE lineNumber)
{
635
    _UU32 elements = num_elements;
636 637
    UNITY_PTR_ATTRIBUTE const _UF* ptr_expected = expected;
    UNITY_PTR_ATTRIBUTE const _UF* ptr_actual = actual;
M
mvandervoord 已提交
638
    _UF diff, tol;
639

640
    UNITY_SKIP_EXECUTION;
641

642 643
    if (elements == 0)
    {
644
        UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
645 646 647
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
648
    }
649

650
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE const void*)expected, (UNITY_PTR_ATTRIBUTE const void*)actual, lineNumber, msg) == 1)
651
        return;
652 653 654

    while (elements--)
    {
655
        diff = *ptr_expected - *ptr_actual;
656 657
        if (diff < 0.0f)
          diff = 0.0f - diff;
M
mvandervoord 已提交
658
        tol = UNITY_FLOAT_PRECISION * *ptr_expected;
659 660
        if (tol < 0.0f)
            tol = 0.0f - tol;
661

662 663
        //This first part of this condition will catch any NaN or Infinite values
        if ((diff * 0.0f != 0.0f) || (diff > tol))
664
        {
665
            UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
666
            UnityPrint(UnityStrElement);
667
            UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
668 669 670 671 672 673
#ifdef UNITY_FLOAT_VERBOSE
            UnityPrint(UnityStrExpected);
            UnityPrintFloat(*ptr_expected);
            UnityPrint(UnityStrWas);
            UnityPrintFloat(*ptr_actual);
#else
674
            UnityPrint(UnityStrDelta);
675
#endif
M
mvandervoord 已提交
676 677
            UnityAddMsgIfSpecified(msg);
            UNITY_FAIL_AND_BAIL;
M
mvandervoord 已提交
678
        }
679 680
        ptr_expected++;
        ptr_actual++;
M
mvandervoord 已提交
681 682 683
    }
}

M
mvandervoord 已提交
684
//-----------------------------------------------
685 686 687
void UnityAssertFloatsWithin(const _UF delta,
                             const _UF expected,
                             const _UF actual,
688
                             const char* msg,
M
mvandervoord 已提交
689
                             const UNITY_LINE_TYPE lineNumber)
G
greg-williams 已提交
690
{
691 692
    _UF diff = actual - expected;
    _UF pos_delta = delta;
693

694
    UNITY_SKIP_EXECUTION;
695

696
    if (diff < 0.0f)
G
greg-williams 已提交
697
    {
698
        diff = 0.0f - diff;
G
greg-williams 已提交
699
    }
700
    if (pos_delta < 0.0f)
701 702 703
    {
        pos_delta = 0.0f - pos_delta;
    }
704

705 706
    //This first part of this condition will catch any NaN or Infinite values
    if ((diff * 0.0f != 0.0f) || (pos_delta < diff))
G
greg-williams 已提交
707
    {
708
        UnityTestResultsFailBegin(lineNumber);
709 710 711 712 713 714
#ifdef UNITY_FLOAT_VERBOSE
        UnityPrint(UnityStrExpected);
        UnityPrintFloat(expected);
        UnityPrint(UnityStrWas);
        UnityPrintFloat(actual);
#else
M
mvandervoord 已提交
715
        UnityPrint(UnityStrDelta);
716
#endif
M
mvandervoord 已提交
717 718
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
G
greg-williams 已提交
719 720
    }
}
M
mvandervoord 已提交
721

722
//-----------------------------------------------
723 724 725
void UnityAssertFloatSpecial(const _UF actual,
                             const char* msg,
                             const UNITY_LINE_TYPE lineNumber,
726
                             const UNITY_FLOAT_TRAIT_T style)
727
{
728
    const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet };
729 730 731
    _U_SINT should_be_trait   = ((_U_SINT)style & 1);
    _U_SINT is_trait          = !should_be_trait;
    _U_SINT trait_index       = style >> 1;
732

733 734
    UNITY_SKIP_EXECUTION;

735
    switch(style)
736
    {
737 738 739 740 741 742 743 744 745 746
        //To determine Inf / Neg Inf, we compare to an Inf / Neg Inf value we create on the fly
        //We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise
        case UNITY_FLOAT_IS_INF:
        case UNITY_FLOAT_IS_NOT_INF:
            is_trait = ((1.0f / f_zero) == actual) ? 1 : 0;
            break;
        case UNITY_FLOAT_IS_NEG_INF:
        case UNITY_FLOAT_IS_NOT_NEG_INF:
            is_trait = ((-1.0f / f_zero) == actual) ? 1 : 0;
            break;
747

748 749 750 751 752
        //NaN is the only floating point value that does NOT equal itself. Therefore if Actual == Actual, then it is NOT NaN.
        case UNITY_FLOAT_IS_NAN:
        case UNITY_FLOAT_IS_NOT_NAN:
            is_trait = (actual == actual) ? 0 : 1;
            break;
753 754 755 756 757 758 759 760 761

        //A determinate number is non infinite and not NaN. (therefore the opposite of the two above)
        case UNITY_FLOAT_IS_DET:
        case UNITY_FLOAT_IS_NOT_DET:
            if ( (actual != actual) || ((1.0f / f_zero) == actual) || ((-1.0f / f_zero) == actual) )
                is_trait = 0;
            else
                is_trait = 1;
            break;
K
kotofos 已提交
762 763
	default:
	    ;
764
    }
765

766
    if (is_trait != should_be_trait)
767 768 769
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrExpected);
770
        if (!should_be_trait)
771
            UnityPrint(UnityStrNot);
772
        UnityPrint(trait_names[trait_index]);
773
        UnityPrint(UnityStrWas);
774
#ifdef UNITY_FLOAT_VERBOSE
775 776
        UnityPrintFloat(actual);
#else
777
        if (should_be_trait)
778
            UnityPrint(UnityStrNot);
779
        UnityPrint(trait_names[trait_index]);
780 781 782 783 784 785
#endif
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
}

M
mvandervoord 已提交
786 787 788 789
#endif //not UNITY_EXCLUDE_FLOAT

//-----------------------------------------------
#ifndef UNITY_EXCLUDE_DOUBLE
790 791
void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected,
                                 UNITY_PTR_ATTRIBUTE const _UD* actual,
M
mvandervoord 已提交
792 793 794 795 796
                                 const _UU32 num_elements,
                                 const char* msg,
                                 const UNITY_LINE_TYPE lineNumber)
{
    _UU32 elements = num_elements;
797 798
    UNITY_PTR_ATTRIBUTE const _UD* ptr_expected = expected;
    UNITY_PTR_ATTRIBUTE const _UD* ptr_actual = actual;
M
mvandervoord 已提交
799 800 801
    _UD diff, tol;

    UNITY_SKIP_EXECUTION;
802

M
mvandervoord 已提交
803 804 805 806 807 808 809
    if (elements == 0)
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
810

811
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1)
M
mvandervoord 已提交
812 813 814 815 816 817 818 819 820 821
        return;

    while (elements--)
    {
        diff = *ptr_expected - *ptr_actual;
        if (diff < 0.0)
          diff = 0.0 - diff;
        tol = UNITY_DOUBLE_PRECISION * *ptr_expected;
        if (tol < 0.0)
            tol = 0.0 - tol;
822

823
        //This first part of this condition will catch any NaN or Infinite values
824
        if ((diff * 0.0 != 0.0) || (diff > tol))
M
mvandervoord 已提交
825 826 827 828 829 830 831 832 833 834 835
        {
            UnityTestResultsFailBegin(lineNumber);
            UnityPrint(UnityStrElement);
            UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
#ifdef UNITY_DOUBLE_VERBOSE
            UnityPrint(UnityStrExpected);
            UnityPrintFloat((float)(*ptr_expected));
            UnityPrint(UnityStrWas);
            UnityPrintFloat((float)(*ptr_actual));
#else
            UnityPrint(UnityStrDelta);
836
#endif
M
mvandervoord 已提交
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855
            UnityAddMsgIfSpecified(msg);
            UNITY_FAIL_AND_BAIL;
        }
        ptr_expected++;
        ptr_actual++;
    }
}

//-----------------------------------------------
void UnityAssertDoublesWithin(const _UD delta,
                              const _UD expected,
                              const _UD actual,
                              const char* msg,
                              const UNITY_LINE_TYPE lineNumber)
{
    _UD diff = actual - expected;
    _UD pos_delta = delta;

    UNITY_SKIP_EXECUTION;
856

857
    if (diff < 0.0)
M
mvandervoord 已提交
858
    {
859
        diff = 0.0 - diff;
M
mvandervoord 已提交
860
    }
861
    if (pos_delta < 0.0)
M
mvandervoord 已提交
862
    {
863
        pos_delta = 0.0 - pos_delta;
M
mvandervoord 已提交
864 865
    }

866
    //This first part of this condition will catch any NaN or Infinite values
867
    if ((diff * 0.0 != 0.0) || (pos_delta < diff))
M
mvandervoord 已提交
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882
    {
        UnityTestResultsFailBegin(lineNumber);
#ifdef UNITY_DOUBLE_VERBOSE
        UnityPrint(UnityStrExpected);
        UnityPrintFloat((float)expected);
        UnityPrint(UnityStrWas);
        UnityPrintFloat((float)actual);
#else
        UnityPrint(UnityStrDelta);
#endif
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
}

883
//-----------------------------------------------
884 885 886 887

void UnityAssertDoubleSpecial(const _UD actual,
                              const char* msg,
                              const UNITY_LINE_TYPE lineNumber,
888
                              const UNITY_FLOAT_TRAIT_T style)
889
{
890 891 892 893 894
    const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet };
    _U_SINT should_be_trait   = ((_U_SINT)style & 1);
    _U_SINT is_trait          = !should_be_trait;
    _U_SINT trait_index       = style >> 1;

895 896
    UNITY_SKIP_EXECUTION;

897
    switch(style)
898
    {
899 900 901 902 903 904 905 906 907 908
        //To determine Inf / Neg Inf, we compare to an Inf / Neg Inf value we create on the fly
        //We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise
        case UNITY_FLOAT_IS_INF:
        case UNITY_FLOAT_IS_NOT_INF:
            is_trait = ((1.0 / d_zero) == actual) ? 1 : 0;
            break;
        case UNITY_FLOAT_IS_NEG_INF:
        case UNITY_FLOAT_IS_NOT_NEG_INF:
            is_trait = ((-1.0 / d_zero) == actual) ? 1 : 0;
            break;
909

910 911 912 913 914
        //NaN is the only floating point value that does NOT equal itself. Therefore if Actual == Actual, then it is NOT NaN.
        case UNITY_FLOAT_IS_NAN:
        case UNITY_FLOAT_IS_NOT_NAN:
            is_trait = (actual == actual) ? 0 : 1;
            break;
915

916 917 918 919 920 921 922 923
        //A determinate number is non infinite and not NaN. (therefore the opposite of the two above)
        case UNITY_FLOAT_IS_DET:
        case UNITY_FLOAT_IS_NOT_DET:
            if ( (actual != actual) || ((1.0 / d_zero) == actual) || ((-1.0 / d_zero) == actual) )
                is_trait = 0;
            else
                is_trait = 1;
            break;
K
kotofos 已提交
924 925
	default:
	    ;
926 927
    }

928
    if (is_trait != should_be_trait)
929 930 931
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrExpected);
932 933 934
        if (!should_be_trait)
            UnityPrint(UnityStrNot);
        UnityPrint(trait_names[trait_index]);
935
        UnityPrint(UnityStrWas);
936 937
#ifdef UNITY_DOUBLE_VERBOSE
        UnityPrintFloat(actual);
938
#else
939 940 941
        if (should_be_trait)
            UnityPrint(UnityStrNot);
        UnityPrint(trait_names[trait_index]);
942 943 944 945 946 947
#endif
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
}

948

M
mvandervoord 已提交
949
#endif // not UNITY_EXCLUDE_DOUBLE
G
greg-williams 已提交
950

M
mvandervoord 已提交
951
//-----------------------------------------------
M
mvandervoord 已提交
952 953 954
void UnityAssertNumbersWithin( const _U_SINT delta,
                               const _U_SINT expected,
                               const _U_SINT actual,
M
mvandervoord 已提交
955 956 957
                               const char* msg,
                               const UNITY_LINE_TYPE lineNumber,
                               const UNITY_DISPLAY_STYLE_T style)
G
greg-williams 已提交
958
{
959
    UNITY_SKIP_EXECUTION;
960

M
mvandervoord 已提交
961
    if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
G
greg-williams 已提交
962
    {
M
mvandervoord 已提交
963 964 965 966
        if (actual > expected)
          Unity.CurrentTestFailed = ((actual - expected) > delta);
        else
          Unity.CurrentTestFailed = ((expected - actual) > delta);
G
greg-williams 已提交
967
    }
M
mvandervoord 已提交
968
    else
G
greg-williams 已提交
969
    {
M
mvandervoord 已提交
970 971
        if ((_U_UINT)actual > (_U_UINT)expected)
            Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > (_U_UINT)delta);
M
mvandervoord 已提交
972
        else
M
mvandervoord 已提交
973
            Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > (_U_UINT)delta);
974 975
    }

M
mvandervoord 已提交
976
    if (Unity.CurrentTestFailed)
977
    {
978
        UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
979 980 981 982 983 984 985 986
        UnityPrint(UnityStrDelta);
        UnityPrintNumberByStyle(delta, style);
        UnityPrint(UnityStrExpected);
        UnityPrintNumberByStyle(expected, style);
        UnityPrint(UnityStrWas);
        UnityPrintNumberByStyle(actual, style);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
G
greg-williams 已提交
987 988 989
    }
}

M
mvandervoord 已提交
990
//-----------------------------------------------
991 992 993
void UnityAssertEqualString(const char* expected,
                            const char* actual,
                            const char* msg,
M
mvandervoord 已提交
994
                            const UNITY_LINE_TYPE lineNumber)
G
greg-williams 已提交
995
{
996
    _UU32 i;
G
greg-williams 已提交
997

998
    UNITY_SKIP_EXECUTION;
999

G
greg-williams 已提交
1000 1001 1002 1003 1004 1005 1006 1007
    // if both pointers not null compare the strings
    if (expected && actual)
    {
        for (i = 0; expected[i] || actual[i]; i++)
        {
            if (expected[i] != actual[i])
            {
                Unity.CurrentTestFailed = 1;
1008
                break;
G
greg-williams 已提交
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
            }
        }
    }
    else
    { // handle case of one pointers being null (if both null, test should pass)
        if (expected != actual)
        {
            Unity.CurrentTestFailed = 1;
        }
    }

    if (Unity.CurrentTestFailed)
    {
1022
      UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
1023
      UnityPrintExpectedAndActualStrings(expected, actual);
1024 1025
      UnityAddMsgIfSpecified(msg);
      UNITY_FAIL_AND_BAIL;
G
greg-williams 已提交
1026 1027 1028
    }
}

1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
//-----------------------------------------------
void UnityAssertEqualStringLen(const char* expected,
                            const char* actual,
                            const _UU32 length,
                            const char* msg,
                            const UNITY_LINE_TYPE lineNumber)
{
    _UU32 i;

    UNITY_SKIP_EXECUTION;

    // if both pointers not null compare the strings
    if (expected && actual)
    {
        for (i = 0; (expected[i] || actual[i]) && i < length; i++)
        {
            if (expected[i] != actual[i])
            {
                Unity.CurrentTestFailed = 1;
                break;
            }
        }
    }
    else
    { // handle case of one pointers being null (if both null, test should pass)
        if (expected != actual)
        {
            Unity.CurrentTestFailed = 1;
        }
    }

    if (Unity.CurrentTestFailed)
    {
      UnityTestResultsFailBegin(lineNumber);
      UnityPrintExpectedAndActualStringsLen(expected, actual, length);
      UnityAddMsgIfSpecified(msg);
      UNITY_FAIL_AND_BAIL;
    }
}


M
mvandervoord 已提交
1070 1071 1072 1073 1074 1075 1076 1077
//-----------------------------------------------
void UnityAssertEqualStringArray( const char** expected,
                                  const char** actual,
                                  const _UU32 num_elements,
                                  const char* msg,
                                  const UNITY_LINE_TYPE lineNumber)
{
    _UU32 i, j = 0;
1078

1079
    UNITY_SKIP_EXECUTION;
1080

M
mvandervoord 已提交
1081 1082 1083 1084 1085 1086 1087 1088 1089
    // if no elements, it's an error
    if (num_elements == 0)
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }

1090
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1)
1091
        return;
1092

M
mvandervoord 已提交
1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
    do
    {
        // if both pointers not null compare the strings
        if (expected[j] && actual[j])
        {
            for (i = 0; expected[j][i] || actual[j][i]; i++)
            {
                if (expected[j][i] != actual[j][i])
                {
                    Unity.CurrentTestFailed = 1;
                    break;
                }
            }
        }
        else
        { // handle case of one pointers being null (if both null, test should pass)
            if (expected[j] != actual[j])
            {
                Unity.CurrentTestFailed = 1;
            }
        }

        if (Unity.CurrentTestFailed)
        {
            UnityTestResultsFailBegin(lineNumber);
            if (num_elements > 1)
            {
                UnityPrint(UnityStrElement);
1121
                UnityPrintNumberByStyle((j), UNITY_DISPLAY_STYLE_UINT);
M
mvandervoord 已提交
1122
            }
M
mvandervoord 已提交
1123
            UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j]));
M
mvandervoord 已提交
1124 1125
            UnityAddMsgIfSpecified(msg);
            UNITY_FAIL_AND_BAIL;
1126
        }
M
mvandervoord 已提交
1127 1128 1129 1130
    } while (++j < num_elements);
}

//-----------------------------------------------
1131 1132
void UnityAssertEqualMemory( UNITY_PTR_ATTRIBUTE const void* expected,
                             UNITY_PTR_ATTRIBUTE const void* actual,
1133 1134
                             const _UU32 length,
                             const _UU32 num_elements,
M
mvandervoord 已提交
1135 1136
                             const char* msg,
                             const UNITY_LINE_TYPE lineNumber)
1137
{
1138 1139
    UNITY_PTR_ATTRIBUTE const unsigned char* ptr_exp = (UNITY_PTR_ATTRIBUTE const unsigned char*)expected;
    UNITY_PTR_ATTRIBUTE const unsigned char* ptr_act = (UNITY_PTR_ATTRIBUTE const unsigned char*)actual;
1140
    _UU32 elements = num_elements;
1141
    _UU32 bytes;
1142 1143

    UNITY_SKIP_EXECUTION;
1144

1145 1146
    if ((elements == 0) || (length == 0))
    {
1147
        UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
1148 1149 1150
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
1151
    }
1152

1153
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE const void*)expected, (UNITY_PTR_ATTRIBUTE const void*)actual, lineNumber, msg) == 1)
1154
        return;
1155

1156
    while (elements--)
1157
    {
1158 1159 1160
        /////////////////////////////////////
        bytes = length;
        while (bytes--)
1161
        {
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179
            if (*ptr_exp != *ptr_act)
            {
                UnityTestResultsFailBegin(lineNumber);
                UnityPrint(UnityStrMemory);
                if (num_elements > 1)
                {
                    UnityPrint(UnityStrElement);
                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
                }
                UnityPrint(UnityStrByte);
                UnityPrintNumberByStyle((length - bytes - 1), UNITY_DISPLAY_STYLE_UINT);
                UnityPrint(UnityStrExpected);
                UnityPrintNumberByStyle(*ptr_exp, UNITY_DISPLAY_STYLE_HEX8);
                UnityPrint(UnityStrWas);
                UnityPrintNumberByStyle(*ptr_act, UNITY_DISPLAY_STYLE_HEX8);
                UnityAddMsgIfSpecified(msg);
                UNITY_FAIL_AND_BAIL;
            }
1180 1181
            ptr_exp = (UNITY_PTR_ATTRIBUTE const void*)((_UP)ptr_exp + 1);
            ptr_act = (UNITY_PTR_ATTRIBUTE const void*)((_UP)ptr_act + 1);
1182
        }
1183
        /////////////////////////////////////
1184

1185 1186 1187
    }
}

M
mvandervoord 已提交
1188 1189 1190 1191 1192
//-----------------------------------------------
// Control Functions
//-----------------------------------------------

void UnityFail(const char* msg, const UNITY_LINE_TYPE line)
G
greg-williams 已提交
1193
{
1194 1195
    UNITY_SKIP_EXECUTION;

M
mvandervoord 已提交
1196
    UnityTestResultsBegin(Unity.TestFile, line);
1197
    UnityPrintFail();
M
mvandervoord 已提交
1198
    if (msg != NULL)
1199 1200
    {
      UNITY_OUTPUT_CHAR(':');
1201 1202
      if (msg[0] != ' ')
      {
1203
        UNITY_OUTPUT_CHAR(' ');
M
mvandervoord 已提交
1204
      }
M
mvandervoord 已提交
1205
      UnityPrint(msg);
1206
    }
M
mvandervoord 已提交
1207
    UNITY_FAIL_AND_BAIL;
G
greg-williams 已提交
1208 1209
}

M
mvandervoord 已提交
1210
//-----------------------------------------------
M
mvandervoord 已提交
1211
void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
G
greg-williams 已提交
1212
{
1213 1214
    UNITY_SKIP_EXECUTION;

M
mvandervoord 已提交
1215
    UnityTestResultsBegin(Unity.TestFile, line);
1216
    UnityPrint(UnityStrIgnore);
M
mvandervoord 已提交
1217
    if (msg != NULL)
1218 1219
    {
      UNITY_OUTPUT_CHAR(':');
1220
      UNITY_OUTPUT_CHAR(' ');
M
mvandervoord 已提交
1221
      UnityPrint(msg);
1222
    }
M
mvandervoord 已提交
1223
    UNITY_IGNORE_AND_BAIL;
G
greg-williams 已提交
1224 1225
}

1226
//-----------------------------------------------
1227
#if defined(UNITY_WEAK_ATTRIBUTE)
1228 1229
    void setUp(void);
    void tearDown(void);
1230 1231 1232 1233
    UNITY_WEAK_ATTRIBUTE void setUp(void) { }
    UNITY_WEAK_ATTRIBUTE void tearDown(void) { }
#elif defined(UNITY_WEAK_PRAGMA)
#   pragma weak setUp
1234
    void setUp(void) { }
1235
#   pragma weak tearDown
1236
    void tearDown(void) { }
1237
#else
1238 1239
    void setUp(void);
    void tearDown(void);
1240 1241
#endif
//-----------------------------------------------
1242 1243 1244
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
{
    Unity.CurrentTestName = FuncName;
1245
    Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)FuncLineNum;
1246
    Unity.NumberOfTests++;
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
    if (TEST_PROTECT())
    {
        setUp();
        Func();
    }
    if (TEST_PROTECT() && !(Unity.CurrentTestIgnored))
    {
        tearDown();
    }
    UnityConcludeTest();
}

M
mvandervoord 已提交
1259
//-----------------------------------------------
M
Mark VanderVoord 已提交
1260
void UnityBegin(const char* filename)
G
greg-williams 已提交
1261
{
M
Mark VanderVoord 已提交
1262
    Unity.TestFile = filename;
1263 1264
    Unity.CurrentTestName = NULL;
    Unity.CurrentTestLineNumber = 0;
G
greg-williams 已提交
1265
    Unity.NumberOfTests = 0;
1266 1267 1268 1269
    Unity.TestFailures = 0;
    Unity.TestIgnores = 0;
    Unity.CurrentTestFailed = 0;
    Unity.CurrentTestIgnored = 0;
M
Mark VanderVoord 已提交
1270 1271

    UNITY_OUTPUT_START();
G
greg-williams 已提交
1272 1273
}

M
mvandervoord 已提交
1274
//-----------------------------------------------
1275
int UnityEnd(void)
G
greg-williams 已提交
1276
{
1277
    UNITY_PRINT_EOL;
1278
    UnityPrint(UnityStrBreaker);
M
mvandervoord 已提交
1279
    UNITY_PRINT_EOL;
1280
    UnityPrintNumber((_U_SINT)(Unity.NumberOfTests));
1281
    UnityPrint(UnityStrResultsTests);
1282
    UnityPrintNumber((_U_SINT)(Unity.TestFailures));
1283
    UnityPrint(UnityStrResultsFailures);
1284
    UnityPrintNumber((_U_SINT)(Unity.TestIgnores));
1285
    UnityPrint(UnityStrResultsIgnored);
M
mvandervoord 已提交
1286
    UNITY_PRINT_EOL;
G
greg-williams 已提交
1287 1288
    if (Unity.TestFailures == 0U)
    {
1289
        UnityPrintOk();
G
greg-williams 已提交
1290 1291 1292
    }
    else
    {
1293
        UnityPrintFail();
G
greg-williams 已提交
1294
    }
M
mvandervoord 已提交
1295
    UNITY_PRINT_EOL;
M
Mark VanderVoord 已提交
1296
    UNITY_OUTPUT_COMPLETE();
1297
    return (int)(Unity.TestFailures);
G
greg-williams 已提交
1298
}
1299 1300

//-----------------------------------------------