mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-10-03 23:47:26 +00:00
Fix const pointer handling in return values
This commit is contained in:
+13
-6
@@ -296,11 +296,20 @@ class CMockGenerator
|
|||||||
file << "}\n\n"
|
file << "}\n\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def function_return_type(function)
|
||||||
|
# When const_ptr? is true, the "const" in :modifier belongs after the asterisk (e.g. "int* const"),
|
||||||
|
# not as a prefix (which would incorrectly produce "const int*").
|
||||||
|
ret = if function[:return][:const_ptr?]
|
||||||
|
"#{function[:return][:type]} const"
|
||||||
|
else
|
||||||
|
(function[:modifier].empty? ? '' : "#{function[:modifier]} ") + function[:return][:type]
|
||||||
|
end
|
||||||
|
ret + (function[:c_calling_convention] ? " #{function[:c_calling_convention]}" : '')
|
||||||
|
end
|
||||||
|
|
||||||
def create_mock_implementation(file, function)
|
def create_mock_implementation(file, function)
|
||||||
# prepare return value and arguments
|
# prepare return value and arguments
|
||||||
function_mod_and_rettype = (function[:modifier].empty? ? '' : "#{function[:modifier]} ") +
|
function_mod_and_rettype = function_return_type(function)
|
||||||
(function[:return][:type]) +
|
|
||||||
(function[:c_calling_convention] ? " #{function[:c_calling_convention]}" : '')
|
|
||||||
args_string = function[:args_string]
|
args_string = function[:args_string]
|
||||||
args_string += ", #{function[:var_arg]}" unless function[:var_arg].nil?
|
args_string += ", #{function[:var_arg]}" unless function[:var_arg].nil?
|
||||||
|
|
||||||
@@ -359,9 +368,7 @@ class CMockGenerator
|
|||||||
|
|
||||||
def create_function_skeleton(file, function, existing)
|
def create_function_skeleton(file, function, existing)
|
||||||
# prepare return value and arguments
|
# prepare return value and arguments
|
||||||
function_mod_and_rettype = (function[:modifier].empty? ? '' : "#{function[:modifier]} ") +
|
function_mod_and_rettype = function_return_type(function)
|
||||||
(function[:return][:type]) +
|
|
||||||
(function[:c_calling_convention] ? " #{function[:c_calling_convention]}" : '')
|
|
||||||
args_string = function[:args_string]
|
args_string = function[:args_string]
|
||||||
args_string += ", #{function[:var_arg]}" unless function[:var_arg].nil?
|
args_string += ", #{function[:var_arg]}" unless function[:var_arg].nil?
|
||||||
|
|
||||||
|
|||||||
@@ -567,9 +567,10 @@ class CMockHeaderParser
|
|||||||
|
|
||||||
rettype = parsed[:type]
|
rettype = parsed[:type]
|
||||||
rettype = 'void' if @local_as_void.include?(rettype.strip)
|
rettype = 'void' if @local_as_void.include?(rettype.strip)
|
||||||
|
retstr = parsed[:const_ptr?] ? "#{rettype} const" : rettype
|
||||||
decl[:return] = { :type => rettype,
|
decl[:return] = { :type => rettype,
|
||||||
:name => 'cmock_to_return',
|
:name => 'cmock_to_return',
|
||||||
:str => "#{rettype} cmock_to_return",
|
:str => "#{retstr} cmock_to_return",
|
||||||
:void? => (rettype == 'void'),
|
:void? => (rettype == 'void'),
|
||||||
:ptr? => parsed[:ptr?] || false,
|
:ptr? => parsed[:ptr?] || false,
|
||||||
:const? => parsed[:const?] || false,
|
:const? => parsed[:const?] || false,
|
||||||
|
|||||||
@@ -1038,7 +1038,7 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do
|
|||||||
:ptr? => true,
|
:ptr? => true,
|
||||||
:const? => false,
|
:const? => false,
|
||||||
:const_ptr? => true,
|
:const_ptr? => true,
|
||||||
:str => "int* cmock_to_return",
|
:str => "int* const cmock_to_return",
|
||||||
:void? => false
|
:void? => false
|
||||||
},
|
},
|
||||||
:modifier=>"const",
|
:modifier=>"const",
|
||||||
|
|||||||
Reference in New Issue
Block a user