| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
class CMockGeneratorPluginArray |
| 8 |
attr_reader :priority |
| 9 |
attr_accessor :config, :utils, :unity_helper, :ordered |
| 10 |
def initialize(config, utils) |
| 11 |
@config = config |
| 12 |
@ptr_handling = @config.when_ptr |
| 13 |
@ordered = @config.enforce_strict_ordering |
| 14 |
@utils = utils |
| 15 |
@unity_helper = @utils.helpers[:unity_helper] |
| 16 |
@priority = 8 |
| 17 |
end |
| 18 |
|
| 19 |
def instance_typedefs(function) |
| 20 |
function[:args].inject('') do |all, arg| |
| 21 |
arg[:ptr?] ? all + " int Expected_#{arg[:name]}_Depth;\n" : all |
| 22 |
end |
| 23 |
end |
| 24 |
|
| 25 |
def mock_function_declarations(function) |
| 26 |
return nil unless function[:contains_ptr?] |
| 27 |
|
| 28 |
args_call = function[:args].map { |m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : (m[:name]).to_s }.join(', ') |
| 29 |
args_string = function[:args].map do |m| |
| 30 |
type = @utils.arg_type_with_const(m) |
| 31 |
m[:ptr?] ? "#{type} #{m[:name]}, int #{m[:name]}_Depth" : "#{type} #{m[:name]}" |
| 32 |
end.join(', ') |
| 33 |
if function[:return][:void?] |
| 34 |
return "#define #{function[:name]}_ExpectWithArray(#{args_call}) #{function[:name]}_CMockExpectWithArray(__LINE__, #{args_call})\n" \ |
| 35 |
"void #{function[:name]}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, #{args_string});\n" |
| 36 |
else |
| 37 |
return "#define #{function[:name]}_ExpectWithArrayAndReturn(#{args_call}, cmock_retval) #{function[:name]}_CMockExpectWithArrayAndReturn(__LINE__, #{args_call}, cmock_retval)\n" \ |
| 38 |
"void #{function[:name]}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, #{args_string}, #{function[:return][:str]});\n" |
| 39 |
end |
| 40 |
end |
| 41 |
|
| 42 |
def mock_interfaces(function) |
| 43 |
return nil unless function[:contains_ptr?] |
| 44 |
|
| 45 |
lines = [] |
| 46 |
func_name = function[:name] |
| 47 |
args_string = function[:args].map do |m| |
| 48 |
type = @utils.arg_type_with_const(m) |
| 49 |
m[:ptr?] ? "#{type} #{m[:name]}, int #{m[:name]}_Depth" : "#{type} #{m[:name]}" |
| 50 |
end.join(', ') |
| 51 |
call_string = function[:args].map { |m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : m[:name] }.join(', ') |
| 52 |
lines << if function[:return][:void?] |
| 53 |
"void #{func_name}_CMockExpectWithArray(UNITY_LINE_TYPE cmock_line, #{args_string})\n" |
| 54 |
else |
| 55 |
"void #{func_name}_CMockExpectWithArrayAndReturn(UNITY_LINE_TYPE cmock_line, #{args_string}, #{function[:return][:str]})\n" |
| 56 |
end |
| 57 |
lines << "{\n" |
| 58 |
lines << @utils.code_add_base_expectation(func_name) |
| 59 |
lines << " CMockExpectParameters_#{func_name}(cmock_call_instance, #{call_string});\n" |
| 60 |
lines << " cmock_call_instance->ReturnVal = cmock_to_return;\n" unless function[:return][:void?] |
| 61 |
lines << "}\n\n" |
| 62 |
end |
| 63 |
end |