OLD | NEW |
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 "Test.h" | 8 #include "Test.h" |
9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
(...skipping 1425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1436 static void test_isRect_open_close(skiatest::Reporter* reporter) { | 1436 static void test_isRect_open_close(skiatest::Reporter* reporter) { |
1437 SkPath path; | 1437 SkPath path; |
1438 bool isClosed; | 1438 bool isClosed; |
1439 | 1439 |
1440 path.moveTo(0, 0); path.lineTo(1, 0); path.lineTo(1, 1); path.lineTo(0, 1); | 1440 path.moveTo(0, 0); path.lineTo(1, 0); path.lineTo(1, 1); path.lineTo(0, 1); |
1441 path.close(); | 1441 path.close(); |
1442 | 1442 |
1443 REPORTER_ASSERT(reporter, path.isRect(NULL, NULL)); | 1443 REPORTER_ASSERT(reporter, path.isRect(NULL, NULL)); |
1444 REPORTER_ASSERT(reporter, path.isRect(&isClosed, NULL)); | 1444 REPORTER_ASSERT(reporter, path.isRect(&isClosed, NULL)); |
1445 REPORTER_ASSERT(reporter, isClosed); | 1445 REPORTER_ASSERT(reporter, isClosed); |
| 1446 REPORTER_ASSERT(reporter, SkPath::kFill_PathAsRect == path.asRect(NULL)); |
1446 } | 1447 } |
1447 | 1448 |
1448 // Simple isRect test is inline TestPath, below. | 1449 // Simple isRect test is inline TestPath, below. |
1449 // test_isRect provides more extensive testing. | 1450 // test_isRect provides more extensive testing. |
1450 static void test_isRect(skiatest::Reporter* reporter) { | 1451 static void test_isRect(skiatest::Reporter* reporter) { |
1451 test_isRect_open_close(reporter); | 1452 test_isRect_open_close(reporter); |
1452 | 1453 |
1453 // passing tests (all moveTo / lineTo... | 1454 // passing tests (all moveTo / lineTo... |
1454 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; | 1455 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; |
1455 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}}; | 1456 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}}; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1553 expected.set(tests[testIndex].fPoints, tests[testIndex].fPointCount)
; | 1554 expected.set(tests[testIndex].fPoints, tests[testIndex].fPointCount)
; |
1554 REPORTER_ASSERT(reporter, path.isRect(&computed)); | 1555 REPORTER_ASSERT(reporter, path.isRect(&computed)); |
1555 REPORTER_ASSERT(reporter, expected == computed); | 1556 REPORTER_ASSERT(reporter, expected == computed); |
1556 | 1557 |
1557 bool isClosed; | 1558 bool isClosed; |
1558 SkPath::Direction direction, cheapDirection; | 1559 SkPath::Direction direction, cheapDirection; |
1559 REPORTER_ASSERT(reporter, path.cheapComputeDirection(&cheapDirection
)); | 1560 REPORTER_ASSERT(reporter, path.cheapComputeDirection(&cheapDirection
)); |
1560 REPORTER_ASSERT(reporter, path.isRect(&isClosed, &direction)); | 1561 REPORTER_ASSERT(reporter, path.isRect(&isClosed, &direction)); |
1561 REPORTER_ASSERT(reporter, isClosed == tests[testIndex].fClose); | 1562 REPORTER_ASSERT(reporter, isClosed == tests[testIndex].fClose); |
1562 REPORTER_ASSERT(reporter, direction == cheapDirection); | 1563 REPORTER_ASSERT(reporter, direction == cheapDirection); |
| 1564 direction = (SkPath::Direction) -1; |
| 1565 if (tests[testIndex].fClose) { |
| 1566 REPORTER_ASSERT(reporter, SkPath::kFill_PathAsRect == path.asRec
t()); |
| 1567 REPORTER_ASSERT(reporter, SkPath::kFill_PathAsRect == path.asRec
t(&direction)); |
| 1568 } else { |
| 1569 REPORTER_ASSERT(reporter, SkPath::kStroke_PathAsRect == path.asR
ect()); |
| 1570 REPORTER_ASSERT(reporter, SkPath::kStroke_PathAsRect == path.asR
ect(&direction)); |
| 1571 } |
| 1572 REPORTER_ASSERT(reporter, direction == cheapDirection); |
1563 } else { | 1573 } else { |
1564 SkRect computed; | 1574 SkRect computed; |
1565 computed.set(123, 456, 789, 1011); | 1575 computed.set(123, 456, 789, 1011); |
1566 REPORTER_ASSERT(reporter, !path.isRect(&computed)); | 1576 REPORTER_ASSERT(reporter, !path.isRect(&computed)); |
1567 REPORTER_ASSERT(reporter, computed.fLeft == 123 && computed.fTop ==
456); | 1577 REPORTER_ASSERT(reporter, computed.fLeft == 123 && computed.fTop ==
456); |
1568 REPORTER_ASSERT(reporter, computed.fRight == 789 && computed.fBottom
== 1011); | 1578 REPORTER_ASSERT(reporter, computed.fRight == 789 && computed.fBottom
== 1011); |
1569 | 1579 |
1570 bool isClosed = (bool) -1; | 1580 bool isClosed = (bool) -1; |
1571 SkPath::Direction direction = (SkPath::Direction) -1; | 1581 SkPath::Direction direction = (SkPath::Direction) -1; |
1572 REPORTER_ASSERT(reporter, !path.isRect(&isClosed, &direction)); | 1582 REPORTER_ASSERT(reporter, !path.isRect(&isClosed, &direction)); |
1573 REPORTER_ASSERT(reporter, isClosed == (bool) -1); | 1583 REPORTER_ASSERT(reporter, isClosed == (bool) -1); |
1574 REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1); | 1584 REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1); |
| 1585 REPORTER_ASSERT(reporter, SkPath::kNone_PathAsRect == path.asRect())
; |
| 1586 REPORTER_ASSERT(reporter, SkPath::kNone_PathAsRect == path.asRect(&d
irection)); |
| 1587 REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1); |
1575 } | 1588 } |
1576 } | 1589 } |
1577 | 1590 |
1578 // fail, close then line | 1591 // fail, close then line |
1579 SkPath path1; | 1592 SkPath path1; |
1580 path1.moveTo(r1[0].fX, r1[0].fY); | 1593 path1.moveTo(r1[0].fX, r1[0].fY); |
1581 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) { | 1594 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) { |
1582 path1.lineTo(r1[index].fX, r1[index].fY); | 1595 path1.lineTo(r1[index].fX, r1[index].fY); |
1583 } | 1596 } |
1584 path1.close(); | 1597 path1.close(); |
(...skipping 1778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3363 test_rrect(reporter); | 3376 test_rrect(reporter); |
3364 test_arc(reporter); | 3377 test_arc(reporter); |
3365 test_arcTo(reporter); | 3378 test_arcTo(reporter); |
3366 test_addPath(reporter); | 3379 test_addPath(reporter); |
3367 test_conicTo_special_case(reporter); | 3380 test_conicTo_special_case(reporter); |
3368 test_get_point(reporter); | 3381 test_get_point(reporter); |
3369 test_contains(reporter); | 3382 test_contains(reporter); |
3370 PathTest_Private::TestPathTo(reporter); | 3383 PathTest_Private::TestPathTo(reporter); |
3371 PathRefTest_Private::TestPathRef(reporter); | 3384 PathRefTest_Private::TestPathRef(reporter); |
3372 } | 3385 } |
OLD | NEW |