6 #include "flutter/testing/testing.h"
7 #include "gtest/gtest.h"
15 #include "impeller/renderer/testing/mocks.h"
18 std::vector<impeller::Point> a,
19 std::vector<impeller::Point>
b) {
20 if (a.size() !=
b.size()) {
21 return ::testing::AssertionFailure() <<
"Colors length does not match";
23 for (
auto i = 0u; i <
b.size(); i++) {
25 return ::testing::AssertionFailure() <<
"Positions are not equal.";
28 return ::testing::AssertionSuccess();
32 std::vector<impeller::TextureFillVertexShader::PerVertexData> a,
33 std::vector<impeller::TextureFillVertexShader::PerVertexData>
b) {
34 if (a.size() !=
b.size()) {
35 return ::testing::AssertionFailure() <<
"Colors length does not match";
37 for (
auto i = 0u; i <
b.size(); i++) {
38 if (!
PointNear(a[i].position,
b[i].position)) {
39 return ::testing::AssertionFailure() <<
"Positions are not equal.";
41 if (!
PointNear(a[i].texture_coords,
b[i].texture_coords)) {
42 return ::testing::AssertionFailure() <<
"Texture coords are not equal.";
45 return ::testing::AssertionSuccess();
48 #define EXPECT_SOLID_VERTICES_NEAR(a, b) \
49 EXPECT_PRED2(&::SolidVerticesNear, a, b)
50 #define EXPECT_TEXTURE_VERTICES_NEAR(a, b) \
51 EXPECT_PRED2(&::TextureVerticesNear, a, b)
64 return StrokePathGeometry::GenerateSolidStrokeVertices(
71 TEST(EntityGeometryTest, RectGeometryCoversArea) {
73 ASSERT_TRUE(geometry->CoversArea({},
Rect::MakeLTRB(0, 0, 100, 100)));
74 ASSERT_FALSE(geometry->CoversArea({},
Rect::MakeLTRB(-1, 0, 100, 100)));
75 ASSERT_TRUE(geometry->CoversArea({},
Rect::MakeLTRB(1, 1, 100, 100)));
76 ASSERT_TRUE(geometry->CoversArea({},
Rect()));
79 TEST(EntityGeometryTest, FillPathGeometryCoversArea) {
83 ASSERT_TRUE(geometry->CoversArea({},
Rect::MakeLTRB(0, 0, 100, 100)));
84 ASSERT_FALSE(geometry->CoversArea({},
Rect::MakeLTRB(-1, 0, 100, 100)));
85 ASSERT_TRUE(geometry->CoversArea({},
Rect::MakeLTRB(1, 1, 100, 100)));
86 ASSERT_TRUE(geometry->CoversArea({},
Rect()));
89 TEST(EntityGeometryTest, FillPathGeometryCoversAreaNoInnerRect) {
92 ASSERT_FALSE(geometry->CoversArea({},
Rect::MakeLTRB(0, 0, 100, 100)));
93 ASSERT_FALSE(geometry->CoversArea({},
Rect::MakeLTRB(-1, 0, 100, 100)));
94 ASSERT_FALSE(geometry->CoversArea({},
Rect::MakeLTRB(1, 1, 100, 100)));
95 ASSERT_FALSE(geometry->CoversArea({},
Rect()));
98 TEST(EntityGeometryTest, LineGeometryCoverage) {
101 EXPECT_EQ(geometry->GetCoverage({}),
Rect::MakeLTRB(10, 9, 20, 11));
102 EXPECT_TRUE(geometry->CoversArea({},
Rect::MakeLTRB(10, 9, 20, 11)));
107 EXPECT_EQ(geometry->GetCoverage({}),
Rect::MakeLTRB(9, 9, 21, 11));
108 EXPECT_TRUE(geometry->CoversArea({},
Rect::MakeLTRB(9, 9, 21, 11)));
113 EXPECT_EQ(geometry->GetCoverage({}),
Rect::MakeLTRB(9, 10, 11, 20));
114 EXPECT_TRUE(geometry->CoversArea({},
Rect::MakeLTRB(9, 10, 11, 20)));
119 EXPECT_EQ(geometry->GetCoverage({}),
Rect::MakeLTRB(9, 9, 11, 21));
120 EXPECT_TRUE(geometry->CoversArea({},
Rect::MakeLTRB(9, 9, 11, 21)));
124 TEST(EntityGeometryTest, RoundRectGeometryCoversArea) {
127 EXPECT_FALSE(geometry->CoversArea({},
Rect::MakeLTRB(15, 15, 85, 85)));
128 EXPECT_TRUE(geometry->CoversArea({},
Rect::MakeLTRB(20, 20, 80, 80)));
129 EXPECT_TRUE(geometry->CoversArea({},
Rect::MakeLTRB(30, 1, 70, 99)));
130 EXPECT_TRUE(geometry->CoversArea({},
Rect::MakeLTRB(1, 30, 99, 70)));
133 TEST(EntityGeometryTest, GeometryResultHasReasonableDefaults) {
140 TEST(EntityGeometryTest, AlphaCoverageStrokePaths) {
static std::unique_ptr< Geometry > MakeStrokePath(const Path &path, Scalar stroke_width=0.0, Scalar miter_limit=4.0, Cap stroke_cap=Cap::kButt, Join stroke_join=Join::kMiter)
static std::unique_ptr< Geometry > MakeFillPath(const Path &path, std::optional< Rect > inner_rect=std::nullopt)
static std::unique_ptr< Geometry > MakeLine(const Point &p0, const Point &p1, Scalar width, Cap cap)
static std::unique_ptr< Geometry > MakeRect(const Rect &rect)
static std::unique_ptr< Geometry > MakeRoundRect(const Rect &rect, const Size &radii)
static std::vector< Point > GenerateSolidStrokeVertices(const Path::Polyline &polyline, Scalar stroke_width, Scalar miter_limit, Join stroke_join, Cap stroke_cap, Scalar scale)
Path TakePath(FillType fill=FillType::kNonZero)
PathBuilder & AddRect(const Rect &rect)
inline ::testing::AssertionResult SolidVerticesNear(std::vector< impeller::Point > a, std::vector< impeller::Point > b)
inline ::testing::AssertionResult TextureVerticesNear(std::vector< impeller::TextureFillVertexShader::PerVertexData > a, std::vector< impeller::TextureFillVertexShader::PerVertexData > b)
inline ::testing::AssertionResult PointNear(impeller::Point a, impeller::Point b)
TEST(AllocationSizeTest, CanCreateTypedAllocations)
const Scalar stroke_width
const Path::Polyline & polyline
@ kNormal
The geometry has no overlapping triangles.
A 4x4 matrix using column-major storage.
static constexpr Matrix MakeScale(const Vector3 &s)
constexpr static TRect MakeLTRB(Type left, Type top, Type right, Type bottom)