In the following example, I would like to check if fooFunction
is called upon destruction of the object.
#include <gtest/gtest.h>
#include <gmock/gmock.h>
class FooClass
{
public:
~FooClass(){ FooClass::fooFunction(); }
virtual void fooFunction() {}
};
class MockFooClass : public FooClass
{
public:
MOCK_METHOD0(fooFunction, void());
};
TEST(DumbTest, blabla)
{
auto mock = new MockFooClass;
EXPECT_CALL(*mock, fooFunction());
delete mock;
}
However this test fails because the destructor of FooClass
calls FooClass::fooFunction()
instead of MockFooClass::fooFunction()
.
Does anyone know of a way to do that?
I'm using Visual Studio 2010.
I understand why this test fails: as soon as we enter the destructor of FooClass
, the object is not a MockFooClass
any more. What I'm looking for is if anyone knows of a way to get around it.