From 8567b09290fe402cf01923e2131c5635b8ed851b Mon Sep 17 00:00:00 2001 From: dmauro Date: Fri, 12 Jun 2020 11:56:15 -0400 Subject: [PATCH] Googletest export Adds support for printing pointers of types char8_t, char16_t, and char32_t. PiperOrigin-RevId: 316112767 --- googletest/include/gtest/gtest-printers.h | 20 +++++++++ googletest/test/googletest-printers-test.cc | 50 +++++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index c74894b0..f24512a9 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -499,6 +499,26 @@ inline void PrintTo(const unsigned char* s, ::std::ostream* os) { inline void PrintTo(unsigned char* s, ::std::ostream* os) { PrintTo(ImplicitCast_(s), os); } +#ifdef __cpp_char8_t +inline void PrintTo(const char8_t* s, ::std::ostream* os) { + PrintTo(ImplicitCast_(s), os); +} +inline void PrintTo(char8_t* s, ::std::ostream* os) { + PrintTo(ImplicitCast_(s), os); +} +#endif +inline void PrintTo(const char16_t* s, ::std::ostream* os) { + PrintTo(ImplicitCast_(s), os); +} +inline void PrintTo(char16_t* s, ::std::ostream* os) { + PrintTo(ImplicitCast_(s), os); +} +inline void PrintTo(const char32_t* s, ::std::ostream* os) { + PrintTo(ImplicitCast_(s), os); +} +inline void PrintTo(char32_t* s, ::std::ostream* os) { + PrintTo(ImplicitCast_(s), os); +} // MSVC can be configured to define wchar_t as a typedef of unsigned // short. It defines _NATIVE_WCHAR_T_DEFINED when wchar_t is a native diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc index b0c52ef5..ba2befb8 100644 --- a/googletest/test/googletest-printers-test.cc +++ b/googletest/test/googletest-printers-test.cc @@ -513,6 +513,56 @@ TEST(PrintCharPointerTest, ConstUnsignedChar) { EXPECT_EQ("NULL", Print(p)); } +#ifdef __cpp_char8_t +// char8_t* +TEST(PrintCharPointerTest, Char8) { + char8_t* p = reinterpret_cast(0x1234); + EXPECT_EQ(PrintPointer(p), Print(p)); + p = nullptr; + EXPECT_EQ("NULL", Print(p)); +} + +// const char8_t* +TEST(PrintCharPointerTest, ConstChar8) { + const char8_t* p = reinterpret_cast(0x1234); + EXPECT_EQ(PrintPointer(p), Print(p)); + p = nullptr; + EXPECT_EQ("NULL", Print(p)); +} +#endif + +// char16_t* +TEST(PrintCharPointerTest, Char16) { + char16_t* p = reinterpret_cast(0x1234); + EXPECT_EQ(PrintPointer(p), Print(p)); + p = nullptr; + EXPECT_EQ("NULL", Print(p)); +} + +// const char16_t* +TEST(PrintCharPointerTest, ConstChar16) { + const char16_t* p = reinterpret_cast(0x1234); + EXPECT_EQ(PrintPointer(p), Print(p)); + p = nullptr; + EXPECT_EQ("NULL", Print(p)); +} + +// char32_t* +TEST(PrintCharPointerTest, Char32) { + char32_t* p = reinterpret_cast(0x1234); + EXPECT_EQ(PrintPointer(p), Print(p)); + p = nullptr; + EXPECT_EQ("NULL", Print(p)); +} + +// const char32_t* +TEST(PrintCharPointerTest, ConstChar32) { + const char32_t* p = reinterpret_cast(0x1234); + EXPECT_EQ(PrintPointer(p), Print(p)); + p = nullptr; + EXPECT_EQ("NULL", Print(p)); +} + // Tests printing pointers to simple, built-in types. // bool*.