Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Functions
geometry_unittests.cc File Reference
#include <memory>
#include "flutter/testing/testing.h"
#include "impeller/entity/contents/content_context.h"
#include "impeller/entity/geometry/geometry.h"
#include "impeller/entity/geometry/stroke_path_geometry.h"
#include "impeller/geometry/geometry_asserts.h"
#include "impeller/geometry/path_builder.h"
#include "impeller/renderer/testing/mocks.h"

Go to the source code of this file.

Classes

class  impeller::ImpellerEntityUnitTestAccessor
 

Namespaces

namespace  impeller
 
namespace  impeller::testing
 

Macros

#define EXPECT_SOLID_VERTICES_NEAR(a, b)    EXPECT_PRED2(&::SolidVerticesNear, a, b)
 
#define EXPECT_TEXTURE_VERTICES_NEAR(a, b)    EXPECT_PRED2(&::TextureVerticesNear, a, b)
 

Functions

inline ::testing::AssertionResult SolidVerticesNear (std::vector< impeller::SolidFillVertexShader::PerVertexData > a, std::vector< impeller::SolidFillVertexShader::PerVertexData > b)
 
inline ::testing::AssertionResult TextureVerticesNear (std::vector< impeller::TextureFillVertexShader::PerVertexData > a, std::vector< impeller::TextureFillVertexShader::PerVertexData > b)
 
 impeller::testing::TEST (EntityGeometryTest, RectGeometryCoversArea)
 
 impeller::testing::TEST (EntityGeometryTest, FillPathGeometryCoversArea)
 
 impeller::testing::TEST (EntityGeometryTest, FillPathGeometryCoversAreaNoInnerRect)
 
 impeller::testing::TEST (EntityGeometryTest, LineGeometryCoverage)
 
 impeller::testing::TEST (EntityGeometryTest, RoundRectGeometryCoversArea)
 
 impeller::testing::TEST (EntityGeometryTest, GeometryResultHasReasonableDefaults)
 

Macro Definition Documentation

◆ EXPECT_SOLID_VERTICES_NEAR

#define EXPECT_SOLID_VERTICES_NEAR (   a,
  b 
)     EXPECT_PRED2(&::SolidVerticesNear, a, b)

Definition at line 45 of file geometry_unittests.cc.

