mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-10-02 23:17:25 +00:00
Merge branch 'master' of https://github.com/ThrowTheSwitch/CMock
Conflicts: lib/cmock_config.rb lib/cmock_generator_utils.rb
This commit is contained in:
+18
-18
@@ -8,24 +8,24 @@ class CMockConfig
|
|||||||
|
|
||||||
CMockDefaultOptions =
|
CMockDefaultOptions =
|
||||||
{
|
{
|
||||||
:framework => :unity,
|
:framework => :unity,
|
||||||
:mock_path => 'mocks',
|
:mock_path => 'mocks',
|
||||||
:mock_prefix => 'Mock',
|
:mock_prefix => 'Mock',
|
||||||
:plugins => [],
|
:plugins => [],
|
||||||
:strippables => ['(?:__attribute__\s*\(+.*?\)+)'],
|
:strippables => ['(?:__attribute__\s*\(+.*?\)+)'],
|
||||||
:attributes => ['__ramfunc', '__irq', '__fiq', 'register', 'extern'],
|
:attributes => ['__ramfunc', '__irq', '__fiq', 'register', 'extern'],
|
||||||
:c_calling_conventions => ['__stdcall', '__cdecl', '__fastcall'],
|
:c_calling_conventions => ['__stdcall', '__cdecl', '__fastcall'],
|
||||||
:enforce_strict_ordering => false,
|
:enforce_strict_ordering => false,
|
||||||
:unity_helper_path => false,
|
:unity_helper_path => false,
|
||||||
:treat_as => {},
|
:treat_as => {},
|
||||||
:treat_as_void => [],
|
:treat_as_void => [],
|
||||||
:memcmp_if_unknown => true,
|
:memcmp_if_unknown => true,
|
||||||
:when_no_prototypes => :warn, #the options being :ignore, :warn, or :error
|
:when_no_prototypes => :warn, #the options being :ignore, :warn, or :error
|
||||||
:when_ptr => :compare_data, #the options being :compare_ptr, :compare_data, or :smart
|
:when_ptr => :compare_data, #the options being :compare_ptr, :compare_data, or :smart
|
||||||
:verbosity => 2, #the options being 0 errors only, 1 warnings and errors, 2 normal info, 3 verbose
|
:verbosity => 2, #the options being 0 errors only, 1 warnings and errors, 2 normal info, 3 verbose
|
||||||
:treat_externs => :exclude, #the options being :include or :exclude
|
:treat_externs => :exclude, #the options being :include or :exclude
|
||||||
:callback_include_count => true,
|
:callback_include_count => true,
|
||||||
:callback_after_arg_check => false,
|
:callback_after_arg_check => false,
|
||||||
:includes => nil,
|
:includes => nil,
|
||||||
:includes_h_pre_orig_header => nil,
|
:includes_h_pre_orig_header => nil,
|
||||||
:includes_h_post_orig_header => nil,
|
:includes_h_post_orig_header => nil,
|
||||||
|
|||||||
@@ -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,13 +14,12 @@ 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)
|
||||||
@@ -41,38 +40,37 @@ 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
|
||||||
@@ -80,25 +78,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]
|
||||||
@@ -112,7 +110,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 = ""
|
||||||
@@ -137,12 +135,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
|
||||||
@@ -168,12 +166,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
|
||||||
@@ -205,10 +203,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
|
||||||
|
|||||||
Reference in New Issue
Block a user