Debian Codegraph @

test/unit/cmock_generator_utils_test.rb

raw symbols SCIP
1 # ==========================================
2 # CMock Project - Automatic Mock Generation 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 require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
8 require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_utils'
9
10 describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
11
12 before do
13 create_mocks :config, :unity_helper, :unity_helper
14
15 @config.expect :when_ptr, :compare_ptr
16 @config.expect :enforce_strict_ordering, false
17 @config.expect :plugins, []
18 @config.expect :plugins, []
19 @config.expect :plugins, []
20 @config.expect :plugins, []
21 @config.expect :plugins, []
22 @config.expect :plugins, []
23 @config.expect :plugins, []
24 @config.expect :treat_as, {'int' => 'INT','short' => 'INT16','long' => 'INT','char' => 'INT8','const char*' => 'STRING'}
25 @cmock_generator_utils_simple = CMockGeneratorUtils.new(@config, {:unity_helper => @unity_helper})
26
27 @config.expect :when_ptr, :smart
28 @config.expect :enforce_strict_ordering, true
29 @config.expect :plugins, [:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore, :ignore_stateless]
30 @config.expect :plugins, [:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore, :ignore_stateless]
31 @config.expect :plugins, [:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore, :ignore_stateless]
32 @config.expect :plugins, [:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore, :ignore_stateless]
33 @config.expect :plugins, [:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore, :ignore_stateless]
34 @config.expect :plugins, [:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore, :ignore_stateless]
35 @config.expect :plugins, [:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore, :ignore_stateless]
36 @config.expect :treat_as, {'int' => 'INT','short' => 'INT16','long' => 'INT','char' => 'INT8','uint32_t' => 'HEX32','const char*' => 'STRING'}
37 @cmock_generator_utils_complex = CMockGeneratorUtils.new(@config, {:unity_helper => @unity_helper, :A=>1, :B=>2})
38 end
39
40 after do
41 end
42
43 it "have set up internal accessors correctly on init" do
44 assert_equal(false, @cmock_generator_utils_simple.arrays)
45 assert_equal(false, @cmock_generator_utils_simple.cexception)
46 end
47
48 it "have set up internal accessors correctly on init, complete with passed helpers" do
49 assert_equal(true, @cmock_generator_utils_complex.arrays)
50 assert_equal(true, @cmock_generator_utils_complex.cexception)
51 end
52
53 it "detect pointers and strings" do
54 assert_equal(false, @cmock_generator_utils_simple.ptr_or_str?('int'))
55 assert_equal(true, @cmock_generator_utils_simple.ptr_or_str?('int*'))
56 assert_equal(true, @cmock_generator_utils_simple.ptr_or_str?('char*'))
57 end
58
59 it "add code for a base expectation with no plugins" do
60 expected =
61 " CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" +
62 " CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" +
63 " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n" +
64 " memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" +
65 " Mock.Apple_CallInstance = CMock_Guts_MemChain(Mock.Apple_CallInstance, cmock_guts_index);\n" +
66 " cmock_call_instance->LineNumber = cmock_line;\n"
67 output = @cmock_generator_utils_simple.code_add_base_expectation("Apple")
68 assert_equal(expected, output)
69 end
70
71 it "add code for a base expectation with all plugins" do
72 expected =
73 " CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" +
74 " CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" +
75 " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n" +
76 " memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" +
77 " Mock.Apple_CallInstance = CMock_Guts_MemChain(Mock.Apple_CallInstance, cmock_guts_index);\n" +
78 " Mock.Apple_IgnoreBool = (char)0;\n" +
79 " cmock_call_instance->LineNumber = cmock_line;\n" +
80 " cmock_call_instance->CallOrder = ++GlobalExpectCount;\n" +
81 " cmock_call_instance->ExceptionToThrow = CEXCEPTION_NONE;\n"
82 output = @cmock_generator_utils_complex.code_add_base_expectation("Apple", true)
83 assert_equal(expected, output)
84 end
85
86 it "add code for a base expectation with all plugins and ordering not supported" do
87 expected =
88 " CMOCK_MEM_INDEX_TYPE cmock_guts_index = CMock_Guts_MemNew(sizeof(CMOCK_Apple_CALL_INSTANCE));\n" +
89 " CMOCK_Apple_CALL_INSTANCE* cmock_call_instance = (CMOCK_Apple_CALL_INSTANCE*)CMock_Guts_GetAddressFor(cmock_guts_index);\n" +
90 " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringOutOfMemory);\n" +
91 " memset(cmock_call_instance, 0, sizeof(*cmock_call_instance));\n" +
92 " Mock.Apple_CallInstance = CMock_Guts_MemChain(Mock.Apple_CallInstance, cmock_guts_index);\n" +
93 " Mock.Apple_IgnoreBool = (char)0;\n" +
94 " cmock_call_instance->LineNumber = cmock_line;\n" +
95 " cmock_call_instance->ExceptionToThrow = CEXCEPTION_NONE;\n"
96 output = @cmock_generator_utils_complex.code_add_base_expectation("Apple", false)
97 assert_equal(expected, output)
98 end
99
100 it "add argument expectations for values when no array plugin" do
101 arg1 = { :name => "Orange", :const? => false, :type => 'int', :ptr? => false }
102 expected1 = " cmock_call_instance->Expected_Orange = Orange;\n"
103
104 arg2 = { :name => "Lemon", :const? => true, :type => 'const char*', :ptr? => false }
105 expected2 = " cmock_call_instance->Expected_Lemon = Lemon;\n"
106
107 arg3 = { :name => "Kiwi", :const? => false, :type => 'KIWI_T*', :ptr? => true }
108 expected3 = " cmock_call_instance->Expected_Kiwi = Kiwi;\n"
109
110 arg4 = { :name => "Lime", :const? => false, :type => 'LIME_T', :ptr? => false }
111 expected4 = " memcpy((void*)(&cmock_call_instance->Expected_Lime), (void*)(&Lime),\n" +
112 " sizeof(LIME_T[sizeof(Lime) == sizeof(LIME_T) ? 1 : -1])); /* add LIME_T to :treat_as_array if this causes an error */\n"
113
114 assert_equal(expected1, @cmock_generator_utils_simple.code_add_an_arg_expectation(arg1))
115 assert_equal(expected2, @cmock_generator_utils_simple.code_add_an_arg_expectation(arg2))
116 assert_equal(expected3, @cmock_generator_utils_simple.code_add_an_arg_expectation(arg3))
117 assert_equal(expected4, @cmock_generator_utils_simple.code_add_an_arg_expectation(arg4))
118 end
119
120 it "add argument expectations for values when array plugin enabled" do
121 arg1 = { :name => "Orange", :const? => false, :type => 'int', :ptr? => false }
122 expected1 = " cmock_call_instance->Expected_Orange = Orange;\n" +
123 " cmock_call_instance->IgnoreArg_Orange = 0;\n"
124
125 arg2 = { :name => "Lemon", :const? => true, :type => 'const char*', :ptr? => false }
126 expected2 = " cmock_call_instance->Expected_Lemon = Lemon;\n" +
127 " cmock_call_instance->Expected_Lemon_Depth = Lemon_Depth;\n" +
128 " cmock_call_instance->IgnoreArg_Lemon = 0;\n"
129
130 arg3 = { :name => "Kiwi", :const? => false, :type => 'KIWI_T*', :ptr? => true }
131 expected3 = " cmock_call_instance->Expected_Kiwi = Kiwi;\n" +
132 " cmock_call_instance->Expected_Kiwi_Depth = Kiwi_Depth;\n" +
133 " cmock_call_instance->IgnoreArg_Kiwi = 0;\n" +
134 " cmock_call_instance->ReturnThruPtr_Kiwi_Used = 0;\n"
135
136 arg4 = { :name => "Lime", :const? => false, :type => 'LIME_T', :ptr? => false }
137 expected4 = " memcpy((void*)(&cmock_call_instance->Expected_Lime), (void*)(&Lime),\n" +
138 " sizeof(LIME_T[sizeof(Lime) == sizeof(LIME_T) ? 1 : -1])); /* add LIME_T to :treat_as_array if this causes an error */\n" +
139 " cmock_call_instance->IgnoreArg_Lime = 0;\n"
140
141 assert_equal(expected1, @cmock_generator_utils_complex.code_add_an_arg_expectation(arg1))
142 assert_equal(expected2, @cmock_generator_utils_complex.code_add_an_arg_expectation(arg2, 'Lemon_Depth'))
143 assert_equal(expected3, @cmock_generator_utils_complex.code_add_an_arg_expectation(arg3, 'Lemon_Depth'))
144 assert_equal(expected4, @cmock_generator_utils_complex.code_add_an_arg_expectation(arg4))
145 end
146
147 it 'not have an argument loader when the function has no arguments' do
148 function = { :name => "Melon", :args_string => "void" }
149
150 assert_equal("", @cmock_generator_utils_complex.code_add_argument_loader(function))
151 end
152
153 it 'create an argument loader when the function has arguments' do
154 function = { :name => "Melon",
155 :args_string => "stuff",
156 :args => [test_arg[:int_ptr], test_arg[:mytype], test_arg[:string]]
157 }
158 expected = "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, stuff);\n" +
159 "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, stuff)\n{\n" +
160 " cmock_call_instance->Expected_MyIntPtr = MyIntPtr;\n" +
161 " memcpy((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType),\n" +
162 " sizeof(MY_TYPE[sizeof(MyMyType) == sizeof(MY_TYPE) ? 1 : -1])); /* add MY_TYPE to :treat_as_array if this causes an error */\n" +
163 " cmock_call_instance->Expected_MyStr = MyStr;\n" +
164 "}\n\n"
165 assert_equal(expected, @cmock_generator_utils_simple.code_add_argument_loader(function))
166 end
167
168 it 'create an argument loader when the function has arguments supporting arrays' do
169 function = { :name => "Melon",
170 :args_string => "stuff",
171 :args => [test_arg[:int_ptr], test_arg[:mytype], test_arg[:string]]
172 }
173 expected = "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, int* MyIntPtr, int MyIntPtr_Depth, const MY_TYPE MyMyType, const char* MyStr);\n" +
174 "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, int* MyIntPtr, int MyIntPtr_Depth, const MY_TYPE MyMyType, const char* MyStr)\n{\n" +
175 " cmock_call_instance->Expected_MyIntPtr = MyIntPtr;\n" +
176 " cmock_call_instance->Expected_MyIntPtr_Depth = MyIntPtr_Depth;\n" +
177 " cmock_call_instance->IgnoreArg_MyIntPtr = 0;\n" +
178 " cmock_call_instance->ReturnThruPtr_MyIntPtr_Used = 0;\n" +
179 " memcpy((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType),\n" +
180 " sizeof(MY_TYPE[sizeof(MyMyType) == sizeof(MY_TYPE) ? 1 : -1])); /* add MY_TYPE to :treat_as_array if this causes an error */\n" +
181 " cmock_call_instance->IgnoreArg_MyMyType = 0;\n" +
182 " cmock_call_instance->Expected_MyStr = MyStr;\n" +
183 " cmock_call_instance->IgnoreArg_MyStr = 0;\n" +
184 "}\n\n"
185 assert_equal(expected, @cmock_generator_utils_complex.code_add_argument_loader(function))
186 end
187
188 it 'create an argument loader when the function has pointer arguments supporting arrays' do
189 function = { :name => "Melon",
190 :args_string => "stuff",
191 :args => [test_arg[:const_ptr], test_arg[:double_ptr]]
192 }
193 expected = "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, int* const MyConstPtr, int MyConstPtr_Depth, int const** MyDoublePtr, int MyDoublePtr_Depth);\n" +
194 "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, int* const MyConstPtr, int MyConstPtr_Depth, int const** MyDoublePtr, int MyDoublePtr_Depth)\n{\n" +
195 " cmock_call_instance->Expected_MyConstPtr = MyConstPtr;\n" +
196 " cmock_call_instance->Expected_MyConstPtr_Depth = MyConstPtr_Depth;\n" +
197 " cmock_call_instance->IgnoreArg_MyConstPtr = 0;\n" +
198 " cmock_call_instance->ReturnThruPtr_MyConstPtr_Used = 0;\n" +
199 " cmock_call_instance->Expected_MyDoublePtr = MyDoublePtr;\n" +
200 " cmock_call_instance->Expected_MyDoublePtr_Depth = MyDoublePtr_Depth;\n" +
201 " cmock_call_instance->IgnoreArg_MyDoublePtr = 0;\n" +
202 "}\n\n"
203 assert_equal(expected, @cmock_generator_utils_complex.code_add_argument_loader(function))
204 end
205
206 it "not call argument loader if there are no arguments to actually use for this function" do
207 function = { :name => "Pineapple", :args_string => "void" }
208
209 assert_equal("", @cmock_generator_utils_complex.code_call_argument_loader(function))
210 end
211
212 it 'call an argument loader when the function has arguments' do
213 function = { :name => "Pineapple",
214 :args_string => "stuff",
215 :args => [test_arg[:int_ptr], test_arg[:mytype], test_arg[:string]]
216 }
217 expected = " CMockExpectParameters_Pineapple(cmock_call_instance, MyIntPtr, MyMyType, MyStr);\n"
218 assert_equal(expected, @cmock_generator_utils_simple.code_call_argument_loader(function))
219 end
220
221 it 'call an argument loader when the function has arguments with arrays' do
222 function = { :name => "Pineapple",
223 :args_string => "stuff",
224 :args => [test_arg[:int_ptr], test_arg[:mytype], test_arg[:string]]
225 }
226 expected = " CMockExpectParameters_Pineapple(cmock_call_instance, MyIntPtr, 1, MyMyType, MyStr);\n"
227 assert_equal(expected, @cmock_generator_utils_complex.code_call_argument_loader(function))
228 end
229
230 it 'handle a simple assert when requested' do
231 function = { :name => 'Pear' }
232 arg = test_arg[:int]
233 expected = " {\n" +
234 " UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyInt);\n" +
235 " UNITY_TEST_ASSERT_EQUAL_INT(cmock_call_instance->Expected_MyInt, MyInt, cmock_line, CMockStringMismatch);\n" +
236 " }\n"
237 @unity_helper.expect :nil?, false
238 @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_INT', ''], ['int']
239 assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
240 end
241
242 it 'handle a pointer comparison when configured to do so' do
243 function = { :name => 'Pear' }
244 arg = test_arg[:int_ptr]
245 expected = " {\n" +
246 " UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyIntPtr);\n" +
247 " UNITY_TEST_ASSERT_EQUAL_PTR(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_line, CMockStringMismatch);\n" +
248 " }\n"
249 assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
250 end
251
252 it 'handle const char as string compares ' do
253 function = { :name => 'Pear' }
254 arg = test_arg[:string]
255 expected = " {\n" +
256 " UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyStr);\n" +
257 " UNITY_TEST_ASSERT_EQUAL_STRING(cmock_call_instance->Expected_MyStr, MyStr, cmock_line, CMockStringMismatch);\n" +
258 " }\n"
259 @unity_helper.expect :nil?, false
260 @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_STRING',''], ['const char*']
261 assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
262 end
263
264 it 'handle custom types as memory compares when we have no better way to do it' do
265 function = { :name => 'Pear' }
266 arg = test_arg[:mytype]
267 expected = " {\n" +
268 " UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
269 " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType), sizeof(MY_TYPE), cmock_line, CMockStringMismatch);\n" +
270 " }\n"
271 @unity_helper.expect :nil?, false
272 @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MEMORY','&'], ['MY_TYPE']
273 assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
274 end
275
276 it 'handle custom types with custom handlers when available, even if they do not support the extra message' do
277 function = { :name => 'Pear' }
278 arg = test_arg[:mytype]
279 expected = " {\n" +
280 " UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
281 " UNITY_TEST_ASSERT_EQUAL_MY_TYPE(cmock_call_instance->Expected_MyMyType, MyMyType, cmock_line, CMockStringMismatch);\n" +
282 " }\n"
283 @unity_helper.expect :nil?, false
284 @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE',''], ['MY_TYPE']
285 assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
286 end
287
288 it 'handle pointers to custom types with array handlers, even if the array extension is turned off' do
289 function = { :name => 'Pear' }
290 arg = test_arg[:mytype]
291 expected = " {\n" +
292 " UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
293 " UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1, cmock_line, CMockStringMismatch);\n" +
294 " }\n"
295 @unity_helper.expect :nil?, false
296 @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY','&'], ['MY_TYPE']
297 assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
298 end
299
300 it 'handle a simple assert when requested with array plugin enabled' do
301 function = { :name => 'Pear' }
302 arg = test_arg[:int]
303 expected = " if (!cmock_call_instance->IgnoreArg_MyInt)\n" +
304 " {\n" +
305 " UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyInt);\n" +
306 " UNITY_TEST_ASSERT_EQUAL_INT(cmock_call_instance->Expected_MyInt, MyInt, cmock_line, CMockStringMismatch);\n" +
307 " }\n"
308 @unity_helper.expect :nil?, false
309 @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_INT',''], ['int']
310 assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
311 end
312
313 it 'handle an array comparison with array plugin enabled' do
314 function = { :name => 'Pear' }
315 arg = test_arg[:int_ptr]
316 expected = " if (!cmock_call_instance->IgnoreArg_MyIntPtr)\n" +
317 " {\n" +
318 " UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyIntPtr);\n" +
319 " if (cmock_call_instance->Expected_MyIntPtr == NULL)\n" +
320 " { UNITY_TEST_ASSERT_NULL(MyIntPtr, cmock_line, CMockStringExpNULL); }\n" +
321 " else if (cmock_call_instance->Expected_MyIntPtr_Depth == 0)\n" +
322 " { UNITY_TEST_ASSERT_EQUAL_PTR(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_line, CMockStringMismatch); }\n" +
323 " else\n" +
324 " { UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_call_instance->Expected_MyIntPtr_Depth, cmock_line, CMockStringMismatch); }\n" +
325 " }\n"
326 @unity_helper.expect :nil?, false
327 @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_INT_ARRAY',''], ['int*']
328 assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
329 end
330
331 it 'handle const char as string compares with array plugin enabled' do
332 function = { :name => 'Pear' }
333 arg = test_arg[:string]
334 expected = " if (!cmock_call_instance->IgnoreArg_MyStr)\n" +
335 " {\n" +
336 " UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyStr);\n" +
337 " UNITY_TEST_ASSERT_EQUAL_STRING(cmock_call_instance->Expected_MyStr, MyStr, cmock_line, CMockStringMismatch);\n" +
338 " }\n"
339 @unity_helper.expect :nil?, false
340 @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_STRING',''], ['const char*']
341 assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
342 end
343
344 it 'handle custom types as memory compares when we have no better way to do it with array plugin enabled' do
345 function = { :name => 'Pear' }
346 arg = test_arg[:mytype]
347 expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n" +
348 " {\n" +
349 " UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
350 " if (cmock_call_instance->Expected_MyMyType == NULL)\n" +
351 " { UNITY_TEST_ASSERT_NULL(MyMyType, cmock_line, CMockStringExpNULL); }\n" +
352 " else\n" +
353 " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(cmock_call_instance->Expected_MyMyType), (void*)(MyMyType), sizeof(MY_TYPE), 1, cmock_line, CMockStringMismatch); }\n" +
354 " }\n"
355 @unity_helper.expect :nil?, false
356 @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY', ''], ['MY_TYPE']
357 assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
358 end
359
360 it 'handle custom types with custom handlers when available, even if they do not support the extra message with array plugin enabled' do
361 function = { :name => 'Pear' }
362 arg = test_arg[:mytype]
363 expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n" +
364 " {\n" +
365 " UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
366 " UNITY_TEST_ASSERT_EQUAL_MY_TYPE(cmock_call_instance->Expected_MyMyType, MyMyType, cmock_line, CMockStringMismatch);\n" +
367 " }\n"
368 @unity_helper.expect :nil?, false
369 @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE', ''], ['MY_TYPE']
370 assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
371 end
372
373 it 'handle custom types with array handlers when array plugin is enabled' do
374 function = { :name => 'Pear' }
375 arg = test_arg[:mytype_ptr]
376 expected = " if (!cmock_call_instance->IgnoreArg_MyMyTypePtr)\n" +
377 " {\n" +
378 " UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyTypePtr);\n" +
379 " if (cmock_call_instance->Expected_MyMyTypePtr == NULL)\n" +
380 " { UNITY_TEST_ASSERT_NULL(MyMyTypePtr, cmock_line, CMockStringExpNULL); }\n" +
381 " else if (cmock_call_instance->Expected_MyMyTypePtr_Depth == 0)\n" +
382 " { UNITY_TEST_ASSERT_EQUAL_PTR(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_line, CMockStringMismatch); }\n" +
383 " else\n" +
384 " { UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_call_instance->Expected_MyMyTypePtr_Depth, cmock_line, CMockStringMismatch); }\n" +
385 " }\n"
386 @unity_helper.expect :nil?, false
387 @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY', ''], ['MY_TYPE*']
388 assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
389 end
390
391 it 'handle custom types with array handlers when array plugin is enabled for non-array types' do
392 function = { :name => 'Pear' }
393 arg = test_arg[:mytype]
394 expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n" +
395 " {\n" +
396 " UNITY_SET_DETAILS(CMockString_Pear,CMockString_MyMyType);\n" +
397 " UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1, cmock_line, CMockStringMismatch);\n" +
398 " }\n"
399 @unity_helper.expect :nil?, false
400 @unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY', '&'], ['MY_TYPE']
401 assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
402 end
403 end