reed@google.com | bdee9fc | 2011-02-22 20:17:43 +0000 | [diff] [blame^] | 1 | #include "Test.h" |
| 2 | #include "SkClipStack.h" |
| 3 | |
| 4 | static void assert_count(skiatest::Reporter* reporter, const SkClipStack& stack, |
| 5 | int count) { |
| 6 | REPORTER_ASSERT(reporter, count == stack.getSaveCount()); |
| 7 | |
| 8 | SkClipStack::B2FIter iter(stack); |
| 9 | int counter = 0; |
| 10 | while (iter.next()) { |
| 11 | counter += 1; |
| 12 | } |
| 13 | REPORTER_ASSERT(reporter, count == counter); |
| 14 | } |
| 15 | |
| 16 | static void TestClipStack(skiatest::Reporter* reporter) { |
| 17 | SkClipStack stack; |
| 18 | |
| 19 | assert_count(reporter, stack, 0); |
| 20 | |
| 21 | static const SkIRect gRects[] = { |
| 22 | { 0, 0, 100, 100 }, |
| 23 | { 25, 25, 125, 125 }, |
| 24 | { 0, 0, 1000, 1000 }, |
| 25 | { 0, 0, 75, 75 } |
| 26 | }; |
| 27 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRects); i++) { |
| 28 | stack.clipDevRect(gRects[i]); |
| 29 | } |
| 30 | |
| 31 | // all of the above rects should have been intersected, leaving only 1 rect |
| 32 | SkClipStack::B2FIter iter(stack); |
| 33 | const SkClipStack::B2FIter::Clip* clip = iter.next(); |
| 34 | const SkRect answer = { 25, 25, 75, 75 }; |
| 35 | |
| 36 | REPORTER_ASSERT(reporter, clip); |
| 37 | REPORTER_ASSERT(reporter, clip->fRect); |
| 38 | REPORTER_ASSERT(reporter, !clip->fPath); |
| 39 | REPORTER_ASSERT(reporter, SkRegion::kIntersect_Op == clip->fOp); |
| 40 | REPORTER_ASSERT(reporter, *clip->fRect == answer); |
| 41 | // now check that we only had one in our iterator |
| 42 | REPORTER_ASSERT(reporter, !iter.next()); |
| 43 | |
| 44 | stack.reset(); |
| 45 | assert_count(reporter, stack, 0); |
| 46 | } |
| 47 | |
| 48 | #include "TestClassDef.h" |
| 49 | DEFINE_TESTCLASS("ClipStack", TestClipStackClass, TestClipStack) |