unity.c 36.0 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 8
#include "unity.h"

9 10
#define UNITY_FAIL_AND_BAIL   { Unity.CurrentTestFailed  = 1; longjmp(Unity.AbortFrame, 1); }
#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; longjmp(Unity.AbortFrame, 1); }
11 12
/// 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 已提交
13
#define UNITY_PRINT_EOL       { UNITY_OUTPUT_CHAR('\n'); }
M
mvandervoord 已提交
14

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

17
const char* UnityStrNull     = "NULL";
18
const char* UnityStrSpacer   = ". ";
M
mvandervoord 已提交
19 20 21 22
const char* UnityStrExpected = " Expected ";
const char* UnityStrWas      = " Was ";
const char* UnityStrTo       = " To ";
const char* UnityStrElement  = " Element ";
23 24
const char* UnityStrByte     = " Byte ";
const char* UnityStrMemory   = " Memory Mismatch.";
M
mvandervoord 已提交
25
const char* UnityStrDelta    = " Values Not Within Delta ";
26
const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless.";
27 28
const char* UnityStrNullPointerForExpected= " Expected pointer to be NULL";
const char* UnityStrNullPointerForActual  = " Actual pointer was NULL";
29
const char* UnityStrNot      = "Not ";
30 31 32
const char* UnityStrInf      = "Infinity";
const char* UnityStrNegInf   = "Negative Infinity";
const char* UnityStrNaN      = "NaN";
33
const char* UnityStrDet      = "Determinate";
34 35 36
const char* UnityStrErrFloat = "Unity Floating Point Disabled";
const char* UnityStrErrDouble= "Unity Double Precision Disabled";
const char* UnityStrErr64    = "Unity 64-bit Support Disabled";
M
mvandervoord 已提交
37

38
#ifndef UNITY_EXCLUDE_FLOAT
39 40 41 42 43 44
// 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
45
#endif
46

47
// compiler-generic print formatting masks
48
const _U_UINT UnitySizeMask[] =
49
{
50 51
    255u,         // 0xFF
    65535u,       // 0xFFFF
M
 
mvandervoord 已提交
52
    65535u,
53
    4294967295u,  // 0xFFFFFFFF
M
 
mvandervoord 已提交
54 55 56
    4294967295u,
    4294967295u,
    4294967295u
57 58 59 60 61
#ifdef UNITY_SUPPORT_64
    ,0xFFFFFFFFFFFFFFFF
#endif
};

62 63 64
void UnityPrintFail(void);
void UnityPrintOk(void);

M
mvandervoord 已提交
65
//-----------------------------------------------
66
// Pretty Printers & Test Result Output Handlers
M
mvandervoord 已提交
67 68
//-----------------------------------------------

69
void UnityPrint(const char* string)
G
greg-williams 已提交
70
{
71
    const char* pch = string;
G
greg-williams 已提交
72 73 74 75 76

    if (pch != NULL)
    {
        while (*pch)
        {
M
mvandervoord 已提交
77
            // printable characters plus CR & LF are printed
M
mvandervoord 已提交
78
            if ((*pch <= 126) && (*pch >= 32))
M
mvandervoord 已提交
79 80 81
            {
                UNITY_OUTPUT_CHAR(*pch);
            }
M
mvandervoord 已提交
82 83 84 85 86 87 88 89 90 91 92 93
            //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 已提交
94 95 96 97
            // unprintable characters are shown as codes
            else
            {
                UNITY_OUTPUT_CHAR('\\');
98
                UnityPrintNumberHex((_U_UINT)*pch, 2);
M
mvandervoord 已提交
99
            }
G
greg-williams 已提交
100 101 102 103 104
            pch++;
        }
    }
}

M
mvandervoord 已提交
105
//-----------------------------------------------
M
mvandervoord 已提交
106
void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style)
G
greg-williams 已提交
107
{
M
mvandervoord 已提交
108 109 110 111 112 113
    if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
    {
        UnityPrintNumber(number);
    }
    else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT)
    {
114
        UnityPrintNumberUnsigned(  (_U_UINT)number  &  UnitySizeMask[((_U_UINT)style & (_U_UINT)0x0F) - 1]  );
M
mvandervoord 已提交
115 116
    }
    else
G
greg-williams 已提交
117
    {
118
        UnityPrintNumberHex((_U_UINT)number, (char)((style & 0x000F) << 1));
G
greg-williams 已提交
119 120 121
    }
}

