resolved conflicts

This commit is contained in:
Mark VanderVoord
2014-03-17 11:14:32 -04:00
parent 4f2dd38b6c
commit fcc6a40581
2 changed files with 29 additions and 31 deletions
+28 -30
View File
@@ -2,7 +2,7 @@
# CMock Project - Automatic Mock Generation for C # CMock Project - Automatic Mock Generation for C
# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams # Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
# [Released under MIT License. Please refer to license.txt for details] # [Released under MIT License. Please refer to license.txt for details]
# ========================================== # ==========================================
class CMockGeneratorUtils class CMockGeneratorUtils
@@ -14,12 +14,13 @@ class CMockGeneratorUtils
@ordered = @config.enforce_strict_ordering @ordered = @config.enforce_strict_ordering
@arrays = @config.plugins.include? :array @arrays = @config.plugins.include? :array
@cexception = @config.plugins.include? :cexception @cexception = @config.plugins.include? :cexception
@expect_any = @config.plugins.include? :expect_any_args
@return_thru_ptr = @config.plugins.include? :return_thru_ptr @return_thru_ptr = @config.plugins.include? :return_thru_ptr
@ignore_arg = @config.plugins.include? :ignore_arg @ignore_arg = @config.plugins.include? :ignore_arg
@treat_as = @config.treat_as @treat_as = @config.treat_as
@helpers = helpers @helpers = helpers
end end
def code_verify_an_arg_expectation(function, arg) def code_verify_an_arg_expectation(function, arg)
if (@arrays) if (@arrays)
case(@ptr_handling) case(@ptr_handling)
@@ -40,37 +41,38 @@ class CMockGeneratorUtils
lines << " cmock_call_instance->LineNumber = cmock_line;\n" lines << " cmock_call_instance->LineNumber = cmock_line;\n"
lines << " cmock_call_instance->CallOrder = ++GlobalExpectCount;\n" if (@ordered and global_ordering_supported) lines << " cmock_call_instance->CallOrder = ++GlobalExpectCount;\n" if (@ordered and global_ordering_supported)
lines << " cmock_call_instance->ExceptionToThrow = CEXCEPTION_NONE;\n" if (@cexception) lines << " cmock_call_instance->ExceptionToThrow = CEXCEPTION_NONE;\n" if (@cexception)
lines << " cmock_call_instance->IgnoreMode = CMOCK_ARG_ALL;\n" if (@expect_any)
lines lines
end end
def code_add_an_arg_expectation(arg, depth=1) def code_add_an_arg_expectation(arg, depth=1)
lines = code_assign_argument_quickly("cmock_call_instance->Expected_#{arg[:name]}", arg) lines = code_assign_argument_quickly("cmock_call_instance->Expected_#{arg[:name]}", arg)
lines << " cmock_call_instance->Expected_#{arg[:name]}_Depth = #{arg[:name]}_Depth;\n" if (@arrays and (depth.class == String)) lines << " cmock_call_instance->Expected_#{arg[:name]}_Depth = #{arg[:name]}_Depth;\n" if (@arrays and (depth.class == String))
lines << " cmock_call_instance->IgnoreArg_#{arg[:name]} = 0;\n" if (@ignore_arg) lines << " cmock_call_instance->IgnoreArg_#{arg[:name]} = 0;\n" if (@ignore_arg)
lines << " cmock_call_instance->ReturnThruPtr_#{arg[:name]}_Used = 0;\n" if (@return_thru_ptr and ptr_or_str?(arg[:type]) and not arg[:const?]) lines << " cmock_call_instance->ReturnThruPtr_#{arg[:name]}_Used = 0;\n" if (@return_thru_ptr and ptr_or_str?(arg[:type]) and not arg[:const?])
lines lines
end end
def code_assign_argument_quickly(dest, arg) def code_assign_argument_quickly(dest, arg)
if (arg[:ptr?] or @treat_as.include?(arg[:type])) if (arg[:ptr?] or @treat_as.include?(arg[:type]))
" #{dest} = #{arg[:const?] ? "(#{arg[:type]})" : ''}#{arg[:name]};\n" " #{dest} = #{arg[:const?] ? "(#{arg[:type]})" : ''}#{arg[:name]};\n"
else else
" memcpy(&#{dest}, &#{arg[:name]}, sizeof(#{arg[:type]}));\n" " memcpy(&#{dest}, &#{arg[:name]}, sizeof(#{arg[:type]}));\n"
end end
end end
def code_add_argument_loader(function) def code_add_argument_loader(function)
if (function[:args_string] != "void") if (function[:args_string] != "void")
if (@arrays) if (@arrays)
args_string = function[:args].map do |m| args_string = function[:args].map do |m|
const_str = m[ :const? ] ? 'const ' : '' const_str = m[ :const? ] ? 'const ' : ''
m[:ptr?] ? "#{const_str}#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{const_str}#{m[:type]} #{m[:name]}" m[:ptr?] ? "#{const_str}#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{const_str}#{m[:type]} #{m[:name]}"
end.join(', ') end.join(', ')
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{args_string})\n{\n" + "void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{args_string})\n{\n" +
function[:args].inject("") { |all, arg| all + code_add_an_arg_expectation(arg, (arg[:ptr?] ? "#{arg[:name]}_Depth" : 1) ) } + function[:args].inject("") { |all, arg| all + code_add_an_arg_expectation(arg, (arg[:ptr?] ? "#{arg[:name]}_Depth" : 1) ) } +
"}\n\n" "}\n\n"
else else
"void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{function[:args_string]})\n{\n" + "void CMockExpectParameters_#{function[:name]}(CMOCK_#{function[:name]}_CALL_INSTANCE* cmock_call_instance, #{function[:args_string]})\n{\n" +
function[:args].inject("") { |all, arg| all + code_add_an_arg_expectation(arg) } + function[:args].inject("") { |all, arg| all + code_add_an_arg_expectation(arg) } +
"}\n\n" "}\n\n"
end end
@@ -78,25 +80,25 @@ class CMockGeneratorUtils
"" ""
end end
end end
def code_call_argument_loader(function) def code_call_argument_loader(function)
if (function[:args_string] != "void") if (function[:args_string] != "void")
args = function[:args].map do |m| args = function[:args].map do |m|
(@arrays and m[:ptr?]) ? "#{m[:name]}, 1" : m[:name] (@arrays and m[:ptr?]) ? "#{m[:name]}, 1" : m[:name]
end end
" CMockExpectParameters_#{function[:name]}(cmock_call_instance, #{args.join(', ')});\n" " CMockExpectParameters_#{function[:name]}(cmock_call_instance, #{args.join(', ')});\n"
else else
"" ""
end end
end end
def ptr_or_str?(arg_type) def ptr_or_str?(arg_type)
return (arg_type.include? '*' or return (arg_type.include? '*' or
@treat_as.fetch(arg_type, "").include? '*') @treat_as.fetch(arg_type, "").include? '*')
end end
#private ###################### #private ######################
def lookup_expect_type(function, arg) def lookup_expect_type(function, arg)
c_type = arg[:type] c_type = arg[:type]
arg_name = arg[:name] arg_name = arg[:name]
@@ -110,7 +112,7 @@ class CMockGeneratorUtils
unity_msg = "Function '#{function[:name]}' called with unexpected value for argument '#{arg_name}'." unity_msg = "Function '#{function[:name]}' called with unexpected value for argument '#{arg_name}'."
return c_type, arg_name, expected, ignore, unity_func[0], unity_func[1], unity_msg return c_type, arg_name, expected, ignore, unity_func[0], unity_func[1], unity_msg
end end
def code_verify_an_arg_expectation_with_no_arrays(function, arg) def code_verify_an_arg_expectation_with_no_arrays(function, arg)
c_type, arg_name, expected, ignore, unity_func, pre, unity_msg = lookup_expect_type(function, arg) c_type, arg_name, expected, ignore, unity_func, pre, unity_msg = lookup_expect_type(function, arg)
lines = "" lines = ""
@@ -135,12 +137,12 @@ class CMockGeneratorUtils
lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, 1, cmock_line, \"#{unity_msg}\"); }\n" lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, 1, cmock_line, \"#{unity_msg}\"); }\n"
end end
else else
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\");\n" lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\");\n"
end end
lines << " }\n" lines << " }\n"
lines lines
end end
def code_verify_an_arg_expectation_with_normal_arrays(function, arg) def code_verify_an_arg_expectation_with_normal_arrays(function, arg)
c_type, arg_name, expected, ignore, unity_func, pre, unity_msg = lookup_expect_type(function, arg) c_type, arg_name, expected, ignore, unity_func, pre, unity_msg = lookup_expect_type(function, arg)
depth_name = (arg[:ptr?]) ? "cmock_call_instance->Expected_#{arg_name}_Depth" : 1 depth_name = (arg[:ptr?]) ? "cmock_call_instance->Expected_#{arg_name}_Depth" : 1
@@ -166,12 +168,12 @@ class CMockGeneratorUtils
lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, \"#{unity_msg}\"); }\n" lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, \"#{unity_msg}\"); }\n"
end end
else else
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\");\n" lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\");\n"
end end
lines << " }\n" lines << " }\n"
lines lines
end end
def code_verify_an_arg_expectation_with_smart_arrays(function, arg) def code_verify_an_arg_expectation_with_smart_arrays(function, arg)
c_type, arg_name, expected, ignore, unity_func, pre, unity_msg = lookup_expect_type(function, arg) c_type, arg_name, expected, ignore, unity_func, pre, unity_msg = lookup_expect_type(function, arg)
depth_name = (arg[:ptr?]) ? "cmock_call_instance->Expected_#{arg_name}_Depth" : 1 depth_name = (arg[:ptr?]) ? "cmock_call_instance->Expected_#{arg_name}_Depth" : 1
@@ -183,15 +185,11 @@ class CMockGeneratorUtils
c_type_local = c_type.gsub(/\*$/,'') c_type_local = c_type.gsub(/\*$/,'')
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line, \"#{unity_msg}\");\n" lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type_local}), cmock_line, \"#{unity_msg}\");\n"
when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY" when "UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY"
if (pre == '&') lines << " if (#{pre}#{expected} == NULL)\n"
lines << " UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line, \"#{unity_msg}\");\n" lines << " { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, \"Expected NULL. #{unity_msg}\"); }\n"
else lines << ((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_PTR(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\"); }\n" : "")
lines << " if (#{pre}#{expected} == NULL)\n" lines << " else\n"
lines << " { UNITY_TEST_ASSERT_NULL(#{arg_name}, cmock_line, \"Expected NULL. #{unity_msg}\"); }\n" lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line, \"#{unity_msg}\"); }\n"
lines << ((depth_name != 1) ? " else if (#{depth_name} == 0)\n { UNITY_TEST_ASSERT_EQUAL_PTR(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\"); }\n" : "")
lines << " else\n"
lines << " { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(#{pre}#{expected}), (void*)(#{pre}#{arg_name}), sizeof(#{c_type.sub('*','')}), #{depth_name}, cmock_line, \"#{unity_msg}\"); }\n"
end
when /_ARRAY/ when /_ARRAY/
if (pre == '&') if (pre == '&')
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, \"#{unity_msg}\");\n" lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, \"#{unity_msg}\");\n"
@@ -203,10 +201,10 @@ class CMockGeneratorUtils
lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, \"#{unity_msg}\"); }\n" lines << " { #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, #{depth_name}, cmock_line, \"#{unity_msg}\"); }\n"
end end
else else
lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\");\n" lines << " #{unity_func}(#{pre}#{expected}, #{pre}#{arg_name}, cmock_line, \"#{unity_msg}\");\n"
end end
lines << " }\n" lines << " }\n"
lines lines
end end
end end
+1 -1
View File
@@ -279,7 +279,7 @@ class CMockGeneratorUtilsTest < Test::Unit::TestCase
should 'handle custom types as memory compares when we have no better way to do it with array plugin enabled' do should 'handle custom types as memory compares when we have no better way to do it with array plugin enabled' do
function = { :name => 'Pear' } function = { :name => 'Pear' }
arg = test_arg[:mytype] arg = test_arg[:mytype]
expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n {\n UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType), sizeof(MY_TYPE), 1, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\");\n }\n" expected = " if (!cmock_call_instance->IgnoreArg_MyMyType)\n {\n if (&cmock_call_instance->Expected_MyMyType == NULL)\n { UNITY_TEST_ASSERT_NULL(MyMyType, cmock_line, \"Expected NULL. Function 'Pear' called with unexpected value for argument 'MyMyType'.\"); }\n else\n { UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((void*)(&cmock_call_instance->Expected_MyMyType), (void*)(&MyMyType), sizeof(MY_TYPE), 1, cmock_line, \"Function 'Pear' called with unexpected value for argument 'MyMyType'.\"); }\n }\n"
@unity_helper.expect.get_helper('MY_TYPE').returns(['UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY','&']) @unity_helper.expect.get_helper('MY_TYPE').returns(['UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY','&'])
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg)) assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
end end