假设我有一个像这样的模拟:
class MockSocket : public Socket
{
public:
MOCK_METHOD1(Write, bool(Packet *p));
};
我想测试是否使用满足以下条件的对象调用Write方法:
如何在GMock中编写第二个条件? 我试过这样的东西,但第二个属性不能正常工作。
EXPECT_CALL(ms, Write(AllOf(Property(&ESMCPacket::get_QL, 0), Property(&ESMCPacket::get_MAC, (mmac_source1))))).Times(1);
答案 0 :(得分:2)
我不确定gMock是否具有您需要的内存匹配器,但编写自定义内存匹配器是微不足道的:
MATCHER_P2(MatchesMemory, data, size, "") {
return memcmp(arg, data, size) == 0;
}
EXPECT_CALL(
ms,
Write(AllOf(Property(&ESMCPacket::get_QL, 0),
Property(&ESMCPacket::get_MAC, MatchesMemory("abc\0ef", 6))))
.Times(1);