OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 "SkMatrix.h" | 8 #include "SkMatrix.h" |
9 #include "SkRRect.h" | 9 #include "SkRRect.h" |
10 #include "Test.h" | 10 #include "Test.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 const SkScalar rad = 40; | 40 const SkScalar rad = 40; |
41 rr.setRectXY(bounds, rad, rad); | 41 rr.setRectXY(bounds, rad, rad); |
42 | 42 |
43 SkRRect other; | 43 SkRRect other; |
44 SkMatrix matrix; | 44 SkMatrix matrix; |
45 matrix.setScale(0, 1); | 45 matrix.setScale(0, 1); |
46 rr.transform(matrix, &other); | 46 rr.transform(matrix, &other); |
47 REPORTER_ASSERT(reporter, SkRRect::kEmpty_Type == other.getType()); | 47 REPORTER_ASSERT(reporter, SkRRect::kEmpty_Type == other.getType()); |
48 } | 48 } |
49 | 49 |
| 50 // Test that all the SkRRect entry points correctly handle un-sorted and |
| 51 // zero-sized input rects |
| 52 static void test_empty(skiatest::Reporter* reporter) { |
| 53 static const SkRect oooRects[] = { // out of order |
| 54 { 100, 0, 0, 100 }, // ooo horizontal |
| 55 { 0, 100, 100, 0 }, // ooo vertical |
| 56 { 100, 100, 0, 0 }, // ooo both |
| 57 }; |
| 58 |
| 59 static const SkRect emptyRects[] = { |
| 60 { 100, 100, 100, 200 }, // empty horizontal |
| 61 { 100, 100, 200, 100 }, // empty vertical |
| 62 { 100, 100, 100, 100 }, // empty both |
| 63 { 0, 0, 0, 0 } // setEmpty-empty |
| 64 }; |
| 65 |
| 66 static const SkVector radii[4] = { { 0, 1 }, { 2, 3 }, { 4, 5 }, { 6, 7 } }; |
| 67 |
| 68 SkRRect r; |
| 69 |
| 70 for (size_t i = 0; i < SK_ARRAY_COUNT(oooRects); ++i) { |
| 71 r.setRect(oooRects[i]); |
| 72 REPORTER_ASSERT(reporter, !r.isEmpty()); |
| 73 |
| 74 r.setOval(oooRects[i]); |
| 75 REPORTER_ASSERT(reporter, !r.isEmpty()); |
| 76 |
| 77 r.setRectXY(oooRects[i], 1, 2); |
| 78 REPORTER_ASSERT(reporter, !r.isEmpty()); |
| 79 |
| 80 r.setNinePatch(oooRects[i], 0, 1, 2, 3); |
| 81 REPORTER_ASSERT(reporter, !r.isEmpty()); |
| 82 |
| 83 r.setRectRadii(oooRects[i], radii); |
| 84 REPORTER_ASSERT(reporter, !r.isEmpty()); |
| 85 } |
| 86 |
| 87 for (size_t i = 0; i < SK_ARRAY_COUNT(emptyRects); ++i) { |
| 88 r.setRect(emptyRects[i]); |
| 89 REPORTER_ASSERT(reporter, r.isEmpty()); |
| 90 |
| 91 r.setOval(emptyRects[i]); |
| 92 REPORTER_ASSERT(reporter, r.isEmpty()); |
| 93 |
| 94 r.setRectXY(emptyRects[i], 1, 2); |
| 95 REPORTER_ASSERT(reporter, r.isEmpty()); |
| 96 |
| 97 r.setNinePatch(emptyRects[i], 0, 1, 2, 3); |
| 98 REPORTER_ASSERT(reporter, r.isEmpty()); |
| 99 |
| 100 r.setRectRadii(emptyRects[i], radii); |
| 101 REPORTER_ASSERT(reporter, r.isEmpty()); |
| 102 } |
| 103 } |
| 104 |
50 static const SkScalar kWidth = 100.0f; | 105 static const SkScalar kWidth = 100.0f; |
51 static const SkScalar kHeight = 100.0f; | 106 static const SkScalar kHeight = 100.0f; |
52 | 107 |
53 static void test_inset(skiatest::Reporter* reporter) { | 108 static void test_inset(skiatest::Reporter* reporter) { |
54 SkRRect rr, rr2; | 109 SkRRect rr, rr2; |
55 SkRect r = { 0, 0, 100, 100 }; | 110 SkRect r = { 0, 0, 100, 100 }; |
56 | 111 |
57 rr.setRect(r); | 112 rr.setRect(r); |
58 rr.inset(-20, -20, &rr2); | 113 rr.inset(-20, -20, &rr2); |
59 REPORTER_ASSERT(reporter, rr2.isRect()); | 114 REPORTER_ASSERT(reporter, rr2.isRect()); |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 test_round_rect_rects(reporter); | 727 test_round_rect_rects(reporter); |
673 test_round_rect_ovals(reporter); | 728 test_round_rect_ovals(reporter); |
674 test_round_rect_general(reporter); | 729 test_round_rect_general(reporter); |
675 test_round_rect_iffy_parameters(reporter); | 730 test_round_rect_iffy_parameters(reporter); |
676 test_inset(reporter); | 731 test_inset(reporter); |
677 test_round_rect_contains_rect(reporter); | 732 test_round_rect_contains_rect(reporter); |
678 test_round_rect_transform(reporter); | 733 test_round_rect_transform(reporter); |
679 test_issue_2696(reporter); | 734 test_issue_2696(reporter); |
680 test_tricky_radii(reporter); | 735 test_tricky_radii(reporter); |
681 test_empty_crbug_458524(reporter); | 736 test_empty_crbug_458524(reporter); |
| 737 test_empty(reporter); |
682 } | 738 } |
OLD | NEW |