| 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 "Resources.h" | 8 #include "Resources.h" |
| 9 #include "SkData.h" | 9 #include "SkData.h" |
| 10 #include "SkFrontBufferedStream.h" | 10 #include "SkFrontBufferedStream.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 stream3->rewind(); | 110 stream3->rewind(); |
| 111 test_loop_stream(reporter, stream3.get(), s, 26, 100); | 111 test_loop_stream(reporter, stream3.get(), s, 26, 100); |
| 112 } | 112 } |
| 113 | 113 |
| 114 for (i = 0; i < 100; i++) { | 114 for (i = 0; i < 100; i++) { |
| 115 REPORTER_ASSERT(reporter, ds.write(s, 26)); | 115 REPORTER_ASSERT(reporter, ds.write(s, 26)); |
| 116 } | 116 } |
| 117 REPORTER_ASSERT(reporter, ds.getOffset() == 100 * 26); | 117 REPORTER_ASSERT(reporter, ds.getOffset() == 100 * 26); |
| 118 | 118 |
| 119 { | 119 { |
| 120 SkAutoTUnref<SkData> data(ds.copyToData()); | 120 sk_sp<SkData> data(ds.copyToData()); |
| 121 REPORTER_ASSERT(reporter, 100 * 26 == data->size()); | 121 REPORTER_ASSERT(reporter, 100 * 26 == data->size()); |
| 122 REPORTER_ASSERT(reporter, memcmp(dst, data->data(), data->size()) == 0); | 122 REPORTER_ASSERT(reporter, memcmp(dst, data->data(), data->size()) == 0); |
| 123 } | 123 } |
| 124 | 124 |
| 125 { | 125 { |
| 126 // Test that this works after a copyToData. | 126 // Test that this works after a copyToData. |
| 127 SkAutoTDelete<SkStreamAsset> stream(ds.detachAsStream()); | 127 SkAutoTDelete<SkStreamAsset> stream(ds.detachAsStream()); |
| 128 REPORTER_ASSERT(reporter, ds.getOffset() == 0); | 128 REPORTER_ASSERT(reporter, ds.getOffset() == 0); |
| 129 test_loop_stream(reporter, stream.get(), s, 26, 100); | 129 test_loop_stream(reporter, stream.get(), s, 26, 100); |
| 130 | 130 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 | 397 |
| 398 static void stream_copy_test(skiatest::Reporter* reporter, | 398 static void stream_copy_test(skiatest::Reporter* reporter, |
| 399 const void* srcData, | 399 const void* srcData, |
| 400 size_t N, | 400 size_t N, |
| 401 SkStream* stream) { | 401 SkStream* stream) { |
| 402 SkDynamicMemoryWStream tgt; | 402 SkDynamicMemoryWStream tgt; |
| 403 if (!SkStreamCopy(&tgt, stream)) { | 403 if (!SkStreamCopy(&tgt, stream)) { |
| 404 ERRORF(reporter, "SkStreamCopy failed"); | 404 ERRORF(reporter, "SkStreamCopy failed"); |
| 405 return; | 405 return; |
| 406 } | 406 } |
| 407 SkAutoTUnref<SkData> data(tgt.copyToData()); | 407 sk_sp<SkData> data(tgt.copyToData()); |
| 408 tgt.reset(); | 408 tgt.reset(); |
| 409 if (data->size() != N) { | 409 if (data->size() != N) { |
| 410 ERRORF(reporter, "SkStreamCopy incorrect size"); | 410 ERRORF(reporter, "SkStreamCopy incorrect size"); |
| 411 return; | 411 return; |
| 412 } | 412 } |
| 413 if (0 != memcmp(data->data(), srcData, N)) { | 413 if (0 != memcmp(data->data(), srcData, N)) { |
| 414 ERRORF(reporter, "SkStreamCopy bad copy"); | 414 ERRORF(reporter, "SkStreamCopy bad copy"); |
| 415 } | 415 } |
| 416 } | 416 } |
| 417 | 417 |
| 418 DEF_TEST(StreamCopy, reporter) { | 418 DEF_TEST(StreamCopy, reporter) { |
| 419 SkRandom random(123456); | 419 SkRandom random(123456); |
| 420 static const int N = 10000; | 420 static const int N = 10000; |
| 421 SkAutoTMalloc<uint8_t> src((size_t)N); | 421 SkAutoTMalloc<uint8_t> src((size_t)N); |
| 422 for (int j = 0; j < N; ++j) { | 422 for (int j = 0; j < N; ++j) { |
| 423 src[j] = random.nextU() & 0xff; | 423 src[j] = random.nextU() & 0xff; |
| 424 } | 424 } |
| 425 // SkStreamCopy had two code paths; this test both. | 425 // SkStreamCopy had two code paths; this test both. |
| 426 DumbStream dumbStream(src.get(), (size_t)N); | 426 DumbStream dumbStream(src.get(), (size_t)N); |
| 427 stream_copy_test(reporter, src, N, &dumbStream); | 427 stream_copy_test(reporter, src, N, &dumbStream); |
| 428 SkMemoryStream smartStream(src.get(), (size_t)N); | 428 SkMemoryStream smartStream(src.get(), (size_t)N); |
| 429 stream_copy_test(reporter, src, N, &smartStream); | 429 stream_copy_test(reporter, src, N, &smartStream); |
| 430 } | 430 } |
| 431 | 431 |
| 432 DEF_TEST(StreamEmptyStreamMemoryBase, r) { | 432 DEF_TEST(StreamEmptyStreamMemoryBase, r) { |
| 433 SkDynamicMemoryWStream tmp; | 433 SkDynamicMemoryWStream tmp; |
| 434 SkAutoTDelete<SkStreamAsset> asset(tmp.detachAsStream()); | 434 SkAutoTDelete<SkStreamAsset> asset(tmp.detachAsStream()); |
| 435 REPORTER_ASSERT(r, nullptr == asset->getMemoryBase()); | 435 REPORTER_ASSERT(r, nullptr == asset->getMemoryBase()); |
| 436 } | 436 } |
| OLD | NEW |