I have a structure that I'm trying to add a comparator to in my unit tests. It's a basic structure with a few basic elements, that does not seem to be applied when I attempt to use it in the mocks. I've created a comparator and copier and have written tests to validate them:
TEST(bcm82209_si_parse, comparisonOfTxSetParametersOnCallShouldFail)
{
int rc = 0;
int p_ctxt_compare = 5;
int p_ctxt = 5;
plp_bcm_tx_t tx_to_compare = {4,5,6,0,0,7};
plp_bcm_tx_t tx_to_program = {0,0,0,0,0,0};
uint32 phy_id = 2, if_side=0, lane=3;
mock().expectOneCall("bcm_pm_if_tx_set")
.withOutputParameterReturning("p_ctxt", &p_ctxt_compare, sizeof(int))
.withUnsignedIntParameter("phy_id", phy_id)
.withUnsignedIntParameter("if_side", if_side)
.withUnsignedIntParameter("lane", lane)
.withOutputParameterOfTypeReturning("plp_bcm_tx_t", "tx", &tx_to_compare)
.withOutputParameterReturning("tx", &tx_to_compare, sizeof(plp_bcm_tx_t))
.andReturnValue(0);
rc = mock().actualCall("bcm_pm_if_tx_set")
.withOutputParameter("p_ctxt", &p_ctxt)
.withUnsignedIntParameter("phy_id", 2)
.withUnsignedIntParameter("if_side", 0)
.withUnsignedIntParameter("lane", 3)
.withOutputParameterOfType("plp_bcm_tx_t", "tx", &tx_to_program)
.returnValue().getIntValue();
CHECK_EQUAL(0,rc);
}
class BcmTxSettingsComparator : public MockNamedValueComparator
{
public:
virtual bool isEqual(const plp_bcm_tx_t* obj1, const plp_bcm_tx_t* obj2)
{
bool match = FALSE;
printf("isEqual: comparing plp_bcm_tx_t* objects\n");
if ((obj1->pre == obj2->pre) &&
(obj1->main == obj2->main) &&
(obj1->post == obj2->post) &&
(obj1->post2 == obj2->post2) &&
(obj1->post3 == obj2->post3) &&
(obj1->amp == obj2->amp)) match = TRUE;
return match;
}
virtual bool isEqual(const void* object1, const void* object2)
{
bool match = FALSE;
printf("isEqual: comparing void* objects\n");
const plp_bcm_tx_t* obj1 = (const plp_bcm_tx_t*) object1;
const plp_bcm_tx_t* obj2 = (const plp_bcm_tx_t*) object2;
if ((obj1->pre == obj2->pre) &&
(obj1->main == obj2->main) &&
(obj1->post == obj2->post) &&
(obj1->post2 == obj2->post2) &&
(obj1->post3 == obj2->post3) &&
(obj1->amp == obj2->amp)) match = TRUE;
return match;
}
SimpleString valueToString(const void* object)
{
const plp_bcm_tx_t* obj = (const plp_bcm_tx_t*) object;
return StringFromFormat("pre: 0x%X, main 0x%X, post 0x%X, post2 0x%X, post3: 0x%X, amp: 0x%X",
obj->pre, obj->main, obj->post, obj->post2, obj->post3, obj->amp);
}
SimpleString stringFrom(const plp_bcm_tx_t& obj)
{
return StringFromFormat("pre: 0x%X, main 0x%X, post 0x%X, post2 0x%X, post3: 0x%X, amp: 0x%X",
obj.pre, obj.main, obj.post, obj.post2, obj.post3, obj.amp); }
};
class BcmTxSettingsCopier : public MockNamedValueCopier
{
public:
virtual void copy(void * out, const void* in)
{
plp_bcm_tx_t *tx_out = (plp_bcm_tx_t *)out;
const plp_bcm_tx_t *tx_in = (plp_bcm_tx_t *)in;
printf("Copying void *s\n");
tx_out->pre = tx_in->pre;
tx_out->main = tx_in->main;
tx_out->post = tx_in->post;
tx_out->post2 = tx_in->post2;
tx_out->post3 = tx_in->post3;
tx_out->amp = tx_in->amp;
}
virtual void copy(plp_bcm_tx_t *tx_out, const plp_bcm_tx_t* tx_in)
{
printf("Copying plp_bcm_tx_t *s\n");
tx_out->pre = tx_in->pre;
tx_out->main = tx_in->main;
tx_out->post = tx_in->post;
tx_out->post2 = tx_in->post2;
tx_out->post3 = tx_in->post3;
tx_out->amp = tx_in->amp;
}
virtual void copy(plp_bcm_tx_t tx_out, const plp_bcm_tx_t tx_in)
{
printf("Copying plp_bcm_tx_t (non-pointer)\n");
tx_out.pre = tx_in.pre;
tx_out.main = tx_in.main;
tx_out.post2 = tx_in.post2;
tx_out.post3 = tx_in.post3;
tx_out.amp = tx_in.amp;
}
};
I've confirmed that the comparator is not being used during the mock functionality by forcing the return value to "false" in both isEqual functions, and the test case comparisonOfTxSetParametersOnCallShouldFail will still pass. Could someone please help me identify what is wrong here?
Thanks.