M
mvandervoord 已提交
122
//-----------------------------------------------
G
greg-williams 已提交
123
/// basically do an itoa using as little ram as possible
M
mvandervoord 已提交
124
void UnityPrintNumber(const _U_SINT number_to_print)
G
greg-williams 已提交
125
{
M
mvandervoord 已提交
126 127
    _U_SINT divisor = 1;
    _U_SINT next_divisor;
128 129
    _U_UINT number;

130
    if (number_to_print == (1l << (UNITY_LONG_WIDTH-1)))
G
greg-williams 已提交
131
    {
132
        //The largest representable negative number
133
        UNITY_OUTPUT_CHAR('-');
134 135 136 137 138 139 140
        number = (_U_UINT)number_to_print;
    }
    else if (number_to_print < 0)
    {
        //Some other negative number
        UNITY_OUTPUT_CHAR('-');
        number = (_U_UINT)(-number_to_print);
141 142 143
    }
    else
    {
144 145
        //Positive number
        number = (_U_UINT)number_to_print;
G
greg-williams 已提交
146 147 148
    }

    // figure out initial divisor
M
mvandervoord 已提交
149
    while (number / divisor > 9)
G
greg-williams 已提交
150
    {
M
mvandervoord 已提交
151 152 153 154 155
        next_divisor = divisor * 10;
        if (next_divisor > divisor)
            divisor = next_divisor;
        else
            break;
G
greg-williams 已提交
156 157
    }

M
mvandervoord 已提交
158
    // now mod and print, then divide divisor
G
greg-williams 已提交
159 160
    do
    {
161
        UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
M
mvandervoord 已提交
162
        divisor /= 10;
G
greg-williams 已提交
163
    }
M
mvandervoord 已提交
164
    while (divisor > 0);
G
greg-williams 已提交
165 166
}

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

    // figure out initial divisor
M
mvandervoord 已提交
175
    while (number / divisor > 9)
G
greg-williams 已提交
176
    {
M
mvandervoord 已提交
177 178 179 180 181
        next_divisor = divisor * 10;
        if (next_divisor > divisor)
            divisor = next_divisor;
        else
            break;
G
greg-williams 已提交
182 183
    }

M
mvandervoord 已提交
184
    // now mod and print, then divide divisor
G
greg-williams 已提交
185 186
    do
    {
187
        UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
M
mvandervoord 已提交
188
        divisor /= 10;
G
greg-williams 已提交
189
    }
M
mvandervoord 已提交
190
    while (divisor > 0);
G
greg-williams 已提交
191 192
}

M
mvandervoord 已提交
193
//-----------------------------------------------
M
mvandervoord 已提交
194
void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print)
G
greg-williams 已提交
195
{
M
mvandervoord 已提交
196
    _U_UINT nibble;
M
mvandervoord 已提交
197
    char nibbles = nibbles_to_print;
198 199
    UNITY_OUTPUT_CHAR('0');
    UNITY_OUTPUT_CHAR('x');
G
greg-williams 已提交
200 201 202 203 204 205

    while (nibbles > 0)
    {
        nibble = (number >> (--nibbles << 2)) & 0x0000000F;
        if (nibble <= 9)
        {
206
            UNITY_OUTPUT_CHAR((char)('0' + nibble));
G
greg-williams 已提交
207 208 209
        }
        else
        {
210
            UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble));
G
greg-williams 已提交
211 212 213 214
        }
    }
}

M
mvandervoord 已提交
215
//-----------------------------------------------
M
mvandervoord 已提交
216
void UnityPrintMask(const _U_UINT mask, const _U_UINT number)
G
greg-williams 已提交
217
{
218
    _U_UINT current_bit = (_U_UINT)1 << (UNITY_INT_WIDTH - 1);
219
    _US32 i;
G
greg-williams 已提交
220

M
mvandervoord 已提交
221
    for (i = 0; i < UNITY_INT_WIDTH; i++)
G
greg-williams 已提交
222
    {
223
        if (current_bit & mask)
G
greg-williams 已提交
224
        {
225
            if (current_bit & number)
G
greg-williams 已提交
226
            {
227
                UNITY_OUTPUT_CHAR('1');
G
greg-williams 已提交
228 229 230
            }
            else
            {
231
                UNITY_OUTPUT_CHAR('0');
G
greg-williams 已提交
232 233 234 235
            }
        }
        else
        {
236
            UNITY_OUTPUT_CHAR('X');
G
greg-williams 已提交
237
        }
238
        current_bit = current_bit >> 1;
G
greg-williams 已提交
239 240 241
    }
}

M
mvandervoord 已提交
242
//-----------------------------------------------
243
#ifdef UNITY_FLOAT_VERBOSE
244
#include <string.h>
245 246 247 248 249 250 251 252
void UnityPrintFloat(_UF number)
{
    char TempBuffer[32];
    sprintf(TempBuffer, "%.6f", number);
    UnityPrint(TempBuffer);
}
#endif

253 254 255 256 257 258 259 260 261 262 263 264
//-----------------------------------------------

void UnityPrintFail(void)
{
    UnityPrint("FAIL");
}

void UnityPrintOk(void)
{
    UnityPrint("OK");
}

