summaryrefslogtreecommitdiff
path: root/testing
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-01-07 12:25:07 -0800
committerTom Sepez <tsepez@chromium.org>2015-01-07 12:25:07 -0800
commit948095edfc04f35a69f15cd7d9926844ee0ac624 (patch)
tree37544706fb77d5cdf4b952a2745cfa570a7206a2 /testing
parentd12a4f465a0bcc8b233079ccd54bf7882f3532d5 (diff)
downloadpdfium-948095edfc04f35a69f15cd7d9926844ee0ac624.tar.xz
Add ostream helpers for FX String classes.
This allows integration with the gtest EXPECT_* macros. R=brucedawson@chromium.org Review URL: https://codereview.chromium.org/837843002
Diffstat (limited to 'testing')
-rw-r--r--testing/fx_string_testhelpers.cpp47
-rw-r--r--testing/fx_string_testhelpers.h19
2 files changed, 66 insertions, 0 deletions
diff --git a/testing/fx_string_testhelpers.cpp b/testing/fx_string_testhelpers.cpp
new file mode 100644
index 0000000000..1ee705fa4c
--- /dev/null
+++ b/testing/fx_string_testhelpers.cpp
@@ -0,0 +1,47 @@
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "fx_string_testhelpers.h"
+
+#include <ios>
+#include <iomanip>
+
+namespace {
+
+template <typename T>
+std::ostream& output_string(std::ostream& out, const T& str) {
+ out << std::hex << std::setfill('0') << '"';
+ for (size_t i = 0; i < str.GetLength(); ++i) {
+ unsigned int c = str.GetAt(i);
+ if (c >= 0x20 && c < 0x7F) {
+ out << static_cast<char>(c);
+ } else if (sizeof(typename T::value_type) == 1) {
+ out << "\\x" << std::setw(2) << c << std::setw(0);
+ } else if (c < 0x10000) {
+ out << "\\u" << std::setw(4) << c << std::setw(0);
+ } else {
+ out << "<invalid>";
+ }
+ }
+ out << '"' << std::dec << std::setfill(' ');
+ return out;
+}
+
+} // namespace
+
+std::ostream& operator<<(std::ostream& out, const CFX_ByteStringC& str) {
+ return output_string(out, str);
+}
+
+std::ostream& operator<<(std::ostream& out, const CFX_ByteString& str) {
+ return output_string(out, str);
+}
+
+std::ostream& operator<<(std::ostream& out, const CFX_WideStringC& str) {
+ return output_string(out, str);
+}
+
+std::ostream& operator<<(std::ostream& out, const CFX_WideString& str) {
+ return output_string(out, str);
+}
diff --git a/testing/fx_string_testhelpers.h b/testing/fx_string_testhelpers.h
new file mode 100644
index 0000000000..7d0668817c
--- /dev/null
+++ b/testing/fx_string_testhelpers.h
@@ -0,0 +1,19 @@
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef TESTING_FX_STRING_TESTHELPERS_H_
+#define TESTING_FX_STRING_TESTHELPERS_H_
+
+#include <ostream>
+
+#include "../core/include/fxcrt/fx_basic.h"
+
+// Output stream operator so GTEST macros work with FX strings.
+std::ostream& operator<<(std::ostream& out, const CFX_ByteStringC& str);
+std::ostream& operator<<(std::ostream& out, const CFX_ByteString& str);
+std::ostream& operator<<(std::ostream& out, const CFX_WideStringC& str);
+std::ostream& operator<<(std::ostream& out, const CFX_WideString& str);
+
+#endif // TESTING_FX_STR_TESTHELPERS_H_
+