mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-08-31 23:40:02 +00:00
Merge branch 'master' into cmock_2_6_rc
This commit is contained in:
@@ -2,9 +2,10 @@ class CMockGeneratorPluginReturnThruPtr
|
||||
attr_reader :priority
|
||||
attr_accessor :utils
|
||||
|
||||
def initialize(_config, utils)
|
||||
def initialize(config, utils)
|
||||
@utils = utils
|
||||
@priority = 9
|
||||
@config = config
|
||||
end
|
||||
|
||||
def instance_typedefs(function)
|
||||
@@ -19,6 +20,15 @@ class CMockGeneratorPluginReturnThruPtr
|
||||
lines
|
||||
end
|
||||
|
||||
def void_pointer?(type)
|
||||
# returns true if the provided type is a void, or is supposed to be treated as void
|
||||
if type.casecmp?('void')
|
||||
true
|
||||
else
|
||||
@config.respond_to?(:treat_as_void) ? @config.treat_as_void.include?(type) : false
|
||||
end
|
||||
end
|
||||
|
||||
def mock_function_declarations(function)
|
||||
lines = ''
|
||||
function[:args].each do |arg|
|
||||
@@ -27,7 +37,8 @@ class CMockGeneratorPluginReturnThruPtr
|
||||
lines << "#define #{function[:name]}_ReturnThruPtr_#{arg[:name]}(#{arg[:name]})"
|
||||
# If the pointer type actually contains an asterisk, we can do sizeof the type (super safe), otherwise
|
||||
# we need to do a sizeof the dereferenced pointer (which could be a problem if give the wrong size
|
||||
lines << if arg[:type][-1] == '*'
|
||||
# however if its a void pointer we are given then we have to use the provided parameter name because sizeof(void) is UB.
|
||||
lines << if (arg[:type][-1] == '*') && (void_pointer?(arg[:type][0..-2]) == false)
|
||||
" #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, sizeof(#{arg[:type][0..-2]}))\n"
|
||||
else
|
||||
" #{function[:name]}_CMockReturnMemThruPtr_#{arg[:name]}(__LINE__, #{arg[:name]}, sizeof(*#{arg[:name]}))\n"
|
||||
|
||||
@@ -137,7 +137,7 @@ class CMockHeaderParser
|
||||
# If the user uses a macro to declare an inline function,
|
||||
# smushing the macros makes it easier to recognize them as a macro and if required,
|
||||
# remove them later on in this function
|
||||
source.gsub!(/\s*\\\s*/m, ' ')
|
||||
source.gsub!(/\s*\\(\n|\s*)/m, ' ')
|
||||
|
||||
# Just looking for static|inline in the gsub is a bit too aggressive (functions that are named like this, ...), so we try to be a bit smarter
|
||||
# Instead, look for an inline pattern (f.e. "static inline") and parse it.
|
||||
|
||||
@@ -35,6 +35,9 @@ class CMockUnityHelperParser
|
||||
def map_c_types
|
||||
c_types = {}
|
||||
@config.treat_as.each_pair do |ctype, expecttype|
|
||||
if ctype.is_a?(Symbol)
|
||||
raise ":treat_as expects a list of identifier: identifier mappings, but got a symbol: #{ctype}. Check the indentation in your project.yml"
|
||||
end
|
||||
c_type = ctype.gsub(/\s+/, '_')
|
||||
if expecttype =~ /\*/
|
||||
c_types[c_type] = "UNITY_TEST_ASSERT_EQUAL_#{expecttype.delete('*')}_ARRAY"
|
||||
|
||||
Reference in New Issue
Block a user