Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
++
  • Loading branch information
jonahwilliams committed Nov 17, 2022
commit ad2913d9d34f7a6fb65d57fb79ee5fb5e0ab964f
9 changes: 6 additions & 3 deletions impeller/geometry/geometry_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1761,7 +1761,7 @@ TEST(GeometryTest, Gradient) {

auto gradient = CreateGradientBuffer(colors, stops);

ASSERT_COLOR_BUFFER_NEAR(gradient.color_bytes, colors);
ASSERT_COLORS_NEAR(gradient.colors, colors);
ASSERT_EQ(gradient.texture_size, 2u);
}

Expand All @@ -1784,7 +1784,7 @@ TEST(GeometryTest, Gradient) {

auto gradient = CreateGradientBuffer(colors, stops);

ASSERT_COLOR_BUFFER_NEAR(gradient.color_bytes, colors);
ASSERT_COLORS_NEAR(gradient.colors, colors);
ASSERT_EQ(gradient.texture_size, 4u);
}

Expand All @@ -1802,7 +1802,7 @@ TEST(GeometryTest, Gradient) {
Color::lerp(Color::Blue(), Color::Green(), 0.6666),
Color::Green(),
};
ASSERT_COLOR_BUFFER_NEAR(gradient.color_bytes, lerped_colors);
ASSERT_COLORS_NEAR(gradient.colors, lerped_colors);
ASSERT_EQ(gradient.texture_size, 5u);
}

Expand All @@ -1818,6 +1818,9 @@ TEST(GeometryTest, Gradient) {
auto gradient = CreateGradientBuffer(colors, stops);

ASSERT_EQ(gradient.texture_size, 1024u);
// Large gradients use color buffer for textures
ASSERT_EQ(gradient.colors.size(), 0u);
ASSERT_EQ(gradient.color_bytes.size(), 1024u * 4);
}
}

Expand Down
18 changes: 18 additions & 0 deletions impeller/geometry/geometry_unittests.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,23 @@ inline ::testing::AssertionResult ColorBufferNear(
return ::testing::AssertionSuccess();
}

inline ::testing::AssertionResult ColorsNear(std::vector<impeller::Color> a,
std::vector<impeller::Color> b) {
if (a.size() != b.size()) {
return ::testing::AssertionFailure() << "Colors length does not match";
}
for (auto i = 0u; i < b.size(); i++) {
auto equal =
NumberNear(a[i].red, b[i].red) && NumberNear(a[i].green, b[i].green) &&
NumberNear(a[i].blue, b[i].blue) && NumberNear(a[i].alpha, b[i].alpha);

if (!equal) {
::testing::AssertionFailure() << "Colors are not equal.";
}
}
return ::testing::AssertionSuccess();
}

#define ASSERT_MATRIX_NEAR(a, b) ASSERT_PRED2(&::MatrixNear, a, b)
#define ASSERT_QUATERNION_NEAR(a, b) ASSERT_PRED2(&::QuaternionNear, a, b)
#define ASSERT_RECT_NEAR(a, b) ASSERT_PRED2(&::RectNear, a, b)
Expand All @@ -141,3 +158,4 @@ inline ::testing::AssertionResult ColorBufferNear(
#define ASSERT_SIZE_NEAR(a, b) ASSERT_PRED2(&::SizeNear, a, b)
#define ASSERT_ARRAY_4_NEAR(a, b) ASSERT_PRED2(&::Array4Near, a, b)
#define ASSERT_COLOR_BUFFER_NEAR(a, b) ASSERT_PRED2(&::ColorBufferNear, a, b)
#define ASSERT_COLORS_NEAR(a, b) ASSERT_PRED2(&::ColorsNear, a, b)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline at EOF.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done