M
mvandervoord 已提交
265
//-----------------------------------------------
M
mvandervoord 已提交
266
void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line)
G
greg-williams 已提交
267
{
268
    UNITY_PRINT_EOL;
269
    UnityPrint(file);
270
    UNITY_OUTPUT_CHAR(':');
271
    UnityPrintNumber((_U_SINT)line);
272
    UNITY_OUTPUT_CHAR(':');
G
greg-williams 已提交
273
    UnityPrint(Unity.CurrentTestName);
274
    UNITY_OUTPUT_CHAR(':');
G
greg-williams 已提交
275 276
}

M
mvandervoord 已提交
277
//-----------------------------------------------
M
mvandervoord 已提交
278
void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line)
279
{
M
mvandervoord 已提交
280
    UnityTestResultsBegin(Unity.TestFile, line);
281 282 283
    UnityPrint("FAIL:");
}

M
mvandervoord 已提交
284
//-----------------------------------------------
285
void UnityConcludeTest(void)
G
greg-williams 已提交
286 287 288 289 290 291 292
{
    if (Unity.CurrentTestIgnored)
    {
        Unity.TestIgnores++;
    }
    else if (!Unity.CurrentTestFailed)
    {
293
        UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
M
mvandervoord 已提交
294
        UnityPrint("PASS");
G
greg-williams 已提交
295 296 297 298 299 300 301 302 303 304
    }
    else
    {
        Unity.TestFailures++;
    }

    Unity.CurrentTestFailed = 0;
    Unity.CurrentTestIgnored = 0;
}

M
mvandervoord 已提交
305
//-----------------------------------------------
M
mvandervoord 已提交
306 307 308 309 310 311 312 313 314
void UnityAddMsgIfSpecified(const char* msg)
{
    if (msg)
    {
        UnityPrint(UnityStrSpacer);
        UnityPrint(msg);
    }
}

315 316 317
//-----------------------------------------------
void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual)
{
M
mvandervoord 已提交
318 319 320 321 322 323 324 325 326
    UnityPrint(UnityStrExpected);
    if (expected != NULL)
    {
        UNITY_OUTPUT_CHAR('\'');
        UnityPrint(expected);
        UNITY_OUTPUT_CHAR('\'');
    }
    else
    {
327
      UnityPrint(UnityStrNull);
M
mvandervoord 已提交
328 329 330 331 332 333 334 335 336 337
    }
    UnityPrint(UnityStrWas);
    if (actual != NULL)
    {
        UNITY_OUTPUT_CHAR('\'');
        UnityPrint(actual);
        UNITY_OUTPUT_CHAR('\'');
    }
    else
    {
338
      UnityPrint(UnityStrNull);
M
mvandervoord 已提交
339
    }
340 341
}

342 343 344 345
//-----------------------------------------------
// Assertion & Control Helpers
//-----------------------------------------------

346
int UnityCheckArraysForNull(UNITY_PTR_ATTRIBUTE const void* expected, UNITY_PTR_ATTRIBUTE const void* actual, const UNITY_LINE_TYPE lineNumber, const char* msg)
347 348 349 350
{
    //return true if they are both NULL
    if ((expected == NULL) && (actual == NULL))
        return 1;
351

352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
    //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;
    }
369

370 371 372
    //return false if neither is NULL
    return 0;
}
373

M
mvandervoord 已提交
374 375 376 377
//-----------------------------------------------
// Assertion Functions
//-----------------------------------------------

M
mvandervoord 已提交
378 379 380
void UnityAssertBits(const _U_SINT mask,
                     const _U_SINT expected,
                     const _U_SINT actual,
381
                     const char* msg,
M
mvandervoord 已提交
382
                     const UNITY_LINE_TYPE lineNumber)
G
greg-williams 已提交
383
{
384
    UNITY_SKIP_EXECUTION;
385

G
greg-williams 已提交
386 387
    if ((mask & expected) != (mask & actual))
    {
388
        UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
389
        UnityPrint(UnityStrExpected);
390
        UnityPrintMask((_U_UINT)mask, (_U_UINT)expected);
M
mvandervoord 已提交
391
        UnityPrint(UnityStrWas);
392
        UnityPrintMask((_U_UINT)mask, (_U_UINT)actual);
M
mvandervoord 已提交
393 394
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
G
greg-williams 已提交
395 396 397
    }
}

M
mvandervoord 已提交
398
//-----------------------------------------------
M
mvandervoord 已提交
399 400
void UnityAssertEqualNumber(const _U_SINT expected,
                            const _U_SINT actual,
M
mvandervoord 已提交
401 402 403
                            const char* msg,
                            const UNITY_LINE_TYPE lineNumber,
                            const UNITY_DISPLAY_STYLE_T style)
