6#include "gtest/gtest.h"
14static constexpr float kTrivial = 8.f * std::numeric_limits<float>::epsilon();
16int TestSizeF(
const SizeF&
s) {
26 EXPECT_EQ(
width,
a.width());
80 a.SetToMax(
Size(2, 4));
82 a.SetToMax(
Size(3, 5));
84 a.SetToMax(
Size(4, 2));
86 a.SetToMax(
Size(8, 10));
89 a.SetToMin(
Size(9, 11));
91 a.SetToMin(
Size(8, 10));
93 a.SetToMin(
Size(11, 9));
95 a.SetToMin(
Size(7, 11));
97 a.SetToMin(
Size(3, 5));
106 a.SetToMax(
SizeF(2.5f, 4.5f));
108 a.SetToMax(
SizeF(3.5f, 5.5f));
110 a.SetToMax(
SizeF(4.5f, 2.5f));
112 a.SetToMax(
SizeF(8.5f, 10.5f));
115 a.SetToMin(
SizeF(9.5f, 11.5f));
117 a.SetToMin(
SizeF(8.5f, 10.5f));
119 a.SetToMin(
SizeF(11.5f, 9.5f));
121 a.SetToMin(
SizeF(7.5f, 11.5f));
123 a.SetToMin(
SizeF(3.5f, 5.5f));
133TEST(SizeTest, IntegerOverflow) {
137 Size max_size(int_max, int_max);
138 Size min_size(int_min, int_min);
142 test.Enlarge(int_max, int_max);
143 EXPECT_EQ(
test, max_size);
146 test.Enlarge(int_min, int_min);
147 EXPECT_EQ(
test, min_size);
150 test.Enlarge(int_max, int_max);
151 EXPECT_EQ(
test, max_size);
154 test.Enlarge(int_min, int_min);
155 EXPECT_EQ(
test, min_size);
159TEST(SizeTest, TrivialDimensionTests) {
160 const float clearly_trivial = kTrivial / 2.f;
161 const float massize_dimension = 4e13f;
171 EXPECT_FALSE(
test.IsEmpty());
173 test.SetSize(clearly_trivial, 1.f);
176 test.SetSize(.01f, clearly_trivial);
179 test.SetSize(0.f, 0.f);
182 test.SetSize(.01f, .01f);
183 EXPECT_FALSE(
test.IsEmpty());
186 test.set_width(clearly_trivial);
189 test.set_width(massize_dimension);
190 test.set_height(clearly_trivial);
193 test.set_width(clearly_trivial);
194 test.set_height(massize_dimension);
198 EXPECT_FALSE(
test.IsEmpty());
204 const float clearly_trivial = kTrivial / 2.f;
205 const float nearly_trivial = kTrivial * 1.5f;
209 EXPECT_FLOAT_EQ(0.f,
test.width());
210 EXPECT_FLOAT_EQ(1.f,
test.height());
212 test.SetSize(.01f, clearly_trivial);
214 EXPECT_FLOAT_EQ(.01f,
test.width());
215 EXPECT_FLOAT_EQ(0.f,
test.height());
217 test.SetSize(nearly_trivial, nearly_trivial);
219 EXPECT_FLOAT_EQ(nearly_trivial,
test.width());
220 EXPECT_FLOAT_EQ(nearly_trivial,
test.height());
224 EXPECT_FLOAT_EQ(0.f,
test.width());
225 EXPECT_FLOAT_EQ(0.f,
test.height());
227 test.SetSize(0.f, 0.f);
228 test.Enlarge(clearly_trivial, clearly_trivial);
229 test.Enlarge(clearly_trivial, clearly_trivial);
230 test.Enlarge(clearly_trivial, clearly_trivial);
237TEST(SizeTest, ConsistentClamping) {
240 resized.
SetSize(kTrivial, 0.f);
241 EXPECT_EQ(
SizeF(kTrivial, 0.f), resized);
243 resized.
SetSize(0.f, kTrivial);
244 EXPECT_EQ(
SizeF(0.f, kTrivial), resized);
250 EXPECT_EQ(2 *
sizeof(
float),
sizeof(
SizeF));
253TEST(SizeTest, OperatorAddSub) {
258 EXPECT_EQ(
Size(150, 30), lhs);
261 EXPECT_EQ(
Size(150, 30), lhs + rhs);
265 EXPECT_EQ(
Size(50, 10), lhs);
268 EXPECT_EQ(
Size(50, 10), lhs - rhs);
271TEST(SizeTest, OperatorAddOverflow) {
274 Size lhs(int_max, int_max);
275 Size rhs(int_max, int_max);
276 EXPECT_EQ(
Size(int_max, int_max), lhs + rhs);
279TEST(SizeTest, OperatorSubClampAtZero) {
282 EXPECT_EQ(
Size(0, 0), lhs - rhs);
285 rhs =
Size(100, 100);
287 EXPECT_EQ(
Size(0, 0), lhs);
290TEST(SizeTest, OperatorCompare) {
295 EXPECT_FALSE(lhs == rhs);
299 EXPECT_FALSE(lhs != rhs);
void SetSize(float width, float height)
static float max(float r, float g, float b)
static float min(float r, float g, float b)
Size ToFlooredSize(const SizeF &size)
Size ToCeiledSize(const SizeF &size)
Size ToRoundedSize(const SizeF &size)
TEST(PointTest, ToPointF)
static std::string ToString(CompilerBackend::Type type)
bool EMSCRIPTEN_KEEPALIVE IsEmpty(const SkPath &path)
#define EXPECT_TRUE(handle)