5#include "gtest/gtest.h"
7#include "flutter/testing/testing.h"
15TEST(PathTest, CubicPathComponentPolylineDoesNotIncludePointOne) {
18 component.AppendPolylinePoints(1.0f,
polyline);
25TEST(PathTest, PathCreatePolyLineDoesNotDuplicatePoints) {
35 ASSERT_EQ(
polyline.contours.size(), 2u);
36 ASSERT_EQ(
polyline.points->size(), 5u);
37 ASSERT_EQ(
polyline.GetPoint(0).x, 10);
38 ASSERT_EQ(
polyline.GetPoint(1).x, 20);
39 ASSERT_EQ(
polyline.GetPoint(2).x, 30);
40 ASSERT_EQ(
polyline.GetPoint(3).x, 40);
41 ASSERT_EQ(
polyline.GetPoint(4).x, 50);
44TEST(PathTest, PathBuilderSetsCorrectContourPropertiesForAddCommands) {
100 ASSERT_FALSE(
contour.is_closed);
106 .
AddCubicCurve({100, 100}, {100, 50}, {100, 150}, {200, 100})
111 ASSERT_FALSE(
contour.is_closed);
121 ASSERT_FALSE(
contour.is_closed);
125TEST(PathTest, PathCreatePolylineGeneratesCorrectContourData) {
127 .
AddLine({100, 100}, {200, 100})
133 .CreatePolyline(1.0f);
134 ASSERT_EQ(
polyline.points->size(), 6u);
135 ASSERT_EQ(
polyline.contours.size(), 2u);
136 ASSERT_EQ(
polyline.contours[0].is_closed,
false);
137 ASSERT_EQ(
polyline.contours[0].start_index, 0u);
138 ASSERT_EQ(
polyline.contours[1].is_closed,
true);
139 ASSERT_EQ(
polyline.contours[1].start_index, 2u);
142TEST(PathTest, PolylineGetContourPointBoundsReturnsCorrectRanges) {
144 .
AddLine({100, 100}, {200, 100})
150 .CreatePolyline(1.0f);
151 size_t a1, a2, b1, b2;
152 std::tie(a1, a2) =
polyline.GetContourPointBounds(0);
153 std::tie(b1, b2) =
polyline.GetContourPointBounds(1);
160TEST(PathTest, PathAddRectPolylineHasCorrectContourData) {
164 .CreatePolyline(1.0f);
165 ASSERT_EQ(
polyline.contours.size(), 1u);
166 ASSERT_TRUE(
polyline.contours[0].is_closed);
167 ASSERT_EQ(
polyline.contours[0].start_index, 0u);
168 ASSERT_EQ(
polyline.points->size(), 5u);
176TEST(PathTest, PathPolylineDuplicatesAreRemovedForSameContour) {
189 .CreatePolyline(1.0f);
190 ASSERT_EQ(
polyline.contours.size(), 2u);
191 ASSERT_EQ(
polyline.contours[0].start_index, 0u);
192 ASSERT_TRUE(
polyline.contours[0].is_closed);
193 ASSERT_EQ(
polyline.contours[1].start_index, 4u);
194 ASSERT_FALSE(
polyline.contours[1].is_closed);
195 ASSERT_EQ(
polyline.points->size(), 7u);
205TEST(PathTest, PolylineBufferReuse) {
206 auto point_buffer = std::make_unique<std::vector<Point>>();
207 auto point_buffer_address =
reinterpret_cast<uintptr_t
>(point_buffer.get());
214 1.0f, std::move(point_buffer),
215 [point_buffer_address](
217 ASSERT_EQ(point_buffer->size(), 0u);
218 ASSERT_EQ(point_buffer_address,
219 reinterpret_cast<uintptr_t
>(point_buffer.get()));
223TEST(PathTest, PolylineFailsWithNullptrBuffer) {
228 .CreatePolyline(1.0f,
nullptr),
248 ASSERT_TRUE(
path.GetContourComponentAtIndex(0,
contour));
249 ASSERT_TRUE(
path.GetLinearComponentAtIndex(1,
linear));
250 ASSERT_TRUE(
path.GetQuadraticComponentAtIndex(3, quad));
251 ASSERT_TRUE(
path.GetCubicComponentAtIndex(5,
cubic));
258 EXPECT_EQ(quad.
cp,
Point(16, 16));
259 EXPECT_EQ(quad.
p1,
Point(11, 11));
260 EXPECT_EQ(quad.
p2,
Point(21, 21));
268TEST(PathTest, PathBuilderWillComputeBounds) {
270 auto path_1 =
builder.AddLine({0, 0}, {1, 1}).TakePath();
275 auto path_2 =
builder.AddLine({-1, -1}, {1, 1}).TakePath();
282 auto path_3 =
builder.AddLine({0, 0}, {1, 1})
290TEST(PathTest, PathHorizontalLine) {
292 auto path =
builder.HorizontalLineTo(10).TakePath();
301TEST(PathTest, PathVerticalLine) {
317 path.GetQuadraticComponentAtIndex(1, quad);
319 EXPECT_EQ(quad.
p1,
Point(0, 0));
320 EXPECT_EQ(quad.
cp,
Point(10, 10));
321 EXPECT_EQ(quad.
p2,
Point(20, 20));
339TEST(PathTest, BoundingBoxCubic) {
342 builder.AddCubicCurve({120, 160}, {25, 200}, {220, 260}, {220, 40})
344 auto box =
path.GetBoundingBox();
346 ASSERT_TRUE(box.has_value());
350TEST(PathTest, BoundingBoxOfCompositePathIsCorrect) {
354 auto actual =
path.GetBoundingBox();
357 ASSERT_TRUE(actual.has_value());
361TEST(PathTest, ExtremaOfCubicPathComponentIsCorrect) {
363 {-6.2857933, 204.356461},
364 {-4.53997231, 156.552902},
365 {17.0067291, 109.472488}};
368 ASSERT_EQ(
points.size(),
static_cast<size_t>(3));
372TEST(PathTest, PathGetBoundingBoxForCubicWithNoDerivativeRootsIsCorrect) {
375 builder.AddCubicCurve({0, 1}, {2, 3}, {4, 5}, {6, 7});
377 auto actual =
path.GetBoundingBox();
380 ASSERT_TRUE(actual.has_value());
386 ASSERT_EQ(
path.GetComponentCount(), 1u);
389 path.GetContourComponentAtIndex(0, c);
393 ASSERT_TRUE(
polyline.points->empty());
394 ASSERT_TRUE(
polyline.contours.empty());
401 .AddQuadraticCurve({100, 100}, {200, 200}, {300, 300})
402 .AddCubicCurve({300, 300}, {400, 400}, {500, 500}, {600, 600})
405 ASSERT_EQ(
path.GetComponentCount(), 6u);
411 path.EnumerateComponents(
415 ASSERT_EQ(index, 1u);
423 ASSERT_EQ(index, 3u);
424 ASSERT_EQ(quad.p1, p1);
425 ASSERT_EQ(quad.cp, cp);
426 ASSERT_EQ(quad.p2, p2);
433 ASSERT_EQ(index, 5u);
434 ASSERT_EQ(
cubic.p1, p1);
435 ASSERT_EQ(
cubic.cp1, cp1);
436 ASSERT_EQ(
cubic.cp2, cp2);
437 ASSERT_EQ(
cubic.p2, p2);
443 ASSERT_EQ(
contour.destination, p1);
444 }
else if (index == 2u) {
446 ASSERT_EQ(
contour.destination, p1);
447 }
else if (index == 4u) {
449 ASSERT_EQ(
contour.destination, p1);
453 ASSERT_FALSE(
contour.is_closed);
457TEST(PathTest, RepeatCloseDoesNotAddNewLines) {
466 EXPECT_EQ(
path.GetComponentCount(), 5u);
471TEST(PathTest, CloseAfterMoveDoesNotAddNewLines) {
480 EXPECT_EQ(
path.GetComponentCount(), 4u);
485TEST(PathTest, CloseAtOriginDoesNotAddNewLineSegment) {
496 EXPECT_EQ(
path.GetComponentCount(), 6u);
510 auto path_b = path_a;
512 EXPECT_EQ(path_a.GetBoundingBox(), path_b.GetBoundingBox());
513 EXPECT_EQ(path_a.GetFillType(), path_b.GetFillType());
514 EXPECT_EQ(path_a.IsConvex(), path_b.IsConvex());
516 auto poly_a = path_a.CreatePolyline(1.0);
517 auto poly_b = path_b.CreatePolyline(1.0);
519 ASSERT_EQ(poly_a.points->size(), poly_b.points->size());
520 ASSERT_EQ(poly_a.contours.size(), poly_b.contours.size());
522 for (
auto i = 0u;
i < poly_a.points->size();
i++) {
523 EXPECT_EQ((*poly_a.points)[
i], (*poly_b.points)[
i]);
526 for (
auto i = 0u;
i < poly_a.contours.size();
i++) {
527 EXPECT_EQ(poly_a.contours[
i].start_index, poly_b.contours[
i].start_index);
528 EXPECT_EQ(poly_a.contours[
i].start_direction,
529 poly_b.contours[
i].start_direction);
533TEST(PathTest, PathBuilderDoesNotMutateCopiedPaths) {
534 auto test_isolation =
536 bool will_close,
Point mutation_offset,
const std::string& label) {
542 auto verify_path = [](
const Path&
path,
bool is_mutated,
bool is_closed,
548 EXPECT_GE(
path.GetComponentCount(), 3u) << label;
550 EXPECT_EQ(
path.GetComponentCount(), 3u) << label;
556 EXPECT_EQ(
contour.is_closed, is_closed) << label;
573 verify_path(
path1,
false,
false, {},
574 "Initial Path1 state before " + label);
576 for (
int i = 0;
i < 10;
i++) {
579 path,
false,
false, {},
583 verify_path(
path1,
false,
false, {},
584 "Path1 state after subsequent " + label);
587 verify_path(
path1,
false,
false, {},
588 "Path1 state after subsequent " + label +
" and CopyPath");
589 verify_path(
path2,
true, will_close, mutation_offset,
590 "Initial Path2 state with subsequent " + label);
597 false, {},
"SetConvex");
603 false, {},
"SetUnknownConvex");
613 builder.MoveTo({20, 30},
false);
615 false, {},
"Absolute MoveTo");
619 builder.MoveTo({20, 30},
true);
621 false, {},
"Relative MoveTo");
625 builder.LineTo({20, 30},
false);
627 false, {},
"Absolute LineTo");
631 builder.LineTo({20, 30},
true);
633 false, {},
"Relative LineTo");
637 builder.HorizontalLineTo(100,
false);
639 false, {},
"Absolute HorizontalLineTo");
643 builder.HorizontalLineTo(100,
true);
645 false, {},
"Relative HorizontalLineTo");
649 builder.VerticalLineTo(100,
false);
651 false, {},
"Absolute VerticalLineTo");
655 builder.VerticalLineTo(100,
true);
657 false, {},
"Relative VerticalLineTo");
661 builder.QuadraticCurveTo({20, 30}, {30, 20},
false);
663 false, {},
"Absolute QuadraticCurveTo");
667 builder.QuadraticCurveTo({20, 30}, {30, 20},
true);
669 false, {},
"Relative QuadraticCurveTo");
673 builder.CubicCurveTo({20, 30}, {30, 20}, {30, 30},
false);
675 false, {},
"Absolute CubicCurveTo");
679 builder.CubicCurveTo({20, 30}, {30, 20}, {30, 30},
true);
681 false, {},
"Relative CubicCurveTo");
685 builder.AddLine({100, 100}, {150, 100});
687 false, {},
"AddLine");
693 false, {},
"AddRect");
699 false, {},
"AddOval");
703 builder.AddCircle({100, 100}, 20);
705 false, {},
"AddCircle");
712 false, {},
"AddArc");
716 builder.AddQuadraticCurve({100, 100}, {150, 100}, {150, 150});
718 false, {},
"AddQuadraticCurve");
722 builder.AddCubicCurve({100, 100}, {150, 100}, {100, 150}, {150, 150});
724 false, {},
"AddCubicCurve");
730 false, {23, 42},
"Shift");
static const int points[]
PathBuilder & AddRect(Rect rect)
Path TakePath(FillType fill=FillType::kNonZero)
PathBuilder & MoveTo(Point point, bool relative=false)
PathBuilder & AddOval(const Rect &rect)
PathBuilder & AddCircle(const Point ¢er, Scalar radius)
PathBuilder & AddLine(const Point &p1, const Point &p2)
Move to point p1, then insert a line from p1 to p2.
PathBuilder & AddRoundedRect(Rect rect, RoundingRadii radii)
PathBuilder & AddQuadraticCurve(Point p1, Point cp, Point p2)
Move to point p1, then insert a quadradic curve from p1 to p2 with the control point cp.
PathBuilder & AddCubicCurve(Point p1, Point cp1, Point cp2, Point p2)
Move to point p1, then insert a cubic curve from p1 to p2 with control points cp1 and cp2.
Dart_NativeFunction function
#define ASSERT_RECT_NEAR(a, b)
#define ASSERT_POINT_NEAR(a, b)
#define EXPECT_POINT_NEAR(a, b)
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
TEST(AiksCanvasTest, EmptyCullRect)
void MoveTo(PathBuilder *builder, Scalar x, Scalar y)
void LineTo(PathBuilder *builder, Scalar x, Scalar y)
void Close(PathBuilder *builder)
static SkString to_string(int n)
const Path::Polyline & polyline
std::unique_ptr< std::vector< Point > > PointBufferPtr
static constexpr TRect MakeXYWH(Type x, Type y, Type width, Type height)
static constexpr TRect MakeMaximum()
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
#define EXPECT_TRUE(handle)
static sk_sp< SkShader > linear(sk_sp< SkShader > shader)