diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index d19a587a1..e9378f982 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -1487,6 +1487,36 @@ GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression, const char* s2_expression, const wchar_t* s1, const wchar_t* s2); +#if GTEST_INTERNAL_HAS_STRING_VIEW +GTEST_ATTRIBUTE_UNUSED_ static inline AssertionResult CmpHelperSTREQ( + const char* s1_expression, const char* s2_expression, + const internal::StringView& s1, const internal::StringView& s2) { + return CmpHelperSTREQ(s1_expression, s2_expression, std::string(s1).c_str(), + std::string(s2).c_str()); +} + +GTEST_ATTRIBUTE_UNUSED_ static inline AssertionResult CmpHelperSTRCASEEQ( + const char* s1_expression, const char* s2_expression, + const internal::StringView& s1, const internal::StringView& s2) { + return CmpHelperSTRCASEEQ(s1_expression, s2_expression, + std::string(s1).c_str(), std::string(s2).c_str()); +} + +GTEST_ATTRIBUTE_UNUSED_ static inline AssertionResult CmpHelperSTRNE( + const char* s1_expression, const char* s2_expression, + const internal::StringView& s1, const internal::StringView& s2) { + return CmpHelperSTRNE(s1_expression, s2_expression, std::string(s1).c_str(), + std::string(s2).c_str()); +} + +GTEST_ATTRIBUTE_UNUSED_ static inline AssertionResult CmpHelperSTRCASENE( + const char* s1_expression, const char* s2_expression, + const internal::StringView& s1, const internal::StringView& s2) { + return CmpHelperSTRCASENE(s1_expression, s2_expression, + std::string(s1).c_str(), std::string(s2).c_str()); +} +#endif // GTEST_INTERNAL_HAS_STRING_VIEW + } // namespace internal // IsSubstring() and IsNotSubstring() are intended to be used as the diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index cdfdc6c42..dca271c03 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -272,6 +272,10 @@ using testing::internal::GetCapturedStdout; using testing::internal::ThreadWithParam; #endif +#if GTEST_INTERNAL_HAS_STRING_VIEW +using testing::internal::StringView; +#endif + class TestingVector : public std::vector {}; ::std::ostream& operator<<(::std::ostream& os, const TestingVector& vector) { @@ -2526,6 +2530,17 @@ TEST(StringAssertionTest, ASSERT_STRCASENE) { EXPECT_FATAL_FAILURE(ASSERT_STRCASENE("Hi", "hi"), "(ignoring case)"); } +#if GTEST_INTERNAL_HAS_STRING_VIEW +// Tests correct mapping to the C-String functions +TEST(StringAssertionTest, StringView) { + ASSERT_STREQ(StringView("hi"), StringView("hi")); + ASSERT_STREQ(StringView("hi"), "hi"); + ASSERT_STRNE("hi", StringView("hi2")); + ASSERT_STRCASEEQ(StringView("hi"), "Hi"); + ASSERT_STRCASENE("hi1", StringView("Hi2")); +} +#endif // GTEST_INTERNAL_HAS_STRING_VIEW + // Tests *_STREQ on wide strings. TEST(StringAssertionTest, STREQ_Wide) { // NULL strings.