ThrowTheSwitch / CMock

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

Only first value of array is checked #475

Closed jvieira88 closed 2 months ago

jvieira88 commented 2 months ago

Hi,

I'm using CMock to generate some mock functions but I believe that there's a problem when checking expected arrays. It seems like the generated mock is only checking the value of the first element of the array. I'll try to point out where I the problem is in the hope that someone has seen this before and knows how to bypass it. I couldn't find any known issues highlighting this problem so I apologise in advance if this is known already.

Here's my environment: Ceedling:: 0.31.1 CMock:: 2.5.4 Unity:: 2.5.4 CException:: 1.3.3

Cmock is generating a mock with the following signature as expected (notice the data pointer and size arguments): HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef* hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t* pData, uint16_t Size, uint32_t Timeout)

At some point down the line within this mock, there's the following code:

  if (!cmock_call_instance->IgnoreArg_pData)
  {
    UNITY_SET_DETAILS(CMockString_HAL_I2C_Mem_Write,CMockString_pData);
    if (cmock_call_instance->Expected_pData == NULL)
      { UNITY_TEST_ASSERT_NULL(pData, cmock_line, CMockStringExpNULL); }
    else
      { UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(cmock_call_instance->Expected_pData, pData, 1, cmock_line, CMockStringMismatch); }
  }

In this area, notice that the generated mock is trying to test all elements of the array, but a size of 1 is used, when I was expecting the size to be the same as the argument uint16_t Size.

So, what happens is that only the first element of the array is checked. Is there any way of bypassing this? Or a quick fix?

mvandervoord commented 2 months ago

You'll want to enable the :array plugin and then use _ExpectWithArray instead of _Expect for these situations. :)

jvieira88 commented 2 months ago

Thank you, I confirm that worked for me ;)