Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for fakes with const parameters #3

Closed
michahoiting opened this issue Nov 8, 2012 · 4 comments
Closed

Add support for fakes with const parameters #3

michahoiting opened this issue Nov 8, 2012 · 4 comments

Comments

@michahoiting
Copy link
Contributor

Using a fake function that has a const parameter leads to compiler errors.
For instance using a fake for the function ‘strlcpy’ see below.

  • fff_test_cpp.cpp: FAKE_VALUE_FUNC(int, strlcpy3, char* const, const char* const, const size_t);
  • test_cases.include: TEST_F(FFFTestSuite, when_fake_func_called_then_const_arguments_captured) { char dst[80]; strlcpy3(dst, __FUNCTION__, sizeof(__FUNCTION__)); }
  • Running gmake:
    Building file: fff_test_cpp.cpp
    Invoking: GCC C++ Compiler
    g++ -I../ -O0 -g3 -Wall -c -o "../build/fff_test_cpp.o" "fff_test_cpp.cpp"
    fff_test_cpp.cpp:23: error: structure strlcpy3_fake' with uninitialized const members fff_test_cpp.cpp: In functionint strlcpy3(char_, const char_, size_t)':
    fff_test_cpp.cpp:23: error: assignment of read-only data-member strlcpy3_Fake::arg0_val' fff_test_cpp.cpp:23: error: assignment of read-only data-memberstrlcpy3_Fake::arg1_val'
    fff_test_cpp.cpp:23: error: assignment of read-only data-member `strlcpy3_Fake::arg2_val'
    fff_test_cpp.cpp:23: error: assignment of read-only location
    fff_test_cpp.cpp:23: error: assignment of read-only location
    fff_test_cpp.cpp:23: error: assignment of read-only location
    gmake[1]: *** [../build/fff_test_cpp.o] Error 1
  • See also https://github.com/michahoiting/fff/tree/const-issue.
    The macros SAVE_ARG and SAVE_ARG_HISTORY in fff.h will need to be changed.
@daveismith
Copy link

Agreed, this feature would significantly increase the utility of fff for me.

@vperron
Copy link

vperron commented Apr 10, 2013

Have been using @michahoiting 's fork with no issues for my (strongly) const parameterized code. Maybe it'd be time considering pulling that request ?
Many thanks for that microframework, has been incredibly helpful !

@meekrosoft
Copy link
Owner

I'd love to include this feature but I haven't received a pull request so far. Let me take a look at how to get his changes in here.

@meekrosoft
Copy link
Owner

Hi folks,
I have merged Micha's const parameter support. Many thanks to Micha for sharing!
Cheers,
Mike

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants