1284990Scy/* =========================================================================
2284990Scy    Unity Project - A Test Framework for C
3284990Scy    Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams
4284990Scy    [Released under MIT License. Please refer to license.txt for details]
5284990Scy============================================================================ */
6284990Scy
7284990Scy#include "unity.h"
8284990Scy
9284990Scy#define UNITY_FAIL_AND_BAIL   { Unity.CurrentTestFailed  = 1; longjmp(Unity.AbortFrame, 1); }
10284990Scy#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; longjmp(Unity.AbortFrame, 1); }
11284990Scy/// return prematurely if we are already in failure or ignore state
12284990Scy#define UNITY_SKIP_EXECUTION  { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} }
13284990Scy#define UNITY_PRINT_EOL       { UNITY_OUTPUT_CHAR('\n'); }
14284990Scy
15284990Scystruct _Unity Unity;
16284990Scy
17284990Scyconst char UnityStrOk[]                     = "OK";
18284990Scyconst char UnityStrPass[]                   = "PASS";
19284990Scyconst char UnityStrFail[]                   = "FAIL";
20284990Scyconst char UnityStrIgnore[]                 = "IGNORE";
21284990Scyconst char UnityStrXPASS[]                  = "XPASS";
22284990Scyconst char UnityStrXFAIL[]                  = "XFAIL";
23284990Scyconst char UnityStrNull[]                   = "NULL";
24284990Scyconst char UnityStrSpacer[]                 = ". ";
25284990Scyconst char UnityStrExpected[]               = " Expected ";
26284990Scyconst char UnityStrWas[]                    = " Was ";
27284990Scyconst char UnityStrTo[]                     = " To ";
28284990Scyconst char UnityStrElement[]                = " Element ";
29284990Scyconst char UnityStrByte[]                   = " Byte ";
30284990Scyconst char UnityStrMemory[]                 = " Memory Mismatch.";
31284990Scyconst char UnityStrDelta[]                  = " Values Not Within Delta ";
32284990Scyconst char UnityStrPointless[]              = " You Asked Me To Compare Nothing, Which Was Pointless.";
33284990Scyconst char UnityStrNullPointerForExpected[] = " Expected pointer to be NULL";
34284990Scyconst char UnityStrNullPointerForActual[]   = " Actual pointer was NULL";
35284990Scyconst char UnityStrNot[]                    = "Not ";
36284990Scyconst char UnityStrInf[]                    = "Infinity";
37284990Scyconst char UnityStrNegInf[]                 = "Negative Infinity";
38284990Scyconst char UnityStrNaN[]                    = "NaN";
39284990Scyconst char UnityStrDet[]                    = "Determinate";
40284990Scyconst char UnityStrErrFloat[]               = "Unity Floating Point Disabled";
41284990Scyconst char UnityStrErrDouble[]              = "Unity Double Precision Disabled";
42284990Scyconst char UnityStrErr64[]                  = "Unity 64-bit Support Disabled";
43284990Scyconst char UnityStrBreaker[]                = "-----------------------";
44284990Scyconst char UnityStrResultsTests[]           = " Tests: ";
45284990Scyconst char UnityStrResultsFailures[]        = " Failures ";
46284990Scyconst char UnityStrResultsIgnored[]         = " Ignored ";
47284990Scyconst char UnityStrResultsXFAIL[]           = " XFAIL ";
48284990Scyconst char UnityStrResultsXPASS[]           = " XPASS ";
49284990Scyconst char UnityStrResultsPass[]            = " PASS ";
50284990Scy
51284990Scy
52284990Scy#ifndef UNITY_EXCLUDE_FLOAT
53284990Scy// Dividing by these constants produces +/- infinity.
54284990Scy// The rationale is given in UnityAssertFloatIsInf's body.
55284990Scystatic const _UF f_zero = 0.0f;
56284990Scy#ifndef UNITY_EXCLUDE_DOUBLE
57284990Scystatic const _UD d_zero = 0.0;
58284990Scy#endif
59284990Scy#endif
60284990Scy
61284990Scy// compiler-generic print formatting masks
62284990Scyconst _U_UINT UnitySizeMask[] =
63284990Scy{
64284990Scy    255u,         // 0xFF
65284990Scy    65535u,       // 0xFFFF
66284990Scy    65535u,
67284990Scy    4294967295u,  // 0xFFFFFFFF
68284990Scy    4294967295u,
69284990Scy    4294967295u,
70284990Scy    4294967295u
71284990Scy#ifdef UNITY_SUPPORT_64
72284990Scy    ,0xFFFFFFFFFFFFFFFF
73284990Scy#endif
74284990Scy};
75284990Scy
76284990Scyvoid UnityPrintFail(void);
77284990Scyvoid UnityPrintOk(void);
78284990Scy
79284990Scy//-----------------------------------------------
80284990Scy// Pretty Printers & Test Result Output Handlers
81284990Scy//-----------------------------------------------
82284990Scy
83284990Scyvoid UnityPrint(const char* string)
84284990Scy{
85284990Scy    const char* pch = string;
86284990Scy
87284990Scy    if (pch != NULL)
88284990Scy    {
89284990Scy        while (*pch)
90284990Scy        {
91284990Scy            // printable characters plus CR & LF are printed
92284990Scy            if ((*pch <= 126) && (*pch >= 32))
93284990Scy            {
94284990Scy                UNITY_OUTPUT_CHAR(*pch);
95284990Scy            }
96284990Scy            //write escaped carriage returns
97284990Scy            else if (*pch == 13)
98284990Scy            {
99284990Scy                UNITY_OUTPUT_CHAR('\\');
100284990Scy                UNITY_OUTPUT_CHAR('r');
101284990Scy            }
102284990Scy            //write escaped line feeds
103284990Scy            else if (*pch == 10)
104284990Scy            {
105284990Scy                UNITY_OUTPUT_CHAR('\\');
106284990Scy                UNITY_OUTPUT_CHAR('n');
107284990Scy            }
108284990Scy            // unprintable characters are shown as codes
109284990Scy            else
110284990Scy            {
111284990Scy                UNITY_OUTPUT_CHAR('\\');
112284990Scy                UnityPrintNumberHex((_U_UINT)*pch, 2);
113284990Scy            }
114284990Scy            pch++;
115284990Scy        }
116284990Scy    }
117284990Scy}
118284990Scy
119284990Scy//-----------------------------------------------
120284990Scyvoid UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style)
121284990Scy{
122284990Scy    if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
123284990Scy    {
124284990Scy        UnityPrintNumber(number);
125284990Scy    }
126284990Scy    else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT)
127284990Scy    {
128284990Scy        UnityPrintNumberUnsigned(  (_U_UINT)number  &  UnitySizeMask[((_U_UINT)style & (_U_UINT)0x0F) - 1]  );
129284990Scy    }
130284990Scy    else
131284990Scy    {
132284990Scy        UnityPrintNumberHex((_U_UINT)number, (char)((style & 0x000F) << 1));
133284990Scy    }
134284990Scy}
135284990Scy
136284990Scy//-----------------------------------------------
137284990Scy/// basically do an itoa using as little ram as possible
138284990Scyvoid UnityPrintNumber(const _U_SINT number_to_print)
139284990Scy{
140284990Scy    _U_SINT divisor = 1;
141284990Scy    _U_SINT next_divisor;
142284990Scy    _U_UINT number;
143284990Scy
144284990Scy    if (number_to_print == (1l << (UNITY_LONG_WIDTH-1)))
145284990Scy    {
146284990Scy        //The largest representable negative number
147284990Scy        UNITY_OUTPUT_CHAR('-');
148284990Scy        number = (1ul << (UNITY_LONG_WIDTH-1));
149284990Scy    }
150284990Scy    else if (number_to_print < 0)
151284990Scy    {
152284990Scy        //Some other negative number
153284990Scy        UNITY_OUTPUT_CHAR('-');
154284990Scy        number = (_U_UINT)(-number_to_print);
155284990Scy    }
156284990Scy    else
157284990Scy    {
158284990Scy        //Positive number
159284990Scy        number = (_U_UINT)number_to_print;
160284990Scy    }
161284990Scy
162284990Scy    // figure out initial divisor
163284990Scy    while (number / divisor > 9)
164284990Scy    {
165284990Scy        next_divisor = divisor * 10;
166284990Scy        if (next_divisor > divisor)
167284990Scy            divisor = next_divisor;
168284990Scy        else
169284990Scy            break;
170284990Scy    }
171284990Scy
172284990Scy    // now mod and print, then divide divisor
173284990Scy    do
174284990Scy    {
175284990Scy        UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
176284990Scy        divisor /= 10;
177284990Scy    }
178284990Scy    while (divisor > 0);
179284990Scy}
180284990Scy
181284990Scy//-----------------------------------------------
182284990Scy/// basically do an itoa using as little ram as possible
183284990Scyvoid UnityPrintNumberUnsigned(const _U_UINT number)
184284990Scy{
185284990Scy    _U_UINT divisor = 1;
186284990Scy    _U_UINT next_divisor;
187284990Scy
188284990Scy    // figure out initial divisor
189284990Scy    while (number / divisor > 9)
190284990Scy    {
191284990Scy        next_divisor = divisor * 10;
192284990Scy        if (next_divisor > divisor)
193284990Scy            divisor = next_divisor;
194284990Scy        else
195284990Scy            break;
196284990Scy    }
197284990Scy
198284990Scy    // now mod and print, then divide divisor
199284990Scy    do
200284990Scy    {
201284990Scy        UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
202284990Scy        divisor /= 10;
203284990Scy    }
204284990Scy    while (divisor > 0);
205284990Scy}
206284990Scy
207284990Scy//-----------------------------------------------
208284990Scyvoid UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print)
209284990Scy{
210284990Scy    _U_UINT nibble;
211284990Scy    char nibbles = nibbles_to_print;
212284990Scy    UNITY_OUTPUT_CHAR('0');
213284990Scy    UNITY_OUTPUT_CHAR('x');
214284990Scy
215284990Scy    while (nibbles > 0)
216284990Scy    {
217284990Scy        nibble = (number >> (--nibbles << 2)) & 0x0000000F;
218284990Scy        if (nibble <= 9)
219284990Scy        {
220284990Scy            UNITY_OUTPUT_CHAR((char)('0' + nibble));
221284990Scy        }
222284990Scy        else
223284990Scy        {
224284990Scy            UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble));
225284990Scy        }
226284990Scy    }
227284990Scy}
228284990Scy
229284990Scy//-----------------------------------------------
230284990Scyvoid UnityPrintMask(const _U_UINT mask, const _U_UINT number)
231284990Scy{
232284990Scy    _U_UINT current_bit = (_U_UINT)1 << (UNITY_INT_WIDTH - 1);
233284990Scy    _US32 i;
234284990Scy
235284990Scy    for (i = 0; i < UNITY_INT_WIDTH; i++)
236284990Scy    {
237284990Scy        if (current_bit & mask)
238284990Scy        {
239284990Scy            if (current_bit & number)
240284990Scy            {
241284990Scy                UNITY_OUTPUT_CHAR('1');
242284990Scy            }
243284990Scy            else
244284990Scy            {
245284990Scy                UNITY_OUTPUT_CHAR('0');
246284990Scy            }
247284990Scy        }
248284990Scy        else
249284990Scy        {
250284990Scy            UNITY_OUTPUT_CHAR('X');
251284990Scy        }
252284990Scy        current_bit = current_bit >> 1;
253284990Scy    }
254284990Scy}
255284990Scy
256284990Scy//-----------------------------------------------
257284990Scy#ifdef UNITY_FLOAT_VERBOSE
258284990Scy#include <string.h>
259284990Scyvoid UnityPrintFloat(_UF number)
260284990Scy{
261284990Scy    char TempBuffer[32];
262284990Scy    sprintf(TempBuffer, "%.6f", number);
263284990Scy    UnityPrint(TempBuffer);
264284990Scy}
265284990Scy#endif
266284990Scy
267284990Scy//-----------------------------------------------
268284990Scy
269284990Scyvoid UnityPrintFail(void)
270284990Scy{
271284990Scy    UnityPrint(UnityStrFail);
272284990Scy}
273284990Scy
274284990Scyvoid UnityPrintOk(void)
275284990Scy{
276284990Scy    UnityPrint(UnityStrOk);
277284990Scy}
278284990Scy
279284990Scy//-----------------------------------------------
280284990Scystatic void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line)
281284990Scy{
282284990Scy    UnityPrint(file);
283284990Scy    UNITY_OUTPUT_CHAR(':');
284284990Scy    UnityPrintNumber((_U_SINT)line);
285284990Scy    UNITY_OUTPUT_CHAR(':');
286284990Scy    UnityPrint(Unity.CurrentTestName);
287284990Scy    UNITY_OUTPUT_CHAR(':');
288284990Scy}
289284990Scy
290284990Scy//-----------------------------------------------
291284990Scystatic void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line)
292284990Scy{
293284990Scy    UnityTestResultsBegin(Unity.TestFile, line);
294284990Scy	if (Unity.isExpectingFail)
295284990Scy	{
296284990Scy		UnityPrint(UnityStrXFAIL);
297284990Scy	}
298284990Scy	else
299284990Scy	{
300284990Scy		UnityPrint(UnityStrFail);
301284990Scy	}
302284990Scy
303284990Scy    UNITY_OUTPUT_CHAR(':');
304284990Scy}
305284990Scy
306284990Scy//-----------------------------------------------
307284990Scyvoid UnityConcludeTest(void)
308284990Scy{
309284990Scy#if 0
310284990Scy	if (Unity.isExpectingFail == 1 && Unity.CurrentTestFailed == 0)
311284990Scy	{
312284990Scy		printf("FAIL WAS EXPECTED, BUT IT DIDN'T HAPPEN?!");
313284990Scy		Unity.TestXPASSES++;
314284990Scy	}
315284990Scy
316284990Scy	else
317284990Scy#endif
318284990Scy	//cant be ignored and accepting fail at the same time!
319284990Scy	if (Unity.isExpectingFail == 1 && Unity.CurrentTestFailed == 1)
320284990Scy	{
321284990Scy		Unity.TestXFAILS++; //error message?!
322284990Scy		if (Unity.XFAILMessage != NULL)
323284990Scy		{
324284990Scy			if (Unity.XFAILMessage[0] != ' ')
325284990Scy			{
326284990Scy				printf(" ");
327284990Scy			}
328284990Scy
329284990Scy			printf("| ");
330290000Sglebius			printf("%s", Unity.XFAILMessage);
331284990Scy			Unity.XFAILMessage = NULL;
332284990Scy		}
333284990Scy		else
334284990Scy		{
335284990Scy			printf(" - EXPECTED FAIL!");
336284990Scy		}
337284990Scy	}
338284990Scy	else
339284990Scy
340284990Scy    if (Unity.CurrentTestIgnored)
341284990Scy    {
342284990Scy        Unity.TestIgnores++;
343284990Scy    }
344284990Scy    else if (!Unity.CurrentTestFailed)
345284990Scy    {
346284990Scy	if(Unity.isExpectingFail == 0) {
347284990Scy		UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
348284990Scy		UnityPrint(UnityStrPass);
349284990Scy		Unity.TestPasses++;
350284990Scy	}
351284990Scy
352284990Scy	//probably should remove the if... part
353284990Scy	else if (Unity.isExpectingFail == 1 && Unity.CurrentTestFailed == 0)
354284990Scy	{
355284990Scy
356284990Scy		UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
357284990Scy		UnityPrint(UnityStrXPASS);
358284990Scy		Unity.TestXPASSES++;
359284990Scy
360284990Scy		printf(" - FAIL WAS EXPECTED, BUT DIDN'T HAPPEN?!");
361284990Scy		//if (Unity.TestPasses > 0) { Unity.TestPasses--; }
362284990Scy	}
363284990Scy    }
364284990Scy    else
365284990Scy    {
366284990Scy        Unity.TestFailures++;
367284990Scy    }
368284990Scy
369284990Scy    Unity.CurrentTestFailed = 0;
370284990Scy    Unity.CurrentTestIgnored = 0;
371284990Scy    Unity.isExpectingFail = 0;
372284990Scy
373284990Scy    UNITY_PRINT_EOL;
374284990Scy}
375284990Scy
376284990Scy//-----------------------------------------------
377284990Scystatic void UnityAddMsgIfSpecified(const char* msg)
378284990Scy{
379284990Scy    if (msg)
380284990Scy    {
381284990Scy        UnityPrint(UnityStrSpacer);
382284990Scy        UnityPrint(msg);
383284990Scy    }
384284990Scy}
385284990Scy
386284990Scy//-----------------------------------------------
387284990Scystatic void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual)
388284990Scy{
389284990Scy    UnityPrint(UnityStrExpected);
390284990Scy    if (expected != NULL)
391284990Scy    {
392284990Scy        UNITY_OUTPUT_CHAR('\'');
393284990Scy        UnityPrint(expected);
394284990Scy        UNITY_OUTPUT_CHAR('\'');
395284990Scy    }
396284990Scy    else
397284990Scy    {
398284990Scy      UnityPrint(UnityStrNull);
399284990Scy    }
400284990Scy    UnityPrint(UnityStrWas);
401284990Scy    if (actual != NULL)
402284990Scy    {
403284990Scy        UNITY_OUTPUT_CHAR('\'');
404284990Scy        UnityPrint(actual);
405284990Scy        UNITY_OUTPUT_CHAR('\'');
406284990Scy    }
407284990Scy    else
408284990Scy    {
409284990Scy      UnityPrint(UnityStrNull);
410284990Scy    }
411284990Scy}
412284990Scy
413284990Scy//-----------------------------------------------
414284990Scy// Assertion & Control Helpers
415284990Scy//-----------------------------------------------
416284990Scy
417284990Scystatic int UnityCheckArraysForNull(UNITY_PTR_ATTRIBUTE const void* expected, UNITY_PTR_ATTRIBUTE const void* actual, const UNITY_LINE_TYPE lineNumber, const char* msg)
418284990Scy{
419284990Scy    //return true if they are both NULL
420284990Scy    if ((expected == NULL) && (actual == NULL))
421284990Scy        return 1;
422284990Scy
423284990Scy    //throw error if just expected is NULL
424284990Scy    if (expected == NULL)
425284990Scy    {
426284990Scy        UnityTestResultsFailBegin(lineNumber);
427284990Scy        UnityPrint(UnityStrNullPointerForExpected);
428284990Scy        UnityAddMsgIfSpecified(msg);
429284990Scy        UNITY_FAIL_AND_BAIL;
430284990Scy    }
431284990Scy
432284990Scy    //throw error if just actual is NULL
433284990Scy    if (actual == NULL)
434284990Scy    {
435284990Scy        UnityTestResultsFailBegin(lineNumber);
436284990Scy        UnityPrint(UnityStrNullPointerForActual);
437284990Scy        UnityAddMsgIfSpecified(msg);
438284990Scy        UNITY_FAIL_AND_BAIL;
439284990Scy    }
440284990Scy
441284990Scy    //return false if neither is NULL
442284990Scy    return 0;
443284990Scy}
444284990Scy
445284990Scy//-----------------------------------------------
446284990Scy// Assertion Functions
447284990Scy//-----------------------------------------------
448284990Scy
449284990Scyvoid UnityAssertBits(const _U_SINT mask,
450284990Scy                     const _U_SINT expected,
451284990Scy                     const _U_SINT actual,
452284990Scy                     const char* msg,
453284990Scy                     const UNITY_LINE_TYPE lineNumber)
454284990Scy{
455284990Scy    UNITY_SKIP_EXECUTION;
456284990Scy
457284990Scy    if ((mask & expected) != (mask & actual))
458284990Scy    {
459284990Scy        UnityTestResultsFailBegin(lineNumber);
460284990Scy        UnityPrint(UnityStrExpected);
461284990Scy        UnityPrintMask((_U_UINT)mask, (_U_UINT)expected);
462284990Scy        UnityPrint(UnityStrWas);
463284990Scy        UnityPrintMask((_U_UINT)mask, (_U_UINT)actual);
464284990Scy        UnityAddMsgIfSpecified(msg);
465284990Scy        UNITY_FAIL_AND_BAIL;
466284990Scy    }
467284990Scy}
468284990Scy
469284990Scy//-----------------------------------------------
470284990Scyvoid UnityAssertEqualNumber(const _U_SINT expected,
471284990Scy                            const _U_SINT actual,
472284990Scy                            const char* msg,
473284990Scy                            const UNITY_LINE_TYPE lineNumber,
474284990Scy                            const UNITY_DISPLAY_STYLE_T style)
475284990Scy{
476284990Scy    UNITY_SKIP_EXECUTION;
477284990Scy
478284990Scy    if (expected != actual)
479284990Scy    {
480284990Scy        UnityTestResultsFailBegin(lineNumber);
481284990Scy        UnityPrint(UnityStrExpected);
482284990Scy        UnityPrintNumberByStyle(expected, style);
483284990Scy        UnityPrint(UnityStrWas);
484284990Scy        UnityPrintNumberByStyle(actual, style);
485284990Scy        UnityAddMsgIfSpecified(msg);
486284990Scy        UNITY_FAIL_AND_BAIL;
487284990Scy    }
488284990Scy}
489284990Scy
490284990Scy//-----------------------------------------------
491284990Scyvoid UnityAssertEqualIntArray(UNITY_PTR_ATTRIBUTE const void* expected,
492284990Scy                              UNITY_PTR_ATTRIBUTE const void* actual,
493284990Scy                              const _UU32 num_elements,
494284990Scy                              const char* msg,
495284990Scy                              const UNITY_LINE_TYPE lineNumber,
496284990Scy                              const UNITY_DISPLAY_STYLE_T style)
497284990Scy{
498284990Scy    _UU32 elements = num_elements;
499284990Scy    UNITY_PTR_ATTRIBUTE const _US8* ptr_exp = (UNITY_PTR_ATTRIBUTE const _US8*)expected;
500284990Scy    UNITY_PTR_ATTRIBUTE const _US8* ptr_act = (UNITY_PTR_ATTRIBUTE const _US8*)actual;
501284990Scy
502284990Scy    UNITY_SKIP_EXECUTION;
503284990Scy
504284990Scy    if (elements == 0)
505284990Scy    {
506284990Scy        UnityTestResultsFailBegin(lineNumber);
507284990Scy        UnityPrint(UnityStrPointless);
508284990Scy        UnityAddMsgIfSpecified(msg);
509284990Scy        UNITY_FAIL_AND_BAIL;
510284990Scy    }
511284990Scy
512284990Scy    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE const void*)expected, (UNITY_PTR_ATTRIBUTE const void*)actual, lineNumber, msg) == 1)
513284990Scy        return;
514284990Scy
515284990Scy    // If style is UNITY_DISPLAY_STYLE_INT, we'll fall into the default case rather than the INT16 or INT32 (etc) case
516284990Scy    // as UNITY_DISPLAY_STYLE_INT includes a flag for UNITY_DISPLAY_RANGE_AUTO, which the width-specific
517284990Scy    // variants do not. Therefore remove this flag.
518284990Scy    switch(style & (UNITY_DISPLAY_STYLE_T)(~UNITY_DISPLAY_RANGE_AUTO))
519284990Scy    {
520284990Scy        case UNITY_DISPLAY_STYLE_HEX8:
521284990Scy        case UNITY_DISPLAY_STYLE_INT8:
522284990Scy        case UNITY_DISPLAY_STYLE_UINT8:
523284990Scy            while (elements--)
524284990Scy            {
525284990Scy                if (*ptr_exp != *ptr_act)
526284990Scy                {
527284990Scy                    UnityTestResultsFailBegin(lineNumber);
528284990Scy                    UnityPrint(UnityStrElement);
529284990Scy                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
530284990Scy                    UnityPrint(UnityStrExpected);
531284990Scy                    UnityPrintNumberByStyle(*ptr_exp, style);
532284990Scy                    UnityPrint(UnityStrWas);
533284990Scy                    UnityPrintNumberByStyle(*ptr_act, style);
534284990Scy                    UnityAddMsgIfSpecified(msg);
535284990Scy                    UNITY_FAIL_AND_BAIL;
536284990Scy                }
537284990Scy                ptr_exp += 1;
538284990Scy                ptr_act += 1;
539284990Scy            }
540284990Scy            break;
541284990Scy        case UNITY_DISPLAY_STYLE_HEX16:
542284990Scy        case UNITY_DISPLAY_STYLE_INT16:
543284990Scy        case UNITY_DISPLAY_STYLE_UINT16:
544284990Scy            while (elements--)
545284990Scy            {
546284990Scy                if (*(UNITY_PTR_ATTRIBUTE const _US16*)(void*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US16*)(void*)ptr_act)
547284990Scy                {
548284990Scy                    UnityTestResultsFailBegin(lineNumber);
549284990Scy                    UnityPrint(UnityStrElement);
550284990Scy                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
551284990Scy                    UnityPrint(UnityStrExpected);
552284990Scy                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US16*)(void*)ptr_exp, style);
553284990Scy                    UnityPrint(UnityStrWas);
554284990Scy                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US16*)(void*)ptr_act, style);
555284990Scy                    UnityAddMsgIfSpecified(msg);
556284990Scy                    UNITY_FAIL_AND_BAIL;
557284990Scy                }
558284990Scy                ptr_exp += 2;
559284990Scy                ptr_act += 2;
560284990Scy            }
561284990Scy            break;
562284990Scy#ifdef UNITY_SUPPORT_64
563284990Scy        case UNITY_DISPLAY_STYLE_HEX64:
564284990Scy        case UNITY_DISPLAY_STYLE_INT64:
565284990Scy        case UNITY_DISPLAY_STYLE_UINT64:
566284990Scy            while (elements--)
567284990Scy            {
568284990Scy                if (*(UNITY_PTR_ATTRIBUTE const _US64*)(void*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US64*)(void*)ptr_act)
569284990Scy                {
570284990Scy                    UnityTestResultsFailBegin(lineNumber);
571284990Scy                    UnityPrint(UnityStrElement);
572284990Scy                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
573284990Scy                    UnityPrint(UnityStrExpected);
574284990Scy                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US64*)(void*)ptr_exp, style);
575284990Scy                    UnityPrint(UnityStrWas);
576284990Scy                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US64*)(void*)ptr_act, style);
577284990Scy                    UnityAddMsgIfSpecified(msg);
578284990Scy                    UNITY_FAIL_AND_BAIL;
579284990Scy                }
580284990Scy                ptr_exp += 8;
581284990Scy                ptr_act += 8;
582284990Scy            }
583284990Scy            break;
584284990Scy#endif
585284990Scy        default:
586284990Scy            while (elements--)
587284990Scy            {
588284990Scy                if (*(UNITY_PTR_ATTRIBUTE const _US32*)(void*)ptr_exp != *(UNITY_PTR_ATTRIBUTE const _US32*)(void*)ptr_act)
589284990Scy                {
590284990Scy                    UnityTestResultsFailBegin(lineNumber);
591284990Scy                    UnityPrint(UnityStrElement);
592284990Scy                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
593284990Scy                    UnityPrint(UnityStrExpected);
594284990Scy                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US32*)(void*)ptr_exp, style);
595284990Scy                    UnityPrint(UnityStrWas);
596284990Scy                    UnityPrintNumberByStyle(*(UNITY_PTR_ATTRIBUTE const _US32*)(void*)ptr_act, style);
597284990Scy                    UnityAddMsgIfSpecified(msg);
598284990Scy                    UNITY_FAIL_AND_BAIL;
599284990Scy                }
600284990Scy                ptr_exp += 4;
601284990Scy                ptr_act += 4;
602284990Scy            }
603284990Scy            break;
604284990Scy    }
605284990Scy}
606284990Scy
607284990Scy//-----------------------------------------------
608284990Scy#ifndef UNITY_EXCLUDE_FLOAT
609284990Scyvoid UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected,
610284990Scy                                UNITY_PTR_ATTRIBUTE const _UF* actual,
611284990Scy                                const _UU32 num_elements,
612284990Scy                                const char* msg,
613284990Scy                                const UNITY_LINE_TYPE lineNumber)
614284990Scy{
615284990Scy    _UU32 elements = num_elements;
616284990Scy    UNITY_PTR_ATTRIBUTE const _UF* ptr_expected = expected;
617284990Scy    UNITY_PTR_ATTRIBUTE const _UF* ptr_actual = actual;
618284990Scy    _UF diff, tol;
619284990Scy
620284990Scy    UNITY_SKIP_EXECUTION;
621284990Scy
622284990Scy    if (elements == 0)
623284990Scy    {
624284990Scy        UnityTestResultsFailBegin(lineNumber);
625284990Scy        UnityPrint(UnityStrPointless);
626284990Scy        UnityAddMsgIfSpecified(msg);
627284990Scy        UNITY_FAIL_AND_BAIL;
628284990Scy    }
629284990Scy
630284990Scy    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE const void*)expected, (UNITY_PTR_ATTRIBUTE const void*)actual, lineNumber, msg) == 1)
631284990Scy        return;
632284990Scy
633284990Scy    while (elements--)
634284990Scy    {
635284990Scy        diff = *ptr_expected - *ptr_actual;
636284990Scy        if (diff < 0.0f)
637284990Scy          diff = 0.0f - diff;
638284990Scy        tol = UNITY_FLOAT_PRECISION * *ptr_expected;
639284990Scy        if (tol < 0.0f)
640284990Scy            tol = 0.0f - tol;
641284990Scy
642284990Scy        //This first part of this condition will catch any NaN or Infinite values
643284990Scy        if ((diff * 0.0f != 0.0f) || (diff > tol))
644284990Scy        {
645284990Scy            UnityTestResultsFailBegin(lineNumber);
646284990Scy            UnityPrint(UnityStrElement);
647284990Scy            UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
648284990Scy#ifdef UNITY_FLOAT_VERBOSE
649284990Scy            UnityPrint(UnityStrExpected);
650284990Scy            UnityPrintFloat(*ptr_expected);
651284990Scy            UnityPrint(UnityStrWas);
652284990Scy            UnityPrintFloat(*ptr_actual);
653284990Scy#else
654284990Scy            UnityPrint(UnityStrDelta);
655284990Scy#endif
656284990Scy            UnityAddMsgIfSpecified(msg);
657284990Scy            UNITY_FAIL_AND_BAIL;
658284990Scy        }
659284990Scy        ptr_expected++;
660284990Scy        ptr_actual++;
661284990Scy    }
662284990Scy}
663284990Scy
664284990Scy//-----------------------------------------------
665284990Scyvoid UnityAssertFloatsWithin(const _UF delta,
666284990Scy                             const _UF expected,
667284990Scy                             const _UF actual,
668284990Scy                             const char* msg,
669284990Scy                             const UNITY_LINE_TYPE lineNumber)
670284990Scy{
671284990Scy    _UF diff = actual - expected;
672284990Scy    _UF pos_delta = delta;
673284990Scy
674284990Scy    UNITY_SKIP_EXECUTION;
675284990Scy
676284990Scy    if (diff < 0.0f)
677284990Scy    {
678284990Scy        diff = 0.0f - diff;
679284990Scy    }
680284990Scy    if (pos_delta < 0.0f)
681284990Scy    {
682284990Scy        pos_delta = 0.0f - pos_delta;
683284990Scy    }
684284990Scy
685284990Scy    //This first part of this condition will catch any NaN or Infinite values
686284990Scy    if ((diff * 0.0f != 0.0f) || (pos_delta < diff))
687284990Scy    {
688284990Scy        UnityTestResultsFailBegin(lineNumber);
689284990Scy#ifdef UNITY_FLOAT_VERBOSE
690284990Scy        UnityPrint(UnityStrExpected);
691284990Scy        UnityPrintFloat(expected);
692284990Scy        UnityPrint(UnityStrWas);
693284990Scy        UnityPrintFloat(actual);
694284990Scy#else
695284990Scy        UnityPrint(UnityStrDelta);
696284990Scy#endif
697284990Scy        UnityAddMsgIfSpecified(msg);
698284990Scy        UNITY_FAIL_AND_BAIL;
699284990Scy    }
700284990Scy}
701284990Scy
702284990Scy//-----------------------------------------------
703284990Scyvoid UnityAssertFloatSpecial(const _UF actual,
704284990Scy                             const char* msg,
705284990Scy                             const UNITY_LINE_TYPE lineNumber,
706284990Scy                             const UNITY_FLOAT_TRAIT_T style)
707284990Scy{
708284990Scy    const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet };
709284990Scy    _U_SINT should_be_trait   = ((_U_SINT)style & 1);
710284990Scy    _U_SINT is_trait          = !should_be_trait;
711284990Scy    _U_SINT trait_index       = style >> 1;
712284990Scy
713284990Scy    UNITY_SKIP_EXECUTION;
714284990Scy
715284990Scy    switch(style)
716284990Scy    {
717284990Scy        //To determine Inf / Neg Inf, we compare to an Inf / Neg Inf value we create on the fly
718284990Scy        //We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise
719284990Scy        case UNITY_FLOAT_IS_INF:
720284990Scy        case UNITY_FLOAT_IS_NOT_INF:
721284990Scy            is_trait = ((1.0f / f_zero) == actual) ? 1 : 0;
722284990Scy            break;
723284990Scy        case UNITY_FLOAT_IS_NEG_INF:
724284990Scy        case UNITY_FLOAT_IS_NOT_NEG_INF:
725284990Scy            is_trait = ((-1.0f / f_zero) == actual) ? 1 : 0;
726284990Scy            break;
727284990Scy
728284990Scy        //NaN is the only floating point value that does NOT equal itself. Therefore if Actual == Actual, then it is NOT NaN.
729284990Scy        case UNITY_FLOAT_IS_NAN:
730284990Scy        case UNITY_FLOAT_IS_NOT_NAN:
731284990Scy            is_trait = (actual == actual) ? 0 : 1;
732284990Scy            break;
733284990Scy
734284990Scy        //A determinate number is non infinite and not NaN. (therefore the opposite of the two above)
735284990Scy        case UNITY_FLOAT_IS_DET:
736284990Scy        case UNITY_FLOAT_IS_NOT_DET:
737284990Scy            if ( (actual != actual) || ((1.0f / f_zero) == actual) || ((-1.0f / f_zero) == actual) )
738284990Scy                is_trait = 0;
739284990Scy            else
740284990Scy                is_trait = 1;
741284990Scy            break;
742284990Scy	default:
743284990Scy	    ;
744284990Scy    }
745284990Scy
746284990Scy    if (is_trait != should_be_trait)
747284990Scy    {
748284990Scy        UnityTestResultsFailBegin(lineNumber);
749284990Scy        UnityPrint(UnityStrExpected);
750284990Scy        if (!should_be_trait)
751284990Scy            UnityPrint(UnityStrNot);
752284990Scy        UnityPrint(trait_names[trait_index]);
753284990Scy        UnityPrint(UnityStrWas);
754284990Scy#ifdef UNITY_FLOAT_VERBOSE
755284990Scy        UnityPrintFloat(actual);
756284990Scy#else
757284990Scy        if (should_be_trait)
758284990Scy            UnityPrint(UnityStrNot);
759284990Scy        UnityPrint(trait_names[trait_index]);
760284990Scy#endif
761284990Scy        UnityAddMsgIfSpecified(msg);
762284990Scy        UNITY_FAIL_AND_BAIL;
763284990Scy    }
764284990Scy}
765284990Scy
766284990Scy#endif //not UNITY_EXCLUDE_FLOAT
767284990Scy
768284990Scy//-----------------------------------------------
769284990Scy#ifndef UNITY_EXCLUDE_DOUBLE
770284990Scyvoid UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected,
771284990Scy                                 UNITY_PTR_ATTRIBUTE const _UD* actual,
772284990Scy                                 const _UU32 num_elements,
773284990Scy                                 const char* msg,
774284990Scy                                 const UNITY_LINE_TYPE lineNumber)
775284990Scy{
776284990Scy    _UU32 elements = num_elements;
777284990Scy    UNITY_PTR_ATTRIBUTE const _UD* ptr_expected = expected;
778284990Scy    UNITY_PTR_ATTRIBUTE const _UD* ptr_actual = actual;
779284990Scy    _UD diff, tol;
780284990Scy
781284990Scy    UNITY_SKIP_EXECUTION;
782284990Scy
783284990Scy    if (elements == 0)
784284990Scy    {
785284990Scy        UnityTestResultsFailBegin(lineNumber);
786284990Scy        UnityPrint(UnityStrPointless);
787284990Scy        UnityAddMsgIfSpecified(msg);
788284990Scy        UNITY_FAIL_AND_BAIL;
789284990Scy    }
790284990Scy
791284990Scy    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1)
792284990Scy        return;
793284990Scy
794284990Scy    while (elements--)
795284990Scy    {
796284990Scy        diff = *ptr_expected - *ptr_actual;
797284990Scy        if (diff < 0.0)
798284990Scy          diff = 0.0 - diff;
799284990Scy        tol = UNITY_DOUBLE_PRECISION * *ptr_expected;
800284990Scy        if (tol < 0.0)
801284990Scy            tol = 0.0 - tol;
802284990Scy
803284990Scy        //This first part of this condition will catch any NaN or Infinite values
804284990Scy        if ((diff * 0.0 != 0.0) || (diff > tol))
805284990Scy        {
806284990Scy            UnityTestResultsFailBegin(lineNumber);
807284990Scy            UnityPrint(UnityStrElement);
808284990Scy            UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
809284990Scy#ifdef UNITY_DOUBLE_VERBOSE
810284990Scy            UnityPrint(UnityStrExpected);
811284990Scy            UnityPrintFloat((float)(*ptr_expected));
812284990Scy            UnityPrint(UnityStrWas);
813284990Scy            UnityPrintFloat((float)(*ptr_actual));
814284990Scy#else
815284990Scy            UnityPrint(UnityStrDelta);
816284990Scy#endif
817284990Scy            UnityAddMsgIfSpecified(msg);
818284990Scy            UNITY_FAIL_AND_BAIL;
819284990Scy        }
820284990Scy        ptr_expected++;
821284990Scy        ptr_actual++;
822284990Scy    }
823284990Scy}
824284990Scy
825284990Scy//-----------------------------------------------
826284990Scyvoid UnityAssertDoublesWithin(const _UD delta,
827284990Scy                              const _UD expected,
828284990Scy                              const _UD actual,
829284990Scy                              const char* msg,
830284990Scy                              const UNITY_LINE_TYPE lineNumber)
831284990Scy{
832284990Scy    _UD diff = actual - expected;
833284990Scy    _UD pos_delta = delta;
834284990Scy
835284990Scy    UNITY_SKIP_EXECUTION;
836284990Scy
837284990Scy    if (diff < 0.0)
838284990Scy    {
839284990Scy        diff = 0.0 - diff;
840284990Scy    }
841284990Scy    if (pos_delta < 0.0)
842284990Scy    {
843284990Scy        pos_delta = 0.0 - pos_delta;
844284990Scy    }
845284990Scy
846284990Scy    //This first part of this condition will catch any NaN or Infinite values
847284990Scy    if ((diff * 0.0 != 0.0) || (pos_delta < diff))
848284990Scy    {
849284990Scy        UnityTestResultsFailBegin(lineNumber);
850284990Scy#ifdef UNITY_DOUBLE_VERBOSE
851284990Scy        UnityPrint(UnityStrExpected);
852284990Scy        UnityPrintFloat((float)expected);
853284990Scy        UnityPrint(UnityStrWas);
854284990Scy        UnityPrintFloat((float)actual);
855284990Scy#else
856284990Scy        UnityPrint(UnityStrDelta);
857284990Scy#endif
858284990Scy        UnityAddMsgIfSpecified(msg);
859284990Scy        UNITY_FAIL_AND_BAIL;
860284990Scy    }
861284990Scy}
862284990Scy
863284990Scy//-----------------------------------------------
864284990Scy
865284990Scyvoid UnityAssertDoubleSpecial(const _UD actual,
866284990Scy                              const char* msg,
867284990Scy                              const UNITY_LINE_TYPE lineNumber,
868284990Scy                              const UNITY_FLOAT_TRAIT_T style)
869284990Scy{
870284990Scy    const char* trait_names[] = { UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet };
871284990Scy    _U_SINT should_be_trait   = ((_U_SINT)style & 1);
872284990Scy    _U_SINT is_trait          = !should_be_trait;
873284990Scy    _U_SINT trait_index       = style >> 1;
874284990Scy
875284990Scy    UNITY_SKIP_EXECUTION;
876284990Scy
877284990Scy    switch(style)
878284990Scy    {
879284990Scy        //To determine Inf / Neg Inf, we compare to an Inf / Neg Inf value we create on the fly
880284990Scy        //We are using a variable to hold the zero value because some compilers complain about dividing by zero otherwise
881284990Scy        case UNITY_FLOAT_IS_INF:
882284990Scy        case UNITY_FLOAT_IS_NOT_INF:
883284990Scy            is_trait = ((1.0 / d_zero) == actual) ? 1 : 0;
884284990Scy            break;
885284990Scy        case UNITY_FLOAT_IS_NEG_INF:
886284990Scy        case UNITY_FLOAT_IS_NOT_NEG_INF:
887284990Scy            is_trait = ((-1.0 / d_zero) == actual) ? 1 : 0;
888284990Scy            break;
889284990Scy
890284990Scy        //NaN is the only floating point value that does NOT equal itself. Therefore if Actual == Actual, then it is NOT NaN.
891284990Scy        case UNITY_FLOAT_IS_NAN:
892284990Scy        case UNITY_FLOAT_IS_NOT_NAN:
893284990Scy            is_trait = (actual == actual) ? 0 : 1;
894284990Scy            break;
895284990Scy
896284990Scy        //A determinate number is non infinite and not NaN. (therefore the opposite of the two above)
897284990Scy        case UNITY_FLOAT_IS_DET:
898284990Scy        case UNITY_FLOAT_IS_NOT_DET:
899284990Scy            if ( (actual != actual) || ((1.0 / d_zero) == actual) || ((-1.0 / d_zero) == actual) )
900284990Scy                is_trait = 0;
901284990Scy            else
902284990Scy                is_trait = 1;
903284990Scy            break;
904284990Scy	default:
905284990Scy	    ;
906284990Scy    }
907284990Scy
908284990Scy    if (is_trait != should_be_trait)
909284990Scy    {
910284990Scy        UnityTestResultsFailBegin(lineNumber);
911284990Scy        UnityPrint(UnityStrExpected);
912284990Scy        if (!should_be_trait)
913284990Scy            UnityPrint(UnityStrNot);
914284990Scy        UnityPrint(trait_names[trait_index]);
915284990Scy        UnityPrint(UnityStrWas);
916284990Scy#ifdef UNITY_DOUBLE_VERBOSE
917284990Scy        UnityPrintFloat(actual);
918284990Scy#else
919284990Scy        if (should_be_trait)
920284990Scy            UnityPrint(UnityStrNot);
921284990Scy        UnityPrint(trait_names[trait_index]);
922284990Scy#endif
923284990Scy        UnityAddMsgIfSpecified(msg);
924284990Scy        UNITY_FAIL_AND_BAIL;
925284990Scy    }
926284990Scy}
927284990Scy
928284990Scy
929284990Scy#endif // not UNITY_EXCLUDE_DOUBLE
930284990Scy
931284990Scy//-----------------------------------------------
932284990Scyvoid UnityAssertNumbersWithin( const _U_SINT delta,
933284990Scy                               const _U_SINT expected,
934284990Scy                               const _U_SINT actual,
935284990Scy                               const char* msg,
936284990Scy                               const UNITY_LINE_TYPE lineNumber,
937284990Scy                               const UNITY_DISPLAY_STYLE_T style)
938284990Scy{
939284990Scy    UNITY_SKIP_EXECUTION;
940284990Scy
941284990Scy    if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
942284990Scy    {
943284990Scy        if (actual > expected)
944284990Scy          Unity.CurrentTestFailed = ((actual - expected) > delta);
945284990Scy        else
946284990Scy          Unity.CurrentTestFailed = ((expected - actual) > delta);
947284990Scy    }
948284990Scy    else
949284990Scy    {
950284990Scy        if ((_U_UINT)actual > (_U_UINT)expected)
951284990Scy            Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > (_U_UINT)delta);
952284990Scy        else
953284990Scy            Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > (_U_UINT)delta);
954284990Scy    }
955284990Scy
956284990Scy    if (Unity.CurrentTestFailed)
957284990Scy    {
958284990Scy        UnityTestResultsFailBegin(lineNumber);
959284990Scy        UnityPrint(UnityStrDelta);
960284990Scy        UnityPrintNumberByStyle(delta, style);
961284990Scy        UnityPrint(UnityStrExpected);
962284990Scy        UnityPrintNumberByStyle(expected, style);
963284990Scy        UnityPrint(UnityStrWas);
964284990Scy        UnityPrintNumberByStyle(actual, style);
965284990Scy        UnityAddMsgIfSpecified(msg);
966284990Scy        UNITY_FAIL_AND_BAIL;
967284990Scy    }
968284990Scy}
969284990Scy
970284990Scy//-----------------------------------------------
971284990Scyvoid UnityAssertEqualString(const char* expected,
972284990Scy                            const char* actual,
973284990Scy                            const char* msg,
974284990Scy                            const UNITY_LINE_TYPE lineNumber)
975284990Scy{
976284990Scy    _UU32 i;
977284990Scy
978284990Scy    UNITY_SKIP_EXECUTION;
979284990Scy
980284990Scy    // if both pointers not null compare the strings
981284990Scy    if (expected && actual)
982284990Scy    {
983284990Scy        for (i = 0; expected[i] || actual[i]; i++)
984284990Scy        {
985284990Scy            if (expected[i] != actual[i])
986284990Scy            {
987284990Scy                Unity.CurrentTestFailed = 1;
988284990Scy                break;
989284990Scy            }
990284990Scy        }
991284990Scy    }
992284990Scy    else
993284990Scy    { // handle case of one pointers being null (if both null, test should pass)
994284990Scy        if (expected != actual)
995284990Scy        {
996284990Scy            Unity.CurrentTestFailed = 1;
997284990Scy        }
998284990Scy    }
999284990Scy
1000284990Scy    if (Unity.CurrentTestFailed)
1001284990Scy    {
1002284990Scy      UnityTestResultsFailBegin(lineNumber);
1003284990Scy      UnityPrintExpectedAndActualStrings(expected, actual);
1004284990Scy      UnityAddMsgIfSpecified(msg);
1005284990Scy      UNITY_FAIL_AND_BAIL;
1006284990Scy    }
1007284990Scy}
1008284990Scy
1009284990Scy//-----------------------------------------------
1010284990Scyvoid UnityAssertEqualStringArray( const char** expected,
1011284990Scy                                  const char** actual,
1012284990Scy                                  const _UU32 num_elements,
1013284990Scy                                  const char* msg,
1014284990Scy                                  const UNITY_LINE_TYPE lineNumber)
1015284990Scy{
1016284990Scy    _UU32 i, j = 0;
1017284990Scy
1018284990Scy    UNITY_SKIP_EXECUTION;
1019284990Scy
1020284990Scy    // if no elements, it's an error
1021284990Scy    if (num_elements == 0)
1022284990Scy    {
1023284990Scy        UnityTestResultsFailBegin(lineNumber);
1024284990Scy        UnityPrint(UnityStrPointless);
1025284990Scy        UnityAddMsgIfSpecified(msg);
1026284990Scy        UNITY_FAIL_AND_BAIL;
1027284990Scy    }
1028284990Scy
1029284990Scy    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE void*)expected, (UNITY_PTR_ATTRIBUTE void*)actual, lineNumber, msg) == 1)
1030284990Scy        return;
1031284990Scy
1032284990Scy    do
1033284990Scy    {
1034284990Scy        // if both pointers not null compare the strings
1035284990Scy        if (expected[j] && actual[j])
1036284990Scy        {
1037284990Scy            for (i = 0; expected[j][i] || actual[j][i]; i++)
1038284990Scy            {
1039284990Scy                if (expected[j][i] != actual[j][i])
1040284990Scy                {
1041284990Scy                    Unity.CurrentTestFailed = 1;
1042284990Scy                    break;
1043284990Scy                }
1044284990Scy            }
1045284990Scy        }
1046284990Scy        else
1047284990Scy        { // handle case of one pointers being null (if both null, test should pass)
1048284990Scy            if (expected[j] != actual[j])
1049284990Scy            {
1050284990Scy                Unity.CurrentTestFailed = 1;
1051284990Scy            }
1052284990Scy        }
1053284990Scy
1054284990Scy        if (Unity.CurrentTestFailed)
1055284990Scy        {
1056284990Scy            UnityTestResultsFailBegin(lineNumber);
1057284990Scy            if (num_elements > 1)
1058284990Scy            {
1059284990Scy                UnityPrint(UnityStrElement);
1060284990Scy                UnityPrintNumberByStyle((j), UNITY_DISPLAY_STYLE_UINT);
1061284990Scy            }
1062284990Scy            UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j]));
1063284990Scy            UnityAddMsgIfSpecified(msg);
1064284990Scy            UNITY_FAIL_AND_BAIL;
1065284990Scy        }
1066284990Scy    } while (++j < num_elements);
1067284990Scy}
1068284990Scy
1069284990Scy//-----------------------------------------------
1070284990Scyvoid UnityAssertEqualMemory( UNITY_PTR_ATTRIBUTE const void* expected,
1071284990Scy                             UNITY_PTR_ATTRIBUTE const void* actual,
1072284990Scy                             const _UU32 length,
1073284990Scy                             const _UU32 num_elements,
1074284990Scy                             const char* msg,
1075284990Scy                             const UNITY_LINE_TYPE lineNumber)
1076284990Scy{
1077284990Scy    UNITY_PTR_ATTRIBUTE const unsigned char* ptr_exp = (UNITY_PTR_ATTRIBUTE const unsigned char*)expected;
1078284990Scy    UNITY_PTR_ATTRIBUTE const unsigned char* ptr_act = (UNITY_PTR_ATTRIBUTE const unsigned char*)actual;
1079284990Scy    _UU32 elements = num_elements;
1080284990Scy    _UU32 bytes;
1081284990Scy
1082284990Scy    UNITY_SKIP_EXECUTION;
1083284990Scy
1084284990Scy    if ((elements == 0) || (length == 0))
1085284990Scy    {
1086284990Scy        UnityTestResultsFailBegin(lineNumber);
1087284990Scy        UnityPrint(UnityStrPointless);
1088284990Scy        UnityAddMsgIfSpecified(msg);
1089284990Scy        UNITY_FAIL_AND_BAIL;
1090284990Scy    }
1091284990Scy
1092284990Scy    if (UnityCheckArraysForNull((UNITY_PTR_ATTRIBUTE const void*)expected, (UNITY_PTR_ATTRIBUTE const void*)actual, lineNumber, msg) == 1)
1093284990Scy        return;
1094284990Scy
1095284990Scy    while (elements--)
1096284990Scy    {
1097284990Scy        /////////////////////////////////////
1098284990Scy        bytes = length;
1099284990Scy        while (bytes--)
1100284990Scy        {
1101284990Scy            if (*ptr_exp != *ptr_act)
1102284990Scy            {
1103284990Scy                UnityTestResultsFailBegin(lineNumber);
1104284990Scy                UnityPrint(UnityStrMemory);
1105284990Scy                if (num_elements > 1)
1106284990Scy                {
1107284990Scy                    UnityPrint(UnityStrElement);
1108284990Scy                    UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
1109284990Scy                }
1110284990Scy                UnityPrint(UnityStrByte);
1111284990Scy                UnityPrintNumberByStyle((length - bytes - 1), UNITY_DISPLAY_STYLE_UINT);
1112284990Scy                UnityPrint(UnityStrExpected);
1113284990Scy                UnityPrintNumberByStyle(*ptr_exp, UNITY_DISPLAY_STYLE_HEX8);
1114284990Scy                UnityPrint(UnityStrWas);
1115284990Scy                UnityPrintNumberByStyle(*ptr_act, UNITY_DISPLAY_STYLE_HEX8);
1116284990Scy                UnityAddMsgIfSpecified(msg);
1117284990Scy                UNITY_FAIL_AND_BAIL;
1118284990Scy            }
1119284990Scy            ptr_exp += 1;
1120284990Scy            ptr_act += 1;
1121284990Scy        }
1122284990Scy        /////////////////////////////////////
1123284990Scy
1124284990Scy    }
1125284990Scy}
1126284990Scy
1127284990Scy//-----------------------------------------------
1128284990Scy// Control Functions
1129284990Scy//-----------------------------------------------
1130284990Scy
1131284990Scyvoid UnityFail(const char* msg, const UNITY_LINE_TYPE line)
1132284990Scy{
1133284990Scy    UNITY_SKIP_EXECUTION;
1134284990Scy
1135284990Scy    UnityTestResultsBegin(Unity.TestFile, line);
1136284990Scy    UnityPrintFail();
1137284990Scy    if (msg != NULL)
1138284990Scy    {
1139284990Scy      UNITY_OUTPUT_CHAR(':');
1140284990Scy      if (msg[0] != ' ')
1141284990Scy      {
1142284990Scy        UNITY_OUTPUT_CHAR(' ');
1143284990Scy      }
1144284990Scy      UnityPrint(msg);
1145284990Scy    }
1146284990Scy    UNITY_FAIL_AND_BAIL;
1147284990Scy}
1148284990Scy
1149284990Scy//-----------------------------------------------
1150284990Scyvoid UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
1151284990Scy{
1152284990Scy    UNITY_SKIP_EXECUTION;
1153284990Scy
1154284990Scy    UnityTestResultsBegin(Unity.TestFile, line);
1155284990Scy    UnityPrint(UnityStrIgnore);
1156284990Scy    if (msg != NULL)
1157284990Scy    {
1158284990Scy      UNITY_OUTPUT_CHAR(':');
1159284990Scy      UNITY_OUTPUT_CHAR(' ');
1160284990Scy      UnityPrint(msg);
1161284990Scy    }
1162284990Scy    UNITY_IGNORE_AND_BAIL;
1163284990Scy}
1164284990Scy
1165284990Scy//----------------------------------------------
1166284990Scy
1167284990Scyvoid UnityExpectFail(){
1168284990Scy
1169284990Scy	Unity.isExpectingFail = 1;
1170284990Scy
1171284990Scy}
1172284990Scy
1173284990Scyvoid UnityExpectFailMessage(const char* msg, const UNITY_LINE_TYPE line ){
1174284990Scy
1175284990Scy	Unity.isExpectingFail = 1;
1176284990Scy	  if (msg != NULL)
1177284990Scy    {
1178284990Scy		Unity.XFAILMessage = msg;
1179284990Scy    }
1180284990Scy}
1181284990Scy
1182284990Scy//-----------------------------------------------
1183284990Scy#if defined(UNITY_WEAK_ATTRIBUTE)
1184284990Scy    void setUp(void);
1185284990Scy    void tearDown(void);
1186284990Scy    UNITY_WEAK_ATTRIBUTE void setUp(void) { }
1187284990Scy    UNITY_WEAK_ATTRIBUTE void tearDown(void) { }
1188284990Scy#elif defined(UNITY_WEAK_PRAGMA)
1189284990Scy#   pragma weak setUp
1190284990Scy    void setUp(void);
1191284990Scy#   pragma weak tearDown
1192284990Scy    void tearDown(void);
1193284990Scy#else
1194284990Scy    void setUp(void);
1195284990Scy    void tearDown(void);
1196284990Scy#endif
1197284990Scy
1198284990Scy//-----------------------------------------------
1199284990Scyvoid UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
1200284990Scy{
1201284990Scy    Unity.CurrentTestName = FuncName;
1202284990Scy    Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)FuncLineNum;
1203284990Scy    Unity.NumberOfTests++;
1204284990Scy
1205284990Scy    if (TEST_PROTECT())
1206284990Scy    {
1207284990Scy        setUp();
1208284990Scy        Func();
1209284990Scy    }
1210284990Scy    if (TEST_PROTECT() && !(Unity.CurrentTestIgnored))
1211284990Scy    {
1212284990Scy        tearDown();
1213284990Scy    }
1214284990Scy
1215284990Scy    UnityConcludeTest();
1216284990Scy}
1217284990Scy
1218284990Scy
1219284990Scy//-----------------------------------------------
1220284990Scyvoid UnityBegin(const char* filename)
1221284990Scy{
1222284990Scy    Unity.TestFile = filename;
1223284990Scy    Unity.CurrentTestName = NULL;
1224284990Scy    Unity.CurrentTestLineNumber = 0;
1225284990Scy    Unity.NumberOfTests = 0;
1226284990Scy    Unity.TestFailures = 0;
1227284990Scy    Unity.TestIgnores = 0;
1228284990Scy    Unity.CurrentTestFailed = 0;
1229284990Scy    Unity.CurrentTestIgnored = 0;
1230284990Scy    Unity.TestXFAILS = 0;
1231284990Scy    Unity.isExpectingFail = 0;
1232284990Scy    Unity.TestPasses = 0;
1233284990Scy    Unity.TestXPASSES = 0;
1234284990Scy    Unity.XFAILMessage = NULL;
1235284990Scy
1236284990Scy    UNITY_OUTPUT_START();
1237284990Scy}
1238284990Scy
1239284990Scy
1240284990Scy//-----------------------------------------------
1241284990Scyint UnityEnd(void)
1242284990Scy{
1243284990Scy    UNITY_PRINT_EOL;
1244284990Scy    UnityPrint(UnityStrBreaker);
1245284990Scy    UNITY_PRINT_EOL;
1246284990Scy    UnityPrintNumber((_U_SINT)(Unity.NumberOfTests));
1247284990Scy    UnityPrint(UnityStrResultsTests);
1248284990Scy    UNITY_PRINT_EOL;
1249284990Scy    UnityPrintNumber((_U_SINT)(Unity.TestPasses));
1250284990Scy    UnityPrint(UnityStrResultsPass);
1251284990Scy    UNITY_PRINT_EOL;
1252284990Scy    UnityPrintNumber((_U_SINT)(Unity.TestXFAILS));
1253284990Scy    UnityPrint(UnityStrResultsXFAIL);
1254284990Scy    UNITY_PRINT_EOL;
1255284990Scy    UnityPrintNumber((_U_SINT)(Unity.TestFailures));
1256284990Scy    UnityPrint(UnityStrResultsFailures);
1257284990Scy    UNITY_PRINT_EOL;
1258284990Scy    UnityPrintNumber((_U_SINT)(Unity.TestXPASSES));
1259284990Scy    UnityPrint(UnityStrResultsXPASS);
1260284990Scy    UNITY_PRINT_EOL;
1261284990Scy    UnityPrintNumber((_U_SINT)(Unity.TestIgnores));
1262284990Scy    UnityPrint(UnityStrResultsIgnored);
1263284990Scy    UNITY_PRINT_EOL;
1264284990Scy
1265284990Scy    UNITY_PRINT_EOL;
1266284990Scy    if (Unity.TestFailures == 0U && Unity.TestXPASSES == 0U)
1267284990Scy    {
1268284990Scy        UnityPrintOk();
1269284990Scy    }
1270284990Scy    else
1271284990Scy    {
1272284990Scy        UnityPrintFail();
1273284990Scy    }
1274284990Scy    UNITY_PRINT_EOL;
1275284990Scy    UNITY_OUTPUT_COMPLETE();
1276284990Scy    return (int)(Unity.TestFailures);
1277284990Scy}
1278284990Scy
1279284990Scy
1280284990Scy//-----------------------------------------------
1281