mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-06-22 21:40:29 +00:00
Compare commits
18 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cb1ad78b97 | |||
| 2b4f9b43c7 | |||
| 2a2f19dfae | |||
| e42996ea67 | |||
| b9da6d6def | |||
| 0fc09121d7 | |||
| 4df347bf17 | |||
| e765181c8d | |||
| 6d1c0f97f5 | |||
| 488c469cdf | |||
| 3df5c035e6 | |||
| 1f87c158da | |||
| 76b6231f77 | |||
| ca05fe4285 | |||
| 37fcb8535a | |||
| 526668961a | |||
| 3b123fb533 | |||
| c725e4ddc6 |
+8
-9
@@ -1,29 +1,28 @@
|
||||
language: ruby
|
||||
|
||||
os:
|
||||
os:
|
||||
- osx
|
||||
- linux
|
||||
|
||||
|
||||
rvm:
|
||||
- "2.0.0"
|
||||
- "2.2.2"
|
||||
|
||||
|
||||
before_install:
|
||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then rvm install 2.1 && rvm use 2.1 && ruby -v; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install --assume-yes --quiet gcc-multilib; fi
|
||||
|
||||
|
||||
install:
|
||||
- bundle install
|
||||
- gem install rspec
|
||||
- gem install rubocop
|
||||
|
||||
|
||||
script:
|
||||
- cd test && rake ci
|
||||
- cd ..
|
||||
- cd examples && cd make_example
|
||||
- make clean
|
||||
- make setup
|
||||
- make clean
|
||||
- make setup
|
||||
- make test
|
||||
- cd ..
|
||||
- cd temp_sensor
|
||||
- cd temp_sensor
|
||||
- rake ci
|
||||
|
||||
@@ -7,17 +7,17 @@ Getting Started
|
||||
================
|
||||
|
||||
If you're using Ceedling, there is no need to install CMock. It will handle it for you.
|
||||
For everyone else, the simplest way is to grab it off github. You can also download it
|
||||
For everyone else, the simplest way is to grab it off github. You can also download it
|
||||
as a zip if you prefer. The Github method looks something like this:
|
||||
|
||||
> git clone --recursive https://github.com/throwtheswitch/cmock.git
|
||||
> cd cmock
|
||||
> bundle install # Ensures you have all RubyGems needed
|
||||
|
||||
|
||||
If you plan to help with the development of CMock (or just want to verify that it can
|
||||
perform its self tests on your system) then you can enter the test directory and then
|
||||
ask it to test:
|
||||
|
||||
|
||||
> rake # Run all CMock self tests
|
||||
|
||||
API Documentation
|
||||
|
||||
@@ -597,7 +597,7 @@ Examples
|
||||
|
||||
You can look in the [examples directory](/examples/) for a couple of examples on how
|
||||
you might tool CMock into your build process. You may also want to consider
|
||||
using [Ceedling](https://throwtheswitch.org/Ceedling). Please note that
|
||||
using [Ceedling](https://throwtheswitch.org/ceedling). Please note that
|
||||
these examples are meant to show how the build process works. They have
|
||||
failing tests ON PURPOSE to show what that would look like. Don't be alarmed. ;)
|
||||
|
||||
|
||||
@@ -120,6 +120,8 @@ class CMockConfig
|
||||
'UINT32' => 'HEX32',
|
||||
'UINT32_T' => 'HEX32',
|
||||
'void*' => 'HEX8_ARRAY',
|
||||
'void const*' => 'HEX8_ARRAY',
|
||||
'const void*' => 'HEX8_ARRAY',
|
||||
'unsigned short' => 'HEX16',
|
||||
'uint16' => 'HEX16',
|
||||
'uint16_t' => 'HEX16',
|
||||
@@ -131,6 +133,8 @@ class CMockConfig
|
||||
'UINT8' => 'HEX8',
|
||||
'UINT8_T' => 'HEX8',
|
||||
'char*' => 'STRING',
|
||||
'char const*' => 'STRING',
|
||||
'const char*' => 'STRING',
|
||||
'pCHAR' => 'STRING',
|
||||
'cstring' => 'STRING',
|
||||
'CSTRING' => 'STRING',
|
||||
|
||||
@@ -103,7 +103,9 @@ class CMockGenerator
|
||||
file << "\n"
|
||||
file << "/* Ignore the following warnings, since we are copying code */\n"
|
||||
file << "#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n"
|
||||
file << "#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n"
|
||||
file << "#pragma GCC diagnostic push\n"
|
||||
file << "#endif\n"
|
||||
file << "#if !defined(__clang__)\n"
|
||||
file << "#pragma GCC diagnostic ignored \"-Wpragmas\"\n"
|
||||
file << "#endif\n"
|
||||
@@ -128,8 +130,10 @@ class CMockGenerator
|
||||
def create_mock_header_footer(header)
|
||||
header << "\n"
|
||||
header << "#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n"
|
||||
header << "#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n"
|
||||
header << "#pragma GCC diagnostic pop\n"
|
||||
header << "#endif\n"
|
||||
header << "#endif\n"
|
||||
header << "\n"
|
||||
header << "#endif\n"
|
||||
end
|
||||
@@ -247,10 +251,9 @@ class CMockGenerator
|
||||
file << " if (cmock_call_instance->CallOrder < GlobalVerifyOrder)\n"
|
||||
file << " UNITY_TEST_FAIL(cmock_line, CMockStringCalledLate);\n"
|
||||
end
|
||||
return_type = function[:return][:const?] ? "(const #{function[:return][:type]})" : ((function[:return][:type] =~ /cmock/) ? "(#{function[:return][:type]})" : '')
|
||||
file << @plugins.run(:mock_implementation, function)
|
||||
file << " UNITY_CLR_DETAILS();\n"
|
||||
file << " return #{return_type}cmock_call_instance->ReturnVal;\n" unless (function[:return][:void?])
|
||||
file << " return cmock_call_instance->ReturnVal;\n" unless (function[:return][:void?])
|
||||
file << "}\n\n"
|
||||
end
|
||||
|
||||
|
||||
@@ -27,8 +27,8 @@ class CMockGeneratorPluginArray
|
||||
return nil unless function[:contains_ptr?]
|
||||
args_call = function[:args].map{|m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : "#{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]}"
|
||||
type = @utils.arg_type_with_const(m)
|
||||
m[:ptr?] ? "#{type} #{m[:name]}, int #{m[:name]}_Depth" : "#{type} #{m[:name]}"
|
||||
end.join(', ')
|
||||
if (function[:return][:void?])
|
||||
return "#define #{function[:name]}_ExpectWithArray(#{args_call}) #{function[:name]}_CMockExpectWithArray(__LINE__, #{args_call})\n" +
|
||||
@@ -44,8 +44,8 @@ class CMockGeneratorPluginArray
|
||||
lines = []
|
||||
func_name = function[:name]
|
||||
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]}"
|
||||
type = @utils.arg_type_with_const(m)
|
||||
m[:ptr?] ? "#{type} #{m[:name]}, int #{m[:name]}_Depth" : "#{type} #{m[:name]}"
|
||||
end.join(', ')
|
||||
call_string = function[:args].map{|m| m[:ptr?] ? "#{m[:name]}, #{m[:name]}_Depth" : m[:name]}.join(', ')
|
||||
if (function[:return][:void?])
|
||||
|
||||
@@ -33,7 +33,7 @@ class CMockGeneratorPluginCallback
|
||||
|
||||
def mock_function_declarations(function)
|
||||
func_name = function[:name]
|
||||
return_type = function[:return][:const?] ? "const #{function[:return][:type]}" : function[:return][:type]
|
||||
return_type = function[:return][:type]
|
||||
style = (@include_count ? 1 : 0) | (function[:args].empty? ? 0 : 2)
|
||||
styles = [ "void", "int cmock_num_calls", function[:args_string], "#{function[:args_string]}, int cmock_num_calls" ]
|
||||
"typedef #{return_type} (* CMOCK_#{func_name}_CALLBACK)(#{styles[style]});\nvoid #{func_name}_StubWithCallback(CMOCK_#{func_name}_CALLBACK Callback);\n"
|
||||
@@ -41,7 +41,6 @@ class CMockGeneratorPluginCallback
|
||||
|
||||
def mock_implementation_for_callbacks_after_arg_check(function)
|
||||
func_name = function[:name]
|
||||
return_cast = function[:return][:const?] ? "(#{function[:return][:type]})" : ""
|
||||
style = (@include_count ? 1 : 0) | (function[:args].empty? ? 0 : 2) | (function[:return][:void?] ? 0 : 4)
|
||||
" if (Mock.#{func_name}_CallbackFunctionPointer != NULL)\n {\n" +
|
||||
case(style)
|
||||
@@ -49,16 +48,15 @@ class CMockGeneratorPluginCallback
|
||||
when 1 then " Mock.#{func_name}_CallbackFunctionPointer(Mock.#{func_name}_CallbackCalls++);\n }\n"
|
||||
when 2 then " Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')});\n }\n"
|
||||
when 3 then " Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')}, Mock.#{func_name}_CallbackCalls++);\n }\n"
|
||||
when 4 then " cmock_call_instance->ReturnVal = #{return_cast}Mock.#{func_name}_CallbackFunctionPointer();\n }\n"
|
||||
when 5 then " cmock_call_instance->ReturnVal = #{return_cast}Mock.#{func_name}_CallbackFunctionPointer(Mock.#{func_name}_CallbackCalls++);\n }\n"
|
||||
when 6 then " cmock_call_instance->ReturnVal = #{return_cast}Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')});\n }\n"
|
||||
when 7 then " cmock_call_instance->ReturnVal = #{return_cast}Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')}, Mock.#{func_name}_CallbackCalls++);\n }\n"
|
||||
when 4 then " cmock_call_instance->ReturnVal = Mock.#{func_name}_CallbackFunctionPointer();\n }\n"
|
||||
when 5 then " cmock_call_instance->ReturnVal = Mock.#{func_name}_CallbackFunctionPointer(Mock.#{func_name}_CallbackCalls++);\n }\n"
|
||||
when 6 then " cmock_call_instance->ReturnVal = Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')});\n }\n"
|
||||
when 7 then " cmock_call_instance->ReturnVal = Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')}, Mock.#{func_name}_CallbackCalls++);\n }\n"
|
||||
end
|
||||
end
|
||||
|
||||
def mock_implementation_for_callbacks_without_arg_check(function)
|
||||
func_name = function[:name]
|
||||
return_cast = function[:return][:const?] ? "(#{function[:return][:type]})" : ""
|
||||
style = (@include_count ? 1 : 0) | (function[:args].empty? ? 0 : 2) | (function[:return][:void?] ? 0 : 4)
|
||||
" if (Mock.#{func_name}_CallbackFunctionPointer != NULL)\n {\n" +
|
||||
case(style)
|
||||
@@ -66,10 +64,10 @@ class CMockGeneratorPluginCallback
|
||||
when 1 then " Mock.#{func_name}_CallbackFunctionPointer(Mock.#{func_name}_CallbackCalls++);\n return;\n }\n"
|
||||
when 2 then " Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')});\n return;\n }\n"
|
||||
when 3 then " Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')}, Mock.#{func_name}_CallbackCalls++);\n return;\n }\n"
|
||||
when 4 then " return #{return_cast}Mock.#{func_name}_CallbackFunctionPointer();\n }\n"
|
||||
when 5 then " return #{return_cast}Mock.#{func_name}_CallbackFunctionPointer(Mock.#{func_name}_CallbackCalls++);\n }\n"
|
||||
when 6 then " return #{return_cast}Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')});\n }\n"
|
||||
when 7 then " return #{return_cast}Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')}, Mock.#{func_name}_CallbackCalls++);\n }\n"
|
||||
when 4 then " return Mock.#{func_name}_CallbackFunctionPointer();\n }\n"
|
||||
when 5 then " return Mock.#{func_name}_CallbackFunctionPointer(Mock.#{func_name}_CallbackCalls++);\n }\n"
|
||||
when 6 then " return Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')});\n }\n"
|
||||
when 7 then " return Mock.#{func_name}_CallbackFunctionPointer(#{function[:args].map{|m| m[:name]}.join(', ')}, Mock.#{func_name}_CallbackCalls++);\n }\n"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ class CMockGeneratorPluginCexception
|
||||
|
||||
def mock_interfaces(function)
|
||||
arg_insert = (function[:args_string] == "void") ? "" : "#{function[:args_string]}, "
|
||||
call_string = function[:args].map{|m| m[:name]}.join(', ')
|
||||
[ "void #{function[:name]}_CMockExpectAndThrow(UNITY_LINE_TYPE cmock_line, #{arg_insert}CEXCEPTION_T cmock_to_throw)\n{\n",
|
||||
@utils.code_add_base_expectation(function[:name]),
|
||||
@utils.code_call_argument_loader(function),
|
||||
|
||||
@@ -40,10 +40,9 @@ class CMockGeneratorPluginIgnore
|
||||
lines << " return;\n }\n"
|
||||
else
|
||||
retval = function[:return].merge( { :name => "cmock_call_instance->ReturnVal"} )
|
||||
return_type = function[:return][:const?] ? "(const #{function[:return][:type]})" : ((function[:return][:type] =~ /cmock/) ? "(#{function[:return][:type]})" : '')
|
||||
lines << " if (cmock_call_instance == NULL)\n return #{return_type}Mock.#{function[:name]}_FinalReturn;\n"
|
||||
lines << " if (cmock_call_instance == NULL)\n return Mock.#{function[:name]}_FinalReturn;\n"
|
||||
lines << " " + @utils.code_assign_argument_quickly("Mock.#{function[:name]}_FinalReturn", retval) unless (retval[:void?])
|
||||
lines << " return #{return_type}cmock_call_instance->ReturnVal;\n }\n"
|
||||
lines << " return cmock_call_instance->ReturnVal;\n }\n"
|
||||
end
|
||||
lines
|
||||
end
|
||||
|
||||
@@ -29,14 +29,12 @@ class CMockGeneratorPluginIgnoreArg
|
||||
lines = []
|
||||
func_name = function[:name]
|
||||
function[:args].each do |arg|
|
||||
arg_name = arg[:name]
|
||||
arg_type = arg[:type]
|
||||
lines << "void #{function[:name]}_CMockIgnoreArg_#{arg[:name]}(UNITY_LINE_TYPE cmock_line)\n"
|
||||
lines << "void #{func_name}_CMockIgnoreArg_#{arg[:name]}(UNITY_LINE_TYPE cmock_line)\n"
|
||||
lines << "{\n"
|
||||
lines << " CMOCK_#{func_name}_CALL_INSTANCE* cmock_call_instance = " +
|
||||
"(CMOCK_#{func_name}_CALL_INSTANCE*)CMock_Guts_GetAddressFor(CMock_Guts_MemEndOfChain(Mock.#{func_name}_CallInstance));\n"
|
||||
lines << " UNITY_TEST_ASSERT_NOT_NULL(cmock_call_instance, cmock_line, CMockStringIgnPreExp);\n"
|
||||
lines << " cmock_call_instance->IgnoreArg_#{arg_name} = 1;\n"
|
||||
lines << " cmock_call_instance->IgnoreArg_#{arg[:name]} = 1;\n"
|
||||
lines << "}\n\n"
|
||||
end
|
||||
lines
|
||||
|
||||
@@ -40,7 +40,6 @@ class CMockGeneratorPluginReturnThruPtr
|
||||
func_name = function[:name]
|
||||
function[:args].each do |arg|
|
||||
arg_name = arg[:name]
|
||||
arg_type = arg[:type]
|
||||
if (@utils.ptr_or_str?(arg[:type]) and not arg[:const?])
|
||||
lines << "void #{func_name}_CMockReturnMemThruPtr_#{arg_name}(UNITY_LINE_TYPE cmock_line, #{arg[:type]} #{arg_name}, int cmock_size)\n"
|
||||
lines << "{\n"
|
||||
@@ -60,7 +59,6 @@ class CMockGeneratorPluginReturnThruPtr
|
||||
lines = []
|
||||
function[:args].each do |arg|
|
||||
arg_name = arg[:name]
|
||||
arg_type = arg[:type]
|
||||
if (@utils.ptr_or_str?(arg[:type]) and not arg[:const?])
|
||||
lines << " if (cmock_call_instance->ReturnThruPtr_#{arg_name}_Used)\n"
|
||||
lines << " {\n"
|
||||
|
||||
@@ -22,6 +22,19 @@ class CMockGeneratorUtils
|
||||
@helpers = helpers
|
||||
end
|
||||
|
||||
def self.arg_type_with_const(arg)
|
||||
# Restore any "const" that was removed in header parsing
|
||||
if arg[:type].include?('*')
|
||||
arg[:const_ptr?] ? "#{arg[:type]} const" : arg[:type]
|
||||
else
|
||||
arg[:const?] ? "const #{arg[:type]}" : arg[:type]
|
||||
end
|
||||
end
|
||||
|
||||
def arg_type_with_const(arg)
|
||||
self.class.arg_type_with_const(arg)
|
||||
end
|
||||
|
||||
def code_verify_an_arg_expectation(function, arg)
|
||||
if (@arrays)
|
||||
case(@ptr_handling)
|
||||
@@ -58,7 +71,7 @@ class CMockGeneratorUtils
|
||||
|
||||
def code_assign_argument_quickly(dest, arg)
|
||||
if (arg[:ptr?] or @treat_as.include?(arg[:type]))
|
||||
" #{dest} = #{arg[:const?] ? "(#{arg[:type]})" : ''}#{arg[:name]};\n"
|
||||
" #{dest} = #{arg[:name]};\n"
|
||||
else
|
||||
" memcpy(&#{dest}, &#{arg[:name]}, sizeof(#{arg[:type]}));\n"
|
||||
end
|
||||
@@ -68,8 +81,8 @@ class CMockGeneratorUtils
|
||||
if (function[:args_string] != "void")
|
||||
if (@arrays)
|
||||
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]}"
|
||||
type = arg_type_with_const(m)
|
||||
m[:ptr?] ? "#{type} #{m[:name]}, int #{m[:name]}_Depth" : "#{type} #{m[:name]}"
|
||||
end.join(', ')
|
||||
"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) ) } +
|
||||
|
||||
+54
-38
@@ -140,24 +140,51 @@ class CMockHeaderParser
|
||||
return funcs
|
||||
end
|
||||
|
||||
def parse_type_and_name(arg)
|
||||
# Split up words and remove known attributes. For pointer types, make sure
|
||||
# to remove 'const' only when it applies to the pointer itself, not when it
|
||||
# applies to the type pointed to. For non-pointer types, remove any
|
||||
# occurrence of 'const'.
|
||||
arg.gsub!(/(\w)\*/,'\1 *') # pull asterisks away from preceding word
|
||||
arg.gsub!(/\*(\w)/,'* \1') # pull asterisks away from following word
|
||||
arg_array = arg.split
|
||||
arg_info = divine_ptr_and_const(arg)
|
||||
arg_info[:name] = arg_array[-1]
|
||||
|
||||
attributes = arg.include?('*') ? @c_attr_noconst : @c_attributes
|
||||
attr_array = []
|
||||
type_array = []
|
||||
|
||||
arg_array[0..-2].each do |word|
|
||||
if attributes.include?(word)
|
||||
attr_array << word
|
||||
elsif @c_calling_conventions.include?(word)
|
||||
arg_info[:c_calling_convention] = word
|
||||
else
|
||||
type_array << word
|
||||
end
|
||||
end
|
||||
|
||||
if arg_info[:const_ptr?]
|
||||
attr_array << 'const'
|
||||
type_array.delete_at(type_array.rindex('const'))
|
||||
end
|
||||
|
||||
arg_info[:modifier] = attr_array.join(' ')
|
||||
arg_info[:type] = type_array.join(' ').gsub(/\s+\*/,'*') # remove space before asterisks
|
||||
return arg_info
|
||||
end
|
||||
|
||||
def parse_args(arg_list)
|
||||
args = []
|
||||
arg_list.split(',').each do |arg|
|
||||
arg.strip!
|
||||
return args if (arg =~ /^\s*((\.\.\.)|(void))\s*$/) # we're done if we reach void by itself or ...
|
||||
|
||||
# Split up words and remove known attributes, but in case of pointer args, don't remove any
|
||||
# 'const' from the type that it points to, since that may change the underlying assembly-code
|
||||
# pointer type on some embedded platforms, making it point to RAM instead of ROM. (I.e. For
|
||||
# pointer args, remove 'const' only when it applies to the pointer itself. For non-pointer
|
||||
# args, remove 'const' regardless.)
|
||||
#
|
||||
arg_array = arg.split
|
||||
ptr_const_info = divine_ptr_and_const(arg)
|
||||
arg_elements = arg_array - (arg.include?('*') ? @c_attr_noconst : @c_attributes)
|
||||
args << { :type => arg_elements[0..(ptr_const_info[:const_ptr?] ? -3 : -2)].join(' '),
|
||||
:name => arg_elements[-1]
|
||||
}.merge(ptr_const_info)
|
||||
arg_info = parse_type_and_name(arg)
|
||||
arg_info.delete(:modifier) # don't care about this
|
||||
arg_info.delete(:c_calling_convention) # don't care about this
|
||||
args << arg_info
|
||||
end
|
||||
return args
|
||||
end
|
||||
@@ -236,35 +263,24 @@ class CMockHeaderParser
|
||||
args = regex_match[2].strip
|
||||
|
||||
#process function attributes, return type, and name
|
||||
descriptors = regex_match[1]
|
||||
descriptors.gsub!(/(\w)\*/,'\1 *') #pull asterisks away from preceding word
|
||||
descriptors.gsub!(/\*(\w)/,'* \1') #pull asterisks away from following word
|
||||
descriptors = descriptors.split #array of all descriptor strings
|
||||
parsed = parse_type_and_name(regex_match[1])
|
||||
|
||||
#grab name
|
||||
decl[:name] = descriptors[-1] #snag name as last array item
|
||||
|
||||
#build attribute and return type strings
|
||||
decl[:modifier] = []
|
||||
rettype = []
|
||||
full_retval = descriptors[0..-2].join(' ')
|
||||
descriptors[0..-2].each do |word|
|
||||
if @c_attributes.include?(word)
|
||||
decl[:modifier] << word
|
||||
elsif @c_calling_conventions.include?(word)
|
||||
decl[:c_calling_convention] = word
|
||||
else
|
||||
rettype << word
|
||||
end
|
||||
decl[:name] = parsed[:name]
|
||||
decl[:modifier] = parsed[:modifier]
|
||||
unless parsed[:c_calling_convention].nil?
|
||||
decl[:c_calling_convention] = parsed[:c_calling_convention]
|
||||
end
|
||||
decl[:modifier] = decl[:modifier].join(' ')
|
||||
rettype = rettype.join(' ').gsub(/\s+\*/,'*') #remove space before asterisks
|
||||
|
||||
rettype = parsed[:type]
|
||||
rettype = 'void' if (@local_as_void.include?(rettype.strip))
|
||||
decl[:return] = { :type => rettype,
|
||||
:name => 'cmock_to_return',
|
||||
:str => "#{rettype} cmock_to_return",
|
||||
:void? => (rettype == 'void')
|
||||
}.merge(divine_ptr_and_const(full_retval))
|
||||
decl[:return] = { :type => rettype,
|
||||
:name => 'cmock_to_return',
|
||||
:str => "#{rettype} cmock_to_return",
|
||||
:void? => (rettype == 'void'),
|
||||
:ptr? => parsed[:ptr?],
|
||||
:const? => parsed[:const?],
|
||||
:const_ptr? => parsed[:const_ptr?]
|
||||
}
|
||||
|
||||
#remove default argument statements from mock definitions
|
||||
args.gsub!(/=\s*[a-zA-Z0-9_\.]+\s*/, ' ')
|
||||
|
||||
+1
-1
@@ -1,2 +1,2 @@
|
||||
216
|
||||
217
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
2.4.5
|
||||
2.4.6
|
||||
|
||||
|
||||
+11
-6
@@ -48,12 +48,17 @@ CMOCK_MEM_INDEX_TYPE CMock_Guts_MemNew(CMOCK_MEM_INDEX_TYPE size)
|
||||
size = (size + CMOCK_MEM_ALIGN_MASK) & ~CMOCK_MEM_ALIGN_MASK;
|
||||
if ((CMock_Guts_BufferSize - CMock_Guts_FreePtr) < size)
|
||||
{
|
||||
#ifdef CMOCK_MEM_DYNAMIC
|
||||
CMock_Guts_BufferSize += CMOCK_MEM_SIZE + size;
|
||||
CMock_Guts_Buffer = realloc(CMock_Guts_Buffer, (size_t)CMock_Guts_BufferSize);
|
||||
if (CMock_Guts_Buffer == NULL)
|
||||
#endif //yes that if will continue to the return below if TRUE
|
||||
return CMOCK_GUTS_NONE;
|
||||
#ifndef CMOCK_MEM_DYNAMIC
|
||||
return CMOCK_GUTS_NONE; // nothing we can do; our static buffer is out of memory
|
||||
#else
|
||||
// our dynamic buffer does not have enough room; request more via realloc()
|
||||
CMOCK_MEM_INDEX_TYPE new_buffersize = CMock_Guts_BufferSize + CMOCK_MEM_SIZE + size;
|
||||
unsigned char* new_buffer = realloc(CMock_Guts_Buffer, (size_t)new_buffersize);
|
||||
if (new_buffer == NULL)
|
||||
return CMOCK_GUTS_NONE; // realloc() failed; out of memory
|
||||
CMock_Guts_Buffer = new_buffer;
|
||||
CMock_Guts_BufferSize = new_buffersize;
|
||||
#endif
|
||||
}
|
||||
|
||||
//determine where we're putting this new block, and init its pointer to be the end of the line
|
||||
|
||||
+11
-10
@@ -24,20 +24,21 @@ end
|
||||
|
||||
def test_return
|
||||
{
|
||||
:int => {:type => "int", :name => 'cmock_to_return', :ptr? => false, :const? => false, :void? => false, :str => 'int cmock_to_return'},
|
||||
:int_ptr => {:type => "int*", :name => 'cmock_to_return', :ptr? => true, :const? => false, :void? => false, :str => 'int* cmock_to_return'},
|
||||
:void => {:type => "void", :name => 'cmock_to_return', :ptr? => false, :const? => false, :void? => true, :str => 'void cmock_to_return'},
|
||||
:string => {:type => "char*", :name => 'cmock_to_return', :ptr? => false, :const? => true, :void? => false, :str => 'const char* cmock_to_return'},
|
||||
:int => {:type => "int", :name => 'cmock_to_return', :ptr? => false, :const? => false, :void? => false, :str => 'int cmock_to_return'},
|
||||
:int_ptr => {:type => "int*", :name => 'cmock_to_return', :ptr? => true, :const? => false, :void? => false, :str => 'int* cmock_to_return'},
|
||||
:void => {:type => "void", :name => 'cmock_to_return', :ptr? => false, :const? => false, :void? => true, :str => 'void cmock_to_return'},
|
||||
:string => {:type => "const char*", :name => 'cmock_to_return', :ptr? => false, :const? => true, :void? => false, :str => 'const char* cmock_to_return'},
|
||||
}
|
||||
end
|
||||
|
||||
def test_arg
|
||||
{
|
||||
:int => {:type => "int", :name => 'MyInt', :ptr? => false, :const? => false},
|
||||
:int_ptr => {:type => "int*", :name => 'MyIntPtr', :ptr? => true, :const? => false},
|
||||
:mytype => {:type => "MY_TYPE", :name => 'MyMyType', :ptr? => false, :const? => true},
|
||||
:mytype_ptr => {:type => "MY_TYPE*", :name => 'MyMyTypePtr', :ptr? => true, :const? => false},
|
||||
:string => {:type => "char*", :name => 'MyStr', :ptr? => false, :const? => true},
|
||||
:int => {:type => "int", :name => 'MyInt', :ptr? => false, :const? => false, :const_ptr? => false},
|
||||
:int_ptr => {:type => "int*", :name => 'MyIntPtr', :ptr? => true, :const? => false, :const_ptr? => false},
|
||||
:const_ptr => {:type => "int*", :name => 'MyConstPtr', :ptr? => true, :const? => false, :const_ptr? => true},
|
||||
:double_ptr => {:type => "int const**", :name => 'MyDoublePtr', :ptr? => true, :const? => true, :const_ptr? => false},
|
||||
:mytype => {:type => "MY_TYPE", :name => 'MyMyType', :ptr? => false, :const? => true, :const_ptr? => false},
|
||||
:mytype_ptr => {:type => "MY_TYPE*", :name => 'MyMyTypePtr', :ptr? => true, :const? => false, :const_ptr? => false},
|
||||
:string => {:type => "const char*", :name => 'MyStr', :ptr? => false, :const? => true, :const_ptr? => false},
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@ describe CMockConfig, "Verify CMockConfig Module" do
|
||||
it "use default settings when no parameters are specified" do
|
||||
config = CMockConfig.new
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:includes], config.includes)
|
||||
assert_nil(CMockConfig::CMockDefaultOptions[:includes])
|
||||
assert_nil(config.includes)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:attributes], config.attributes)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:plugins], config.plugins)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:treat_externs], config.treat_externs)
|
||||
@@ -35,7 +36,8 @@ describe CMockConfig, "Verify CMockConfig Module" do
|
||||
test_plugins = [:soda, :pizza]
|
||||
config = CMockConfig.new("#{File.expand_path(File.dirname(__FILE__))}/cmock_config_test.yml")
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:mock_path], config.mock_path)
|
||||
assert_equal(CMockConfig::CMockDefaultOptions[:includes], config.includes)
|
||||
assert_nil(CMockConfig::CMockDefaultOptions[:includes])
|
||||
assert_nil(config.includes)
|
||||
assert_equal(test_plugins, config.plugins)
|
||||
assert_equal(:include, config.treat_externs)
|
||||
end
|
||||
|
||||
@@ -87,7 +87,6 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
@config.expect :weak, ""
|
||||
orig_filename = "PoutPoutFish.h"
|
||||
define_name = "MOCKPOUTPOUTFISH_H"
|
||||
mock_name = "MockPoutPoutFish"
|
||||
output = []
|
||||
expected = [
|
||||
"/* AUTOGENERATED FILE. DO NOT EDIT. */\n",
|
||||
@@ -100,7 +99,9 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
"\n",
|
||||
"/* Ignore the following warnings, since we are copying code */\n",
|
||||
"#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n",
|
||||
"#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n",
|
||||
"#pragma GCC diagnostic push\n",
|
||||
"#endif\n",
|
||||
"#if !defined(__clang__)\n",
|
||||
"#pragma GCC diagnostic ignored \"-Wpragmas\"\n",
|
||||
"#endif\n",
|
||||
@@ -141,7 +142,6 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
@config.expect :weak, ""
|
||||
orig_filename = "Pout-Pout Fish.h"
|
||||
define_name = "MOCKPOUT_POUT_FISH_H"
|
||||
mock_name = "MockPout_Pout_Fish"
|
||||
output = []
|
||||
expected = [
|
||||
"/* AUTOGENERATED FILE. DO NOT EDIT. */\n",
|
||||
@@ -154,7 +154,9 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
"\n",
|
||||
"/* Ignore the following warnings, since we are copying code */\n",
|
||||
"#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n",
|
||||
"#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n",
|
||||
"#pragma GCC diagnostic push\n",
|
||||
"#endif\n",
|
||||
"#if !defined(__clang__)\n",
|
||||
"#pragma GCC diagnostic ignored \"-Wpragmas\"\n",
|
||||
"#endif\n",
|
||||
@@ -178,7 +180,6 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
@config.expect :weak, ""
|
||||
orig_filename = "PoutPoutFish.h"
|
||||
define_name = "MOCKPOUTPOUTFISH_H"
|
||||
mock_name = "MockPoutPoutFish"
|
||||
output = []
|
||||
expected = [
|
||||
"/* AUTOGENERATED FILE. DO NOT EDIT. */\n",
|
||||
@@ -190,7 +191,9 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
"\n",
|
||||
"/* Ignore the following warnings, since we are copying code */\n",
|
||||
"#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n",
|
||||
"#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n",
|
||||
"#pragma GCC diagnostic push\n",
|
||||
"#endif\n",
|
||||
"#if !defined(__clang__)\n",
|
||||
"#pragma GCC diagnostic ignored \"-Wpragmas\"\n",
|
||||
"#endif\n",
|
||||
@@ -214,7 +217,6 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
@config.expect :weak, ""
|
||||
orig_filename = "PoutPoutFish.h"
|
||||
define_name = "MOCKPOUTPOUTFISH_H"
|
||||
mock_name = "MockPoutPoutFish"
|
||||
output = []
|
||||
expected = [
|
||||
"/* AUTOGENERATED FILE. DO NOT EDIT. */\n",
|
||||
@@ -227,7 +229,9 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
"\n",
|
||||
"/* Ignore the following warnings, since we are copying code */\n",
|
||||
"#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n",
|
||||
"#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n",
|
||||
"#pragma GCC diagnostic push\n",
|
||||
"#endif\n",
|
||||
"#if !defined(__clang__)\n",
|
||||
"#pragma GCC diagnostic ignored \"-Wpragmas\"\n",
|
||||
"#endif\n",
|
||||
@@ -281,8 +285,10 @@ describe CMockGenerator, "Verify CMockGenerator Module" do
|
||||
output = []
|
||||
expected = ["\n",
|
||||
"#if defined(__GNUC__) && !defined(__ICC) && !defined(__TMS470__)\n",
|
||||
"#if __GNUC__ > 4 || (__GNUC__ == 4 && (__GNUC_MINOR__ > 6 || (__GNUC_MINOR__ == 6 && __GNUC_PATCHLEVEL__ > 0)))\n",
|
||||
"#pragma GCC diagnostic pop\n",
|
||||
"#endif\n",
|
||||
"#endif\n",
|
||||
"\n",
|
||||
"#endif\n"
|
||||
]
|
||||
|
||||
@@ -6,21 +6,29 @@
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__)) + "/../test_helper"
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_plugin_array'
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/../../lib/cmock_generator_utils'
|
||||
|
||||
class UtilsStub
|
||||
def helpers
|
||||
{}
|
||||
end
|
||||
def arg_type_with_const(arg)
|
||||
CMockGeneratorUtils.arg_type_with_const(arg)
|
||||
end
|
||||
def code_add_base_expectation(func)
|
||||
"mock_retval_0"
|
||||
end
|
||||
end
|
||||
|
||||
describe CMockGeneratorPluginArray, "Verify CMockPGeneratorluginArray Module" do
|
||||
before do
|
||||
create_mocks :utils
|
||||
|
||||
#no strict ordering
|
||||
@config = create_stub(
|
||||
:when_ptr => :compare_data,
|
||||
:enforce_strict_ordering => false,
|
||||
:respond_to? => true )
|
||||
|
||||
@utils = create_stub(
|
||||
:helpers => {},
|
||||
:code_add_base_expectation => "mock_retval_0"
|
||||
)
|
||||
@utils = UtilsStub.new
|
||||
|
||||
@cmock_generator_plugin_array = CMockGeneratorPluginArray.new(@config, @utils)
|
||||
end
|
||||
@@ -29,8 +37,8 @@ describe CMockGeneratorPluginArray, "Verify CMockPGeneratorluginArray Module" do
|
||||
end
|
||||
|
||||
it "have set up internal priority" do
|
||||
assert_equal(nil, @cmock_generator_plugin_array.unity_helper)
|
||||
assert_equal(8, @cmock_generator_plugin_array.priority)
|
||||
assert_nil(@cmock_generator_plugin_array.unity_helper)
|
||||
assert_equal(8, @cmock_generator_plugin_array.priority)
|
||||
end
|
||||
|
||||
it "not include any additional include files" do
|
||||
@@ -88,10 +96,10 @@ describe CMockGeneratorPluginArray, "Verify CMockPGeneratorluginArray Module" do
|
||||
|
||||
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,
|
||||
:args => [{ :type => "const int*",
|
||||
:name => "tofu",
|
||||
:ptr? => true,
|
||||
:const? => true,
|
||||
}],
|
||||
:return => test_return[:string],
|
||||
:contains_ptr? => true }
|
||||
|
||||
@@ -26,8 +26,8 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module W
|
||||
end
|
||||
|
||||
it "have set up internal priority on init" do
|
||||
assert_equal(nil, @cmock_generator_plugin_expect.unity_helper)
|
||||
assert_equal(5, @cmock_generator_plugin_expect.priority)
|
||||
assert_nil(@cmock_generator_plugin_expect.unity_helper)
|
||||
assert_equal(5, @cmock_generator_plugin_expect.priority)
|
||||
end
|
||||
|
||||
it "not include any additional include files" do
|
||||
|
||||
@@ -26,8 +26,8 @@ describe CMockGeneratorPluginExpect, "Verify CMockGeneratorPluginExpect Module w
|
||||
end
|
||||
|
||||
it "have set up internal priority on init" do
|
||||
assert_equal(nil, @cmock_generator_plugin_expect.unity_helper)
|
||||
assert_equal(5, @cmock_generator_plugin_expect.priority)
|
||||
assert_nil(@cmock_generator_plugin_expect.unity_helper)
|
||||
assert_equal(5, @cmock_generator_plugin_expect.priority)
|
||||
end
|
||||
|
||||
it "not include any additional include files" do
|
||||
|
||||
@@ -21,9 +21,9 @@ describe CMockGeneratorPluginIgnoreArg, "Verify CMockGeneratorPluginIgnoreArg Mo
|
||||
:name => "chicken",
|
||||
:ptr? => false,
|
||||
},
|
||||
{ :type => "int*",
|
||||
:name => "beef",
|
||||
:ptr? => true,
|
||||
{ :type => "const int*",
|
||||
:name => "beef",
|
||||
:ptr? => true,
|
||||
:const? => true,
|
||||
},
|
||||
{ :type => "int*",
|
||||
|
||||
@@ -27,9 +27,9 @@ describe CMockGeneratorPluginReturnThruPtr, "Verify CMockGeneratorPluginReturnTh
|
||||
:name => "chicken",
|
||||
:ptr? => false,
|
||||
},
|
||||
{ :type => "int*",
|
||||
:name => "beef",
|
||||
:ptr? => true,
|
||||
{ :type => "const int*",
|
||||
:name => "beef",
|
||||
:ptr? => true,
|
||||
:const? => true,
|
||||
},
|
||||
{ :type => "int*",
|
||||
@@ -52,7 +52,7 @@ describe CMockGeneratorPluginReturnThruPtr, "Verify CMockGeneratorPluginReturnTh
|
||||
|
||||
def complex_func_expect
|
||||
@utils.expect :ptr_or_str?, false, ['int']
|
||||
@utils.expect :ptr_or_str?, true, ['int*']
|
||||
@utils.expect :ptr_or_str?, true, ['const int*']
|
||||
@utils.expect :ptr_or_str?, true, ['int*']
|
||||
end
|
||||
|
||||
@@ -124,11 +124,13 @@ describe CMockGeneratorPluginReturnThruPtr, "Verify CMockGeneratorPluginReturnTh
|
||||
expected =
|
||||
" if (cmock_call_instance->ReturnThruPtr_tofu_Used)\n" +
|
||||
" {\n" +
|
||||
" memcpy(tofu, cmock_call_instance->ReturnThruPtr_tofu_Val,\n" +
|
||||
" UNITY_TEST_ASSERT_NOT_NULL(tofu, cmock_line, CMockStringPtrIsNULL);\n" +
|
||||
" memcpy((void*)tofu, (void*)cmock_call_instance->ReturnThruPtr_tofu_Val,\n" +
|
||||
" cmock_call_instance->ReturnThruPtr_tofu_Size);\n" +
|
||||
" }\n" +
|
||||
" }\n"
|
||||
|
||||
returned = @cmock_generator_plugin_return_thru_ptr.mock_implementation(@complex_func).join("")
|
||||
assert_equal(expected, returned)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -20,7 +20,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
@config.expect :plugins, []
|
||||
@config.expect :plugins, []
|
||||
@config.expect :plugins, []
|
||||
@config.expect :treat_as, {'int' => 'INT','short' => 'INT16','long' => 'INT','char' => 'INT8','char*' => 'STRING'}
|
||||
@config.expect :treat_as, {'int' => 'INT','short' => 'INT16','long' => 'INT','char' => 'INT8','const char*' => 'STRING'}
|
||||
@cmock_generator_utils_simple = CMockGeneratorUtils.new(@config, {:unity_helper => @unity_helper})
|
||||
|
||||
@config.expect :when_ptr, :smart
|
||||
@@ -31,7 +31,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
@config.expect :plugins, [:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore]
|
||||
@config.expect :plugins, [:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore]
|
||||
@config.expect :plugins, [:array, :cexception, :return_thru_ptr, :ignore_arg, :ignore]
|
||||
@config.expect :treat_as, {'int' => 'INT','short' => 'INT16','long' => 'INT','char' => 'INT8','uint32_t' => 'HEX32','char*' => 'STRING'}
|
||||
@config.expect :treat_as, {'int' => 'INT','short' => 'INT16','long' => 'INT','char' => 'INT8','uint32_t' => 'HEX32','const char*' => 'STRING'}
|
||||
@cmock_generator_utils_complex = CMockGeneratorUtils.new(@config, {:unity_helper => @unity_helper, :A=>1, :B=>2})
|
||||
end
|
||||
|
||||
@@ -99,8 +99,8 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
arg1 = { :name => "Orange", :const? => false, :type => 'int', :ptr? => false }
|
||||
expected1 = " cmock_call_instance->Expected_Orange = Orange;\n"
|
||||
|
||||
arg2 = { :name => "Lemon", :const? => true, :type => 'const char*', :ptr? => true }
|
||||
expected2 = " cmock_call_instance->Expected_Lemon = (const char*)Lemon;\n"
|
||||
arg2 = { :name => "Lemon", :const? => true, :type => 'const char*', :ptr? => false }
|
||||
expected2 = " cmock_call_instance->Expected_Lemon = Lemon;\n"
|
||||
|
||||
arg3 = { :name => "Kiwi", :const? => false, :type => 'KIWI_T*', :ptr? => true }
|
||||
expected3 = " cmock_call_instance->Expected_Kiwi = Kiwi;\n"
|
||||
@@ -119,8 +119,8 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
expected1 = " cmock_call_instance->Expected_Orange = Orange;\n" +
|
||||
" cmock_call_instance->IgnoreArg_Orange = 0;\n"
|
||||
|
||||
arg2 = { :name => "Lemon", :const? => true, :type => 'const char*', :ptr? => true }
|
||||
expected2 = " cmock_call_instance->Expected_Lemon = (const char*)Lemon;\n" +
|
||||
arg2 = { :name => "Lemon", :const? => true, :type => 'const char*', :ptr? => false }
|
||||
expected2 = " cmock_call_instance->Expected_Lemon = Lemon;\n" +
|
||||
" cmock_call_instance->Expected_Lemon_Depth = Lemon_Depth;\n" +
|
||||
" cmock_call_instance->IgnoreArg_Lemon = 0;\n"
|
||||
|
||||
@@ -154,7 +154,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
expected = "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, stuff)\n{\n" +
|
||||
" cmock_call_instance->Expected_MyIntPtr = MyIntPtr;\n" +
|
||||
" memcpy(&cmock_call_instance->Expected_MyMyType, &MyMyType, sizeof(MY_TYPE));\n" +
|
||||
" cmock_call_instance->Expected_MyStr = (char*)MyStr;\n" +
|
||||
" cmock_call_instance->Expected_MyStr = MyStr;\n" +
|
||||
"}\n\n"
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_add_argument_loader(function))
|
||||
end
|
||||
@@ -171,12 +171,29 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
" cmock_call_instance->ReturnThruPtr_MyIntPtr_Used = 0;\n" +
|
||||
" memcpy(&cmock_call_instance->Expected_MyMyType, &MyMyType, sizeof(MY_TYPE));\n" +
|
||||
" cmock_call_instance->IgnoreArg_MyMyType = 0;\n" +
|
||||
" cmock_call_instance->Expected_MyStr = (char*)MyStr;\n" +
|
||||
" cmock_call_instance->Expected_MyStr = MyStr;\n" +
|
||||
" cmock_call_instance->IgnoreArg_MyStr = 0;\n" +
|
||||
"}\n\n"
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_add_argument_loader(function))
|
||||
end
|
||||
|
||||
it 'create an argument loader when the function has pointer arguments supporting arrays' do
|
||||
function = { :name => "Melon",
|
||||
:args_string => "stuff",
|
||||
:args => [test_arg[:const_ptr], test_arg[:double_ptr]]
|
||||
}
|
||||
expected = "void CMockExpectParameters_Melon(CMOCK_Melon_CALL_INSTANCE* cmock_call_instance, int* const MyConstPtr, int MyConstPtr_Depth, int const** MyDoublePtr, int MyDoublePtr_Depth)\n{\n" +
|
||||
" cmock_call_instance->Expected_MyConstPtr = MyConstPtr;\n" +
|
||||
" cmock_call_instance->Expected_MyConstPtr_Depth = MyConstPtr_Depth;\n" +
|
||||
" cmock_call_instance->IgnoreArg_MyConstPtr = 0;\n" +
|
||||
" cmock_call_instance->ReturnThruPtr_MyConstPtr_Used = 0;\n" +
|
||||
" cmock_call_instance->Expected_MyDoublePtr = MyDoublePtr;\n" +
|
||||
" cmock_call_instance->Expected_MyDoublePtr_Depth = MyDoublePtr_Depth;\n" +
|
||||
" cmock_call_instance->IgnoreArg_MyDoublePtr = 0;\n" +
|
||||
"}\n\n"
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_add_argument_loader(function))
|
||||
end
|
||||
|
||||
it "not call argument loader if there are no arguments to actually use for this function" do
|
||||
function = { :name => "Pineapple", :args_string => "void" }
|
||||
|
||||
@@ -231,7 +248,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
" UNITY_TEST_ASSERT_EQUAL_STRING(cmock_call_instance->Expected_MyStr, MyStr, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_STRING',''], ['char*']
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_STRING',''], ['const char*']
|
||||
assert_equal(expected, @cmock_generator_utils_simple.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
@@ -311,7 +328,7 @@ describe CMockGeneratorUtils, "Verify CMockGeneratorUtils Module" do
|
||||
" UNITY_TEST_ASSERT_EQUAL_STRING(cmock_call_instance->Expected_MyStr, MyStr, cmock_line, CMockStringMismatch);\n" +
|
||||
" }\n"
|
||||
@unity_helper.expect :nil?, false
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_STRING',''], ['char*']
|
||||
@unity_helper.expect :get_helper, ['UNITY_TEST_ASSERT_EQUAL_STRING',''], ['const char*']
|
||||
assert_equal(expected, @cmock_generator_utils_complex.code_verify_an_arg_expectation(function, arg))
|
||||
end
|
||||
|
||||
|
||||
@@ -805,32 +805,57 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do
|
||||
assert_equal(expected, @parser.parse("module", source)[:functions])
|
||||
end
|
||||
|
||||
it "should properly handle const before or after return type" do
|
||||
|
||||
it "should properly handle const before return type" do
|
||||
sources = [
|
||||
"const int * PorkRoast(void);\n",
|
||||
"int const * PorkRoast(void);\n",
|
||||
"const int* PorkRoast(void);\n",
|
||||
"const int *PorkRoast(void);\n"
|
||||
]
|
||||
|
||||
expected = [{ :var_arg => nil,
|
||||
:name => "PorkRoast",
|
||||
:return => { :type => "const int*",
|
||||
:name => 'cmock_to_return',
|
||||
:ptr? => true,
|
||||
:const? => true,
|
||||
:const_ptr? => false,
|
||||
:str => "const int* cmock_to_return",
|
||||
:void? => false
|
||||
},
|
||||
:modifier => "",
|
||||
:contains_ptr? => false,
|
||||
:args => [],
|
||||
:args_string => "void",
|
||||
:args_call => ""
|
||||
}]
|
||||
|
||||
sources.each do |source|
|
||||
assert_equal(expected, @parser.parse("module", source)[:functions])
|
||||
end
|
||||
end
|
||||
|
||||
it "should properly handle const before return type" do
|
||||
sources = [
|
||||
"int const * PorkRoast(void);\n",
|
||||
"int const* PorkRoast(void);\n",
|
||||
"const int *PorkRoast(void);\n",
|
||||
"int const *PorkRoast(void);\n"
|
||||
]
|
||||
|
||||
expected = [{ :var_arg=>nil,
|
||||
:name=>"PorkRoast",
|
||||
:return=> { :type => "int*",
|
||||
:name => 'cmock_to_return',
|
||||
:ptr? => true,
|
||||
:const? => true,
|
||||
:const_ptr? => false,
|
||||
:str => "int* cmock_to_return",
|
||||
:void? => false
|
||||
},
|
||||
:modifier=>"const",
|
||||
expected = [{ :var_arg => nil,
|
||||
:name => "PorkRoast",
|
||||
:return => { :type => "int const*",
|
||||
:name => 'cmock_to_return',
|
||||
:ptr? => true,
|
||||
:const? => true,
|
||||
:const_ptr? => false,
|
||||
:str => "int const* cmock_to_return",
|
||||
:void? => false
|
||||
},
|
||||
:modifier => "",
|
||||
:contains_ptr? => false,
|
||||
:args=>[],
|
||||
:args_string=>"void",
|
||||
:args_call=>""
|
||||
:args => [],
|
||||
:args_string => "void",
|
||||
:args_call => ""
|
||||
}]
|
||||
|
||||
sources.each do |source|
|
||||
|
||||
Vendored
+1
-1
Submodule vendor/unity updated: 60b13f0685...287e076962
Reference in New Issue
Block a user