From 1fdfb6189173d14ddcb2bf38e28a16cb3e3293db Mon Sep 17 00:00:00 2001 From: Mark VanderVoord Date: Tue, 18 Aug 2015 13:28:29 -0400 Subject: [PATCH] Support void* arguments as arrays of bytes by default instead of pointers. --- lib/cmock_config.rb | 2 +- lib/cmock_header_parser.rb | 2 +- .../array_and_pointer_handling.yml | 61 +++++++++++++++++++ test/unit/cmock_header_parser_test.rb | 21 +++++++ 4 files changed, 84 insertions(+), 2 deletions(-) diff --git a/lib/cmock_config.rb b/lib/cmock_config.rb index 058157b..715f601 100644 --- a/lib/cmock_config.rb +++ b/lib/cmock_config.rb @@ -112,7 +112,7 @@ class CMockConfig 'uint32_t' => 'HEX32', 'UINT32' => 'HEX32', 'UINT32_T' => 'HEX32', - 'void*' => 'PTR', + 'void*' => 'HEX8_ARRAY', 'unsigned short' => 'HEX16', 'uint16' => 'HEX16', 'uint16_t' => 'HEX16', diff --git a/lib/cmock_header_parser.rb b/lib/cmock_header_parser.rb index 472ab92..f53b961 100644 --- a/lib/cmock_header_parser.rb +++ b/lib/cmock_header_parser.rb @@ -139,7 +139,7 @@ class CMockHeaderParser return args if (arg =~ /^\s*((\.\.\.)|(void))\s*$/) # we're done if we reach void by itself or ... arg_array = arg.split arg_elements = arg_array - @c_attributes # split up words and remove known attributes - args << { :type => (arg_type =arg_elements[0..-2].join(' ')), + args << { :type => (arg_type = arg_elements[0..-2].join(' ')), :name => arg_elements[-1], :ptr? => divine_ptr(arg_type), :const? => arg_array.include?('const') diff --git a/test/system/test_interactions/array_and_pointer_handling.yml b/test/system/test_interactions/array_and_pointer_handling.yml index 4e8c5c0..5d48761 100644 --- a/test/system/test_interactions/array_and_pointer_handling.yml +++ b/test/system/test_interactions/array_and_pointer_handling.yml @@ -21,6 +21,7 @@ void no_pointers(int a, const char* b); int mixed(int a, int* b, int c); void potential_packing_problem(short *a); + void voidpointerfunc(void* a); :source: :header: | @@ -29,6 +30,7 @@ void function_c(void); int function_d(void); void function_e(void); + void function_f(void); :code: | void function_a(void) @@ -55,6 +57,10 @@ potential_packing_problem(&test_list[1]); } + void function_f(void) { + voidpointerfunc("hello"); + } + :tests: :common: | void setUp(void) {} @@ -380,5 +386,60 @@ function_e(); } + - :pass: TRUE + :should: 'handle a void pointers as arguments and still be able to use the array plugin' + :code: | + test() + { + char* expect_list = "hello"; + voidpointerfunc_ExpectWithArray(expect_list, 5); + + function_f(); + } + + - :pass: TRUE + :should: 'handle a void pointers as arguments and still be able to use the array plugin (short)' + :code: | + test() + { + char* expect_list = "help!"; + voidpointerfunc_ExpectWithArray(expect_list, 3); + + function_f(); + } + + - :pass: FALSE + :should: 'handle a void pointers as arguments and still be able to use the array plugin (fail)' + :code: | + test() + { + char* expect_list = "help!"; + voidpointerfunc_ExpectWithArray(expect_list, 4); + + function_f(); + } + + - :pass: TRUE + :should: 'handle a void pointer with a standard expectation (pass)' + :code: | + test() + { + char* expect_list = "h"; + voidpointerfunc_Expect(expect_list); + + function_f(); + } + + - :pass: FALSE + :should: 'handle a void pointer with a standard expectation (fail)' + :code: | + test() + { + char* expect_list = "g"; + voidpointerfunc_Expect(expect_list); + + function_f(); + } + ... diff --git a/test/unit/cmock_header_parser_test.rb b/test/unit/cmock_header_parser_test.rb index c72f027..743fc47 100644 --- a/test/unit/cmock_header_parser_test.rb +++ b/test/unit/cmock_header_parser_test.rb @@ -1313,6 +1313,27 @@ describe CMockHeaderParser, "Verify CMockHeaderParser Module" do assert_equal(expected, @parser.parse("module", source)[:functions]) end + it "extract functions with void pointers" do + source = "void* MoreSillySongs(void* stuff);\n" + expected = [{ :var_arg=>nil, + :return=> { :type => "void*", + :name => 'cmock_to_return', + :ptr? => true, + :const? => false, + :str => "void* cmock_to_return", + :void? => false + }, + :name=>"MoreSillySongs", + :modifier=>"", + :contains_ptr? => true, + :args=>[ {:type=>"void*", :name=>"stuff", :ptr? => true, :const? => false} + ], + :args_string=>"void* stuff", + :args_call=>"stuff" + }] + assert_equal(expected, @parser.parse("module", source)[:functions]) + end + it "extract functions with strippable confusing junk like gcc attributes" do source = "int LaverneAndShirley(int Lenny, int Squiggy) __attribute__((weak)) __attribute__ ((deprecated));\n" expected = [{ :var_arg=>nil,