diff options
author | mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-11-07 01:57:32 +0000 |
---|---|---|
committer | mike@reedtribe.org <mike@reedtribe.org@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-11-07 01:57:32 +0000 |
commit | 5a7ae4f5e5de3be99210dd9df89794f52c7c6d6e (patch) | |
tree | 3b96a500fdaabebb9329405f68772a441de8250e /tests/RegionTest.cpp | |
parent | b4467e642e1c0772940cb266cae46f5fda399952 (diff) |
add SkRegion tests, inspired by http://code.google.com/p/skia/issues/detail?id=958
git-svn-id: http://skia.googlecode.com/svn/trunk@6323 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/RegionTest.cpp')
-rw-r--r-- | tests/RegionTest.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/RegionTest.cpp b/tests/RegionTest.cpp index 8e66502f5e..f3d1e0b5a1 100644 --- a/tests/RegionTest.cpp +++ b/tests/RegionTest.cpp @@ -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" |