ceedling 0.28.2 → 0.28.3

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