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 "SkRandom.h" | 8 #include "SkRandom.h" |
9 #include "SkReader32.h" | 9 #include "SkReader32.h" |
10 #include "SkWriter32.h" | 10 #include "SkWriter32.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 writer.reset(); | 273 writer.reset(); |
274 testOverwriteT(reporter, &writer); | 274 testOverwriteT(reporter, &writer); |
275 } | 275 } |
276 | 276 |
277 DEF_TEST(Writer32_misc, reporter) { | 277 DEF_TEST(Writer32_misc, reporter) { |
278 test_reserve(reporter); | 278 test_reserve(reporter); |
279 test_string_null(reporter); | 279 test_string_null(reporter); |
280 test_ptr(reporter); | 280 test_ptr(reporter); |
281 test_rewind(reporter); | 281 test_rewind(reporter); |
282 } | 282 } |
| 283 |
| 284 DEF_TEST(Writer32_snapshot, reporter) { |
| 285 int32_t array[] = { 1, 2, 4, 11 }; |
| 286 SkSWriter32<sizeof(array) + 4> writer; |
| 287 writer.write(array, sizeof(array)); |
| 288 check_contents(reporter, writer, array, sizeof(array)); |
| 289 const void* beforeData = writer.contiguousArray(); |
| 290 SkAutoDataUnref snapshot(writer.snapshotAsData()); |
| 291 // check the snapshot forced a copy of the static data |
| 292 REPORTER_ASSERT(reporter, snapshot->data() != beforeData); |
| 293 REPORTER_ASSERT(reporter, snapshot->size() == writer.bytesWritten()); |
| 294 } |
| 295 |
| 296 DEF_TEST(Writer32_snapshot_dynamic, reporter) { |
| 297 int32_t array[] = { 1, 2, 4, 11 }; |
| 298 SkWriter32 writer; |
| 299 writer.write(array, sizeof(array)); |
| 300 check_contents(reporter, writer, array, sizeof(array)); |
| 301 // force a capacity increase so we can test COW behaviour |
| 302 writer.write(array, sizeof(array)); |
| 303 writer.rewindToOffset(sizeof(array)); |
| 304 const void* beforeData = writer.contiguousArray(); |
| 305 SkAutoDataUnref snapshot(writer.snapshotAsData()); |
| 306 // check the snapshot still points to the same data as the writer |
| 307 REPORTER_ASSERT(reporter, writer.contiguousArray() == beforeData); |
| 308 REPORTER_ASSERT(reporter, snapshot->data() == beforeData); |
| 309 REPORTER_ASSERT(reporter, snapshot->size() == writer.bytesWritten()); |
| 310 // write more data that would fit in the buffer |
| 311 writer.write(array, sizeof(array)); |
| 312 // test it triggered COW anyway |
| 313 REPORTER_ASSERT(reporter, writer.contiguousArray() != beforeData); |
| 314 } |
| 315 |
OLD | NEW |