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 "SkDeflate.h" | 8 #include "SkDeflate.h" |
9 #include "SkRandom.h" | 9 #include "SkRandom.h" |
10 #include "Test.h" | 10 #include "Test.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 inflateEnd(&flateData); | 95 inflateEnd(&flateData); |
96 if (rc != Z_STREAM_END) { | 96 if (rc != Z_STREAM_END) { |
97 ERRORF(reporter, "Zlib: inflateEnd failed"); | 97 ERRORF(reporter, "Zlib: inflateEnd failed"); |
98 return nullptr; | 98 return nullptr; |
99 } | 99 } |
100 return decompressedDynamicMemoryWStream.detachAsStream(); | 100 return decompressedDynamicMemoryWStream.detachAsStream(); |
101 } | 101 } |
102 } // namespace | 102 } // namespace |
103 | 103 |
104 DEF_TEST(SkDeflateWStream, r) { | 104 DEF_TEST(SkPDF_DeflateWStream, r) { |
105 SkRandom random(123456); | 105 SkRandom random(123456); |
106 for (int i = 0; i < 50; ++i) { | 106 for (int i = 0; i < 50; ++i) { |
107 uint32_t size = random.nextULessThan(10000); | 107 uint32_t size = random.nextULessThan(10000); |
108 SkAutoTMalloc<uint8_t> buffer(size); | 108 SkAutoTMalloc<uint8_t> buffer(size); |
109 for (uint32_t j = 0; j < size; ++j) { | 109 for (uint32_t j = 0; j < size; ++j) { |
110 buffer[j] = random.nextU() & 0xff; | 110 buffer[j] = random.nextU() & 0xff; |
111 } | 111 } |
112 | 112 |
113 SkDynamicMemoryWStream dynamicMemoryWStream; | 113 SkDynamicMemoryWStream dynamicMemoryWStream; |
114 { | 114 { |
115 SkDeflateWStream deflateWStream(&dynamicMemoryWStream); | 115 SkDeflateWStream deflateWStream(&dynamicMemoryWStream); |
116 uint32_t j = 0; | 116 uint32_t j = 0; |
117 while (j < size) { | 117 while (j < size) { |
118 uint32_t writeSize = | 118 uint32_t writeSize = |
119 SkTMin(size - j, random.nextRangeU(1, 400)); | 119 SkTMin(size - j, random.nextRangeU(1, 400)); |
120 if (!deflateWStream.write(&buffer[j], writeSize)) { | 120 if (!deflateWStream.write(&buffer[j], writeSize)) { |
121 ERRORF(r, "something went wrong."); | 121 ERRORF(r, "something went wrong."); |
122 return; | 122 return; |
123 } | 123 } |
124 j += writeSize; | 124 j += writeSize; |
125 } | 125 } |
| 126 REPORTER_ASSERT(r, deflateWStream.bytesWritten() == size); |
126 } | 127 } |
127 SkAutoTDelete<SkStreamAsset> compressed( | 128 SkAutoTDelete<SkStreamAsset> compressed( |
128 dynamicMemoryWStream.detachAsStream()); | 129 dynamicMemoryWStream.detachAsStream()); |
129 SkAutoTDelete<SkStreamAsset> decompressed(stream_inflate(r, compressed))
; | 130 SkAutoTDelete<SkStreamAsset> decompressed(stream_inflate(r, compressed))
; |
130 | 131 |
131 if (!decompressed) { | 132 if (!decompressed) { |
132 ERRORF(r, "Decompression failed."); | 133 ERRORF(r, "Decompression failed."); |
133 return; | 134 return; |
134 } | 135 } |
135 if (decompressed->getLength() != size) { | 136 if (decompressed->getLength() != size) { |
(...skipping 16 matching lines...) Expand all Loading... |
152 for (uint32_t i = 0; i < minLength; ++i) { | 153 for (uint32_t i = 0; i < minLength; ++i) { |
153 uint8_t c; | 154 uint8_t c; |
154 SkDEBUGCODE(size_t rb =)decompressed->read(&c, sizeof(uint8_t)); | 155 SkDEBUGCODE(size_t rb =)decompressed->read(&c, sizeof(uint8_t)); |
155 SkASSERT(sizeof(uint8_t) == rb); | 156 SkASSERT(sizeof(uint8_t) == rb); |
156 if (buffer[i] != c) { | 157 if (buffer[i] != c) { |
157 ERRORF(r, "Decompression failed at byte %u.", (unsigned)i); | 158 ERRORF(r, "Decompression failed at byte %u.", (unsigned)i); |
158 break; | 159 break; |
159 } | 160 } |
160 } | 161 } |
161 } | 162 } |
| 163 SkDeflateWStream emptyDeflateWStream(nullptr); |
| 164 REPORTER_ASSERT(r, !emptyDeflateWStream.writeText("FOO")); |
162 } | 165 } |
OLD | NEW |