I need to check if an object will correctly deleted after some
operations.
find out some help in cookbook:
http://code.google.com/p/googlemock/wiki/CookBook#Mocking_Destructors
but, when i try to implement this feature i take nothink than
correctly passed tests. For example:
$ cat tmp.cpp
#include <gtest/gtest.h>
#include <gmock/gmock.h>
class Foo {
public:
virtual ~Foo() {}
};
class FooMock : public Foo {
public:
MOCK_METHOD0(Die, void());
virtual ~FooMock() { Die(); }
};
TEST(DieTest, destr)
{
FooMock * m = new FooMock();
EXPECT_CALL(*m, Die());
}
$ g++ tmp.cpp -lgtest -lgmock -lgmock_main -o tmp && ./tmp
Running main() from gmock_main.cc
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from DieTest
[ RUN ] DieTest.destr
[ OK ] DieTest.destr (0 ms)
[----------] 1 test from DieTest (0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[ PASSED ] 1 test.
tmp.cpp:19: ERROR: this mock object (used in test DieTest.destr)
should be deleted but never is. Its address is @0x131ec80.
ERROR: 1 leaked mock object found at program exit.
How to implement gmock object and call expectation to fail test, when
an object doesn't deleted correctly? Or mock framework expects, that
i'll figure out such type of errors in "leacked mock" messages?