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
|
#!/usr/bin/env perl
require 5.008;
use warnings;
use strict;
use Digest::MD5;
use File::Basename;
use File::Copy;
unshift(@INC, '.');
require qpdf_test_helpers;
chdir("qpdf") or die "chdir testdir failed: $!\n";
require TestDriver;
cleanup();
my $td = new TestDriver('content-preservation');
my @files = ("encrypted-with-images.pdf", # encrypted
"inline-images.pdf",
"lin-special.pdf",
"object-stream.pdf",
"hybrid-xref.pdf");
my @flags = (["-qdf", # 1
"qdf"],
["-qdf --normalize-content=n", # 2
"qdf not normalized"],
["-qdf --stream-data=preserve", # 3
"qdf not uncompressed"],
["-qdf --stream-data=preserve --normalize-content=n", # 4
"qdf not normalized or uncompressed"],
["--stream-data=uncompress", # 5
"uncompresed"],
["--normalize-content=y", # 6
"normalized"],
["--stream-data=uncompress --normalize-content=y", # 7
"uncompressed and normalized"],
["-decrypt", # 8
"decrypted"],
["-linearize", # 9
"linearized"],
["-allow-weak-crypto -encrypt \"\" owner 128 --", # 10
"encrypted"],
["-linearize -allow-weak-crypto -encrypt \"\" o 128 --", # 11
"linearized and encrypted"],
["", # 12
"no arguments"],
);
my $n_tests = 1 + (@files * @flags * 2 * 3);
my $n_compare_pdfs = 1 + (@files * @flags * 2);
foreach my $file (@files)
{
my $base = basename($file, '.pdf');
foreach my $o (qw(disable generate))
{
my $n = 0;
my $oflags = "--object-streams=$o";
my $odescrip = "os:" . substr($o, 0, 1);
my $osuf = ($o eq 'generate' ? "-ogen" : "");
foreach my $d (@flags)
{
my ($flags, $fdescrip) = @$d;
++$n;
system("rm -f *.pnm");
$td->runtest("$file ($odescrip $fdescrip)",
{$td->COMMAND => "qpdf $flags $oflags $file a.pdf"},
{$td->STRING => "",
$td->EXIT_STATUS => 0});
$td->runtest("check status",
{$td->COMMAND => "qpdf --check a.pdf"},
{$td->FILE => "$base.$n$osuf.check",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("check with C API",
{$td->COMMAND => [qw(qpdf-ctest 1 a.pdf), "", ""]},
{$td->FILE => "$base.$n$osuf.c-check",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
compare_pdfs($td, $file, "a.pdf");
}
flush_tiff_cache();
}
}
$td->runtest("convert inline-images to qdf",
{$td->COMMAND => "qpdf --static-id --no-original-object-ids" .
" --qdf inline-images.pdf a.pdf"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
compare_pdfs($td, "inline-images.pdf", "a.pdf");
cleanup();
$td->report(calc_ntests($n_tests, $n_compare_pdfs));
|