404
{
405 406
    UNITY_SKIP_EXECUTION;

407 408
    if (expected != actual)
    {
409
        UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
410
        UnityPrint(UnityStrExpected);
411
        UnityPrintNumberByStyle(expected, style);
M
mvandervoord 已提交
412
        UnityPrint(UnityStrWas);
413
        UnityPrintNumberByStyle(actual, style);
M
mvandervoord 已提交
414 415
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
416 417 418
    }
}

M
mvandervoord 已提交
419
//-----------------------------------------------
420 421
void UnityAssertEqualIntArray(UNITY_PTR_ATTRIBUTE const void* expected,
                              UNITY_PTR_ATTRIBUTE const void* actual,
422
                              const _UU32 num_elements,
423
                              const char* msg,
M
mvandervoord 已提交
424
                              const UNITY_LINE_TYPE lineNumber,
425 426
                              const UNITY_DISPLAY_STYLE_T style)
{
427
    _UU32 elements = num_elements;
428 429
    UNITY_PTR_ATTRIBUTE const _US8* ptr_exp = (UNITY_PTR_ATTRIBUTE _US8*)expected;
    UNITY_PTR_ATTRIBUTE const _US8* ptr_act = (UNITY_PTR_ATTRIBUTE _US8*)actual;
430

431
    UNITY_SKIP_EXECUTION;
432

433 434 435 436 437 438 439
    if (elements == 0)
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
440

441
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1)
442
        return;
443

444 445 446
    // 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.
447
    switch(style & (UNITY_DISPLAY_STYLE_T)(~UNITY_DISPLAY_RANGE_AUTO))
448 449
    {
        case UNITY_DISPLAY_STYLE_HEX8:
M
mvandervoord 已提交
450 451
        case UNITY_DISPLAY_STYLE_INT8:
        case UNITY_DISPLAY_STYLE_UINT8:
452 453
            while (elements--)
            {
M
mvandervoord 已提交
454
                if (*ptr_exp != *ptr_act)
455 456 457 458 459
                {
                    UnityTestResultsFailBegin(lineNumber);
                    UnityPrint(UnityStrElement);
                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
                    UnityPrint(UnityStrExpected);
M
mvandervoord 已提交
460
                    UnityPrintNumberByStyle(*ptr_exp, style);
461
                    UnityPrint(UnityStrWas);
M
mvandervoord 已提交
462
                    UnityPrintNumberByStyle(*ptr_act, style);
463 464 465
                    UnityAddMsgIfSpecified(msg);
                    UNITY_FAIL_AND_BAIL;
                }
M
mvandervoord 已提交
466 467
                ptr_exp += 1;
                ptr_act += 1;
468 469 470
            }
            break;
        case UNITY_DISPLAY_STYLE_HEX16:
M
mvandervoord 已提交
471 472
        case UNITY_DISPLAY_STYLE_INT16:
        case UNITY_DISPLAY_STYLE_UINT16:
473 474
            while (elements--)
            {
475
                if (*(UNITY_PTR_ATTRIBUTE _US16*)ptr_exp != *(UNITY_PTR_ATTRIBUTE _US16*)ptr_act)
476 477 478 479 480
                {
                    UnityTestResultsFailBegin(lineNumber);
                    UnityPrint(UnityStrElement);
                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
                    UnityPrint(UnityStrExpected);
481
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE _US16*)ptr_exp, style);
482
                    UnityPrint(UnityStrWas);
483
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE _US16*)ptr_act, style);
484 485 486
                    UnityAddMsgIfSpecified(msg);
                    UNITY_FAIL_AND_BAIL;
                }
M
mvandervoord 已提交
487 488
                ptr_exp += 2;
                ptr_act += 2;
489 490
            }
            break;
M
mvandervoord 已提交
491 492 493 494 495 496
#ifdef UNITY_SUPPORT_64
        case UNITY_DISPLAY_STYLE_HEX64:
        case UNITY_DISPLAY_STYLE_INT64:
        case UNITY_DISPLAY_STYLE_UINT64:
            while (elements--)
            {
497
                if (*(UNITY_PTR_ATTRIBUTE _US64*)ptr_exp != *(UNITY_PTR_ATTRIBUTE _US64*)ptr_act)
M
mvandervoord 已提交
498 499 500 501 502
                {
                    UnityTestResultsFailBegin(lineNumber);
                    UnityPrint(UnityStrElement);
                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
                    UnityPrint(UnityStrExpected);
503
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE _US64*)ptr_exp, style);
M
mvandervoord 已提交
504
                    UnityPrint(UnityStrWas);
505
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE _US64*)ptr_act, style);
M
mvandervoord 已提交
506 507 508 509 510 511 512 513
                    UnityAddMsgIfSpecified(msg);
                    UNITY_FAIL_AND_BAIL;
                }
                ptr_exp += 8;
                ptr_act += 8;
            }
            break;
