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

Side by Side Diff: tests/PathTest.cpp

Issue 115323004: Improved SkPathRef interface security (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years 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 | Annotate | Revision Log
« src/core/SkPathRef.cpp ('K') | « src/core/SkPathRef.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 "Test.h" 8 #include "Test.h"
9 #include "TestClassDef.h" 9 #include "TestClassDef.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 2661 matching lines...) Expand 10 before | Expand all | Expand 10 after
2672 static const SkPath::Direction kCircleDir = SkPath::kCW_Direction; 2672 static const SkPath::Direction kCircleDir = SkPath::kCW_Direction;
2673 static const SkPath::Direction kCircleDirOpposite = SkPath::kCCW_Direction; 2673 static const SkPath::Direction kCircleDirOpposite = SkPath::kCCW_Direction;
2674 2674
2675 circle.addCircle(0, 0, SkIntToScalar(10), kCircleDir); 2675 circle.addCircle(0, 0, SkIntToScalar(10), kCircleDir);
2676 rect.addRect(SkIntToScalar(5), SkIntToScalar(5), 2676 rect.addRect(SkIntToScalar(5), SkIntToScalar(5),
2677 SkIntToScalar(20), SkIntToScalar(20), SkPath::kCW_Direction); 2677 SkIntToScalar(20), SkIntToScalar(20), SkPath::kCW_Direction);
2678 2678
2679 SkMatrix translate; 2679 SkMatrix translate;
2680 translate.setTranslate(SkIntToScalar(12), SkIntToScalar(12)); 2680 translate.setTranslate(SkIntToScalar(12), SkIntToScalar(12));
2681 2681
2682 // For simplicity, all the path concatenation related operations 2682 // Although all the path concatenation related operations leave
2683 // would mark it non-circle, though in theory it's still a circle. 2683 // the path a circle, most mark it as a non-circle for simplicity
2684 2684
2685 // empty + circle (translate) 2685 // empty + circle (translate)
2686 path = empty; 2686 path = empty;
2687 path.addPath(circle, translate); 2687 path.addPath(circle, translate);
2688 check_for_circle(reporter, path, false, kCircleDir); 2688 check_for_circle(reporter, path, false, kCircleDir);
2689 2689
2690 // circle + empty (translate) 2690 // circle + empty (translate)
2691 path = circle; 2691 path = circle;
2692 path.addPath(empty, translate); 2692 path.addPath(empty, translate);
2693 check_for_circle(reporter, path, false, kCircleDir); 2693 check_for_circle(reporter, path, true, kCircleDir);
2694 2694
2695 // test reverseAddPath 2695 // test reverseAddPath
2696 path = circle; 2696 path = circle;
2697 path.reverseAddPath(rect); 2697 path.reverseAddPath(rect);
2698 check_for_circle(reporter, path, false, kCircleDirOpposite); 2698 check_for_circle(reporter, path, false, kCircleDirOpposite);
2699 } 2699 }
2700 2700
2701 static void test_circle(skiatest::Reporter* reporter) { 2701 static void test_circle(skiatest::Reporter* reporter) {
2702 test_circle_with_direction(reporter, SkPath::kCW_Direction); 2702 test_circle_with_direction(reporter, SkPath::kCW_Direction);
2703 test_circle_with_direction(reporter, SkPath::kCCW_Direction); 2703 test_circle_with_direction(reporter, SkPath::kCCW_Direction);
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
3131 p.setFillType(SkPath::kEvenOdd_FillType); 3131 p.setFillType(SkPath::kEvenOdd_FillType);
3132 p.moveTo(pts[i].fX, pts[i].fY); 3132 p.moveTo(pts[i].fX, pts[i].fY);
3133 p.cubicTo(pts[i + 1].fX, pts[i + 1].fY, pts[i + 2].fX, pts[i + 2].fY, pt s[i + 3].fX, pts[i + 3].fY); 3133 p.cubicTo(pts[i + 1].fX, pts[i + 1].fY, pts[i + 2].fX, pts[i + 2].fY, pt s[i + 3].fX, pts[i + 3].fY);
3134 p.cubicTo(pts[i + 4].fX, pts[i + 4].fY, pts[i + 5].fX, pts[i + 5].fY, pt s[i + 6].fX, pts[i + 6].fY); 3134 p.cubicTo(pts[i + 4].fX, pts[i + 4].fY, pts[i + 5].fX, pts[i + 5].fY, pt s[i + 6].fX, pts[i + 6].fY);
3135 p.close(); 3135 p.close();
3136 REPORTER_ASSERT(reporter, p.contains(5.5f, 5.5f)); 3136 REPORTER_ASSERT(reporter, p.contains(5.5f, 5.5f));
3137 REPORTER_ASSERT(reporter, !p.contains(4.5f, 5.5f)); 3137 REPORTER_ASSERT(reporter, !p.contains(4.5f, 5.5f));
3138 } 3138 }
3139 } 3139 }
3140 3140
3141 class TestingPathRefCreator {
3142 public:
3143 static SkPathRef* Create() {
3144 return SkNEW(SkPathRef);
3145 }
3146 };
3147
3141 static void test_pathref(skiatest::Reporter* reporter) { 3148 static void test_pathref(skiatest::Reporter* reporter) {
3142 static const int kRepeatCnt = 10; 3149 static const int kRepeatCnt = 10;
3143 3150
3144 SkPathRef* pathRef = SkPathRef::CreateEmpty(); 3151 SkAutoTUnref<SkPathRef> pathRef(TestingPathRefCreator::Create());
3145 SkAutoTUnref<SkPathRef> pathRef2(SkPathRef::CreateEmpty());
3146 SkMatrix mat;
3147 3152
3148 mat.setTranslate(10, 10); 3153 SkPathRef::Editor ed(&pathRef);
3149
3150 SkPathRef::CreateTransformedCopy(&pathRef2, *pathRef, mat);
3151
3152 SkPathRef::Editor ed(&pathRef2);
3153 3154
3154 { 3155 {
3155 ed.growForRepeatedVerb(SkPath::kMove_Verb, kRepeatCnt); 3156 ed.growForRepeatedVerb(SkPath::kMove_Verb, kRepeatCnt);
3156 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef2->countVerbs()); 3157 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3157 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef2->countPoints()); 3158 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints());
3158 REPORTER_ASSERT(reporter, 0 == pathRef2->getSegmentMasks()); 3159 REPORTER_ASSERT(reporter, 0 == pathRef->getSegmentMasks());
3159 for (int i = 0; i < kRepeatCnt; ++i) { 3160 for (int i = 0; i < kRepeatCnt; ++i) {
3160 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == pathRef2->atVerb(i)) ; 3161 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == pathRef->atVerb(i));
3161 } 3162 }
3162 ed.resetToSize(0, 0, 0); 3163 ed.resetToSize(0, 0, 0);
3163 } 3164 }
3164 3165
3165 { 3166 {
3166 ed.growForRepeatedVerb(SkPath::kLine_Verb, kRepeatCnt); 3167 ed.growForRepeatedVerb(SkPath::kLine_Verb, kRepeatCnt);
3167 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef2->countVerbs()); 3168 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3168 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef2->countPoints()); 3169 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints());
3169 REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == pathRef2->getSegm entMasks()); 3170 REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == pathRef->getSegme ntMasks());
3170 for (int i = 0; i < kRepeatCnt; ++i) { 3171 for (int i = 0; i < kRepeatCnt; ++i) {
3171 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == pathRef2->atVerb(i)) ; 3172 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == pathRef->atVerb(i));
3172 } 3173 }
3173 ed.resetToSize(0, 0, 0); 3174 ed.resetToSize(0, 0, 0);
3174 } 3175 }
3175 3176
3176 { 3177 {
3177 ed.growForRepeatedVerb(SkPath::kQuad_Verb, kRepeatCnt); 3178 ed.growForRepeatedVerb(SkPath::kQuad_Verb, kRepeatCnt);
3178 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef2->countVerbs()); 3179 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3179 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef2->countPoints()); 3180 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints());
3180 REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == pathRef2->getSegm entMasks()); 3181 REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == pathRef->getSegme ntMasks());
3181 for (int i = 0; i < kRepeatCnt; ++i) { 3182 for (int i = 0; i < kRepeatCnt; ++i) {
3182 REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == pathRef2->atVerb(i)) ; 3183 REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == pathRef->atVerb(i));
3183 } 3184 }
3184 ed.resetToSize(0, 0, 0); 3185 ed.resetToSize(0, 0, 0);
3185 } 3186 }
3186 3187
3187 { 3188 {
3188 SkScalar* weights = NULL; 3189 SkScalar* weights = NULL;
3189 ed.growForRepeatedVerb(SkPath::kConic_Verb, kRepeatCnt, &weights); 3190 ed.growForRepeatedVerb(SkPath::kConic_Verb, kRepeatCnt, &weights);
3190 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef2->countVerbs()); 3191 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3191 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef2->countPoints()); 3192 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints());
3192 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef2->countWeights()); 3193 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countWeights());
3193 REPORTER_ASSERT(reporter, SkPath::kConic_SegmentMask == pathRef2->getSeg mentMasks()); 3194 REPORTER_ASSERT(reporter, SkPath::kConic_SegmentMask == pathRef->getSegm entMasks());
3194 REPORTER_ASSERT(reporter, NULL != weights); 3195 REPORTER_ASSERT(reporter, NULL != weights);
3195 for (int i = 0; i < kRepeatCnt; ++i) { 3196 for (int i = 0; i < kRepeatCnt; ++i) {
3196 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == pathRef2->atVerb(i) ); 3197 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == pathRef->atVerb(i)) ;
3197 } 3198 }
3198 ed.resetToSize(0, 0, 0); 3199 ed.resetToSize(0, 0, 0);
3199 } 3200 }
3200 3201
3201 { 3202 {
3202 ed.growForRepeatedVerb(SkPath::kCubic_Verb, kRepeatCnt); 3203 ed.growForRepeatedVerb(SkPath::kCubic_Verb, kRepeatCnt);
3203 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef2->countVerbs()); 3204 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3204 REPORTER_ASSERT(reporter, 3*kRepeatCnt == pathRef2->countPoints()); 3205 REPORTER_ASSERT(reporter, 3*kRepeatCnt == pathRef->countPoints());
3205 REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == pathRef2->getSeg mentMasks()); 3206 REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == pathRef->getSegm entMasks());
3206 for (int i = 0; i < kRepeatCnt; ++i) { 3207 for (int i = 0; i < kRepeatCnt; ++i) {
3207 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == pathRef2->atVerb(i) ); 3208 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == pathRef->atVerb(i)) ;
3208 } 3209 }
3209 ed.resetToSize(0, 0, 0); 3210 ed.resetToSize(0, 0, 0);
3210 } 3211 }
3211 } 3212 }
3212 3213
3213 static void test_operatorEqual(skiatest::Reporter* reporter) { 3214 static void test_operatorEqual(skiatest::Reporter* reporter) {
3214 SkPath a; 3215 SkPath a;
3215 SkPath b; 3216 SkPath b;
3216 REPORTER_ASSERT(reporter, a == a); 3217 REPORTER_ASSERT(reporter, a == a);
3217 REPORTER_ASSERT(reporter, a == b); 3218 REPORTER_ASSERT(reporter, a == b);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
3365 test_rrect(reporter); 3366 test_rrect(reporter);
3366 test_arc(reporter); 3367 test_arc(reporter);
3367 test_arcTo(reporter); 3368 test_arcTo(reporter);
3368 test_addPath(reporter); 3369 test_addPath(reporter);
3369 test_conicTo_special_case(reporter); 3370 test_conicTo_special_case(reporter);
3370 test_get_point(reporter); 3371 test_get_point(reporter);
3371 test_contains(reporter); 3372 test_contains(reporter);
3372 test_pathref(reporter); 3373 test_pathref(reporter);
3373 PathTest_Private::TestPathTo(reporter); 3374 PathTest_Private::TestPathTo(reporter);
3374 } 3375 }
OLDNEW
« src/core/SkPathRef.cpp ('K') | « src/core/SkPathRef.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698