Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1268)

Unified Diff: tests/RegionTest.cpp

Issue 1188293002: Add test for SkRegion::writeToMemory. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/RegionTest.cpp
diff --git a/tests/RegionTest.cpp b/tests/RegionTest.cpp
index acb81809de3bf4788d74a950928c740dfb6062d8..121f16d6ec521454bbf0d534327e25178b21d6dc 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);
+}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698