c_project 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +29 -0
  6. data/Rakefile +18 -0
  7. data/bin/c_project +77 -0
  8. data/c_project.gemspec +25 -0
  9. data/lib/c_project/version.rb +3 -0
  10. data/lib/c_project.rb +5 -0
  11. data/templates/LICENCE.tt +23 -0
  12. data/templates/Makefile.tt +74 -0
  13. data/templates/README.md.tt +15 -0
  14. data/templates/src/CExceptionConfig.h.tt +8 -0
  15. data/templates/src/c_project.c.tt +16 -0
  16. data/templates/src/c_project.h.tt +8 -0
  17. data/templates/src/main.c.tt +15 -0
  18. data/templates/test/support/test_helper.c.tt +2 -0
  19. data/templates/test/support/test_helper.h.tt +13 -0
  20. data/templates/test/test_c_project.c.tt +41 -0
  21. data/templates/vendor/cexception/docs/license.txt +30 -0
  22. data/templates/vendor/cexception/docs/readme.txt +242 -0
  23. data/templates/vendor/cexception/lib/CException.c +43 -0
  24. data/templates/vendor/cexception/lib/CException.h +86 -0
  25. data/templates/vendor/cexception/release/build.info +2 -0
  26. data/templates/vendor/cexception/release/version.info +2 -0
  27. data/templates/vendor/commander.c/History.md +27 -0
  28. data/templates/vendor/commander.c/Makefile +8 -0
  29. data/templates/vendor/commander.c/Readme.md +103 -0
  30. data/templates/vendor/commander.c/package.json +9 -0
  31. data/templates/vendor/commander.c/src/commander.c +250 -0
  32. data/templates/vendor/commander.c/src/commander.h +88 -0
  33. data/templates/vendor/commander.c/test.c +34 -0
  34. data/templates/vendor/unity/.gitignore +1 -0
  35. data/templates/vendor/unity/auto/colour_prompt.rb +94 -0
  36. data/templates/vendor/unity/auto/colour_reporter.rb +39 -0
  37. data/templates/vendor/unity/auto/generate_config.yml +36 -0
  38. data/templates/vendor/unity/auto/generate_module.rb +202 -0
  39. data/templates/vendor/unity/auto/generate_test_runner.rb +316 -0
  40. data/templates/vendor/unity/auto/test_file_filter.rb +23 -0
  41. data/templates/vendor/unity/auto/unity_test_summary.rb +139 -0
  42. data/templates/vendor/unity/docs/Unity Summary.txt +216 -0
  43. data/templates/vendor/unity/docs/license.txt +31 -0
  44. data/templates/vendor/unity/release/build.info +2 -0
  45. data/templates/vendor/unity/release/version.info +2 -0
  46. data/templates/vendor/unity/src/unity.c +1146 -0
  47. data/templates/vendor/unity/src/unity.h +245 -0
  48. data/templates/vendor/unity/src/unity_internals.h +546 -0
  49. metadata +135 -0
