summaryrefslogtreecommitdiffstats
path: root/googlemock/test
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2020-12-21 20:41:17 (GMT)
committerDerek Mauro <dmauro@google.com>2020-12-22 17:15:41 (GMT)
commitca4b7c9ff4d8a5c37ac51795b03ffe934958aeff (patch)
tree9b90d078223828eb4acf5b274e4cc3c5cb79ecfd /googlemock/test
parent4f6fa70870de48cf0db655acc9cb8c30b2760ec9 (diff)
downloadgoogletest-ca4b7c9ff4d8a5c37ac51795b03ffe934958aeff.zip
googletest-ca4b7c9ff4d8a5c37ac51795b03ffe934958aeff.tar.gz
googletest-ca4b7c9ff4d8a5c37ac51795b03ffe934958aeff.tar.bz2
Googletest export
Give each of Naggy/Nice/StrictMock a base class whose constructor runs before the mocked class's constructor, and a destructor that runs after the mocked class's destructor, so that any mock methods run in either the constructor or destructor use the same strictness as other calls. PiperOrigin-RevId: 348511612
Diffstat (limited to 'googlemock/test')
-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));