gmock multiple in-out parameters SetArgReferee

℡╲_俬逩灬. 提交于 2019-12-22 01:26:08

问题


I have an interface Itest:

class Itest {
    bool testfunction(vector<int>& v, int& id);
}

I can mock it with:

MOCK_METHOD2(testfunction, bool(vector<int>&, int&))

but how can I set the return values?

I tried:

vector<int> v;
int i;
EXPECT_CALL(testobject, testfunction(_,_, _))
            .WillOnce(testing::SetArgReferee<0>(v))
            .WillOnce(testing::SetArgReferee<1>(i))
            .WillOnce(Return(true));

but then it is called three times..

How do I set these argReferees and the return value one time?


回答1:


You combine several actions together using the DoAll action:

EXPECT_CALL(testobject, testfunction(_, _, _))
    .WillOnce(DoAll(SetArgReferee<0>(v), SetArgReferee<1>(i), Return(true)));

See Google Mock wiki CheatSheet for more info.



来源:https://stackoverflow.com/questions/23156717/gmock-multiple-in-out-parameters-setargreferee

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!