object-stream.test
5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env perl
require 5.008;
use warnings;
use strict;
use Digest::MD5;
use File::Copy;
unshift(@INC, '.');
require qpdf_test_helpers;
chdir("qpdf") or die "chdir testdir failed: $!\n";
require TestDriver;
cleanup();
my $td = new TestDriver('object-stream');
my $n_tests = 10 + (36 * 4) + (12 * 2);
my $n_compare_pdfs = 36;
for (my $n = 16; $n <= 19; ++$n)
{
my $in = "good$n.pdf";
foreach my $flags ('-object-streams=disable',
'-object-streams=preserve',
'-object-streams=generate')
{
foreach my $qdf ('-qdf', '', '-allow-weak-crypto -encrypt "" x 128 --')
{
# 4 tests + 1 compare_pdfs * 36 cases
# 2 additional tests * 12 cases
$td->runtest("object stream mode",
{$td->COMMAND =>
"qpdf --static-id $flags $qdf $in a.pdf"},
{$td->STRING => "",
$td->EXIT_STATUS => 0});
compare_pdfs($td, "good$n.pdf", "a.pdf");
if ($qdf eq '-qdf')
{
$td->runtest("fix-qdf identity check",
{$td->COMMAND => "fix-qdf a.pdf >| b.pdf"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("compare files",
{$td->FILE => "a.pdf"},
{$td->FILE => "b.pdf"});
}
$td->runtest("convert to qdf",
{$td->COMMAND =>
"qpdf --static-id --no-original-object-ids" .
" -qdf -decrypt" .
" -object-streams=disable $in a.qdf"},
{$td->STRING => "",
$td->EXIT_STATUS => 0});
$td->runtest("convert output to qdf",
{$td->COMMAND =>
"qpdf --static-id --no-original-object-ids" .
" -qdf -object-streams=disable a.pdf b.qdf"},
{$td->STRING => "",
$td->EXIT_STATUS => 0});
$td->runtest("compare files",
{$td->FILE => "a.qdf"},
{$td->FILE => "b.qdf"});
}
}
flush_tiff_cache();
}
# The file override-compressed-object.pdf contains an object stream
# with four strings in it. The file is then appended. The appended
# section overrides one of the four strings with a string in another
# object stream and another one in an uncompressed object. The other
# two strings are left alone. The test case exercises that all four
# objects have the correct value.
$td->runtest("overridden compressed objects",
{$td->COMMAND => "test_driver 38 override-compressed-object.pdf"},
{$td->FILE => "override-compressed-object.out",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("generate object streams for gen > 0",
{$td->COMMAND => "qpdf --qdf --static-id" .
" --object-streams=generate gen1.pdf a.pdf"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check file",
{$td->FILE => "a.pdf"},
{$td->FILE => "gen1.qdf"});
$td->runtest("generate object streams for gen > 0",
{$td->COMMAND => "qpdf --qdf --static-id" .
" --object-streams=generate gen1-no-dangling.pdf a.pdf"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check file",
{$td->FILE => "a.pdf"},
# Intentionally compare against gen1.pdf -- should have
# the same results as above.
{$td->FILE => "gen1.qdf"});
# Recover a file with xref streams
$td->runtest("recover file with xref stream",
{$td->COMMAND => "qpdf --static-id --compress-streams=n" .
" recover-xref-stream.pdf a.pdf"},
{$td->FILE => "recover-xref-stream.out", $td->EXIT_STATUS => 3},
$td->NORMALIZE_NEWLINES);
$td->runtest("check file",
{$td->FILE => "a.pdf"},
{$td->FILE => "recover-xref-stream-recovered.pdf"});
# Self-referential object stream
$td->runtest("self-referential object stream",
{$td->COMMAND => "qpdf --static-id --qdf" .
" object-stream-self-ref.pdf a.pdf"},
{$td->FILE => "object-stream-self-ref.out", $td->EXIT_STATUS => 3},
$td->NORMALIZE_NEWLINES);
$td->runtest("check file",
{$td->FILE => "a.pdf"},
{$td->FILE => "object-stream-self-ref.out.pdf"});
# The file no-space-compressed-object.pdf contains an object stream containing two
# integer objects that are not separated by any white space. The test case exercises
# that all objects in the stream have the correct value.
$td->runtest("adjacent compressed objects",
{$td->COMMAND => "test_driver 99 no-space-compressed-object.pdf"},
{$td->FILE => "no-space-compressed-object.out",
$td->EXIT_STATUS => 0},
$td->EXPECT_FAILURE);
cleanup();
$td->report(calc_ntests($n_tests, $n_compare_pdfs));