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

Side by Side Diff: tests/PathOpsDRectTest.cpp

Issue 19374003: harden and speed up path op unit tests (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rename threaded to single Created 7 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 | Annotate | Revision Log
« no previous file with comments | « tests/PathOpsDQuadTest.cpp ('k') | tests/PathOpsDTriangleTest.cpp » ('j') | 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 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 #include "PathOpsTestCommon.h"
7 #include "SkPathOpsCubic.h" 8 #include "SkPathOpsCubic.h"
8 #include "SkPathOpsLine.h" 9 #include "SkPathOpsLine.h"
9 #include "SkPathOpsQuad.h" 10 #include "SkPathOpsQuad.h"
10 #include "SkPathOpsRect.h" 11 #include "SkPathOpsRect.h"
11 #include "Test.h" 12 #include "Test.h"
12 13
13 static const SkDLine lineTests[] = { 14 static const SkDLine lineTests[] = {
14 {{{2, 1}, {2, 1}}}, 15 {{{2, 1}, {2, 1}}},
15 {{{2, 1}, {1, 1}}}, 16 {{{2, 1}, {1, 1}}},
16 {{{2, 1}, {2, 2}}}, 17 {{{2, 1}, {2, 2}}},
(...skipping 18 matching lines...) Expand all
35 36
36 static const size_t lineTests_count = SK_ARRAY_COUNT(lineTests); 37 static const size_t lineTests_count = SK_ARRAY_COUNT(lineTests);
37 static const size_t quadTests_count = SK_ARRAY_COUNT(quadTests); 38 static const size_t quadTests_count = SK_ARRAY_COUNT(quadTests);
38 static const size_t cubicTests_count = SK_ARRAY_COUNT(cubicTests); 39 static const size_t cubicTests_count = SK_ARRAY_COUNT(cubicTests);
39 40
40 static void PathOpsDRectTest(skiatest::Reporter* reporter) { 41 static void PathOpsDRectTest(skiatest::Reporter* reporter) {
41 size_t index; 42 size_t index;
42 SkDRect rect, rect2; 43 SkDRect rect, rect2;
43 for (index = 0; index < lineTests_count; ++index) { 44 for (index = 0; index < lineTests_count; ++index) {
44 const SkDLine& line = lineTests[index]; 45 const SkDLine& line = lineTests[index];
46 SkASSERT(ValidLine(line));
45 rect.setBounds(line); 47 rect.setBounds(line);
46 REPORTER_ASSERT(reporter, rect.fLeft == SkTMin(line[0].fX, line[1].fX)); 48 REPORTER_ASSERT(reporter, rect.fLeft == SkTMin(line[0].fX, line[1].fX));
47 REPORTER_ASSERT(reporter, rect.fTop == SkTMin(line[0].fY, line[1].fY)); 49 REPORTER_ASSERT(reporter, rect.fTop == SkTMin(line[0].fY, line[1].fY));
48 REPORTER_ASSERT(reporter, rect.fRight == SkTMax(line[0].fX, line[1].fX)) ; 50 REPORTER_ASSERT(reporter, rect.fRight == SkTMax(line[0].fX, line[1].fX)) ;
49 REPORTER_ASSERT(reporter, rect.fBottom == SkTMax(line[0].fY, line[1].fY) ); 51 REPORTER_ASSERT(reporter, rect.fBottom == SkTMax(line[0].fY, line[1].fY) );
50 rect2.set(line[0]); 52 rect2.set(line[0]);
51 rect2.add(line[1]); 53 rect2.add(line[1]);
52 REPORTER_ASSERT(reporter, rect2.fLeft == SkTMin(line[0].fX, line[1].fX)) ; 54 REPORTER_ASSERT(reporter, rect2.fLeft == SkTMin(line[0].fX, line[1].fX)) ;
53 REPORTER_ASSERT(reporter, rect2.fTop == SkTMin(line[0].fY, line[1].fY)); 55 REPORTER_ASSERT(reporter, rect2.fTop == SkTMin(line[0].fY, line[1].fY));
54 REPORTER_ASSERT(reporter, rect2.fRight == SkTMax(line[0].fX, line[1].fX) ); 56 REPORTER_ASSERT(reporter, rect2.fRight == SkTMax(line[0].fX, line[1].fX) );
55 REPORTER_ASSERT(reporter, rect2.fBottom == SkTMax(line[0].fY, line[1].fY )); 57 REPORTER_ASSERT(reporter, rect2.fBottom == SkTMax(line[0].fY, line[1].fY ));
56 REPORTER_ASSERT(reporter, rect.contains(line[0])); 58 REPORTER_ASSERT(reporter, rect.contains(line[0]));
57 REPORTER_ASSERT(reporter, rect.intersects(&rect2)); 59 REPORTER_ASSERT(reporter, rect.intersects(&rect2));
58 } 60 }
59 for (index = 0; index < quadTests_count; ++index) { 61 for (index = 0; index < quadTests_count; ++index) {
60 const SkDQuad& quad = quadTests[index]; 62 const SkDQuad& quad = quadTests[index];
63 SkASSERT(ValidQuad(quad));
61 rect.setRawBounds(quad); 64 rect.setRawBounds(quad);
62 REPORTER_ASSERT(reporter, rect.fLeft == SkTMin(quad[0].fX, 65 REPORTER_ASSERT(reporter, rect.fLeft == SkTMin(quad[0].fX,
63 SkTMin(quad[1].fX, quad[2].fX))); 66 SkTMin(quad[1].fX, quad[2].fX)));
64 REPORTER_ASSERT(reporter, rect.fTop == SkTMin(quad[0].fY, 67 REPORTER_ASSERT(reporter, rect.fTop == SkTMin(quad[0].fY,
65 SkTMin(quad[1].fY, quad[2].fY))); 68 SkTMin(quad[1].fY, quad[2].fY)));
66 REPORTER_ASSERT(reporter, rect.fRight == SkTMax(quad[0].fX, 69 REPORTER_ASSERT(reporter, rect.fRight == SkTMax(quad[0].fX,
67 SkTMax(quad[1].fX, quad[2].fX))); 70 SkTMax(quad[1].fX, quad[2].fX)));
68 REPORTER_ASSERT(reporter, rect.fBottom == SkTMax(quad[0].fY, 71 REPORTER_ASSERT(reporter, rect.fBottom == SkTMax(quad[0].fY,
69 SkTMax(quad[1].fY, quad[2].fY))); 72 SkTMax(quad[1].fY, quad[2].fY)));
70 rect2.setBounds(quad); 73 rect2.setBounds(quad);
71 REPORTER_ASSERT(reporter, rect.intersects(&rect2)); 74 REPORTER_ASSERT(reporter, rect.intersects(&rect2));
72 // FIXME: add a recursive box subdivision method to verify that tight bo unds is correct 75 // FIXME: add a recursive box subdivision method to verify that tight bo unds is correct
73 SkDPoint leftTop = {rect2.fLeft, rect2.fTop}; 76 SkDPoint leftTop = {rect2.fLeft, rect2.fTop};
74 REPORTER_ASSERT(reporter, rect.contains(leftTop)); 77 REPORTER_ASSERT(reporter, rect.contains(leftTop));
75 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom}; 78 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom};
76 REPORTER_ASSERT(reporter, rect.contains(rightBottom)); 79 REPORTER_ASSERT(reporter, rect.contains(rightBottom));
77 } 80 }
78 for (index = 0; index < cubicTests_count; ++index) { 81 for (index = 0; index < cubicTests_count; ++index) {
79 const SkDCubic& cubic = cubicTests[index]; 82 const SkDCubic& cubic = cubicTests[index];
83 SkASSERT(ValidCubic(cubic));
80 rect.setRawBounds(cubic); 84 rect.setRawBounds(cubic);
81 REPORTER_ASSERT(reporter, rect.fLeft == SkTMin(cubic[0].fX, 85 REPORTER_ASSERT(reporter, rect.fLeft == SkTMin(cubic[0].fX,
82 SkTMin(cubic[1].fX, SkTMin(cubic[2].fX, cubic[3].fX)))); 86 SkTMin(cubic[1].fX, SkTMin(cubic[2].fX, cubic[3].fX))));
83 REPORTER_ASSERT(reporter, rect.fTop == SkTMin(cubic[0].fY, 87 REPORTER_ASSERT(reporter, rect.fTop == SkTMin(cubic[0].fY,
84 SkTMin(cubic[1].fY, SkTMin(cubic[2].fY, cubic[3].fY)))); 88 SkTMin(cubic[1].fY, SkTMin(cubic[2].fY, cubic[3].fY))));
85 REPORTER_ASSERT(reporter, rect.fRight == SkTMax(cubic[0].fX, 89 REPORTER_ASSERT(reporter, rect.fRight == SkTMax(cubic[0].fX,
86 SkTMax(cubic[1].fX, SkTMax(cubic[2].fX, cubic[3].fX)))); 90 SkTMax(cubic[1].fX, SkTMax(cubic[2].fX, cubic[3].fX))));
87 REPORTER_ASSERT(reporter, rect.fBottom == SkTMax(cubic[0].fY, 91 REPORTER_ASSERT(reporter, rect.fBottom == SkTMax(cubic[0].fY,
88 SkTMax(cubic[1].fY, SkTMax(cubic[2].fY, cubic[3].fY)))); 92 SkTMax(cubic[1].fY, SkTMax(cubic[2].fY, cubic[3].fY))));
89 rect2.setBounds(cubic); 93 rect2.setBounds(cubic);
90 REPORTER_ASSERT(reporter, rect.intersects(&rect2)); 94 REPORTER_ASSERT(reporter, rect.intersects(&rect2));
91 // FIXME: add a recursive box subdivision method to verify that tight bo unds is correct 95 // FIXME: add a recursive box subdivision method to verify that tight bo unds is correct
92 SkDPoint leftTop = {rect2.fLeft, rect2.fTop}; 96 SkDPoint leftTop = {rect2.fLeft, rect2.fTop};
93 REPORTER_ASSERT(reporter, rect.contains(leftTop)); 97 REPORTER_ASSERT(reporter, rect.contains(leftTop));
94 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom}; 98 SkDPoint rightBottom = {rect2.fRight, rect2.fBottom};
95 REPORTER_ASSERT(reporter, rect.contains(rightBottom)); 99 REPORTER_ASSERT(reporter, rect.contains(rightBottom));
96 } 100 }
97 } 101 }
98 102
99 #include "TestClassDef.h" 103 #include "TestClassDef.h"
100 DEFINE_TESTCLASS_SHORT(PathOpsDRectTest) 104 DEFINE_TESTCLASS_SHORT(PathOpsDRectTest)
OLDNEW
« no previous file with comments | « tests/PathOpsDQuadTest.cpp ('k') | tests/PathOpsDTriangleTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698