Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
ParsePathTest.cpp File Reference
#include "include/core/SkPath.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
#include "include/core/SkString.h"
#include "include/utils/SkParsePath.h"
#include "tests/Test.h"
#include <array>
#include <cstddef>

Go to the source code of this file.

Functions

static void test_to_from (skiatest::Reporter *reporter, const SkPath &path)
 
 DEF_TEST (ParsePath, reporter)
 
 DEF_TEST (ParsePath_invalid, r)
 
 DEF_TEST (ParsePathOptionalCommand, r)
 
 DEF_TEST (ParsePathArcFlags, r)
 

Variables

struct { 
 
   const char *   fStr 
 
   const SkRect   fBounds 
 
gRec [] 
 

Function Documentation

◆ DEF_TEST() [1/4]

DEF_TEST ( ParsePath  ,
reporter   
)

Definition at line 50 of file ParsePathTest.cpp.

50 {
51 for (size_t i = 0; i < std::size(gRec); i++) {
53 bool success = SkParsePath::FromSVGString(gRec[i].fStr, &path);
54 REPORTER_ASSERT(reporter, success);
55 const SkRect& expectedBounds = gRec[i].fBounds;
56 const SkRect& pathBounds = path.getBounds();
57 REPORTER_ASSERT(reporter, expectedBounds == pathBounds);
58
60 }
61
62 SkRect r;
63 r.setLTRB(0, 0, 10, 10.5f);
64 SkPath p;
65 p.addRect(r);
67 p.addOval(r);
69 p.addRoundRect(r, 4, 4.5f);
71}
reporter
static void test_to_from(skiatest::Reporter *reporter, const SkPath &path)
static struct @441 gRec[]
const char * fStr
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
static bool FromSVGString(const char str[], SkPath *)
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
void setLTRB(float left, float top, float right, float bottom)
Definition SkRect.h:865

◆ DEF_TEST() [2/4]

DEF_TEST ( ParsePath_invalid  ,
 
)

Definition at line 73 of file ParsePathTest.cpp.

73 {
75 // This is an invalid SVG string, but the test verifies that we do not
76 // crash.
77 bool success = SkParsePath::FromSVGString("M 5", &path);
78 REPORTER_ASSERT(r, !success);
79}

◆ DEF_TEST() [3/4]

DEF_TEST ( ParsePathArcFlags  ,
 
)

Definition at line 121 of file ParsePathTest.cpp.

121 {
122 const char* arcs = "M10 10a2.143 2.143 0 100-4.285 2.143 2.143 0 000 4.286";
123 SkPath path;
125 // Arcs decompose to two conics.
126 REPORTER_ASSERT(r, path.countVerbs() == 5);
127 // One for move, 2x per conic.
128 REPORTER_ASSERT(r, path.countPoints() == 9);
129}

◆ DEF_TEST() [4/4]

DEF_TEST ( ParsePathOptionalCommand  ,
 
)

Definition at line 81 of file ParsePathTest.cpp.

81 {
82 struct {
83 const char* fStr;
84 int fVerbs;
85 int fPoints;
86 } gTests[] = {
87 { "", 0, 0 },
88
89 { "H100 200 ", 3, 3 },
90 { "H-100-200", 3, 3 },
91 { "H+100+200", 3, 3 },
92 { "H.10.20" , 3, 3 },
93 { "H-.10-.20", 3, 3 },
94 { "H+.10+.20", 3, 3 },
95
96 { "L100 100 200 200" , 3, 3 },
97 { "L-100-100-200-200", 3, 3 },
98 { "L+100+100+200+200", 3, 3 },
99 { "L.10.10.20.20" , 3, 3 },
100 { "L-.10-.10-.20-.20", 3, 3 },
101 { "L+.10+.10+.20+.20", 3, 3 },
102
103 { "C100 100 200 200 300 300 400 400 500 500 600 600" , 3, 7 },
104 { "C100-100-200-200-300-300-400-400-500-500-600-600" , 3, 7 },
105 { "C100+100+200+200+300+300+400+400+500+500+600+600" , 3, 7 },
106 { "C.10.10.20.20.30.30.40.40.50.50.60.60" , 3, 7 },
107 { "C-.10-.10-.20-.20-.30-.30-.40-.40-.50-.50-.60-.60", 3, 7 },
108 { "C+.10+.10+.20+.20+.30+.30+.40+.40+.50+.50+.60+.60", 3, 7 },
109
110 { "c-1.49.71-2.12 2.5-1.4 4 .71 1.49 2.5 2.12 4 1.4z", 4, 7 },
111 };
112
113 SkPath path;
114 for (size_t i = 0; i < std::size(gTests); ++i) {
116 REPORTER_ASSERT(r, path.countVerbs() == gTests[i].fVerbs);
117 REPORTER_ASSERT(r, path.countPoints() == gTests[i].fPoints);
118 }
119}
static const TestCase gTests[]

◆ test_to_from()

static void test_to_from ( skiatest::Reporter reporter,
const SkPath path 
)
static

Definition at line 18 of file ParsePathTest.cpp.

18 {
20
22 bool success = SkParsePath::FromSVGString(str.c_str(), &path2);
23 REPORTER_ASSERT(reporter, success);
24
26 REPORTER_ASSERT(reporter, str == str2);
27#if 0 // closed paths are not equal, the iter explicitly gives the closing
28 // edge, even if it is not in the path.
30 if (path != path2) {
31 SkDebugf("str1=%s\nstr2=%s\n", str.c_str(), str2.c_str());
32 }
33#endif
34}
static SkPath path2()
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static SkString ToSVGString(const SkPath &, PathEncoding=PathEncoding::Absolute)
const char * c_str() const
Definition SkString.h:133

Variable Documentation

◆ fBounds

const SkRect fBounds

Definition at line 38 of file ParsePathTest.cpp.

◆ fStr

const char* fStr

Definition at line 37 of file ParsePathTest.cpp.

◆ [struct]

struct { ... } gRec[]
Initial value:
= {
{ "M1,1 l-2.58-2.828-3.82-0.113, 1.9-3.3223-1.08-3.6702, 3.75,0.7744,3.16-2.1551,"
"0.42,3.8008,3.02,2.3384-3.48,1.574-1.29,3.601z",
{ -5.39999962f, -10.3142f, 5.77000046f, 1.f } },
{ "", { 0, 0, 0, 0 } },
{ "M0,0L10,10", { 0, 0, SkIntToScalar(10), SkIntToScalar(10) } },
{ "M-5.5,-0.5 Q 0 0 6,6.50",
{ -5.5f, -0.5f,
6, 6.5f } }
}
#define SkIntToScalar(x)
Definition SkScalar.h:57