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

Side by Side Diff: third_party/WebKit/Source/platform/testing/GeometryPrinters.cpp

Issue 2191233002: Add platform/geometry pretty printers for logging and testing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adjust tests to work around uninteresting cross-platform differences Created 4 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "platform/testing/GeometryPrinters.h"
6
7 #include "platform/geometry/FloatBox.h"
8 #include "platform/geometry/FloatPoint.h"
9 #include "platform/geometry/FloatPoint3D.h"
10 #include "platform/geometry/FloatQuad.h"
11 #include "platform/geometry/FloatRect.h"
12 #include "platform/geometry/FloatSize.h"
13 #include "platform/geometry/LayoutRect.h"
14 #include <ostream> // NOLINT
15
16 namespace blink {
17
18 namespace {
19
20 class ScopedFloatFlags {
21 public:
22 ScopedFloatFlags(std::ostream& out) : m_out(out), m_flags(out.flags())
23 {
24 out.unsetf(std::ios::floatfield);
25 m_precision = out.precision(4);
26 }
27
28 ~ScopedFloatFlags()
29 {
30 m_out.flags(m_flags);
31 m_out.precision(m_precision);
32 }
33
34 private:
35 std::ostream& m_out;
36 std::ios::fmtflags m_flags;
37 std::streamsize m_precision;
38 };
39
40 } // namespace
41
42 void PrintTo(const FloatBox& box, std::ostream* os)
43 {
44 ScopedFloatFlags scope(*os);
45 *os << "FloatBox("
46 << box.x() << ", "
47 << box.y() << ", "
48 << box.z() << ", "
49 << box.width() << ", "
50 << box.height() << ", "
51 << box.depth() << ")";
52 }
53
54 void PrintTo(const FloatPoint& point, std::ostream* os)
55 {
56 ScopedFloatFlags scope(*os);
57 *os << "FloatPoint("
58 << point.x() << ", "
59 << point.y() << ")";
60 }
61
62 void PrintTo(const FloatPoint3D& point, std::ostream* os)
63 {
64 ScopedFloatFlags scope(*os);
65 *os << "FloatPoint3D("
66 << point.x() << ", "
67 << point.y() << ", "
68 << point.z() << ")";
69 }
70
71 void PrintTo(const FloatQuad& quad, std::ostream* os)
72 {
73 ScopedFloatFlags scope(*os);
74 *os << "FloatQuad("
75 << "(" << quad.p1().x() << ", " << quad.p1().y() << "), "
76 << "(" << quad.p2().x() << ", " << quad.p2().y() << "), "
77 << "(" << quad.p3().x() << ", " << quad.p3().y() << "), "
78 << "(" << quad.p4().x() << ", " << quad.p4().y() << "))";
79 }
80
81 void PrintTo(const FloatRect& rect, std::ostream* os)
82 {
83 ScopedFloatFlags scope(*os);
84 *os << "FloatRect("
85 << rect.x() << ", "
86 << rect.y() << ", "
87 << rect.width() << ", "
88 << rect.height() << ")";
89 }
90
91 void PrintTo(const FloatRoundedRect& roundedRect, std::ostream* os)
92 {
93 *os << "FloatRoundedRect(";
94 PrintTo(roundedRect.rect(), os);
95 *os << ", ";
96 PrintTo(roundedRect.getRadii(), os);
97 *os << ")";
98 }
99
100 void PrintTo(const FloatRoundedRect::Radii& radii, std::ostream* os)
101 {
102 *os << "FloatRoundedRect::Radii(";
103 PrintTo(radii.topLeft(), os);
104 *os << ", ";
105 PrintTo(radii.topRight(), os);
106 *os << ", ";
107 PrintTo(radii.bottomLeft(), os);
108 *os << ", ";
109 PrintTo(radii.bottomRight(), os);
110 *os << ")";
111 }
112
113 void PrintTo(const FloatSize& size, std::ostream* os)
114 {
115 ScopedFloatFlags scope(*os);
116 *os << "FloatSize("
117 << size.width() << ", "
118 << size.height() << ")";
119 }
120
121 void PrintTo(const IntRect& rect, std::ostream* os)
122 {
123 *os << "IntRect("
124 << rect.x() << ", "
125 << rect.y() << ", "
126 << rect.width() << ", "
127 << rect.height() << ")";
128 }
129
130 void PrintTo(const LayoutRect& rect, std::ostream* os)
131 {
132 ScopedFloatFlags scope(*os);
133 *os << "LayoutRect("
134 << rect.x().toFloat() << ", "
135 << rect.y().toFloat() << ", "
136 << rect.width().toFloat() << ", "
137 << rect.height().toFloat() << ")";
138 }
139
140 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698