how to make EXPECT_CALL on union object

263 views
Skip to first unread message

Tomasz Michalski

unread,
Dec 16, 2016, 1:08:46 PM12/16/16
to Google C++ Mocking Framework
Hi
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
{
   
struct
   
{
        u32 PSU_X
:                 8;
        u32 PSU_Y
:                 4;
        u32
:                      3;
        u32 PSU_EN
:                1;
        u32 PSU_BYTE
:              8;
        u32
:                      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));
}


TEST_F
(....

   
SPsuAlarm psuAlarm = SPsuAlarm();
    psuAlarm
.bits.PSU_EN = 0x0;
    EXPECT_CALL
(*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
Forward
0 new messages