diff options
author | 2015-06-18 06:16:36 -0700 | |
---|---|---|
committer | 2015-06-18 06:16:36 -0700 | |
commit | d49f48ddf70cb1afcf13b7654457de8a85c12ad2 (patch) | |
tree | 0eb7986e225f65db4151872f1d16aa59e93e8464 | |
parent | bcd7ab5c0d0e5c3432a9aaeb44f1b703fea94282 (diff) |
Add test for SkRegion::writeToMemory.
When calling SkRegion::writeToMemory(NULL), it should return the same
number of bytes that it writes when calling
SkRegion::writeToMemory(buffer). Add a test to confirm this.
BUG=b/21271229
Review URL: https://codereview.chromium.org/1188293002
-rw-r--r-- | tests/RegionTest.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/RegionTest.cpp b/tests/RegionTest.cpp index acb81809de..121f16d6ec 100644 --- a/tests/RegionTest.cpp +++ b/tests/RegionTest.cpp @@ -262,3 +262,31 @@ DEF_TEST(Region, reporter) { test_empties(reporter); test_fromchrome(reporter); } + +// Test that writeToMemory reports the same number of bytes whether there was a +// buffer to write to or not. +static void test_write(const SkRegion& region, skiatest::Reporter* r) { + const size_t bytesNeeded = region.writeToMemory(NULL); + SkAutoMalloc storage(bytesNeeded); + const size_t bytesWritten = region.writeToMemory(storage.get()); + REPORTER_ASSERT(r, bytesWritten == bytesNeeded); +} + +DEF_TEST(Region_writeToMemory, r) { + // Test an empty region. + SkRegion region; + REPORTER_ASSERT(r, region.isEmpty()); + test_write(region, r); + + // Test a rectangular region + bool nonEmpty = region.setRect(0, 0, 50, 50); + REPORTER_ASSERT(r, nonEmpty); + REPORTER_ASSERT(r, region.isRect()); + test_write(region, r); + + // Test a complex region + nonEmpty = region.op(50, 50, 100, 100, SkRegion::kUnion_Op); + REPORTER_ASSERT(r, nonEmpty); + REPORTER_ASSERT(r, region.isComplex()); + test_write(region, r); +} |