@@ -0,0 +1,1146 @@
1
+ /* ==========================================
2
+ Unity Project - A Test Framework for C
3
+ Copyright (c) 2007 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 <stdio.h>
9
+ #include <string.h>
10
+
11
+ #define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
12
+ #define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
13
+ /// return prematurely if we are already in failure or ignore state
14
+ #define UNITY_SKIP_EXECUTION { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} }
15
+ #define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\n'); }
16
+
17
+ struct _Unity Unity = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , { 0 } };
18
+
19
+ const char* UnityStrNull = "NULL";
20
+ const char* UnityStrSpacer = ". ";
21
+ const char* UnityStrExpected = " Expected ";
22
+ const char* UnityStrWas = " Was ";
23
+ const char* UnityStrTo = " To ";
24
+ const char* UnityStrElement = " Element ";
25
+ const char* UnityStrByte = " Byte ";
26
+ const char* UnityStrMemory = " Memory Mismatch.";
27
+ const char* UnityStrDelta = " Values Not Within Delta ";
28
+ const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless.";
29
+ const char* UnityStrNullPointerForExpected= " Expected pointer to be NULL";
30
+ const char* UnityStrNullPointerForActual = " Actual pointer was NULL";
31
+ const char* UnityStrInf = "Infinity";
32
+ const char* UnityStrNegInf = "Negative Infinity";
33
+ const char* UnityStrNaN = "NaN";
34
+
35
+ #ifndef UNITY_EXCLUDE_FLOAT
36
+ // Dividing by these constants produces +/- infinity.
37
+ // The rationale is given in UnityAssertFloatIsInf's body.
38
+ static const _UF f_zero = 0.0f;
39
+ #ifndef UNITY_EXCLUDE_DOUBLE
40
+ static const _UD d_zero = 0.0;
41
+ #endif
42
+ #endif
43
+
44
+ // compiler-generic print formatting masks
45
+ const _U_UINT UnitySizeMask[] =
46
+ {
47
+ 255u, // 0xFF
48
+ 65535u, // 0xFFFF
49
+ 65535u,
50
+ 4294967295u, // 0xFFFFFFFF
51
+ 4294967295u,
52
+ 4294967295u,
53
+ 4294967295u
54
+ #ifdef UNITY_SUPPORT_64
55
+ ,0xFFFFFFFFFFFFFFFF
56
+ #endif
57
+ };
58
+
59
+ void UnityPrintFail(void);
60
+ void UnityPrintOk(void);
61
+
62
+ //-----------------------------------------------
63
+ // Pretty Printers & Test Result Output Handlers
64
+ //-----------------------------------------------
65
+
66
+ void UnityPrint(const char* string)
67
+ {
68
+ const char* pch = string;
69
+
70
+ if (pch != NULL)
71
+ {
72
+ while (*pch)
73
+ {
74
+ // printable characters plus CR & LF are printed
75
+ if ((*pch <= 126) && (*pch >= 32))
76
+ {
77
+ UNITY_OUTPUT_CHAR(*pch);
78
+ }
79
+ //write escaped carriage returns
80
+ else if (*pch == 13)
81
+ {
82
+ UNITY_OUTPUT_CHAR('\\');
83
+ UNITY_OUTPUT_CHAR('r');
84
+ }
85
+ //write escaped line feeds
86
+ else if (*pch == 10)
87
+ {
88
+ UNITY_OUTPUT_CHAR('\\');
89
+ UNITY_OUTPUT_CHAR('n');
90
+ }
91
+ // unprintable characters are shown as codes
92
+ else
93
+ {
94
+ UNITY_OUTPUT_CHAR('\\');
95
+ UnityPrintNumberHex((_U_SINT)*pch, 2);
96
+ }
97
+ pch++;
98
+ }
99
+ }
100
+ }
101
+
102
+ //-----------------------------------------------
103
+ void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style)
104
+ {
105
+ if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
106
+ {
107
+ UnityPrintNumber(number);
108
+ }
109
+ else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT)
110
+ {
111
+ UnityPrintNumberUnsigned( (_U_UINT)number & UnitySizeMask[((_U_UINT)style & (_U_UINT)0x0F) - 1] );
112
+ }
113
+ else
114
+ {
115
+ UnityPrintNumberHex((_U_UINT)number, (style & 0x000F) << 1);
116
+ }
117
+ }
118
+
119
+ //-----------------------------------------------
120
+ /// basically do an itoa using as little ram as possible
121
+ void UnityPrintNumber(const _U_SINT number_to_print)
122
+ {
123
+ _U_SINT divisor = 1;
124
+ _U_SINT next_divisor;
125
+ _U_SINT number = number_to_print;
126
+
127
+ if (number < 0)
128
+ {
129
+ UNITY_OUTPUT_CHAR('-');
130
+ number = -number;
131
+ }
132
+
133
+ // figure out initial divisor
134
+ while (number / divisor > 9)
135
+ {
136
+ next_divisor = divisor * 10;
137
+ if (next_divisor > divisor)
138
+ divisor = next_divisor;
139
+ else
140
+ break;
141
+ }
142
+
143
+ // now mod and print, then divide divisor
144
+ do
145
+ {
146
+ UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
147
+ divisor /= 10;
148
+ }
149
+ while (divisor > 0);
150
+ }
151
+
152
+ //-----------------------------------------------
153
+ /// basically do an itoa using as little ram as possible
154
+ void UnityPrintNumberUnsigned(const _U_UINT number)
155
+ {
156
+ _U_UINT divisor = 1;
157
+ _U_UINT next_divisor;
158
+
159
+ // figure out initial divisor
160
+ while (number / divisor > 9)
161
+ {
162
+ next_divisor = divisor * 10;
163
+ if (next_divisor > divisor)
164
+ divisor = next_divisor;
165
+ else
166
+ break;
167
+ }
168
+
169
+ // now mod and print, then divide divisor
170
+ do
171
+ {
172
+ UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
173
+ divisor /= 10;
174
+ }
175
+ while (divisor > 0);
176
+ }
177
+
178
+ //-----------------------------------------------
179
+ void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print)
180
+ {
181
+ _U_UINT nibble;
182
+ char nibbles = nibbles_to_print;
183
+ UNITY_OUTPUT_CHAR('0');
184
+ UNITY_OUTPUT_CHAR('x');
185
+
186
+ while (nibbles > 0)
187
+ {
188
+ nibble = (number >> (--nibbles << 2)) & 0x0000000F;
189
+ if (nibble <= 9)
190
+ {
191
+ UNITY_OUTPUT_CHAR((char)('0' + nibble));
192
+ }
193
+ else
194
+ {
195
+ UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble));
196
+ }
197
+ }
198
+ }
199
+
200
+ //-----------------------------------------------
201
+ void UnityPrintMask(const _U_UINT mask, const _U_UINT number)
202
+ {
203
+ _U_UINT current_bit = (_U_UINT)1 << (UNITY_INT_WIDTH - 1);
204
+ _US32 i;
205
+
206
+ for (i = 0; i < UNITY_INT_WIDTH; i++)
207
+ {
208
+ if (current_bit & mask)
209
+ {
210
+ if (current_bit & number)
211
+ {
212
+ UNITY_OUTPUT_CHAR('1');
213
+ }
214
+ else
215
+ {
216
+ UNITY_OUTPUT_CHAR('0');
217
+ }
218
+ }
219
+ else
220
+ {
221
+ UNITY_OUTPUT_CHAR('X');
222
+ }
223
+ current_bit = current_bit >> 1;
224
+ }
225
+ }
226
+
227
+ //-----------------------------------------------
228
+ #ifdef UNITY_FLOAT_VERBOSE
229
+ void UnityPrintFloat(_UF number)
230
+ {
231
+ char TempBuffer[32];
232
+ sprintf(TempBuffer, "%.6f", number);
233
+ UnityPrint(TempBuffer);
234
+ }
235
+ #endif
236
+
237
+ //-----------------------------------------------
238
+
239
+ void UnityPrintFail(void)
240
+ {
241
+ UnityPrint("FAIL");
242
+ }
243
+
244
+ void UnityPrintOk(void)
245
+ {
246
+ UnityPrint("OK");
247
+ }
248
+
249
+ //-----------------------------------------------
250
+ void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line)
251
+ {
252
+ UnityPrint(file);
253
+ UNITY_OUTPUT_CHAR(':');
254
+ UnityPrintNumber(line);
255
+ UNITY_OUTPUT_CHAR(':');
256
+ UnityPrint(Unity.CurrentTestName);
257
+ UNITY_OUTPUT_CHAR(':');
258
+ }
259
+
260
+ //-----------------------------------------------
261
+ void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line)
262
+ {
263
+ UnityTestResultsBegin(Unity.TestFile, line);
264
+ UnityPrint("FAIL:");
265
+ }
266
+
267
+ //-----------------------------------------------
268
+ void UnityConcludeTest(void)
269
+ {
270
+ if (Unity.CurrentTestIgnored)
271
+ {
272
+ Unity.TestIgnores++;
273
+ }
274
+ else if (!Unity.CurrentTestFailed)
275
+ {
276
+ UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
277
+ UnityPrint("PASS");
278
+ UNITY_PRINT_EOL;
279
+ }
280
+ else
281
+ {
282
+ Unity.TestFailures++;
283
+ }
284
+
285
+ Unity.CurrentTestFailed = 0;
286
+ Unity.CurrentTestIgnored = 0;
287
+ }
288
+
289
+ //-----------------------------------------------
290
+ void UnityAddMsgIfSpecified(const char* msg)
291
+ {
292
+ if (msg)
293
+ {
294
+ UnityPrint(UnityStrSpacer);
295
+ UnityPrint(msg);
296
+ }
297
+ }
298
+
299
+ //-----------------------------------------------
300
+ void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual)
301
+ {
302
+ UnityPrint(UnityStrExpected);
303
+ if (expected != NULL)
304
+ {
305
+ UNITY_OUTPUT_CHAR('\'');
306
+ UnityPrint(expected);
307
+ UNITY_OUTPUT_CHAR('\'');
308
+ }
309
+ else
310
+ {
311
+ UnityPrint(UnityStrNull);
312
+ }
313
+ UnityPrint(UnityStrWas);
314
+ if (actual != NULL)
315
+ {
316
+ UNITY_OUTPUT_CHAR('\'');
317
+ UnityPrint(actual);
318
+ UNITY_OUTPUT_CHAR('\'');
319
+ }
320
+ else
321
+ {
322
+ UnityPrint(UnityStrNull);
323
+ }
324
+ }
325
+
326
+ //-----------------------------------------------
327
+ // Assertion & Control Helpers
328
+ //-----------------------------------------------
329
+
330
+ int UnityCheckArraysForNull(const void* expected, const void* actual, const UNITY_LINE_TYPE lineNumber, const char* msg)
331
+ {
332
+ //return true if they are both NULL
333
+ if ((expected == NULL) && (actual == NULL))
334
+ return 1;
335
+
336
+ //throw error if just expected is NULL
337
+ if (expected == NULL)
338
+ {
339
+ UnityTestResultsFailBegin(lineNumber);
340
+ UnityPrint(UnityStrNullPointerForExpected);
341
+ UnityAddMsgIfSpecified(msg);
342
+ UNITY_FAIL_AND_BAIL;
343
+ }
344
+
345
+ //throw error if just actual is NULL
346
+ if (actual == NULL)
347
+ {
348
+ UnityTestResultsFailBegin(lineNumber);
349
+ UnityPrint(UnityStrNullPointerForActual);
350
+ UnityAddMsgIfSpecified(msg);
351
+ UNITY_FAIL_AND_BAIL;
352
+ }
353
+
354
+ //return false if neither is NULL
355
+ return 0;
356
+ }
357
+
358
+ //-----------------------------------------------
359
+ // Assertion Functions
360
+ //-----------------------------------------------
361
+
362
+ void UnityAssertBits(const _U_SINT mask,
363
+ const _U_SINT expected,
364
+ const _U_SINT actual,
365
+ const char* msg,
366
+ const UNITY_LINE_TYPE lineNumber)
367
+ {
368
+ UNITY_SKIP_EXECUTION;
369
+
370
+ if ((mask & expected) != (mask & actual))
371
+ {
372
+ UnityTestResultsFailBegin(lineNumber);
373
+ UnityPrint(UnityStrExpected);
374
+ UnityPrintMask(mask, expected);
375
+ UnityPrint(UnityStrWas);
376
+ UnityPrintMask(mask, actual);
377
+ UnityAddMsgIfSpecified(msg);
378
+ UNITY_FAIL_AND_BAIL;
379
+ }
380
+ }
381
+
382
+ //-----------------------------------------------
383
+ void UnityAssertEqualNumber(const _U_SINT expected,
384
+ const _U_SINT actual,
385
+ const char* msg,
386
+ const UNITY_LINE_TYPE lineNumber,
387
+ const UNITY_DISPLAY_STYLE_T style)
388
+ {
389
+ UNITY_SKIP_EXECUTION;
390
+
391
+ if (expected != actual)
392
+ {
393
+ UnityTestResultsFailBegin(lineNumber);
394
+ UnityPrint(UnityStrExpected);
395
+ UnityPrintNumberByStyle(expected, style);
396
+ UnityPrint(UnityStrWas);
397
+ UnityPrintNumberByStyle(actual, style);
398
+ UnityAddMsgIfSpecified(msg);
399
+ UNITY_FAIL_AND_BAIL;
400
+ }
401
+ }
402
+
403
+ //-----------------------------------------------
404
+ void UnityAssertEqualIntArray(const _U_SINT* expected,
405
+ const _U_SINT* actual,
406
+ const _UU32 num_elements,
407
+ const char* msg,
408
+ const UNITY_LINE_TYPE lineNumber,
409
+ const UNITY_DISPLAY_STYLE_T style)
410
+ {
411
+ _UU32 elements = num_elements;
412
+ const _US8* ptr_exp = (_US8*)expected;
413
+ const _US8* ptr_act = (_US8*)actual;
414
+
415
+ UNITY_SKIP_EXECUTION;
416
+
417
+ if (elements == 0)
418
+ {
419
+ UnityTestResultsFailBegin(lineNumber);
420
+ UnityPrint(UnityStrPointless);
421
+ UnityAddMsgIfSpecified(msg);
422
+ UNITY_FAIL_AND_BAIL;
423
+ }
424
+
425
+ if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
426
+ return;
427
+
428
+ // If style is UNITY_DISPLAY_STYLE_INT, we'll fall into the default case rather than the INT16 or INT32 (etc) case
429
+ // as UNITY_DISPLAY_STYLE_INT includes a flag for UNITY_DISPLAY_RANGE_AUTO, which the width-specific
430
+ // variants do not. Therefore remove this flag.
431
+ switch(style & ~UNITY_DISPLAY_RANGE_AUTO)
432
+ {
433
+ case UNITY_DISPLAY_STYLE_HEX8:
434
+ case UNITY_DISPLAY_STYLE_INT8:
435
+ case UNITY_DISPLAY_STYLE_UINT8:
436
+ while (elements--)
437
+ {
438
+ if (*ptr_exp != *ptr_act)
439
+ {
440
+ UnityTestResultsFailBegin(lineNumber);
441
+ UnityPrint(UnityStrElement);
442
+ UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
443
+ UnityPrint(UnityStrExpected);
444
+ UnityPrintNumberByStyle(*ptr_exp, style);
445
+ UnityPrint(UnityStrWas);
446
+ UnityPrintNumberByStyle(*ptr_act, style);
447
+ UnityAddMsgIfSpecified(msg);
448
+ UNITY_FAIL_AND_BAIL;
449
+ }
450
+ ptr_exp += 1;
451
+ ptr_act += 1;
452
+ }
453
+ break;
454
+ case UNITY_DISPLAY_STYLE_HEX16:
455
+ case UNITY_DISPLAY_STYLE_INT16:
456
+ case UNITY_DISPLAY_STYLE_UINT16:
457
+ while (elements--)
458
+ {
459
+ if (*(_US16*)ptr_exp != *(_US16*)ptr_act)
460
+ {
461
+ UnityTestResultsFailBegin(lineNumber);
462
+ UnityPrint(UnityStrElement);
463
+ UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
464
+ UnityPrint(UnityStrExpected);
465
+ UnityPrintNumberByStyle(*(_US16*)ptr_exp, style);
466
+ UnityPrint(UnityStrWas);
467
+ UnityPrintNumberByStyle(*(_US16*)ptr_act, style);
468
+ UnityAddMsgIfSpecified(msg);
469
+ UNITY_FAIL_AND_BAIL;
470
+ }
471
+ ptr_exp += 2;
472
+ ptr_act += 2;
473
+ }
474
+ break;
475
+ #ifdef UNITY_SUPPORT_64
476
+ case UNITY_DISPLAY_STYLE_HEX64:
477
+ case UNITY_DISPLAY_STYLE_INT64:
478
+ case UNITY_DISPLAY_STYLE_UINT64:
479
+ while (elements--)
480
+ {
481
+ if (*(_US64*)ptr_exp != *(_US64*)ptr_act)
482
+ {
483
+ UnityTestResultsFailBegin(lineNumber);
484
+ UnityPrint(UnityStrElement);
485
+ UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
486
+ UnityPrint(UnityStrExpected);
487
+ UnityPrintNumberByStyle(*(_US64*)ptr_exp, style);
488
+ UnityPrint(UnityStrWas);
489
+ UnityPrintNumberByStyle(*(_US64*)ptr_act, style);
490
+ UnityAddMsgIfSpecified(msg);
491
+ UNITY_FAIL_AND_BAIL;
492
+ }
493
+ ptr_exp += 8;
494
+ ptr_act += 8;
495
+ }
496
+ break;
497
+ #endif
498
+ default:
499
+ while (elements--)
500
+ {
501
+ if (*(_US32*)ptr_exp != *(_US32*)ptr_act)
502
+ {
503
+ UnityTestResultsFailBegin(lineNumber);
504
+ UnityPrint(UnityStrElement);
505
+ UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
506
+ UnityPrint(UnityStrExpected);
507
+ UnityPrintNumberByStyle(*(_US32*)ptr_exp, style);
508
+ UnityPrint(UnityStrWas);
509
+ UnityPrintNumberByStyle(*(_US32*)ptr_act, style);
510
+ UnityAddMsgIfSpecified(msg);
511
+ UNITY_FAIL_AND_BAIL;
512
+ }
513
+ ptr_exp += 4;
514
+ ptr_act += 4;
515
+ }
516
+ break;
517
+ }
518
+ }
519
+
520
+ //-----------------------------------------------
521
+ #ifndef UNITY_EXCLUDE_FLOAT
522
+ void UnityAssertEqualFloatArray(const _UF* expected,
523
+ const _UF* actual,
524
+ const _UU32 num_elements,
525
+ const char* msg,
526
+ const UNITY_LINE_TYPE lineNumber)
527
+ {
528
+ _UU32 elements = num_elements;
529
+ const _UF* ptr_expected = expected;
530
+ const _UF* ptr_actual = actual;
531
+ _UF diff, tol;
532
+
533
+ UNITY_SKIP_EXECUTION;
534
+
535
+ if (elements == 0)
536
+ {
537
+ UnityTestResultsFailBegin(lineNumber);
538
+ UnityPrint(UnityStrPointless);
539
+ UnityAddMsgIfSpecified(msg);
540
+ UNITY_FAIL_AND_BAIL;
541
+ }
542
+
543
+ if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
544
+ return;
545
+
546
+ while (elements--)
547
+ {
548
+ diff = *ptr_expected - *ptr_actual;
549
+ if (diff < 0.0f)
550
+ diff = 0.0f - diff;
551
+ tol = UNITY_FLOAT_PRECISION * *ptr_expected;
552
+ if (tol < 0.0f)
553
+ tol = 0.0f - tol;
554
+
555
+ //This first part of this condition will catch any NaN or Infinite values
556
+ if ((diff * 0.0f != 0.0f) || (diff > tol))
557
+ {
558
+ UnityTestResultsFailBegin(lineNumber);
559
+ UnityPrint(UnityStrElement);
560
+ UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
561
+ #ifdef UNITY_FLOAT_VERBOSE
562
+ UnityPrint(UnityStrExpected);
563
+ UnityPrintFloat(*ptr_expected);
564
+ UnityPrint(UnityStrWas);
565
+ UnityPrintFloat(*ptr_actual);
566
+ #else
567
+ UnityPrint(UnityStrDelta);
568
+ #endif
569
+ UnityAddMsgIfSpecified(msg);
570
+ UNITY_FAIL_AND_BAIL;
571
+ }
572
+ ptr_expected++;
573
+ ptr_actual++;
574
+ }
575
+ }
576
+
577
+ //-----------------------------------------------
578
+ void UnityAssertFloatsWithin(const _UF delta,
579
+ const _UF expected,
580
+ const _UF actual,
581
+ const char* msg,
582
+ const UNITY_LINE_TYPE lineNumber)
583
+ {
584
+ _UF diff = actual - expected;
585
+ _UF pos_delta = delta;
586
+
587
+ UNITY_SKIP_EXECUTION;
588
+
589
+ if (diff < 0.0f)
590
+ {
591
+ diff = 0.0f - diff;
592
+ }
593
+ if (pos_delta < 0.0f)
594
+ {
595
+ pos_delta = 0.0f - pos_delta;
596
+ }
597
+
598
+ //This first part of this condition will catch any NaN or Infinite values
599
+ if ((diff * 0.0f != 0.0f) || (pos_delta < diff))
600
+ {
601
+ UnityTestResultsFailBegin(lineNumber);
602
+ #ifdef UNITY_FLOAT_VERBOSE
603
+ UnityPrint(UnityStrExpected);
604
+ UnityPrintFloat(expected);
605
+ UnityPrint(UnityStrWas);
606
+ UnityPrintFloat(actual);
607
+ #else
608
+ UnityPrint(UnityStrDelta);
609
+ #endif
610
+ UnityAddMsgIfSpecified(msg);
611
+ UNITY_FAIL_AND_BAIL;
612
+ }
613
+ }
614
+
615
+ //-----------------------------------------------
616
+ void UnityAssertFloatIsInf(const _UF actual,
617
+ const char* msg,
618
+ const UNITY_LINE_TYPE lineNumber)
619
+ {
620
+ UNITY_SKIP_EXECUTION;
621
+
622
+ // In Microsoft Visual C++ Express Edition 2008,
623
+ // if ((1.0f / f_zero) != actual)
624
+ // produces
625
+ // error C2124: divide or mod by zero
626
+ // As a workaround, place 0 into a variable.
627
+ if ((1.0f / f_zero) != actual)
628
+ {
629
+ UnityTestResultsFailBegin(lineNumber);
630
+ #ifdef UNITY_FLOAT_VERBOSE
631
+ UnityPrint(UnityStrExpected);
632
+ UnityPrint(UnityStrInf);
633
+ UnityPrint(UnityStrWas);
634
+ UnityPrintFloat(actual);
635
+ #else
636
+ UnityPrint(UnityStrDelta);
637
+ #endif
638
+ UnityAddMsgIfSpecified(msg);
639
+ UNITY_FAIL_AND_BAIL;
640
+ }
641
+ }
642
+
643
+ //-----------------------------------------------
644
+ void UnityAssertFloatIsNegInf(const _UF actual,
645
+ const char* msg,
646
+ const UNITY_LINE_TYPE lineNumber)
647
+ {
648
+ UNITY_SKIP_EXECUTION;
649
+
650
+ // The rationale for not using 1.0f/0.0f is given in UnityAssertFloatIsInf's body.
651
+ if ((-1.0f / f_zero) != actual)
652
+ {
653
+ UnityTestResultsFailBegin(lineNumber);
654
+ #ifdef UNITY_FLOAT_VERBOSE
655
+ UnityPrint(UnityStrExpected);
656
+ UnityPrint(UnityStrNegInf);
657
+ UnityPrint(UnityStrWas);
658
+ UnityPrintFloat(actual);
659
+ #else
660
+ UnityPrint(UnityStrDelta);
661
+ #endif
662
+ UnityAddMsgIfSpecified(msg);
663
+ UNITY_FAIL_AND_BAIL;
664
+ }
665
+ }
666
+
667
+ //-----------------------------------------------
668
+ void UnityAssertFloatIsNaN(const _UF actual,
669
+ const char* msg,
670
+ const UNITY_LINE_TYPE lineNumber)
671
+ {
672
+ UNITY_SKIP_EXECUTION;
673
+
674
+ if (actual == actual)
675
+ {
676
+ UnityTestResultsFailBegin(lineNumber);
677
+ #ifdef UNITY_FLOAT_VERBOSE
678
+ UnityPrint(UnityStrExpected);
679
+ UnityPrint(UnityStrNaN);
680
+ UnityPrint(UnityStrWas);
681
+ UnityPrintFloat(actual);
682
+ #else
683
+ UnityPrint(UnityStrDelta);
684
+ #endif
685
+ UnityAddMsgIfSpecified(msg);
686
+ UNITY_FAIL_AND_BAIL;
687
+ }
688
+ }
689
+
690
+ #endif //not UNITY_EXCLUDE_FLOAT
691
+
692
+ //-----------------------------------------------
693
+ #ifndef UNITY_EXCLUDE_DOUBLE
694
+ void UnityAssertEqualDoubleArray(const _UD* expected,
695
+ const _UD* actual,
696
+ const _UU32 num_elements,
697
+ const char* msg,
698
+ const UNITY_LINE_TYPE lineNumber)
699
+ {
700
+ _UU32 elements = num_elements;
701
+ const _UD* ptr_expected = expected;
702
+ const _UD* ptr_actual = actual;
703
+ _UD diff, tol;
704
+
705
+ UNITY_SKIP_EXECUTION;
706
+
707
+ if (elements == 0)
708
+ {
709
+ UnityTestResultsFailBegin(lineNumber);
710
+ UnityPrint(UnityStrPointless);
711
+ UnityAddMsgIfSpecified(msg);
712
+ UNITY_FAIL_AND_BAIL;
713
+ }
714
+
715
+ if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
716
+ return;
717
+
718
+ while (elements--)
719
+ {
720
+ diff = *ptr_expected - *ptr_actual;
721
+ if (diff < 0.0)
722
+ diff = 0.0 - diff;
723
+ tol = UNITY_DOUBLE_PRECISION * *ptr_expected;
724
+ if (tol < 0.0)
725
+ tol = 0.0 - tol;
726
+
727
+ //This first part of this condition will catch any NaN or Infinite values
728
+ if ((diff * 0.0 != 0.0) || (diff > tol))
729
+ {
730
+ UnityTestResultsFailBegin(lineNumber);
731
+ UnityPrint(UnityStrElement);
732
+ UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
733
+ #ifdef UNITY_DOUBLE_VERBOSE
734
+ UnityPrint(UnityStrExpected);
735
+ UnityPrintFloat((float)(*ptr_expected));
736
+ UnityPrint(UnityStrWas);
737
+ UnityPrintFloat((float)(*ptr_actual));
738
+ #else
739
+ UnityPrint(UnityStrDelta);
740
+ #endif
741
+ UnityAddMsgIfSpecified(msg);
742
+ UNITY_FAIL_AND_BAIL;
743
+ }
744
+ ptr_expected++;
745
+ ptr_actual++;
746
+ }
747
+ }
748
+
749
+ //-----------------------------------------------
750
+ void UnityAssertDoublesWithin(const _UD delta,
751
+ const _UD expected,
752
+ const _UD actual,
753
+ const char* msg,
754
+ const UNITY_LINE_TYPE lineNumber)
755
+ {
756
+ _UD diff = actual - expected;
757
+ _UD pos_delta = delta;
758
+
759
+ UNITY_SKIP_EXECUTION;
760
+
761
+ if (diff < 0.0)
762
+ {
763
+ diff = 0.0 - diff;
764
+ }
765
+ if (pos_delta < 0.0)
766
+ {
767
+ pos_delta = 0.0 - pos_delta;
768
+ }
769
+
770
+ //This first part of this condition will catch any NaN or Infinite values
771
+ if ((diff * 0.0 != 0.0) || (pos_delta < diff))
772
+ {
773
+ UnityTestResultsFailBegin(lineNumber);
774
+ #ifdef UNITY_DOUBLE_VERBOSE
775
+ UnityPrint(UnityStrExpected);
776
+ UnityPrintFloat((float)expected);
777
+ UnityPrint(UnityStrWas);
778
+ UnityPrintFloat((float)actual);
779
+ #else
780
+ UnityPrint(UnityStrDelta);
781
+ #endif
782
+ UnityAddMsgIfSpecified(msg);
783
+ UNITY_FAIL_AND_BAIL;
784
+ }
785
+ }
786
+
787
+ //-----------------------------------------------
788
+ void UnityAssertDoubleIsInf(const _UD actual,
789
+ const char* msg,
790
+ const UNITY_LINE_TYPE lineNumber)
791
+ {
792
+ UNITY_SKIP_EXECUTION;
793
+
794
+ // The rationale for not using 1.0/0.0 is given in UnityAssertFloatIsInf's body.
795
+ if ((1.0 / d_zero) != actual)
796
+ {
797
+ UnityTestResultsFailBegin(lineNumber);
798
+ #ifdef UNITY_DOUBLE_VERBOSE
799
+ UnityPrint(UnityStrExpected);
800
+ UnityPrint(UnityStrInf);
801
+ UnityPrint(UnityStrWas);
802
+ UnityPrintFloat((float)actual);
803
+ #else
804
+ UnityPrint(UnityStrDelta);
805
+ #endif
806
+ UnityAddMsgIfSpecified(msg);
807
+ UNITY_FAIL_AND_BAIL;
808
+ }
809
+ }
810
+
811
+ //-----------------------------------------------
812
+ void UnityAssertDoubleIsNegInf(const _UD actual,
813
+ const char* msg,
814
+ const UNITY_LINE_TYPE lineNumber)
815
+ {
816
+ UNITY_SKIP_EXECUTION;
817
+
818
+ // The rationale for not using 1.0/0.0 is given in UnityAssertFloatIsInf's body.
819
+ if ((-1.0 / d_zero) != actual)
820
+ {
821
+ UnityTestResultsFailBegin(lineNumber);
822
+ #ifdef UNITY_DOUBLE_VERBOSE
823
+ UnityPrint(UnityStrExpected);
824
+ UnityPrint(UnityStrNegInf);
825
+ UnityPrint(UnityStrWas);
826
+ UnityPrintFloat((float)actual);
827
+ #else
828
+ UnityPrint(UnityStrDelta);
829
+ #endif
830
+ UnityAddMsgIfSpecified(msg);
831
+ UNITY_FAIL_AND_BAIL;
832
+ }
833
+ }
834
+
835
+ //-----------------------------------------------
836
+ void UnityAssertDoubleIsNaN(const _UD actual,
837
+ const char* msg,
838
+ const UNITY_LINE_TYPE lineNumber)
839
+ {
840
+ UNITY_SKIP_EXECUTION;
841
+
842
+ if (actual == actual)
843
+ {
844
+ UnityTestResultsFailBegin(lineNumber);
845
+ #ifdef UNITY_DOUBLE_VERBOSE
846
+ UnityPrint(UnityStrExpected);
847
+ UnityPrint(UnityStrNaN);
848
+ UnityPrint(UnityStrWas);
849
+ UnityPrintFloat((float)actual);
850
+ #else
851
+ UnityPrint(UnityStrDelta);
852
+ #endif
853
+ UnityAddMsgIfSpecified(msg);
854
+ UNITY_FAIL_AND_BAIL;
855
+ }
856
+ }
857
+
858
+ #endif // not UNITY_EXCLUDE_DOUBLE
859
+
860
+ //-----------------------------------------------
861
+ void UnityAssertNumbersWithin( const _U_SINT delta,
862
+ const _U_SINT expected,
863
+ const _U_SINT actual,
864
+ const char* msg,
865
+ const UNITY_LINE_TYPE lineNumber,
866
+ const UNITY_DISPLAY_STYLE_T style)
867
+ {
868
+ UNITY_SKIP_EXECUTION;
869
+
870
+ if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
871
+ {
872
+ if (actual > expected)
873
+ Unity.CurrentTestFailed = ((actual - expected) > delta);
874
+ else
875
+ Unity.CurrentTestFailed = ((expected - actual) > delta);
876
+ }
877
+ else
878
+ {
879
+ if ((_U_UINT)actual > (_U_UINT)expected)
880
+ Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > (_U_UINT)delta);
881
+ else
882
+ Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > (_U_UINT)delta);
883
+ }
884
+
885
+ if (Unity.CurrentTestFailed)
886
+ {
887
+ UnityTestResultsFailBegin(lineNumber);
888
+ UnityPrint(UnityStrDelta);
889
+ UnityPrintNumberByStyle(delta, style);
890
+ UnityPrint(UnityStrExpected);
891
+ UnityPrintNumberByStyle(expected, style);
892
+ UnityPrint(UnityStrWas);
893
+ UnityPrintNumberByStyle(actual, style);
894
+ UnityAddMsgIfSpecified(msg);
895
+ UNITY_FAIL_AND_BAIL;
896
+ }
897
+ }
898
+
899
+ //-----------------------------------------------
900
+ void UnityAssertEqualString(const char* expected,
901
+ const char* actual,
902
+ const char* msg,
903
+ const UNITY_LINE_TYPE lineNumber)
904
+ {
905
+ _UU32 i;
906
+
907
+ UNITY_SKIP_EXECUTION;
908
+
909
+ // if both pointers not null compare the strings
910
+ if (expected && actual)
911
+ {
912
+ for (i = 0; expected[i] || actual[i]; i++)
913
+ {
914
+ if (expected[i] != actual[i])
915
+ {
916
+ Unity.CurrentTestFailed = 1;
917
+ break;
918
+ }
919
+ }
920
+ }
921
+ else
922
+ { // handle case of one pointers being null (if both null, test should pass)
923
+ if (expected != actual)
924
+ {
925
+ Unity.CurrentTestFailed = 1;
926
+ }
927
+ }
928
+
929
+ if (Unity.CurrentTestFailed)
930
+ {
931
+ UnityTestResultsFailBegin(lineNumber);
932
+ UnityPrintExpectedAndActualStrings(expected, actual);
933
+ UnityAddMsgIfSpecified(msg);
934
+ UNITY_FAIL_AND_BAIL;
935
+ }
936
+ }
937
+
938
+ //-----------------------------------------------
939
+ void UnityAssertEqualStringArray( const char** expected,
940
+ const char** actual,
941
+ const _UU32 num_elements,
942
+ const char* msg,
943
+ const UNITY_LINE_TYPE lineNumber)
944
+ {
945
+ _UU32 i, j = 0;
946
+
947
+ UNITY_SKIP_EXECUTION;
948
+
949
+ // if no elements, it's an error
950
+ if (num_elements == 0)
951
+ {
952
+ UnityTestResultsFailBegin(lineNumber);
953
+ UnityPrint(UnityStrPointless);
954
+ UnityAddMsgIfSpecified(msg);
955
+ UNITY_FAIL_AND_BAIL;
956
+ }
957
+
958
+ if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
959
+ return;
960
+
961
+ do
962
+ {
963
+ // if both pointers not null compare the strings
964
+ if (expected[j] && actual[j])
965
+ {
966
+ for (i = 0; expected[j][i] || actual[j][i]; i++)
967
+ {
968
+ if (expected[j][i] != actual[j][i])
969
+ {
970
+ Unity.CurrentTestFailed = 1;
971
+ break;
972
+ }
973
+ }
974
+ }
975
+ else
976
+ { // handle case of one pointers being null (if both null, test should pass)
977
+ if (expected[j] != actual[j])
978
+ {
979
+ Unity.CurrentTestFailed = 1;
980
+ }
981
+ }
982
+
983
+ if (Unity.CurrentTestFailed)
984
+ {
985
+ UnityTestResultsFailBegin(lineNumber);
986
+ if (num_elements > 1)
987
+ {
988
+ UnityPrint(UnityStrElement);
989
+ UnityPrintNumberByStyle((j), UNITY_DISPLAY_STYLE_UINT);
990
+ }
991
+ UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j]));
992
+ UnityAddMsgIfSpecified(msg);
993
+ UNITY_FAIL_AND_BAIL;
994
+ }
995
+ } while (++j < num_elements);
996
+ }
997
+
998
+ //-----------------------------------------------
999
+ void UnityAssertEqualMemory( const void* expected,
1000
+ const void* actual,
1001
+ const _UU32 length,
1002
+ const _UU32 num_elements,
1003
+ const char* msg,
1004
+ const UNITY_LINE_TYPE lineNumber)
1005
+ {
1006
+ unsigned char* ptr_exp = (unsigned char*)expected;
1007
+ unsigned char* ptr_act = (unsigned char*)actual;
1008
+ _UU32 elements = num_elements;
1009
+ _UU32 bytes;
1010
+
1011
+ UNITY_SKIP_EXECUTION;
1012
+
1013
+ if ((elements == 0) || (length == 0))
1014
+ {
1015
+ UnityTestResultsFailBegin(lineNumber);
1016
+ UnityPrint(UnityStrPointless);
1017
+ UnityAddMsgIfSpecified(msg);
1018
+ UNITY_FAIL_AND_BAIL;
1019
+ }
1020
+
1021
+ if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
1022
+ return;
1023
+
1024
+ while (elements--)
1025
+ {
1026
+ /////////////////////////////////////
1027
+ bytes = length;
1028
+ while (bytes--)
1029
+ {
1030
+ if (*ptr_exp != *ptr_act)
1031
+ {
1032
+ UnityTestResultsFailBegin(lineNumber);
1033
+ UnityPrint(UnityStrMemory);
1034
+ if (num_elements > 1)
1035
+ {
1036
+ UnityPrint(UnityStrElement);
1037
+ UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
1038
+ }
1039
+ UnityPrint(UnityStrByte);
1040
+ UnityPrintNumberByStyle((length - bytes - 1), UNITY_DISPLAY_STYLE_UINT);
1041
+ UnityPrint(UnityStrExpected);
1042
+ UnityPrintNumberByStyle(*ptr_exp, UNITY_DISPLAY_STYLE_HEX8);
1043
+ UnityPrint(UnityStrWas);
1044
+ UnityPrintNumberByStyle(*ptr_act, UNITY_DISPLAY_STYLE_HEX8);
1045
+ UnityAddMsgIfSpecified(msg);
1046
+ UNITY_FAIL_AND_BAIL;
1047
+ }
1048
+ ptr_exp += 1;
1049
+ ptr_act += 1;
1050
+ }
1051
+ /////////////////////////////////////
1052
+
1053
+ }
1054
+ }
1055
+
1056
+ //-----------------------------------------------
1057
+ // Control Functions
1058
+ //-----------------------------------------------
1059
+
1060
+ void UnityFail(const char* msg, const UNITY_LINE_TYPE line)
1061
+ {
1062
+ UNITY_SKIP_EXECUTION;
1063
+
1064
+ UnityTestResultsBegin(Unity.TestFile, line);
1065
+ UnityPrintFail();
1066
+ if (msg != NULL)
1067
+ {
1068
+ UNITY_OUTPUT_CHAR(':');
1069
+ if (msg[0] != ' ')
1070
+ {
1071
+ UNITY_OUTPUT_CHAR(' ');
1072
+ }
1073
+ UnityPrint(msg);
1074
+ }
1075
+ UNITY_FAIL_AND_BAIL;
1076
+ }
1077
+
1078
+ //-----------------------------------------------
1079
+ void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
1080
+ {
1081
+ UNITY_SKIP_EXECUTION;
1082
+
1083
+ UnityTestResultsBegin(Unity.TestFile, line);
1084
+ UnityPrint("IGNORE");
1085
+ if (msg != NULL)
1086
+ {
1087
+ UNITY_OUTPUT_CHAR(':');
1088
+ UNITY_OUTPUT_CHAR(' ');
1089
+ UnityPrint(msg);
1090
+ }
1091
+ UNITY_IGNORE_AND_BAIL;
1092
+ }
1093
+
1094
+ //-----------------------------------------------
1095
+ void setUp(void);
1096
+ void tearDown(void);
1097
+ void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
1098
+ {
1099
+ Unity.CurrentTestName = FuncName;
1100
+ Unity.CurrentTestLineNumber = FuncLineNum;
1101
+ Unity.NumberOfTests++;
1102
+ if (TEST_PROTECT())
1103
+ {
1104
+ setUp();
1105
+ Func();
1106
+ }
1107
+ if (TEST_PROTECT() && !(Unity.CurrentTestIgnored))
1108
+ {
1109
+ tearDown();
1110
+ }
1111
+ UnityConcludeTest();
1112
+ }
1113
+
1114
+ //-----------------------------------------------
1115
+ void UnityBegin(void)
1116
+ {
1117
+ Unity.NumberOfTests = 0;
1118
+ Unity.TestFailures = 0;
1119
+ Unity.TestIgnores = 0;
1120
+ Unity.CurrentTestFailed = 0;
1121
+ Unity.CurrentTestIgnored = 0;
1122
+ }
1123
+
1124
+ //-----------------------------------------------
1125
+ int UnityEnd(void)
1126
+ {
1127
+ UnityPrint("-----------------------");
1128
+ UNITY_PRINT_EOL;
1129
+ UnityPrintNumber(Unity.NumberOfTests);
1130
+ UnityPrint(" Tests ");
1131
+ UnityPrintNumber(Unity.TestFailures);
1132
+ UnityPrint(" Failures ");
1133
+ UnityPrintNumber(Unity.TestIgnores);
1134
+ UnityPrint(" Ignored");
1135
+ UNITY_PRINT_EOL;
1136
+ if (Unity.TestFailures == 0U)
1137
+ {
1138
+ UnityPrintOk();
1139
+ }
1140
+ else
1141
+ {
1142
+ UnityPrintFail();
1143
+ }
1144
+ UNITY_PRINT_EOL;
1145
+ return Unity.TestFailures;
1146
+ }