diff options
| -rw-r--r-- | googlemock/include/gmock/gmock-matchers.h | 69 | ||||
| -rw-r--r-- | googlemock/src/gmock-matchers.cc | 77 | ||||
| -rw-r--r-- | googlemock/test/gmock-internal-utils_test.cc | 28 | ||||
| -rw-r--r-- | googlemock/test/gmock_output_test_.cc | 6 | 
4 files changed, 120 insertions, 60 deletions
| diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 9522c850..044a323e 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -323,7 +323,13 @@ class Matcher : public internal::MatcherBase<T> {    explicit Matcher() {}  // NOLINT    // Constructs a matcher from its implementation. -  explicit Matcher(const MatcherInterface<T>* impl) +  explicit Matcher(const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)>* impl) +      : internal::MatcherBase<T>(impl) {} + +  template <typename U> +  explicit Matcher(const MatcherInterface<U>* impl, +                   typename internal::EnableIf<!internal::IsSame< +                       U, GTEST_REFERENCE_TO_CONST_(U)>::value>::type* = NULL)        : internal::MatcherBase<T>(impl) {}    // Implicit constructor here allows people to write @@ -332,64 +338,79 @@ class Matcher : public internal::MatcherBase<T> {  };  // The following two specializations allow the user to write str -// instead of Eq(str) and "foo" instead of Eq("foo") when a string +// instead of Eq(str) and "foo" instead of Eq("foo") when a std::string  // matcher is expected.  template <> -class GTEST_API_ Matcher<const internal::string&> -    : public internal::MatcherBase<const internal::string&> { +class GTEST_API_ Matcher<const std::string&> +    : public internal::MatcherBase<const std::string&> {   public:    Matcher() {} -  explicit Matcher(const MatcherInterface<const internal::string&>* impl) -      : internal::MatcherBase<const internal::string&>(impl) {} +  explicit Matcher(const MatcherInterface<const std::string&>* impl) +      : internal::MatcherBase<const std::string&>(impl) {}    // Allows the user to write str instead of Eq(str) sometimes, where -  // str is a string object. -  Matcher(const internal::string& s);  // NOLINT +  // str is a std::string object. +  Matcher(const std::string& s);  // NOLINT + +#if GTEST_HAS_GLOBAL_STRING +  // Allows the user to write str instead of Eq(str) sometimes, where +  // str is a ::string object. +  Matcher(const ::string& s);  // NOLINT +#endif                         // GTEST_HAS_GLOBAL_STRING    // Allows the user to write "foo" instead of Eq("foo") sometimes.    Matcher(const char* s);  // NOLINT  };  template <> -class GTEST_API_ Matcher<internal::string> -    : public internal::MatcherBase<internal::string> { +class GTEST_API_ Matcher<std::string> +    : public internal::MatcherBase<std::string> {   public:    Matcher() {} -  explicit Matcher(const MatcherInterface<internal::string>* impl) -      : internal::MatcherBase<internal::string>(impl) {} +  explicit Matcher(const MatcherInterface<std::string>* impl) +      : internal::MatcherBase<std::string>(impl) {}    // Allows the user to write str instead of Eq(str) sometimes, where    // str is a string object. -  Matcher(const internal::string& s);  // NOLINT +  Matcher(const std::string& s);  // NOLINT + +#if GTEST_HAS_GLOBAL_STRING +  // Allows the user to write str instead of Eq(str) sometimes, where +  // str is a ::string object. +  Matcher(const ::string& s);  // NOLINT +#endif                         // GTEST_HAS_GLOBAL_STRING    // Allows the user to write "foo" instead of Eq("foo") sometimes.    Matcher(const char* s);  // NOLINT  }; -#if GTEST_HAS_STRING_PIECE_ +#if GTEST_HAS_GLOBAL_STRING  // The following two specializations allow the user to write str -// instead of Eq(str) and "foo" instead of Eq("foo") when a StringPiece +// instead of Eq(str) and "foo" instead of Eq("foo") when a ::string  // matcher is expected.  template <> -class GTEST_API_ Matcher<const StringPiece&> -    : public internal::MatcherBase<const StringPiece&> { +class GTEST_API_ Matcher<const ::string&> +    : public internal::MatcherBase<const ::string&> {   public:    Matcher() {} -  explicit Matcher(const MatcherInterface<const StringPiece&>* impl) -      : internal::MatcherBase<const StringPiece&>(impl) {} +  explicit Matcher(const MatcherInterface<const ::string&>* impl) +      : internal::MatcherBase<const ::string&>(impl) {}    // Allows the user to write str instead of Eq(str) sometimes, where -  // str is a string object. -  Matcher(const internal::string& s);  // NOLINT +  // str is a std::string object. +  Matcher(const std::string& s);  // NOLINT + +  // Allows the user to write str instead of Eq(str) sometimes, where +  // str is a ::string object. +  Matcher(const ::string& s);  // NOLINT    // Allows the user to write "foo" instead of Eq("foo") sometimes.    Matcher(const char* s);  // NOLINT +}; -  // Allows the user to pass StringPieces directly. -  Matcher(StringPiece s);  // NOLINT  };  template <> @@ -1340,7 +1361,7 @@ class MatchesRegexMatcher {    // Matches anything that can convert to std::string.    //    // This is a template, not just a plain function with const std::string&, -  // because StringPiece has some interfering non-explicit constructors. +  // because absl::string_view has some interfering non-explicit constructors.    template <class MatcheeStringType>    bool MatchAndExplain(const MatcheeStringType& s,                         MatchResultListener* /* listener */) const { diff --git a/googlemock/src/gmock-matchers.cc b/googlemock/src/gmock-matchers.cc index 88e40088..a5ed686e 100644 --- a/googlemock/src/gmock-matchers.cc +++ b/googlemock/src/gmock-matchers.cc @@ -44,60 +44,67 @@  namespace testing { -// Constructs a matcher that matches a const string& whose value is +// Constructs a matcher that matches a const std::string& whose value is  // equal to s. -Matcher<const internal::string&>::Matcher(const internal::string& s) { -  *this = Eq(s); +Matcher<const std::string&>::Matcher(const std::string& s) { *this = Eq(s); } + +#if GTEST_HAS_GLOBAL_STRING +// Constructs a matcher that matches a const std::string& whose value is +// equal to s. +Matcher<const std::string&>::Matcher(const ::string& s) { +  *this = Eq(static_cast<std::string>(s));  } +#endif  // GTEST_HAS_GLOBAL_STRING -// Constructs a matcher that matches a const string& whose value is +// Constructs a matcher that matches a const std::string& whose value is  // equal to s. -Matcher<const internal::string&>::Matcher(const char* s) { -  *this = Eq(internal::string(s)); +Matcher<const std::string&>::Matcher(const char* s) { +  *this = Eq(std::string(s));  } -// Constructs a matcher that matches a string whose value is equal to s. -Matcher<internal::string>::Matcher(const internal::string& s) { *this = Eq(s); } +// Constructs a matcher that matches a std::string whose value is equal to +// s. +Matcher<std::string>::Matcher(const std::string& s) { *this = Eq(s); } -// Constructs a matcher that matches a string whose value is equal to s. -Matcher<internal::string>::Matcher(const char* s) { -  *this = Eq(internal::string(s)); +#if GTEST_HAS_GLOBAL_STRING +// Constructs a matcher that matches a std::string whose value is equal to +// s. +Matcher<std::string>::Matcher(const ::string& s) { +  *this = Eq(static_cast<std::string>(s));  } +#endif  // GTEST_HAS_GLOBAL_STRING + +// Constructs a matcher that matches a std::string whose value is equal to +// s. +Matcher<std::string>::Matcher(const char* s) { *this = Eq(std::string(s)); } -#if GTEST_HAS_STRING_PIECE_ -// Constructs a matcher that matches a const StringPiece& whose value is +#if GTEST_HAS_GLOBAL_STRING +// Constructs a matcher that matches a const ::string& whose value is  // equal to s. -Matcher<const StringPiece&>::Matcher(const internal::string& s) { -  *this = Eq(s); +Matcher<const ::string&>::Matcher(const std::string& s) { +  *this = Eq(static_cast<::string>(s));  } -// Constructs a matcher that matches a const StringPiece& whose value is +// Constructs a matcher that matches a const ::string& whose value is  // equal to s. -Matcher<const StringPiece&>::Matcher(const char* s) { -  *this = Eq(internal::string(s)); -} +Matcher<const ::string&>::Matcher(const ::string& s) { *this = Eq(s); } -// Constructs a matcher that matches a const StringPiece& whose value is +// Constructs a matcher that matches a const ::string& whose value is  // equal to s. -Matcher<const StringPiece&>::Matcher(StringPiece s) { -  *this = Eq(s.ToString()); -} +Matcher<const ::string&>::Matcher(const char* s) { *this = Eq(::string(s)); } -// Constructs a matcher that matches a StringPiece whose value is equal to s. -Matcher<StringPiece>::Matcher(const internal::string& s) { -  *this = Eq(s); +// Constructs a matcher that matches a ::string whose value is equal to s. +Matcher<::string>::Matcher(const std::string& s) { +  *this = Eq(static_cast<::string>(s));  } -// Constructs a matcher that matches a StringPiece whose value is equal to s. -Matcher<StringPiece>::Matcher(const char* s) { -  *this = Eq(internal::string(s)); -} +// Constructs a matcher that matches a ::string whose value is equal to s. +Matcher<::string>::Matcher(const ::string& s) { *this = Eq(s); } + +// Constructs a matcher that matches a string whose value is equal to s. +Matcher<::string>::Matcher(const char* s) { *this = Eq(::string(s)); } +#endif  // GTEST_HAS_GLOBAL_STRING -// Constructs a matcher that matches a StringPiece whose value is equal to s. -Matcher<StringPiece>::Matcher(StringPiece s) { -  *this = Eq(s.ToString()); -} -#endif  // GTEST_HAS_STRING_PIECE_  namespace internal { diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index c7893ae2..f8633df2 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -44,7 +44,15 @@  #include "gmock/internal/gmock-port.h"  #include "gtest/gtest.h"  #include "gtest/gtest-spi.h" + +// Indicates that this translation unit is part of Google Test's +// implementation.  It must come before gtest-internal-inl.h is +// included, or there will be a compiler error.  This trick is to +// prevent a user from accidentally including gtest-internal-inl.h in +// their code. +#define GTEST_IMPLEMENTATION_ 1  #include "src/gtest-internal-inl.h" +#undef GTEST_IMPLEMENTATION_  #if GTEST_OS_CYGWIN  # include <sys/types.h>  // For ssize_t. NOLINT @@ -61,6 +69,26 @@ namespace internal {  namespace { +TEST(JoinAsTupleTest, JoinsEmptyTuple) { +  EXPECT_EQ("", JoinAsTuple(Strings())); +} + +TEST(JoinAsTupleTest, JoinsOneTuple) { +  const char* fields[] = {"1"}; +  EXPECT_EQ("1", JoinAsTuple(Strings(fields, fields + 1))); +} + +TEST(JoinAsTupleTest, JoinsTwoTuple) { +  const char* fields[] = {"1", "a"}; +  EXPECT_EQ("(1, a)", JoinAsTuple(Strings(fields, fields + 2))); +} + +TEST(JoinAsTupleTest, JoinsTenTuple) { +  const char* fields[] = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; +  EXPECT_EQ("(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)", +            JoinAsTuple(Strings(fields, fields + 10))); +} +  TEST(ConvertIdentifierNameToWordsTest, WorksWhenNameContainsNoWord) {    EXPECT_EQ("", ConvertIdentifierNameToWords(""));    EXPECT_EQ("", ConvertIdentifierNameToWords("_")); diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index 44cba342..d80e2b08 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -47,6 +47,7 @@ using testing::NaggyMock;  using testing::Ref;  using testing::Return;  using testing::Sequence; +using testing::Value;  class MockFoo {   public: @@ -268,6 +269,10 @@ TEST_F(GMockOutputTest, CatchesLeakedMocks) {    // Both foo1 and foo2 are deliberately leaked.  } +MATCHER_P2(IsPair, first, second, "") { +  return Value(arg.first, first) && Value(arg.second, second); +} +  void TestCatchesLeakedMocksInAdHocTests() {    MockFoo* foo = new MockFoo; @@ -280,7 +285,6 @@ void TestCatchesLeakedMocksInAdHocTests() {  int main(int argc, char **argv) {    testing::InitGoogleMock(&argc, argv); -    // Ensures that the tests pass no matter what value of    // --gmock_catch_leaked_mocks and --gmock_verbose the user specifies.    testing::GMOCK_FLAG(catch_leaked_mocks) = true; | 
