When I store my mock object on the heap using a shared_ptr
, the expectations are satisfied and the pointer is destroyed but GMock framework thinks the mock object is still alive:
// Using a mock object
MockFoo foo;
EXPECT_CALL(foo, doSomething());
foo.doSomething();
// Test passes without warnings
// Using shared_ptr to a mock object
auto foo_sp = std::make_shared<MockFoo>();
EXPECT_CALL(*foo_sp, doSomething());
A a(std::move(foo_sp));
a.useFoo();
// a is then deleted
...
// in useFoo:
foo_sp->doSomething();
...
// Test passes WITH warnings that mock object is still alive
Is this a bug in the Google mock framework? If not then how can I store my mock object on the heap in a smart pointer and use it correctly?