blob: 383ad030c57b7e0fef154f6e04731082cebaf576 [file] [log] [blame]
reed@android.com3abec1d2009-03-02 05:36:20 +00001#include "Test.h"
2#include "SkPath.h"
3
4static void TestPath(skiatest::Reporter* reporter) {
5 SkPath p, p2;
6 SkRect bounds, bounds2;
7
8 REPORTER_ASSERT(reporter, p.isEmpty());
9 REPORTER_ASSERT(reporter, p.getFillType() == SkPath::kWinding_FillType);
10 REPORTER_ASSERT(reporter, !p.isInverseFillType());
11 REPORTER_ASSERT(reporter, p == p2);
12 REPORTER_ASSERT(reporter, !(p != p2));
13
14 // initialize bounds to not-empty
15 bounds.set(0, 0, SK_Scalar1, SK_Scalar1);
16 p.computeBounds(&bounds, SkPath::kFast_BoundsType);
17 REPORTER_ASSERT(reporter, bounds.isEmpty());
18
19 bounds.set(0, 0, SK_Scalar1, SK_Scalar1);
20 p.addRect(bounds);
21 bounds2.setEmpty();
22 p.computeBounds(&bounds2, SkPath::kFast_BoundsType);
23 REPORTER_ASSERT(reporter, bounds == bounds2);
24
25 REPORTER_ASSERT(reporter, p != p2);
26 REPORTER_ASSERT(reporter, !(p == p2));
27
28 // does getPoints return the right result
29 REPORTER_ASSERT(reporter, p.getPoints(NULL, 5) == 4);
30 SkPoint pts[4];
31 int count = p.getPoints(pts, 4);
32 REPORTER_ASSERT(reporter, count == 4);
33 bounds2.set(pts, 4);
34 REPORTER_ASSERT(reporter, bounds == bounds2);
35
36 bounds.offset(SK_Scalar1*3, SK_Scalar1*4);
37 p.offset(SK_Scalar1*3, SK_Scalar1*4);
38 p.computeBounds(&bounds2, SkPath::kFast_BoundsType);
39 REPORTER_ASSERT(reporter, bounds == bounds2);
40
41#if 0 // isRect needs to be implemented
42 REPORTER_ASSERT(reporter, p.isRect(NULL));
43 bounds.setEmpty();
44 REPORTER_ASSERT(reporter, p.isRect(&bounds2));
45 REPORTER_ASSERT(reporter, bounds == bounds2);
46
47 // now force p to not be a rect
48 bounds.set(0, 0, SK_Scalar1/2, SK_Scalar1/2);
49 p.addRect(bounds);
50 REPORTER_ASSERT(reporter, !p.isRect(NULL));
51#endif
52
53 SkPoint pt;
54
55 p.moveTo(SK_Scalar1, 0);
56 p.getLastPt(&pt);
57 REPORTER_ASSERT(reporter, pt.fX == SK_Scalar1);
58}
59
60#include "TestClassDef.h"
61DEFINE_TESTCLASS("Path", PathTestClass, TestPath)