#endif
514 515 516
        default:
            while (elements--)
            {
517
                if (*(UNITY_PTR_ATTRIBUTE _US32*)ptr_exp != *(UNITY_PTR_ATTRIBUTE _US32*)ptr_act)
518 519 520 521 522
                {
                    UnityTestResultsFailBegin(lineNumber);
                    UnityPrint(UnityStrElement);
                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
                    UnityPrint(UnityStrExpected);
523
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE _US32*)ptr_exp, style);
524
                    UnityPrint(UnityStrWas);
525
                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE _US32*)ptr_act, style);
526 527 528
                    UnityAddMsgIfSpecified(msg);
                    UNITY_FAIL_AND_BAIL;
                }
M
mvandervoord 已提交
529 530
                ptr_exp += 4;
                ptr_act += 4;
531 532 533 534 535
            }
            break;
    }
}

M
mvandervoord 已提交
536
//-----------------------------------------------
537
#ifndef UNITY_EXCLUDE_FLOAT
538 539
void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected,
                                UNITY_PTR_ATTRIBUTE const _UF* actual,
540
                                const _UU32 num_elements,
541 542 543
                                const char* msg,
                                const UNITY_LINE_TYPE lineNumber)
{
544
    _UU32 elements = num_elements;
545 546
    UNITY_PTR_ATTRIBUTE const _UF* ptr_expected = expected;
    UNITY_PTR_ATTRIBUTE const _UF* ptr_actual = actual;
M
mvandervoord 已提交
547
    _UF diff, tol;
548

549
    UNITY_SKIP_EXECUTION;
550

551 552
    if (elements == 0)
    {
553
        UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
554 555 556
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
557
    }
558

559
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1)
560
        return;
561 562 563

    while (elements--)
    {
564
        diff = *ptr_expected - *ptr_actual;
565 566
        if (diff < 0.0f)
          diff = 0.0f - diff;
M
mvandervoord 已提交
567
        tol = UNITY_FLOAT_PRECISION * *ptr_expected;
568 569
        if (tol < 0.0f)
            tol = 0.0f - tol;
570

571 572
        //This first part of this condition will catch any NaN or Infinite values
        if ((diff * 0.0f != 0.0f) || (diff > tol))
573
        {
574
            UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
575
            UnityPrint(UnityStrElement);
576
            UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
577 578 579 580 581 582
#ifdef UNITY_FLOAT_VERBOSE
            UnityPrint(UnityStrExpected);
            UnityPrintFloat(*ptr_expected);
            UnityPrint(UnityStrWas);
            UnityPrintFloat(*ptr_actual);
#else
583
            UnityPrint(UnityStrDelta);
584
#endif
M
mvandervoord 已提交
585 586
            UnityAddMsgIfSpecified(msg);
            UNITY_FAIL_AND_BAIL;
M
mvandervoord 已提交
587
        }
588 589
        ptr_expected++;
        ptr_actual++;
M
mvandervoord 已提交
590 591 592
    }
}

M
mvandervoord 已提交
593
//-----------------------------------------------
594 595 596
void UnityAssertFloatsWithin(const _UF delta,
                             const _UF expected,
                             const _UF actual,
597
                             const char* msg,
M
mvandervoord 已提交
598
                             const UNITY_LINE_TYPE lineNumber)
G
greg-williams 已提交
599
{
600 601
    _UF diff = actual - expected;
    _UF pos_delta = delta;
602

603
    UNITY_SKIP_EXECUTION;
604

605
    if (diff < 0.0f)
G
greg-williams 已提交
606
    {
607
        diff = 0.0f - diff;
G
greg-williams 已提交
608
    }
609
    if (pos_delta < 0.0f)
610 611 612
    {
        pos_delta = 0.0f - pos_delta;
    }
613

614 615
    //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 已提交
616
    {
617
        UnityTestResultsFailBegin(lineNumber);
618 619 620 621 622 623
#ifdef UNITY_FLOAT_VERBOSE
        UnityPrint(UnityStrExpected);
        UnityPrintFloat(expected);
        UnityPrint(UnityStrWas);
        UnityPrintFloat(actual);
#else
M
mvandervoord 已提交
624
        UnityPrint(UnityStrDelta);
625
#endif
M
mvandervoord 已提交
626 627
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
G
greg-williams 已提交
628 629
    }
}
M
mvandervoord 已提交
630

631
//-----------------------------------------------
632 633 634
void UnityAssertFloatSpecial(const _UF actual,
                             const char* msg,
                             const UNITY_LINE_TYPE lineNumber,
635
                             const UNITY_FLOAT_TRAIT_T style)
636 637 638
{
    UNITY_SKIP_EXECUTION;

639
    const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet };
640 641 642
    _U_SINT should_be_trait   = ((_U_SINT)style & 1);
    _U_SINT is_trait          = !should_be_trait;
    _U_SINT trait_index       = style >> 1;
643

644
    switch(style)
