diff options
author | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-02-22 20:17:43 +0000 |
---|---|---|
committer | reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-02-22 20:17:43 +0000 |
commit | bdee9fc778d4387d805d717f2cd7fc7074991fdb (patch) | |
tree | 1a64bc08b1274e74456cb1e0992d7c4f98cf87dd /tests/ClipStackTest.cpp | |
parent | f9e71320758a4d3a94b58676abad7534d0b160bf (diff) |
add tests for SkClipStack
git-svn-id: http://skia.googlecode.com/svn/trunk@828 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/ClipStackTest.cpp')
-rw-r--r-- | tests/ClipStackTest.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/ClipStackTest.cpp b/tests/ClipStackTest.cpp new file mode 100644 index 0000000000..e3c95b417d --- /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) |