Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(588)

Unified Diff: Source/platform/testing/GeometryPrinters.cpp

Issue 1285413007: Unify geometry test printers in a test support target. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: PrintTo instead of operator<< Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/platform/testing/GeometryPrinters.h ('k') | Source/web/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/testing/GeometryPrinters.cpp
diff --git a/Source/platform/testing/GeometryPrinters.cpp b/Source/platform/testing/GeometryPrinters.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..58498de59445a9175305c7954307d998f14438cd
--- /dev/null
+++ b/Source/platform/testing/GeometryPrinters.cpp
@@ -0,0 +1,122 @@
+// Copyright 2015 The Chromium 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 "config.h"
+#include "platform/testing/GeometryPrinters.h"
+
+#include "platform/geometry/FloatBox.h"
+#include "platform/geometry/FloatPoint.h"
+#include "platform/geometry/FloatQuad.h"
+#include "platform/geometry/FloatRect.h"
+#include "platform/geometry/FloatSize.h"
+#include "platform/geometry/LayoutRect.h"
+#include <ostream> // NOLINT
+
+namespace blink {
+
+namespace {
+
+class ScopedFloatFlags {
+public:
+ ScopedFloatFlags(std::ostream& out) : m_out(out), m_flags(out.flags())
+ {
+ out.unsetf(std::ios::floatfield);
+ m_precision = out.precision(4);
+ }
+
+ ~ScopedFloatFlags()
+ {
+ m_out.flags(m_flags);
+ m_out.precision(m_precision);
+ }
+
+private:
+ std::ostream& m_out;
+ std::ios::fmtflags m_flags;
+ std::streamsize m_precision;
+};
+
+} // namespace
+
+void PrintTo(const FloatBox& box, std::ostream* os)
+{
+ ScopedFloatFlags scope(*os);
+ *os << "FloatBox("
+ << box.x() << ", "
+ << box.y() << ", "
+ << box.z() << ", "
+ << box.width() << ", "
+ << box.height() << ", "
+ << box.depth() << ")";
+}
+
+void PrintTo(const FloatPoint& point, std::ostream* os)
+{
+ ScopedFloatFlags scope(*os);
+ *os << "FloatPoint("
+ << point.x() << ", "
+ << point.y() << ")";
+}
+
+void PrintTo(const FloatQuad& quad, std::ostream* os)
+{
+ ScopedFloatFlags scope(*os);
+ *os << "FloatQuad("
+ << "(" << quad.p1().x() << ", " << quad.p1().y() << "), "
+ << "(" << quad.p2().x() << ", " << quad.p2().y() << "), "
+ << "(" << quad.p3().x() << ", " << quad.p3().y() << "), "
+ << "(" << quad.p4().x() << ", " << quad.p4().y() << "))";
+}
+
+void PrintTo(const FloatRect& rect, std::ostream* os)
+{
+ ScopedFloatFlags scope(*os);
+ *os << "FloatRect("
+ << rect.x() << ", "
+ << rect.y() << ", "
+ << rect.width() << ", "
+ << rect.height() << ")";
+}
+
+void PrintTo(const FloatRoundedRect& roundedRect, std::ostream* os)
+{
+ *os << "FloatRoundedRect(";
+ PrintTo(roundedRect.rect(), os);
+ *os << ", ";
+ PrintTo(roundedRect.radii(), os);
+ *os << ")";
+}
+
+void PrintTo(const FloatRoundedRect::Radii& radii, std::ostream* os)
+{
+ *os << "FloatRoundedRect::Radii(";
+ PrintTo(radii.topLeft(), os);
+ *os << ", ";
+ PrintTo(radii.topRight(), os);
+ *os << ", ";
+ PrintTo(radii.bottomRight(), os);
+ *os << ", ";
+ PrintTo(radii.bottomLeft(), os);
+ *os << ")";
+}
+
+void PrintTo(const FloatSize& size, std::ostream* os)
+{
+ ScopedFloatFlags scope(*os);
+ *os << "FloatSize("
+ << size.width() << ", "
+ << size.height() << ")";
+}
+
+void PrintTo(const LayoutRect& rect, std::ostream* os)
+{
+ ScopedFloatFlags scope(*os);
+ *os << "LayoutRect("
+ << rect.x().toFloat() << ", "
+ << rect.y().toFloat() << ", "
+ << rect.width().toFloat() << ", "
+ << rect.height().toFloat() << ")";
+}
+
+} // namespace blink
« no previous file with comments | « Source/platform/testing/GeometryPrinters.h ('k') | Source/web/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698