how to make EXPECT_CALL on union object

Skip to first unread message

Tomasz Michalski

Dec 16, 2016, 1:08:46 PM12/16/16
to Google C++ Mocking Framework
Due to some reason passing to EXPECT_CALL struct or union argument is designed by gmock people in terrible way. I don't know maybe someone was a bit drunken and implemented it in this way or if not drunken I don't know what problems they had, for sure this might be designed in friendly way. However it is as it is and I need now to do EXPECT_CALL on union argument. Here is what I have:

in product code in header file:
union SPsuAlarm
        u32 PSU_X
:                 8;
        u32 PSU_Y
:                 4;
:                      3;
        u32 PSU_EN
:                1;
        u32 PSU_BYTE
:              8;
:                      7;
        u32 PSU_GOOD
:              1;
} bits;
    u32 value

in unit test cpp:
bool operator==(const SPsuAlarm& left, const SPsuAlarm& right)
return 0 == memcmp(&left, &right, sizeof(SPsuAlarm));


SPsuAlarm psuAlarm = SPsuAlarm();
.bits.PSU_EN = 0x0;
(*myMock, setPsuAlarm(2, psuAlarm)).WillOnce(Return(0)); //setPsuAlarm is mocked, it has 2 arguments const int& and const SPsuAlarm&

Unfortunatelly I got error  
error: no match for 'operator==' (operand types are 'const SPsuAlarm' and 'const SPsuAlarm')
 GMOCK_IMPLEMENT_COMPARISON_MATCHER_(Eq, ==, "is equal to", "isn't equal to");

and operator== is defined but not used, so it is not seen by gmock.

Now I expect that authors of this google mock tell me what to do in order to fix the issue.

Reply all
Reply to author
0 new messages