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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkPath.h" 8 #include "SkPath.h"
9 #include "SkRandom.h" 9 #include "SkRandom.h"
10 #include "SkRegion.h" 10 #include "SkRegion.h"
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 rand_rect(&rect[j], rand); 255 rand_rect(&rect[j], rand);
256 } 256 }
257 REPORTER_ASSERT(reporter, test_rects(rect, N)); 257 REPORTER_ASSERT(reporter, test_rects(rect, N));
258 } 258 }
259 259
260 test_proc(reporter, contains_proc); 260 test_proc(reporter, contains_proc);
261 test_proc(reporter, intersects_proc); 261 test_proc(reporter, intersects_proc);
262 test_empties(reporter); 262 test_empties(reporter);
263 test_fromchrome(reporter); 263 test_fromchrome(reporter);
264 } 264 }
265
266 // Test that writeToMemory reports the same number of bytes whether there was a
267 // buffer to write to or not.
268 static void test_write(const SkRegion& region, skiatest::Reporter* r) {
269 const size_t bytesNeeded = region.writeToMemory(NULL);
270 SkAutoMalloc storage(bytesNeeded);
271 const size_t bytesWritten = region.writeToMemory(storage.get());
272 REPORTER_ASSERT(r, bytesWritten == bytesNeeded);
273 }
274
275 DEF_TEST(Region_writeToMemory, r) {
276 // Test an empty region.
277 SkRegion region;
278 REPORTER_ASSERT(r, region.isEmpty());
279 test_write(region, r);
280
281 // Test a rectangular region
282 bool nonEmpty = region.setRect(0, 0, 50, 50);
283 REPORTER_ASSERT(r, nonEmpty);
284 REPORTER_ASSERT(r, region.isRect());
285 test_write(region, r);
286
287 // Test a complex region
288 nonEmpty = region.op(50, 50, 100, 100, SkRegion::kUnion_Op);
289 REPORTER_ASSERT(r, nonEmpty);
290 REPORTER_ASSERT(r, region.isComplex());
291 test_write(region, r);
292 }
OLDNEW
« 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