summaryrefslogtreecommitdiffstats
path: root/googlemock/test/gmock-nice-strict_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'googlemock/test/gmock-nice-strict_test.cc')
-rw-r--r--googlemock/test/gmock-nice-strict_test.cc39
1 files changed, 39 insertions, 0 deletions
diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc
index 0a201ed..25558eb 100644
--- a/googlemock/test/gmock-nice-strict_test.cc
+++ b/googlemock/test/gmock-nice-strict_test.cc
@@ -67,6 +67,12 @@ class NotDefaultConstructible {
explicit NotDefaultConstructible(int) {}
};
+class CallsMockMethodInDestructor {
+ public:
+ ~CallsMockMethodInDestructor() { OnDestroy(); }
+ MOCK_METHOD(void, OnDestroy, ());
+};
+
// Defines some mock classes needed by the tests.
class Foo {
@@ -302,6 +308,13 @@ TEST(NiceMockTest, AcceptsClassNamedMock) {
nice.DoThis();
}
+TEST(NiceMockTest, IsNiceInDestructor) {
+ {
+ NiceMock<CallsMockMethodInDestructor> nice_on_destroy;
+ // Don't add an expectation for the call before the mock goes out of scope.
+ }
+}
+
TEST(NiceMockTest, IsNaggy_IsNice_IsStrict) {
NiceMock<MockFoo> nice_foo;
EXPECT_FALSE(Mock::IsNaggy(&nice_foo));
@@ -405,6 +418,22 @@ TEST(NaggyMockTest, AcceptsClassNamedMock) {
naggy.DoThis();
}
+TEST(NaggyMockTest, IsNaggyInDestructor) {
+ const std::string saved_flag = GMOCK_FLAG(verbose);
+ GMOCK_FLAG(verbose) = "warning";
+ CaptureStdout();
+
+ {
+ NaggyMock<CallsMockMethodInDestructor> naggy_on_destroy;
+ // Don't add an expectation for the call before the mock goes out of scope.
+ }
+
+ EXPECT_THAT(GetCapturedStdout(),
+ HasSubstr("Uninteresting mock function call"));
+
+ GMOCK_FLAG(verbose) = saved_flag;
+}
+
TEST(NaggyMockTest, IsNaggy_IsNice_IsStrict) {
NaggyMock<MockFoo> naggy_foo;
EXPECT_TRUE(Mock::IsNaggy(&naggy_foo));
@@ -489,6 +518,16 @@ TEST(StrictMockTest, AcceptsClassNamedMock) {
strict.DoThis();
}
+TEST(StrictMockTest, IsStrictInDestructor) {
+ EXPECT_NONFATAL_FAILURE(
+ {
+ StrictMock<CallsMockMethodInDestructor> strict_on_destroy;
+ // Don't add an expectation for the call before the mock goes out of
+ // scope.
+ },
+ "Uninteresting mock function call");
+}
+
TEST(StrictMockTest, IsNaggy_IsNice_IsStrict) {
StrictMock<MockFoo> strict_foo;
EXPECT_FALSE(Mock::IsNaggy(&strict_foo));