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

Side by Side Diff: tests/PathTest.cpp

Issue 16195004: add asserts to point<-->verb helpers (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « tests/PathOpsSimplifyTest.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 firstTime = false; 463 firstTime = false;
464 break; 464 break;
465 case SkPath::kLine_Verb: 465 case SkPath::kLine_Verb:
466 REPORTER_ASSERT(reporter, !firstTime); 466 REPORTER_ASSERT(reporter, !firstTime);
467 REPORTER_ASSERT(reporter, pts[1] == srcPts[0]); 467 REPORTER_ASSERT(reporter, pts[1] == srcPts[0]);
468 srcPts++; 468 srcPts++;
469 break; 469 break;
470 case SkPath::kQuad_Verb: 470 case SkPath::kQuad_Verb:
471 REPORTER_ASSERT(reporter, !"unexpected quad verb"); 471 REPORTER_ASSERT(reporter, !"unexpected quad verb");
472 break; 472 break;
473 case SkPath::kConic_Verb:
474 REPORTER_ASSERT(reporter, !"unexpected conic verb");
475 break;
473 case SkPath::kCubic_Verb: 476 case SkPath::kCubic_Verb:
474 REPORTER_ASSERT(reporter, !"unexpected cubic verb"); 477 REPORTER_ASSERT(reporter, !"unexpected cubic verb");
475 break; 478 break;
476 case SkPath::kClose_Verb: 479 case SkPath::kClose_Verb:
477 REPORTER_ASSERT(reporter, !firstTime); 480 REPORTER_ASSERT(reporter, !firstTime);
478 REPORTER_ASSERT(reporter, !foundClose); 481 REPORTER_ASSERT(reporter, !foundClose);
479 REPORTER_ASSERT(reporter, expectClose); 482 REPORTER_ASSERT(reporter, expectClose);
480 foundClose = true; 483 foundClose = true;
481 break; 484 break;
482 case SkPath::kDone_Verb: 485 case SkPath::kDone_Verb:
(...skipping 1479 matching lines...) Expand 10 before | Expand all | Expand 10 after
1962 expectedPts[numPoints++] = lastMoveToPt; 1965 expectedPts[numPoints++] = lastMoveToPt;
1963 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb; 1966 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
1964 haveMoveTo = true; 1967 haveMoveTo = true;
1965 } 1968 }
1966 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25 ]; 1969 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25 ];
1967 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25]; 1970 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
1968 p.quadTo(expectedPts[numPoints], expectedPts[numPoints + 1]) ; 1971 p.quadTo(expectedPts[numPoints], expectedPts[numPoints + 1]) ;
1969 numPoints += 2; 1972 numPoints += 2;
1970 lastWasClose = false; 1973 lastWasClose = false;
1971 break; 1974 break;
1975 case SkPath::kConic_Verb:
1976 if (!haveMoveTo) {
1977 expectedPts[numPoints++] = lastMoveToPt;
1978 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
1979 haveMoveTo = true;
1980 }
1981 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25 ];
1982 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
1983 p.conicTo(expectedPts[numPoints], expectedPts[numPoints + 1] ,
1984 rand.nextUScalar1() * 4);
1985 numPoints += 2;
1986 lastWasClose = false;
1987 break;
1972 case SkPath::kCubic_Verb: 1988 case SkPath::kCubic_Verb:
1973 if (!haveMoveTo) { 1989 if (!haveMoveTo) {
1974 expectedPts[numPoints++] = lastMoveToPt; 1990 expectedPts[numPoints++] = lastMoveToPt;
1975 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb; 1991 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
1976 haveMoveTo = true; 1992 haveMoveTo = true;
1977 } 1993 }
1978 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25 ]; 1994 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25 ];
1979 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25]; 1995 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
1980 expectedPts[numPoints + 2] = randomPts[(rand.nextU() >> 16) % 25]; 1996 expectedPts[numPoints + 2] = randomPts[(rand.nextU() >> 16) % 25];
1981 p.cubicTo(expectedPts[numPoints], expectedPts[numPoints + 1] , 1997 p.cubicTo(expectedPts[numPoints], expectedPts[numPoints + 1] ,
1982 expectedPts[numPoints + 2]); 1998 expectedPts[numPoints + 2]);
1983 numPoints += 3; 1999 numPoints += 3;
1984 lastWasClose = false; 2000 lastWasClose = false;
1985 break; 2001 break;
1986 case SkPath::kClose_Verb: 2002 case SkPath::kClose_Verb:
1987 p.close(); 2003 p.close();
1988 haveMoveTo = false; 2004 haveMoveTo = false;
1989 lastWasClose = true; 2005 lastWasClose = true;
1990 break; 2006 break;
1991 default:; 2007 default:
2008 SkASSERT(!"unexpected verb");
1992 } 2009 }
1993 expectedVerbs[numIterVerbs++] = nextVerb; 2010 expectedVerbs[numIterVerbs++] = nextVerb;
1994 } 2011 }
1995 2012
1996 iter.setPath(p); 2013 iter.setPath(p);
1997 numVerbs = numIterVerbs; 2014 numVerbs = numIterVerbs;
1998 numIterVerbs = 0; 2015 numIterVerbs = 0;
1999 int numIterPts = 0; 2016 int numIterPts = 0;
2000 SkPoint lastMoveTo; 2017 SkPoint lastMoveTo;
2001 SkPoint lastPt; 2018 SkPoint lastPt;
(...skipping 10 matching lines...) Expand all
2012 numIterPts += 1; 2029 numIterPts += 1;
2013 break; 2030 break;
2014 case SkPath::kLine_Verb: 2031 case SkPath::kLine_Verb:
2015 REPORTER_ASSERT(reporter, numIterPts < numPoints + 1); 2032 REPORTER_ASSERT(reporter, numIterPts < numPoints + 1);
2016 REPORTER_ASSERT(reporter, pts[0] == lastPt); 2033 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2017 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]) ; 2034 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]) ;
2018 lastPt = pts[1]; 2035 lastPt = pts[1];
2019 numIterPts += 1; 2036 numIterPts += 1;
2020 break; 2037 break;
2021 case SkPath::kQuad_Verb: 2038 case SkPath::kQuad_Verb:
2039 case SkPath::kConic_Verb:
2022 REPORTER_ASSERT(reporter, numIterPts < numPoints + 2); 2040 REPORTER_ASSERT(reporter, numIterPts < numPoints + 2);
2023 REPORTER_ASSERT(reporter, pts[0] == lastPt); 2041 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2024 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]) ; 2042 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]) ;
2025 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]); 2043 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
2026 lastPt = pts[2]; 2044 lastPt = pts[2];
2027 numIterPts += 2; 2045 numIterPts += 2;
2028 break; 2046 break;
2029 case SkPath::kCubic_Verb: 2047 case SkPath::kCubic_Verb:
2030 REPORTER_ASSERT(reporter, numIterPts < numPoints + 3); 2048 REPORTER_ASSERT(reporter, numIterPts < numPoints + 3);
2031 REPORTER_ASSERT(reporter, pts[0] == lastPt); 2049 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2032 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]) ; 2050 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]) ;
2033 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]); 2051 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
2034 REPORTER_ASSERT(reporter, pts[3] == expectedPts[numIterPts + 2]); 2052 REPORTER_ASSERT(reporter, pts[3] == expectedPts[numIterPts + 2]);
2035 lastPt = pts[3]; 2053 lastPt = pts[3];
2036 numIterPts += 3; 2054 numIterPts += 3;
2037 break; 2055 break;
2038 case SkPath::kClose_Verb: 2056 case SkPath::kClose_Verb:
2039 REPORTER_ASSERT(reporter, pts[0] == lastMoveTo); 2057 REPORTER_ASSERT(reporter, pts[0] == lastMoveTo);
2040 lastPt = lastMoveTo; 2058 lastPt = lastMoveTo;
2041 break; 2059 break;
2042 default:; 2060 default:
2061 SkASSERT(!"unexpected verb");
2043 } 2062 }
2044 } 2063 }
2045 REPORTER_ASSERT(reporter, numIterPts == numPoints); 2064 REPORTER_ASSERT(reporter, numIterPts == numPoints);
2046 REPORTER_ASSERT(reporter, numIterVerbs == numVerbs); 2065 REPORTER_ASSERT(reporter, numIterVerbs == numVerbs);
2047 } 2066 }
2048 } 2067 }
2049 2068
2050 static void check_for_circle(skiatest::Reporter* reporter, 2069 static void check_for_circle(skiatest::Reporter* reporter,
2051 const SkPath& path, 2070 const SkPath& path,
2052 bool expectedCircle, 2071 bool expectedCircle,
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 test_addrect_isfinite(reporter); 2429 test_addrect_isfinite(reporter);
2411 test_tricky_cubic(); 2430 test_tricky_cubic();
2412 test_clipped_cubic(); 2431 test_clipped_cubic();
2413 test_crbug_170666(); 2432 test_crbug_170666();
2414 test_bad_cubic_crbug229478(); 2433 test_bad_cubic_crbug229478();
2415 test_bad_cubic_crbug234190(); 2434 test_bad_cubic_crbug234190();
2416 } 2435 }
2417 2436
2418 #include "TestClassDef.h" 2437 #include "TestClassDef.h"
2419 DEFINE_TESTCLASS("Path", PathTestClass, TestPath) 2438 DEFINE_TESTCLASS("Path", PathTestClass, TestPath)
OLDNEW
« no previous file with comments | « tests/PathOpsSimplifyTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698