ceedling/cmock: mocking variadic functions, or va_list parameter

521 Views Asked by At

I tried to mock this code:

int myPrintf(const char *fmt, ...);
int myVprintf(const char *fmt, va_list args);

for both functions some wrong code is generated. For example:

typedef int (* CMOCK_myPrintf_CALLBACK)(const char* fmt, int cmock_num_calls);
void myPrintf_AddCallback(CMOCK_myPrintf_CALLBACK Callback);
void myPrintf_Stub(CMOCK_myPrintf_CALLBACK Callback);
#define myPrintf_StubWithCallback myPrintf_Stub

Even, in the case of the va_list parameters, generated code does not compile:

void CMockExpectParameters_myVprintf(CMOCK_myVprintf_CALL_INSTANCE* cmock_call_instance, const char* fmt, va_list args)
{
  cmock_call_instance->Expected_fmt = fmt;
  memcpy((void*)(&cmock_call_instance->Expected_args), (void*)(&args),
         sizeof(va_list[sizeof(args) == sizeof(va_list) ? 1 : -1])); /* add va_list to :treat_as_array if this causes an error */
}

Is there a way around these problems?

0

There are 0 best solutions below