645
    {
646 647 648 649 650 651 652 653 654 655
        //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;
656

657 658 659 660 661
        //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;
662 663 664 665 666 667 668 669 670

        //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;
671
    }
672

673
    if (is_trait != should_be_trait)
674 675 676
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrExpected);
677
        if (!should_be_trait)
678
            UnityPrint(UnityStrNot);
679
        UnityPrint(trait_names[trait_index]);
680
        UnityPrint(UnityStrWas);
681
#ifdef UNITY_FLOAT_VERBOSE
682 683
        UnityPrintFloat(actual);
#else
684
        if (should_be_trait)
685
            UnityPrint(UnityStrNot);
686
        UnityPrint(trait_names[trait_index]);
687 688 689 690 691 692
#endif
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
}

M
mvandervoord 已提交
693 694 695 696
#endif //not UNITY_EXCLUDE_FLOAT

//-----------------------------------------------
#ifndef UNITY_EXCLUDE_DOUBLE
697 698
void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected,
                                 UNITY_PTR_ATTRIBUTE const _UD* actual,
M
mvandervoord 已提交
699 700 701 702 703
                                 const _UU32 num_elements,
                                 const char* msg,
                                 const UNITY_LINE_TYPE lineNumber)
{
    _UU32 elements = num_elements;
704 705
    UNITY_PTR_ATTRIBUTE const _UD* ptr_expected = expected;
    UNITY_PTR_ATTRIBUTE const _UD* ptr_actual = actual;
M
mvandervoord 已提交
706 707 708
    _UD diff, tol;

    UNITY_SKIP_EXECUTION;
709

M
mvandervoord 已提交
710 711 712 713 714 715 716
    if (elements == 0)
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
717

718
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1)
M
mvandervoord 已提交
719 720 721 722 723 724 725 726 727 728
        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;
729

730
        //This first part of this condition will catch any NaN or Infinite values
731
        if ((diff * 0.0 != 0.0) || (diff > tol))
M
mvandervoord 已提交
732 733 734 735 736 737 738 739 740 741 742
        {
            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);
743
#endif
M
mvandervoord 已提交
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762
            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;
763

764
    if (diff < 0.0)
M
mvandervoord 已提交
765
    {
766
        diff = 0.0 - diff;
M
mvandervoord 已提交
767
    }
768
    if (pos_delta < 0.0)
M
mvandervoord 已提交
769
    {
770
        pos_delta = 0.0 - pos_delta;
M
mvandervoord 已提交
771 772
    }

773
    //This first part of this condition will catch any NaN or Infinite values
774
    if ((diff * 0.0 != 0.0) || (pos_delta < diff))
M
mvandervoord 已提交
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789
    {
        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;
    }
}

790
//-----------------------------------------------
791 792 793 794

void UnityAssertDoubleSpecial(const _UD actual,
                              const char* msg,
                              const UNITY_LINE_TYPE lineNumber,
795
                              const UNITY_FLOAT_TRAIT_T style)
796 797 798
{
    UNITY_SKIP_EXECUTION;

799 800 801 802 803 804
    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;

    switch(style)
805
    {
806 807 808 809 810 811 812 813 814 815
        //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;
816

817 818 819 820 821
        //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;
822

823 824 825 826 827 828 829 830
        //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;
831 832
    }

833
    if (is_trait != should_be_trait)
834 835 836
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrExpected);
837 838 839
        if (!should_be_trait)
            UnityPrint(UnityStrNot);
        UnityPrint(trait_names[trait_index]);
840
        UnityPrint(UnityStrWas);
841 842
#ifdef UNITY_DOUBLE_VERBOSE
        UnityPrintFloat(actual);
843
#else
844 845 846
        if (should_be_trait)
            UnityPrint(UnityStrNot);
        UnityPrint(trait_names[trait_index]);
847 848 849 850 851 852
#endif
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }
}

853

M
mvandervoord 已提交
854
#endif // not UNITY_EXCLUDE_DOUBLE
G
greg-williams 已提交
855

M
mvandervoord 已提交
856
//-----------------------------------------------
M
mvandervoord 已提交
857 858 859
void UnityAssertNumbersWithin( const _U_SINT delta,
                               const _U_SINT expected,
                               const _U_SINT actual,
M
mvandervoord 已提交
860 861 862
                               const char* msg,
                               const UNITY_LINE_TYPE lineNumber,
                               const UNITY_DISPLAY_STYLE_T style)
G
greg-williams 已提交
863
{
864
    UNITY_SKIP_EXECUTION;
865

M
mvandervoord 已提交
866
    if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
G
greg-williams 已提交
867
    {
M
mvandervoord 已提交
868 869 870 871
        if (actual > expected)
          Unity.CurrentTestFailed = ((actual - expected) > delta);
        else
          Unity.CurrentTestFailed = ((expected - actual) > delta);
G
greg-williams 已提交
872
    }
M
mvandervoord 已提交
873
    else
G
greg-williams 已提交
874
    {
M
mvandervoord 已提交
875 876
        if ((_U_UINT)actual > (_U_UINT)expected)
            Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > (_U_UINT)delta);
M
mvandervoord 已提交
877
        else
M
mvandervoord 已提交
878
            Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > (_U_UINT)delta);
