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

Side by Side Diff: ui/gfx/test/gfx_util.cc

Issue 368903003: Provide gtest printers for ui/gfx geometry types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add gfx_test_support dep to video_encode_accelerator_unittest Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « ui/gfx/test/gfx_util.h ('k') | ui/gfx/transform.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/test/gfx_util.h" 5 #include "ui/gfx/test/gfx_util.h"
6 6
7 #include <iomanip> 7 #include <iomanip>
8 #include <sstream> 8 #include <sstream>
9 #include <string> 9 #include <string>
10 10
11 #include "ui/gfx/geometry/box_f.h"
12 #include "ui/gfx/geometry/point.h"
13 #include "ui/gfx/geometry/point3_f.h"
14 #include "ui/gfx/geometry/point_f.h"
15 #include "ui/gfx/geometry/quad_f.h"
16 #include "ui/gfx/geometry/rect.h"
17 #include "ui/gfx/geometry/rect_f.h"
18 #include "ui/gfx/geometry/size.h"
19 #include "ui/gfx/geometry/size_f.h"
20 #include "ui/gfx/geometry/vector2d.h"
21 #include "ui/gfx/geometry/vector2d_f.h"
22 #include "ui/gfx/geometry/vector3d_f.h"
23 #include "ui/gfx/transform.h"
24
11 namespace gfx { 25 namespace gfx {
12 26
13 namespace { 27 namespace {
14 28
15 std::string ColorAsString(SkColor color) { 29 std::string ColorAsString(SkColor color) {
16 std::ostringstream stream; 30 std::ostringstream stream;
17 stream << std::hex << std::uppercase << "#" << std::setfill('0') 31 stream << std::hex << std::uppercase << "#" << std::setfill('0')
18 << std::setw(2) << SkColorGetA(color) 32 << std::setw(2) << SkColorGetA(color)
19 << std::setw(2) << SkColorGetR(color) 33 << std::setw(2) << SkColorGetR(color)
20 << std::setw(2) << SkColorGetG(color) 34 << std::setw(2) << SkColorGetG(color)
(...skipping 20 matching lines...) Expand all
41 FloatAlmostEqual(lhs.height(), rhs.height()) && 55 FloatAlmostEqual(lhs.height(), rhs.height()) &&
42 FloatAlmostEqual(lhs.depth(), rhs.depth())) { 56 FloatAlmostEqual(lhs.depth(), rhs.depth())) {
43 return ::testing::AssertionSuccess(); 57 return ::testing::AssertionSuccess();
44 } 58 }
45 return ::testing::AssertionFailure() << "Value of: " << rhs_expr 59 return ::testing::AssertionFailure() << "Value of: " << rhs_expr
46 << "\n Actual: " << rhs.ToString() 60 << "\n Actual: " << rhs.ToString()
47 << "\nExpected: " << lhs_expr 61 << "\nExpected: " << lhs_expr
48 << "\nWhich is: " << lhs.ToString(); 62 << "\nWhich is: " << lhs.ToString();
49 } 63 }
50 64
65 ::testing::AssertionResult AssertRectFloatEqual(const char* lhs_expr,
66 const char* rhs_expr,
67 const RectF& lhs,
68 const RectF& rhs) {
69 if (FloatAlmostEqual(lhs.x(), rhs.x()) &&
70 FloatAlmostEqual(lhs.y(), rhs.y()) &&
71 FloatAlmostEqual(lhs.width(), rhs.width()) &&
72 FloatAlmostEqual(lhs.height(), rhs.height())) {
73 return ::testing::AssertionSuccess();
74 }
75 return ::testing::AssertionFailure()
76 << "Value of: " << rhs_expr << "\n Actual: " << rhs.ToString()
77 << "\nExpected: " << lhs_expr << "\nWhich is: " << lhs.ToString();
78 }
79
51 ::testing::AssertionResult AssertSkColorsEqual(const char* lhs_expr, 80 ::testing::AssertionResult AssertSkColorsEqual(const char* lhs_expr,
52 const char* rhs_expr, 81 const char* rhs_expr,
53 SkColor lhs, 82 SkColor lhs,
54 SkColor rhs) { 83 SkColor rhs) {
55 if (lhs == rhs) { 84 if (lhs == rhs) {
56 return ::testing::AssertionSuccess(); 85 return ::testing::AssertionSuccess();
57 } 86 }
58 return ::testing::AssertionFailure() << "Value of: " << rhs_expr 87 return ::testing::AssertionFailure() << "Value of: " << rhs_expr
59 << "\n Actual: " << ColorAsString(rhs) 88 << "\n Actual: " << ColorAsString(rhs)
60 << "\nExpected: " << lhs_expr 89 << "\nExpected: " << lhs_expr
61 << "\nWhich is: " << ColorAsString(lhs); 90 << "\nWhich is: " << ColorAsString(lhs);
62 } 91 }
63 92
93 void PrintTo(const BoxF& box, ::std::ostream* os) {
94 *os << box.ToString();
95 }
96
97 void PrintTo(const Point& point, ::std::ostream* os) {
98 *os << point.ToString();
99 }
100
101 void PrintTo(const Point3F& point, ::std::ostream* os) {
102 *os << point.ToString();
103 }
104
105 void PrintTo(const PointF& point, ::std::ostream* os) {
106 *os << point.ToString();
107 }
108
109 void PrintTo(const QuadF& quad, ::std::ostream* os) {
110 *os << quad.ToString();
111 }
112
113 void PrintTo(const Rect& rect, ::std::ostream* os) {
114 *os << rect.ToString();
115 }
116
117 void PrintTo(const RectF& rect, ::std::ostream* os) {
118 *os << rect.ToString();
119 }
120
121 void PrintTo(const Size& size, ::std::ostream* os) {
122 *os << size.ToString();
123 }
124
125 void PrintTo(const SizeF& size, ::std::ostream* os) {
126 *os << size.ToString();
127 }
128
129 void PrintTo(const Transform& transform, ::std::ostream* os) {
130 *os << transform.ToString();
131 }
132
133 void PrintTo(const Vector2d& vector, ::std::ostream* os) {
134 *os << vector.ToString();
135 }
136
137 void PrintTo(const Vector2dF& vector, ::std::ostream* os) {
138 *os << vector.ToString();
139 }
140
141 void PrintTo(const Vector3dF& vector, ::std::ostream* os) {
142 *os << vector.ToString();
143 }
144
64 } // namespace gfx 145 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/test/gfx_util.h ('k') | ui/gfx/transform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698