epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame^] | 7 | |
reed@android.com | bbff1d5 | 2009-06-05 16:21:03 +0000 | [diff] [blame] | 8 | #include "Test.h" |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame^] | 9 | #include "TestClassDef.h" |
reed@android.com | bbff1d5 | 2009-06-05 16:21:03 +0000 | [diff] [blame] | 10 | #include "SkParsePath.h" |
| 11 | |
| 12 | static void test_to_from(skiatest::Reporter* reporter, const SkPath& path) { |
| 13 | SkString str, str2; |
| 14 | SkParsePath::ToSVGString(path, &str); |
| 15 | |
| 16 | SkPath path2; |
| 17 | bool success = SkParsePath::FromSVGString(str.c_str(), &path2); |
| 18 | REPORTER_ASSERT(reporter, success); |
| 19 | |
| 20 | SkParsePath::ToSVGString(path2, &str2); |
| 21 | REPORTER_ASSERT(reporter, str == str2); |
| 22 | #if 0 // closed paths are not equal, the iter explicitly gives the closing |
| 23 | // edge, even if it is not in the path. |
| 24 | REPORTER_ASSERT(reporter, path == path2); |
| 25 | if (path != path2) { |
| 26 | SkDebugf("str1=%s\nstr2=%s\n", str.c_str(), str2.c_str()); |
| 27 | } |
| 28 | #endif |
| 29 | } |
| 30 | |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 31 | static struct { |
| 32 | const char* fStr; |
| 33 | const SkRect fBounds; |
| 34 | } gRec[] = { |
| 35 | { "", { 0, 0, 0, 0 } }, |
| 36 | { "M0,0L10,10", { 0, 0, SkIntToScalar(10), SkIntToScalar(10) } }, |
| 37 | { "M-5.5,-0.5 Q 0 0 6,6.50", |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 38 | { -5.5f, -0.5f, |
| 39 | 6, 6.5f } } |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 40 | }; |
| 41 | |
tfarina@chromium.org | e4fafb1 | 2013-12-12 21:11:12 +0000 | [diff] [blame^] | 42 | DEF_TEST(ParsePath, reporter) { |
reed@android.com | bbff1d5 | 2009-06-05 16:21:03 +0000 | [diff] [blame] | 43 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) { |
| 44 | SkPath path; |
| 45 | bool success = SkParsePath::FromSVGString(gRec[i].fStr, &path); |
| 46 | REPORTER_ASSERT(reporter, success); |
| 47 | const SkRect& expectedBounds = gRec[i].fBounds; |
| 48 | const SkRect& pathBounds = path.getBounds(); |
| 49 | REPORTER_ASSERT(reporter, expectedBounds == pathBounds); |
| 50 | |
| 51 | test_to_from(reporter, path); |
| 52 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 53 | |
reed@android.com | bbff1d5 | 2009-06-05 16:21:03 +0000 | [diff] [blame] | 54 | SkRect r; |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 55 | r.set(0, 0, 10, 10.5f); |
reed@android.com | bbff1d5 | 2009-06-05 16:21:03 +0000 | [diff] [blame] | 56 | SkPath p; |
| 57 | p.addRect(r); |
| 58 | test_to_from(reporter, p); |
| 59 | p.addOval(r); |
| 60 | test_to_from(reporter, p); |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 61 | p.addRoundRect(r, 4, 4.5f); |
reed@android.com | bbff1d5 | 2009-06-05 16:21:03 +0000 | [diff] [blame] | 62 | test_to_from(reporter, p); |
| 63 | } |