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

Side by Side Diff: third_party/WebKit/Source/platform/transforms/TransformTestHelper.h

Issue 2265453003: Add platform/transforms pretty printers for logging and testing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update per reviewer comments Created 4 years, 3 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 #ifndef TransformTestHelper_h
6 #define TransformTestHelper_h
7
8 #include "platform/PlatformExport.h"
9 #include "platform/transforms/TransformationMatrix.h"
10 #include "wtf/text/WTFString.h"
11
12 #include <gtest/gtest.h>
13
14 // This file should only be included in test source files.
15
16 #define EXPECT_TRANSFORMS_ALMOST_EQ(a, b) \
17 EXPECT_PRED_FORMAT2(::blink::TransformTestHelper::transformsAreAlmostEqual, a, b)
18 #define ASSERT_TRANSFORMS_ALMOST_EQ(a, b) \
19 ASSERT_PRED_FORMAT2(::blink::TransformTestHelper::transformsAreAlmostEqual, a, b)
20
21 namespace blink {
22 namespace TransformTestHelper {
23
24 // These are helpers for the macros above.
25
26 bool floatsAreAlmostEqual(float a, float b)
27 {
28 // This trick was taken from ui/gfx/test/gfx_util.cc.
29 return ::testing::FloatLE("a", "b", a, b) && ::testing::FloatLE("b", "a", b, a);
30 }
31
32 String transformationMatrixToString(const TransformationMatrix& matrix)
33 {
34 return String::format(
35 "(row-major) [ [ %.2f %.2f %.2f %.2f ] [ %.2f %.2f %.2f %.2f ] [ %.2f %. 2f %.2f %.2f ] [ %.2f %.2f %.2f %.2f ] ]",
36 matrix.m11(), matrix.m21(), matrix.m31(), matrix.m41(),
37 matrix.m12(), matrix.m22(), matrix.m32(), matrix.m42(),
38 matrix.m13(), matrix.m23(), matrix.m33(), matrix.m43(),
39 matrix.m14(), matrix.m24(), matrix.m34(), matrix.m44());
40 }
41
42 const TransformationMatrix& toTransformationMatrix(const TransformationMatrix& m atrix) { return matrix; }
43
44 TransformationMatrix toTransformationMatrix(const SkMatrix44& skMatrix44)
45 {
46 TransformationMatrix matrix;
47 matrix.setMatrix(
48 skMatrix44.getDouble(0, 0),
49 skMatrix44.getDouble(1, 0),
50 skMatrix44.getDouble(2, 0),
51 skMatrix44.getDouble(3, 0),
52 skMatrix44.getDouble(0, 1),
53 skMatrix44.getDouble(1, 1),
54 skMatrix44.getDouble(2, 1),
55 skMatrix44.getDouble(3, 1),
56 skMatrix44.getDouble(0, 2),
57 skMatrix44.getDouble(1, 2),
58 skMatrix44.getDouble(2, 2),
59 skMatrix44.getDouble(3, 2),
60 skMatrix44.getDouble(0, 3),
61 skMatrix44.getDouble(1, 3),
62 skMatrix44.getDouble(2, 3),
63 skMatrix44.getDouble(3, 3));
64 return matrix;
65 }
66
67 template <typename T1, typename T2>
68 ::testing::AssertionResult transformsAreAlmostEqual(
69 const char* lhsExpr, const char* rhsExpr,
70 const T1& lhs, const T2& rhs)
71 {
72 return transformsAreAlmostEqual(lhsExpr, rhsExpr, toTransformationMatrix(lhs ), toTransformationMatrix(rhs));
73 }
74
75 template <>
76 ::testing::AssertionResult transformsAreAlmostEqual(
77 const char* lhsExpr, const char* rhsExpr,
78 const TransformationMatrix& lhs, const TransformationMatrix& rhs)
79 {
80 if (lhs == rhs)
81 return ::testing::AssertionSuccess();
82
83 if (floatsAreAlmostEqual(lhs.m11(), rhs.m11())
84 && floatsAreAlmostEqual(lhs.m12(), rhs.m12())
85 && floatsAreAlmostEqual(lhs.m13(), rhs.m13())
86 && floatsAreAlmostEqual(lhs.m14(), rhs.m14())
87 && floatsAreAlmostEqual(lhs.m21(), rhs.m21())
88 && floatsAreAlmostEqual(lhs.m22(), rhs.m22())
89 && floatsAreAlmostEqual(lhs.m23(), rhs.m23())
90 && floatsAreAlmostEqual(lhs.m24(), rhs.m24())
91 && floatsAreAlmostEqual(lhs.m31(), rhs.m31())
92 && floatsAreAlmostEqual(lhs.m32(), rhs.m32())
93 && floatsAreAlmostEqual(lhs.m33(), rhs.m33())
94 && floatsAreAlmostEqual(lhs.m34(), rhs.m34())
95 && floatsAreAlmostEqual(lhs.m41(), rhs.m41())
96 && floatsAreAlmostEqual(lhs.m42(), rhs.m42())
97 && floatsAreAlmostEqual(lhs.m43(), rhs.m43())
98 && floatsAreAlmostEqual(lhs.m44(), rhs.m44()))
99 return ::testing::AssertionSuccess();
100
101 return ::testing::AssertionFailure()
102 << "Value of: " << rhsExpr
103 << "\n Actual: " << transformationMatrixToString(rhs).ascii().data()
104 << "\nExpected: " << lhsExpr
105 << "\nWhich is: " << transformationMatrixToString(lhs).ascii().data();
106 }
107
108 } // namespace TransformTestHelper
109 } // namespace blink
110
111 #endif // TransformTestHelper_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698