git-svn-id: http://skia.googlecode.com/svn/trunk@6323 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
mike@reedtribe.org 2012-11-07 01:57:32 +00:00
parent b4467e642e
commit 5a7ae4f5e5

View File

@ -9,6 +9,66 @@
#include "SkRegion.h"
#include "SkRandom.h"
static void Union(SkRegion* rgn, const SkIRect& rect) {
rgn->op(rect, SkRegion::kUnion_Op);
}
#define TEST_NO_INTERSECT(rgn, rect) REPORTER_ASSERT(reporter, !rgn.intersects(rect))
#define TEST_INTERSECT(rgn, rect) REPORTER_ASSERT(reporter, rgn.intersects(rect))
#define TEST_NO_CONTAINS(rgn, rect) REPORTER_ASSERT(reporter, rgn.contains(rect))
// inspired by http://code.google.com/p/skia/issues/detail?id=958
//
static void test_fromchrome(skiatest::Reporter* reporter) {
SkRegion r;
Union(&r, SkIRect::MakeXYWH(0, 0, 1, 1));
TEST_NO_INTERSECT(r, SkIRect::MakeXYWH(0, 0, 0, 0));
TEST_INTERSECT(r, SkIRect::MakeXYWH(0, 0, 2, 2));
TEST_INTERSECT(r, SkIRect::MakeXYWH(-1, 0, 2, 2));
TEST_INTERSECT(r, SkIRect::MakeXYWH(-1, -1, 2, 2));
TEST_INTERSECT(r, SkIRect::MakeXYWH(0, -1, 2, 2));
TEST_INTERSECT(r, SkIRect::MakeXYWH(-1, -1, 3, 3));
Union(&r, SkIRect::MakeXYWH(0, 0, 3, 3));
Union(&r, SkIRect::MakeXYWH(10, 0, 3, 3));
Union(&r, SkIRect::MakeXYWH(0, 10, 13, 3));
TEST_INTERSECT(r, SkIRect::MakeXYWH(-1, -1, 2, 2));
TEST_INTERSECT(r, SkIRect::MakeXYWH(2, -1, 2, 2));
TEST_INTERSECT(r, SkIRect::MakeXYWH(2, 2, 2, 2));
TEST_INTERSECT(r, SkIRect::MakeXYWH(-1, 2, 2, 2));
TEST_INTERSECT(r, SkIRect::MakeXYWH(9, -1, 2, 2));
TEST_INTERSECT(r, SkIRect::MakeXYWH(12, -1, 2, 2));
TEST_INTERSECT(r, SkIRect::MakeXYWH(12, 2, 2, 2));
TEST_INTERSECT(r, SkIRect::MakeXYWH(9, 2, 2, 2));
TEST_INTERSECT(r, SkIRect::MakeXYWH(0, -1, 13, 5));
TEST_INTERSECT(r, SkIRect::MakeXYWH(1, -1, 11, 5));
TEST_INTERSECT(r, SkIRect::MakeXYWH(2, -1, 9, 5));
TEST_INTERSECT(r, SkIRect::MakeXYWH(2, -1, 8, 5));
TEST_INTERSECT(r, SkIRect::MakeXYWH(3, -1, 8, 5));
TEST_INTERSECT(r, SkIRect::MakeXYWH(0, 1, 13, 1));
TEST_INTERSECT(r, SkIRect::MakeXYWH(1, 1, 11, 1));
TEST_INTERSECT(r, SkIRect::MakeXYWH(2, 1, 9, 1));
TEST_INTERSECT(r, SkIRect::MakeXYWH(2, 1, 8, 1));
TEST_INTERSECT(r, SkIRect::MakeXYWH(3, 1, 8, 1));
TEST_INTERSECT(r, SkIRect::MakeXYWH(0, 0, 13, 13));
TEST_INTERSECT(r, SkIRect::MakeXYWH(0, 1, 13, 11));
TEST_INTERSECT(r, SkIRect::MakeXYWH(0, 2, 13, 9));
TEST_INTERSECT(r, SkIRect::MakeXYWH(0, 2, 13, 8));
// These test SkRegion::contains(Rect) and SkRegion::contains(Region)
SkRegion container;
Union(&container, SkIRect::MakeXYWH(0, 0, 40, 20));
Union(&container, SkIRect::MakeXYWH(30, 20, 10, 20));
TEST_NO_CONTAINS(container, SkIRect::MakeXYWH(0, 0, 10, 39));
TEST_NO_CONTAINS(container, SkIRect::MakeXYWH(29, 0, 10, 39));
}
static void test_empties(skiatest::Reporter* reporter) {
SkRegion valid(SkIRect::MakeWH(10, 10));
SkRegion empty, empty2;
@ -185,6 +245,7 @@ static void TestRegion(skiatest::Reporter* reporter) {
test_proc(reporter, contains_proc);
test_proc(reporter, intersects_proc);
test_empties(reporter);
test_fromchrome(reporter);
}
#include "TestClassDef.h"