vendredi 30 octobre 2015

How to verify the derived type of a parameter passed to a mocked function

I have a base class and two derived classes, like this:

class Base { ... };
class DerivedA : public Base { ... };
class DerivedB : public Base { ... };

I also have an interface class which I'm mocking (with Google Mock), like this:

class MockSomeInterface : public SomeInterface
{
  public:
    MOCK_METHOD1(someMethod, void(Base* basePtr));
};

I can expect calls to the mocked method like this, not verifying the parameter in the call at all:

EXPECT_CALL(mockSomeInterfaceObj, someMethod(_))
  Times(2);

What i would like to do is verify the type of the parameter given to someMethod, to check that it is in fact called with a DerivedA* once and a DerivedB* once, instead of just twice with any parameter.

Aucun commentaire:

Enregistrer un commentaire