【发布时间】:2022-07-25 23:35:21
【问题描述】:
我正在尝试模拟一个接受结构并返回另一个结构的函数。类似的东西
struct InParams {
int important_value;
int other_value;
}
struct OutParams {
int same_important_value;
int idk_something;
}
virtual OutParams MyClass::TransformParams(const InParams& params){
...
}
在制作模拟函数时,我希望 OutParam 结构依赖于 InParam。所以我做了一个模拟类和函数
class MockMyClass : public MyClass {
public:
MOCK_METHOD(OutParams, TransformParams,
(const InParams& params), (const, override));
};
OutParams FakeOutParams(const InParams& in_parm){
return {in_parm.important_value, 1};
}
在期待的电话中,我尝试像这样使用它
auto fake_wrapper = new MockMyClass();
EXPECT_CALL(*fake_wrapper, TransformParams(_))
.WillRepeatedly(
WithArg<0>(Return(FakeOutParams)));
编译失败。我也尝试过使用 SaveArgPointee,但由于 InParams 不是指针,它也不够
我可以做些什么来解决我的问题?
【问题讨论】:
-
.WillRepeatedly(Invoke(FakeOutParams));
标签: c++ googletest googlemock