0
我有一个受保护的拷贝构造函数的类:谷歌模拟和保护的拷贝构造函数
class ThingList
{
public:
ThingList() {}
virtual ~ThingList() {}
std::vector<Thing> things;
protected:
ThingList(const ThingList ©) {}
};
我有另一大类用途这样一条:这个类的
class AnotherThing
{
public:
AnotherThing()
{
}
virtual ~AnotherThing() {}
void DoListThing(const ThingList &list)
{
}
};
和模拟版本:
class MockAnotherThing : public AnotherThing
{
public:
MOCK_METHOD1(DoListThing, void(const ThingList &list));
};
我想调用这个方法DoListThing用真实的参数来提供一个真正的列表:
TEST(Thing, DoSomeThingList)
{
MockThing thing;
ThingList list;
MockAnotherThing anotherThing;
list.things.push_back(Thing());
EXPECT_CALL(anotherThing, DoListThing(list));
anotherThing.DoListThing(list);
}
我得到一个错误编译如下:
1>..\mockit\googletest\googlemock\include\gmock\gmock-matchers.h(3746): error C2248: 'ThingList::ThingList': cannot access protected member declared in class 'ThingList'
然而,如果我做一个非模拟调用它工作得很好:
ThingList list;
AnotherThing theRealThing;
theRealThing.DoListThing(list);
如果在模拟测试我打电话'_',它的工作原理:
TEST(Thing, DoSomeThingList)
{
MockThing thing;
ThingList list;
MockAnotherThing anotherThing;
list.things.push_back(Thing());
EXPECT_CALL(anotherThing, DoListThing(_));
anotherThing.DoListThing(list);
}
但是,我怎么能传递在这种情况下列出?如果列表是由DoListThing返回的,那么我可以使用Return,但是对于像这样修改的参数,我该如何处理?