Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(669)

Side by Side Diff: tests/DeflateWStream.cpp

Issue 918813002: PDF: Add (low-memory) SkPDFBitmap class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-02-11 (Wednesday) 18:49:13 EST Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/pdf/SkPDFImage.cpp ('K') | « src/pdf/SkPDFImage.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "Test.h"
9 #include "SkDeflateWStream.h"
10 #include "SkFlate.h"
11 #include "SkRandom.h"
12
13 DEF_TEST(SkDeflateWStream, r) {
14 if (!SkFlate::HaveFlate()) {
mtklein 2015/02/12 00:21:46 Why do we pretend SkFlate::HaveFlate() is a runtim
hal.canary 2015/02/12 21:28:03 I agree. I'll change this at some time. I think
15 return;
16 }
17 SkRandom random(123456);
18 for (int i = 0; i < 50; ++i) {
19 uint32_t size = random.nextULessThan(10000);
20 SkAutoTMalloc<uint8_t> buffer(size);
21 for (uint32_t i = 0; i < size; ++i) {
22 buffer[i] = random.nextU() & 0xff;
23 }
24
25 SkDynamicMemoryWStream dynamicMemoryWStream;
26 {
27 SkDeflateWStream deflateWStream(&dynamicMemoryWStream);
28 uint32_t j = 0;
29 while (j < size) {
30 uint32_t writeSize =
31 SkTMin(size - j, random.nextRangeU(1, 400));
32 if (!deflateWStream.write(&buffer[j], writeSize)) {
33 ERRORF(r, "something went wrong.");
34 return;
35 }
36 j += writeSize;
37 }
38 }
39 SkAutoTDelete<SkStreamAsset> compressed(
40 dynamicMemoryWStream.detachAsStream());
41
42 SkDynamicMemoryWStream decompressedDynamicMemoryWStream;
43 SkAssertResult(SkFlate::Inflate(compressed,
44 &decompressedDynamicMemoryWStream));
45
46 SkAutoTDelete<SkStreamAsset> decompressed(
47 decompressedDynamicMemoryWStream.detachAsStream());
48
49 if (decompressed->getLength() != size) {
50 ERRORF(r, "Decompression failed to get right size [%d]."
51 " %u != %u", i, (unsigned)(decompressed->getLength()),
52 (unsigned)size);
53 SkString s = SkStringPrintf("/tmp/deftst_compressed_%d", i);
54 SkFILEWStream o(s.c_str());
55 o.writeStream(compressed.get(), compressed->getLength());
56 compressed->rewind();
57
58 s = SkStringPrintf("/tmp/deftst_input_%d", i);
59 SkFILEWStream o2(s.c_str());
60 o2.write(&buffer[0], size);
61
62 continue;
63 }
64 uint32_t minLength = SkTMin(size,
65 (uint32_t)(decompressed->getLength()));
66 for (uint32_t i = 0; i < minLength; ++i) {
67 uint8_t c;
68 SkDEBUGCODE(size_t rb =)decompressed->read(&c, sizeof(uint8_t));
69 SkASSERT(sizeof(uint8_t) == rb);
70 if (buffer[i] != c) {
71 ERRORF(r, "Decompression failed at byte %u.", (unsigned)i);
72 break;
73 }
74 }
75 }
76 }
OLDNEW
« src/pdf/SkPDFImage.cpp ('K') | « src/pdf/SkPDFImage.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698