add tests for SkClipStack
git-svn-id: http://skia.googlecode.com/svn/trunk@828 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/ClipStackTest.cpp b/tests/ClipStackTest.cpp
new file mode 100644
index 0000000..e3c95b4
--- /dev/null
+++ b/tests/ClipStackTest.cpp
@@ -0,0 +1,49 @@
+#include "Test.h"
+#include "SkClipStack.h"
+
+static void assert_count(skiatest::Reporter* reporter, const SkClipStack& stack,
+ int count) {
+ REPORTER_ASSERT(reporter, count == stack.getSaveCount());
+
+ SkClipStack::B2FIter iter(stack);
+ int counter = 0;
+ while (iter.next()) {
+ counter += 1;
+ }
+ REPORTER_ASSERT(reporter, count == counter);
+}
+
+static void TestClipStack(skiatest::Reporter* reporter) {
+ SkClipStack stack;
+
+ assert_count(reporter, stack, 0);
+
+ static const SkIRect gRects[] = {
+ { 0, 0, 100, 100 },
+ { 25, 25, 125, 125 },
+ { 0, 0, 1000, 1000 },
+ { 0, 0, 75, 75 }
+ };
+ for (size_t i = 0; i < SK_ARRAY_COUNT(gRects); i++) {
+ stack.clipDevRect(gRects[i]);
+ }
+
+ // all of the above rects should have been intersected, leaving only 1 rect
+ SkClipStack::B2FIter iter(stack);
+ const SkClipStack::B2FIter::Clip* clip = iter.next();
+ const SkRect answer = { 25, 25, 75, 75 };
+
+ REPORTER_ASSERT(reporter, clip);
+ REPORTER_ASSERT(reporter, clip->fRect);
+ REPORTER_ASSERT(reporter, !clip->fPath);
+ REPORTER_ASSERT(reporter, SkRegion::kIntersect_Op == clip->fOp);
+ REPORTER_ASSERT(reporter, *clip->fRect == answer);
+ // now check that we only had one in our iterator
+ REPORTER_ASSERT(reporter, !iter.next());
+
+ stack.reset();
+ assert_count(reporter, stack, 0);
+}
+
+#include "TestClassDef.h"
+DEFINE_TESTCLASS("ClipStack", TestClipStackClass, TestClipStack)
diff --git a/tests/tests_files.mk b/tests/tests_files.mk
index 40e8880..6dad0af 100644
--- a/tests/tests_files.mk
+++ b/tests/tests_files.mk
@@ -2,6 +2,7 @@
BitmapCopyTest.cpp \
BlitRowTest.cpp \
ClipCubicTest.cpp \
+ ClipStackTest.cpp \
ClipperTest.cpp \
DequeTest.cpp \
FillPathTest.cpp \