Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using GMock to verify a Destructor Call

Using GMock, how can I verify that a class's destructor is called? Is there a way, other than to wrap it in another class?

The obvious method, EXPECT_CALL(object, ~classtype()) yields a compiler error (gmock cannot produce a mock method called gmock_~classtype).

like image 289
Andres Jaan Tack Avatar asked Jan 19 '11 11:01

Andres Jaan Tack


1 Answers

An easy way to check for a destructor call:

class MockFoo : public Foo {
  ...
  // Add the following two lines to the mock class.
  MOCK_METHOD0(Die, void());
  virtual ~MockFoo() { Die(); }
};

In your test function:

 MockFoo* foo = new MockFoo;
  ...
  {
    EXPECT_CALL(*foo, Die());
  }

More Details can be found here: Mocking Destructors

like image 171
nabulke Avatar answered Sep 26 '22 15:09

nabulke