OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkDeflateWStream.h" | |
9 #include "SkFlate.h" | 8 #include "SkFlate.h" |
10 #include "SkRandom.h" | 9 #include "SkRandom.h" |
11 #include "Test.h" | 10 #include "Test.h" |
12 | 11 |
13 #ifndef SK_NO_FLATE | 12 #ifndef SK_NO_FLATE |
14 | 13 |
15 DEF_TEST(SkDeflateWStream, r) { | 14 DEF_TEST(SkDeflateWStream, r) { |
16 SkRandom random(123456); | 15 SkRandom random(123456); |
17 for (int i = 0; i < 50; ++i) { | 16 for (int i = 0; i < 50; ++i) { |
18 uint32_t size = random.nextULessThan(10000); | 17 uint32_t size = random.nextULessThan(10000); |
19 SkAutoTMalloc<uint8_t> buffer(size); | 18 SkAutoTMalloc<uint8_t> buffer(size); |
20 for (uint32_t i = 0; i < size; ++i) { | 19 for (uint32_t j = 0; j < size; ++j) { |
21 buffer[i] = random.nextU() & 0xff; | 20 buffer[j] = random.nextU() & 0xff; |
22 } | 21 } |
23 | 22 |
24 SkDynamicMemoryWStream dynamicMemoryWStream; | 23 SkDynamicMemoryWStream dynamicMemoryWStream; |
25 { | 24 { |
26 SkDeflateWStream deflateWStream(&dynamicMemoryWStream); | 25 SkDeflateWStream deflateWStream(&dynamicMemoryWStream); |
27 uint32_t j = 0; | 26 uint32_t j = 0; |
28 while (j < size) { | 27 while (j < size) { |
29 uint32_t writeSize = | 28 uint32_t writeSize = |
30 SkTMin(size - j, random.nextRangeU(1, 400)); | 29 SkTMin(size - j, random.nextRangeU(1, 400)); |
31 if (!deflateWStream.write(&buffer[j], writeSize)) { | 30 if (!deflateWStream.write(&buffer[j], writeSize)) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 SkDEBUGCODE(size_t rb =)decompressed->read(&c, sizeof(uint8_t)); | 66 SkDEBUGCODE(size_t rb =)decompressed->read(&c, sizeof(uint8_t)); |
68 SkASSERT(sizeof(uint8_t) == rb); | 67 SkASSERT(sizeof(uint8_t) == rb); |
69 if (buffer[i] != c) { | 68 if (buffer[i] != c) { |
70 ERRORF(r, "Decompression failed at byte %u.", (unsigned)i); | 69 ERRORF(r, "Decompression failed at byte %u.", (unsigned)i); |
71 break; | 70 break; |
72 } | 71 } |
73 } | 72 } |
74 } | 73 } |
75 } | 74 } |
76 #endif // SK_NO_FLATE | 75 #endif // SK_NO_FLATE |
OLD | NEW |