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 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 testOverwriteT(reporter, &writer); | 271 testOverwriteT(reporter, &writer); |
272 } | 272 } |
273 | 273 |
274 DEF_TEST(Writer32_misc, reporter) { | 274 DEF_TEST(Writer32_misc, reporter) { |
275 test_reserve(reporter); | 275 test_reserve(reporter); |
276 test_string_null(reporter); | 276 test_string_null(reporter); |
277 test_ptr(reporter); | 277 test_ptr(reporter); |
278 test_rewind(reporter); | 278 test_rewind(reporter); |
279 } | 279 } |
280 | 280 |
| 281 DEF_TEST(Writer32_data, reporter) { |
| 282 const char* str = "0123456789"; |
| 283 SkAutoTUnref<SkData> data0(SkData::NewWithCString(str)); |
| 284 SkAutoTUnref<SkData> data1(SkData::NewEmpty()); |
| 285 |
| 286 const size_t sizes[] = { |
| 287 SkWriter32::WriteDataSize(nullptr), |
| 288 SkWriter32::WriteDataSize(data0), |
| 289 SkWriter32::WriteDataSize(data1), |
| 290 }; |
| 291 |
| 292 SkSWriter32<1000> writer; |
| 293 size_t sizeWritten = 0; |
| 294 |
| 295 writer.writeData(nullptr); |
| 296 sizeWritten += sizes[0]; |
| 297 REPORTER_ASSERT(reporter, sizeWritten == writer.bytesWritten()); |
| 298 |
| 299 writer.writeData(data0); |
| 300 sizeWritten += sizes[1]; |
| 301 REPORTER_ASSERT(reporter, sizeWritten == writer.bytesWritten()); |
| 302 |
| 303 writer.writeData(data1); |
| 304 sizeWritten += sizes[2]; |
| 305 REPORTER_ASSERT(reporter, sizeWritten == writer.bytesWritten()); |
| 306 |
| 307 SkAutoTUnref<SkData> result(writer.snapshotAsData()); |
| 308 |
| 309 SkReader32 reader(result->data(), result->size()); |
| 310 SkAutoTUnref<SkData> d0(reader.readData()), |
| 311 d1(reader.readData()), |
| 312 d2(reader.readData()); |
| 313 |
| 314 REPORTER_ASSERT(reporter, 0 == d0->size()); |
| 315 REPORTER_ASSERT(reporter, strlen(str)+1 == d1->size()); |
| 316 REPORTER_ASSERT(reporter, !memcmp(str, d1->data(), strlen(str)+1)); |
| 317 REPORTER_ASSERT(reporter, 0 == d2->size()); |
| 318 |
| 319 REPORTER_ASSERT(reporter, reader.offset() == sizeWritten); |
| 320 REPORTER_ASSERT(reporter, reader.eof()); |
| 321 } |
OLD | NEW |