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

Cmock discards const qualifier with custom types #484

Open
astro-stan opened this issue Oct 13, 2024 · 0 comments
Open

Cmock discards const qualifier with custom types #484

astro-stan opened this issue Oct 13, 2024 · 0 comments

Comments

@astro-stan
Copy link

astro-stan commented Oct 13, 2024

Consider the following example:

// MyHeader.h

typedef enum {
    a,
    b,
    c,
} MyType_t;

int myFunc(
    const MyType_t t_MyType
);

When myFunc gets mocked it results in the following code being generated:

// MockMyHeader.c

...

void CMockExpectParameters_MyFunc(CMOCK_MyFunc_CALL_INSTANCE* cmock_call_instance, const MyType_t t_MyType)
{
  memcpy((void*)(&cmock_call_instance->Expected_t_MyType), (void*)(&t_MyType), // <---- NO CONST WHEN CASTING
         sizeof(MyType_t[sizeof(t_MyType) == sizeof(MyType_t) ? 1 : -1])); /* add MyType_t to :treat_as_array if this causes an error */
  cmock_call_instance->IgnoreArg_t_MyType = 0;
}

ITC_Status_t MyFunc(const MyType_t t_MyType)
{
  ...
  if (!cmock_call_instance->IgnoreArg_t_MyType)
  {
    UNITY_SET_DETAILS(CMockString_MyFunc,CMockString_t_MyType);
    // v AGAIN NO CONST WHEN CASTING v
    UNITY_TEST_ASSERT_EQUAL_MEMORY((void*)(&cmock_call_instance->Expected_t_MyType), (void*)(&t_MyType), sizeof(MyType_t), cmock_line, CMockStringMismatch);
  }
  }
  ...
}
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

1 participant