diff options
author | Abseil Team <absl-team@google.com> | 2018-08-24 13:30:17 -0400 |
---|---|---|
committer | Gennadiy Civil <misterg@google.com> | 2018-08-27 12:22:26 -0400 |
commit | a0e62d9f1a5f24cbc9d16bb9d1c4b606e960b2af (patch) | |
tree | e18a6c3959eef469e3199ff5bdca70a5b0316823 /googlemock/test | |
parent | 9c96f500a39df6915f8f1ab53b60be9889f1572b (diff) | |
download | googletest-a0e62d9f1a5f24cbc9d16bb9d1c4b606e960b2af.tar.gz googletest-a0e62d9f1a5f24cbc9d16bb9d1c4b606e960b2af.tar.bz2 googletest-a0e62d9f1a5f24cbc9d16bb9d1c4b606e960b2af.zip |
No longer require a functor passed to ResultOf matcher to define `result_of` type.
This makes ResultOf more convenient to use. In particular, the matcher now accepts
lambdas.
PiperOrigin-RevId: 210118509
Diffstat (limited to 'googlemock/test')
-rw-r--r-- | googlemock/test/gmock-matchers_test.cc | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index d08f08f7..4697f0bf 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -4597,6 +4597,7 @@ struct PolymorphicFunctor { typedef int result_type; int operator()(int n) { return n; } int operator()(const char* s) { return static_cast<int>(strlen(s)); } + std::string operator()(int *p) { return p ? "good ptr" : "null"; } }; TEST(ResultOfTest, WorksForPolymorphicFunctors) { @@ -4611,6 +4612,23 @@ TEST(ResultOfTest, WorksForPolymorphicFunctors) { EXPECT_FALSE(matcher_string.Matches("shrt")); } +#if GTEST_LANG_CXX11 +TEST(ResultOfTest, WorksForPolymorphicFunctorsIgnoringResultType) { + Matcher<int*> matcher = ResultOf(PolymorphicFunctor(), "good ptr"); + + int n = 0; + EXPECT_TRUE(matcher.Matches(&n)); + EXPECT_FALSE(matcher.Matches(nullptr)); +} + +TEST(ResultOfTest, WorksForLambdas) { + Matcher<int> matcher = + ResultOf([](int str_len) { return std::string(str_len, 'x'); }, "xxx"); + EXPECT_TRUE(matcher.Matches(3)); + EXPECT_FALSE(matcher.Matches(1)); +} +#endif + const int* ReferencingFunction(const int& n) { return &n; } struct ReferencingFunctor { |