5 #ifndef FLUTTER_IMPELLER_GEOMETRY_GEOMETRY_ASSERTS_H_
6 #define FLUTTER_IMPELLER_GEOMETRY_GEOMETRY_ASSERTS_H_
11 #include "gtest/gtest.h"
19 static const double epsilon = 1e-3;
20 return (a > (
b - epsilon)) && (a < (
b + epsilon));
42 return equal ? ::testing::AssertionSuccess()
43 : ::testing::AssertionFailure()
44 <<
"Matrixes are not equal " << a <<
" " <<
b;
52 return equal ? ::testing::AssertionSuccess()
53 : ::testing::AssertionFailure() <<
"Quaternions are not equal.";
62 return equal ? ::testing::AssertionSuccess()
63 : ::testing::AssertionFailure()
64 <<
"Rects are not equal (" << a <<
" " <<
b <<
")";
72 return equal ? ::testing::AssertionSuccess()
73 : ::testing::AssertionFailure() <<
"Colors are not equal.";
80 return equal ? ::testing::AssertionSuccess()
81 : ::testing::AssertionFailure()
82 <<
"Points are not equal (" << a <<
" " <<
b <<
").";
90 return equal ? ::testing::AssertionSuccess()
91 : ::testing::AssertionFailure() <<
"Vector3s are not equal.";
99 return equal ? ::testing::AssertionSuccess()
100 : ::testing::AssertionFailure() <<
"Vector4s are not equal.";
106 return equal ? ::testing::AssertionSuccess()
107 : ::testing::AssertionFailure() <<
"Sizes are not equal.";
110 inline ::testing::AssertionResult
Array4Near(std::array<uint8_t, 4> a,
111 std::array<uint8_t, 4>
b) {
115 return equal ? ::testing::AssertionSuccess()
116 : ::testing::AssertionFailure() <<
"Arrays are not equal.";
120 std::vector<uint8_t> a,
121 std::vector<impeller::Color>
b) {
122 if (a.size() !=
b.size() * 4) {
123 return ::testing::AssertionFailure()
124 <<
"Color buffer length does not match";
126 for (
auto i = 0u; i <
b.size(); i++) {
127 auto right =
b[i].Premultiply().ToR8G8B8A8();
133 ::testing::AssertionFailure() <<
"Color buffers are not equal.";
136 return ::testing::AssertionSuccess();
139 inline ::testing::AssertionResult
ColorsNear(std::vector<impeller::Color> a,
140 std::vector<impeller::Color>
b) {
141 if (a.size() !=
b.size()) {
142 return ::testing::AssertionFailure() <<
"Colors length does not match";
144 for (
auto i = 0u; i <
b.size(); i++) {
150 ::testing::AssertionFailure() <<
"Colors are not equal.";
153 return ::testing::AssertionSuccess();
156 #define ASSERT_MATRIX_NEAR(a, b) ASSERT_PRED2(&::MatrixNear, a, b)
157 #define ASSERT_QUATERNION_NEAR(a, b) ASSERT_PRED2(&::QuaternionNear, a, b)
158 #define ASSERT_RECT_NEAR(a, b) ASSERT_PRED2(&::RectNear, a, b)
159 #define ASSERT_COLOR_NEAR(a, b) ASSERT_PRED2(&::ColorNear, a, b)
160 #define ASSERT_POINT_NEAR(a, b) ASSERT_PRED2(&::PointNear, a, b)
161 #define ASSERT_VECTOR3_NEAR(a, b) ASSERT_PRED2(&::Vector3Near, a, b)
162 #define ASSERT_VECTOR4_NEAR(a, b) ASSERT_PRED2(&::Vector4Near, a, b)
163 #define ASSERT_SIZE_NEAR(a, b) ASSERT_PRED2(&::SizeNear, a, b)
164 #define ASSERT_ARRAY_4_NEAR(a, b) ASSERT_PRED2(&::Array4Near, a, b)
165 #define ASSERT_COLOR_BUFFER_NEAR(a, b) ASSERT_PRED2(&::ColorBufferNear, a, b)
166 #define ASSERT_COLORS_NEAR(a, b) ASSERT_PRED2(&::ColorsNear, a, b)
168 #define EXPECT_MATRIX_NEAR(a, b) EXPECT_PRED2(&::MatrixNear, a, b)
169 #define EXPECT_QUATERNION_NEAR(a, b) EXPECT_PRED2(&::QuaternionNear, a, b)
170 #define EXPECT_RECT_NEAR(a, b) EXPECT_PRED2(&::RectNear, a, b)
171 #define EXPECT_COLOR_NEAR(a, b) EXPECT_PRED2(&::ColorNear, a, b)
172 #define EXPECT_POINT_NEAR(a, b) EXPECT_PRED2(&::PointNear, a, b)
173 #define EXPECT_VECTOR3_NEAR(a, b) EXPECT_PRED2(&::Vector3Near, a, b)
174 #define EXPECT_VECTOR4_NEAR(a, b) EXPECT_PRED2(&::Vector4Near, a, b)
175 #define EXPECT_SIZE_NEAR(a, b) EXPECT_PRED2(&::SizeNear, a, b)
176 #define EXPECT_ARRAY_4_NEAR(a, b) EXPECT_PRED2(&::Array4Near, a, b)
177 #define EXPECT_COLOR_BUFFER_NEAR(a, b) EXPECT_PRED2(&::ColorBufferNear, a, b)
178 #define EXPECT_COLORS_NEAR(a, b) EXPECT_PRED2(&::ColorsNear, a, b)
180 #endif // FLUTTER_IMPELLER_GEOMETRY_GEOMETRY_ASSERTS_H_