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

How to add macros to the generated mock files ??? #328

Closed
guillermoarb opened this issue Sep 8, 2020 · 3 comments
Closed

How to add macros to the generated mock files ??? #328

guillermoarb opened this issue Sep 8, 2020 · 3 comments

Comments

@guillermoarb
Copy link

Hi, I wonder for example why CMock does not include in the mock_reference.h created from reference.h the macros that are created in reference.h file.

For example if I am testing test.c then I mock reference.h and inside this there is a definition e.g. #def MASK 0x01 and I want to use it in my unit testing file ut_test.c so the definition is not copied into the mocked version mock_reference.h so then I have to add the #def MASK 0x01 to my test file ut_test.c, if I want it to work. But then I have to maintain to macros with the same value.

Here is a code example, sorry if there is not Ok, is just something quick to explain my question.

reference.h

#def MASK 0x01

test.c

#include reference.h

uint8 check_mask(unit8 input)
{
    return (input & MASK);
}

ut_test.c

#include test.h
#include mock_reference.h

test_TC01(void)
{

ret_val = check_mask(0x02);

TEST_ASSERT_EQUAL_UINT8(MASK, ret_val);  /*This won't compile, MASK is not defined in mock_reference.h */

reset_test( );
}

@Tuc-an
Copy link
Contributor

Tuc-an commented Sep 8, 2020

My generated mocks usually do #include the original header file - what are the first 10 lines of mock_reference.h?

@laurensmiers
Copy link
Contributor

Are you using ceedling? If so, check if the :use_test_preprocessor: is set to FALSE.
Otherwise cmock will receive a preprocessed header, which has all defines/macros/includes/... removed, and so the generated header will also have this stuff removed.

@M-Bab
Copy link

M-Bab commented Jan 12, 2023

Please check if this is the problem described here: ThrowTheSwitch/Ceedling#706 (comment)

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

5 participants