lundi 29 juin 2015

How to create a return value using an unspecified parameter in GMOCK?

Say I'm mocking class IClass which has a method call RClass DoIt(int x) like this:

class RClass
{
    int _x;
public:
    RClass(int x) :_x(x) { }
}

class MockClass : public IClass
{
public:
    MOCK_METHOD(DoIt, RClass(int)));
}

Then in my test I want to return a RClass value constructed with the first argument called in the code under test. I tried like this, but it didn't work:

int value = 0;
MockClass mc;
EXPECT_CALL(mc, DoIt(_)).WillRepeatedly(DoAll(SaveArg<0>(&value), Return(RClass(value))));

Any ideas?

Aucun commentaire:

Enregistrer un commentaire