879 880
    }

M
mvandervoord 已提交
881
    if (Unity.CurrentTestFailed)
882
    {
883
        UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
884 885 886 887 888 889 890 891
        UnityPrint(UnityStrDelta);
        UnityPrintNumberByStyle(delta, style);
        UnityPrint(UnityStrExpected);
        UnityPrintNumberByStyle(expected, style);
        UnityPrint(UnityStrWas);
        UnityPrintNumberByStyle(actual, style);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
G
greg-williams 已提交
892 893 894
    }
}

M
mvandervoord 已提交
895
//-----------------------------------------------
896 897 898
void UnityAssertEqualString(const char* expected,
                            const char* actual,
                            const char* msg,
M
mvandervoord 已提交
899
                            const UNITY_LINE_TYPE lineNumber)
G
greg-williams 已提交
900
{
901
    _UU32 i;
G
greg-williams 已提交
902

903
    UNITY_SKIP_EXECUTION;
904

G
greg-williams 已提交
905 906 907 908 909 910 911 912
    // 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;
913
                break;
G
greg-williams 已提交
914 915 916 917 918 919 920 921 922 923 924 925 926
            }
        }
    }
    else
    { // handle case of one pointers being null (if both null, test should pass)
        if (expected != actual)
        {
            Unity.CurrentTestFailed = 1;
        }
    }

    if (Unity.CurrentTestFailed)
    {
927
      UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
928
      UnityPrintExpectedAndActualStrings(expected, actual);
929 930
      UnityAddMsgIfSpecified(msg);
      UNITY_FAIL_AND_BAIL;
G
greg-williams 已提交
931 932 933
    }
}

M
mvandervoord 已提交
934 935 936 937 938 939 940 941
//-----------------------------------------------
void UnityAssertEqualStringArray( const char** expected,
                                  const char** actual,
                                  const _UU32 num_elements,
                                  const char* msg,
                                  const UNITY_LINE_TYPE lineNumber)
{
    _UU32 i, j = 0;
942

943
    UNITY_SKIP_EXECUTION;
944

M
mvandervoord 已提交
945 946 947 948 949 950 951 952 953
    // if no elements, it's an error
    if (num_elements == 0)
    {
        UnityTestResultsFailBegin(lineNumber);
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
    }

954
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1)
955
        return;
956

M
mvandervoord 已提交
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984
    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);
985
                UnityPrintNumberByStyle((j), UNITY_DISPLAY_STYLE_UINT);
M
mvandervoord 已提交
986
            }
M
mvandervoord 已提交
987
            UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j]));
M
mvandervoord 已提交
988 989
            UnityAddMsgIfSpecified(msg);
            UNITY_FAIL_AND_BAIL;
990
        }
M
mvandervoord 已提交
991 992 993 994
    } while (++j < num_elements);
}

//-----------------------------------------------
995 996
void UnityAssertEqualMemory( UNITY_PTR_ATTRIBUTE const void* expected,
                             UNITY_PTR_ATTRIBUTE const void* actual,
997 998
                             const _UU32 length,
                             const _UU32 num_elements,
M
mvandervoord 已提交
999 1000
                             const char* msg,
                             const UNITY_LINE_TYPE lineNumber)
1001
{
1002 1003
    UNITY_PTR_ATTRIBUTE unsigned char* ptr_exp = (UNITY_PTR_ATTRIBUTE unsigned char*)expected;
    UNITY_PTR_ATTRIBUTE unsigned char* ptr_act = (UNITY_PTR_ATTRIBUTE unsigned char*)actual;
1004
    _UU32 elements = num_elements;
1005
    _UU32 bytes;
1006 1007

    UNITY_SKIP_EXECUTION;
1008

1009 1010
    if ((elements == 0) || (length == 0))
    {
1011
        UnityTestResultsFailBegin(lineNumber);
M
mvandervoord 已提交
1012 1013 1014
        UnityPrint(UnityStrPointless);
        UnityAddMsgIfSpecified(msg);
        UNITY_FAIL_AND_BAIL;
1015
    }
1016

1017
    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1)
1018
        return;
1019

1020
    while (elements--)
1021
    {
1022 1023 1024
        /////////////////////////////////////
        bytes = length;
        while (bytes--)
1025
        {
1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
            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;
            }
            ptr_exp += 1;
            ptr_act += 1;
1046
        }
1047
        /////////////////////////////////////
1048

1049 1050 1051
    }
}

