Hello,
I am working with CppUTest and now CppUMock for the first time, and I have a small design issue for my first proper mock.
I have the following c function which I would like to mock:
i2c_transfer(struct i2c_msg *messages, size_t size);
Typical C pattern for passing array pointer and size of array alongside. I have already implemented MockNamedValueComparator and MockNamedValueCopier for struct i2c_msg ,which seems to work fine for single instance and fixed hardcoded array sizes.
But I have a struggles with finding a neat way to pass the array size to the Comparator of
struct i2c_msg. The problem is not to compare the freestanding size parameter, but to make my comparator to traverse over the wanted array size.My expect_ function looks like this:
void expect_i2c_transfer(i2c_msg *expected_msg, unsigned int size, int call_order)
{
mock()\
.expectOneCall("i2c_transfer")\
.withParameterOfType("struct i2c_msg", "messages", expected_msg)\
// hardcoded size
.withParameter("size", 2)\
.withCallOrder(call_order)\
.andReturnValue(true);
}
I also started to create comparators for corresponding C++ std::vector<i2c_msg> variants, but I figured I should keep the comparator true to the native data structure, and keep the otherwise typical C interface untouched.
Do anyone have a good suggestion to how to I could tackle this problem?
Please let me know if the problem is unclear
Thanks,
Preben