Remove wchar_t overloads if GTEST_HAS_STD_WSTRING is disabled
PiperOrigin-RevId: 966053142 Change-Id: I6535e5577b430186a57ad9c401877aaa83cf37d1
This commit is contained in:
committed by
Copybara-Service
parent
71edd0ef29
commit
7358557f03
@@ -1101,6 +1101,7 @@ TEST(SetArgPointeeTest, AcceptsStringLiteral) {
|
||||
EXPECT_STREQ("world", ptr);
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
TEST(SetArgPointeeTest, AcceptsWideStringLiteral) {
|
||||
typedef void MyFunction(const wchar_t**);
|
||||
Action<MyFunction> a = SetArgPointee<0>(L"world");
|
||||
@@ -1108,16 +1109,13 @@ TEST(SetArgPointeeTest, AcceptsWideStringLiteral) {
|
||||
a.Perform(std::make_tuple(&ptr));
|
||||
EXPECT_STREQ(L"world", ptr);
|
||||
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
|
||||
typedef void MyStringFunction(std::wstring*);
|
||||
Action<MyStringFunction> a2 = SetArgPointee<0>(L"world");
|
||||
std::wstring str = L"";
|
||||
a2.Perform(std::make_tuple(&str));
|
||||
EXPECT_EQ(L"world", str);
|
||||
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
// Tests that SetArgPointee<N>() accepts a char pointer.
|
||||
TEST(SetArgPointeeTest, AcceptsCharPointer) {
|
||||
|
||||
@@ -87,10 +87,10 @@ TEST(InitGoogleMockTest, ParsesSingleFlag) {
|
||||
|
||||
TEST(InitGoogleMockTest, ParsesMultipleFlags) {
|
||||
int old_default_behavior = GMOCK_FLAG_GET(default_mock_behavior);
|
||||
const wchar_t* argv[] = {L"foo.exe", L"--gmock_verbose=info",
|
||||
L"--gmock_default_mock_behavior=2", nullptr};
|
||||
const char* argv[] = {"foo.exe", "--gmock_verbose=info",
|
||||
"--gmock_default_mock_behavior=2", nullptr};
|
||||
|
||||
const wchar_t* new_argv[] = {L"foo.exe", nullptr};
|
||||
const char* new_argv[] = {"foo.exe", nullptr};
|
||||
|
||||
TestInitGoogleMock(argv, new_argv, "info");
|
||||
EXPECT_EQ(2, GMOCK_FLAG_GET(default_mock_behavior));
|
||||
@@ -115,6 +115,8 @@ TEST(InitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) {
|
||||
TestInitGoogleMock(argv, new_argv, "error");
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
|
||||
TEST(WideInitGoogleMockTest, ParsesInvalidCommandLine) {
|
||||
const wchar_t* argv[] = {nullptr};
|
||||
|
||||
@@ -168,6 +170,7 @@ TEST(WideInitGoogleMockTest, ParsesGoogleMockFlagAndUnrecognizedFlag) {
|
||||
|
||||
TestInitGoogleMock(argv, new_argv, "error");
|
||||
}
|
||||
#endif // GTEST_HAS_STD_WSTRING
|
||||
|
||||
#endif // !defined(GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_)
|
||||
|
||||
|
||||
@@ -674,7 +674,12 @@ inline void PrintTo(char32_t* s, ::std::ostream* os) {
|
||||
PrintTo(ImplicitCast_<const char32_t*>(s), os);
|
||||
}
|
||||
|
||||
#if GTEST_HAS_NATIVE_WCHAR
|
||||
// Only add an overload for printing wchar_t* if:
|
||||
// 1. Wide string support is enabled.
|
||||
// 2. wchar_t is a distinct native type. (If it's a typedef, the overload could
|
||||
// cause a pointer to the underlying type to be mistakenly treated as a
|
||||
// string.)
|
||||
#if GTEST_HAS_STD_WSTRING && GTEST_HAS_NATIVE_WCHAR
|
||||
// Overloads for wide C strings
|
||||
GTEST_API_ void PrintTo(const wchar_t* s, ::std::ostream* os);
|
||||
inline void PrintTo(wchar_t* s, ::std::ostream* os) {
|
||||
|
||||
@@ -1514,6 +1514,8 @@ GTEST_API_ AssertionResult CmpHelperSTRCASENE(const char* s1_expression,
|
||||
const char* s2_expression,
|
||||
const char* s1, const char* s2);
|
||||
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
|
||||
// Helper function for *_STREQ on wide strings.
|
||||
//
|
||||
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
|
||||
@@ -1528,6 +1530,8 @@ GTEST_API_ AssertionResult CmpHelperSTRNE(const char* s1_expression,
|
||||
const char* s2_expression,
|
||||
const wchar_t* s1, const wchar_t* s2);
|
||||
|
||||
#endif // GTEST_HAS_STD_WSTRING
|
||||
|
||||
} // namespace internal
|
||||
|
||||
// IsSubstring() and IsNotSubstring() are intended to be used as the
|
||||
@@ -1542,18 +1546,10 @@ GTEST_API_ AssertionResult IsSubstring(const char* needle_expr,
|
||||
const char* haystack_expr,
|
||||
const char* needle,
|
||||
const char* haystack);
|
||||
GTEST_API_ AssertionResult IsSubstring(const char* needle_expr,
|
||||
const char* haystack_expr,
|
||||
const wchar_t* needle,
|
||||
const wchar_t* haystack);
|
||||
GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr,
|
||||
const char* haystack_expr,
|
||||
const char* needle,
|
||||
const char* haystack);
|
||||
GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr,
|
||||
const char* haystack_expr,
|
||||
const wchar_t* needle,
|
||||
const wchar_t* haystack);
|
||||
GTEST_API_ AssertionResult IsSubstring(const char* needle_expr,
|
||||
const char* haystack_expr,
|
||||
const ::std::string& needle,
|
||||
@@ -1564,6 +1560,14 @@ GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr,
|
||||
const ::std::string& haystack);
|
||||
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
GTEST_API_ AssertionResult IsSubstring(const char* needle_expr,
|
||||
const char* haystack_expr,
|
||||
const wchar_t* needle,
|
||||
const wchar_t* haystack);
|
||||
GTEST_API_ AssertionResult IsNotSubstring(const char* needle_expr,
|
||||
const char* haystack_expr,
|
||||
const wchar_t* needle,
|
||||
const wchar_t* haystack);
|
||||
GTEST_API_ AssertionResult IsSubstring(const char* needle_expr,
|
||||
const char* haystack_expr,
|
||||
const ::std::wstring& needle,
|
||||
|
||||
@@ -468,10 +468,9 @@ void PrintTo(const char16_t* s, ostream* os) { PrintCStringTo(s, os); }
|
||||
|
||||
void PrintTo(const char32_t* s, ostream* os) { PrintCStringTo(s, os); }
|
||||
|
||||
#if GTEST_HAS_NATIVE_WCHAR
|
||||
// Prints the given wide C string to the ostream.
|
||||
#if GTEST_HAS_STD_WSTRING && GTEST_HAS_NATIVE_WCHAR
|
||||
void PrintTo(const wchar_t* s, ostream* os) { PrintCStringTo(s, os); }
|
||||
#endif // GTEST_HAS_NATIVE_WCHAR
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
+15
-11
@@ -1876,11 +1876,13 @@ bool IsSubstringPred(const char* needle, const char* haystack) {
|
||||
return strstr(haystack, needle) != nullptr;
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
bool IsSubstringPred(const wchar_t* needle, const wchar_t* haystack) {
|
||||
if (needle == nullptr || haystack == nullptr) return needle == haystack;
|
||||
|
||||
return wcsstr(haystack, needle) != nullptr;
|
||||
}
|
||||
#endif // GTEST_HAS_STD_WSTRING
|
||||
|
||||
// StringType here can be either ::std::string or ::std::wstring.
|
||||
template <typename StringType>
|
||||
@@ -1922,23 +1924,12 @@ AssertionResult IsSubstring(const char* needle_expr, const char* haystack_expr,
|
||||
return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);
|
||||
}
|
||||
|
||||
AssertionResult IsSubstring(const char* needle_expr, const char* haystack_expr,
|
||||
const wchar_t* needle, const wchar_t* haystack) {
|
||||
return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);
|
||||
}
|
||||
|
||||
AssertionResult IsNotSubstring(const char* needle_expr,
|
||||
const char* haystack_expr, const char* needle,
|
||||
const char* haystack) {
|
||||
return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);
|
||||
}
|
||||
|
||||
AssertionResult IsNotSubstring(const char* needle_expr,
|
||||
const char* haystack_expr, const wchar_t* needle,
|
||||
const wchar_t* haystack) {
|
||||
return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);
|
||||
}
|
||||
|
||||
AssertionResult IsSubstring(const char* needle_expr, const char* haystack_expr,
|
||||
const ::std::string& needle,
|
||||
const ::std::string& haystack) {
|
||||
@@ -1953,6 +1944,17 @@ AssertionResult IsNotSubstring(const char* needle_expr,
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
AssertionResult IsSubstring(const char* needle_expr, const char* haystack_expr,
|
||||
const wchar_t* needle, const wchar_t* haystack) {
|
||||
return IsSubstringImpl(true, needle_expr, haystack_expr, needle, haystack);
|
||||
}
|
||||
|
||||
AssertionResult IsNotSubstring(const char* needle_expr,
|
||||
const char* haystack_expr, const wchar_t* needle,
|
||||
const wchar_t* haystack) {
|
||||
return IsSubstringImpl(false, needle_expr, haystack_expr, needle, haystack);
|
||||
}
|
||||
|
||||
AssertionResult IsSubstring(const char* needle_expr, const char* haystack_expr,
|
||||
const ::std::wstring& needle,
|
||||
const ::std::wstring& haystack) {
|
||||
@@ -2182,6 +2184,7 @@ bool String::WideCStringEquals(const wchar_t* lhs, const wchar_t* rhs) {
|
||||
return wcscmp(lhs, rhs) == 0;
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
// Helper function for *_STREQ on wide strings.
|
||||
AssertionResult CmpHelperSTREQ(const char* lhs_expression,
|
||||
const char* rhs_expression, const wchar_t* lhs,
|
||||
@@ -2206,6 +2209,7 @@ AssertionResult CmpHelperSTRNE(const char* s1_expression,
|
||||
<< "Expected: (" << s1_expression << ") != (" << s2_expression
|
||||
<< "), actual: " << PrintToString(s1) << " vs " << PrintToString(s2);
|
||||
}
|
||||
#endif // GTEST_HAS_STD_WSTRING
|
||||
|
||||
// Compares two C strings, ignoring case. Returns true if and only if they have
|
||||
// the same content.
|
||||
|
||||
@@ -649,6 +649,7 @@ TEST(PrintU32StringTest, EscapesProperly) {
|
||||
}
|
||||
|
||||
#if GTEST_HAS_NATIVE_WCHAR
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
|
||||
// const wchar_t*.
|
||||
TEST(PrintWideCStringTest, Const) {
|
||||
@@ -679,6 +680,7 @@ TEST(PrintWideCStringTest, EscapesProperly) {
|
||||
"\\n\\r\\t\\v\\xD3\\x576\\x8D3\\xC74D a\"",
|
||||
Print(static_cast<const wchar_t*>(s)));
|
||||
}
|
||||
#endif // GTEST_HAS_STD_WSTRING
|
||||
#endif // GTEST_HAS_NATIVE_WCHAR
|
||||
|
||||
// Tests printing pointers to other char types.
|
||||
|
||||
@@ -2564,6 +2564,7 @@ TEST(StringAssertionTest, ASSERT_STRCASENE) {
|
||||
EXPECT_FATAL_FAILURE(ASSERT_STRCASENE("Hi", "hi"), "(ignoring case)");
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
// Tests *_STREQ on wide strings.
|
||||
TEST(StringAssertionTest, STREQ_Wide) {
|
||||
// NULL strings.
|
||||
@@ -2619,6 +2620,7 @@ TEST(StringAssertionTest, STRNE_Wide) {
|
||||
// The streaming variation.
|
||||
ASSERT_STRNE(L"abc\x8119", L"abc\x8120") << "This shouldn't happen";
|
||||
}
|
||||
#endif // GTEST_HAS_STD_WSTRING
|
||||
|
||||
// Tests for ::testing::IsSubstring().
|
||||
|
||||
@@ -2633,18 +2635,6 @@ TEST(IsSubstringTest, ReturnsCorrectResultForCString) {
|
||||
EXPECT_TRUE(IsSubstring("", "", "needle", "two needles"));
|
||||
}
|
||||
|
||||
// Tests that IsSubstring() returns the correct result when the input
|
||||
// argument type is const wchar_t*.
|
||||
TEST(IsSubstringTest, ReturnsCorrectResultForWideCString) {
|
||||
EXPECT_FALSE(IsSubstring("", "", kNull, L"a"));
|
||||
EXPECT_FALSE(IsSubstring("", "", L"b", kNull));
|
||||
EXPECT_FALSE(IsSubstring("", "", L"needle", L"haystack"));
|
||||
|
||||
EXPECT_TRUE(
|
||||
IsSubstring("", "", static_cast<const wchar_t*>(nullptr), nullptr));
|
||||
EXPECT_TRUE(IsSubstring("", "", L"needle", L"two needles"));
|
||||
}
|
||||
|
||||
// Tests that IsSubstring() generates the correct message when the input
|
||||
// argument type is const char*.
|
||||
TEST(IsSubstringTest, GeneratesCorrectMessageForCString) {
|
||||
@@ -2665,6 +2655,18 @@ TEST(IsSubstringTest, ReturnsCorrectResultsForStdString) {
|
||||
}
|
||||
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
// Tests that IsSubstring() returns the correct result when the input
|
||||
// argument type is const wchar_t*.
|
||||
TEST(IsSubstringTest, ReturnsCorrectResultForWideCString) {
|
||||
EXPECT_FALSE(IsSubstring("", "", kNull, L"a"));
|
||||
EXPECT_FALSE(IsSubstring("", "", L"b", kNull));
|
||||
EXPECT_FALSE(IsSubstring("", "", L"needle", L"haystack"));
|
||||
|
||||
EXPECT_TRUE(
|
||||
IsSubstring("", "", static_cast<const wchar_t*>(nullptr), nullptr));
|
||||
EXPECT_TRUE(IsSubstring("", "", L"needle", L"two needles"));
|
||||
}
|
||||
|
||||
// Tests that IsSubstring returns the correct result when the input
|
||||
// argument type is ::std::wstring.
|
||||
TEST(IsSubstringTest, ReturnsCorrectResultForStdWstring) {
|
||||
@@ -2696,25 +2698,6 @@ TEST(IsNotSubstringTest, ReturnsCorrectResultForCString) {
|
||||
EXPECT_FALSE(IsNotSubstring("", "", "needle", "two needles"));
|
||||
}
|
||||
|
||||
// Tests that IsNotSubstring() returns the correct result when the input
|
||||
// argument type is const wchar_t*.
|
||||
TEST(IsNotSubstringTest, ReturnsCorrectResultForWideCString) {
|
||||
EXPECT_TRUE(IsNotSubstring("", "", L"needle", L"haystack"));
|
||||
EXPECT_FALSE(IsNotSubstring("", "", L"needle", L"two needles"));
|
||||
}
|
||||
|
||||
// Tests that IsNotSubstring() generates the correct message when the input
|
||||
// argument type is const wchar_t*.
|
||||
TEST(IsNotSubstringTest, GeneratesCorrectMessageForWideCString) {
|
||||
EXPECT_STREQ(
|
||||
"Value of: needle_expr\n"
|
||||
" Actual: L\"needle\"\n"
|
||||
"Expected: not a substring of haystack_expr\n"
|
||||
"Which is: L\"two needles\"",
|
||||
IsNotSubstring("needle_expr", "haystack_expr", L"needle", L"two needles")
|
||||
.failure_message());
|
||||
}
|
||||
|
||||
// Tests that IsNotSubstring returns the correct result when the input
|
||||
// argument type is ::std::string.
|
||||
TEST(IsNotSubstringTest, ReturnsCorrectResultsForStdString) {
|
||||
@@ -2736,6 +2719,25 @@ TEST(IsNotSubstringTest, GeneratesCorrectMessageForStdString) {
|
||||
|
||||
#if GTEST_HAS_STD_WSTRING
|
||||
|
||||
// Tests that IsNotSubstring() returns the correct result when the input
|
||||
// argument type is const wchar_t*.
|
||||
TEST(IsNotSubstringTest, ReturnsCorrectResultForWideCString) {
|
||||
EXPECT_TRUE(IsNotSubstring("", "", L"needle", L"haystack"));
|
||||
EXPECT_FALSE(IsNotSubstring("", "", L"needle", L"two needles"));
|
||||
}
|
||||
|
||||
// Tests that IsNotSubstring() generates the correct message when the input
|
||||
// argument type is const wchar_t*.
|
||||
TEST(IsNotSubstringTest, GeneratesCorrectMessageForWideCString) {
|
||||
EXPECT_STREQ(
|
||||
"Value of: needle_expr\n"
|
||||
" Actual: L\"needle\"\n"
|
||||
"Expected: not a substring of haystack_expr\n"
|
||||
"Which is: L\"two needles\"",
|
||||
IsNotSubstring("needle_expr", "haystack_expr", L"needle", L"two needles")
|
||||
.failure_message());
|
||||
}
|
||||
|
||||
// Tests that IsNotSubstring returns the correct result when the input
|
||||
// argument type is ::std::wstring.
|
||||
TEST(IsNotSubstringTest, ReturnsCorrectResultForStdWstring) {
|
||||
|
||||
Reference in New Issue
Block a user