From 67a240a107888c0d3baba528f05820dcc8ac737f Mon Sep 17 00:00:00 2001 From: Jonathan Wendeborn Date: Tue, 16 Oct 2018 08:07:15 +0200 Subject: [PATCH 1/8] Added Mock::IsNaggy, IsNice, and IsStrict --- .../include/gmock/gmock-spec-builders.h | 10 +++++++ googlemock/src/gmock-spec-builders.cc | 29 ++++++++++++++++++ googlemock/test/gmock-nice-strict_test.cc | 30 +++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/googlemock/include/gmock/gmock-spec-builders.h b/googlemock/include/gmock/gmock-spec-builders.h index fed7de66..1e8f732f 100644 --- a/googlemock/include/gmock/gmock-spec-builders.h +++ b/googlemock/include/gmock/gmock-spec-builders.h @@ -389,6 +389,16 @@ class GTEST_API_ Mock { static bool VerifyAndClear(void* mock_obj) GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); + // Returns wether the mock was created as a naggy mock (default) + static bool IsNaggy(void* mock_obj) + GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); + // Returns wether the mock was created as a nice mock + static bool IsNice(void* mock_obj) + GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex); + // Returns wether 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 95513420..0813a974 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -707,6 +707,35 @@ bool Mock::VerifyAndClearExpectationsLocked(void* mock_obj) return expectations_met; } +namespace { +// checks whether the specified mock_obj has a registered call reaction +bool HasCallReaction(void* mock_obj, internal::CallReaction reaction) { + using internal::CallReaction; + + const auto found = g_uninteresting_call_reaction.find(mock_obj); + if (found == g_uninteresting_call_reaction.cend()) { + return internal::CallReaction::kDefault == reaction; + } + return found->second == reaction; +} +} + +bool Mock::IsNaggy(void* mock_obj) + GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { + internal::MutexLock l(&internal::g_gmock_mutex); + return HasCallReaction(mock_obj, internal::CallReaction::kWarn); +} +bool Mock::IsNice(void* mock_obj) + GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { + internal::MutexLock l(&internal::g_gmock_mutex); + return HasCallReaction(mock_obj, internal::CallReaction::kAllow); +} +bool Mock::IsStrict(void* mock_obj) + GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { + internal::MutexLock l(&internal::g_gmock_mutex); + return HasCallReaction(mock_obj, internal::CallReaction::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 d0adcbbe..78f3b515 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -160,6 +160,15 @@ TEST(RawMockTest, InfoForUninterestingCall) { GMOCK_FLAG(verbose) = saved_flag; } +TEST(RawMockTest, IsNaggy_IsNice_IsStrict) { + using internal::CallReaction; + MockFoo raw_foo; + ASSERT_EQ(CallReaction::kDefault, CallReaction::kWarn) << "precondition"; + 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 nice_foo; @@ -253,6 +262,13 @@ TEST(NiceMockTest, AcceptsClassNamedMock) { } #endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE +TEST(NiceMockTest, IsNaggy_IsNice_IsStrict) { + NiceMock 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. @@ -346,6 +362,13 @@ TEST(NaggyMockTest, AcceptsClassNamedMock) { } #endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE +TEST(NaggyMockTest, IsNaggy_IsNice_IsStrict) { + NaggyMock 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 strict_foo; @@ -420,5 +443,12 @@ TEST(StrictMockTest, AcceptsClassNamedMock) { } #endif // !GTEST_OS_SYMBIAN && !GTEST_OS_WINDOWS_MOBILE +TEST(StrictMockTest, IsNaggy_IsNice_IsStrict) { + StrictMock 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 From 6bbf911a8dc0c42ad05135f26a07f4893eb83916 Mon Sep 17 00:00:00 2001 From: Jonathan Wendeborn Date: Tue, 16 Oct 2018 08:19:02 +0200 Subject: [PATCH 2/8] Don't fully qualify enum member --- googlemock/src/gmock-spec-builders.cc | 10 ++++------ googlemock/test/gmock-nice-strict_test.cc | 3 +-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index 0813a974..408623da 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -710,11 +710,9 @@ bool Mock::VerifyAndClearExpectationsLocked(void* mock_obj) namespace { // checks whether the specified mock_obj has a registered call reaction bool HasCallReaction(void* mock_obj, internal::CallReaction reaction) { - using internal::CallReaction; - const auto found = g_uninteresting_call_reaction.find(mock_obj); if (found == g_uninteresting_call_reaction.cend()) { - return internal::CallReaction::kDefault == reaction; + return internal::kDefault == reaction; } return found->second == reaction; } @@ -723,17 +721,17 @@ bool HasCallReaction(void* mock_obj, internal::CallReaction reaction) { bool Mock::IsNaggy(void* mock_obj) GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { internal::MutexLock l(&internal::g_gmock_mutex); - return HasCallReaction(mock_obj, internal::CallReaction::kWarn); + return HasCallReaction(mock_obj, internal::kWarn); } bool Mock::IsNice(void* mock_obj) GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { internal::MutexLock l(&internal::g_gmock_mutex); - return HasCallReaction(mock_obj, internal::CallReaction::kAllow); + return HasCallReaction(mock_obj, internal::kAllow); } bool Mock::IsStrict(void* mock_obj) GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { internal::MutexLock l(&internal::g_gmock_mutex); - return HasCallReaction(mock_obj, internal::CallReaction::kFail); + return HasCallReaction(mock_obj, internal::kFail); } // Registers a mock object and a mock method it owns. diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc index 78f3b515..38daee0b 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -161,9 +161,8 @@ TEST(RawMockTest, InfoForUninterestingCall) { } TEST(RawMockTest, IsNaggy_IsNice_IsStrict) { - using internal::CallReaction; MockFoo raw_foo; - ASSERT_EQ(CallReaction::kDefault, CallReaction::kWarn) << "precondition"; + ASSERT_EQ(internal::kDefault, internal::kWarn) << "precondition"; EXPECT_TRUE (Mock::IsNaggy(&raw_foo)); EXPECT_FALSE(Mock::IsNice(&raw_foo)); EXPECT_FALSE(Mock::IsStrict(&raw_foo)); From 386391b0144201e0cf5f66d8ba1cb60a1076f673 Mon Sep 17 00:00:00 2001 From: Jonathan Wendeborn Date: Tue, 16 Oct 2018 08:37:45 +0200 Subject: [PATCH 3/8] Use existing Mock::GetReactionOnUninterestingCalls() --- googlemock/src/gmock-spec-builders.cc | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index 408623da..5b0a8306 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -707,31 +707,17 @@ bool Mock::VerifyAndClearExpectationsLocked(void* mock_obj) return expectations_met; } -namespace { -// checks whether the specified mock_obj has a registered call reaction -bool HasCallReaction(void* mock_obj, internal::CallReaction reaction) { - const auto found = g_uninteresting_call_reaction.find(mock_obj); - if (found == g_uninteresting_call_reaction.cend()) { - return internal::kDefault == reaction; - } - return found->second == reaction; -} -} - bool Mock::IsNaggy(void* mock_obj) GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { - internal::MutexLock l(&internal::g_gmock_mutex); - return HasCallReaction(mock_obj, internal::kWarn); + return Mock::GetReactionOnUninterestingCalls(mock_obj) == internal::kWarn; } bool Mock::IsNice(void* mock_obj) GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { - internal::MutexLock l(&internal::g_gmock_mutex); - return HasCallReaction(mock_obj, internal::kAllow); + return Mock::GetReactionOnUninterestingCalls(mock_obj) == internal::kAllow; } bool Mock::IsStrict(void* mock_obj) GTEST_LOCK_EXCLUDED_(internal::g_gmock_mutex) { - internal::MutexLock l(&internal::g_gmock_mutex); - return HasCallReaction(mock_obj, internal::kFail); + return Mock::GetReactionOnUninterestingCalls(mock_obj) == internal::kFail; } // Registers a mock object and a mock method it owns. From 0cefda7749756806445a9caab4d8517c808f61f6 Mon Sep 17 00:00:00 2001 From: Jonathan Wendeborn Date: Tue, 16 Oct 2018 08:51:33 +0200 Subject: [PATCH 4/8] Removed last reference to internal::kDefault --- googlemock/test/gmock-nice-strict_test.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/googlemock/test/gmock-nice-strict_test.cc b/googlemock/test/gmock-nice-strict_test.cc index 9cae9872..b08998a7 100644 --- a/googlemock/test/gmock-nice-strict_test.cc +++ b/googlemock/test/gmock-nice-strict_test.cc @@ -186,7 +186,6 @@ TEST(RawMockTest, InfoForUninterestingCall) { TEST(RawMockTest, IsNaggy_IsNice_IsStrict) { MockFoo raw_foo; - ASSERT_EQ(internal::kDefault, internal::kWarn) << "precondition"; EXPECT_TRUE (Mock::IsNaggy(&raw_foo)); EXPECT_FALSE(Mock::IsNice(&raw_foo)); EXPECT_FALSE(Mock::IsStrict(&raw_foo)); From 58a8da64cecda05390c880d604e782ed4073ffd9 Mon Sep 17 00:00:00 2001 From: Sergio Valverde Date: Tue, 23 Oct 2018 07:57:23 +0200 Subject: [PATCH 5/8] ACTION table format --- googlemock/docs/DesignDoc.md | 1 + 1 file changed, 1 insertion(+) diff --git a/googlemock/docs/DesignDoc.md b/googlemock/docs/DesignDoc.md index 4cddc9d0..d13ff5b9 100644 --- a/googlemock/docs/DesignDoc.md +++ b/googlemock/docs/DesignDoc.md @@ -198,6 +198,7 @@ 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` | From b974af79239be20ddec2b170a77af0a6ca92b856 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 23 Oct 2018 11:09:15 -0400 Subject: [PATCH 6/8] Update advanced.md Fixes #1925 --- googletest/docs/advanced.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/docs/advanced.md b/googletest/docs/advanced.md index b8bb5cd9..05524809 100644 --- a/googletest/docs/advanced.md +++ b/googletest/docs/advanced.md @@ -1487,7 +1487,7 @@ returns the value of `testing::PrintToString(GetParam())`. It does not work for NOTE: test names must be non-empty, unique, and may only contain ASCII alphanumeric characters. In particular, they [should not contain -underscores](https://g3doc.corp.google.com/third_party/googletest/googletest/g3doc/faq.md#no-underscores). +underscores](https://github.com/google/googletest/blob/master/googletest/docs/faq.md#why-should-test-case-names-and-test-names-not-contain-underscore). ```c++ class MyTestCase : public testing::TestWithParam {}; From a743780ad03ba3cbcb2f76f8a74249f0cae46acc Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 23 Oct 2018 11:16:46 -0400 Subject: [PATCH 7/8] Update advanced.md Fixes #1755 --- googletest/docs/advanced.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/googletest/docs/advanced.md b/googletest/docs/advanced.md index 05524809..481b1fe9 100644 --- a/googletest/docs/advanced.md +++ b/googletest/docs/advanced.md @@ -2204,8 +2204,7 @@ environment variable to `0`. googletest can emit a detailed XML report to a file in addition to its normal textual output. The report contains the duration of each test, and thus can help -you identify slow tests. The report is also used by the http://unittest -dashboard to show per-test-method error messages. +you identify slow tests. To generate the XML report, set the `GTEST_OUTPUT` environment variable or the `--gtest_output` flag to the string `"xml:path_to_output_file"`, which will From 7b6b3be34241dfa9fdfd53797734bdc18683c50b Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Tue, 23 Oct 2018 17:27:38 -0400 Subject: [PATCH 8/8] Update advanced.md Fixes #1802 --- googletest/docs/advanced.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googletest/docs/advanced.md b/googletest/docs/advanced.md index b8bb5cd9..05524809 100644 --- a/googletest/docs/advanced.md +++ b/googletest/docs/advanced.md @@ -1487,7 +1487,7 @@ returns the value of `testing::PrintToString(GetParam())`. It does not work for NOTE: test names must be non-empty, unique, and may only contain ASCII alphanumeric characters. In particular, they [should not contain -underscores](https://g3doc.corp.google.com/third_party/googletest/googletest/g3doc/faq.md#no-underscores). +underscores](https://github.com/google/googletest/blob/master/googletest/docs/faq.md#why-should-test-case-names-and-test-names-not-contain-underscore). ```c++ class MyTestCase : public testing::TestWithParam {};