ElectronVector / fake_function_framework

A plug-in for Ceedling to use the Fake Function Framework (fff) for mocking instead of Cmock.
MIT License
37 stars 13 forks source link

fff plugin generates a pointer to const return function for a const pointer return one #3

Closed whyglinux closed 6 years ago

whyglinux commented 7 years ago

Hi, Matt

When declaring a function as following in the header file (.h) char const bar_return_const_ptr(int one); the fff plugin will generate one like this DEFINE_FAKE_VALUE_FUNC1(const char, bar_return_const_ptr, int); Since the function's declaration and definition are different, the build fails.

The function[:modifier] genrated by the Cmock is true both in the following 2 cases: const char bar_return_ptr_to_const(int one); char const bar_return_const_ptr(int one); therefore we must distinguish them from each other. This is where the function[:return][:const?] and function[:return][:const_ptr?] can do.

I made these changes and solved the problem.

$ diff fff_mock_generator.rb ...
122,124c122,126
<       if function.has_key? :modifier
<           # Prepend any modifier. If there isn't one, trim any leading whitespace.
<           return_type = "#{function[:modifier]} #{return_type}".lstrip
---
>       if function[:return][:const?]
>       return_type = "const " + return_type
>       end
>       if function[:return][:const_ptr?]
>       return_type += " const"

And the test
$ diff bar.h ...
12c12,13
< const char * bar_return_const_ptr(int one);
---
> const char * bar_return_ptr_to_const(int one);
> char * const bar_return_const_ptr(int one);

Please give a review, a test and update the trunk.

whyglinux

mchernosky commented 7 years ago

Ah, another case huh?