mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-08-14 07:07:49 +00:00
- updated docs to have latest config options
- allow function pointers to have an implied void like bleh() git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@178 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -76,7 +76,7 @@ class CMockHeaderParser
|
||||
source.gsub!(/^(?:.*\W)?typedef\W.*/, '') # remove typedef statements
|
||||
|
||||
#scan for functions which return function pointers, because they are a pain
|
||||
source.gsub!(/([\w\s\*]+)\(*\(\s*\*([\w\s\*]+)\s*\(([\w\s\*,]+)\)\)\s*\(([\w\s\*,]+)\)\)*/) do |m|
|
||||
source.gsub!(/([\w\s\*]+)\(*\(\s*\*([\w\s\*]+)\s*\(([\w\s\*,]*)\)\)\s*\(([\w\s\*,]*)\)\)*/) do |m|
|
||||
functype = "cmock_#{@module_name}_func_ptr#{@typedefs.size + 1}"
|
||||
@typedefs << "typedef #{$1.strip}(*#{functype})(#{$4});"
|
||||
"#{functype} #{$2.strip}(#{$3});"
|
||||
@@ -146,7 +146,7 @@ class CMockHeaderParser
|
||||
arg_list.gsub!(/\*(\w)/,'* \1') # pull asterisks away from arg to place asterisks with type (where they belong)
|
||||
|
||||
#scan argument list for function pointers and replace them with custom types
|
||||
arg_list.gsub!(/([\w\s]+)\(*\(\s*\*([\w\s\*]+)\)\s*\(([\w\s\*,]+)\)\)*/) do |m|
|
||||
arg_list.gsub!(/([\w\s]+)\(*\(\s*\*([\w\s\*]+)\)\s*\(([\w\s\*,]*)\)\)*/) do |m|
|
||||
functype = "cmock_#{@module_name}_func_ptr#{@typedefs.size + 1}"
|
||||
funcret = $1.strip
|
||||
funcname = $2.strip
|
||||
|
||||
@@ -855,6 +855,29 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(typedefs, result[:typedefs])
|
||||
end
|
||||
|
||||
should "extract functions containing a function pointer with an implied void" do
|
||||
source = "void FunkyTurkey(unsigned int (*func_ptr)())"
|
||||
expected = [{ :var_arg=>nil,
|
||||
:return=>{ :type => "void",
|
||||
:name => 'cmock_to_return',
|
||||
:ptr? => false,
|
||||
:const? => false,
|
||||
:str => "void cmock_to_return",
|
||||
:void? => true
|
||||
},
|
||||
:name=>"FunkyTurkey",
|
||||
:modifier=>"",
|
||||
:contains_ptr? => false,
|
||||
:args=>[ {:type=>"cmock_module_func_ptr1", :name=>"func_ptr", :ptr? => false, :const? => false}
|
||||
],
|
||||
:args_string=>"cmock_module_func_ptr1 func_ptr",
|
||||
:args_call=>"func_ptr" }]
|
||||
typedefs = ["typedef unsigned int(*cmock_module_func_ptr1)();"]
|
||||
result = @parser.parse("module", source)
|
||||
assert_equal(expected, result[:functions])
|
||||
assert_equal(typedefs, result[:typedefs])
|
||||
end
|
||||
|
||||
should "extract functions containing a constant function pointer and a pointer in the nested arg list" do
|
||||
source = "void FunkyChicken(unsigned int (* const func_ptr)(unsigned long int * , char))"
|
||||
expected = [{ :var_arg=>nil,
|
||||
@@ -971,6 +994,28 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
assert_equal(typedefs, result[:typedefs])
|
||||
end
|
||||
|
||||
should "extract functions returning a function pointer with implied void" do
|
||||
source = "unsigned short (*FunkyTweetie())()"
|
||||
expected = [{ :var_arg=>nil,
|
||||
:return=>{ :type => "cmock_module_func_ptr1",
|
||||
:name => 'cmock_to_return',
|
||||
:ptr? => false,
|
||||
:const? => false,
|
||||
:str => "cmock_module_func_ptr1 cmock_to_return",
|
||||
:void? => false
|
||||
},
|
||||
:name=>"FunkyTweetie",
|
||||
:modifier=>"",
|
||||
:contains_ptr? => false,
|
||||
:args=>[],
|
||||
:args_string=>"void",
|
||||
:args_call=>"" }]
|
||||
typedefs = ["typedef unsigned short(*cmock_module_func_ptr1)();"]
|
||||
result = @parser.parse("module", source)
|
||||
assert_equal(expected, result[:functions])
|
||||
assert_equal(typedefs, result[:typedefs])
|
||||
end
|
||||
|
||||
should "extract functions returning a function pointer where everything is a void" do
|
||||
source = "void (* FunkySeaGull(void))(void)"
|
||||
expected = [{ :var_arg=>nil,
|
||||
|
||||
Reference in New Issue
Block a user