diff options
author | Gennadiy Civil <misterg@google.com> | 2018-10-23 19:13:41 (GMT) |
---|---|---|
committer | Gennadiy Civil <misterg@google.com> | 2018-10-23 19:13:42 (GMT) |
commit | 20eaf6e3a9dbefcb1fb91b9a438aaef70cd999cf (patch) | |
tree | 5c1342dd6e163bf6ffca9cb3320733f2ba25c618 /googlemock | |
parent | a743780ad03ba3cbcb2f76f8a74249f0cae46acc (diff) | |
parent | 0cefda7749756806445a9caab4d8517c808f61f6 (diff) | |
download | googletest-20eaf6e3a9dbefcb1fb91b9a438aaef70cd999cf.zip googletest-20eaf6e3a9dbefcb1fb91b9a438aaef70cd999cf.tar.gz googletest-20eaf6e3a9dbefcb1fb91b9a438aaef70cd999cf.tar.bz2 |
Merge pull request #1911 from BrukerJWD:isnice
PiperOrigin-RevId: 218384341
Diffstat (limited to 'googlemock')
-rw-r--r-- | googlemock/docs/DesignDoc.md | 1 | ||||
-rw-r--r-- | googlemock/include/gmock/gmock-spec-builders.h | 10 | ||||
-rw-r--r-- | googlemock/src/gmock-spec-builders.cc | 13 | ||||
-rw-r--r-- | googlemock/test/gmock-nice-strict_test.cc | 28 |
4 files changed, 51 insertions, 1 deletions
diff --git a/googlemock/docs/DesignDoc.md b/googlemock/docs/DesignDoc.md index d13ff5b..4cddc9d 100644 --- a/googlemock/docs/DesignDoc.md +++ b/googlemock/docs/DesignDoc.md @@ -198,7 +198,6 @@ Google Test (the name is chosen to match `static_assert` in C++0x). If you are writing a function that returns an `ACTION` object, you'll need to know its type. The type depends on the macro used to define the action and the parameter types. The rule is relatively simple: - | **Given Definition** | **Expression** | **Has Type** | |:-------------------------|:-----------------------------|:-------------------------| | `ACTION(Foo)` | `Foo()` | `FooAction` | diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h index 849bc92..5d4b73b 100644 --- a/googlemock/include/gmock/gmock-spec-builders.h +++ b/googlemock/include/gmock/gmock-spec-builders.h @@ -399,6 +399,16 @@ class GTEST_API_ Mock { static bool VerifyAndClear(void* mock_obj) GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); + // Returns whether the mock was created as a naggy mock (default) + static bool IsNaggy(void* mock_obj) + GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); + // Returns whether the mock was created as a nice mock + static bool IsNice(void* mock_obj) + GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); + // Returns whether the mock was created as a strict mock + static bool IsStrict(void* mock_obj) + GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); + private: friend class internal::UntypedFunctionMockerBase; diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index 1a8def4..5c20ed1 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -757,6 +757,19 @@ bool Mock::VerifyAndClearExpectationsLocked(void* mock_obj) return expectations_met; } +bool Mock::IsNaggy(void* mock_obj) + GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { + return Mock::GetReactionOnUninterestingCalls(mock_obj) == internal::kWarn; +} +bool Mock::IsNice(void* mock_obj) + GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { + return Mock::GetReactionOnUninterestingCalls(mock_obj) == internal::kAllow; +} +bool Mock::IsStrict(void* mock_obj) + GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { + return Mock::GetReactionOnUninterestingCalls(mock_obj) == internal::kFail; +} + // Registers a mock object and a mock method it owns. void Mock::Register(const void* mock_obj, internal::UntypedFunctionMockerBase* mocker) diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc index dce6642..d00f453 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -184,6 +184,13 @@ TEST(RawMockTest, InfoForUninterestingCall) { GMOCK_FLAG(verbose) = saved_flag; } +TEST(RawMockTest, IsNaggy_IsNice_IsStrict) { + MockFoo raw_foo; + EXPECT_TRUE(Mock::IsNaggy(&raw_foo)); + EXPECT_FALSE(Mock::IsNice(&raw_foo)); + EXPECT_FALSE(Mock::IsStrict(&raw_foo)); +} + // Tests that a nice mock generates no warning for uninteresting calls. TEST(NiceMockTest, NoWarningForUninterestingCall) { NiceMock<MockFoo> nice_foo; @@ -309,6 +316,13 @@ TEST(NiceMockTest, AcceptsClassNamedMock) { } #endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE +TEST(NiceMockTest, IsNaggy_IsNice_IsStrict) { + NiceMock<MockFoo> nice_foo; + EXPECT_FALSE(Mock::IsNaggy(&nice_foo)); + EXPECT_TRUE(Mock::IsNice(&nice_foo)); + EXPECT_FALSE(Mock::IsStrict(&nice_foo)); +} + #if GTEST_HAS_STREAM_REDIRECTION // Tests that a naggy mock generates warnings for uninteresting calls. @@ -417,6 +431,13 @@ TEST(NaggyMockTest, AcceptsClassNamedMock) { } #endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE +TEST(NaggyMockTest, IsNaggy_IsNice_IsStrict) { + NaggyMock<MockFoo> naggy_foo; + EXPECT_TRUE(Mock::IsNaggy(&naggy_foo)); + EXPECT_FALSE(Mock::IsNice(&naggy_foo)); + EXPECT_FALSE(Mock::IsStrict(&naggy_foo)); +} + // Tests that a strict mock allows expected calls. TEST(StrictMockTest, AllowsExpectedCall) { StrictMock<MockFoo> strict_foo; @@ -506,5 +527,12 @@ TEST(StrictMockTest, AcceptsClassNamedMock) { } #endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE +TEST(StrictMockTest, IsNaggy_IsNice_IsStrict) { + StrictMock<MockFoo> strict_foo; + EXPECT_FALSE(Mock::IsNaggy(&strict_foo)); + EXPECT_FALSE(Mock::IsNice(&strict_foo)); + EXPECT_TRUE(Mock::IsStrict(&strict_foo)); +} + } // namespace gmock_nice_strict_test } // namespace testing |