/src/libzmq/external/unity/unity.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* ========================================================================= |
2 | | Unity Project - A Test Framework for C |
3 | | Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams |
4 | | [Released under MIT License. Please refer to license.txt for details] |
5 | | ============================================================================ */ |
6 | | |
7 | | #define UNITY_INCLUDE_SETUP_STUBS |
8 | | #include "unity.h" |
9 | | #include <stddef.h> |
10 | | |
11 | | /* If omitted from header, declare overrideable prototypes here so they're ready for use */ |
12 | | #ifdef UNITY_OMIT_OUTPUT_CHAR_HEADER_DECLARATION |
13 | | void UNITY_OUTPUT_CHAR(int); |
14 | | #endif |
15 | | |
16 | | /* Helpful macros for us to use here in Assert functions */ |
17 | 0 | #define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; TEST_ABORT(); } |
18 | 0 | #define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; TEST_ABORT(); } |
19 | 1.58k | #define RETURN_IF_FAIL_OR_IGNORE if (Unity.CurrentTestFailed || Unity.CurrentTestIgnored) return |
20 | | |
21 | | struct UNITY_STORAGE_T Unity; |
22 | | |
23 | | #ifdef UNITY_OUTPUT_COLOR |
24 | | static const char UnityStrOk[] = "\033[42mOK\033[00m"; |
25 | | static const char UnityStrPass[] = "\033[42mPASS\033[00m"; |
26 | | static const char UnityStrFail[] = "\033[41mFAIL\033[00m"; |
27 | | static const char UnityStrIgnore[] = "\033[43mIGNORE\033[00m"; |
28 | | #else |
29 | | static const char UnityStrOk[] = "OK"; |
30 | | static const char UnityStrPass[] = "PASS"; |
31 | | static const char UnityStrFail[] = "FAIL"; |
32 | | static const char UnityStrIgnore[] = "IGNORE"; |
33 | | #endif |
34 | | static const char UnityStrNull[] = "NULL"; |
35 | | static const char UnityStrSpacer[] = ". "; |
36 | | static const char UnityStrExpected[] = " Expected "; |
37 | | static const char UnityStrWas[] = " Was "; |
38 | | static const char UnityStrGt[] = " to be greater than "; |
39 | | static const char UnityStrLt[] = " to be less than "; |
40 | | static const char UnityStrOrEqual[] = "or equal to "; |
41 | | static const char UnityStrElement[] = " Element "; |
42 | | static const char UnityStrByte[] = " Byte "; |
43 | | static const char UnityStrMemory[] = " Memory Mismatch."; |
44 | | static const char UnityStrDelta[] = " Values Not Within Delta "; |
45 | | static const char UnityStrPointless[] = " You Asked Me To Compare Nothing, Which Was Pointless."; |
46 | | static const char UnityStrNullPointerForExpected[] = " Expected pointer to be NULL"; |
47 | | static const char UnityStrNullPointerForActual[] = " Actual pointer was NULL"; |
48 | | #ifndef UNITY_EXCLUDE_FLOAT |
49 | | static const char UnityStrNot[] = "Not "; |
50 | | static const char UnityStrInf[] = "Infinity"; |
51 | | static const char UnityStrNegInf[] = "Negative Infinity"; |
52 | | static const char UnityStrNaN[] = "NaN"; |
53 | | static const char UnityStrDet[] = "Determinate"; |
54 | | static const char UnityStrInvalidFloatTrait[] = "Invalid Float Trait"; |
55 | | #endif |
56 | | const char UnityStrErrFloat[] = "Unity Floating Point Disabled"; |
57 | | const char UnityStrErrDouble[] = "Unity Double Precision Disabled"; |
58 | | const char UnityStrErr64[] = "Unity 64-bit Support Disabled"; |
59 | | static const char UnityStrBreaker[] = "-----------------------"; |
60 | | static const char UnityStrResultsTests[] = " Tests "; |
61 | | static const char UnityStrResultsFailures[] = " Failures "; |
62 | | static const char UnityStrResultsIgnored[] = " Ignored "; |
63 | | static const char UnityStrDetail1Name[] = UNITY_DETAIL1_NAME " "; |
64 | | static const char UnityStrDetail2Name[] = " " UNITY_DETAIL2_NAME " "; |
65 | | |
66 | | /*----------------------------------------------- |
67 | | * Pretty Printers & Test Result Output Handlers |
68 | | *-----------------------------------------------*/ |
69 | | |
70 | | void UnityPrint(const char* string) |
71 | 0 | { |
72 | 0 | const char* pch = string; |
73 | |
|
74 | 0 | if (pch != NULL) |
75 | 0 | { |
76 | 0 | while (*pch) |
77 | 0 | { |
78 | | /* printable characters plus CR & LF are printed */ |
79 | 0 | if ((*pch <= 126) && (*pch >= 32)) |
80 | 0 | { |
81 | 0 | UNITY_OUTPUT_CHAR(*pch); |
82 | 0 | } |
83 | | /* write escaped carriage returns */ |
84 | 0 | else if (*pch == 13) |
85 | 0 | { |
86 | 0 | UNITY_OUTPUT_CHAR('\\'); |
87 | 0 | UNITY_OUTPUT_CHAR('r'); |
88 | 0 | } |
89 | | /* write escaped line feeds */ |
90 | 0 | else if (*pch == 10) |
91 | 0 | { |
92 | 0 | UNITY_OUTPUT_CHAR('\\'); |
93 | 0 | UNITY_OUTPUT_CHAR('n'); |
94 | 0 | } |
95 | | #ifdef UNITY_OUTPUT_COLOR |
96 | | /* print ANSI escape code */ |
97 | | else if (*pch == 27 && *(pch + 1) == '[') |
98 | | { |
99 | | while (*pch && *pch != 'm') |
100 | | { |
101 | | UNITY_OUTPUT_CHAR(*pch); |
102 | | pch++; |
103 | | } |
104 | | UNITY_OUTPUT_CHAR('m'); |
105 | | } |
106 | | #endif |
107 | | /* unprintable characters are shown as codes */ |
108 | 0 | else |
109 | 0 | { |
110 | 0 | UNITY_OUTPUT_CHAR('\\'); |
111 | 0 | UNITY_OUTPUT_CHAR('x'); |
112 | 0 | UnityPrintNumberHex((UNITY_UINT)*pch, 2); |
113 | 0 | } |
114 | 0 | pch++; |
115 | 0 | } |
116 | 0 | } |
117 | 0 | } |
118 | | |
119 | | void UnityPrintLen(const char* string, const UNITY_UINT32 length) |
120 | 0 | { |
121 | 0 | const char* pch = string; |
122 | |
|
123 | 0 | if (pch != NULL) |
124 | 0 | { |
125 | 0 | while (*pch && (UNITY_UINT32)(pch - string) < length) |
126 | 0 | { |
127 | | /* printable characters plus CR & LF are printed */ |
128 | 0 | if ((*pch <= 126) && (*pch >= 32)) |
129 | 0 | { |
130 | 0 | UNITY_OUTPUT_CHAR(*pch); |
131 | 0 | } |
132 | | /* write escaped carriage returns */ |
133 | 0 | else if (*pch == 13) |
134 | 0 | { |
135 | 0 | UNITY_OUTPUT_CHAR('\\'); |
136 | 0 | UNITY_OUTPUT_CHAR('r'); |
137 | 0 | } |
138 | | /* write escaped line feeds */ |
139 | 0 | else if (*pch == 10) |
140 | 0 | { |
141 | 0 | UNITY_OUTPUT_CHAR('\\'); |
142 | 0 | UNITY_OUTPUT_CHAR('n'); |
143 | 0 | } |
144 | | /* unprintable characters are shown as codes */ |
145 | 0 | else |
146 | 0 | { |
147 | 0 | UNITY_OUTPUT_CHAR('\\'); |
148 | 0 | UNITY_OUTPUT_CHAR('x'); |
149 | 0 | UnityPrintNumberHex((UNITY_UINT)*pch, 2); |
150 | 0 | } |
151 | 0 | pch++; |
152 | 0 | } |
153 | 0 | } |
154 | 0 | } |
155 | | |
156 | | /*-----------------------------------------------*/ |
157 | | void UnityPrintNumberByStyle(const UNITY_INT number, const UNITY_DISPLAY_STYLE_T style) |
158 | 0 | { |
159 | 0 | if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) |
160 | 0 | { |
161 | 0 | UnityPrintNumber(number); |
162 | 0 | } |
163 | 0 | else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT) |
164 | 0 | { |
165 | 0 | UnityPrintNumberUnsigned((UNITY_UINT)number); |
166 | 0 | } |
167 | 0 | else |
168 | 0 | { |
169 | 0 | UNITY_OUTPUT_CHAR('0'); |
170 | 0 | UNITY_OUTPUT_CHAR('x'); |
171 | 0 | UnityPrintNumberHex((UNITY_UINT)number, (char)((style & 0xF) * 2)); |
172 | 0 | } |
173 | 0 | } |
174 | | |
175 | | /*-----------------------------------------------*/ |
176 | | void UnityPrintNumber(const UNITY_INT number_to_print) |
177 | 0 | { |
178 | 0 | UNITY_UINT number = (UNITY_UINT)number_to_print; |
179 | |
|
180 | 0 | if (number_to_print < 0) |
181 | 0 | { |
182 | | /* A negative number, including MIN negative */ |
183 | 0 | UNITY_OUTPUT_CHAR('-'); |
184 | 0 | number = (UNITY_UINT)(-number_to_print); |
185 | 0 | } |
186 | 0 | UnityPrintNumberUnsigned(number); |
187 | 0 | } |
188 | | |
189 | | /*----------------------------------------------- |
190 | | * basically do an itoa using as little ram as possible */ |
191 | | void UnityPrintNumberUnsigned(const UNITY_UINT number) |
192 | 0 | { |
193 | 0 | UNITY_UINT divisor = 1; |
194 | | |
195 | | /* figure out initial divisor */ |
196 | 0 | while (number / divisor > 9) |
197 | 0 | { |
198 | 0 | divisor *= 10; |
199 | 0 | } |
200 | | |
201 | | /* now mod and print, then divide divisor */ |
202 | 0 | do |
203 | 0 | { |
204 | 0 | UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10))); |
205 | 0 | divisor /= 10; |
206 | 0 | } while (divisor > 0); |
207 | 0 | } |
208 | | |
209 | | /*-----------------------------------------------*/ |
210 | | void UnityPrintNumberHex(const UNITY_UINT number, const char nibbles_to_print) |
211 | 0 | { |
212 | 0 | int nibble; |
213 | 0 | char nibbles = nibbles_to_print; |
214 | 0 | if ((unsigned)nibbles > (2 * sizeof(number))) |
215 | 0 | nibbles = 2 * sizeof(number); |
216 | |
|
217 | 0 | while (nibbles > 0) |
218 | 0 | { |
219 | 0 | nibbles--; |
220 | 0 | nibble = (int)(number >> (nibbles * 4)) & 0x0F; |
221 | 0 | if (nibble <= 9) |
222 | 0 | { |
223 | 0 | UNITY_OUTPUT_CHAR((char)('0' + nibble)); |
224 | 0 | } |
225 | 0 | else |
226 | 0 | { |
227 | 0 | UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble)); |
228 | 0 | } |
229 | 0 | } |
230 | 0 | } |
231 | | |
232 | | /*-----------------------------------------------*/ |
233 | | void UnityPrintMask(const UNITY_UINT mask, const UNITY_UINT number) |
234 | 0 | { |
235 | 0 | UNITY_UINT current_bit = (UNITY_UINT)1 << (UNITY_INT_WIDTH - 1); |
236 | 0 | UNITY_INT32 i; |
237 | |
|
238 | 0 | for (i = 0; i < UNITY_INT_WIDTH; i++) |
239 | 0 | { |
240 | 0 | if (current_bit & mask) |
241 | 0 | { |
242 | 0 | if (current_bit & number) |
243 | 0 | { |
244 | 0 | UNITY_OUTPUT_CHAR('1'); |
245 | 0 | } |
246 | 0 | else |
247 | 0 | { |
248 | 0 | UNITY_OUTPUT_CHAR('0'); |
249 | 0 | } |
250 | 0 | } |
251 | 0 | else |
252 | 0 | { |
253 | 0 | UNITY_OUTPUT_CHAR('X'); |
254 | 0 | } |
255 | 0 | current_bit = current_bit >> 1; |
256 | 0 | } |
257 | 0 | } |
258 | | |
259 | | /*-----------------------------------------------*/ |
260 | | #ifndef UNITY_EXCLUDE_FLOAT_PRINT |
261 | | /* This function prints a floating-point value in a format similar to |
262 | | * printf("%.6g"). It can work with either single- or double-precision, |
263 | | * but for simplicity, it prints only 6 significant digits in either case. |
264 | | * Printing more than 6 digits accurately is hard (at least in the single- |
265 | | * precision case) and isn't attempted here. */ |
266 | | void UnityPrintFloat(const UNITY_DOUBLE input_number) |
267 | 0 | { |
268 | 0 | UNITY_DOUBLE number = input_number; |
269 | | |
270 | | /* print minus sign (including for negative zero) */ |
271 | 0 | if (number < 0.0f || (number == 0.0f && 1.0f / number < 0.0f)) |
272 | 0 | { |
273 | 0 | UNITY_OUTPUT_CHAR('-'); |
274 | 0 | number = -number; |
275 | 0 | } |
276 | | |
277 | | /* handle zero, NaN, and +/- infinity */ |
278 | 0 | if (number == 0.0f) UnityPrint("0"); |
279 | 0 | else if (isnan(number)) UnityPrint("nan"); |
280 | 0 | else if (isinf(number)) UnityPrint("inf"); |
281 | 0 | else |
282 | 0 | { |
283 | 0 | int exponent = 0; |
284 | 0 | int decimals, digits; |
285 | 0 | UNITY_INT32 n; |
286 | 0 | char buf[16]; |
287 | | |
288 | | /* scale up or down by powers of 10 */ |
289 | 0 | while (number < 100000.0f / 1e6f) { number *= 1e6f; exponent -= 6; } |
290 | 0 | while (number < 100000.0f) { number *= 10.0f; exponent--; } |
291 | 0 | while (number > 1000000.0f * 1e6f) { number /= 1e6f; exponent += 6; } |
292 | 0 | while (number > 1000000.0f) { number /= 10.0f; exponent++; } |
293 | | |
294 | | /* round to nearest integer */ |
295 | 0 | n = ((UNITY_INT32)(number + number) + 1) / 2; |
296 | 0 | if (n > 999999) |
297 | 0 | { |
298 | 0 | n = 100000; |
299 | 0 | exponent++; |
300 | 0 | } |
301 | | |
302 | | /* determine where to place decimal point */ |
303 | 0 | decimals = (exponent <= 0 && exponent >= -9) ? -exponent : 5; |
304 | 0 | exponent += decimals; |
305 | | |
306 | | /* truncate trailing zeroes after decimal point */ |
307 | 0 | while (decimals > 0 && n % 10 == 0) |
308 | 0 | { |
309 | 0 | n /= 10; |
310 | 0 | decimals--; |
311 | 0 | } |
312 | | |
313 | | /* build up buffer in reverse order */ |
314 | 0 | digits = 0; |
315 | 0 | while (n != 0 || digits < decimals + 1) |
316 | 0 | { |
317 | 0 | buf[digits++] = (char)('0' + n % 10); |
318 | 0 | n /= 10; |
319 | 0 | } |
320 | 0 | while (digits > 0) |
321 | 0 | { |
322 | 0 | if(digits == decimals) UNITY_OUTPUT_CHAR('.'); |
323 | 0 | UNITY_OUTPUT_CHAR(buf[--digits]); |
324 | 0 | } |
325 | | |
326 | | /* print exponent if needed */ |
327 | 0 | if (exponent != 0) |
328 | 0 | { |
329 | 0 | UNITY_OUTPUT_CHAR('e'); |
330 | |
|
331 | 0 | if(exponent < 0) |
332 | 0 | { |
333 | 0 | UNITY_OUTPUT_CHAR('-'); |
334 | 0 | exponent = -exponent; |
335 | 0 | } |
336 | 0 | else |
337 | 0 | { |
338 | 0 | UNITY_OUTPUT_CHAR('+'); |
339 | 0 | } |
340 | |
|
341 | 0 | digits = 0; |
342 | 0 | while (exponent != 0 || digits < 2) |
343 | 0 | { |
344 | 0 | buf[digits++] = (char)('0' + exponent % 10); |
345 | 0 | exponent /= 10; |
346 | 0 | } |
347 | 0 | while (digits > 0) |
348 | 0 | { |
349 | 0 | UNITY_OUTPUT_CHAR(buf[--digits]); |
350 | 0 | } |
351 | 0 | } |
352 | 0 | } |
353 | 0 | } |
354 | | #endif /* ! UNITY_EXCLUDE_FLOAT_PRINT */ |
355 | | |
356 | | /*-----------------------------------------------*/ |
357 | | static void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line) |
358 | 0 | { |
359 | 0 | UnityPrint(file); |
360 | 0 | UNITY_OUTPUT_CHAR(':'); |
361 | 0 | UnityPrintNumber((UNITY_INT)line); |
362 | 0 | UNITY_OUTPUT_CHAR(':'); |
363 | 0 | UnityPrint(Unity.CurrentTestName); |
364 | 0 | UNITY_OUTPUT_CHAR(':'); |
365 | 0 | } |
366 | | |
367 | | /*-----------------------------------------------*/ |
368 | | static void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line) |
369 | 0 | { |
370 | 0 | UnityTestResultsBegin(Unity.TestFile, line); |
371 | 0 | UnityPrint(UnityStrFail); |
372 | 0 | UNITY_OUTPUT_CHAR(':'); |
373 | 0 | } |
374 | | |
375 | | /*-----------------------------------------------*/ |
376 | | void UnityConcludeTest(void) |
377 | 0 | { |
378 | 0 | if (Unity.CurrentTestIgnored) |
379 | 0 | { |
380 | 0 | Unity.TestIgnores++; |
381 | 0 | } |
382 | 0 | else if (!Unity.CurrentTestFailed) |
383 | 0 | { |
384 | 0 | UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber); |
385 | 0 | UnityPrint(UnityStrPass); |
386 | 0 | } |
387 | 0 | else |
388 | 0 | { |
389 | 0 | Unity.TestFailures++; |
390 | 0 | } |
391 | |
|
392 | 0 | Unity.CurrentTestFailed = 0; |
393 | 0 | Unity.CurrentTestIgnored = 0; |
394 | 0 | UNITY_PRINT_EOL(); |
395 | 0 | UNITY_FLUSH_CALL(); |
396 | 0 | } |
397 | | |
398 | | /*-----------------------------------------------*/ |
399 | | static void UnityAddMsgIfSpecified(const char* msg) |
400 | 0 | { |
401 | 0 | if (msg) |
402 | 0 | { |
403 | 0 | UnityPrint(UnityStrSpacer); |
404 | 0 | #ifndef UNITY_EXCLUDE_DETAILS |
405 | 0 | if (Unity.CurrentDetail1) |
406 | 0 | { |
407 | 0 | UnityPrint(UnityStrDetail1Name); |
408 | 0 | UnityPrint(Unity.CurrentDetail1); |
409 | 0 | if (Unity.CurrentDetail2) |
410 | 0 | { |
411 | 0 | UnityPrint(UnityStrDetail2Name); |
412 | 0 | UnityPrint(Unity.CurrentDetail2); |
413 | 0 | } |
414 | 0 | UnityPrint(UnityStrSpacer); |
415 | 0 | } |
416 | 0 | #endif |
417 | 0 | UnityPrint(msg); |
418 | 0 | } |
419 | 0 | } |
420 | | |
421 | | /*-----------------------------------------------*/ |
422 | | static void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual) |
423 | 0 | { |
424 | 0 | UnityPrint(UnityStrExpected); |
425 | 0 | if (expected != NULL) |
426 | 0 | { |
427 | 0 | UNITY_OUTPUT_CHAR('\''); |
428 | 0 | UnityPrint(expected); |
429 | 0 | UNITY_OUTPUT_CHAR('\''); |
430 | 0 | } |
431 | 0 | else |
432 | 0 | { |
433 | 0 | UnityPrint(UnityStrNull); |
434 | 0 | } |
435 | 0 | UnityPrint(UnityStrWas); |
436 | 0 | if (actual != NULL) |
437 | 0 | { |
438 | 0 | UNITY_OUTPUT_CHAR('\''); |
439 | 0 | UnityPrint(actual); |
440 | 0 | UNITY_OUTPUT_CHAR('\''); |
441 | 0 | } |
442 | 0 | else |
443 | 0 | { |
444 | 0 | UnityPrint(UnityStrNull); |
445 | 0 | } |
446 | 0 | } |
447 | | |
448 | | /*-----------------------------------------------*/ |
449 | | static void UnityPrintExpectedAndActualStringsLen(const char* expected, |
450 | | const char* actual, |
451 | | const UNITY_UINT32 length) |
452 | 0 | { |
453 | 0 | UnityPrint(UnityStrExpected); |
454 | 0 | if (expected != NULL) |
455 | 0 | { |
456 | 0 | UNITY_OUTPUT_CHAR('\''); |
457 | 0 | UnityPrintLen(expected, length); |
458 | 0 | UNITY_OUTPUT_CHAR('\''); |
459 | 0 | } |
460 | 0 | else |
461 | 0 | { |
462 | 0 | UnityPrint(UnityStrNull); |
463 | 0 | } |
464 | 0 | UnityPrint(UnityStrWas); |
465 | 0 | if (actual != NULL) |
466 | 0 | { |
467 | 0 | UNITY_OUTPUT_CHAR('\''); |
468 | 0 | UnityPrintLen(actual, length); |
469 | 0 | UNITY_OUTPUT_CHAR('\''); |
470 | 0 | } |
471 | 0 | else |
472 | 0 | { |
473 | 0 | UnityPrint(UnityStrNull); |
474 | 0 | } |
475 | 0 | } |
476 | | |
477 | | /*----------------------------------------------- |
478 | | * Assertion & Control Helpers |
479 | | *-----------------------------------------------*/ |
480 | | |
481 | | static int UnityIsOneArrayNull(UNITY_INTERNAL_PTR expected, |
482 | | UNITY_INTERNAL_PTR actual, |
483 | | const UNITY_LINE_TYPE lineNumber, |
484 | | const char* msg) |
485 | 0 | { |
486 | 0 | if (expected == actual) return 0; /* Both are NULL or same pointer */ |
487 | | |
488 | | /* print and return true if just expected is NULL */ |
489 | 0 | if (expected == NULL) |
490 | 0 | { |
491 | 0 | UnityTestResultsFailBegin(lineNumber); |
492 | 0 | UnityPrint(UnityStrNullPointerForExpected); |
493 | 0 | UnityAddMsgIfSpecified(msg); |
494 | 0 | return 1; |
495 | 0 | } |
496 | | |
497 | | /* print and return true if just actual is NULL */ |
498 | 0 | if (actual == NULL) |
499 | 0 | { |
500 | 0 | UnityTestResultsFailBegin(lineNumber); |
501 | 0 | UnityPrint(UnityStrNullPointerForActual); |
502 | 0 | UnityAddMsgIfSpecified(msg); |
503 | 0 | return 1; |
504 | 0 | } |
505 | | |
506 | 0 | return 0; /* return false if neither is NULL */ |
507 | 0 | } |
508 | | |
509 | | /*----------------------------------------------- |
510 | | * Assertion Functions |
511 | | *-----------------------------------------------*/ |
512 | | |
513 | | void UnityAssertBits(const UNITY_INT mask, |
514 | | const UNITY_INT expected, |
515 | | const UNITY_INT actual, |
516 | | const char* msg, |
517 | | const UNITY_LINE_TYPE lineNumber) |
518 | 0 | { |
519 | 0 | RETURN_IF_FAIL_OR_IGNORE; |
520 | | |
521 | 0 | if ((mask & expected) != (mask & actual)) |
522 | 0 | { |
523 | 0 | UnityTestResultsFailBegin(lineNumber); |
524 | 0 | UnityPrint(UnityStrExpected); |
525 | 0 | UnityPrintMask((UNITY_UINT)mask, (UNITY_UINT)expected); |
526 | 0 | UnityPrint(UnityStrWas); |
527 | 0 | UnityPrintMask((UNITY_UINT)mask, (UNITY_UINT)actual); |
528 | 0 | UnityAddMsgIfSpecified(msg); |
529 | 0 | UNITY_FAIL_AND_BAIL; |
530 | 0 | } |
531 | 0 | } |
532 | | |
533 | | /*-----------------------------------------------*/ |
534 | | void UnityAssertEqualNumber(const UNITY_INT expected, |
535 | | const UNITY_INT actual, |
536 | | const char* msg, |
537 | | const UNITY_LINE_TYPE lineNumber, |
538 | | const UNITY_DISPLAY_STYLE_T style) |
539 | 0 | { |
540 | 0 | RETURN_IF_FAIL_OR_IGNORE; |
541 | | |
542 | 0 | if (expected != actual) |
543 | 0 | { |
544 | 0 | UnityTestResultsFailBegin(lineNumber); |
545 | 0 | UnityPrint(UnityStrExpected); |
546 | 0 | UnityPrintNumberByStyle(expected, style); |
547 | 0 | UnityPrint(UnityStrWas); |
548 | 0 | UnityPrintNumberByStyle(actual, style); |
549 | 0 | UnityAddMsgIfSpecified(msg); |
550 | 0 | UNITY_FAIL_AND_BAIL; |
551 | 0 | } |
552 | 0 | } |
553 | | |
554 | | /*-----------------------------------------------*/ |
555 | | void UnityAssertGreaterOrLessOrEqualNumber(const UNITY_INT threshold, |
556 | | const UNITY_INT actual, |
557 | | const UNITY_COMPARISON_T compare, |
558 | | const char *msg, |
559 | | const UNITY_LINE_TYPE lineNumber, |
560 | | const UNITY_DISPLAY_STYLE_T style) |
561 | 1.58k | { |
562 | 1.58k | int failed = 0; |
563 | 1.58k | RETURN_IF_FAIL_OR_IGNORE; |
564 | | |
565 | 1.58k | if (threshold == actual && compare & UNITY_EQUAL_TO) return; |
566 | 1.58k | if (threshold == actual) failed = 1; |
567 | | |
568 | 1.58k | if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) |
569 | 1.58k | { |
570 | 1.58k | if (actual > threshold && compare & UNITY_SMALLER_THAN) failed = 1; |
571 | 1.58k | if (actual < threshold && compare & UNITY_GREATER_THAN) failed = 1; |
572 | 1.58k | } |
573 | 0 | else /* UINT or HEX */ |
574 | 0 | { |
575 | 0 | if ((UNITY_UINT)actual > (UNITY_UINT)threshold && compare & UNITY_SMALLER_THAN) failed = 1; |
576 | 0 | if ((UNITY_UINT)actual < (UNITY_UINT)threshold && compare & UNITY_GREATER_THAN) failed = 1; |
577 | 0 | } |
578 | | |
579 | 1.58k | if (failed) |
580 | 0 | { |
581 | 0 | UnityTestResultsFailBegin(lineNumber); |
582 | 0 | UnityPrint(UnityStrExpected); |
583 | 0 | UnityPrintNumberByStyle(actual, style); |
584 | 0 | if (compare & UNITY_GREATER_THAN) UnityPrint(UnityStrGt); |
585 | 0 | if (compare & UNITY_SMALLER_THAN) UnityPrint(UnityStrLt); |
586 | 0 | if (compare & UNITY_EQUAL_TO) UnityPrint(UnityStrOrEqual); |
587 | 0 | UnityPrintNumberByStyle(threshold, style); |
588 | 0 | UnityAddMsgIfSpecified(msg); |
589 | 0 | UNITY_FAIL_AND_BAIL; |
590 | 0 | } |
591 | 1.58k | } |
592 | | |
593 | 0 | #define UnityPrintPointlessAndBail() \ |
594 | 0 | { \ |
595 | 0 | UnityTestResultsFailBegin(lineNumber); \ |
596 | 0 | UnityPrint(UnityStrPointless); \ |
597 | 0 | UnityAddMsgIfSpecified(msg); \ |
598 | 0 | UNITY_FAIL_AND_BAIL; } |
599 | | |
600 | | /*-----------------------------------------------*/ |
601 | | void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, |
602 | | UNITY_INTERNAL_PTR actual, |
603 | | const UNITY_UINT32 num_elements, |
604 | | const char* msg, |
605 | | const UNITY_LINE_TYPE lineNumber, |
606 | | const UNITY_DISPLAY_STYLE_T style, |
607 | | const UNITY_FLAGS_T flags) |
608 | 0 | { |
609 | 0 | UNITY_UINT32 elements = num_elements; |
610 | 0 | unsigned int length = style & 0xF; |
611 | |
|
612 | 0 | RETURN_IF_FAIL_OR_IGNORE; |
613 | | |
614 | 0 | if (num_elements == 0) |
615 | 0 | { |
616 | 0 | UnityPrintPointlessAndBail(); |
617 | 0 | } |
618 | | |
619 | 0 | if (expected == actual) return; /* Both are NULL or same pointer */ |
620 | 0 | if (UnityIsOneArrayNull(expected, actual, lineNumber, msg)) |
621 | 0 | UNITY_FAIL_AND_BAIL; |
622 | |
|
623 | 0 | while ((elements > 0) && elements--) |
624 | 0 | { |
625 | 0 | UNITY_INT expect_val; |
626 | 0 | UNITY_INT actual_val; |
627 | 0 | switch (length) |
628 | 0 | { |
629 | 0 | case 1: |
630 | 0 | expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)expected; |
631 | 0 | actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)actual; |
632 | 0 | break; |
633 | 0 | case 2: |
634 | 0 | expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)expected; |
635 | 0 | actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)actual; |
636 | 0 | break; |
637 | 0 | #ifdef UNITY_SUPPORT_64 |
638 | 0 | case 8: |
639 | 0 | expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)expected; |
640 | 0 | actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)actual; |
641 | 0 | break; |
642 | 0 | #endif |
643 | 0 | default: /* length 4 bytes */ |
644 | 0 | expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)expected; |
645 | 0 | actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)actual; |
646 | 0 | length = 4; |
647 | 0 | break; |
648 | 0 | } |
649 | | |
650 | 0 | if (expect_val != actual_val) |
651 | 0 | { |
652 | 0 | if (style & UNITY_DISPLAY_RANGE_UINT && length < sizeof(expect_val)) |
653 | 0 | { /* For UINT, remove sign extension (padding 1's) from signed type casts above */ |
654 | 0 | UNITY_INT mask = 1; |
655 | 0 | mask = (mask << 8 * length) - 1; |
656 | 0 | expect_val &= mask; |
657 | 0 | actual_val &= mask; |
658 | 0 | } |
659 | 0 | UnityTestResultsFailBegin(lineNumber); |
660 | 0 | UnityPrint(UnityStrElement); |
661 | 0 | UnityPrintNumberUnsigned(num_elements - elements - 1); |
662 | 0 | UnityPrint(UnityStrExpected); |
663 | 0 | UnityPrintNumberByStyle(expect_val, style); |
664 | 0 | UnityPrint(UnityStrWas); |
665 | 0 | UnityPrintNumberByStyle(actual_val, style); |
666 | 0 | UnityAddMsgIfSpecified(msg); |
667 | 0 | UNITY_FAIL_AND_BAIL; |
668 | 0 | } |
669 | 0 | if (flags == UNITY_ARRAY_TO_ARRAY) |
670 | 0 | { |
671 | 0 | expected = (UNITY_INTERNAL_PTR)(length + (const char*)expected); |
672 | 0 | } |
673 | 0 | actual = (UNITY_INTERNAL_PTR)(length + (const char*)actual); |
674 | 0 | } |
675 | 0 | } |
676 | | |
677 | | /*-----------------------------------------------*/ |
678 | | #ifndef UNITY_EXCLUDE_FLOAT |
679 | | /* Wrap this define in a function with variable types as float or double */ |
680 | | #define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \ |
681 | 0 | if (isinf(expected) && isinf(actual) && ((expected < 0) == (actual < 0))) return 1; \ |
682 | 0 | if (UNITY_NAN_CHECK) return 1; \ |
683 | 0 | diff = actual - expected; \ |
684 | 0 | if (diff < 0) diff = -diff; \ |
685 | 0 | if (delta < 0) delta = -delta; \ |
686 | 0 | return !(isnan(diff) || isinf(diff) || (diff > delta)) |
687 | | /* This first part of this condition will catch any NaN or Infinite values */ |
688 | | #ifndef UNITY_NAN_NOT_EQUAL_NAN |
689 | 0 | #define UNITY_NAN_CHECK isnan(expected) && isnan(actual) |
690 | | #else |
691 | | #define UNITY_NAN_CHECK 0 |
692 | | #endif |
693 | | |
694 | | #ifndef UNITY_EXCLUDE_FLOAT_PRINT |
695 | | #define UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual) \ |
696 | 0 | { \ |
697 | 0 | UnityPrint(UnityStrExpected); \ |
698 | 0 | UnityPrintFloat(expected); \ |
699 | 0 | UnityPrint(UnityStrWas); \ |
700 | 0 | UnityPrintFloat(actual); } |
701 | | #else |
702 | | #define UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual) \ |
703 | | UnityPrint(UnityStrDelta) |
704 | | #endif /* UNITY_EXCLUDE_FLOAT_PRINT */ |
705 | | |
706 | | static int UnityFloatsWithin(UNITY_FLOAT delta, UNITY_FLOAT expected, UNITY_FLOAT actual) |
707 | 0 | { |
708 | 0 | UNITY_FLOAT diff; |
709 | 0 | UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff); |
710 | 0 | } |
711 | | |
712 | | void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* expected, |
713 | | UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* actual, |
714 | | const UNITY_UINT32 num_elements, |
715 | | const char* msg, |
716 | | const UNITY_LINE_TYPE lineNumber, |
717 | | const UNITY_FLAGS_T flags) |
718 | 0 | { |
719 | 0 | UNITY_UINT32 elements = num_elements; |
720 | 0 | UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* ptr_expected = expected; |
721 | 0 | UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* ptr_actual = actual; |
722 | |
|
723 | 0 | RETURN_IF_FAIL_OR_IGNORE; |
724 | | |
725 | 0 | if (elements == 0) |
726 | 0 | { |
727 | 0 | UnityPrintPointlessAndBail(); |
728 | 0 | } |
729 | | |
730 | 0 | if (expected == actual) return; /* Both are NULL or same pointer */ |
731 | 0 | if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg)) |
732 | 0 | UNITY_FAIL_AND_BAIL; |
733 | |
|
734 | 0 | while (elements--) |
735 | 0 | { |
736 | 0 | if (!UnityFloatsWithin(*ptr_expected * UNITY_FLOAT_PRECISION, *ptr_expected, *ptr_actual)) |
737 | 0 | { |
738 | 0 | UnityTestResultsFailBegin(lineNumber); |
739 | 0 | UnityPrint(UnityStrElement); |
740 | 0 | UnityPrintNumberUnsigned(num_elements - elements - 1); |
741 | 0 | UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT((UNITY_DOUBLE)*ptr_expected, (UNITY_DOUBLE)*ptr_actual); |
742 | 0 | UnityAddMsgIfSpecified(msg); |
743 | 0 | UNITY_FAIL_AND_BAIL; |
744 | 0 | } |
745 | 0 | if (flags == UNITY_ARRAY_TO_ARRAY) |
746 | 0 | { |
747 | 0 | ptr_expected++; |
748 | 0 | } |
749 | 0 | ptr_actual++; |
750 | 0 | } |
751 | 0 | } |
752 | | |
753 | | /*-----------------------------------------------*/ |
754 | | void UnityAssertFloatsWithin(const UNITY_FLOAT delta, |
755 | | const UNITY_FLOAT expected, |
756 | | const UNITY_FLOAT actual, |
757 | | const char* msg, |
758 | | const UNITY_LINE_TYPE lineNumber) |
759 | 0 | { |
760 | 0 | RETURN_IF_FAIL_OR_IGNORE; |
761 | | |
762 | | |
763 | 0 | if (!UnityFloatsWithin(delta, expected, actual)) |
764 | 0 | { |
765 | 0 | UnityTestResultsFailBegin(lineNumber); |
766 | 0 | UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT((UNITY_DOUBLE)expected, (UNITY_DOUBLE)actual); |
767 | 0 | UnityAddMsgIfSpecified(msg); |
768 | 0 | UNITY_FAIL_AND_BAIL; |
769 | 0 | } |
770 | 0 | } |
771 | | |
772 | | /*-----------------------------------------------*/ |
773 | | void UnityAssertFloatSpecial(const UNITY_FLOAT actual, |
774 | | const char* msg, |
775 | | const UNITY_LINE_TYPE lineNumber, |
776 | | const UNITY_FLOAT_TRAIT_T style) |
777 | 0 | { |
778 | 0 | const char* trait_names[] = {UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet}; |
779 | 0 | UNITY_INT should_be_trait = ((UNITY_INT)style & 1); |
780 | 0 | UNITY_INT is_trait = !should_be_trait; |
781 | 0 | UNITY_INT trait_index = (UNITY_INT)(style >> 1); |
782 | |
|
783 | 0 | RETURN_IF_FAIL_OR_IGNORE; |
784 | | |
785 | 0 | switch (style) |
786 | 0 | { |
787 | 0 | case UNITY_FLOAT_IS_INF: |
788 | 0 | case UNITY_FLOAT_IS_NOT_INF: |
789 | 0 | is_trait = isinf(actual) && (actual > 0); |
790 | 0 | break; |
791 | 0 | case UNITY_FLOAT_IS_NEG_INF: |
792 | 0 | case UNITY_FLOAT_IS_NOT_NEG_INF: |
793 | 0 | is_trait = isinf(actual) && (actual < 0); |
794 | 0 | break; |
795 | | |
796 | 0 | case UNITY_FLOAT_IS_NAN: |
797 | 0 | case UNITY_FLOAT_IS_NOT_NAN: |
798 | 0 | is_trait = isnan(actual) ? 1 : 0; |
799 | 0 | break; |
800 | | |
801 | 0 | case UNITY_FLOAT_IS_DET: /* A determinate number is non infinite and not NaN. */ |
802 | 0 | case UNITY_FLOAT_IS_NOT_DET: |
803 | 0 | is_trait = !isinf(actual) && !isnan(actual); |
804 | 0 | break; |
805 | | |
806 | 0 | default: |
807 | 0 | trait_index = 0; |
808 | 0 | trait_names[0] = UnityStrInvalidFloatTrait; |
809 | 0 | break; |
810 | 0 | } |
811 | | |
812 | 0 | if (is_trait != should_be_trait) |
813 | 0 | { |
814 | 0 | UnityTestResultsFailBegin(lineNumber); |
815 | 0 | UnityPrint(UnityStrExpected); |
816 | 0 | if (!should_be_trait) |
817 | 0 | UnityPrint(UnityStrNot); |
818 | 0 | UnityPrint(trait_names[trait_index]); |
819 | 0 | UnityPrint(UnityStrWas); |
820 | 0 | #ifndef UNITY_EXCLUDE_FLOAT_PRINT |
821 | 0 | UnityPrintFloat((UNITY_DOUBLE)actual); |
822 | | #else |
823 | | if (should_be_trait) |
824 | | UnityPrint(UnityStrNot); |
825 | | UnityPrint(trait_names[trait_index]); |
826 | | #endif |
827 | 0 | UnityAddMsgIfSpecified(msg); |
828 | 0 | UNITY_FAIL_AND_BAIL; |
829 | 0 | } |
830 | 0 | } |
831 | | |
832 | | #endif /* not UNITY_EXCLUDE_FLOAT */ |
833 | | |
834 | | /*-----------------------------------------------*/ |
835 | | #ifndef UNITY_EXCLUDE_DOUBLE |
836 | | static int UnityDoublesWithin(UNITY_DOUBLE delta, UNITY_DOUBLE expected, UNITY_DOUBLE actual) |
837 | | { |
838 | | UNITY_DOUBLE diff; |
839 | | UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff); |
840 | | } |
841 | | |
842 | | void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* expected, |
843 | | UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* actual, |
844 | | const UNITY_UINT32 num_elements, |
845 | | const char* msg, |
846 | | const UNITY_LINE_TYPE lineNumber, |
847 | | const UNITY_FLAGS_T flags) |
848 | | { |
849 | | UNITY_UINT32 elements = num_elements; |
850 | | UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* ptr_expected = expected; |
851 | | UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* ptr_actual = actual; |
852 | | |
853 | | RETURN_IF_FAIL_OR_IGNORE; |
854 | | |
855 | | if (elements == 0) |
856 | | { |
857 | | UnityPrintPointlessAndBail(); |
858 | | } |
859 | | |
860 | | if (expected == actual) return; /* Both are NULL or same pointer */ |
861 | | if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg)) |
862 | | UNITY_FAIL_AND_BAIL; |
863 | | |
864 | | while (elements--) |
865 | | { |
866 | | if (!UnityDoublesWithin(*ptr_expected * UNITY_DOUBLE_PRECISION, *ptr_expected, *ptr_actual)) |
867 | | { |
868 | | UnityTestResultsFailBegin(lineNumber); |
869 | | UnityPrint(UnityStrElement); |
870 | | UnityPrintNumberUnsigned(num_elements - elements - 1); |
871 | | UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(*ptr_expected, *ptr_actual); |
872 | | UnityAddMsgIfSpecified(msg); |
873 | | UNITY_FAIL_AND_BAIL; |
874 | | } |
875 | | if (flags == UNITY_ARRAY_TO_ARRAY) |
876 | | { |
877 | | ptr_expected++; |
878 | | } |
879 | | ptr_actual++; |
880 | | } |
881 | | } |
882 | | |
883 | | /*-----------------------------------------------*/ |
884 | | void UnityAssertDoublesWithin(const UNITY_DOUBLE delta, |
885 | | const UNITY_DOUBLE expected, |
886 | | const UNITY_DOUBLE actual, |
887 | | const char* msg, |
888 | | const UNITY_LINE_TYPE lineNumber) |
889 | | { |
890 | | RETURN_IF_FAIL_OR_IGNORE; |
891 | | |
892 | | if (!UnityDoublesWithin(delta, expected, actual)) |
893 | | { |
894 | | UnityTestResultsFailBegin(lineNumber); |
895 | | UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual); |
896 | | UnityAddMsgIfSpecified(msg); |
897 | | UNITY_FAIL_AND_BAIL; |
898 | | } |
899 | | } |
900 | | |
901 | | /*-----------------------------------------------*/ |
902 | | |
903 | | void UnityAssertDoubleSpecial(const UNITY_DOUBLE actual, |
904 | | const char* msg, |
905 | | const UNITY_LINE_TYPE lineNumber, |
906 | | const UNITY_FLOAT_TRAIT_T style) |
907 | | { |
908 | | const char* trait_names[] = {UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet}; |
909 | | UNITY_INT should_be_trait = ((UNITY_INT)style & 1); |
910 | | UNITY_INT is_trait = !should_be_trait; |
911 | | UNITY_INT trait_index = (UNITY_INT)(style >> 1); |
912 | | |
913 | | RETURN_IF_FAIL_OR_IGNORE; |
914 | | |
915 | | switch (style) |
916 | | { |
917 | | case UNITY_FLOAT_IS_INF: |
918 | | case UNITY_FLOAT_IS_NOT_INF: |
919 | | is_trait = isinf(actual) && (actual > 0); |
920 | | break; |
921 | | case UNITY_FLOAT_IS_NEG_INF: |
922 | | case UNITY_FLOAT_IS_NOT_NEG_INF: |
923 | | is_trait = isinf(actual) && (actual < 0); |
924 | | break; |
925 | | |
926 | | case UNITY_FLOAT_IS_NAN: |
927 | | case UNITY_FLOAT_IS_NOT_NAN: |
928 | | is_trait = isnan(actual) ? 1 : 0; |
929 | | break; |
930 | | |
931 | | case UNITY_FLOAT_IS_DET: /* A determinate number is non infinite and not NaN. */ |
932 | | case UNITY_FLOAT_IS_NOT_DET: |
933 | | is_trait = !isinf(actual) && !isnan(actual); |
934 | | break; |
935 | | |
936 | | default: |
937 | | trait_index = 0; |
938 | | trait_names[0] = UnityStrInvalidFloatTrait; |
939 | | break; |
940 | | } |
941 | | |
942 | | if (is_trait != should_be_trait) |
943 | | { |
944 | | UnityTestResultsFailBegin(lineNumber); |
945 | | UnityPrint(UnityStrExpected); |
946 | | if (!should_be_trait) |
947 | | UnityPrint(UnityStrNot); |
948 | | UnityPrint(trait_names[trait_index]); |
949 | | UnityPrint(UnityStrWas); |
950 | | #ifndef UNITY_EXCLUDE_FLOAT_PRINT |
951 | | UnityPrintFloat(actual); |
952 | | #else |
953 | | if (should_be_trait) |
954 | | UnityPrint(UnityStrNot); |
955 | | UnityPrint(trait_names[trait_index]); |
956 | | #endif |
957 | | UnityAddMsgIfSpecified(msg); |
958 | | UNITY_FAIL_AND_BAIL; |
959 | | } |
960 | | } |
961 | | |
962 | | #endif /* not UNITY_EXCLUDE_DOUBLE */ |
963 | | |
964 | | /*-----------------------------------------------*/ |
965 | | void UnityAssertNumbersWithin(const UNITY_UINT delta, |
966 | | const UNITY_INT expected, |
967 | | const UNITY_INT actual, |
968 | | const char* msg, |
969 | | const UNITY_LINE_TYPE lineNumber, |
970 | | const UNITY_DISPLAY_STYLE_T style) |
971 | 0 | { |
972 | 0 | RETURN_IF_FAIL_OR_IGNORE; |
973 | | |
974 | 0 | if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) |
975 | 0 | { |
976 | 0 | if (actual > expected) |
977 | 0 | Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta); |
978 | 0 | else |
979 | 0 | Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(expected - actual) > delta); |
980 | 0 | } |
981 | 0 | else |
982 | 0 | { |
983 | 0 | if ((UNITY_UINT)actual > (UNITY_UINT)expected) |
984 | 0 | Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(actual - expected) > delta); |
985 | 0 | else |
986 | 0 | Unity.CurrentTestFailed = (UNITY_UINT)((UNITY_UINT)(expected - actual) > delta); |
987 | 0 | } |
988 | |
|
989 | 0 | if (Unity.CurrentTestFailed) |
990 | 0 | { |
991 | 0 | UnityTestResultsFailBegin(lineNumber); |
992 | 0 | UnityPrint(UnityStrDelta); |
993 | 0 | UnityPrintNumberByStyle((UNITY_INT)delta, style); |
994 | 0 | UnityPrint(UnityStrExpected); |
995 | 0 | UnityPrintNumberByStyle(expected, style); |
996 | 0 | UnityPrint(UnityStrWas); |
997 | 0 | UnityPrintNumberByStyle(actual, style); |
998 | 0 | UnityAddMsgIfSpecified(msg); |
999 | 0 | UNITY_FAIL_AND_BAIL; |
1000 | 0 | } |
1001 | 0 | } |
1002 | | |
1003 | | /*-----------------------------------------------*/ |
1004 | | void UnityAssertEqualString(const char* expected, |
1005 | | const char* actual, |
1006 | | const char* msg, |
1007 | | const UNITY_LINE_TYPE lineNumber) |
1008 | 0 | { |
1009 | 0 | UNITY_UINT32 i; |
1010 | |
|
1011 | 0 | RETURN_IF_FAIL_OR_IGNORE; |
1012 | | |
1013 | | /* if both pointers not null compare the strings */ |
1014 | 0 | if (expected && actual) |
1015 | 0 | { |
1016 | 0 | for (i = 0; expected[i] || actual[i]; i++) |
1017 | 0 | { |
1018 | 0 | if (expected[i] != actual[i]) |
1019 | 0 | { |
1020 | 0 | Unity.CurrentTestFailed = 1; |
1021 | 0 | break; |
1022 | 0 | } |
1023 | 0 | } |
1024 | 0 | } |
1025 | 0 | else |
1026 | 0 | { /* handle case of one pointers being null (if both null, test should pass) */ |
1027 | 0 | if (expected != actual) |
1028 | 0 | { |
1029 | 0 | Unity.CurrentTestFailed = 1; |
1030 | 0 | } |
1031 | 0 | } |
1032 | |
|
1033 | 0 | if (Unity.CurrentTestFailed) |
1034 | 0 | { |
1035 | 0 | UnityTestResultsFailBegin(lineNumber); |
1036 | 0 | UnityPrintExpectedAndActualStrings(expected, actual); |
1037 | 0 | UnityAddMsgIfSpecified(msg); |
1038 | 0 | UNITY_FAIL_AND_BAIL; |
1039 | 0 | } |
1040 | 0 | } |
1041 | | |
1042 | | /*-----------------------------------------------*/ |
1043 | | void UnityAssertEqualStringLen(const char* expected, |
1044 | | const char* actual, |
1045 | | const UNITY_UINT32 length, |
1046 | | const char* msg, |
1047 | | const UNITY_LINE_TYPE lineNumber) |
1048 | 0 | { |
1049 | 0 | UNITY_UINT32 i; |
1050 | |
|
1051 | 0 | RETURN_IF_FAIL_OR_IGNORE; |
1052 | | |
1053 | | /* if both pointers not null compare the strings */ |
1054 | 0 | if (expected && actual) |
1055 | 0 | { |
1056 | 0 | for (i = 0; (i < length) && (expected[i] || actual[i]); i++) |
1057 | 0 | { |
1058 | 0 | if (expected[i] != actual[i]) |
1059 | 0 | { |
1060 | 0 | Unity.CurrentTestFailed = 1; |
1061 | 0 | break; |
1062 | 0 | } |
1063 | 0 | } |
1064 | 0 | } |
1065 | 0 | else |
1066 | 0 | { /* handle case of one pointers being null (if both null, test should pass) */ |
1067 | 0 | if (expected != actual) |
1068 | 0 | { |
1069 | 0 | Unity.CurrentTestFailed = 1; |
1070 | 0 | } |
1071 | 0 | } |
1072 | |
|
1073 | 0 | if (Unity.CurrentTestFailed) |
1074 | 0 | { |
1075 | 0 | UnityTestResultsFailBegin(lineNumber); |
1076 | 0 | UnityPrintExpectedAndActualStringsLen(expected, actual, length); |
1077 | 0 | UnityAddMsgIfSpecified(msg); |
1078 | 0 | UNITY_FAIL_AND_BAIL; |
1079 | 0 | } |
1080 | 0 | } |
1081 | | |
1082 | | /*-----------------------------------------------*/ |
1083 | | void UnityAssertEqualStringArray(UNITY_INTERNAL_PTR expected, |
1084 | | const char** actual, |
1085 | | const UNITY_UINT32 num_elements, |
1086 | | const char* msg, |
1087 | | const UNITY_LINE_TYPE lineNumber, |
1088 | | const UNITY_FLAGS_T flags) |
1089 | 0 | { |
1090 | 0 | UNITY_UINT32 i = 0; |
1091 | 0 | UNITY_UINT32 j = 0; |
1092 | 0 | const char* expd = NULL; |
1093 | 0 | const char* act = NULL; |
1094 | |
|
1095 | 0 | RETURN_IF_FAIL_OR_IGNORE; |
1096 | | |
1097 | | /* if no elements, it's an error */ |
1098 | 0 | if (num_elements == 0) |
1099 | 0 | { |
1100 | 0 | UnityPrintPointlessAndBail(); |
1101 | 0 | } |
1102 | | |
1103 | 0 | if ((const void*)expected == (const void*)actual) |
1104 | 0 | { |
1105 | 0 | return; /* Both are NULL or same pointer */ |
1106 | 0 | } |
1107 | | |
1108 | 0 | if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg)) |
1109 | 0 | { |
1110 | 0 | UNITY_FAIL_AND_BAIL; |
1111 | 0 | } |
1112 | | |
1113 | 0 | if (flags != UNITY_ARRAY_TO_ARRAY) |
1114 | 0 | { |
1115 | 0 | expd = (const char*)expected; |
1116 | 0 | } |
1117 | |
|
1118 | 0 | do |
1119 | 0 | { |
1120 | 0 | act = actual[j]; |
1121 | 0 | if (flags == UNITY_ARRAY_TO_ARRAY) |
1122 | 0 | { |
1123 | 0 | expd = ((const char* const*)expected)[j]; |
1124 | 0 | } |
1125 | | |
1126 | | /* if both pointers not null compare the strings */ |
1127 | 0 | if (expd && act) |
1128 | 0 | { |
1129 | 0 | for (i = 0; expd[i] || act[i]; i++) |
1130 | 0 | { |
1131 | 0 | if (expd[i] != act[i]) |
1132 | 0 | { |
1133 | 0 | Unity.CurrentTestFailed = 1; |
1134 | 0 | break; |
1135 | 0 | } |
1136 | 0 | } |
1137 | 0 | } |
1138 | 0 | else |
1139 | 0 | { /* handle case of one pointers being null (if both null, test should pass) */ |
1140 | 0 | if (expd != act) |
1141 | 0 | { |
1142 | 0 | Unity.CurrentTestFailed = 1; |
1143 | 0 | } |
1144 | 0 | } |
1145 | |
|
1146 | 0 | if (Unity.CurrentTestFailed) |
1147 | 0 | { |
1148 | 0 | UnityTestResultsFailBegin(lineNumber); |
1149 | 0 | if (num_elements > 1) |
1150 | 0 | { |
1151 | 0 | UnityPrint(UnityStrElement); |
1152 | 0 | UnityPrintNumberUnsigned(j); |
1153 | 0 | } |
1154 | 0 | UnityPrintExpectedAndActualStrings(expd, act); |
1155 | 0 | UnityAddMsgIfSpecified(msg); |
1156 | 0 | UNITY_FAIL_AND_BAIL; |
1157 | 0 | } |
1158 | 0 | } while (++j < num_elements); |
1159 | 0 | } |
1160 | | |
1161 | | /*-----------------------------------------------*/ |
1162 | | void UnityAssertEqualMemory(UNITY_INTERNAL_PTR expected, |
1163 | | UNITY_INTERNAL_PTR actual, |
1164 | | const UNITY_UINT32 length, |
1165 | | const UNITY_UINT32 num_elements, |
1166 | | const char* msg, |
1167 | | const UNITY_LINE_TYPE lineNumber, |
1168 | | const UNITY_FLAGS_T flags) |
1169 | 0 | { |
1170 | 0 | UNITY_PTR_ATTRIBUTE const unsigned char* ptr_exp = (UNITY_PTR_ATTRIBUTE const unsigned char*)expected; |
1171 | 0 | UNITY_PTR_ATTRIBUTE const unsigned char* ptr_act = (UNITY_PTR_ATTRIBUTE const unsigned char*)actual; |
1172 | 0 | UNITY_UINT32 elements = num_elements; |
1173 | 0 | UNITY_UINT32 bytes; |
1174 | |
|
1175 | 0 | RETURN_IF_FAIL_OR_IGNORE; |
1176 | | |
1177 | 0 | if ((elements == 0) || (length == 0)) |
1178 | 0 | { |
1179 | 0 | UnityPrintPointlessAndBail(); |
1180 | 0 | } |
1181 | | |
1182 | 0 | if (expected == actual) return; /* Both are NULL or same pointer */ |
1183 | 0 | if (UnityIsOneArrayNull(expected, actual, lineNumber, msg)) |
1184 | 0 | UNITY_FAIL_AND_BAIL; |
1185 | |
|
1186 | 0 | while (elements--) |
1187 | 0 | { |
1188 | 0 | bytes = length; |
1189 | 0 | while (bytes--) |
1190 | 0 | { |
1191 | 0 | if (*ptr_exp != *ptr_act) |
1192 | 0 | { |
1193 | 0 | UnityTestResultsFailBegin(lineNumber); |
1194 | 0 | UnityPrint(UnityStrMemory); |
1195 | 0 | if (num_elements > 1) |
1196 | 0 | { |
1197 | 0 | UnityPrint(UnityStrElement); |
1198 | 0 | UnityPrintNumberUnsigned(num_elements - elements - 1); |
1199 | 0 | } |
1200 | 0 | UnityPrint(UnityStrByte); |
1201 | 0 | UnityPrintNumberUnsigned(length - bytes - 1); |
1202 | 0 | UnityPrint(UnityStrExpected); |
1203 | 0 | UnityPrintNumberByStyle(*ptr_exp, UNITY_DISPLAY_STYLE_HEX8); |
1204 | 0 | UnityPrint(UnityStrWas); |
1205 | 0 | UnityPrintNumberByStyle(*ptr_act, UNITY_DISPLAY_STYLE_HEX8); |
1206 | 0 | UnityAddMsgIfSpecified(msg); |
1207 | 0 | UNITY_FAIL_AND_BAIL; |
1208 | 0 | } |
1209 | 0 | ptr_exp++; |
1210 | 0 | ptr_act++; |
1211 | 0 | } |
1212 | 0 | if (flags == UNITY_ARRAY_TO_VAL) |
1213 | 0 | { |
1214 | 0 | ptr_exp = (UNITY_PTR_ATTRIBUTE const unsigned char*)expected; |
1215 | 0 | } |
1216 | 0 | } |
1217 | 0 | } |
1218 | | |
1219 | | /*-----------------------------------------------*/ |
1220 | | |
1221 | | static union |
1222 | | { |
1223 | | UNITY_INT8 i8; |
1224 | | UNITY_INT16 i16; |
1225 | | UNITY_INT32 i32; |
1226 | | #ifdef UNITY_SUPPORT_64 |
1227 | | UNITY_INT64 i64; |
1228 | | #endif |
1229 | | #ifndef UNITY_EXCLUDE_FLOAT |
1230 | | float f; |
1231 | | #endif |
1232 | | #ifndef UNITY_EXCLUDE_DOUBLE |
1233 | | double d; |
1234 | | #endif |
1235 | | } UnityQuickCompare; |
1236 | | |
1237 | | UNITY_INTERNAL_PTR UnityNumToPtr(const UNITY_INT num, const UNITY_UINT8 size) |
1238 | 0 | { |
1239 | 0 | switch(size) |
1240 | 0 | { |
1241 | 0 | case 1: |
1242 | 0 | UnityQuickCompare.i8 = (UNITY_INT8)num; |
1243 | 0 | return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i8); |
1244 | | |
1245 | 0 | case 2: |
1246 | 0 | UnityQuickCompare.i16 = (UNITY_INT16)num; |
1247 | 0 | return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i16); |
1248 | | |
1249 | 0 | #ifdef UNITY_SUPPORT_64 |
1250 | 0 | case 8: |
1251 | 0 | UnityQuickCompare.i64 = (UNITY_INT64)num; |
1252 | 0 | return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i64); |
1253 | 0 | #endif |
1254 | 0 | default: /* 4 bytes */ |
1255 | 0 | UnityQuickCompare.i32 = (UNITY_INT32)num; |
1256 | 0 | return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i32); |
1257 | 0 | } |
1258 | 0 | } |
1259 | | |
1260 | | #ifndef UNITY_EXCLUDE_FLOAT |
1261 | | UNITY_INTERNAL_PTR UnityFloatToPtr(const float num) |
1262 | 0 | { |
1263 | 0 | UnityQuickCompare.f = num; |
1264 | 0 | return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.f); |
1265 | 0 | } |
1266 | | #endif |
1267 | | |
1268 | | #ifndef UNITY_EXCLUDE_DOUBLE |
1269 | | UNITY_INTERNAL_PTR UnityDoubleToPtr(const double num) |
1270 | | { |
1271 | | UnityQuickCompare.d = num; |
1272 | | return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.d); |
1273 | | } |
1274 | | #endif |
1275 | | |
1276 | | /*----------------------------------------------- |
1277 | | * Control Functions |
1278 | | *-----------------------------------------------*/ |
1279 | | |
1280 | | void UnityFail(const char* msg, const UNITY_LINE_TYPE line) |
1281 | 0 | { |
1282 | 0 | RETURN_IF_FAIL_OR_IGNORE; |
1283 | | |
1284 | 0 | UnityTestResultsBegin(Unity.TestFile, line); |
1285 | 0 | UnityPrint(UnityStrFail); |
1286 | 0 | if (msg != NULL) |
1287 | 0 | { |
1288 | 0 | UNITY_OUTPUT_CHAR(':'); |
1289 | |
|
1290 | 0 | #ifndef UNITY_EXCLUDE_DETAILS |
1291 | 0 | if (Unity.CurrentDetail1) |
1292 | 0 | { |
1293 | 0 | UnityPrint(UnityStrDetail1Name); |
1294 | 0 | UnityPrint(Unity.CurrentDetail1); |
1295 | 0 | if (Unity.CurrentDetail2) |
1296 | 0 | { |
1297 | 0 | UnityPrint(UnityStrDetail2Name); |
1298 | 0 | UnityPrint(Unity.CurrentDetail2); |
1299 | 0 | } |
1300 | 0 | UnityPrint(UnityStrSpacer); |
1301 | 0 | } |
1302 | 0 | #endif |
1303 | 0 | if (msg[0] != ' ') |
1304 | 0 | { |
1305 | 0 | UNITY_OUTPUT_CHAR(' '); |
1306 | 0 | } |
1307 | 0 | UnityPrint(msg); |
1308 | 0 | } |
1309 | |
|
1310 | 0 | UNITY_FAIL_AND_BAIL; |
1311 | 0 | } |
1312 | | |
1313 | | /*-----------------------------------------------*/ |
1314 | | void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line) |
1315 | 0 | { |
1316 | 0 | RETURN_IF_FAIL_OR_IGNORE; |
1317 | | |
1318 | 0 | UnityTestResultsBegin(Unity.TestFile, line); |
1319 | 0 | UnityPrint(UnityStrIgnore); |
1320 | 0 | if (msg != NULL) |
1321 | 0 | { |
1322 | 0 | UNITY_OUTPUT_CHAR(':'); |
1323 | 0 | UNITY_OUTPUT_CHAR(' '); |
1324 | 0 | UnityPrint(msg); |
1325 | 0 | } |
1326 | 0 | UNITY_IGNORE_AND_BAIL; |
1327 | 0 | } |
1328 | | |
1329 | | /*-----------------------------------------------*/ |
1330 | | void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum) |
1331 | 0 | { |
1332 | 0 | Unity.CurrentTestName = FuncName; |
1333 | 0 | Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)FuncLineNum; |
1334 | 0 | Unity.NumberOfTests++; |
1335 | 0 | UNITY_CLR_DETAILS(); |
1336 | 0 | if (TEST_PROTECT()) |
1337 | 0 | { |
1338 | 0 | setUp(); |
1339 | 0 | Func(); |
1340 | 0 | } |
1341 | 0 | if (TEST_PROTECT()) |
1342 | 0 | { |
1343 | 0 | tearDown(); |
1344 | 0 | } |
1345 | 0 | UnityConcludeTest(); |
1346 | 0 | } |
1347 | | |
1348 | | /*-----------------------------------------------*/ |
1349 | | void UnityBegin(const char* filename) |
1350 | 0 | { |
1351 | 0 | Unity.TestFile = filename; |
1352 | 0 | Unity.CurrentTestName = NULL; |
1353 | 0 | Unity.CurrentTestLineNumber = 0; |
1354 | 0 | Unity.NumberOfTests = 0; |
1355 | 0 | Unity.TestFailures = 0; |
1356 | 0 | Unity.TestIgnores = 0; |
1357 | 0 | Unity.CurrentTestFailed = 0; |
1358 | 0 | Unity.CurrentTestIgnored = 0; |
1359 | |
|
1360 | 0 | UNITY_CLR_DETAILS(); |
1361 | 0 | UNITY_OUTPUT_START(); |
1362 | 0 | } |
1363 | | |
1364 | | /*-----------------------------------------------*/ |
1365 | | int UnityEnd(void) |
1366 | 0 | { |
1367 | 0 | UNITY_PRINT_EOL(); |
1368 | 0 | UnityPrint(UnityStrBreaker); |
1369 | 0 | UNITY_PRINT_EOL(); |
1370 | 0 | UnityPrintNumber((UNITY_INT)(Unity.NumberOfTests)); |
1371 | 0 | UnityPrint(UnityStrResultsTests); |
1372 | 0 | UnityPrintNumber((UNITY_INT)(Unity.TestFailures)); |
1373 | 0 | UnityPrint(UnityStrResultsFailures); |
1374 | 0 | UnityPrintNumber((UNITY_INT)(Unity.TestIgnores)); |
1375 | 0 | UnityPrint(UnityStrResultsIgnored); |
1376 | 0 | UNITY_PRINT_EOL(); |
1377 | 0 | if (Unity.TestFailures == 0U) |
1378 | 0 | { |
1379 | 0 | UnityPrint(UnityStrOk); |
1380 | 0 | } |
1381 | 0 | else |
1382 | 0 | { |
1383 | 0 | UnityPrint(UnityStrFail); |
1384 | | #ifdef UNITY_DIFFERENTIATE_FINAL_FAIL |
1385 | | UNITY_OUTPUT_CHAR('E'); UNITY_OUTPUT_CHAR('D'); |
1386 | | #endif |
1387 | 0 | } |
1388 | 0 | UNITY_PRINT_EOL(); |
1389 | 0 | UNITY_FLUSH_CALL(); |
1390 | 0 | UNITY_OUTPUT_COMPLETE(); |
1391 | 0 | return (int)(Unity.TestFailures); |
1392 | 0 | } |
1393 | | |
1394 | | /*----------------------------------------------- |
1395 | | * Command Line Argument Support |
1396 | | *-----------------------------------------------*/ |
1397 | | #ifdef UNITY_USE_COMMAND_LINE_ARGS |
1398 | | |
1399 | | char* UnityOptionIncludeNamed = NULL; |
1400 | | char* UnityOptionExcludeNamed = NULL; |
1401 | | int UnityVerbosity = 1; |
1402 | | |
1403 | | int UnityParseOptions(int argc, char** argv) |
1404 | | { |
1405 | | UnityOptionIncludeNamed = NULL; |
1406 | | UnityOptionExcludeNamed = NULL; |
1407 | | |
1408 | | for (int i = 1; i < argc; i++) |
1409 | | { |
1410 | | if (argv[i][0] == '-') |
1411 | | { |
1412 | | switch (argv[i][1]) |
1413 | | { |
1414 | | case 'l': /* list tests */ |
1415 | | return -1; |
1416 | | case 'n': /* include tests with name including this string */ |
1417 | | case 'f': /* an alias for -n */ |
1418 | | if (argv[i][2] == '=') |
1419 | | UnityOptionIncludeNamed = &argv[i][3]; |
1420 | | else if (++i < argc) |
1421 | | UnityOptionIncludeNamed = argv[i]; |
1422 | | else |
1423 | | { |
1424 | | UnityPrint("ERROR: No Test String to Include Matches For"); |
1425 | | UNITY_PRINT_EOL(); |
1426 | | return 1; |
1427 | | } |
1428 | | break; |
1429 | | case 'q': /* quiet */ |
1430 | | UnityVerbosity = 0; |
1431 | | break; |
1432 | | case 'v': /* verbose */ |
1433 | | UnityVerbosity = 2; |
1434 | | break; |
1435 | | case 'x': /* exclude tests with name including this string */ |
1436 | | if (argv[i][2] == '=') |
1437 | | UnityOptionExcludeNamed = &argv[i][3]; |
1438 | | else if (++i < argc) |
1439 | | UnityOptionExcludeNamed = argv[i]; |
1440 | | else |
1441 | | { |
1442 | | UnityPrint("ERROR: No Test String to Exclude Matches For"); |
1443 | | UNITY_PRINT_EOL(); |
1444 | | return 1; |
1445 | | } |
1446 | | break; |
1447 | | default: |
1448 | | UnityPrint("ERROR: Unknown Option "); |
1449 | | UNITY_OUTPUT_CHAR(argv[i][1]); |
1450 | | UNITY_PRINT_EOL(); |
1451 | | return 1; |
1452 | | } |
1453 | | } |
1454 | | } |
1455 | | |
1456 | | return 0; |
1457 | | } |
1458 | | |
1459 | | int IsStringInBiggerString(const char* longstring, const char* shortstring) |
1460 | | { |
1461 | | const char* lptr = longstring; |
1462 | | const char* sptr = shortstring; |
1463 | | const char* lnext = lptr; |
1464 | | |
1465 | | if (*sptr == '*') |
1466 | | return 1; |
1467 | | |
1468 | | while (*lptr) |
1469 | | { |
1470 | | lnext = lptr + 1; |
1471 | | |
1472 | | /* If they current bytes match, go on to the next bytes */ |
1473 | | while (*lptr && *sptr && (*lptr == *sptr)) |
1474 | | { |
1475 | | lptr++; |
1476 | | sptr++; |
1477 | | |
1478 | | /* We're done if we match the entire string or up to a wildcard */ |
1479 | | if (*sptr == '*') |
1480 | | return 1; |
1481 | | if (*sptr == ',') |
1482 | | return 1; |
1483 | | if (*sptr == '"') |
1484 | | return 1; |
1485 | | if (*sptr == '\'') |
1486 | | return 1; |
1487 | | if (*sptr == ':') |
1488 | | return 2; |
1489 | | if (*sptr == 0) |
1490 | | return 1; |
1491 | | } |
1492 | | |
1493 | | /* Otherwise we start in the long pointer 1 character further and try again */ |
1494 | | lptr = lnext; |
1495 | | sptr = shortstring; |
1496 | | } |
1497 | | return 0; |
1498 | | } |
1499 | | |
1500 | | int UnityStringArgumentMatches(const char* str) |
1501 | | { |
1502 | | int retval; |
1503 | | const char* ptr1; |
1504 | | const char* ptr2; |
1505 | | const char* ptrf; |
1506 | | |
1507 | | /* Go through the options and get the substrings for matching one at a time */ |
1508 | | ptr1 = str; |
1509 | | while (ptr1[0] != 0) |
1510 | | { |
1511 | | if ((ptr1[0] == '"') || (ptr1[0] == '\'')) |
1512 | | ptr1++; |
1513 | | |
1514 | | /* look for the start of the next partial */ |
1515 | | ptr2 = ptr1; |
1516 | | ptrf = 0; |
1517 | | do |
1518 | | { |
1519 | | ptr2++; |
1520 | | if ((ptr2[0] == ':') && (ptr2[1] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ',')) |
1521 | | ptrf = &ptr2[1]; |
1522 | | } while ((ptr2[0] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ',')); |
1523 | | while ((ptr2[0] != 0) && ((ptr2[0] == ':') || (ptr2[0] == '\'') || (ptr2[0] == '"') || (ptr2[0] == ','))) |
1524 | | ptr2++; |
1525 | | |
1526 | | /* done if complete filename match */ |
1527 | | retval = IsStringInBiggerString(Unity.TestFile, ptr1); |
1528 | | if (retval == 1) |
1529 | | return retval; |
1530 | | |
1531 | | /* done if testname match after filename partial match */ |
1532 | | if ((retval == 2) && (ptrf != 0)) |
1533 | | { |
1534 | | if (IsStringInBiggerString(Unity.CurrentTestName, ptrf)) |
1535 | | return 1; |
1536 | | } |
1537 | | |
1538 | | /* done if complete testname match */ |
1539 | | if (IsStringInBiggerString(Unity.CurrentTestName, ptr1) == 1) |
1540 | | return 1; |
1541 | | |
1542 | | ptr1 = ptr2; |
1543 | | } |
1544 | | |
1545 | | /* we couldn't find a match for any substrings */ |
1546 | | return 0; |
1547 | | } |
1548 | | |
1549 | | int UnityTestMatches(void) |
1550 | | { |
1551 | | /* Check if this test name matches the included test pattern */ |
1552 | | int retval; |
1553 | | if (UnityOptionIncludeNamed) |
1554 | | { |
1555 | | retval = UnityStringArgumentMatches(UnityOptionIncludeNamed); |
1556 | | } |
1557 | | else |
1558 | | retval = 1; |
1559 | | |
1560 | | /* Check if this test name matches the excluded test pattern */ |
1561 | | if (UnityOptionExcludeNamed) |
1562 | | { |
1563 | | if (UnityStringArgumentMatches(UnityOptionExcludeNamed)) |
1564 | | retval = 0; |
1565 | | } |
1566 | | return retval; |
1567 | | } |
1568 | | |
1569 | | #endif /* UNITY_USE_COMMAND_LINE_ARGS */ |
1570 | | /*-----------------------------------------------*/ |