Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(297)

Side by Side Diff: tests/PathTest.cpp

Issue 351833003: add path dump test (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: generate a single line feed (or none if empty) Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkPath.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkCanvas.h" 8 #include "SkCanvas.h"
9 #include "SkPaint.h" 9 #include "SkPaint.h"
10 #include "SkParse.h" 10 #include "SkParse.h"
11 #include "SkParsePath.h" 11 #include "SkParsePath.h"
12 #include "SkPath.h" 12 #include "SkPath.h"
13 #include "SkPathEffect.h" 13 #include "SkPathEffect.h"
14 #include "SkRRect.h" 14 #include "SkRRect.h"
15 #include "SkRandom.h" 15 #include "SkRandom.h"
16 #include "SkReader32.h" 16 #include "SkReader32.h"
17 #include "SkSize.h" 17 #include "SkSize.h"
18 #include "SkStream.h"
18 #include "SkSurface.h" 19 #include "SkSurface.h"
19 #include "SkTypes.h" 20 #include "SkTypes.h"
20 #include "SkWriter32.h" 21 #include "SkWriter32.h"
21 #include "Test.h" 22 #include "Test.h"
22 23
23 static void make_path_crbug364224(SkPath* path) { 24 static void make_path_crbug364224(SkPath* path) {
24 path->reset(); 25 path->reset();
25 path->moveTo(3.747501373f, 2.724499941f); 26 path->moveTo(3.747501373f, 2.724499941f);
26 path->lineTo(3.747501373f, 3.75f); 27 path->lineTo(3.747501373f, 3.75f);
27 path->cubicTo(3.747501373f, 3.88774991f, 3.635501385f, 4.0f, 3.497501373f, 4 .0f); 28 path->cubicTo(3.747501373f, 3.88774991f, 3.635501385f, 4.0f, 3.497501373f, 4 .0f);
(...skipping 3329 matching lines...) Expand 10 before | Expand all | Expand 10 after
3357 a.reset(); 3358 a.reset();
3358 REPORTER_ASSERT(reporter, a == b); 3359 REPORTER_ASSERT(reporter, a == b);
3359 a.lineTo(1, 1); 3360 a.lineTo(1, 1);
3360 b.lineTo(1, 2); 3361 b.lineTo(1, 2);
3361 REPORTER_ASSERT(reporter, a != b); 3362 REPORTER_ASSERT(reporter, a != b);
3362 a.reset(); 3363 a.reset();
3363 a.lineTo(1, 2); 3364 a.lineTo(1, 2);
3364 REPORTER_ASSERT(reporter, a == b); 3365 REPORTER_ASSERT(reporter, a == b);
3365 } 3366 }
3366 3367
3368 static void compare_dump(skiatest::Reporter* reporter, const SkPath& path, bool force,
3369 const char* str) {
3370 SkDynamicMemoryWStream wStream;
3371 path.dump(&wStream, force);
3372 SkAutoDataUnref data(wStream.copyToData());
3373 REPORTER_ASSERT(reporter, data->size() == strlen(str));
3374 REPORTER_ASSERT(reporter, !memcmp(data->data(), str, strlen(str)));
3375 }
3376
3377 static void test_dump(skiatest::Reporter* reporter) {
3378 SkPath p;
3379 compare_dump(reporter, p, false, "");
3380 compare_dump(reporter, p, true, "");
3381 p.moveTo(1, 2);
3382 p.lineTo(3, 4);
3383 compare_dump(reporter, p, false, "path.moveTo(1, 2);\n"
3384 "path.lineTo(3, 4);\n");
3385 compare_dump(reporter, p, true, "path.moveTo(1, 2);\n"
3386 "path.lineTo(3, 4);\n"
3387 "path.lineTo(1, 2);\n"
3388 "path.close();\n");
3389 p.reset();
3390 p.moveTo(1, 2);
3391 p.quadTo(3, 4, 5, 6);
3392 compare_dump(reporter, p, false, "path.moveTo(1, 2);\n"
3393 "path.quadTo(3, 4, 5, 6);\n");
3394 p.reset();
3395 p.moveTo(1, 2);
3396 p.conicTo(3, 4, 5, 6, 0.5f);
3397 compare_dump(reporter, p, false, "path.moveTo(1, 2);\n"
3398 "path.conicTo(3, 4, 5, 6, 0.5f);\n");
3399 p.reset();
3400 p.moveTo(1, 2);
3401 p.cubicTo(3, 4, 5, 6, 7, 8);
3402 compare_dump(reporter, p, false, "path.moveTo(1, 2);\n"
3403 "path.cubicTo(3, 4, 5, 6, 7, 8);\n");
3404 }
3405
3367 class PathTest_Private { 3406 class PathTest_Private {
3368 public: 3407 public:
3369 static void TestPathTo(skiatest::Reporter* reporter) { 3408 static void TestPathTo(skiatest::Reporter* reporter) {
3370 SkPath p, q; 3409 SkPath p, q;
3371 p.lineTo(4, 4); 3410 p.lineTo(4, 4);
3372 p.reversePathTo(q); 3411 p.reversePathTo(q);
3373 check_path_is_line(reporter, &p, 4, 4); 3412 check_path_is_line(reporter, &p, 4, 4);
3374 q.moveTo(-4, -4); 3413 q.moveTo(-4, -4);
3375 p.reversePathTo(q); 3414 p.reversePathTo(q);
3376 check_path_is_line(reporter, &p, 4, 4); 3415 check_path_is_line(reporter, &p, 4, 4);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
3506 test_addPathMode(reporter, false, true); 3545 test_addPathMode(reporter, false, true);
3507 test_addPathMode(reporter, true, true); 3546 test_addPathMode(reporter, true, true);
3508 test_extendClosedPath(reporter); 3547 test_extendClosedPath(reporter);
3509 test_addEmptyPath(reporter, SkPath::kExtend_AddPathMode); 3548 test_addEmptyPath(reporter, SkPath::kExtend_AddPathMode);
3510 test_addEmptyPath(reporter, SkPath::kAppend_AddPathMode); 3549 test_addEmptyPath(reporter, SkPath::kAppend_AddPathMode);
3511 test_conicTo_special_case(reporter); 3550 test_conicTo_special_case(reporter);
3512 test_get_point(reporter); 3551 test_get_point(reporter);
3513 test_contains(reporter); 3552 test_contains(reporter);
3514 PathTest_Private::TestPathTo(reporter); 3553 PathTest_Private::TestPathTo(reporter);
3515 PathRefTest_Private::TestPathRef(reporter); 3554 PathRefTest_Private::TestPathRef(reporter);
3555 test_dump(reporter);
3516 } 3556 }
OLDNEW
« no previous file with comments | « src/core/SkPath.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698