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

Side by Side Diff: tests/DeflateWStream.cpp

Issue 1278403006: SkPDF: clean up overuse of SK_SUPPORT_PDF (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-11 (Tuesday) 16:25:36 EDT Created 5 years, 4 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
« no previous file with comments | « tests/CanvasTest.cpp ('k') | tests/DocumentTest.cpp » ('j') | 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 "SkFlate.h"
9 #include "SkRandom.h"
10 #include "Test.h"
11
12 #if SK_SUPPORT_PDF
13
14 DEF_TEST(SkDeflateWStream, r) {
15 SkRandom random(123456);
16 for (int i = 0; i < 50; ++i) {
17 uint32_t size = random.nextULessThan(10000);
18 SkAutoTMalloc<uint8_t> buffer(size);
19 for (uint32_t j = 0; j < size; ++j) {
20 buffer[j] = random.nextU() & 0xff;
21 }
22
23 SkDynamicMemoryWStream dynamicMemoryWStream;
24 {
25 SkDeflateWStream deflateWStream(&dynamicMemoryWStream);
26 uint32_t j = 0;
27 while (j < size) {
28 uint32_t writeSize =
29 SkTMin(size - j, random.nextRangeU(1, 400));
30 if (!deflateWStream.write(&buffer[j], writeSize)) {
31 ERRORF(r, "something went wrong.");
32 return;
33 }
34 j += writeSize;
35 }
36 }
37 SkAutoTDelete<SkStreamAsset> compressed(
38 dynamicMemoryWStream.detachAsStream());
39
40 SkDynamicMemoryWStream decompressedDynamicMemoryWStream;
41 SkAssertResult(SkFlate::Inflate(compressed,
42 &decompressedDynamicMemoryWStream));
43
44 SkAutoTDelete<SkStreamAsset> decompressed(
45 decompressedDynamicMemoryWStream.detachAsStream());
46
47 if (decompressed->getLength() != size) {
48 ERRORF(r, "Decompression failed to get right size [%d]."
49 " %u != %u", i, (unsigned)(decompressed->getLength()),
50 (unsigned)size);
51 SkString s = SkStringPrintf("/tmp/deftst_compressed_%d", i);
52 SkFILEWStream o(s.c_str());
53 o.writeStream(compressed.get(), compressed->getLength());
54 compressed->rewind();
55
56 s = SkStringPrintf("/tmp/deftst_input_%d", i);
57 SkFILEWStream o2(s.c_str());
58 o2.write(&buffer[0], size);
59
60 continue;
61 }
62 uint32_t minLength = SkTMin(size,
63 (uint32_t)(decompressed->getLength()));
64 for (uint32_t i = 0; i < minLength; ++i) {
65 uint8_t c;
66 SkDEBUGCODE(size_t rb =)decompressed->read(&c, sizeof(uint8_t));
67 SkASSERT(sizeof(uint8_t) == rb);
68 if (buffer[i] != c) {
69 ERRORF(r, "Decompression failed at byte %u.", (unsigned)i);
70 break;
71 }
72 }
73 }
74 }
75 #endif // SK_SUPPORT_PDF
OLDNEW
« no previous file with comments | « tests/CanvasTest.cpp ('k') | tests/DocumentTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698