From 7ab71baf65eb7c5ee5b0025953baa5395c0fc5d4 Mon Sep 17 00:00:00 2001 From: "reed@google.com" Date: Wed, 2 May 2012 16:09:21 +0000 Subject: [PATCH] add more tests around contains for rects and regions git-svn-id: http://skia.googlecode.com/svn/trunk@3818 2bbb7eff-a529-9590-31e7-b0007b416f81 --- tests/RegionTest.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/RegionTest.cpp b/tests/RegionTest.cpp index e85fca7645..23ac9b7ae9 100644 --- a/tests/RegionTest.cpp +++ b/tests/RegionTest.cpp @@ -52,16 +52,44 @@ static bool slow_contains(const SkRegion& outer, const SkRegion& inner) { return outer == tmp; } +static bool slow_contains(const SkRegion& outer, const SkIRect& r) { + SkRegion tmp; + tmp.op(outer, SkRegion(r), SkRegion::kUnion_Op); + return outer == tmp; +} + static bool slow_intersects(const SkRegion& outer, const SkRegion& inner) { SkRegion tmp; return tmp.op(outer, inner, SkRegion::kIntersect_Op); } +static void test_contains_iter(skiatest::Reporter* reporter, const SkRegion& rgn) { + SkRegion::Iterator iter(rgn); + while (!iter.done()) { + SkIRect r = iter.rect(); + REPORTER_ASSERT(reporter, rgn.contains(r)); + r.inset(-1, -1); + REPORTER_ASSERT(reporter, !rgn.contains(r)); + iter.next(); + } +} + static void contains_proc(skiatest::Reporter* reporter, const SkRegion& a, const SkRegion& b) { + // test rgn bool c0 = a.contains(b); bool c1 = slow_contains(a, b); REPORTER_ASSERT(reporter, c0 == c1); + + // test rect + SkIRect r = a.getBounds(); + r.inset(r.width()/4, r.height()/4); + c0 = a.contains(r); + c1 = slow_contains(a, r); + REPORTER_ASSERT(reporter, c0 == c1); + + test_contains_iter(reporter, a); + test_contains_iter(reporter, b); } static void intersects_proc(skiatest::Reporter* reporter,