M.Herzog
M.Herzog

Reputation: 5

Try to mock pure virtual class

i' trying to mock a function in a pure virtual class with google mock. Here is my code:

class I_Circle

{

private :

public: 

    virtual ~I_Circle() {}

    virtual void GetClone(I_Circle * k) = 0;
};


class Mock_I_Circle : public I_Circle
{
public:
    Mock_I_Circle() {}
    virtual ~Mock_I_Circle() {};

    MOCK_METHOD1(GetClone, void(I_Circle* k));

};

TEST(CircleTest, secondTest) {
    NiceMock<Mock_I_Circle> iCircle;
    Mock_I_Circle* pICircle = &iCircle;

    EXPECT_CALL(iCircle, GetClone(_))
        .WillOnce(
            SetArgPointee<0>(*pICircle)
        );

    iCircle.GetClone(pICircle);

    Mock::VerifyAndClear(&iCircle);
}

With this implementation i'm getting the following error:

Error   C2280   'testing::PolymorphicAction<testing::internal::SetArgumentPointeeAction<0,Mock_I_Circle,false>>::PolymorphicAction(const testing::PolymorphicAction<testing::internal::SetArgumentPointeeAction<0,Mock_I_Circle,false>> &)': attempting to reference a deleted function MockInterface   c:\source\googletest\googlemock\include\gmock\gmock-actions.h   1110        

What function here is meant to be deletetd? The problem seems to be result from the EXPECT_CALL with SetArgPointee, but i don't know what's wrong with it.

Upvotes: 0

Views: 1691

Answers (1)

RA.
RA.

Reputation: 7777

From the Google Mock Cookbook:

SetArgPointee() conveniently makes an internal copy of the value you pass to it, removing the need to keep the value in scope and alive. The implication however is that the value must have a copy constructor and assignment operator.

In your case, the Mock_I_Circle class lacks a copy constructor and assignment operator. Adding these would fix the compilation error. That being said, I'm not clear as to the purpose of the test you've written.

Upvotes: 1

Related Questions