mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-09-19 16:49:58 +00:00
added handling to explicitly ignore externed functions in header file to be mocked
git-svn-id: http://cmock.svn.sourceforge.net/svnroot/cmock/trunk@116 bf332499-1b4d-0410-844d-d2d48d5cc64c
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ class CMockConfig
|
||||
:mock_prefix => 'Mock',
|
||||
:plugins => ['cexception', 'ignore'],
|
||||
:includes => [],
|
||||
:attributes => ['static', 'inline', 'extern', 'auto', 'register', '__ramfunc', '__irq', '__fiq'],
|
||||
:attributes => ['static', 'inline', 'auto', 'register', '__ramfunc', '__irq', '__fiq'],
|
||||
:tab => ' ',
|
||||
:expect_call_count_type => 'unsigned short',
|
||||
:enforce_strict_ordering => false,
|
||||
|
||||
@@ -60,8 +60,10 @@ class CMockHeaderParser
|
||||
@src_lines = source.split(/\s*;\s*/)
|
||||
|
||||
# remove function pointer array declarations (they're erroneously recognized as function prototypes);
|
||||
# look for something like (* blah [#]) - this can't be a parameter list
|
||||
# look for something like (* blah [#]) - this can't be a function parameter list
|
||||
@src_lines.delete_if {|line| !(line =~ /\(\s*\*(.*\[\d*\])??\s*\)/).nil?}
|
||||
# remove functions that are externed - mocking an extern'd function will lead to possible collisions at link time
|
||||
@src_lines.delete_if {|line| !(line =~ /^extern/).nil?}
|
||||
# remove blank lines
|
||||
@src_lines.delete_if {|line| line.strip.length == 0}
|
||||
end
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
unsigned int **ptr_ptr_return3(unsigned int **a);
|
||||
unsigned int ** ptr_ptr_return4(unsigned int ** a);
|
||||
|
||||
extern unsigned long int incredible_descriptors(register const unsigned short a);
|
||||
unsigned long int incredible_descriptors(register const unsigned short a);
|
||||
|
||||
:source:
|
||||
:header: |
|
||||
|
||||
@@ -6,7 +6,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
def setup
|
||||
create_mocks :config, :prototype_parser, :parsed
|
||||
@test_name = 'test_file.h'
|
||||
@config.expect.attributes.returns(['static', 'inline', '__ramfunc', 'register', 'extern'])
|
||||
@config.expect.attributes.returns(['static', 'inline', '__ramfunc', 'register'])
|
||||
end
|
||||
|
||||
def teardown
|
||||
@@ -17,7 +17,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
@parser = CMockHeaderParser.new(@prototype_parser, "", @config, @test_name)
|
||||
assert_equal([], @parser.prototypes)
|
||||
assert_equal([], @parser.src_lines)
|
||||
assert_equal(['static', 'inline', '__ramfunc', 'register', 'extern'], @parser.c_attributes)
|
||||
assert_equal(['static', 'inline', '__ramfunc', 'register'], @parser.c_attributes)
|
||||
end
|
||||
|
||||
|
||||
@@ -138,6 +138,22 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
|
||||
should "remove externed functions" do
|
||||
source =
|
||||
" extern uint32 foobar(unsigned int);\n" +
|
||||
"uint32 foo(unsigned int);\n" +
|
||||
"extern void bar(unsigned int);\n"
|
||||
@parser = CMockHeaderParser.new(@prototype_parser, source, @config, @test_name)
|
||||
|
||||
expected =
|
||||
[
|
||||
"uint32 foo(unsigned int)"
|
||||
]
|
||||
|
||||
assert_equal(expected, @parser.src_lines)
|
||||
end
|
||||
|
||||
|
||||
should "remove defines" do
|
||||
source =
|
||||
"#define whatever you feel like defining\n" +
|
||||
@@ -424,12 +440,12 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
|
||||
|
||||
should "not extract for mocking multiply defined prototypes" do
|
||||
# multiple instances of same function (particularly externs) can be present in output of preprocessor
|
||||
# just in case a function is defined multiple times and we haven't already dealt with it
|
||||
source =
|
||||
"extern int Foo(int a, unsigned int b);\n" +
|
||||
"int Foo(int a, unsigned int b);\n" +
|
||||
"void FunkyChicken (\n uint la,\n int de,\n bool da) ; \n" +
|
||||
" void \n tat();\n" +
|
||||
"extern int Foo (int, unsigned int);"
|
||||
"int Foo (int, unsigned int);"
|
||||
|
||||
@prototype_parser.expect.parse('int Foo(int a, unsigned int b)').returns(@parsed)
|
||||
|
||||
@@ -483,7 +499,7 @@ class CMockHeaderParserTest < Test::Unit::TestCase
|
||||
expected_hashes =
|
||||
[
|
||||
{
|
||||
:modifier => 'extern',
|
||||
:modifier => '',
|
||||
:args_string => 'woody',
|
||||
:return_type => 'little',
|
||||
:return_string => 'bo peep',
|
||||
|
||||
Reference in New Issue
Block a user