对代码有所删改,如有语法错误请忽略。问题在于SetArgPointee 这个 函数,详情可见代码
这是原函数声明: 已经用virtual声明了 ,
class AlarmService
{
public:
virtual SWORD32 CurlPost(const char *pcURL, struct curl_slist *ptHeaders, void *pvFormData, size_t qwFormDataSize, ResponsHeaderData * ptResHeadData);
}
这是mock 类对上述函数的打桩
MOCK_METHOD5(CurlPost, SWORD32(const char *, struct curl_slist *, void *, size_t, ResponsHeaderData * ));
这是对该 CurlPost 函数的调用
TEST(XXX, XXXX)
{
AlarmService_Mock *tAlarmServiceMockObj = new AlarmService_Mock();
ResponsHeaderData tResHeadDataTest;
memset(&tResHeadDataTest, 0, sizeof(ResponsHeaderData));
CurlWriteData tRespHeaderObjTest;
CurlWriteData tRespDataObjTest;
tRespHeaderObjTest.m_pcData = "RespHeader";
tRespHeaderObjTest.m_qwSize = 11;
tRespDataObjTest.m_pcData = "RespData";
tRespDataObjTest.m_qwSize = 9;
tResHeadDataTest.m_tRespHeader = tRespHeaderObjTest;
tResHeadDataTest.m_tRespData = tRespDataObjTest;
ResponsHeaderData* a = (ResponsHeaderData*)&tResHeadDataTest;
EXPECT_CALL(*tAlarmServiceMockObj, CurlPost(_, _, _, _, _)).WillRepeatedly(Return(0)); //这里没问题
EXPECT_CALL(*tAlarmServiceMockObj, CurlPost(_, _, _, _, _)).WillRepeatedly(SetArgPointee<4>(a), Return(0)); //一旦加上SetArgPointee<4>(a)就会报错
tAlarmServiceMockObj->GetToken(strTokenValue); // GetToken会调用CurlPost,先需要CurlPost中的第五个出参 ResponsHeaderData * 用于后续判断
delete tAlarmServiceMockObj;
}
报错: