Home | History | Annotate | Download | only in tests
      1 #include "Test.h"
      2 #include "SkParsePath.h"
      3 
      4 static void test_to_from(skiatest::Reporter* reporter, const SkPath& path) {
      5     SkString str, str2;
      6     SkParsePath::ToSVGString(path, &str);
      7 
      8     SkPath path2;
      9     bool success = SkParsePath::FromSVGString(str.c_str(), &path2);
     10     REPORTER_ASSERT(reporter, success);
     11 
     12     SkParsePath::ToSVGString(path2, &str2);
     13     REPORTER_ASSERT(reporter, str == str2);
     14 #if 0 // closed paths are not equal, the iter explicitly gives the closing
     15       // edge, even if it is not in the path.
     16     REPORTER_ASSERT(reporter, path == path2);
     17     if (path != path2) {
     18         SkDebugf("str1=%s\nstr2=%s\n", str.c_str(), str2.c_str());
     19     }
     20 #endif
     21 }
     22 
     23 static void TestParsePath(skiatest::Reporter* reporter) {
     24     static const struct {
     25         const char* fStr;
     26         SkRect      fBounds;
     27     } gRec[] = {
     28         { "", { 0, 0, 0, 0 } },
     29         { "M0,0L10,10", { 0, 0, SkIntToScalar(10), SkIntToScalar(10) } },
     30         { "M-5.5,-0.5 Q 0 0 6,6.50",
     31             { SkFloatToScalar(-5.5f), SkFloatToScalar(-0.5f),
     32               SkFloatToScalar(6), SkFloatToScalar(6.5f) } }
     33     };
     34 
     35     for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
     36         SkPath  path;
     37         bool success = SkParsePath::FromSVGString(gRec[i].fStr, &path);
     38         REPORTER_ASSERT(reporter, success);
     39         const SkRect& expectedBounds = gRec[i].fBounds;
     40         const SkRect& pathBounds = path.getBounds();
     41         REPORTER_ASSERT(reporter, expectedBounds == pathBounds);
     42 
     43         test_to_from(reporter, path);
     44     }
     45 
     46     SkRect r;
     47     r.set(0, 0, SkFloatToScalar(10), SkFloatToScalar(10.5));
     48     SkPath p;
     49     p.addRect(r);
     50     test_to_from(reporter, p);
     51     p.addOval(r);
     52     test_to_from(reporter, p);
     53     p.addRoundRect(r, SkFloatToScalar(4), SkFloatToScalar(4.5));
     54     test_to_from(reporter, p);
     55 }
     56 
     57 #include "TestClassDef.h"
     58 DEFINE_TESTCLASS("ParsePath", ParsePathClass, TestParsePath)
     59