• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "Test.h"
2 #include "SkPath.h"
3 
check_convex_bounds(skiatest::Reporter * reporter,const SkPath & p,const SkRect & bounds)4 static void check_convex_bounds(skiatest::Reporter* reporter, const SkPath& p,
5                                 const SkRect& bounds) {
6     REPORTER_ASSERT(reporter, p.isConvex());
7     REPORTER_ASSERT(reporter, p.getBounds() == bounds);
8 
9     SkPath p2(p);
10     REPORTER_ASSERT(reporter, p2.isConvex());
11     REPORTER_ASSERT(reporter, p2.getBounds() == bounds);
12 
13     SkPath other;
14     other.swap(p2);
15     REPORTER_ASSERT(reporter, other.isConvex());
16     REPORTER_ASSERT(reporter, other.getBounds() == bounds);
17 }
18 
TestPath(skiatest::Reporter * reporter)19 static void TestPath(skiatest::Reporter* reporter) {
20     SkPath  p, p2;
21     SkRect  bounds, bounds2;
22 
23     REPORTER_ASSERT(reporter, p.isEmpty());
24     REPORTER_ASSERT(reporter, !p.isConvex());
25     REPORTER_ASSERT(reporter, p.getFillType() == SkPath::kWinding_FillType);
26     REPORTER_ASSERT(reporter, !p.isInverseFillType());
27     REPORTER_ASSERT(reporter, p == p2);
28     REPORTER_ASSERT(reporter, !(p != p2));
29 
30     REPORTER_ASSERT(reporter, p.getBounds().isEmpty());
31 
32     bounds.set(0, 0, SK_Scalar1, SK_Scalar1);
33 
34     p.setIsConvex(false);
35     p.addRoundRect(bounds, SK_Scalar1, SK_Scalar1);
36     check_convex_bounds(reporter, p, bounds);
37 
38     p.reset();
39     p.setIsConvex(false);
40     p.addOval(bounds);
41     check_convex_bounds(reporter, p, bounds);
42 
43     p.reset();
44     p.setIsConvex(false);
45     p.addRect(bounds);
46     check_convex_bounds(reporter, p, bounds);
47 
48     REPORTER_ASSERT(reporter, p != p2);
49     REPORTER_ASSERT(reporter, !(p == p2));
50 
51     // does getPoints return the right result
52     REPORTER_ASSERT(reporter, p.getPoints(NULL, 5) == 4);
53     SkPoint pts[4];
54     int count = p.getPoints(pts, 4);
55     REPORTER_ASSERT(reporter, count == 4);
56     bounds2.set(pts, 4);
57     REPORTER_ASSERT(reporter, bounds == bounds2);
58 
59     bounds.offset(SK_Scalar1*3, SK_Scalar1*4);
60     p.offset(SK_Scalar1*3, SK_Scalar1*4);
61     REPORTER_ASSERT(reporter, bounds == p.getBounds());
62 
63 #if 0 // isRect needs to be implemented
64     REPORTER_ASSERT(reporter, p.isRect(NULL));
65     bounds.setEmpty();
66     REPORTER_ASSERT(reporter, p.isRect(&bounds2));
67     REPORTER_ASSERT(reporter, bounds == bounds2);
68 
69     // now force p to not be a rect
70     bounds.set(0, 0, SK_Scalar1/2, SK_Scalar1/2);
71     p.addRect(bounds);
72     REPORTER_ASSERT(reporter, !p.isRect(NULL));
73 #endif
74 
75     SkPoint pt;
76 
77     p.moveTo(SK_Scalar1, 0);
78     p.getLastPt(&pt);
79     REPORTER_ASSERT(reporter, pt.fX == SK_Scalar1);
80 }
81 
82 #include "TestClassDef.h"
83 DEFINE_TESTCLASS("Path", PathTestClass, TestPath)
84