Implements --gmock_catch_leaked_mocks and Mock::AllowLeak.

This commit is contained in:
zhanyong.wan
2009-04-22 22:25:31 +00:00
parent 1c8eb1c059
commit df35a763b9
17 changed files with 681 additions and 43 deletions

View File

@@ -40,6 +40,7 @@
#include <gtest/gtest.h>
using testing::_;
using testing::AnyNumber;
using testing::Ge;
using testing::InSequence;
using testing::Ref;
@@ -239,3 +240,31 @@ TEST_F(GMockOutputTest, ExplicitActionsRunOutWithDefaultAction) {
foo_.Bar2(2, 2);
foo_.Bar2(1, 1); // Explicit actions in EXPECT_CALL run out.
}
TEST_F(GMockOutputTest, CatchesLeakedMocks) {
MockFoo* foo1 = new MockFoo;
MockFoo* foo2 = new MockFoo;
// Invokes ON_CALL on foo1.
ON_CALL(*foo1, Bar(_, _, _)).WillByDefault(Return('a'));
// Invokes EXPECT_CALL on foo2.
EXPECT_CALL(*foo2, Bar2(_, _));
EXPECT_CALL(*foo2, Bar2(1, _));
EXPECT_CALL(*foo2, Bar3(_, _)).Times(AnyNumber());
foo2->Bar2(2, 1);
foo2->Bar2(1, 1);
// Both foo1 and foo2 are deliberately leaked.
}
int main(int argc, char **argv) {
testing::InitGoogleMock(&argc, argv);
// Ensures that the tests pass no matter what value of
// --gmock_catch_leaked_mocks and --gmock_verbose the user specifies.
testing::GMOCK_FLAG(catch_leaked_mocks) = true;
testing::GMOCK_FLAG(verbose) = "warning";
return RUN_ALL_TESTS();
}