Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Line num fix lol

...

Code Block
languagecpp
linenumberstrue
TEST_F(Fixture1, Test1) {
 
	Mock * ourMock = new Mock; // The mock is created (could also be in the test fixture constructor) at address 0x5634d2e8ca736700
	EXPECT_CALL(*ourMock, fun()); // We set expectations on the mock
 
	code->run1(); // We hope this calls ourMock->fun();
 
	delete ourMock; // Here, expectations on ourMock are verified and cleanup is performed. GoogleTest is happy.
 
	EXPECT_CALL(*ourMock, fun()); // OH NO! GoogleTest now again thinks 0x5634d2e8ca736700 is still active
 
} // after all cleanup, GoogleTest will report "Mock leaked at 0x5634d2e8ca736700 used in Fixture1.Test1", despite it was deleted on line 78.
 
 

Make sure you don't set EXPECT_CALLs after you delete the mock. Sometimes, they can hide in the test destructor, or in a mock destructor.

...