gmock多个输入输出参数SetArgReferee
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了gmock多个输入输出参数SetArgReferee相关的知识,希望对你有一定的参考价值。
我有一个界面Itest:
class Itest {
bool testfunction(vector<int>& v, int& id);
}
我可以嘲笑它:
MOCK_METHOD2(testfunction, bool(vector<int>&, int&))
但是如何设置返回值?
我试过了:
vector<int> v;
int i;
EXPECT_CALL(testobject, testfunction(_,_, _))
.WillOnce(testing::SetArgReferee<0>(v))
.WillOnce(testing::SetArgReferee<1>(i))
.WillOnce(Return(true));
但它被称为三次..
如何设置这些argReferees
和返回值一次?
答案
您可以使用DoAll
操作将多个操作组合在一起:
EXPECT_CALL(testobject, testfunction(_, _, _))
.WillOnce(DoAll(SetArgReferee<0>(v), SetArgReferee<1>(i), Return(true)));
有关详细信息,请参阅Google Mock wiki。
以上是关于gmock多个输入输出参数SetArgReferee的主要内容,如果未能解决你的问题,请参考以下文章