In my module there are function like macros. This is no obstacle for a module test, but it is an obstacle for other modules which include this module.
My question: is there a way to make a part of the .h file visible for CMock only?
e.g.:
Module_1.h:
#ifdef MODULE_TEST_CMOCK
void FunctionLikeMacro_1(unsigned int x);
unsigned int FunctionLikeMacro_2(void);
#else
#define FunctionLikeMacro_1(x) (HWREGISTER_1 = (unsigned int)x)
#define FunctionLikeMacro_2 ((unsigned int)HWREGISTER_2)
#endif
This is the way I would prefer. But where should I define MODULE_TEST_CMOCK? I can't define it in the Project.yml because with this change, my module tests for Module_1 would fail. But on the other hand, in my module tests for Module_2, which needs a mocked version of Module_1.h, I can't expect calls of FunctionLikeMacro_1 and FunctionLikeMacro_2.
Thank you for your time. :)
According to
docs/CeedlingPacket.md
, you can add specific defines to each test file that is to be compiled to the:defines:
section inproject.yml
:So in your case, you would have to add
MODULE_TEST_CMOCK
for all test files in which want to mock Module_1.h to the:defines:
seciton inproject.yml
.I tried it using your example header file two test files:
test/test_module1.c
which includedModule_1.h
directly andtest/test_module2.c
which includedmock_Module_1.h
. I added this to myproject.yml
:And this seemed to work fine. I could use
FunctionLikeMacro_2_IgnoreAndReturn()
fromtest/test_module2.c
and the tests behaved as expected, while the macros were being used directly for the tests intest/test_module1.c
.