add more tests around contains for rects and regions

git-svn-id: http://skia.googlecode.com/svn/trunk@3818 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2012-05-02 16:09:21 +00:00
parent 47ab504d49
commit 7ab71baf65

View File

@ -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,