10 #include "gtest/gtest.h"
18 static const double epsilon = 1e-3;
19 return (a > (b - epsilon)) && (a < (b + epsilon));
41 return equal ? ::testing::AssertionSuccess()
42 : ::testing::AssertionFailure() <<
"Matrixes are not equal.";
50 return equal ? ::testing::AssertionSuccess()
51 : ::testing::AssertionFailure() <<
"Quaternions are not equal.";
60 return equal ? ::testing::AssertionSuccess()
61 : ::testing::AssertionFailure() <<
"Rects are not equal.";
69 return equal ? ::testing::AssertionSuccess()
70 : ::testing::AssertionFailure() <<
"Colors are not equal.";
77 return equal ? ::testing::AssertionSuccess()
78 : ::testing::AssertionFailure() <<
"Points are not equal.";
86 return equal ? ::testing::AssertionSuccess()
87 : ::testing::AssertionFailure() <<
"Vector3s are not equal.";
95 return equal ? ::testing::AssertionSuccess()
96 : ::testing::AssertionFailure() <<
"Vector4s are not equal.";
102 return equal ? ::testing::AssertionSuccess()
103 : ::testing::AssertionFailure() <<
"Sizes are not equal.";
106 inline ::testing::AssertionResult
Array4Near(std::array<uint8_t, 4> a,
107 std::array<uint8_t, 4> b) {
111 return equal ? ::testing::AssertionSuccess()
112 : ::testing::AssertionFailure() <<
"Arrays are not equal.";
116 std::vector<uint8_t> a,
117 std::vector<impeller::Color> b) {
118 if (a.size() != b.size() * 4) {
119 return ::testing::AssertionFailure()
120 <<
"Color buffer length does not match";
122 for (
auto i = 0u; i < b.size(); i++) {
123 auto right = b[i].Premultiply().ToR8G8B8A8();
129 ::testing::AssertionFailure() <<
"Color buffers are not equal.";
132 return ::testing::AssertionSuccess();
135 inline ::testing::AssertionResult
ColorsNear(std::vector<impeller::Color> a,
136 std::vector<impeller::Color> b) {
137 if (a.size() != b.size()) {
138 return ::testing::AssertionFailure() <<
"Colors length does not match";
140 for (
auto i = 0u; i < b.size(); i++) {
146 ::testing::AssertionFailure() <<
"Colors are not equal.";
149 return ::testing::AssertionSuccess();
152 #define ASSERT_MATRIX_NEAR(a, b) ASSERT_PRED2(&::MatrixNear, a, b)
153 #define ASSERT_QUATERNION_NEAR(a, b) ASSERT_PRED2(&::QuaternionNear, a, b)
154 #define ASSERT_RECT_NEAR(a, b) ASSERT_PRED2(&::RectNear, a, b)
155 #define ASSERT_COLOR_NEAR(a, b) ASSERT_PRED2(&::ColorNear, a, b)
156 #define ASSERT_POINT_NEAR(a, b) ASSERT_PRED2(&::PointNear, a, b)
157 #define ASSERT_VECTOR3_NEAR(a, b) ASSERT_PRED2(&::Vector3Near, a, b)
158 #define ASSERT_VECTOR4_NEAR(a, b) ASSERT_PRED2(&::Vector4Near, a, b)
159 #define ASSERT_SIZE_NEAR(a, b) ASSERT_PRED2(&::SizeNear, a, b)
160 #define ASSERT_ARRAY_4_NEAR(a, b) ASSERT_PRED2(&::Array4Near, a, b)
161 #define ASSERT_COLOR_BUFFER_NEAR(a, b) ASSERT_PRED2(&::ColorBufferNear, a, b)
162 #define ASSERT_COLORS_NEAR(a, b) ASSERT_PRED2(&::ColorsNear, a, b)