blob: c91186005a0d28f4e2badd083b570a4997f1456e [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@android.combbff1d52009-06-05 16:21:03 +00008#include "Test.h"
9#include "SkParsePath.h"
10
11static void test_to_from(skiatest::Reporter* reporter, const SkPath& path) {
12 SkString str, str2;
13 SkParsePath::ToSVGString(path, &str);
14
15 SkPath path2;
16 bool success = SkParsePath::FromSVGString(str.c_str(), &path2);
17 REPORTER_ASSERT(reporter, success);
18
19 SkParsePath::ToSVGString(path2, &str2);
20 REPORTER_ASSERT(reporter, str == str2);
21#if 0 // closed paths are not equal, the iter explicitly gives the closing
22 // edge, even if it is not in the path.
23 REPORTER_ASSERT(reporter, path == path2);
24 if (path != path2) {
25 SkDebugf("str1=%s\nstr2=%s\n", str.c_str(), str2.c_str());
26 }
27#endif
28}
29
caryclark@google.com42639cd2012-06-06 12:03:39 +000030static struct {
31 const char* fStr;
32 const SkRect fBounds;
33} gRec[] = {
34 { "", { 0, 0, 0, 0 } },
35 { "M0,0L10,10", { 0, 0, SkIntToScalar(10), SkIntToScalar(10) } },
36 { "M-5.5,-0.5 Q 0 0 6,6.50",
37 { SkFloatToScalar(-5.5f), SkFloatToScalar(-0.5f),
38 SkFloatToScalar(6), SkFloatToScalar(6.5f) } }
39};
40
reed@android.combbff1d52009-06-05 16:21:03 +000041static void TestParsePath(skiatest::Reporter* reporter) {
reed@android.combbff1d52009-06-05 16:21:03 +000042 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
43 SkPath path;
44 bool success = SkParsePath::FromSVGString(gRec[i].fStr, &path);
45 REPORTER_ASSERT(reporter, success);
46 const SkRect& expectedBounds = gRec[i].fBounds;
47 const SkRect& pathBounds = path.getBounds();
48 REPORTER_ASSERT(reporter, expectedBounds == pathBounds);
49
50 test_to_from(reporter, path);
51 }
rmistry@google.comd6176b02012-08-23 18:14:13 +000052
reed@android.combbff1d52009-06-05 16:21:03 +000053 SkRect r;
caryclark@google.com42639cd2012-06-06 12:03:39 +000054 r.set(0, 0, SkFloatToScalar(10), SkFloatToScalar(10.5f));
reed@android.combbff1d52009-06-05 16:21:03 +000055 SkPath p;
56 p.addRect(r);
57 test_to_from(reporter, p);
58 p.addOval(r);
59 test_to_from(reporter, p);
caryclark@google.com42639cd2012-06-06 12:03:39 +000060 p.addRoundRect(r, SkFloatToScalar(4), SkFloatToScalar(4.5f));
reed@android.combbff1d52009-06-05 16:21:03 +000061 test_to_from(reporter, p);
62}
63
64#include "TestClassDef.h"
65DEFINE_TESTCLASS("ParsePath", ParsePathClass, TestParsePath)