From 436ffe0fee042cd32e728dc15b1d289318f89d26 Mon Sep 17 00:00:00 2001 From: mvandervoord Date: Tue, 30 Mar 2010 03:36:08 +0000 Subject: [PATCH] - cleaned up an error or two when using memory compares - can use array assertions for non-arrays - can sometimes get away with normal assertions for arrays (doesn't yet go through array, just first element) - made parsing_challenges test better git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@159 bf332499-1b4d-0410-844d-d2d48d5cc64c --- lib/cmock_generator_utils.rb | 68 +++++++++++-------- lib/cmock_unityhelper_parser.rb | 12 +++- .../test_interactions/parsing_challenges.yml | 26 ++++--- test/unit/cmock_generator_utils_test.rb | 50 +++++++------- test/unit/cmock_unityhelper_parser_test.rb | 44 ++++++++++-- 5 files changed, 128 insertions(+), 72 deletions(-) diff --git a/lib/cmock_generator_utils.rb b/lib/cmock_generator_utils.rb index ce92a27..71f948c 100644 --- a/lib/cmock_generator_utils.rb +++ b/lib/cmock_generator_utils.rb @@ -85,78 +85,86 @@ class CMockGeneratorUtils arg_name = arg[:name] expected = "cmock_call_instance->Expected_#{arg_name}" unity_func = if ((arg[:ptr?]) and (@ptr_handling == :compare_ptr)) - "UNITY_TEST_ASSERT_EQUAL_HEX32" + ["UNITY_TEST_ASSERT_EQUAL_HEX32", ''] else - (@helpers.nil? or @helpers[:unity_helper].nil?) ? "UNITY_TEST_ASSERT_EQUAL" : @helpers[:unity_helper].get_helper(c_type) + (@helpers.nil? or @helpers[:unity_helper].nil?) ? ["UNITY_TEST_ASSERT_EQUAL",''] : @helpers[:unity_helper].get_helper(c_type) end unity_msg = ", \"Function '#{function[:name]}' called with unexpected value for argument '#{arg_name}'.\"" - return c_type, arg_name, expected, unity_func, unity_msg + return c_type, arg_name, expected, unity_func[0], unity_func[1], unity_msg end def code_verify_an_arg_expectation_with_no_arrays(function, arg) - c_type, arg_name, expected, unity_func, unity_msg = lookup_expect_type(function, arg) + c_type, arg_name, expected, unity_func, pre, unity_msg = lookup_expect_type(function, arg) case(unity_func) when "UNITY_TEST_ASSERT_EQUAL_MEMORY" full_expected = (expected =~ /^\*/) ? expected.slice(1..-1) : "(&#{expected})" return " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)#{full_expected}, (void*)(&#{arg_name}), sizeof(#{c_type}), cmock_line#{unity_msg});\n" when "UNITY_TEST_ASSERT_EQUAL_MEMORY" - [ " if (#{expected} == NULL)", - " { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, NULL); }", + [ " if (#{pre}#{expected} == NULL)", + " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, NULL); }", " else", - " { UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{expected}), (void*)#{arg_name}, sizeof(#{c_type.sub('*','')}), cmock_line#{unity_msg}); }\n"].join("\n") + " { UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), cmock_line#{unity_msg}); }\n"].join("\n") when /_ARRAY/ - [ " if (#{expected} == NULL)", - " { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, NULL); }", + [ " if (#{pre}#{expected} == NULL)", + " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, NULL); }", " else", - " { #{unity_func}(#{expected}, #{arg_name}, 1, cmock_line, NULL); }\n"].join("\n") + " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, 1, cmock_line, NULL); }\n"].join("\n") else - return " #{unity_func}(#{expected}, #{arg_name}, cmock_line#{unity_msg});\n" + return " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line#{unity_msg});\n" end end def code_verify_an_arg_expectation_with_normal_arrays(function, arg) - c_type, arg_name, expected, unity_func, unity_msg = lookup_expect_type(function, arg) + c_type, arg_name, expected, unity_func, pre, unity_msg = lookup_expect_type(function, arg) depth_name = (arg[:ptr?]) ? "cmock_call_instance->Expected_#{arg_name}_Depth" : 1 case(unity_func) when "UNITY_TEST_ASSERT_EQUAL_MEMORY" full_expected = (expected =~ /^\*/) ? expected.slice(1..-1) : "(&#{expected})" return " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)#{full_expected}, (void*)(&#{arg_name}), sizeof(#{c_type}), cmock_line#{unity_msg});\n" when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY" - [ " if (#{expected} == NULL)", - " { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, NULL); }", + [ " if (#{pre}#{expected} == NULL)", + " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, NULL); }", " else", - " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{expected}), (void*)#{arg_name}, sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line#{unity_msg}); }\n"].compact.join("\n") + " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line#{unity_msg}); }\n"].compact.join("\n") when /_ARRAY/ - [ " if (#{expected} == NULL)", - " { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, NULL); }", - " else", - " { #{unity_func}(#{expected}, #{arg_name}, #{depth_name}, cmock_line, NULL); }\n"].compact.join("\n") + if (pre == '&') + " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, NULL);\n" + else + [ " if (#{pre}#{expected} == NULL)", + " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, NULL); }", + " else", + " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, NULL); }\n"].compact.join("\n") + end else - return " #{unity_func}(#{expected}, #{arg_name}, cmock_line#{unity_msg});\n" + return " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line#{unity_msg});\n" end end def code_verify_an_arg_expectation_with_smart_arrays(function, arg) - c_type, arg_name, expected, unity_func, unity_msg = lookup_expect_type(function, arg) + c_type, arg_name, expected, unity_func, pre, unity_msg = lookup_expect_type(function, arg) depth_name = (arg[:ptr?]) ? "cmock_call_instance->Expected_#{arg_name}_Depth" : 1 case(unity_func) when "UNITY_TEST_ASSERT_EQUAL_MEMORY" full_expected = (expected =~ /^\*/) ? expected.slice(1..-1) : "(&#{expected})" return " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)#{full_expected}, (void*)(&#{arg_name}), sizeof(#{c_type}), cmock_line#{unity_msg});\n" when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY" - [ " if (#{expected} == NULL)", + [ " if (#{pre}#{expected} == NULL)", " { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, NULL); }", - ((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_HEX32(#{expected}, #{arg_name}, cmock_line, NULL); }" : nil), + ((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_HEX32(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, NULL); }" : nil), " else", - " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{expected}), (void*)#{arg_name}, sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line#{unity_msg}); }\n"].compact.join("\n") + " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line#{unity_msg}); }\n"].compact.join("\n") when /_ARRAY/ - [ " if (#{expected} == NULL)", - " { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, NULL); }", - ((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_HEX32(#{expected}, #{arg_name}, cmock_line, NULL); }" : nil), - " else", - " { #{unity_func}(#{expected}, #{arg_name}, #{depth_name}, cmock_line, NULL); }\n"].compact.join("\n") + if (pre == '&') + " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, NULL);\n" + else + [ " if (#{pre}#{expected} == NULL)", + " { UNITY_TEST_ASSERT_NULL(#{pre}#{arg_name}, cmock_line, NULL); }", + ((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_HEX32(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, NULL); }" : nil), + " else", + " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, NULL); }\n"].compact.join("\n") + end else - return " #{unity_func}(#{expected}, #{arg_name}, cmock_line#{unity_msg});\n" + return " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line#{unity_msg});\n" end end diff --git a/lib/cmock_unityhelper_parser.rb b/lib/cmock_unityhelper_parser.rb index 8f4a5ee..c976765 100644 --- a/lib/cmock_unityhelper_parser.rb +++ b/lib/cmock_unityhelper_parser.rb @@ -10,9 +10,16 @@ class CMockUnityHelperParser def get_helper(ctype) lookup = ctype.gsub(/(?:^|(\S?)(\s*)|(\W))const(?:$|(\s*)(\S)|(\W))/,'\1\3\5\6').strip.gsub(/\s+/,'_') - return @c_types[lookup] if (@c_types[lookup]) + return [@c_types[lookup], ''] if (@c_types[lookup]) + if (lookup =~ /\*$/) + lookup = lookup.gsub(/\*$/,'') + return [@c_types[lookup], '*'] if (@c_types[lookup]) + else + lookup = lookup + '*' + return [@c_types[lookup], '&'] if (@c_types[lookup]) + end raise("Don't know how to test #{ctype} and memory tests are disabled!") unless @config.memcmp_if_unknown - return @fallback + return [@fallback, ''] end private ########################### @@ -21,6 +28,7 @@ class CMockUnityHelperParser c_types = {} @config.treat_as.each_pair do |ctype, expecttype| c_types[ctype.gsub(/\s+/,'_')] = "UNITY_TEST_ASSERT_EQUAL_#{expecttype}" + c_types[ctype.gsub(/\s+/,'_')+'*'] = "UNITY_TEST_ASSERT_EQUAL_#{expecttype}_ARRAY" end c_types end diff --git a/test/system/test_interactions/parsing_challenges.yml b/test/system/test_interactions/parsing_challenges.yml index 16682ee..d2e9cdb 100644 --- a/test/system/test_interactions/parsing_challenges.yml +++ b/test/system/test_interactions/parsing_challenges.yml @@ -73,6 +73,7 @@ :code: | int A, B, C; + unsigned int *pA, *pB, *pC; U16* exercise_return_pointers(int a) { @@ -118,10 +119,19 @@ :tests: :common: | - void setUp(void) {} - void tearDown(void) {} - extern int A, B, C; + extern unsigned int *pA, *pB, *pC; + + void setUp(void) + { + A = 100; + B = 200; + C = 300; + pA = (unsigned int*)(&A); + pB = (unsigned int*)(&B); + pC = (unsigned int*)(&C); + } + void tearDown(void) {} :units: - :pass: TRUE :should: 'execute simple pointer return value check' @@ -169,11 +179,11 @@ :code: | test() { - ptr_ptr_return1_ExpectAndReturn((unsigned int**)A, (unsigned int**)B); - ptr_ptr_return2_ExpectAndReturn((unsigned int**)A, (unsigned int**)B); - ptr_ptr_return3_ExpectAndReturn((unsigned int**)A, (unsigned int**)B); - ptr_ptr_return4_ExpectAndReturn((unsigned int**)A, (unsigned int**)B); - exercise_double_pointers((unsigned int)A); + ptr_ptr_return1_ExpectAndReturn(&pA, &pB); + ptr_ptr_return2_ExpectAndReturn(&pA, &pB); + ptr_ptr_return3_ExpectAndReturn(&pA, &pB); + ptr_ptr_return4_ExpectAndReturn(&pA, &pB); + exercise_double_pointers((unsigned int)(&pA)); } - :pass: TRUE diff --git a/test/unit/cmock_generator_utils_test.rb b/test/unit/cmock_generator_utils_test.rb index 09068c1..35976c5 100644 --- a/test/unit/cmock_generator_utils_test.rb +++ b/test/unit/cmock_generator_utils_test.rb @@ -171,7 +171,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase function = { :name => 'Pear' } arg = test_arg[:int] expected = " UNITY_TEST_ASSERT_EQUAL_INT(cmock_call_instance->Expected_MyInt, MyInt, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyInt'.\");\n" - @unity_helper.expect.get_helper('int').returns('UNITY_TEST_ASSERT_EQUAL_INT') + @unity_helper.expect.get_helper('int').returns(['UNITY_TEST_ASSERT_EQUAL_INT','']) assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg)) end @@ -186,7 +186,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase function = { :name => 'Pear' } arg = test_arg[:string] expected = " UNITY_TEST_ASSERT_EQUAL_STRING(cmock_call_instance->Expected_MyStr, MyStr, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyStr'.\");\n" - @unity_helper.expect.get_helper('char*').returns('UNITY_TEST_ASSERT_EQUAL_STRING') + @unity_helper.expect.get_helper('char*').returns(['UNITY_TEST_ASSERT_EQUAL_STRING','']) assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg)) end @@ -194,7 +194,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase function = { :name => 'Pear' } arg = test_arg[:mytype] expected = " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType), sizeof(MY_TYPE), cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n" - @unity_helper.expect.get_helper('MY_TYPE').returns('UNITY_TEST_ASSERT_EQUAL_MEMORY') + @unity_helper.expect.get_helper('MY_TYPE').returns(['UNITY_TEST_ASSERT_EQUAL_MEMORY','']) assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg)) end @@ -202,24 +202,23 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase function = { :name => 'Pear' } arg = test_arg[:mytype] expected = " UNITY_TEST_ASSERT_EQUAL_MY_TYPE(cmock_call_instance->Expected_MyMyType, MyMyType, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n" - @unity_helper.expect.get_helper('MY_TYPE').returns('UNITY_TEST_ASSERT_EQUAL_MY_TYPE') + @unity_helper.expect.get_helper('MY_TYPE').returns(['UNITY_TEST_ASSERT_EQUAL_MY_TYPE','']) assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg)) end - #This is not yet supported - # should 'handle pointers to custom types with array handlers, even if the array extension is turned off' do - # function = { :name => 'Pear' } - # arg = test_arg[:mytype] - # expected = " UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1);\n" - # @unity_helper.expect.get_helper('MY_TYPE').returns('UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY') - # assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg)) - # end + should 'handle pointers to custom types with array handlers, even if the array extension is turned off' do + function = { :name => 'Pear' } + arg = test_arg[:mytype] + expected = " UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1, cmock_line, NULL);\n" + @unity_helper.expect.get_helper('MY_TYPE').returns(['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY','&']) + assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg)) + end should 'handle a simple assert when requested with array plugin enabled' do function = { :name => 'Pear' } arg = test_arg[:int] expected = " UNITY_TEST_ASSERT_EQUAL_INT(cmock_call_instance->Expected_MyInt, MyInt, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyInt'.\");\n" - @unity_helper.expect.get_helper('int').returns('UNITY_TEST_ASSERT_EQUAL_INT') + @unity_helper.expect.get_helper('int').returns(['UNITY_TEST_ASSERT_EQUAL_INT','']) assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg)) end @@ -232,7 +231,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase " { UNITY_TEST_ASSERT_EQUAL_HEX32(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_line, NULL); }\n" + " else\n" + " { UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(cmock_call_instance->Expected_MyIntPtr, MyIntPtr, cmock_call_instance->Expected_MyIntPtr_Depth, cmock_line, NULL); }\n" - @unity_helper.expect.get_helper('int*').returns('UNITY_TEST_ASSERT_EQUAL_INT_ARRAY') + @unity_helper.expect.get_helper('int*').returns(['UNITY_TEST_ASSERT_EQUAL_INT_ARRAY','']) assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg)) end @@ -240,7 +239,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase function = { :name => 'Pear' } arg = test_arg[:string] expected = " UNITY_TEST_ASSERT_EQUAL_STRING(cmock_call_instance->Expected_MyStr, MyStr, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyStr'.\");\n" - @unity_helper.expect.get_helper('char*').returns('UNITY_TEST_ASSERT_EQUAL_STRING') + @unity_helper.expect.get_helper('char*').returns(['UNITY_TEST_ASSERT_EQUAL_STRING','']) assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg)) end @@ -248,7 +247,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase function = { :name => 'Pear' } arg = test_arg[:mytype] expected = " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType), sizeof(MY_TYPE), cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n" - @unity_helper.expect.get_helper('MY_TYPE').returns('UNITY_TEST_ASSERT_EQUAL_MEMORY') + @unity_helper.expect.get_helper('MY_TYPE').returns(['UNITY_TEST_ASSERT_EQUAL_MEMORY','']) assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg)) end @@ -256,7 +255,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase function = { :name => 'Pear' } arg = test_arg[:mytype] expected = " UNITY_TEST_ASSERT_EQUAL_MY_TYPE(cmock_call_instance->Expected_MyMyType, MyMyType, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n" - @unity_helper.expect.get_helper('MY_TYPE').returns('UNITY_TEST_ASSERT_EQUAL_MY_TYPE') + @unity_helper.expect.get_helper('MY_TYPE').returns(['UNITY_TEST_ASSERT_EQUAL_MY_TYPE','']) assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg)) end @@ -269,16 +268,15 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase " { UNITY_TEST_ASSERT_EQUAL_HEX32(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_line, NULL); }\n" + " else\n" + " { UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(cmock_call_instance->Expected_MyMyTypePtr, MyMyTypePtr, cmock_call_instance->Expected_MyMyTypePtr_Depth, cmock_line, NULL); }\n" - @unity_helper.expect.get_helper('MY_TYPE*').returns('UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY') + @unity_helper.expect.get_helper('MY_TYPE*').returns(['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY','']) assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg)) end - #This is not yet supported -# should 'handle custom types with array handlers when array plugin is enabled for non-array types' do -# function = { :name => 'Pear' } -# arg = test_arg[:mytype] -# expected = " UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1);\n" -# @unity_helper.expect.get_helper('MY_TYPE').returns('UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY') -# assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg)) -# end + should 'handle custom types with array handlers when array plugin is enabled for non-array types' do + function = { :name => 'Pear' } + arg = test_arg[:mytype] + expected = " UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY(&cmock_call_instance->Expected_MyMyType, &MyMyType, 1, cmock_line, NULL);\n" + @unity_helper.expect.get_helper('MY_TYPE').returns(['UNITY_TEST_ASSERT_EQUAL_MY_TYPE_ARRAY','&']) + assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg)) + end end diff --git a/test/unit/cmock_unityhelper_parser_test.rb b/test/unit/cmock_unityhelper_parser_test.rb index 1e6aefd..cdae738 100644 --- a/test/unit/cmock_unityhelper_parser_test.rb +++ b/test/unit/cmock_unityhelper_parser_test.rb @@ -88,6 +88,8 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase expected = { "UINT" => "UNITY_TEST_ASSERT_EQUAL_HEX32", "unsigned_long" => "UNITY_TEST_ASSERT_EQUAL_HEX64", + "UINT*" => "UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY", + "unsigned_long*"=> "UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY", } @config.expects.plugins.returns([]) #not :array @config.expects.treat_as.returns(pairs) @@ -105,6 +107,8 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase expected = { "char*" => "UNITY_TEST_ASSERT_EQUAL_STRING", "unsigned_int" => "UNITY_TEST_ASSERT_EQUAL_HEX32", + "char**" => "UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY", + "unsigned_int*" => "UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY", } @config.expects.plugins.returns([]) #not :array @config.expects.treat_as.returns(pairs) @@ -130,7 +134,7 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase ["UINT16*","UINT16_ARRAY"], ["const SPINACH","SPINACH"], ["LONG LONG","LONG_LONG"] ].each do |ctype, exptype| - assert_equal("UNITY_TEST_ASSERT_EQUAL_#{exptype}", @parser.get_helper(ctype)) + assert_equal(["UNITY_TEST_ASSERT_EQUAL_#{exptype}",''], @parser.get_helper(ctype)) end end @@ -145,9 +149,9 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase 'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH", } - ["UINT16","SPINACH_T","SALAD","PINEAPPLE"].each do |ctype| + ["UINT32","SPINACH_T","SALAD","PINEAPPLE"].each do |ctype| @config.expect.memcmp_if_unknown.returns(true) - assert_equal("UNITY_TEST_ASSERT_EQUAL_MEMORY", @parser.get_helper(ctype)) + assert_equal(["UNITY_TEST_ASSERT_EQUAL_MEMORY",''], @parser.get_helper(ctype)) end end @@ -162,12 +166,40 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase 'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH", } - ["UINT8*","SPINACH_T*"].each do |ctype| + ["UINT32*","SPINACH_T*"].each do |ctype| @config.expect.memcmp_if_unknown.returns(true) - assert_equal("UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY", @parser.get_helper(ctype)) + assert_equal(["UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY",''], @parser.get_helper(ctype)) end end + should "return the array handler if we cannot find the normal handler" do + @config.expects.plugins.returns([]) #not :array + @config.expects.treat_as.returns({}) + @config.expect.load_unity_helper.returns("") + @parser = CMockUnityHelperParser.new(@config) + @parser.c_types = { + 'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8", + 'UINT16*' => "UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY", + 'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH", + } + + assert_equal(["UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY",'&'], @parser.get_helper("UINT16")) + end + + should "return the normal handler if we cannot find the array handler" do + @config.expects.plugins.returns([]) #not :array + @config.expects.treat_as.returns({}) + @config.expect.load_unity_helper.returns("") + @parser = CMockUnityHelperParser.new(@config) + @parser.c_types = { + 'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8", + 'UINT16' => "UNITY_TEST_ASSERT_EQUAL_UINT16", + 'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH", + } + + assert_equal(["UNITY_TEST_ASSERT_EQUAL_UINT8",'*'], @parser.get_helper("UINT8*")) + end + should "raise error when asked to fetch helper of type not on my list and not allowed to mem check" do @config.expects.plugins.returns([]) #not :array @config.expects.treat_as.returns({}) @@ -176,7 +208,7 @@ class CMockUnityHelperParserTest < Test::Unit::TestCase @parser = CMockUnityHelperParser.new(@config) @parser.c_types = { 'UINT8' => "UNITY_TEST_ASSERT_EQUAL_UINT8", - 'UINT16*' => "UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY", + 'UINT32*' => "UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY", 'SPINACH' => "UNITY_TEST_ASSERT_EQUAL_SPINACH", }