libft
Loading...
Searching...
No Matches
unity.c
Go to the documentation of this file.
1/* =========================================================================
2 Unity Project - A Test Framework for C
3 Copyright (c) 2007-21 Mike Karlesky, Mark VanderVoord, Greg Williams
4 [Released under MIT License. Please refer to license.txt for details]
5============================================================================ */
6
7#include "unity.h"
8#include <stddef.h>
9
10#ifndef UNITY_PROGMEM
11#define UNITY_PROGMEM
12#endif
13
14/* If omitted from header, declare overrideable prototypes here so they're ready for use */
15#ifdef UNITY_OMIT_OUTPUT_CHAR_HEADER_DECLARATION
16void UNITY_OUTPUT_CHAR(int);
17#endif
18
19/* Helpful macros for us to use here in Assert functions */
20#define UNITY_FAIL_AND_BAIL do { Unity.CurrentTestFailed = 1; UNITY_OUTPUT_FLUSH(); TEST_ABORT(); } while (0)
21#define UNITY_IGNORE_AND_BAIL do { Unity.CurrentTestIgnored = 1; UNITY_OUTPUT_FLUSH(); TEST_ABORT(); } while (0)
22#define RETURN_IF_FAIL_OR_IGNORE do { if (Unity.CurrentTestFailed || Unity.CurrentTestIgnored) { TEST_ABORT(); } } while (0)
23
25
26#ifdef UNITY_OUTPUT_COLOR
27const char UNITY_PROGMEM UnityStrOk[] = "\033[42mOK\033[0m";
28const char UNITY_PROGMEM UnityStrPass[] = "\033[42mPASS\033[0m";
29const char UNITY_PROGMEM UnityStrFail[] = "\033[41mFAIL\033[0m";
30const char UNITY_PROGMEM UnityStrIgnore[] = "\033[43mIGNORE\033[0m";
31#else
32const char UNITY_PROGMEM UnityStrOk[] = "OK";
33const char UNITY_PROGMEM UnityStrPass[] = "PASS";
34const char UNITY_PROGMEM UnityStrFail[] = "FAIL";
35const char UNITY_PROGMEM UnityStrIgnore[] = "IGNORE";
36#endif
37static const char UNITY_PROGMEM UnityStrNull[] = "NULL";
38static const char UNITY_PROGMEM UnityStrSpacer[] = ". ";
39static const char UNITY_PROGMEM UnityStrExpected[] = " Expected ";
40static const char UNITY_PROGMEM UnityStrWas[] = " Was ";
41static const char UNITY_PROGMEM UnityStrGt[] = " to be greater than ";
42static const char UNITY_PROGMEM UnityStrLt[] = " to be less than ";
43static const char UNITY_PROGMEM UnityStrOrEqual[] = "or equal to ";
44static const char UNITY_PROGMEM UnityStrNotEqual[] = " to be not equal to ";
45static const char UNITY_PROGMEM UnityStrElement[] = " Element ";
46static const char UNITY_PROGMEM UnityStrByte[] = " Byte ";
47static const char UNITY_PROGMEM UnityStrMemory[] = " Memory Mismatch.";
48static const char UNITY_PROGMEM UnityStrDelta[] = " Values Not Within Delta ";
49static const char UNITY_PROGMEM UnityStrPointless[] = " You Asked Me To Compare Nothing, Which Was Pointless.";
50static const char UNITY_PROGMEM UnityStrNullPointerForExpected[] = " Expected pointer to be NULL";
51static const char UNITY_PROGMEM UnityStrNullPointerForActual[] = " Actual pointer was NULL";
52#ifndef UNITY_EXCLUDE_FLOAT
53static const char UNITY_PROGMEM UnityStrNot[] = "Not ";
54static const char UNITY_PROGMEM UnityStrInf[] = "Infinity";
55static const char UNITY_PROGMEM UnityStrNegInf[] = "Negative Infinity";
56static const char UNITY_PROGMEM UnityStrNaN[] = "NaN";
57static const char UNITY_PROGMEM UnityStrDet[] = "Determinate";
58static const char UNITY_PROGMEM UnityStrInvalidFloatTrait[] = "Invalid Float Trait";
59#endif
60const char UNITY_PROGMEM UnityStrErrShorthand[] = "Unity Shorthand Support Disabled";
61const char UNITY_PROGMEM UnityStrErrFloat[] = "Unity Floating Point Disabled";
62const char UNITY_PROGMEM UnityStrErrDouble[] = "Unity Double Precision Disabled";
63const char UNITY_PROGMEM UnityStrErr64[] = "Unity 64-bit Support Disabled";
64static const char UNITY_PROGMEM UnityStrBreaker[] = "-----------------------";
65static const char UNITY_PROGMEM UnityStrResultsTests[] = " Tests ";
66static const char UNITY_PROGMEM UnityStrResultsFailures[] = " Failures ";
67static const char UNITY_PROGMEM UnityStrResultsIgnored[] = " Ignored ";
68#ifndef UNITY_EXCLUDE_DETAILS
69static const char UNITY_PROGMEM UnityStrDetail1Name[] = UNITY_DETAIL1_NAME " ";
70static const char UNITY_PROGMEM UnityStrDetail2Name[] = " " UNITY_DETAIL2_NAME " ";
71#endif
72/*-----------------------------------------------
73 * Pretty Printers & Test Result Output Handlers
74 *-----------------------------------------------*/
75
76/*-----------------------------------------------*/
77/* Local helper function to print characters. */
78static void UnityPrintChar(const char* pch)
79{
80 /* printable characters plus CR & LF are printed */
81 if ((*pch <= 126) && (*pch >= 32))
82 {
84 }
85 /* write escaped carriage returns */
86 else if (*pch == 13)
87 {
90 }
91 /* write escaped line feeds */
92 else if (*pch == 10)
93 {
96 }
97 /* unprintable characters are shown as codes */
98 else
99 {
100 UNITY_OUTPUT_CHAR('\\');
103 }
104}
105
106/*-----------------------------------------------*/
107/* Local helper function to print ANSI escape strings e.g. "\033[42m". */
108#ifdef UNITY_OUTPUT_COLOR
109static UNITY_UINT UnityPrintAnsiEscapeString(const char* string)
110{
111 const char* pch = string;
112 UNITY_UINT count = 0;
113
114 while (*pch && (*pch != 'm'))
115 {
116 UNITY_OUTPUT_CHAR(*pch);
117 pch++;
118 count++;
119 }
121 count++;
122
123 return count;
124}
125#endif
126
127/*-----------------------------------------------*/
128void UnityPrint(const char* string)
129{
130 const char* pch = string;
131
132 if (pch != NULL)
133 {
134 while (*pch)
135 {
136#ifdef UNITY_OUTPUT_COLOR
137 /* print ANSI escape code */
138 if ((*pch == 27) && (*(pch + 1) == '['))
139 {
140 pch += UnityPrintAnsiEscapeString(pch);
141 continue;
142 }
143#endif
144 UnityPrintChar(pch);
145 pch++;
146 }
147 }
148}
149/*-----------------------------------------------*/
150void UnityPrintLen(const char* string, const UNITY_UINT32 length)
151{
152 const char* pch = string;
153
154 if (pch != NULL)
155 {
156 while (*pch && ((UNITY_UINT32)(pch - string) < length))
157 {
158 /* printable characters plus CR & LF are printed */
159 if ((*pch <= 126) && (*pch >= 32))
160 {
161 UNITY_OUTPUT_CHAR(*pch);
162 }
163 /* write escaped carriage returns */
164 else if (*pch == 13)
165 {
166 UNITY_OUTPUT_CHAR('\\');
168 }
169 /* write escaped line feeds */
170 else if (*pch == 10)
171 {
172 UNITY_OUTPUT_CHAR('\\');
174 }
175 /* unprintable characters are shown as codes */
176 else
177 {
178 UNITY_OUTPUT_CHAR('\\');
181 }
182 pch++;
183 }
184 }
185}
186
187/*-----------------------------------------------*/
189{
191 {
192 if (style == UNITY_DISPLAY_STYLE_CHAR)
193 {
194 /* printable characters plus CR & LF are printed */
195 UNITY_OUTPUT_CHAR('\'');
196 if ((number <= 126) && (number >= 32))
197 {
198 UNITY_OUTPUT_CHAR((int)number);
199 }
200 /* write escaped carriage returns */
201 else if (number == 13)
202 {
203 UNITY_OUTPUT_CHAR('\\');
205 }
206 /* write escaped line feeds */
207 else if (number == 10)
208 {
209 UNITY_OUTPUT_CHAR('\\');
211 }
212 /* unprintable characters are shown as codes */
213 else
214 {
215 UNITY_OUTPUT_CHAR('\\');
218 }
219 UNITY_OUTPUT_CHAR('\'');
220 }
221 else
222 {
223 UnityPrintNumber(number);
224 }
225 }
227 {
229 }
230 else
231 {
234 UnityPrintNumberHex((UNITY_UINT)number, (char)((style & 0xF) * 2));
235 }
236}
237
238/*-----------------------------------------------*/
239void UnityPrintNumber(const UNITY_INT number_to_print)
240{
241 UNITY_UINT number = (UNITY_UINT)number_to_print;
242
243 if (number_to_print < 0)
244 {
245 /* A negative number, including MIN negative */
247 number = (~number) + 1;
248 }
250}
251
252/*-----------------------------------------------
253 * basically do an itoa using as little ram as possible */
255{
256 UNITY_UINT divisor = 1;
257
258 /* figure out initial divisor */
259 while (number / divisor > 9)
260 {
261 divisor *= 10;
262 }
263
264 /* now mod and print, then divide divisor */
265 do
266 {
267 UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
268 divisor /= 10;
269 } while (divisor > 0);
270}
271
272/*-----------------------------------------------*/
273void UnityPrintNumberHex(const UNITY_UINT number, const char nibbles_to_print)
274{
275 int nibble;
276 char nibbles = nibbles_to_print;
277
278 if ((unsigned)nibbles > UNITY_MAX_NIBBLES)
279 {
280 nibbles = UNITY_MAX_NIBBLES;
281 }
282
283 while (nibbles > 0)
284 {
285 nibbles--;
286 nibble = (int)(number >> (nibbles * 4)) & 0x0F;
287 if (nibble <= 9)
288 {
289 UNITY_OUTPUT_CHAR((char)('0' + nibble));
290 }
291 else
292 {
293 UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble));
294 }
295 }
296}
297
298/*-----------------------------------------------*/
299void UnityPrintMask(const UNITY_UINT mask, const UNITY_UINT number)
300{
301 UNITY_UINT current_bit = (UNITY_UINT)1 << (UNITY_INT_WIDTH - 1);
302 UNITY_INT32 i;
303
304 for (i = 0; i < UNITY_INT_WIDTH; i++)
305 {
306 if (current_bit & mask)
307 {
308 if (current_bit & number)
309 {
311 }
312 else
313 {
315 }
316 }
317 else
318 {
320 }
321 current_bit = current_bit >> 1;
322 }
323}
324
325/*-----------------------------------------------*/
326#ifndef UNITY_EXCLUDE_FLOAT_PRINT
327/*
328 * This function prints a floating-point value in a format similar to
329 * printf("%.7g") on a single-precision machine or printf("%.9g") on a
330 * double-precision machine. The 7th digit won't always be totally correct
331 * in single-precision operation (for that level of accuracy, a more
332 * complicated algorithm would be needed).
333 */
334void UnityPrintFloat(const UNITY_DOUBLE input_number)
335{
336#ifdef UNITY_INCLUDE_DOUBLE
337 static const int sig_digits = 9;
338 static const UNITY_INT32 min_scaled = 100000000;
339 static const UNITY_INT32 max_scaled = 1000000000;
340#else
341 static const int sig_digits = 7;
342 static const UNITY_INT32 min_scaled = 1000000;
343 static const UNITY_INT32 max_scaled = 10000000;
344#endif
345
346 UNITY_DOUBLE number = input_number;
347
348 /* print minus sign (does not handle negative zero) */
349 if (number < 0.0f)
350 {
352 number = -number;
353 }
354
355 /* handle zero, NaN, and +/- infinity */
356 if (number == 0.0f)
357 {
358 UnityPrint("0");
359 }
360 else if (isnan(number))
361 {
362 UnityPrint("nan");
363 }
364 else if (isinf(number))
365 {
366 UnityPrint("inf");
367 }
368 else
369 {
370 UNITY_INT32 n_int = 0;
371 UNITY_INT32 n;
372 int exponent = 0;
373 int decimals;
374 int digits;
375 char buf[16] = {0};
376
377 /*
378 * Scale up or down by powers of 10. To minimize rounding error,
379 * start with a factor/divisor of 10^10, which is the largest
380 * power of 10 that can be represented exactly. Finally, compute
381 * (exactly) the remaining power of 10 and perform one more
382 * multiplication or division.
383 */
384 if (number < 1.0f)
385 {
386 UNITY_DOUBLE factor = 1.0f;
387
388 while (number < (UNITY_DOUBLE)max_scaled / 1e10f) { number *= 1e10f; exponent -= 10; }
389 while (number * factor < (UNITY_DOUBLE)min_scaled) { factor *= 10.0f; exponent--; }
390
391 number *= factor;
392 }
393 else if (number > (UNITY_DOUBLE)max_scaled)
394 {
395 UNITY_DOUBLE divisor = 1.0f;
396
397 while (number > (UNITY_DOUBLE)min_scaled * 1e10f) { number /= 1e10f; exponent += 10; }
398 while (number / divisor > (UNITY_DOUBLE)max_scaled) { divisor *= 10.0f; exponent++; }
399
400 number /= divisor;
401 }
402 else
403 {
404 /*
405 * In this range, we can split off the integer part before
406 * doing any multiplications. This reduces rounding error by
407 * freeing up significant bits in the fractional part.
408 */
409 UNITY_DOUBLE factor = 1.0f;
410 n_int = (UNITY_INT32)number;
411 number -= (UNITY_DOUBLE)n_int;
412
413 while (n_int < min_scaled) { n_int *= 10; factor *= 10.0f; exponent--; }
414
415 number *= factor;
416 }
417
418 /* round to nearest integer */
419 n = ((UNITY_INT32)(number + number) + 1) / 2;
420
421#ifndef UNITY_ROUND_TIES_AWAY_FROM_ZERO
422 /* round to even if exactly between two integers */
423 if ((n & 1) && (((UNITY_DOUBLE)n - number) == 0.5f))
424 n--;
425#endif
426
427 n += n_int;
428
429 if (n >= max_scaled)
430 {
431 n = min_scaled;
432 exponent++;
433 }
434
435 /* determine where to place decimal point */
436 decimals = ((exponent <= 0) && (exponent >= -(sig_digits + 3))) ? (-exponent) : (sig_digits - 1);
437 exponent += decimals;
438
439 /* truncate trailing zeroes after decimal point */
440 while ((decimals > 0) && ((n % 10) == 0))
441 {
442 n /= 10;
443 decimals--;
444 }
445
446 /* build up buffer in reverse order */
447 digits = 0;
448 while ((n != 0) || (digits <= decimals))
449 {
450 buf[digits++] = (char)('0' + n % 10);
451 n /= 10;
452 }
453
454 /* print out buffer (backwards) */
455 while (digits > 0)
456 {
457 if (digits == decimals)
458 {
460 }
461 UNITY_OUTPUT_CHAR(buf[--digits]);
462 }
463
464 /* print exponent if needed */
465 if (exponent != 0)
466 {
468
469 if (exponent < 0)
470 {
472 exponent = -exponent;
473 }
474 else
475 {
477 }
478
479 digits = 0;
480 while ((exponent != 0) || (digits < 2))
481 {
482 buf[digits++] = (char)('0' + exponent % 10);
483 exponent /= 10;
484 }
485 while (digits > 0)
486 {
487 UNITY_OUTPUT_CHAR(buf[--digits]);
488 }
489 }
490 }
491}
492#endif /* ! UNITY_EXCLUDE_FLOAT_PRINT */
493
494/*-----------------------------------------------*/
495static void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line)
496{
497#ifdef UNITY_OUTPUT_FOR_ECLIPSE
499 UnityPrint(file);
506#else
507#ifdef UNITY_OUTPUT_FOR_IAR_WORKBENCH
508 UnityPrint("<SRCREF line=");
510 UnityPrint(" file=\"");
511 UnityPrint(file);
515 UnityPrint("</SRCREF> ");
516#else
517#ifdef UNITY_OUTPUT_FOR_QT_CREATOR
518 UnityPrint("file://");
519 UnityPrint(file);
525#else
526 UnityPrint(file);
532#endif
533#endif
534#endif
535}
536
537/*-----------------------------------------------*/
538static void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line)
539{
540 UnityTestResultsBegin(Unity.TestFile, line);
543}
544
545/*-----------------------------------------------*/
547{
549 {
551 }
552 else if (!Unity.CurrentTestFailed)
553 {
554 UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
556 }
557 else
558 {
560 }
561
567}
568
569/*-----------------------------------------------*/
570static void UnityAddMsgIfSpecified(const char* msg)
571{
572#ifdef UNITY_PRINT_TEST_CONTEXT
573 UnityPrint(UnityStrSpacer);
574 UNITY_PRINT_TEST_CONTEXT();
575#endif
576#ifndef UNITY_EXCLUDE_DETAILS
578 {
579 UnityPrint(UnityStrSpacer);
580 UnityPrint(UnityStrDetail1Name);
583 {
584 UnityPrint(UnityStrDetail2Name);
586 }
587 }
588#endif
589 if (msg)
590 {
591 UnityPrint(UnityStrSpacer);
592 UnityPrint(msg);
593 }
594}
595
596/*-----------------------------------------------*/
597static void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual)
598{
599 UnityPrint(UnityStrExpected);
600 if (expected != NULL)
601 {
602 UNITY_OUTPUT_CHAR('\'');
603 UnityPrint(expected);
604 UNITY_OUTPUT_CHAR('\'');
605 }
606 else
607 {
608 UnityPrint(UnityStrNull);
609 }
610 UnityPrint(UnityStrWas);
611 if (actual != NULL)
612 {
613 UNITY_OUTPUT_CHAR('\'');
614 UnityPrint(actual);
615 UNITY_OUTPUT_CHAR('\'');
616 }
617 else
618 {
619 UnityPrint(UnityStrNull);
620 }
621}
622
623/*-----------------------------------------------*/
624static void UnityPrintExpectedAndActualStringsLen(const char* expected,
625 const char* actual,
626 const UNITY_UINT32 length)
627{
628 UnityPrint(UnityStrExpected);
629 if (expected != NULL)
630 {
631 UNITY_OUTPUT_CHAR('\'');
632 UnityPrintLen(expected, length);
633 UNITY_OUTPUT_CHAR('\'');
634 }
635 else
636 {
637 UnityPrint(UnityStrNull);
638 }
639 UnityPrint(UnityStrWas);
640 if (actual != NULL)
641 {
642 UNITY_OUTPUT_CHAR('\'');
643 UnityPrintLen(actual, length);
644 UNITY_OUTPUT_CHAR('\'');
645 }
646 else
647 {
648 UnityPrint(UnityStrNull);
649 }
650}
651
652/*-----------------------------------------------
653 * Assertion & Control Helpers
654 *-----------------------------------------------*/
655
656/*-----------------------------------------------*/
657static int UnityIsOneArrayNull(UNITY_INTERNAL_PTR expected,
658 UNITY_INTERNAL_PTR actual,
659 const UNITY_LINE_TYPE lineNumber,
660 const char* msg)
661{
662 /* Both are NULL or same pointer */
663 if (expected == actual) { return 0; }
664
665 /* print and return true if just expected is NULL */
666 if (expected == NULL)
667 {
668 UnityTestResultsFailBegin(lineNumber);
669 UnityPrint(UnityStrNullPointerForExpected);
670 UnityAddMsgIfSpecified(msg);
671 return 1;
672 }
673
674 /* print and return true if just actual is NULL */
675 if (actual == NULL)
676 {
677 UnityTestResultsFailBegin(lineNumber);
678 UnityPrint(UnityStrNullPointerForActual);
679 UnityAddMsgIfSpecified(msg);
680 return 1;
681 }
682
683 return 0; /* return false if neither is NULL */
684}
685
686/*-----------------------------------------------
687 * Assertion Functions
688 *-----------------------------------------------*/
689
690/*-----------------------------------------------*/
692 const UNITY_INT expected,
693 const UNITY_INT actual,
694 const char* msg,
695 const UNITY_LINE_TYPE lineNumber)
696{
698
699 if ((mask & expected) != (mask & actual))
700 {
701 UnityTestResultsFailBegin(lineNumber);
702 UnityPrint(UnityStrExpected);
703 UnityPrintMask((UNITY_UINT)mask, (UNITY_UINT)expected);
704 UnityPrint(UnityStrWas);
705 UnityPrintMask((UNITY_UINT)mask, (UNITY_UINT)actual);
706 UnityAddMsgIfSpecified(msg);
708 }
709}
710
711/*-----------------------------------------------*/
713 const UNITY_INT actual,
714 const char* msg,
715 const UNITY_LINE_TYPE lineNumber,
716 const UNITY_DISPLAY_STYLE_T style)
717{
719
720 if (expected != actual)
721 {
722 UnityTestResultsFailBegin(lineNumber);
723 UnityPrint(UnityStrExpected);
724 UnityPrintNumberByStyle(expected, style);
725 UnityPrint(UnityStrWas);
726 UnityPrintNumberByStyle(actual, style);
727 UnityAddMsgIfSpecified(msg);
729 }
730}
731
732/*-----------------------------------------------*/
734 const UNITY_INT actual,
735 const UNITY_COMPARISON_T compare,
736 const char *msg,
737 const UNITY_LINE_TYPE lineNumber,
738 const UNITY_DISPLAY_STYLE_T style)
739{
740 int failed = 0;
742
743 if ((threshold == actual) && (compare & UNITY_EQUAL_TO)) { return; }
744 if ((threshold == actual)) { failed = 1; }
745
747 {
748 if ((actual > threshold) && (compare & UNITY_SMALLER_THAN)) { failed = 1; }
749 if ((actual < threshold) && (compare & UNITY_GREATER_THAN)) { failed = 1; }
750 }
751 else /* UINT or HEX */
752 {
753 if (((UNITY_UINT)actual > (UNITY_UINT)threshold) && (compare & UNITY_SMALLER_THAN)) { failed = 1; }
754 if (((UNITY_UINT)actual < (UNITY_UINT)threshold) && (compare & UNITY_GREATER_THAN)) { failed = 1; }
755 }
756
757 if (failed)
758 {
759 UnityTestResultsFailBegin(lineNumber);
760 UnityPrint(UnityStrExpected);
761 UnityPrintNumberByStyle(actual, style);
762 if (compare & UNITY_GREATER_THAN) { UnityPrint(UnityStrGt); }
763 if (compare & UNITY_SMALLER_THAN) { UnityPrint(UnityStrLt); }
764 if (compare & UNITY_EQUAL_TO) { UnityPrint(UnityStrOrEqual); }
765 if (compare == UNITY_NOT_EQUAL) { UnityPrint(UnityStrNotEqual); }
766 UnityPrintNumberByStyle(threshold, style);
767 UnityAddMsgIfSpecified(msg);
769 }
770}
771
772#define UnityPrintPointlessAndBail() \
773do { \
774 UnityTestResultsFailBegin(lineNumber); \
775 UnityPrint(UnityStrPointless); \
776 UnityAddMsgIfSpecified(msg); \
777 UNITY_FAIL_AND_BAIL; \
778} while (0)
779
780/*-----------------------------------------------*/
782 UNITY_INTERNAL_PTR actual,
783 const UNITY_UINT32 num_elements,
784 const char* msg,
785 const UNITY_LINE_TYPE lineNumber,
786 const UNITY_DISPLAY_STYLE_T style,
787 const UNITY_FLAGS_T flags)
788{
789 UNITY_UINT32 elements = num_elements;
790 unsigned int length = style & 0xF;
791 unsigned int increment = 0;
792
794
795 if (num_elements == 0)
796 {
797#ifdef UNITY_COMPARE_PTRS_ON_ZERO_ARRAY
798 UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, lineNumber, msg);
799#else
801#endif
802 }
803
804 if (expected == actual)
805 {
806 return; /* Both are NULL or same pointer */
807 }
808
809 if (UnityIsOneArrayNull(expected, actual, lineNumber, msg))
810 {
812 }
813
814 while ((elements > 0) && (elements--))
815 {
816 UNITY_INT expect_val;
817 UNITY_INT actual_val;
818
819 switch (length)
820 {
821 case 1:
822 expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)expected;
823 actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)actual;
825 {
826 expect_val &= 0x000000FF;
827 actual_val &= 0x000000FF;
828 }
829 increment = sizeof(UNITY_INT8);
830 break;
831
832 case 2:
833 expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)expected;
834 actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)actual;
836 {
837 expect_val &= 0x0000FFFF;
838 actual_val &= 0x0000FFFF;
839 }
840 increment = sizeof(UNITY_INT16);
841 break;
842
843#ifdef UNITY_SUPPORT_64
844 case 8:
845 expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)expected;
846 actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)actual;
847 increment = sizeof(UNITY_INT64);
848 break;
849#endif
850
851 default: /* default is length 4 bytes */
852 case 4:
853 expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)expected;
854 actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)actual;
855#ifdef UNITY_SUPPORT_64
857 {
858 expect_val &= 0x00000000FFFFFFFF;
859 actual_val &= 0x00000000FFFFFFFF;
860 }
861#endif
862 increment = sizeof(UNITY_INT32);
863 length = 4;
864 break;
865 }
866
867 if (expect_val != actual_val)
868 {
869 if ((style & UNITY_DISPLAY_RANGE_UINT) && (length < (UNITY_INT_WIDTH / 8)))
870 { /* For UINT, remove sign extension (padding 1's) from signed type casts above */
871 UNITY_INT mask = 1;
872 mask = (mask << 8 * length) - 1;
873 expect_val &= mask;
874 actual_val &= mask;
875 }
876 UnityTestResultsFailBegin(lineNumber);
877 UnityPrint(UnityStrElement);
878 UnityPrintNumberUnsigned(num_elements - elements - 1);
879 UnityPrint(UnityStrExpected);
880 UnityPrintNumberByStyle(expect_val, style);
881 UnityPrint(UnityStrWas);
882 UnityPrintNumberByStyle(actual_val, style);
883 UnityAddMsgIfSpecified(msg);
885 }
886 /* Walk through array by incrementing the pointers */
887 if (flags == UNITY_ARRAY_TO_ARRAY)
888 {
889 expected = (UNITY_INTERNAL_PTR)((const char*)expected + increment);
890 }
891 actual = (UNITY_INTERNAL_PTR)((const char*)actual + increment);
892 }
893}
894
895/*-----------------------------------------------*/
896#ifndef UNITY_EXCLUDE_FLOAT
897/* Wrap this define in a function with variable types as float or double */
898#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \
899 if (isinf(expected) && isinf(actual) && (((expected) < 0) == ((actual) < 0))) return 1; \
900 if (UNITY_NAN_CHECK) return 1; \
901 (diff) = (actual) - (expected); \
902 if ((diff) < 0) (diff) = -(diff); \
903 if ((delta) < 0) (delta) = -(delta); \
904 return !(isnan(diff) || isinf(diff) || ((diff) > (delta)))
905 /* This first part of this condition will catch any NaN or Infinite values */
906#ifndef UNITY_NAN_NOT_EQUAL_NAN
907 #define UNITY_NAN_CHECK isnan(expected) && isnan(actual)
908#else
909 #define UNITY_NAN_CHECK 0
910#endif
911
912#ifndef UNITY_EXCLUDE_FLOAT_PRINT
913 #define UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual) \
914 do { \
915 UnityPrint(UnityStrExpected); \
916 UnityPrintFloat(expected); \
917 UnityPrint(UnityStrWas); \
918 UnityPrintFloat(actual); \
919 } while (0)
920#else
921 #define UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual) \
922 UnityPrint(UnityStrDelta)
923#endif /* UNITY_EXCLUDE_FLOAT_PRINT */
924
925/*-----------------------------------------------*/
926static int UnityFloatsWithin(UNITY_FLOAT delta, UNITY_FLOAT expected, UNITY_FLOAT actual)
927{
928 UNITY_FLOAT diff;
929 UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff);
930}
931
932/*-----------------------------------------------*/
934 UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* actual,
935 const UNITY_UINT32 num_elements,
936 const char* msg,
937 const UNITY_LINE_TYPE lineNumber,
938 const UNITY_FLAGS_T flags)
939{
940 UNITY_UINT32 elements = num_elements;
941 UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* ptr_expected = expected;
942 UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* ptr_actual = actual;
943
945
946 if (elements == 0)
947 {
948#ifdef UNITY_COMPARE_PTRS_ON_ZERO_ARRAY
949 UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, lineNumber, msg);
950#else
952#endif
953 }
954
955 if (expected == actual)
956 {
957 return; /* Both are NULL or same pointer */
958 }
959
960 if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg))
961 {
963 }
964
965 while (elements--)
966 {
967 if (!UnityFloatsWithin(*ptr_expected * UNITY_FLOAT_PRECISION, *ptr_expected, *ptr_actual))
968 {
969 UnityTestResultsFailBegin(lineNumber);
970 UnityPrint(UnityStrElement);
971 UnityPrintNumberUnsigned(num_elements - elements - 1);
973 UnityAddMsgIfSpecified(msg);
975 }
976 if (flags == UNITY_ARRAY_TO_ARRAY)
977 {
978 ptr_expected++;
979 }
980 ptr_actual++;
981 }
982}
983
984/*-----------------------------------------------*/
986 const UNITY_FLOAT expected,
987 const UNITY_FLOAT actual,
988 const char* msg,
989 const UNITY_LINE_TYPE lineNumber)
990{
992
993
994 if (!UnityFloatsWithin(delta, expected, actual))
995 {
996 UnityTestResultsFailBegin(lineNumber);
998 UnityAddMsgIfSpecified(msg);
1000 }
1001}
1002
1003/*-----------------------------------------------*/
1005 const UNITY_FLOAT expected,
1006 const UNITY_FLOAT actual,
1007 const char* msg,
1008 const UNITY_LINE_TYPE lineNumber)
1009{
1011
1012 if (UnityFloatsWithin(delta, expected, actual))
1013 {
1014 UnityTestResultsFailBegin(lineNumber);
1015 UnityPrint(UnityStrExpected);
1016 UnityPrintFloat((UNITY_DOUBLE)expected);
1017 UnityPrint(UnityStrNotEqual);
1019 UnityAddMsgIfSpecified(msg);
1021 }
1022}
1023
1024/*-----------------------------------------------*/
1026 const UNITY_FLOAT actual,
1027 const UNITY_COMPARISON_T compare,
1028 const char* msg,
1029 const UNITY_LINE_TYPE lineNumber)
1030{
1031 int failed;
1032
1034
1035 failed = 0;
1036
1037 /* Checking for "not success" rather than failure to get the right result for NaN */
1038 if (!(actual < threshold) && (compare & UNITY_SMALLER_THAN)) { failed = 1; }
1039 if (!(actual > threshold) && (compare & UNITY_GREATER_THAN)) { failed = 1; }
1040
1041 if ((compare & UNITY_EQUAL_TO) && UnityFloatsWithin(threshold * UNITY_FLOAT_PRECISION, threshold, actual)) { failed = 0; }
1042
1043 if (failed)
1044 {
1045 UnityTestResultsFailBegin(lineNumber);
1046 UnityPrint(UnityStrExpected);
1047 UnityPrintFloat(actual);
1048 if (compare & UNITY_GREATER_THAN) { UnityPrint(UnityStrGt); }
1049 if (compare & UNITY_SMALLER_THAN) { UnityPrint(UnityStrLt); }
1050 if (compare & UNITY_EQUAL_TO) { UnityPrint(UnityStrOrEqual); }
1051 UnityPrintFloat(threshold);
1052 UnityAddMsgIfSpecified(msg);
1054 }
1055}
1056
1057/*-----------------------------------------------*/
1059 const char* msg,
1060 const UNITY_LINE_TYPE lineNumber,
1061 const UNITY_FLOAT_TRAIT_T style)
1062{
1063 const char* trait_names[] = {UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet};
1064 UNITY_INT should_be_trait = ((UNITY_INT)style & 1);
1065 UNITY_INT is_trait = !should_be_trait;
1066 UNITY_INT trait_index = (UNITY_INT)(style >> 1);
1067
1069
1070 switch (style)
1071 {
1072 case UNITY_FLOAT_IS_INF:
1074 is_trait = isinf(actual) && (actual > 0);
1075 break;
1078 is_trait = isinf(actual) && (actual < 0);
1079 break;
1080
1081 case UNITY_FLOAT_IS_NAN:
1083 is_trait = isnan(actual) ? 1 : 0;
1084 break;
1085
1086 case UNITY_FLOAT_IS_DET: /* A determinate number is non infinite and not NaN. */
1088 is_trait = !isinf(actual) && !isnan(actual);
1089 break;
1090
1091 default: /* including UNITY_FLOAT_INVALID_TRAIT */
1092 trait_index = 0;
1093 trait_names[0] = UnityStrInvalidFloatTrait;
1094 break;
1095 }
1096
1097 if (is_trait != should_be_trait)
1098 {
1099 UnityTestResultsFailBegin(lineNumber);
1100 UnityPrint(UnityStrExpected);
1101 if (!should_be_trait)
1102 {
1103 UnityPrint(UnityStrNot);
1104 }
1105 UnityPrint(trait_names[trait_index]);
1106 UnityPrint(UnityStrWas);
1107#ifndef UNITY_EXCLUDE_FLOAT_PRINT
1109#else
1110 if (should_be_trait)
1111 {
1112 UnityPrint(UnityStrNot);
1113 }
1114 UnityPrint(trait_names[trait_index]);
1115#endif
1116 UnityAddMsgIfSpecified(msg);
1118 }
1119}
1120
1121#endif /* not UNITY_EXCLUDE_FLOAT */
1122
1123/*-----------------------------------------------*/
1124#ifndef UNITY_EXCLUDE_DOUBLE
1125static int UnityDoublesWithin(UNITY_DOUBLE delta, UNITY_DOUBLE expected, UNITY_DOUBLE actual)
1126{
1127 UNITY_DOUBLE diff;
1128 UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff);
1129}
1130
1131/*-----------------------------------------------*/
1132void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* expected,
1133 UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* actual,
1134 const UNITY_UINT32 num_elements,
1135 const char* msg,
1136 const UNITY_LINE_TYPE lineNumber,
1137 const UNITY_FLAGS_T flags)
1138{
1139 UNITY_UINT32 elements = num_elements;
1140 UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* ptr_expected = expected;
1141 UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* ptr_actual = actual;
1142
1144
1145 if (elements == 0)
1146 {
1147#ifdef UNITY_COMPARE_PTRS_ON_ZERO_ARRAY
1148 UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, lineNumber, msg);
1149#else
1151#endif
1152 }
1153
1154 if (expected == actual)
1155 {
1156 return; /* Both are NULL or same pointer */
1157 }
1158
1159 if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg))
1160 {
1162 }
1163
1164 while (elements--)
1165 {
1166 if (!UnityDoublesWithin(*ptr_expected * UNITY_DOUBLE_PRECISION, *ptr_expected, *ptr_actual))
1167 {
1168 UnityTestResultsFailBegin(lineNumber);
1169 UnityPrint(UnityStrElement);
1170 UnityPrintNumberUnsigned(num_elements - elements - 1);
1171 UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(*ptr_expected, *ptr_actual);
1172 UnityAddMsgIfSpecified(msg);
1174 }
1175 if (flags == UNITY_ARRAY_TO_ARRAY)
1176 {
1177 ptr_expected++;
1178 }
1179 ptr_actual++;
1180 }
1181}
1182
1183/*-----------------------------------------------*/
1184void UnityAssertDoublesWithin(const UNITY_DOUBLE delta,
1185 const UNITY_DOUBLE expected,
1186 const UNITY_DOUBLE actual,
1187 const char* msg,
1188 const UNITY_LINE_TYPE lineNumber)
1189{
1191
1192 if (!UnityDoublesWithin(delta, expected, actual))
1193 {
1194 UnityTestResultsFailBegin(lineNumber);
1195 UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual);
1196 UnityAddMsgIfSpecified(msg);
1198 }
1199}
1200
1201/*-----------------------------------------------*/
1202void UnityAssertDoublesNotWithin(const UNITY_DOUBLE delta,
1203 const UNITY_DOUBLE expected,
1204 const UNITY_DOUBLE actual,
1205 const char* msg,
1206 const UNITY_LINE_TYPE lineNumber)
1207{
1209
1210 if (UnityDoublesWithin(delta, expected, actual))
1211 {
1212 UnityTestResultsFailBegin(lineNumber);
1213 UnityPrint(UnityStrExpected);
1214 UnityPrintFloat((UNITY_DOUBLE)expected);
1215 UnityPrint(UnityStrNotEqual);
1217 UnityAddMsgIfSpecified(msg);
1219 }
1220}
1221
1222/*-----------------------------------------------*/
1223void UnityAssertGreaterOrLessDouble(const UNITY_DOUBLE threshold,
1224 const UNITY_DOUBLE actual,
1225 const UNITY_COMPARISON_T compare,
1226 const char* msg,
1227 const UNITY_LINE_TYPE lineNumber)
1228{
1229 int failed;
1230
1232
1233 failed = 0;
1234
1235 /* Checking for "not success" rather than failure to get the right result for NaN */
1236 if (!(actual < threshold) && (compare & UNITY_SMALLER_THAN)) { failed = 1; }
1237 if (!(actual > threshold) && (compare & UNITY_GREATER_THAN)) { failed = 1; }
1238
1239 if ((compare & UNITY_EQUAL_TO) && UnityFloatsWithin(threshold * UNITY_DOUBLE_PRECISION, threshold, actual)) { failed = 0; }
1240
1241 if (failed)
1242 {
1243 UnityTestResultsFailBegin(lineNumber);
1244 UnityPrint(UnityStrExpected);
1245 UnityPrintFloat(actual);
1246 if (compare & UNITY_GREATER_THAN) { UnityPrint(UnityStrGt); }
1247 if (compare & UNITY_SMALLER_THAN) { UnityPrint(UnityStrLt); }
1248 if (compare & UNITY_EQUAL_TO) { UnityPrint(UnityStrOrEqual); }
1249 UnityPrintFloat(threshold);
1250 UnityAddMsgIfSpecified(msg);
1252 }
1253}
1254
1255/*-----------------------------------------------*/
1256void UnityAssertDoubleSpecial(const UNITY_DOUBLE actual,
1257 const char* msg,
1258 const UNITY_LINE_TYPE lineNumber,
1259 const UNITY_FLOAT_TRAIT_T style)
1260{
1261 const char* trait_names[] = {UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet};
1262 UNITY_INT should_be_trait = ((UNITY_INT)style & 1);
1263 UNITY_INT is_trait = !should_be_trait;
1264 UNITY_INT trait_index = (UNITY_INT)(style >> 1);
1265
1267
1268 switch (style)
1269 {
1270 case UNITY_FLOAT_IS_INF:
1272 is_trait = isinf(actual) && (actual > 0);
1273 break;
1276 is_trait = isinf(actual) && (actual < 0);
1277 break;
1278
1279 case UNITY_FLOAT_IS_NAN:
1281 is_trait = isnan(actual) ? 1 : 0;
1282 break;
1283
1284 case UNITY_FLOAT_IS_DET: /* A determinate number is non infinite and not NaN. */
1286 is_trait = !isinf(actual) && !isnan(actual);
1287 break;
1288
1289 default: /* including UNITY_FLOAT_INVALID_TRAIT */
1290 trait_index = 0;
1291 trait_names[0] = UnityStrInvalidFloatTrait;
1292 break;
1293 }
1294
1295 if (is_trait != should_be_trait)
1296 {
1297 UnityTestResultsFailBegin(lineNumber);
1298 UnityPrint(UnityStrExpected);
1299 if (!should_be_trait)
1300 {
1301 UnityPrint(UnityStrNot);
1302 }
1303 UnityPrint(trait_names[trait_index]);
1304 UnityPrint(UnityStrWas);
1305#ifndef UNITY_EXCLUDE_FLOAT_PRINT
1306 UnityPrintFloat(actual);
1307#else
1308 if (should_be_trait)
1309 {
1310 UnityPrint(UnityStrNot);
1311 }
1312 UnityPrint(trait_names[trait_index]);
1313#endif
1314 UnityAddMsgIfSpecified(msg);
1316 }
1317}
1318
1319#endif /* not UNITY_EXCLUDE_DOUBLE */
1320
1321/*-----------------------------------------------*/
1323 const UNITY_INT expected,
1324 const UNITY_INT actual,
1325 const char* msg,
1326 const UNITY_LINE_TYPE lineNumber,
1327 const UNITY_DISPLAY_STYLE_T style)
1328{
1330
1332 {
1333 if (actual > expected)
1334 {
1335 Unity.CurrentTestFailed = (((UNITY_UINT)actual - (UNITY_UINT)expected) > delta);
1336 }
1337 else
1338 {
1339 Unity.CurrentTestFailed = (((UNITY_UINT)expected - (UNITY_UINT)actual) > delta);
1340 }
1341 }
1342 else
1343 {
1344 if ((UNITY_UINT)actual > (UNITY_UINT)expected)
1345 {
1346 Unity.CurrentTestFailed = (((UNITY_UINT)actual - (UNITY_UINT)expected) > delta);
1347 }
1348 else
1349 {
1350 Unity.CurrentTestFailed = (((UNITY_UINT)expected - (UNITY_UINT)actual) > delta);
1351 }
1352 }
1353
1355 {
1356 UnityTestResultsFailBegin(lineNumber);
1357 UnityPrint(UnityStrDelta);
1358 UnityPrintNumberByStyle((UNITY_INT)delta, style);
1359 UnityPrint(UnityStrExpected);
1360 UnityPrintNumberByStyle(expected, style);
1361 UnityPrint(UnityStrWas);
1362 UnityPrintNumberByStyle(actual, style);
1363 UnityAddMsgIfSpecified(msg);
1365 }
1366}
1367
1368/*-----------------------------------------------*/
1370 UNITY_INTERNAL_PTR expected,
1371 UNITY_INTERNAL_PTR actual,
1372 const UNITY_UINT32 num_elements,
1373 const char* msg,
1374 const UNITY_LINE_TYPE lineNumber,
1375 const UNITY_DISPLAY_STYLE_T style,
1376 const UNITY_FLAGS_T flags)
1377{
1378 UNITY_UINT32 elements = num_elements;
1379 unsigned int length = style & 0xF;
1380 unsigned int increment = 0;
1381
1383
1384 if (num_elements == 0)
1385 {
1386#ifdef UNITY_COMPARE_PTRS_ON_ZERO_ARRAY
1387 UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, lineNumber, msg);
1388#else
1390#endif
1391 }
1392
1393 if (expected == actual)
1394 {
1395 return; /* Both are NULL or same pointer */
1396 }
1397
1398 if (UnityIsOneArrayNull(expected, actual, lineNumber, msg))
1399 {
1401 }
1402
1403 while ((elements > 0) && (elements--))
1404 {
1405 UNITY_INT expect_val;
1406 UNITY_INT actual_val;
1407
1408 switch (length)
1409 {
1410 case 1:
1411 /* fixing problems with signed overflow on unsigned numbers */
1413 {
1414 expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)expected;
1415 actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)actual;
1416 increment = sizeof(UNITY_INT8);
1417 }
1418 else
1419 {
1420 expect_val = (UNITY_INT)*(UNITY_PTR_ATTRIBUTE const UNITY_UINT8*)expected;
1421 actual_val = (UNITY_INT)*(UNITY_PTR_ATTRIBUTE const UNITY_UINT8*)actual;
1422 increment = sizeof(UNITY_UINT8);
1423 }
1424 break;
1425
1426 case 2:
1427 /* fixing problems with signed overflow on unsigned numbers */
1429 {
1430 expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)expected;
1431 actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)actual;
1432 increment = sizeof(UNITY_INT16);
1433 }
1434 else
1435 {
1436 expect_val = (UNITY_INT)*(UNITY_PTR_ATTRIBUTE const UNITY_UINT16*)expected;
1437 actual_val = (UNITY_INT)*(UNITY_PTR_ATTRIBUTE const UNITY_UINT16*)actual;
1438 increment = sizeof(UNITY_UINT16);
1439 }
1440 break;
1441
1442#ifdef UNITY_SUPPORT_64
1443 case 8:
1444 /* fixing problems with signed overflow on unsigned numbers */
1446 {
1447 expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)expected;
1448 actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)actual;
1449 increment = sizeof(UNITY_INT64);
1450 }
1451 else
1452 {
1453 expect_val = (UNITY_INT)*(UNITY_PTR_ATTRIBUTE const UNITY_UINT64*)expected;
1454 actual_val = (UNITY_INT)*(UNITY_PTR_ATTRIBUTE const UNITY_UINT64*)actual;
1455 increment = sizeof(UNITY_UINT64);
1456 }
1457 break;
1458#endif
1459
1460 default: /* default is length 4 bytes */
1461 case 4:
1462 /* fixing problems with signed overflow on unsigned numbers */
1464 {
1465 expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)expected;
1466 actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)actual;
1467 increment = sizeof(UNITY_INT32);
1468 }
1469 else
1470 {
1471 expect_val = (UNITY_INT)*(UNITY_PTR_ATTRIBUTE const UNITY_UINT32*)expected;
1472 actual_val = (UNITY_INT)*(UNITY_PTR_ATTRIBUTE const UNITY_UINT32*)actual;
1473 increment = sizeof(UNITY_UINT32);
1474 }
1475 length = 4;
1476 break;
1477 }
1478
1480 {
1481 if (actual_val > expect_val)
1482 {
1483 Unity.CurrentTestFailed = (((UNITY_UINT)actual_val - (UNITY_UINT)expect_val) > delta);
1484 }
1485 else
1486 {
1487 Unity.CurrentTestFailed = (((UNITY_UINT)expect_val - (UNITY_UINT)actual_val) > delta);
1488 }
1489 }
1490 else
1491 {
1492 if ((UNITY_UINT)actual_val > (UNITY_UINT)expect_val)
1493 {
1494 Unity.CurrentTestFailed = (((UNITY_UINT)actual_val - (UNITY_UINT)expect_val) > delta);
1495 }
1496 else
1497 {
1498 Unity.CurrentTestFailed = (((UNITY_UINT)expect_val - (UNITY_UINT)actual_val) > delta);
1499 }
1500 }
1501
1503 {
1504 if ((style & UNITY_DISPLAY_RANGE_UINT) && (length < (UNITY_INT_WIDTH / 8)))
1505 { /* For UINT, remove sign extension (padding 1's) from signed type casts above */
1506 UNITY_INT mask = 1;
1507 mask = (mask << 8 * length) - 1;
1508 expect_val &= mask;
1509 actual_val &= mask;
1510 }
1511 UnityTestResultsFailBegin(lineNumber);
1512 UnityPrint(UnityStrDelta);
1513 UnityPrintNumberByStyle((UNITY_INT)delta, style);
1514 UnityPrint(UnityStrElement);
1515 UnityPrintNumberUnsigned(num_elements - elements - 1);
1516 UnityPrint(UnityStrExpected);
1517 UnityPrintNumberByStyle(expect_val, style);
1518 UnityPrint(UnityStrWas);
1519 UnityPrintNumberByStyle(actual_val, style);
1520 UnityAddMsgIfSpecified(msg);
1522 }
1523 /* Walk through array by incrementing the pointers */
1524 if (flags == UNITY_ARRAY_TO_ARRAY)
1525 {
1526 expected = (UNITY_INTERNAL_PTR)((const char*)expected + increment);
1527 }
1528 actual = (UNITY_INTERNAL_PTR)((const char*)actual + increment);
1529 }
1530}
1531
1532/*-----------------------------------------------*/
1533void UnityAssertEqualString(const char* expected,
1534 const char* actual,
1535 const char* msg,
1536 const UNITY_LINE_TYPE lineNumber)
1537{
1538 UNITY_UINT32 i;
1539
1541
1542 /* if both pointers not null compare the strings */
1543 if (expected && actual)
1544 {
1545 for (i = 0; expected[i] || actual[i]; i++)
1546 {
1547 if (expected[i] != actual[i])
1548 {
1550 break;
1551 }
1552 }
1553 }
1554 else
1555 { /* handle case of one pointers being null (if both null, test should pass) */
1556 if (expected != actual)
1557 {
1559 }
1560 }
1561
1563 {
1564 UnityTestResultsFailBegin(lineNumber);
1565 UnityPrintExpectedAndActualStrings(expected, actual);
1566 UnityAddMsgIfSpecified(msg);
1568 }
1569}
1570
1571/*-----------------------------------------------*/
1572void UnityAssertEqualStringLen(const char* expected,
1573 const char* actual,
1574 const UNITY_UINT32 length,
1575 const char* msg,
1576 const UNITY_LINE_TYPE lineNumber)
1577{
1578 UNITY_UINT32 i;
1579
1581
1582 /* if both pointers not null compare the strings */
1583 if (expected && actual)
1584 {
1585 for (i = 0; (i < length) && (expected[i] || actual[i]); i++)
1586 {
1587 if (expected[i] != actual[i])
1588 {
1590 break;
1591 }
1592 }
1593 }
1594 else
1595 { /* handle case of one pointers being null (if both null, test should pass) */
1596 if (expected != actual)
1597 {
1599 }
1600 }
1601
1603 {
1604 UnityTestResultsFailBegin(lineNumber);
1605 UnityPrintExpectedAndActualStringsLen(expected, actual, length);
1606 UnityAddMsgIfSpecified(msg);
1608 }
1609}
1610
1611/*-----------------------------------------------*/
1613 const char** actual,
1614 const UNITY_UINT32 num_elements,
1615 const char* msg,
1616 const UNITY_LINE_TYPE lineNumber,
1617 const UNITY_FLAGS_T flags)
1618{
1619 UNITY_UINT32 i = 0;
1620 UNITY_UINT32 j = 0;
1621 const char* expd = NULL;
1622 const char* act = NULL;
1623
1625
1626 /* if no elements, it's an error */
1627 if (num_elements == 0)
1628 {
1629#ifdef UNITY_COMPARE_PTRS_ON_ZERO_ARRAY
1630 UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, lineNumber, msg);
1631#else
1633#endif
1634 }
1635
1636 if ((const void*)expected == (const void*)actual)
1637 {
1638 return; /* Both are NULL or same pointer */
1639 }
1640
1641 if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg))
1642 {
1644 }
1645
1646 if (flags != UNITY_ARRAY_TO_ARRAY)
1647 {
1648 expd = (const char*)expected;
1649 }
1650
1651 do
1652 {
1653 act = actual[j];
1654 if (flags == UNITY_ARRAY_TO_ARRAY)
1655 {
1656 expd = ((const char* const*)expected)[j];
1657 }
1658
1659 /* if both pointers not null compare the strings */
1660 if (expd && act)
1661 {
1662 for (i = 0; expd[i] || act[i]; i++)
1663 {
1664 if (expd[i] != act[i])
1665 {
1667 break;
1668 }
1669 }
1670 }
1671 else
1672 { /* handle case of one pointers being null (if both null, test should pass) */
1673 if (expd != act)
1674 {
1676 }
1677 }
1678
1680 {
1681 UnityTestResultsFailBegin(lineNumber);
1682 if (num_elements > 1)
1683 {
1684 UnityPrint(UnityStrElement);
1686 }
1687 UnityPrintExpectedAndActualStrings(expd, act);
1688 UnityAddMsgIfSpecified(msg);
1690 }
1691 } while (++j < num_elements);
1692}
1693
1694/*-----------------------------------------------*/
1696 UNITY_INTERNAL_PTR actual,
1697 const UNITY_UINT32 length,
1698 const UNITY_UINT32 num_elements,
1699 const char* msg,
1700 const UNITY_LINE_TYPE lineNumber,
1701 const UNITY_FLAGS_T flags)
1702{
1703 UNITY_PTR_ATTRIBUTE const unsigned char* ptr_exp = (UNITY_PTR_ATTRIBUTE const unsigned char*)expected;
1704 UNITY_PTR_ATTRIBUTE const unsigned char* ptr_act = (UNITY_PTR_ATTRIBUTE const unsigned char*)actual;
1705 UNITY_UINT32 elements = num_elements;
1706 UNITY_UINT32 bytes;
1707
1709
1710 if (elements == 0)
1711 {
1712#ifdef UNITY_COMPARE_PTRS_ON_ZERO_ARRAY
1713 UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, lineNumber, msg);
1714#else
1716#endif
1717 }
1718 if (length == 0)
1719 {
1721 }
1722
1723 if (expected == actual)
1724 {
1725 return; /* Both are NULL or same pointer */
1726 }
1727
1728 if (UnityIsOneArrayNull(expected, actual, lineNumber, msg))
1729 {
1731 }
1732
1733 while (elements--)
1734 {
1735 bytes = length;
1736 while (bytes--)
1737 {
1738 if (*ptr_exp != *ptr_act)
1739 {
1740 UnityTestResultsFailBegin(lineNumber);
1741 UnityPrint(UnityStrMemory);
1742 if (num_elements > 1)
1743 {
1744 UnityPrint(UnityStrElement);
1745 UnityPrintNumberUnsigned(num_elements - elements - 1);
1746 }
1747 UnityPrint(UnityStrByte);
1748 UnityPrintNumberUnsigned(length - bytes - 1);
1749 UnityPrint(UnityStrExpected);
1751 UnityPrint(UnityStrWas);
1753 UnityAddMsgIfSpecified(msg);
1755 }
1756 ptr_exp++;
1757 ptr_act++;
1758 }
1759 if (flags == UNITY_ARRAY_TO_VAL)
1760 {
1761 ptr_exp = (UNITY_PTR_ATTRIBUTE const unsigned char*)expected;
1762 }
1763 }
1764}
1765
1766/*-----------------------------------------------*/
1767
1768static union
1769{
1773#ifdef UNITY_SUPPORT_64
1774 UNITY_INT64 i64;
1775#endif
1776#ifndef UNITY_EXCLUDE_FLOAT
1777 float f;
1778#endif
1779#ifndef UNITY_EXCLUDE_DOUBLE
1780 double d;
1781#endif
1782} UnityQuickCompare;
1783
1785{
1786 switch(size)
1787 {
1788 case 1:
1789 UnityQuickCompare.i8 = (UNITY_INT8)num;
1790 return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i8);
1791
1792 case 2:
1793 UnityQuickCompare.i16 = (UNITY_INT16)num;
1794 return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i16);
1795
1796#ifdef UNITY_SUPPORT_64
1797 case 8:
1798 UnityQuickCompare.i64 = (UNITY_INT64)num;
1799 return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i64);
1800#endif
1801
1802 default: /* 4 bytes */
1803 UnityQuickCompare.i32 = (UNITY_INT32)num;
1804 return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i32);
1805 }
1806}
1807
1808#ifndef UNITY_EXCLUDE_FLOAT
1809/*-----------------------------------------------*/
1811{
1812 UnityQuickCompare.f = num;
1813 return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.f);
1814}
1815#endif
1816
1817#ifndef UNITY_EXCLUDE_DOUBLE
1818/*-----------------------------------------------*/
1819UNITY_INTERNAL_PTR UnityDoubleToPtr(const double num)
1820{
1821 UnityQuickCompare.d = num;
1822 return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.d);
1823}
1824#endif
1825
1826/*-----------------------------------------------
1827 * printf helper function
1828 *-----------------------------------------------*/
1829#ifdef UNITY_INCLUDE_PRINT_FORMATTED
1830static void UnityPrintFVA(const char* format, va_list va)
1831{
1832 const char* pch = format;
1833 if (pch != NULL)
1834 {
1835 while (*pch)
1836 {
1837 /* format identification character */
1838 if (*pch == '%')
1839 {
1840 pch++;
1841
1842 if (pch != NULL)
1843 {
1844 switch (*pch)
1845 {
1846 case 'd':
1847 case 'i':
1848 {
1849 const int number = va_arg(va, int);
1850 UnityPrintNumber((UNITY_INT)number);
1851 break;
1852 }
1853#ifndef UNITY_EXCLUDE_FLOAT_PRINT
1854 case 'f':
1855 case 'g':
1856 {
1857 const double number = va_arg(va, double);
1859 break;
1860 }
1861#endif
1862 case 'u':
1863 {
1864 const unsigned int number = va_arg(va, unsigned int);
1866 break;
1867 }
1868 case 'b':
1869 {
1870 const unsigned int number = va_arg(va, unsigned int);
1871 const UNITY_UINT mask = (UNITY_UINT)0 - (UNITY_UINT)1;
1872 UNITY_OUTPUT_CHAR('0');
1873 UNITY_OUTPUT_CHAR('b');
1874 UnityPrintMask(mask, (UNITY_UINT)number);
1875 break;
1876 }
1877 case 'x':
1878 case 'X':
1879 case 'p':
1880 {
1881 const unsigned int number = va_arg(va, unsigned int);
1882 UNITY_OUTPUT_CHAR('0');
1883 UNITY_OUTPUT_CHAR('x');
1884 UnityPrintNumberHex((UNITY_UINT)number, 8);
1885 break;
1886 }
1887 case 'c':
1888 {
1889 const int ch = va_arg(va, int);
1890 UnityPrintChar((const char *)&ch);
1891 break;
1892 }
1893 case 's':
1894 {
1895 const char * string = va_arg(va, const char *);
1896 UnityPrint(string);
1897 break;
1898 }
1899 case '%':
1900 {
1901 UnityPrintChar(pch);
1902 break;
1903 }
1904 default:
1905 {
1906 /* print the unknown format character */
1907 UNITY_OUTPUT_CHAR('%');
1908 UnityPrintChar(pch);
1909 break;
1910 }
1911 }
1912 }
1913 }
1914#ifdef UNITY_OUTPUT_COLOR
1915 /* print ANSI escape code */
1916 else if ((*pch == 27) && (*(pch + 1) == '['))
1917 {
1918 pch += UnityPrintAnsiEscapeString(pch);
1919 continue;
1920 }
1921#endif
1922 else if (*pch == '\n')
1923 {
1925 }
1926 else
1927 {
1928 UnityPrintChar(pch);
1929 }
1930
1931 pch++;
1932 }
1933 }
1934}
1935
1936void UnityPrintF(const UNITY_LINE_TYPE line, const char* format, ...)
1937{
1938 UnityTestResultsBegin(Unity.TestFile, line);
1939 UnityPrint("INFO");
1940 if(format != NULL)
1941 {
1942 UnityPrint(": ");
1943 va_list va;
1944 va_start(va, format);
1945 UnityPrintFVA(format, va);
1946 va_end(va);
1947 }
1949}
1950#endif /* ! UNITY_INCLUDE_PRINT_FORMATTED */
1951
1952
1953/*-----------------------------------------------
1954 * Control Functions
1955 *-----------------------------------------------*/
1956
1957/*-----------------------------------------------*/
1958void UnityFail(const char* msg, const UNITY_LINE_TYPE line)
1959{
1961
1962 UnityTestResultsBegin(Unity.TestFile, line);
1964 if (msg != NULL)
1965 {
1966 UNITY_OUTPUT_CHAR(':');
1967
1968#ifdef UNITY_PRINT_TEST_CONTEXT
1969 UNITY_PRINT_TEST_CONTEXT();
1970#endif
1971#ifndef UNITY_EXCLUDE_DETAILS
1973 {
1974 UnityPrint(UnityStrDetail1Name);
1977 {
1978 UnityPrint(UnityStrDetail2Name);
1980 }
1981 UnityPrint(UnityStrSpacer);
1982 }
1983#endif
1984 if (msg[0] != ' ')
1985 {
1986 UNITY_OUTPUT_CHAR(' ');
1987 }
1988 UnityPrint(msg);
1989 }
1990
1992}
1993
1994/*-----------------------------------------------*/
1995void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
1996{
1998
1999 UnityTestResultsBegin(Unity.TestFile, line);
2001 if (msg != NULL)
2002 {
2003 UNITY_OUTPUT_CHAR(':');
2004 UNITY_OUTPUT_CHAR(' ');
2005 UnityPrint(msg);
2006 }
2008}
2009
2010/*-----------------------------------------------*/
2011void UnityMessage(const char* msg, const UNITY_LINE_TYPE line)
2012{
2013 UnityTestResultsBegin(Unity.TestFile, line);
2014 UnityPrint("INFO");
2015 if (msg != NULL)
2016 {
2017 UNITY_OUTPUT_CHAR(':');
2018 UNITY_OUTPUT_CHAR(' ');
2019 UnityPrint(msg);
2020 }
2022}
2023
2024/*-----------------------------------------------*/
2025/* If we have not defined our own test runner, then include our default test runner to make life easier */
2026#ifndef UNITY_SKIP_DEFAULT_RUNNER
2027void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
2028{
2029 Unity.CurrentTestName = FuncName;
2034 if (TEST_PROTECT())
2035 {
2036 setUp();
2037 Func();
2038 }
2039 if (TEST_PROTECT())
2040 {
2041 tearDown();
2042 }
2045}
2046#endif
2047
2048/*-----------------------------------------------*/
2049void UnitySetTestFile(const char* filename)
2050{
2051 Unity.TestFile = filename;
2052}
2053
2054/*-----------------------------------------------*/
2055void UnityBegin(const char* filename)
2056{
2057 Unity.TestFile = filename;
2058 Unity.CurrentTestName = NULL;
2060 Unity.NumberOfTests = 0;
2061 Unity.TestFailures = 0;
2062 Unity.TestIgnores = 0;
2065
2068}
2069
2070/*-----------------------------------------------*/
2071int UnityEnd(void)
2072{
2074 UnityPrint(UnityStrBreaker);
2077 UnityPrint(UnityStrResultsTests);
2079 UnityPrint(UnityStrResultsFailures);
2081 UnityPrint(UnityStrResultsIgnored);
2083 if (Unity.TestFailures == 0U)
2084 {
2086 }
2087 else
2088 {
2090#ifdef UNITY_DIFFERENTIATE_FINAL_FAIL
2092#endif
2093 }
2097 return (int)(Unity.TestFailures);
2098}
2099
2100/*-----------------------------------------------
2101 * Command Line Argument Support
2102 *-----------------------------------------------*/
2103#ifdef UNITY_USE_COMMAND_LINE_ARGS
2104
2105char* UnityOptionIncludeNamed = NULL;
2106char* UnityOptionExcludeNamed = NULL;
2107int UnityVerbosity = 1;
2108
2109/*-----------------------------------------------*/
2110int UnityParseOptions(int argc, char** argv)
2111{
2112 int i;
2113 UnityOptionIncludeNamed = NULL;
2114 UnityOptionExcludeNamed = NULL;
2115
2116 for (i = 1; i < argc; i++)
2117 {
2118 if (argv[i][0] == '-')
2119 {
2120 switch (argv[i][1])
2121 {
2122 case 'l': /* list tests */
2123 return -1;
2124 case 'n': /* include tests with name including this string */
2125 case 'f': /* an alias for -n */
2126 if (argv[i][2] == '=')
2127 {
2128 UnityOptionIncludeNamed = &argv[i][3];
2129 }
2130 else if (++i < argc)
2131 {
2132 UnityOptionIncludeNamed = argv[i];
2133 }
2134 else
2135 {
2136 UnityPrint("ERROR: No Test String to Include Matches For");
2138 return 1;
2139 }
2140 break;
2141 case 'q': /* quiet */
2142 UnityVerbosity = 0;
2143 break;
2144 case 'v': /* verbose */
2145 UnityVerbosity = 2;
2146 break;
2147 case 'x': /* exclude tests with name including this string */
2148 if (argv[i][2] == '=')
2149 {
2150 UnityOptionExcludeNamed = &argv[i][3];
2151 }
2152 else if (++i < argc)
2153 {
2154 UnityOptionExcludeNamed = argv[i];
2155 }
2156 else
2157 {
2158 UnityPrint("ERROR: No Test String to Exclude Matches For");
2160 return 1;
2161 }
2162 break;
2163 default:
2164 UnityPrint("ERROR: Unknown Option ");
2165 UNITY_OUTPUT_CHAR(argv[i][1]);
2167 return 1;
2168 }
2169 }
2170 }
2171
2172 return 0;
2173}
2174
2175/*-----------------------------------------------*/
2176int IsStringInBiggerString(const char* longstring, const char* shortstring)
2177{
2178 const char* lptr = longstring;
2179 const char* sptr = shortstring;
2180 const char* lnext = lptr;
2181
2182 if (*sptr == '*')
2183 {
2184 return 1;
2185 }
2186
2187 while (*lptr)
2188 {
2189 lnext = lptr + 1;
2190
2191 /* If they current bytes match, go on to the next bytes */
2192 while (*lptr && *sptr && (*lptr == *sptr))
2193 {
2194 lptr++;
2195 sptr++;
2196
2197 /* We're done if we match the entire string or up to a wildcard */
2198 if (*sptr == '*')
2199 return 1;
2200 if (*sptr == ',')
2201 return 1;
2202 if (*sptr == '"')
2203 return 1;
2204 if (*sptr == '\'')
2205 return 1;
2206 if (*sptr == ':')
2207 return 2;
2208 if (*sptr == 0)
2209 return 1;
2210 }
2211
2212 /* Otherwise we start in the long pointer 1 character further and try again */
2213 lptr = lnext;
2214 sptr = shortstring;
2215 }
2216
2217 return 0;
2218}
2219
2220/*-----------------------------------------------*/
2221int UnityStringArgumentMatches(const char* str)
2222{
2223 int retval;
2224 const char* ptr1;
2225 const char* ptr2;
2226 const char* ptrf;
2227
2228 /* Go through the options and get the substrings for matching one at a time */
2229 ptr1 = str;
2230 while (ptr1[0] != 0)
2231 {
2232 if ((ptr1[0] == '"') || (ptr1[0] == '\''))
2233 {
2234 ptr1++;
2235 }
2236
2237 /* look for the start of the next partial */
2238 ptr2 = ptr1;
2239 ptrf = 0;
2240 do
2241 {
2242 ptr2++;
2243 if ((ptr2[0] == ':') && (ptr2[1] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ','))
2244 {
2245 ptrf = &ptr2[1];
2246 }
2247 } while ((ptr2[0] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ','));
2248
2249 while ((ptr2[0] != 0) && ((ptr2[0] == ':') || (ptr2[0] == '\'') || (ptr2[0] == '"') || (ptr2[0] == ',')))
2250 {
2251 ptr2++;
2252 }
2253
2254 /* done if complete filename match */
2255 retval = IsStringInBiggerString(Unity.TestFile, ptr1);
2256 if (retval == 1)
2257 {
2258 return retval;
2259 }
2260
2261 /* done if testname match after filename partial match */
2262 if ((retval == 2) && (ptrf != 0))
2263 {
2264 if (IsStringInBiggerString(Unity.CurrentTestName, ptrf))
2265 {
2266 return 1;
2267 }
2268 }
2269
2270 /* done if complete testname match */
2271 if (IsStringInBiggerString(Unity.CurrentTestName, ptr1) == 1)
2272 {
2273 return 1;
2274 }
2275
2276 ptr1 = ptr2;
2277 }
2278
2279 /* we couldn't find a match for any substrings */
2280 return 0;
2281}
2282
2283/*-----------------------------------------------*/
2284int UnityTestMatches(void)
2285{
2286 /* Check if this test name matches the included test pattern */
2287 int retval;
2288 if (UnityOptionIncludeNamed)
2289 {
2290 retval = UnityStringArgumentMatches(UnityOptionIncludeNamed);
2291 }
2292 else
2293 {
2294 retval = 1;
2295 }
2296
2297 /* Check if this test name matches the excluded test pattern */
2298 if (UnityOptionExcludeNamed)
2299 {
2300 if (UnityStringArgumentMatches(UnityOptionExcludeNamed))
2301 {
2302 retval = 0;
2303 }
2304 }
2305
2306 return retval;
2307}
2308
2309#endif /* UNITY_USE_COMMAND_LINE_ARGS */
2310/*-----------------------------------------------*/
UNITY_COUNTER_TYPE TestFailures
const char * TestFile
const char * CurrentDetail2
UNITY_COUNTER_TYPE TestIgnores
UNITY_COUNTER_TYPE CurrentTestFailed
const char * CurrentTestName
UNITY_COUNTER_TYPE NumberOfTests
const char * CurrentDetail1
UNITY_COUNTER_TYPE CurrentTestIgnored
UNITY_LINE_TYPE CurrentTestLineNumber
void setUp(void)
Definition test.c:7
void tearDown(void)
Definition test.c:10
void UnityIgnore(const char *msg, const UNITY_LINE_TYPE line)
Definition unity.c:1995
UNITY_INTERNAL_PTR UnityFloatToPtr(const float num)
Definition unity.c:1810
#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff)
Definition unity.c:898
void UnityFail(const char *msg, const UNITY_LINE_TYPE line)
Definition unity.c:1958
const char UNITY_PROGMEM UnityStrOk[]
Definition unity.c:32
void UnityAssertEqualMemory(UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_PTR actual, const UNITY_UINT32 length, const UNITY_UINT32 num_elements, const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLAGS_T flags)
Definition unity.c:1695
void UnityAssertNumbersWithin(const UNITY_UINT delta, const UNITY_INT expected, const UNITY_INT actual, const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style)
Definition unity.c:1322
void UnityPrintMask(const UNITY_UINT mask, const UNITY_UINT number)
Definition unity.c:299
const char UNITY_PROGMEM UnityStrErr64[]
Definition unity.c:63
void UnityAssertEqualStringArray(UNITY_INTERNAL_PTR expected, const char **actual, const UNITY_UINT32 num_elements, const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLAGS_T flags)
Definition unity.c:1612
#define UnityPrintPointlessAndBail()
Definition unity.c:772
void UnityPrintNumberUnsigned(const UNITY_UINT number)
Definition unity.c:254
void UnityAssertEqualNumber(const UNITY_INT expected, const UNITY_INT actual, const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style)
Definition unity.c:712
UNITY_INT16 i16
Definition unity.c:1771
void UnityConcludeTest(void)
Definition unity.c:546
int UnityEnd(void)
Definition unity.c:2071
void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_PTR actual, const UNITY_UINT32 num_elements, const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style, const UNITY_FLAGS_T flags)
Definition unity.c:781
const char UNITY_PROGMEM UnityStrErrDouble[]
Definition unity.c:62
void UnityPrintNumber(const UNITY_INT number_to_print)
Definition unity.c:239
void UnityAssertNumbersArrayWithin(const UNITY_UINT delta, UNITY_INTERNAL_PTR expected, UNITY_INTERNAL_PTR actual, const UNITY_UINT32 num_elements, const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style, const UNITY_FLAGS_T flags)
Definition unity.c:1369
void UnityPrintLen(const char *string, const UNITY_UINT32 length)
Definition unity.c:150
void UnityPrintNumberByStyle(const UNITY_INT number, const UNITY_DISPLAY_STYLE_T style)
Definition unity.c:188
#define UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual)
Definition unity.c:913
void UnityAssertGreaterOrLessOrEqualNumber(const UNITY_INT threshold, const UNITY_INT actual, const UNITY_COMPARISON_T compare, const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_DISPLAY_STYLE_T style)
Definition unity.c:733
void UnityAssertBits(const UNITY_INT mask, const UNITY_INT expected, const UNITY_INT actual, const char *msg, const UNITY_LINE_TYPE lineNumber)
Definition unity.c:691
#define UNITY_IGNORE_AND_BAIL
Definition unity.c:21
const char UNITY_PROGMEM UnityStrPass[]
Definition unity.c:33
void UnityAssertFloatSpecial(const UNITY_FLOAT actual, const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLOAT_TRAIT_T style)
Definition unity.c:1058
struct UNITY_STORAGE_T Unity
Definition unity.c:24
void UnityAssertFloatsNotWithin(const UNITY_FLOAT delta, const UNITY_FLOAT expected, const UNITY_FLOAT actual, const char *msg, const UNITY_LINE_TYPE lineNumber)
Definition unity.c:1004
void UnityAssertEqualStringLen(const char *expected, const char *actual, const UNITY_UINT32 length, const char *msg, const UNITY_LINE_TYPE lineNumber)
Definition unity.c:1572
void UnityPrintNumberHex(const UNITY_UINT number, const char nibbles_to_print)
Definition unity.c:273
const char UNITY_PROGMEM UnityStrErrFloat[]
Definition unity.c:61
void UnityMessage(const char *msg, const UNITY_LINE_TYPE line)
Definition unity.c:2011
#define RETURN_IF_FAIL_OR_IGNORE
Definition unity.c:22
const char UNITY_PROGMEM UnityStrFail[]
Definition unity.c:34
void UnityPrintFloat(const UNITY_DOUBLE input_number)
Definition unity.c:334
void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const UNITY_FLOAT *expected, UNITY_PTR_ATTRIBUTE const UNITY_FLOAT *actual, const UNITY_UINT32 num_elements, const char *msg, const UNITY_LINE_TYPE lineNumber, const UNITY_FLAGS_T flags)
Definition unity.c:933
const char UNITY_PROGMEM UnityStrErrShorthand[]
Definition unity.c:60
void UnityPrint(const char *string)
Definition unity.c:128
UNITY_INT8 i8
Definition unity.c:1770
void UnityAssertGreaterOrLessFloat(const UNITY_FLOAT threshold, const UNITY_FLOAT actual, const UNITY_COMPARISON_T compare, const char *msg, const UNITY_LINE_TYPE lineNumber)
Definition unity.c:1025
const char UNITY_PROGMEM UnityStrIgnore[]
Definition unity.c:35
void UnityAssertFloatsWithin(const UNITY_FLOAT delta, const UNITY_FLOAT expected, const UNITY_FLOAT actual, const char *msg, const UNITY_LINE_TYPE lineNumber)
Definition unity.c:985
void UnityDefaultTestRun(UnityTestFunction Func, const char *FuncName, const int FuncLineNum)
Definition unity.c:2027
UNITY_INT32 i32
Definition unity.c:1772
void UnityAssertEqualString(const char *expected, const char *actual, const char *msg, const UNITY_LINE_TYPE lineNumber)
Definition unity.c:1533
#define UNITY_FAIL_AND_BAIL
Definition unity.c:20
UNITY_INTERNAL_PTR UnityNumToPtr(const UNITY_INT num, const UNITY_UINT8 size)
Definition unity.c:1784
void UnityBegin(const char *filename)
Definition unity.c:2055
#define UNITY_PROGMEM
Definition unity.c:11
float f
Definition unity.c:1777
void UnitySetTestFile(const char *filename)
Definition unity.c:2049
#define UNITY_PRINT_EXEC_TIME()
#define UNITY_DETAIL1_NAME
signed int UNITY_INT32
#define UNITY_OUTPUT_COMPLETE()
#define UNITY_DISPLAY_RANGE_HEX
enum UNITY_FLOAT_TRAIT UNITY_FLOAT_TRAIT_T
#define UNITY_CLR_DETAILS()
UNITY_FLAGS_T
@ UNITY_ARRAY_TO_VAL
@ UNITY_ARRAY_TO_ARRAY
#define UNITY_DISPLAY_RANGE_INT
unsigned short UNITY_UINT16
#define UNITY_INT_WIDTH
#define UNITY_DISPLAY_RANGE_UINT
#define isnan(n)
#define UNITY_LINE_TYPE
#define UNITY_INTERNAL_PTR
#define TEST_PROTECT()
unsigned int UNITY_UINT32
void(* UnityTestFunction)(void)
#define UNITY_FLUSH_CALL()
#define UNITY_OUTPUT_CHAR(a)
#define UNITY_PTR_ATTRIBUTE
UNITY_DISPLAY_STYLE_T
@ UNITY_DISPLAY_STYLE_CHAR
@ UNITY_DISPLAY_STYLE_HEX8
@ UNITY_FLOAT_IS_NOT_NEG_INF
@ UNITY_FLOAT_IS_NAN
@ UNITY_FLOAT_IS_NEG_INF
@ UNITY_FLOAT_IS_NOT_INF
@ UNITY_FLOAT_IS_NOT_NAN
@ UNITY_FLOAT_IS_NOT_DET
@ UNITY_FLOAT_IS_INF
@ UNITY_FLOAT_IS_DET
#define isinf(n)
#define UNITY_OUTPUT_START()
#define UNITY_FLOAT_PRECISION
#define UNITY_PRINT_EOL()
#define UNITY_EXEC_TIME_START()
#define UNITY_MAX_NIBBLES
UNITY_INT32 UNITY_INT
UNITY_UINT32 UNITY_UINT
UNITY_FLOAT UNITY_DOUBLE
UNITY_FLOAT_TYPE UNITY_FLOAT
#define UNITY_DETAIL2_NAME
signed char UNITY_INT8
#define UNITY_EXEC_TIME_STOP()
#define UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, line, message)
unsigned char UNITY_UINT8
UNITY_COMPARISON_T
@ UNITY_SMALLER_THAN
@ UNITY_EQUAL_TO
@ UNITY_NOT_EQUAL
@ UNITY_GREATER_THAN
signed short UNITY_INT16