Constructor Google模拟和受保护副本构造函数

Constructor Google模拟和受保护副本构造函数,constructor,copy,protected,googlemock,Constructor,Copy,Protected,Googlemock,我有一个具有受保护副本构造函数的类: class ThingList { public: ThingList() {} virtual ~ThingList() {} std::vector<Thing> things; protected: ThingList(const ThingList &copy) {} }; 以及该类的模拟版本: class MockAnotherThing : public AnotherThing { pu

我有一个具有受保护副本构造函数的类:

class ThingList
{
public:
    ThingList() {}
    virtual ~ThingList() {}

    std::vector<Thing> things;

protected:
    ThingList(const ThingList &copy) {}
};
以及该类的模拟版本:

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);
如果在模拟测试中,我使用“3;”调用,它将起作用:

TEST(Thing, DoSomeThingList)
{
    MockThing thing;
    ThingList list;
    MockAnotherThing anotherThing;

    list.things.push_back(Thing());

    EXPECT_CALL(anotherThing, DoListThing(_));

    anotherThing.DoListThing(list);
}

但是,在这种情况下,如何传递列表?如果列表是由DoListThing返回的,我可以使用Return,但是对于这样修改的参数,我该怎么办?

我无法通过受保护的副本构造函数,所以我的答案是创建一个类的假虚拟版本并忽略Google Mock。这很好,足以让我测试这门课。我在这里提供的示例是更大软件包的简化版本

TEST(Thing, DoSomeThingList)
{
    MockThing thing;
    ThingList list;
    MockAnotherThing anotherThing;

    list.things.push_back(Thing());

    EXPECT_CALL(anotherThing, DoListThing(_));

    anotherThing.DoListThing(list);
}