OLD | NEW |
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 Loading... |
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 } |
OLD | NEW |