aboutsummaryrefslogtreecommitdiffstats
path: root/test/gmock_output_test_.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/gmock_output_test_.cc')
-rw-r--r--test/gmock_output_test_.cc29
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();
+}