50 {
51
52class ImpellerEntityUnitTestAccessor {
53 public:
54 static std::vector<SolidFillVertexShader::PerVertexData>
55 GenerateSolidStrokeVertices(const Path::Polyline& polyline,
56 Scalar stroke_width,
57 Scalar miter_limit,
58 Join stroke_join,
59 Cap stroke_cap,
60 Scalar scale) {
61 return StrokePathGeometry::GenerateSolidStrokeVertices(
62 polyline, stroke_width, miter_limit, stroke_join, stroke_cap, scale);
63 }
64};
65
66namespace testing {
67
68TEST(EntityGeometryTest, RectGeometryCoversArea) {
69 auto geometry = Geometry::MakeRect(Rect::MakeLTRB(0, 0, 100, 100));
70 ASSERT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(0, 0, 100, 100)));
71 ASSERT_FALSE(geometry->CoversArea({}, Rect::MakeLTRB(-1, 0, 100, 100)));
72 ASSERT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(1, 1, 100, 100)));
73 ASSERT_TRUE(geometry->CoversArea({}, Rect()));
74}
75
76TEST(EntityGeometryTest, FillPathGeometryCoversArea) {
77 auto path = PathBuilder{}.AddRect(Rect::MakeLTRB(0, 0, 100, 100)).TakePath();
78 auto geometry = Geometry::MakeFillPath(
79 path, /* inner rect */ Rect::MakeLTRB(0, 0, 100, 100));
80 ASSERT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(0, 0, 100, 100)));
81 ASSERT_FALSE(geometry->CoversArea({}, Rect::MakeLTRB(-1, 0, 100, 100)));
82 ASSERT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(1, 1, 100, 100)));
83 ASSERT_TRUE(geometry->CoversArea({}, Rect()));
84}
85
86TEST(EntityGeometryTest, FillPathGeometryCoversAreaNoInnerRect) {
87 auto path = PathBuilder{}.AddRect(Rect::MakeLTRB(0, 0, 100, 100)).TakePath();
88 auto geometry = Geometry::MakeFillPath(path);
89 ASSERT_FALSE(geometry->CoversArea({}, Rect::MakeLTRB(0, 0, 100, 100)));
90 ASSERT_FALSE(geometry->CoversArea({}, Rect::MakeLTRB(-1, 0, 100, 100)));
91 ASSERT_FALSE(geometry->CoversArea({}, Rect::MakeLTRB(1, 1, 100, 100)));
92 ASSERT_FALSE(geometry->CoversArea({}, Rect()));
93}
94
95TEST(EntityGeometryTest, LineGeometryCoverage) {
96 {
97 auto geometry = Geometry::MakeLine({10, 10}, {20, 10}, 2, Cap::kButt);
98 EXPECT_EQ(geometry->GetCoverage({}), Rect::MakeLTRB(10, 9, 20, 11));
99 EXPECT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(10, 9, 20, 11)));
100 }
101
102 {
103 auto geometry = Geometry::MakeLine({10, 10}, {20, 10}, 2, Cap::kSquare);
104 EXPECT_EQ(geometry->GetCoverage({}), Rect::MakeLTRB(9, 9, 21, 11));
105 EXPECT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(9, 9, 21, 11)));
106 }
107
108 {
109 auto geometry = Geometry::MakeLine({10, 10}, {10, 20}, 2, Cap::kButt);
110 EXPECT_EQ(geometry->GetCoverage({}), Rect::MakeLTRB(9, 10, 11, 20));
111 EXPECT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(9, 10, 11, 20)));
112 }
113
114 {
115 auto geometry = Geometry::MakeLine({10, 10}, {10, 20}, 2, Cap::kSquare);
116 EXPECT_EQ(geometry->GetCoverage({}), Rect::MakeLTRB(9, 9, 11, 21));
117 EXPECT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(9, 9, 11, 21)));
118 }
119}
120
121TEST(EntityGeometryTest, RoundRectGeometryCoversArea) {
122 auto geometry =
123 Geometry::MakeRoundRect(Rect::MakeLTRB(0, 0, 100, 100), Size(20, 20));
124 EXPECT_FALSE(geometry->CoversArea({}, Rect::MakeLTRB(15, 15, 85, 85)));
125 EXPECT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(20, 20, 80, 80)));
126 EXPECT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(30, 1, 70, 99)));
127 EXPECT_TRUE(geometry->CoversArea({}, Rect::MakeLTRB(1, 30, 99, 70)));
128}
129
130TEST(EntityGeometryTest, GeometryResultHasReasonableDefaults) {
131 GeometryResult result;
132 EXPECT_EQ(result.type, PrimitiveType::kTriangleStrip);
133 EXPECT_EQ(result.transform, Matrix());
134 EXPECT_EQ(result.mode, GeometryResult::Mode::kNormal);
135}
136
137} // namespace testing
138} // namespace impeller
#define TEST(S, s, D, expected)
GAsyncResult * result
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57
TRect< Scalar > Rect
Definition rect.h:746
TSize< Scalar > Size
Definition size.h:137
const Scalar stroke_width
const Scalar scale
const Path::Polyline & polyline
#define EXPECT_TRUE(handle)
Definition unit_test.h:685

◆ EXPECT_TEXTURE_VERTICES_NEAR

#define EXPECT_TEXTURE_VERTICES_NEAR (   a,
  b 
)     EXPECT_PRED2(&::TextureVerticesNear, a, b)

Definition at line 47 of file geometry_unittests.cc.

Function Documentation

◆ SolidVerticesNear()

inline ::testing::AssertionResult SolidVerticesNear ( std::vector< impeller::SolidFillVertexShader::PerVertexData >  a,
std::vector< impeller::SolidFillVertexShader::PerVertexData >  b 
)

Definition at line 14 of file geometry_unittests.cc.

16 {
17 if (a.size() != b.size()) {
18 return ::testing::AssertionFailure() << "Colors length does not match";
19 }
20 for (auto i = 0u; i < b.size(); i++) {
21 if (!PointNear(a[i].position, b[i].position)) {
22 return ::testing::AssertionFailure() << "Positions are not equal.";
23 }
24 }
25 return ::testing::AssertionSuccess();
26}
static bool b
struct MyStruct a[10]
inline ::testing::AssertionResult PointNear(impeller::Point a, impeller::Point b)

◆ TextureVerticesNear()

inline ::testing::AssertionResult TextureVerticesNear ( std::vector< impeller::TextureFillVertexShader::PerVertexData >  a,
std::vector< impeller::TextureFillVertexShader::PerVertexData >  b 
)

Definition at line 28 of file geometry_unittests.cc.

30 {
31 if (a.size() != b.size()) {
32 return ::testing::AssertionFailure() << "Colors length does not match";
33 }
34 for (auto i = 0u; i < b.size(); i++) {
35 if (!PointNear(a[i].position, b[i].position)) {
36 return ::testing::AssertionFailure() << "Positions are not equal.";
37 }
38 if (!PointNear(a[i].texture_coords, b[i].texture_coords)) {
39 return ::testing::AssertionFailure() << "Texture coords are not equal.";
40 }
41 }
42 return ::testing::AssertionSuccess();
43}