OLD | NEW |
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/axis_transform2d.h" |
11 #include "ui/gfx/geometry/box_f.h" | 12 #include "ui/gfx/geometry/box_f.h" |
12 #include "ui/gfx/geometry/point.h" | 13 #include "ui/gfx/geometry/point.h" |
13 #include "ui/gfx/geometry/point3_f.h" | 14 #include "ui/gfx/geometry/point3_f.h" |
14 #include "ui/gfx/geometry/point_f.h" | 15 #include "ui/gfx/geometry/point_f.h" |
15 #include "ui/gfx/geometry/quad_f.h" | 16 #include "ui/gfx/geometry/quad_f.h" |
16 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
17 #include "ui/gfx/geometry/rect_f.h" | 18 #include "ui/gfx/geometry/rect_f.h" |
18 #include "ui/gfx/geometry/scroll_offset.h" | 19 #include "ui/gfx/geometry/scroll_offset.h" |
19 #include "ui/gfx/geometry/size.h" | 20 #include "ui/gfx/geometry/size.h" |
20 #include "ui/gfx/geometry/size_f.h" | 21 #include "ui/gfx/geometry/size_f.h" |
(...skipping 17 matching lines...) Expand all Loading... |
38 } | 39 } |
39 | 40 |
40 bool FloatAlmostEqual(float a, float b) { | 41 bool FloatAlmostEqual(float a, float b) { |
41 // FloatLE is the gtest predicate for less than or almost equal to. | 42 // FloatLE is the gtest predicate for less than or almost equal to. |
42 return ::testing::FloatLE("a", "b", a, b) && | 43 return ::testing::FloatLE("a", "b", a, b) && |
43 ::testing::FloatLE("b", "a", b, a); | 44 ::testing::FloatLE("b", "a", b, a); |
44 } | 45 } |
45 | 46 |
46 } // namespace | 47 } // namespace |
47 | 48 |
| 49 ::testing::AssertionResult AssertAxisTransform2dFloatEqual( |
| 50 const char* lhs_expr, |
| 51 const char* rhs_expr, |
| 52 const AxisTransform2d& lhs, |
| 53 const AxisTransform2d& rhs) { |
| 54 if (FloatAlmostEqual(lhs.scale(), rhs.scale()) && |
| 55 FloatAlmostEqual(lhs.translation().x(), rhs.translation().x()) && |
| 56 FloatAlmostEqual(lhs.translation().y(), rhs.translation().y())) { |
| 57 return ::testing::AssertionSuccess(); |
| 58 } |
| 59 return ::testing::AssertionFailure() |
| 60 << "Value of: " << rhs_expr << "\n Actual: " << rhs.ToString() |
| 61 << "\nExpected: " << lhs_expr << "\nWhich is: " << lhs.ToString(); |
| 62 } |
| 63 |
48 ::testing::AssertionResult AssertBoxFloatEqual(const char* lhs_expr, | 64 ::testing::AssertionResult AssertBoxFloatEqual(const char* lhs_expr, |
49 const char* rhs_expr, | 65 const char* rhs_expr, |
50 const BoxF& lhs, | 66 const BoxF& lhs, |
51 const BoxF& rhs) { | 67 const BoxF& rhs) { |
52 if (FloatAlmostEqual(lhs.x(), rhs.x()) && | 68 if (FloatAlmostEqual(lhs.x(), rhs.x()) && |
53 FloatAlmostEqual(lhs.y(), rhs.y()) && | 69 FloatAlmostEqual(lhs.y(), rhs.y()) && |
54 FloatAlmostEqual(lhs.z(), rhs.z()) && | 70 FloatAlmostEqual(lhs.z(), rhs.z()) && |
55 FloatAlmostEqual(lhs.width(), rhs.width()) && | 71 FloatAlmostEqual(lhs.width(), rhs.width()) && |
56 FloatAlmostEqual(lhs.height(), rhs.height()) && | 72 FloatAlmostEqual(lhs.height(), rhs.height()) && |
57 FloatAlmostEqual(lhs.depth(), rhs.depth())) { | 73 FloatAlmostEqual(lhs.depth(), rhs.depth())) { |
58 return ::testing::AssertionSuccess(); | 74 return ::testing::AssertionSuccess(); |
59 } | 75 } |
60 return ::testing::AssertionFailure() << "Value of: " << rhs_expr | 76 return ::testing::AssertionFailure() << "Value of: " << rhs_expr |
61 << "\n Actual: " << rhs.ToString() | 77 << "\n Actual: " << rhs.ToString() |
62 << "\nExpected: " << lhs_expr | 78 << "\nExpected: " << lhs_expr |
63 << "\nWhich is: " << lhs.ToString(); | 79 << "\nWhich is: " << lhs.ToString(); |
64 } | 80 } |
65 | 81 |
| 82 ::testing::AssertionResult AssertPointFloatEqual(const char* lhs_expr, |
| 83 const char* rhs_expr, |
| 84 const PointF& lhs, |
| 85 const PointF& rhs) { |
| 86 if (FloatAlmostEqual(lhs.x(), rhs.x()) && |
| 87 FloatAlmostEqual(lhs.y(), rhs.y())) { |
| 88 return ::testing::AssertionSuccess(); |
| 89 } |
| 90 return ::testing::AssertionFailure() |
| 91 << "Value of: " << rhs_expr << "\n Actual: " << rhs.ToString() |
| 92 << "\nExpected: " << lhs_expr << "\nWhich is: " << lhs.ToString(); |
| 93 } |
| 94 |
66 ::testing::AssertionResult AssertRectFloatEqual(const char* lhs_expr, | 95 ::testing::AssertionResult AssertRectFloatEqual(const char* lhs_expr, |
67 const char* rhs_expr, | 96 const char* rhs_expr, |
68 const RectF& lhs, | 97 const RectF& lhs, |
69 const RectF& rhs) { | 98 const RectF& rhs) { |
70 if (FloatAlmostEqual(lhs.x(), rhs.x()) && | 99 if (FloatAlmostEqual(lhs.x(), rhs.x()) && |
71 FloatAlmostEqual(lhs.y(), rhs.y()) && | 100 FloatAlmostEqual(lhs.y(), rhs.y()) && |
72 FloatAlmostEqual(lhs.width(), rhs.width()) && | 101 FloatAlmostEqual(lhs.width(), rhs.width()) && |
73 FloatAlmostEqual(lhs.height(), rhs.height())) { | 102 FloatAlmostEqual(lhs.height(), rhs.height())) { |
74 return ::testing::AssertionSuccess(); | 103 return ::testing::AssertionSuccess(); |
75 } | 104 } |
76 return ::testing::AssertionFailure() | 105 return ::testing::AssertionFailure() |
77 << "Value of: " << rhs_expr << "\n Actual: " << rhs.ToString() | 106 << "Value of: " << rhs_expr << "\n Actual: " << rhs.ToString() |
78 << "\nExpected: " << lhs_expr << "\nWhich is: " << lhs.ToString(); | 107 << "\nExpected: " << lhs_expr << "\nWhich is: " << lhs.ToString(); |
79 } | 108 } |
80 | 109 |
81 ::testing::AssertionResult AssertSkColorsEqual(const char* lhs_expr, | 110 ::testing::AssertionResult AssertSkColorsEqual(const char* lhs_expr, |
82 const char* rhs_expr, | 111 const char* rhs_expr, |
83 SkColor lhs, | 112 SkColor lhs, |
84 SkColor rhs) { | 113 SkColor rhs) { |
85 if (lhs == rhs) { | 114 if (lhs == rhs) { |
86 return ::testing::AssertionSuccess(); | 115 return ::testing::AssertionSuccess(); |
87 } | 116 } |
88 return ::testing::AssertionFailure() << "Value of: " << rhs_expr | 117 return ::testing::AssertionFailure() << "Value of: " << rhs_expr |
89 << "\n Actual: " << ColorAsString(rhs) | 118 << "\n Actual: " << ColorAsString(rhs) |
90 << "\nExpected: " << lhs_expr | 119 << "\nExpected: " << lhs_expr |
91 << "\nWhich is: " << ColorAsString(lhs); | 120 << "\nWhich is: " << ColorAsString(lhs); |
92 } | 121 } |
93 | 122 |
| 123 void PrintTo(const AxisTransform2d& transform, ::std::ostream* os) { |
| 124 *os << transform.ToString(); |
| 125 } |
| 126 |
94 void PrintTo(const BoxF& box, ::std::ostream* os) { | 127 void PrintTo(const BoxF& box, ::std::ostream* os) { |
95 *os << box.ToString(); | 128 *os << box.ToString(); |
96 } | 129 } |
97 | 130 |
98 void PrintTo(const Point& point, ::std::ostream* os) { | 131 void PrintTo(const Point& point, ::std::ostream* os) { |
99 *os << point.ToString(); | 132 *os << point.ToString(); |
100 } | 133 } |
101 | 134 |
102 void PrintTo(const Point3F& point, ::std::ostream* os) { | 135 void PrintTo(const Point3F& point, ::std::ostream* os) { |
103 *os << point.ToString(); | 136 *os << point.ToString(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 174 |
142 void PrintTo(const Vector2dF& vector, ::std::ostream* os) { | 175 void PrintTo(const Vector2dF& vector, ::std::ostream* os) { |
143 *os << vector.ToString(); | 176 *os << vector.ToString(); |
144 } | 177 } |
145 | 178 |
146 void PrintTo(const Vector3dF& vector, ::std::ostream* os) { | 179 void PrintTo(const Vector3dF& vector, ::std::ostream* os) { |
147 *os << vector.ToString(); | 180 *os << vector.ToString(); |
148 } | 181 } |
149 | 182 |
150 } // namespace gfx | 183 } // namespace gfx |
OLD | NEW |