Skip to content

Commit ce3b93c

Browse files
committed
tests: p/cmock: Add 0001-Added-array_as_byte-config-options.patch
This change is needed for testing libs2 which is using anynomous type (struct S2) Relate-to: SiliconLabsSoftware/z-wave-protocol-controller#60 Relate-to: SiliconLabsSoftware/z-wave-engine-application-layer#6 Relate-to: SiliconLabsSoftware/z-wave-protocol-controller#75 Signed-off-by: Philippe Coval <philippe.coval@silabs.com>
1 parent c63ab0e commit ce3b93c

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
From 2b089523835cf0ab3c4ac66984ee7b02f21a6d9d Mon Sep 17 00:00:00 2001
2+
From: Philippe Coval <philippe.coval@silabs.com>
3+
Date: Fri, 24 Apr 2020 14:05:54 +0200
4+
Subject: [PATCH] Added array_as_byte config options.
5+
MIME-Version: 1.0
6+
Content-Type: text/plain; charset=UTF-8
7+
Content-Transfer-Encoding: 8bit
8+
9+
[Anders Esbensen]
10+
11+
Option to check arrays by the number of bytes instead of number of elements.
12+
13+
[Philippe Coval]
14+
15+
This change was applied to a fork (ths_cmock) used in a Z-Wave project.
16+
It was needed to generate mocks from a header that used annonymous structures.
17+
18+
The observed issue was:
19+
20+
(...)_mock.c:486:123: error: invalid application of ‘sizeof’ to incomplete type ‘struct (...)’
21+
22+
Which was just declared in relative header.
23+
24+
The array_as_byte feature prevent this error.
25+
26+
Author: Anders Esbensen <Anders.Esbensen@silabs.com>
27+
Origin-Upstream: https://github.com/ThrowTheSwitch/CMock/pull/503
28+
Origin-SiliconLabs: v2.5.1-74-ga078d10
29+
Relate-to: https://github.com/SiliconLabsSoftware/z-wave-protocol-controller/issues/75
30+
Signed-off-by: Philippe Coval <philippe.coval@silabs.com>
31+
---
32+
docs/CMock_Summary.md | 4 ++++
33+
lib/cmock_config.rb | 1 +
34+
lib/cmock_generator_utils.rb | 7 ++++++-
35+
3 files changed, 11 insertions(+), 1 deletion(-)
36+
37+
diff --git a/docs/CMock_Summary.md b/docs/CMock_Summary.md
38+
index 3183665..5cb201c 100644
39+
--- a/docs/CMock_Summary.md
40+
+++ b/docs/CMock_Summary.md
41+
@@ -738,6 +738,10 @@ from the defaults. We've tried to specify what the defaults are below.
42+
43+
GoBananas_ExpectWithArray(b, 2, 2);
44+
45+
+ `:array_as_byte`:
46+
+ When checking arrays, the element size will always be 1, ie depth is the number
47+
+ of bytes to check.
48+
+
49+
* `:fail_on_unexpected_calls`:
50+
By default, CMock will fail a test if a mock is called without `_Expect` and `_Ignore`
51+
called first. While this forces test writers to be more explicit in their expectations,
52+
diff --git a/lib/cmock_config.rb b/lib/cmock_config.rb
53+
index ccbf4dc..27cece4 100644
54+
--- a/lib/cmock_config.rb
55+
+++ b/lib/cmock_config.rb
56+
@@ -41,6 +41,7 @@ class CMockConfig
57+
:orig_header_include_fmt => '#include "%s"',
58+
:array_size_type => [],
59+
:array_size_name => 'size|len',
60+
+ :array_as_byte => false,
61+
:skeleton => false,
62+
:exclude_setjmp_h => false,
63+
64+
diff --git a/lib/cmock_generator_utils.rb b/lib/cmock_generator_utils.rb
65+
index 83e762f..6f0ddc8 100644
66+
--- a/lib/cmock_generator_utils.rb
67+
+++ b/lib/cmock_generator_utils.rb
68+
@@ -21,6 +21,7 @@ class CMockGeneratorUtils
69+
@ignore_stateless = @config.plugins.include? :ignore_stateless
70+
@treat_as = @config.treat_as
71+
@helpers = helpers
72+
+ @array_as_byte = @config.array_as_byte
73+
end
74+
75+
def self.arg_type_with_const(arg)
76+
@@ -230,7 +231,11 @@ class CMockGeneratorUtils
77+
lines << " { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, CMockStringExpNULL); }\n"
78+
lines << (depth_name != 1 ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_PTR(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, CMockStringMismatch); }\n" : '')
79+
lines << " else\n"
80+
- lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*', '')}), #{depth_name}, cmock_line, CMockStringMismatch); }\n"
81+
+ if @array_as_byte
82+
+ lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), 1, #{depth_name}, cmock_line, CMockStringMismatch); }\n"
83+
+ else
84+
+ lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*', '')}), #{depth_name}, cmock_line, CMockStringMismatch); }\n"
85+
+ end
86+
end
87+
when /_ARRAY/
88+
if pre == '&'
89+
--
90+
2.39.5
91+

0 commit comments

Comments
 (0)