M
mvandervoord 已提交
1052 1053 1054 1055 1056
//-----------------------------------------------
// Control Functions
//-----------------------------------------------

void UnityFail(const char* msg, const UNITY_LINE_TYPE line)
G
greg-williams 已提交
1057
{
1058 1059
    UNITY_SKIP_EXECUTION;

M
mvandervoord 已提交
1060
    UnityTestResultsBegin(Unity.TestFile, line);
1061
    UnityPrintFail();
M
mvandervoord 已提交
1062
    if (msg != NULL)
1063 1064
    {
      UNITY_OUTPUT_CHAR(':');
1065 1066
      if (msg[0] != ' ')
      {
1067
        UNITY_OUTPUT_CHAR(' ');
M
mvandervoord 已提交
1068
      }
M
mvandervoord 已提交
1069
      UnityPrint(msg);
1070
    }
M
mvandervoord 已提交
1071
    UNITY_FAIL_AND_BAIL;
G
greg-williams 已提交
1072 1073
}

M
mvandervoord 已提交
1074
//-----------------------------------------------
M
mvandervoord 已提交
1075
void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
G
greg-williams 已提交
1076
{
1077 1078
    UNITY_SKIP_EXECUTION;

M
mvandervoord 已提交
1079
    UnityTestResultsBegin(Unity.TestFile, line);
1080
    UnityPrint("IGNORE");
M
mvandervoord 已提交
1081
    if (msg != NULL)
1082 1083
    {
      UNITY_OUTPUT_CHAR(':');
1084
      UNITY_OUTPUT_CHAR(' ');
M
mvandervoord 已提交
1085
      UnityPrint(msg);
1086
    }
M
mvandervoord 已提交
1087
    UNITY_IGNORE_AND_BAIL;
G
greg-williams 已提交
1088 1089
}

1090
//-----------------------------------------------
1091
#ifdef UNITY_SUPPORT_WEAK
1092 1093
UNITY_WEAK void setUp(void) { }
UNITY_WEAK void tearDown(void) { }
1094
#else
1095 1096
void setUp(void);
void tearDown(void);
1097 1098
#endif
//-----------------------------------------------
1099 1100 1101
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
{
    Unity.CurrentTestName = FuncName;
1102
    Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)FuncLineNum;
1103
    Unity.NumberOfTests++;
1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115
    if (TEST_PROTECT())
    {
        setUp();
        Func();
    }
    if (TEST_PROTECT() && !(Unity.CurrentTestIgnored))
    {
        tearDown();
    }
    UnityConcludeTest();
}

M
mvandervoord 已提交
1116
//-----------------------------------------------
M
Mark VanderVoord 已提交
1117
void UnityBegin(const char* filename)
G
greg-williams 已提交
1118
{
M
Mark VanderVoord 已提交
1119
    Unity.TestFile = filename;
1120 1121
    Unity.CurrentTestName = NULL;
    Unity.CurrentTestLineNumber = 0;
G
greg-williams 已提交
1122
    Unity.NumberOfTests = 0;
1123 1124 1125 1126
    Unity.TestFailures = 0;
    Unity.TestIgnores = 0;
    Unity.CurrentTestFailed = 0;
    Unity.CurrentTestIgnored = 0;
M
Mark VanderVoord 已提交
1127 1128

    UNITY_OUTPUT_START();
G
greg-williams 已提交
1129 1130
}

M
mvandervoord 已提交
1131
//-----------------------------------------------
1132
int UnityEnd(void)
G
greg-williams 已提交
1133
{
1134
    UNITY_PRINT_EOL;
M
mvandervoord 已提交
1135
    UnityPrint("-----------------------");
M
mvandervoord 已提交
1136
    UNITY_PRINT_EOL;
1137
    UnityPrintNumber((_U_SINT)(Unity.NumberOfTests));
G
greg-williams 已提交
1138
    UnityPrint(" Tests ");
1139
    UnityPrintNumber((_U_SINT)(Unity.TestFailures));
G
greg-williams 已提交
1140
    UnityPrint(" Failures ");
1141
    UnityPrintNumber((_U_SINT)(Unity.TestIgnores));
M
mvandervoord 已提交
1142
    UnityPrint(" Ignored");
M
mvandervoord 已提交
1143
    UNITY_PRINT_EOL;
G
greg-williams 已提交
1144 1145
    if (Unity.TestFailures == 0U)
    {
1146
        UnityPrintOk();
G
greg-williams 已提交
1147 1148 1149
    }
    else
    {
1150
        UnityPrintFail();
G
greg-williams 已提交
1151
    }
M
mvandervoord 已提交
1152
    UNITY_PRINT_EOL;
M
Mark VanderVoord 已提交
1153
    UNITY_OUTPUT_COMPLETE();
1154
    return (int)(Unity.TestFailures);
G
greg-williams 已提交
1155
}
1156 1157 1158 1159

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