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
This commit is contained in:
scroggo 2015-06-18 06:16:36 -07:00 committed by Commit bot
parent bcd7ab5c0d
commit d49f48ddf7

View File

@ -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);
}