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

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_decode_unittest.cpp

Issue 845313006: Add small flate decode unit test. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Address comments. Created 5 years, 9 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 | « BUILD.gn ('k') | pdfium.gyp » ('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 // Copyright 2015 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <cstring>
6 #include <string>
7
8 #include "../../../../fpdfsdk/include/fpdfview.h"
9 #include "../../../../testing/fx_string_testhelpers.h"
10 #include "../../../include/fxcrt/fx_basic.h"
11 #include "../../../include/fpdfapi/fpdf_parser.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 // NOTE: python's zlib.compress() and zlib.decompress() may be useful for
15 // external validation of the FlateEncode/FlateDecode test cases.
16
17 #define TEST_CASE(input_literal, expected_literal) \
18 { (const unsigned char*)input_literal, sizeof(input_literal) - 1, \
19 (const unsigned char*)expected_literal, sizeof(expected_literal) - 1 }
20
21 TEST(ParserDecode, FlateEncode) {
22 struct FlateEncodeCase {
23 const unsigned char* input;
24 unsigned int input_size;
25 const unsigned char* expected;
26 unsigned int expected_size;
27 } flate_encode_cases[] = {
28 TEST_CASE("", "\x78\x9c\x03\x00\x00\x00\x00\x01"),
29 TEST_CASE(" ", "\x78\x9c\x53\x00\x00\x00\x21\x00\x21"),
30 TEST_CASE("123", "\x78\x9c\x33\x34\x32\x06\x00\01\x2d\x00\x97"),
31 TEST_CASE("\x00\xff", "\x78\x9c\x63\xf8\x0f\x00\x01\x01\x01\x00"),
32 TEST_CASE("1 0 0 -1 29 763 cm\n0 0 555 735 re\nW n\nq\n0 0 555 734.394 re\n"
33 "W n\nq\n0.8009 0 0 0.8009 0 0 cm\n1 1 1 RG 1 1 1 rg\n/G0 gs\n"
34 "0 0 693 917 re\nf\nQ\nQ\n"
35 ,
36 "\x78\x9c\x33\x54\x30\x00\x42\x5d\x43\x05\x23\x4b\x05\x73\x33\x63"
37 "\x85\xe4\x5c\x2e\x90\x80\xa9\xa9\xa9\x82\xb9\xb1\xa9\x42\x51\x2a"
38 "\x57\xb8\x42\x1e\x57\x21\x92\xa0\x89\x9e\xb1\xa5\x09\x92\x84\x9e"
39 "\x85\x81\x81\x25\xd8\x14\x24\x26\xd0\x18\x43\x05\x10\x0c\x72\x57"
40 "\x80\x30\x8a\xd2\xb9\xf4\xdd\x0d\x14\xd2\x8b\xc1\x46\x99\x59\x1a"
41 "\x2b\x58\x1a\x9a\x83\x8c\x49\xe3\x0a\x04\x42\x00\x37\x4c\x1b\x42"
42 ),
43 };
44
45 FPDF_InitLibrary();
46 for (size_t i = 0; i < FX_ArraySize(flate_encode_cases); ++i) {
47 FlateEncodeCase* ptr = &flate_encode_cases[i];
48 unsigned char* result;
49 unsigned int result_size;
50 FlateEncode(ptr->input, ptr->input_size, result, result_size); // Leaks.
51 EXPECT_EQ(std::string((const char*)ptr->expected, ptr->expected_size),
52 std::string((const char*)result, result_size))
53 << " for case " << i;
54 }
55 FPDF_DestroyLibrary();
56 }
57
58 TEST(ParserDecode, FlateDecode) {
59 struct FlateDecodeCase {
60 const unsigned char* input;
61 unsigned int input_size;
62 const unsigned char* expected;
63 unsigned int expected_size;
64 } flate_decode_cases[] = {
65 TEST_CASE("", ""),
66 TEST_CASE("preposterous nonsense", ""),
67 TEST_CASE("\x78\x9c\x03\x00\x00\x00\x00\x01", ""),
68 TEST_CASE("\x78\x9c\x53\x00\x00\x00\x21\x00\x21", " "),
69 TEST_CASE("\x78\x9c\x33\x34\x32\x06\x00\01\x2d\x00\x97", "123"),
70 TEST_CASE("\x78\x9c\x63\xf8\x0f\x00\x01\x01\x01\x00", "\x00\xff"),
71 TEST_CASE("\x78\x9c\x33\x54\x30\x00\x42\x5d\x43\x05\x23\x4b\x05\x73\x33\x63"
72 "\x85\xe4\x5c\x2e\x90\x80\xa9\xa9\xa9\x82\xb9\xb1\xa9\x42\x51\x2a"
73 "\x57\xb8\x42\x1e\x57\x21\x92\xa0\x89\x9e\xb1\xa5\x09\x92\x84\x9e"
74 "\x85\x81\x81\x25\xd8\x14\x24\x26\xd0\x18\x43\x05\x10\x0c\x72\x57"
75 "\x80\x30\x8a\xd2\xb9\xf4\xdd\x0d\x14\xd2\x8b\xc1\x46\x99\x59\x1a"
76 "\x2b\x58\x1a\x9a\x83\x8c\x49\xe3\x0a\x04\x42\x00\x37\x4c\x1b\x42"
77 ,
78 "1 0 0 -1 29 763 cm\n0 0 555 735 re\nW n\nq\n0 0 555 734.394 re\n"
79 "W n\nq\n0.8009 0 0 0.8009 0 0 cm\n1 1 1 RG 1 1 1 rg\n/G0 gs\n"
80 "0 0 693 917 re\nf\nQ\nQ\n"
81 ),
82 };
83
84 FPDF_InitLibrary();
85 for (size_t i = 0; i < FX_ArraySize(flate_decode_cases); ++i) {
86 FlateDecodeCase* ptr = &flate_decode_cases[i];
87 unsigned char* result;
88 unsigned int result_size;
89 FlateDecode(ptr->input, ptr->input_size, result, result_size); // Leaks.
90 EXPECT_EQ(std::string((const char*)ptr->expected, ptr->expected_size),
91 std::string((const char*)result, result_size))
92 << " for case " << i;
93 }
94 FPDF_DestroyLibrary();
95 }
96
97
98 #undef TEST_CASE
OLDNEW
« no previous file with comments | « BUILD.gn ('k') | pdfium.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698