Hello All,
I am having a problem with writing a mock to a function which accepts multiple parameters. The function looks like below. (A pseudo representation)
class ExternalClass
{
ReplyPacketOut(unsigned char *pucCommandBuff, unsigned int *uiMessageLen)
{
// Function body
}
}
Within my class the function is called like below,
class MyClass
{
FunctionB()
{
unsigned char parameter1[100];
unsigned int parameter2 = sizeof(parameter1);
ExternalClass->ReplyPacketOut(parameter1, ¶meter2);
}
}
In my mocked function, I have implemented the function as below,
class MockedClass
{
ReplyPacketOut(unsigned char *param1, unsigned int *parm2)
{
mock().actualCall("ReplyPacketOut").withParameter("pucCommandBuff",param1).withParameter("uiMessageLen",param2);
}
}
In my test I am expecting the call as follows,
TEST
{
unsigned char my_param1[100];
unsigned int my_param2 = sizeof(my_param1);
mock().expectCall("ReplyPacketOut").withParameter("pucCommandBuff",my_param1).withParameter("uiMessageLen",my_param2);
}
This fails, may be because ReplyPacketOut is not actually getting the pointer that I am specifying.
Mock Failure: Unexpected parameter value to parameter "pucCommandBuff" to function "ReplyPacketOut": <0x2a3fb24>
1> EXPECTED calls that DID NOT happen related to function: ReplyPacketOut
1> (object address: 00E5AD38)::ReplyPacketOut -> void* pucCommandBuff: <0x92e9a4>, unsigned int uiMessageLen: < 256 (0x00000100)>
1> ACTUAL calls that DID happen related to function: ReplyPacketOut
1> <none>
1> ACTUAL unexpected parameter passed to function: ReplyPacketOut
1> void* pucCommandBuff: <0x2a3fb24>
In fact the pucCommandBuff and uiMessageLen are parameters that will be returning values back to the caller. (I guess this is what output parameters means, or is it not?)
With that in mind, I changed the TEST as follows,
TEST
{
unsigned char my_param1[100];
unsigned int my_param2 = sizeof(my_param1);
mock().expectOneCall("ReplyPacketOut").withOutputParameterReturning("pucCommandBuff",my_param1,sizeof(my_param1)).withOutputParameterReturning("uiMessageLen",&my_param2,sizeof(my_param2));
}
And I changed the Mock object as follows,
class MockedClass
{
ReplyPacketOut(unsigned char *param1, unsigned int *parm2)
{
mock().actualCall("ReplyPacketOut").withOutputParameter("pucCommandBuff",pucCommandBuff).withOutputParameter("uiMessageLen",uiMessageLen);
}
}
But then the TEST fails giving following error,
1> Mock Failure: Expected call on object for function "ReplyPacketOut" but it did not happen.
1> EXPECTED calls that DID NOT happen related to function: ReplyPacketOut
1> (object address: 0137C200)::ReplyPacketOut -> const void* pucCommandBuff: <output>, const void* uiMessageLen: <output>
1> ACTUAL calls that DID happen related to function: ReplyPacketOut
1> <none>
1>
1> - 0 ms
Can someone help me perform this test?
Thank you.