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 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 170 |
142 void PrintTo(const Vector2dF& vector, ::std::ostream* os) { | 171 void PrintTo(const Vector2dF& vector, ::std::ostream* os) { |
143 *os << vector.ToString(); | 172 *os << vector.ToString(); |
144 } | 173 } |
145 | 174 |
146 void PrintTo(const Vector3dF& vector, ::std::ostream* os) { | 175 void PrintTo(const Vector3dF& vector, ::std::ostream* os) { |
147 *os << vector.ToString(); | 176 *os << vector.ToString(); |
148 } | 177 } |
149 | 178 |
150 } // namespace gfx | 179 } // namespace gfx |
OLD | NEW |