aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ClipStackTest.cpp
diff options
context:
space:
mode:
authorGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-20 15:33:18 +0000
committerGravatar robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-07-20 15:33:18 +0000
commit80214e26c57c5fea954006400852e8999e201923 (patch)
tree59e23fdd0310caa1438c979ffb91a5cb8aab2de6 /tests/ClipStackTest.cpp
parentcbd0ad90307c2d9d1fce0239476fb03dec8eca9b (diff)
Made clarifying renamings to SkClipStack's iterators (and added to unit test)
Diffstat (limited to 'tests/ClipStackTest.cpp')
-rw-r--r--tests/ClipStackTest.cpp94
1 files changed, 89 insertions, 5 deletions
diff --git a/tests/ClipStackTest.cpp b/tests/ClipStackTest.cpp
index a1e8323116..85a999797a 100644
--- a/tests/ClipStackTest.cpp
+++ b/tests/ClipStackTest.cpp
@@ -10,12 +10,18 @@
#include "SkPath.h"
#include "SkRect.h"
+
+
static void test_assign_and_comparison(skiatest::Reporter* reporter) {
SkClipStack s;
bool doAA = false;
+ REPORTER_ASSERT(reporter, 0 == s.getSaveCount());
+
// Build up a clip stack with a path, an empty clip, and a rect.
s.save();
+ REPORTER_ASSERT(reporter, 1 == s.getSaveCount());
+
SkPath p;
p.moveTo(5, 6);
p.lineTo(7, 8);
@@ -24,12 +30,16 @@ static void test_assign_and_comparison(skiatest::Reporter* reporter) {
s.clipDevPath(p, SkRegion::kIntersect_Op, doAA);
s.save();
+ REPORTER_ASSERT(reporter, 2 == s.getSaveCount());
+
SkRect r = SkRect::MakeLTRB(1, 2, 3, 4);
s.clipDevRect(r, SkRegion::kIntersect_Op, doAA);
r = SkRect::MakeLTRB(10, 11, 12, 13);
s.clipDevRect(r, SkRegion::kIntersect_Op, doAA);
s.save();
+ REPORTER_ASSERT(reporter, 3 == s.getSaveCount());
+
r = SkRect::MakeLTRB(14, 15, 16, 17);
s.clipDevRect(r, SkRegion::kUnion_Op, doAA);
@@ -39,17 +49,23 @@ static void test_assign_and_comparison(skiatest::Reporter* reporter) {
// Test that different save levels triggers not equal.
s.restore();
+ REPORTER_ASSERT(reporter, 2 == s.getSaveCount());
REPORTER_ASSERT(reporter, s != copy);
// Test that an equal, but not copied version is equal.
s.save();
+ REPORTER_ASSERT(reporter, 3 == s.getSaveCount());
+
r = SkRect::MakeLTRB(14, 15, 16, 17);
s.clipDevRect(r, SkRegion::kUnion_Op, doAA);
REPORTER_ASSERT(reporter, s == copy);
// Test that a different op on one level triggers not equal.
s.restore();
+ REPORTER_ASSERT(reporter, 2 == s.getSaveCount());
s.save();
+ REPORTER_ASSERT(reporter, 3 == s.getSaveCount());
+
r = SkRect::MakeLTRB(14, 15, 16, 17);
s.clipDevRect(r, SkRegion::kIntersect_Op, doAA);
REPORTER_ASSERT(reporter, s != copy);
@@ -69,22 +85,33 @@ static void test_assign_and_comparison(skiatest::Reporter* reporter) {
// Test that different rects triggers not equal.
s.restore();
+ REPORTER_ASSERT(reporter, 2 == s.getSaveCount());
s.save();
+ REPORTER_ASSERT(reporter, 3 == s.getSaveCount());
+
r = SkRect::MakeLTRB(24, 25, 26, 27);
s.clipDevRect(r, SkRegion::kUnion_Op, doAA);
REPORTER_ASSERT(reporter, s != copy);
// Sanity check
s.restore();
+ REPORTER_ASSERT(reporter, 2 == s.getSaveCount());
+
copy.restore();
+ REPORTER_ASSERT(reporter, 2 == copy.getSaveCount());
REPORTER_ASSERT(reporter, s == copy);
s.restore();
+ REPORTER_ASSERT(reporter, 1 == s.getSaveCount());
copy.restore();
+ REPORTER_ASSERT(reporter, 1 == copy.getSaveCount());
REPORTER_ASSERT(reporter, s == copy);
// Test that different paths triggers not equal.
s.restore();
+ REPORTER_ASSERT(reporter, 0 == s.getSaveCount());
s.save();
+ REPORTER_ASSERT(reporter, 1 == s.getSaveCount());
+
p.addRect(r);
s.clipDevPath(p, SkRegion::kIntersect_Op, doAA);
REPORTER_ASSERT(reporter, s != copy);
@@ -92,9 +119,7 @@ static void test_assign_and_comparison(skiatest::Reporter* reporter) {
static void assert_count(skiatest::Reporter* reporter, const SkClipStack& stack,
int count) {
- REPORTER_ASSERT(reporter, count == stack.getSaveCount());
-
- SkClipStack::B2FIter iter(stack);
+ SkClipStack::B2TIter iter(stack);
int counter = 0;
while (iter.next()) {
counter += 1;
@@ -102,9 +127,66 @@ static void assert_count(skiatest::Reporter* reporter, const SkClipStack& stack,
REPORTER_ASSERT(reporter, count == counter);
}
+static void test_iterators(skiatest::Reporter* reporter) {
+ SkClipStack stack;
+
+ static const SkRect gRects[] = {
+ { 0, 0, 40, 40 },
+ { 60, 0, 100, 40 },
+ { 0, 60, 40, 100 },
+ { 60, 60, 100, 100 }
+ };
+
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gRects); i++) {
+ // the union op will prevent these from being fused together
+ stack.clipDevRect(gRects[i], SkRegion::kUnion_Op, false);
+ }
+
+ assert_count(reporter, stack, 4);
+
+ // bottom to top iteration
+ {
+ const SkClipStack::B2TIter::Clip* clip = NULL;
+
+ SkClipStack::B2TIter iter(stack);
+ int i;
+
+ for (i = 0, clip = iter.next(); clip; ++i, clip = iter.next()) {
+ REPORTER_ASSERT(reporter, *clip->fRect == gRects[i]);
+ }
+
+ SkASSERT(i == 4);
+ }
+
+ // top to bottom iteration
+ {
+ const SkClipStack::Iter::Clip* clip = NULL;
+
+ SkClipStack::Iter iter(stack, SkClipStack::Iter::kTop_IterStart);
+ int i;
+
+ for (i = 3, clip = iter.prev(); clip; --i, clip = iter.prev()) {
+ REPORTER_ASSERT(reporter, *clip->fRect == gRects[i]);
+ }
+
+ SkASSERT(i == -1);
+ }
+
+ // skipToTopmost
+ {
+ const SkClipStack::Iter::Clip*clip = NULL;
+
+ SkClipStack::Iter iter(stack, SkClipStack::Iter::kBottom_IterStart);
+
+ clip = iter.skipToTopmost(SkRegion::kUnion_Op);
+ REPORTER_ASSERT(reporter, *clip->fRect == gRects[3]);
+ }
+}
+
static void TestClipStack(skiatest::Reporter* reporter) {
SkClipStack stack;
+ REPORTER_ASSERT(reporter, 0 == stack.getSaveCount());
assert_count(reporter, stack, 0);
static const SkIRect gRects[] = {
@@ -118,8 +200,8 @@ static void TestClipStack(skiatest::Reporter* reporter) {
}
// all of the above rects should have been intersected, leaving only 1 rect
- SkClipStack::B2FIter iter(stack);
- const SkClipStack::B2FIter::Clip* clip = iter.next();
+ SkClipStack::B2TIter iter(stack);
+ const SkClipStack::B2TIter::Clip* clip = iter.next();
SkRect answer;
answer.iset(25, 25, 75, 75);
@@ -132,9 +214,11 @@ static void TestClipStack(skiatest::Reporter* reporter) {
REPORTER_ASSERT(reporter, !iter.next());
stack.reset();
+ REPORTER_ASSERT(reporter, 0 == stack.getSaveCount());
assert_count(reporter, stack, 0);
test_assign_and_comparison(reporter);
+ test_iterators(reporter);
}
#include "TestClassDef.h"