mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-09-07 18:59:57 +00:00
- array plugin now handles const the way other plugins do.
This commit is contained in:
@@ -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 CMockGeneratorPluginArray
|
class CMockGeneratorPluginArray
|
||||||
|
|
||||||
@@ -26,7 +26,10 @@ class CMockGeneratorPluginArray
|
|||||||
def mock_function_declarations(function)
|
def mock_function_declarations(function)
|
||||||
return nil unless function[:contains_ptr?]
|
return nil unless function[:contains_ptr?]
|
||||||
args_call = function[:args].map{|m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : "#{m[:name]}"}.join(', ')
|
args_call = function[:args].map{|m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : "#{m[:name]}"}.join(', ')
|
||||||
args_string = function[:args].map{|m| m[:ptr?] ? "#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{m[:type]} #{m[:name]}"}.join(', ')
|
args_string = function[:args].map do |m|
|
||||||
|
const_str = m[:const?] ? 'const ' : ''
|
||||||
|
m[:ptr?] ? "#{const_str}#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{const_str}#{m[:type]} #{m[:name]}"
|
||||||
|
end.join(', ')
|
||||||
if (function[:return][:void?])
|
if (function[:return][:void?])
|
||||||
return "#define #{function[:name]}_ExpectWithArray(#{args_call}) #{function[:name]}_CMockExpectWithArray(__LINE__, #{args_call})\n" +
|
return "#define #{function[:name]}_ExpectWithArray(#{args_call}) #{function[:name]}_CMockExpectWithArray(__LINE__, #{args_call})\n" +
|
||||||
"void #{function[:name]}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, #{args_string});\n"
|
"void #{function[:name]}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, #{args_string});\n"
|
||||||
@@ -40,7 +43,10 @@ class CMockGeneratorPluginArray
|
|||||||
return nil unless function[:contains_ptr?]
|
return nil unless function[:contains_ptr?]
|
||||||
lines = []
|
lines = []
|
||||||
func_name = function[:name]
|
func_name = function[:name]
|
||||||
args_string = function[:args].map{|m| m[:ptr?] ? "#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{m[:type]} #{m[:name]}"}.join(', ')
|
args_string = function[:args].map do |m|
|
||||||
|
const_str = m[:const?] ? 'const ' : ''
|
||||||
|
m[:ptr?] ? "#{const_str}#{m[:type]} #{m[:name]}, int #{m[:name]}_Depth" : "#{const_str}#{m[:type]} #{m[:name]}"
|
||||||
|
end.join(', ')
|
||||||
call_string = function[:args].map{|m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : m[:name]}.join(', ')
|
call_string = function[:args].map{|m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : m[:name]}.join(', ')
|
||||||
if (function[:return][:void?])
|
if (function[:return][:void?])
|
||||||
lines << "void #{func_name}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, #{args_string})\n"
|
lines << "void #{func_name}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, #{args_string})\n"
|
||||||
|
|||||||
@@ -86,6 +86,22 @@ describe CMockGeneratorPluginArray, "Verify CMockPGeneratorluginArray Module" do
|
|||||||
assert_equal(expected, returned)
|
assert_equal(expected, returned)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "add another mock function declaration for functions of style 'const char* func(const int* tofu)'" do
|
||||||
|
function = {:name => "Pine",
|
||||||
|
:args => [{ :type => "int*",
|
||||||
|
:name => "tofu",
|
||||||
|
:ptr? => true,
|
||||||
|
:const? => true,
|
||||||
|
}],
|
||||||
|
:return => test_return[:string],
|
||||||
|
:contains_ptr? => true }
|
||||||
|
|
||||||
|
expected = "#define #{function[:name]}_ExpectWithArrayAndReturn(tofu, tofu_Depth, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, tofu, tofu_Depth, cmock_retval)\n" +
|
||||||
|
"void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, const int* tofu, int tofu_Depth, const char* cmock_to_return);\n"
|
||||||
|
returned = @cmock_generator_plugin_array.mock_function_declarations(function)
|
||||||
|
assert_equal(expected, returned)
|
||||||
|
end
|
||||||
|
|
||||||
it "not have a mock function implementation" do
|
it "not have a mock function implementation" do
|
||||||
assert(!@cmock_generator_plugin_array.respond_to?(:mock_implementation))
|
assert(!@cmock_generator_plugin_array.respond_to?(:mock_implementation))
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user