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