ThrowTheSwitch / CMock

CMock - Mock/stub generator for C
http://throwtheswitch.org
MIT License
684 stars 276 forks source link

Array of constant pointers as an argument of mock function #450

Open slavko-m opened 1 year ago

slavko-m commented 1 year ago

Hi,

I am trying to mock a function from OpenVX:

vx_image vxCreateImageFromHandle(vx_context context, vx_df_image color, const vx_imagepatch_addressing_t addrs[], void *const ptrs[], vx_enum memory_type);

The problem is when the mock is generated, there is a weird function called UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY_ARRAY generated (which doesn't exist in Unity), because of void *const ptrs[] argument:

  if (!cmock_call_instance->IgnoreArg_ptrs)
  {
    UNITY_SET_DETAILS(CMockString_vxCreateImageFromHandle,CMockString_ptrs);
    if (cmock_call_instance->Expected_ptrs == NULL)
      { UNITY_TEST_ASSERT_NULL(ptrs, cmock_line, CMockStringExpNULL); }
    else
      { UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY_ARRAY(cmock_call_instance->Expected_ptrs, ptrs, cmock_call_instance->Expected_ptrs_Depth, cmock_line, CMockStringMismatch); }
  }

Anyone knows why is this happening, and if there is a solution for this?

mvandervoord commented 1 year ago

It's happening because it's a bug. ;)

It's processing the brackets and the pointer separately, and using each to specify that you're talking to an array... so it's decided it's and array of array (correctly) but (incorrectly) not collapsed it down to a single pointer as it does other things.

The handling for arrays and pointers should be getting major improvements soon. this is one of the things to be addressed.

Sorry for the headaches. :(

slavko-m commented 1 year ago

Thanks for the answer! For now, I will use workaround by using :unity_helper_path: where I defined

#define UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY_ARRAY UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY

to avoid build issues.