1 #ifdef TEST_INSTANCES
2
3 #include <string.h>
4 #include <stdint.h>
5
6 /* Dividing by these constants produces +/- infinity.
7 * The rationale is given in UnityAssertFloatIsInf's body.
8 */
9 #ifndef UNITY_EXCLUDE_FLOAT
10 static const UNITY_FLOAT f_zero = 0.0f;
11 #endif
12
13 #ifndef UNITY_EXCLUDE_DOUBLE
14 static const UNITY_DOUBLE d_zero = 0.0;
15 #endif
16
17 /* Macros for Catching An Expected Failure or Ignore */
18 #define EXPECT_ABORT_BEGIN \
19 startPutcharSpy(); \
20 if (TEST_PROTECT()) \
21 {
22
23 #define VERIFY_FAILS_END \
24 } \
25 endPutcharSpy(); /* start/end Spy to suppress output of failure message */ \
26 Unity.CurrentTestFailed = (Unity.CurrentTestFailed == 1) ? 0 : 1; \
27 if (Unity.CurrentTestFailed == 1) { \
28 SetToOneMeanWeAlreadyCheckedThisGuy = 1; \
29 UnityPrintNumberUnsigned(Unity.CurrentTestLineNumber); \
30 UNITY_OUTPUT_CHAR(':'); \
31 UnityPrint(Unity.CurrentTestName); \
32 UnityPrint(":FAIL: [[[[ Test Should Have Failed But Did Not ]]]]"); \
33 UNITY_OUTPUT_CHAR('\n'); \
34 }
35
36 #define VERIFY_IGNORES_END \
37 } \
38 endPutcharSpy(); /* start/end Spy to suppress output of ignore message */ \
39 Unity.CurrentTestFailed = (Unity.CurrentTestIgnored == 1) ? 0 : 1; \
40 Unity.CurrentTestIgnored = 0; \
41 if (Unity.CurrentTestFailed == 1) { \
42 SetToOneMeanWeAlreadyCheckedThisGuy = 1; \
43 UnityPrintNumberUnsigned(Unity.CurrentTestLineNumber); \
44 UNITY_OUTPUT_CHAR(':'); \
45 UnityPrint(Unity.CurrentTestName); \
46 UnityPrint(":FAIL: [[[[ Test Should Have Ignored But Did Not ]]]]"); \
47 UNITY_OUTPUT_CHAR('\n'); \
48 }
49
50 /* Tricky series of macros to set USING_OUTPUT_SPY */
51 #define USING_SPY_AS(a) EXPAND_AND_USE_2ND(ASSIGN_VALUE(a), 0)
52 #define ASSIGN_VALUE(a) VAL_##a
53 #define VAL_putcharSpy 0, 1
54 #define EXPAND_AND_USE_2ND(a, b) SECOND_PARAM(a, b, throwaway)
55 #define SECOND_PARAM(a, b, ...) b
56 #if USING_SPY_AS(UNITY_OUTPUT_CHAR)
57 #define USING_OUTPUT_SPY /* true only if UNITY_OUTPUT_CHAR = putcharSpy */
58 #endif
59
60 #ifdef USING_OUTPUT_SPY
61 #include <stdio.h>
62 #define SPY_BUFFER_MAX 40
63 static char putcharSpyBuffer[SPY_BUFFER_MAX];
64 #endif
65 static int indexSpyBuffer;
66 static int putcharSpyEnabled;
67
startPutcharSpy(void)68 void startPutcharSpy(void)
69 {
70 indexSpyBuffer = 0;
71 putcharSpyEnabled = 1;
72 }
73
endPutcharSpy(void)74 void endPutcharSpy(void)
75 {
76 putcharSpyEnabled = 0;
77 }
78
getBufferPutcharSpy(void)79 char* getBufferPutcharSpy(void)
80 {
81 #ifdef USING_OUTPUT_SPY
82 putcharSpyBuffer[indexSpyBuffer] = '\0';
83 return putcharSpyBuffer;
84 #else
85 return NULL;
86 #endif
87 }
88
putcharSpy(int c)89 void putcharSpy(int c)
90 {
91 #ifdef USING_OUTPUT_SPY
92 if (putcharSpyEnabled)
93 {
94 if (indexSpyBuffer < SPY_BUFFER_MAX - 1)
95 putcharSpyBuffer[indexSpyBuffer++] = (char)c;
96 } else
97 putchar((char)c);
98 #else
99 (void)c;
100 #endif
101 }
102
103 /* This is for counting the calls to the flushSpy */
104 static int flushSpyEnabled;
105 static int flushSpyCalls = 0;
106
startFlushSpy(void)107 void startFlushSpy(void)
108 {
109 flushSpyCalls = 0;
110 flushSpyEnabled = 1;
111 }
112
endFlushSpy(void)113 void endFlushSpy(void)
114 {
115 flushSpyCalls = 0;
116 flushSpyEnabled = 0;
117 }
118
getFlushSpyCalls(void)119 int getFlushSpyCalls(void)
120 {
121 return flushSpyCalls;
122 }
123
flushSpy(void)124 void flushSpy(void)
125 {
126 if (flushSpyEnabled){ flushSpyCalls++; }
127 }
128
129 #define TEST_ASSERT_EQUAL_PRINT_NUMBERS(expected, actual) { \
130 startPutcharSpy(); UnityPrintNumber((actual)); endPutcharSpy(); \
131 TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy()); \
132 }
133
134 #define TEST_ASSERT_EQUAL_PRINT_UNSIGNED_NUMBERS(expected, actual) { \
135 startPutcharSpy(); UnityPrintNumberUnsigned((actual)); endPutcharSpy(); \
136 TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy()); \
137 }
138
139 #define TEST_ASSERT_EQUAL_PRINT_FLOATING(expected, actual) { \
140 startPutcharSpy(); UnityPrintFloat((actual)); endPutcharSpy(); \
141 TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy()); \
142 }
143
144 #endif
145