mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-06-05 21:15:20 +00:00
Support void* arguments as arrays of bytes by default instead of pointers.
This commit is contained in:
+1
-1
@@ -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',
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
...
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user