Teach googletest about C-string to ByteString comparisons

Add custom gtest printer code to treat the C-string in a C-string to
ByteString comparison as a string instead of a pointer.

Change-Id: I9b496da300dd134c4e3a8ee626939c70815a6c8f
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/107135
Reviewed-by: K. Moon <kmoon@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcrt/BUILD.gn b/core/fxcrt/BUILD.gn
index f91be3c..4b0e4ee 100644
--- a/core/fxcrt/BUILD.gn
+++ b/core/fxcrt/BUILD.gn
@@ -125,6 +125,7 @@
     "../../third_party:fx_lcms2",
     "../../third_party:fx_libopenjpeg",
     "../../third_party:fx_tiff",
+    "../../third_party/googletest:gtest",
     "../../xfa/*",
   ]
   deps = [ "../../third_party:pdfium_base" ]
diff --git a/third_party/googletest/BUILD.gn b/third_party/googletest/BUILD.gn
index 02f0ff8..e2c3f6b 100644
--- a/third_party/googletest/BUILD.gn
+++ b/third_party/googletest/BUILD.gn
@@ -61,6 +61,7 @@
 source_set("gtest") {
   testonly = true
   sources = [
+    "custom/gtest/internal/custom/gtest-printers.h",
     "custom/gtest/internal/custom/gtest.h",
     "custom/gtest/internal/custom/stack_trace_getter.cc",
     "custom/gtest/internal/custom/stack_trace_getter.h",
@@ -127,7 +128,7 @@
   ]
 
   deps = []
-  public_deps = []
+  public_deps = [ "../../core/fxcrt" ]
 
   if (is_fuchsia) {
     deps += [
diff --git a/third_party/googletest/DEPS b/third_party/googletest/DEPS
new file mode 100644
index 0000000..f80c171
--- /dev/null
+++ b/third_party/googletest/DEPS
@@ -0,0 +1,3 @@
+include_rules = [
+  '+core/fxcrt',
+]
diff --git a/third_party/googletest/custom/gtest/internal/custom/gtest-printers.h b/third_party/googletest/custom/gtest/internal/custom/gtest-printers.h
new file mode 100644
index 0000000..b2aebb3
--- /dev/null
+++ b/third_party/googletest/custom/gtest/internal/custom/gtest-printers.h
@@ -0,0 +1,33 @@
+// Copyright 2023 The PDFium Authors
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef THIRD_PARTY_GOOGLETEST_CUSTOM_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
+#define THIRD_PARTY_GOOGLETEST_CUSTOM_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_
+
+#include <string>
+
+#include "core/fxcrt/bytestring.h"
+
+namespace testing {
+
+// If a C string is compared with a PDFium string object, then it is meant to
+// point to a NUL-terminated string, and thus print it as a string.
+
+#define GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(CharType, OtherStringType) \
+  template <>                                                            \
+  class internal::FormatForComparison<CharType*, OtherStringType> {      \
+   public:                                                               \
+    static std::string Format(CharType* value) {                         \
+      return ::testing::PrintToString(value);                            \
+    }                                                                    \
+  }
+
+GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(char, fxcrt::ByteString);
+GTEST_IMPL_FORMAT_C_STRING_AS_STRING_(const char, fxcrt::ByteString);
+
+#undef GTEST_IMPL_FORMAT_C_STRING_AS_STRING_
+
+}  // namespace testing
+
+#endif  // THIRD_PARTY_GOOGLETEST_CUSTOM_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_