diff options
author | zhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386> | 2009-04-22 22:25:31 +0000 |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@8415998a-534a-0410-bf83-d39667b30386> | 2009-04-22 22:25:31 +0000 |
commit | df35a763b9d98d7040a00fc1e5cffe91a80ba9e0 (patch) | |
tree | 9c04a37b5aa0cf26aff318ae43cbf4cacca1755f /test/gmock_output_test_.cc | |
parent | 1c8eb1c059d6727d9fcf45864dc6efa3d844e184 (diff) | |
download | googletest-df35a763b9d98d7040a00fc1e5cffe91a80ba9e0.tar.gz googletest-df35a763b9d98d7040a00fc1e5cffe91a80ba9e0.tar.bz2 googletest-df35a763b9d98d7040a00fc1e5cffe91a80ba9e0.zip |
Implements --gmock_catch_leaked_mocks and Mock::AllowLeak.
Diffstat (limited to 'test/gmock_output_test_.cc')
-rw-r--r-- | test/gmock_output_test_.cc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/gmock_output_test_.cc b/test/gmock_output_test_.cc index bb56b7cd..c97bc78c 100644 --- a/test/gmock_output_test_.cc +++ b/test/gmock_output_test_.cc @@ -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(); +} |