aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf/qtest/xref-errors.test
blob: 9db27114bb2425027da8d5a694e47736ecf011ef (plain) (blame)
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
#!/usr/bin/env perl
require 5.008;
use warnings;
use strict;

unshift(@INC, '.');
require qpdf_test_helpers;

chdir("qpdf") or die "chdir testdir failed: $!\n";

require TestDriver;

cleanup();

my $td = new TestDriver('xref-errors');

my $n_tests = 6;

# Handle file with invalid xref table and object 0 as a regular object
# (bug 3159950).
$td->runtest("check obj0.pdf",
             {$td->COMMAND => "qpdf --check obj0.pdf"},
             {$td->FILE => "obj0-check.out",
              $td->EXIT_STATUS => 3},
             $td->NORMALIZE_NEWLINES);

# Demonstrate show-xref after check and not after check to illustrate
# that it can dump the real xref or the recovered xref.
$td->runtest("dump bad xref",
             {$td->COMMAND => "qpdf --show-xref bad-xref-entry.pdf"},
             {$td->FILE => "bad-xref-entry.out",
              $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
# Test @file here too.
open(F, ">args") or die;
print F "--check\n";
print F "--show-xref\n";
close(F);
$td->runtest("dump corrected bad xref",
             {$td->COMMAND => "qpdf \@args bad-xref-entry.pdf"},
             {$td->FILE => "bad-xref-entry-corrected.out",
              $td->EXIT_STATUS => 3},
             $td->NORMALIZE_NEWLINES);
unlink "args";

$td->runtest("combine show and --pages",
             {$td->COMMAND =>
                  "qpdf --empty --pages minimal.pdf -- --show-pages"},
             {$td->FILE => "show-pages-pages.out",
              $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);

$td->runtest("show number of pages",
             {$td->COMMAND =>
                  "qpdf --show-npages 20-pages.pdf --password=user"},
             {$td->STRING => "20\n", $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);

# Issue 482 -- don't range check fields[2] for xref entry type 0.
$td->runtest("out of range in deleted object",
             {$td->COMMAND => "qpdf --check xref-range.pdf"},
             {$td->FILE => "xref-range.out", $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);

cleanup();
$td->report($n_tests);