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
|
#!/usr/bin/env perl
require 5.008;
use warnings;
use strict;
use File::Copy;
unshift(@INC, '.');
require qpdf_test_helpers;
chdir("qpdf") or die "chdir testdir failed: $!\n";
require TestDriver;
cleanup();
my $td = new TestDriver('arg_parsing');
my $n_tests = 13;
$td->runtest("required argument",
{$td->COMMAND => "qpdf --password minimal.pdf"},
{$td->REGEXP => "must be given as --password=pass",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
$td->runtest("required argument with choices",
{$td->COMMAND => "qpdf --decode-level minimal.pdf"},
{$td->REGEXP => "must be given as --decode-level=\\{.*all.*\\}",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
$td->runtest("required argument with choices",
{$td->COMMAND => "qpdf --decode-level minimal.pdf"},
{$td->REGEXP => "must be given as --decode-level=\\{.*all.*\\}",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
copy("minimal.pdf", '@file.pdf');
$td->runtest("\@file exists and file doesn't",
{$td->COMMAND => "qpdf --check \@file.pdf"},
{$td->FILE => "check-at-file.out", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("missing underlay filename",
{$td->COMMAND => "qpdf --underlay --"},
{$td->REGEXP => ".*underlay file not specified.*",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
$td->runtest("extra overlay filename",
{$td->COMMAND => "qpdf --overlay x x --"},
{$td->REGEXP => ".*overlay file already specified.*",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
$td->runtest("multiple pages options",
{$td->COMMAND => "qpdf --pages . --password=x -- --pages . --"},
{$td->REGEXP => ".*--pages may only be specified one time.*",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
$td->runtest("bad numeric range detects unclosed --pages",
{$td->COMMAND => "qpdf --pages . --pages . --"},
{$td->REGEXP => ".*pages options must be terminated with --.*",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
$td->runtest("bad file detected as unclosed --pages",
{$td->COMMAND => "qpdf --pages . 1 --xyz out"},
{$td->REGEXP => ".*pages options must be terminated with --.*",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
$td->runtest("misplaced pages password 1",
{$td->COMMAND => "qpdf --pages . 1 --password=z --"},
{$td->REGEXP => ".*password must immediately follow a file name.*",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
$td->runtest("misplaced pages password 2",
{$td->COMMAND => "qpdf --pages --password=z . 1 --"},
{$td->REGEXP => ".*password must immediately follow a file name.*",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
$td->runtest("duplicated pages password",
{$td->COMMAND => "qpdf --pages . --password=z --password=z --"},
{$td->REGEXP => ".*password already specified.*",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
# Ignoring -- at the top level was never intended but turned out to
# have been there for a long time so that people relied on it. It is
# intentionally not documented.
$td->runtest("ignore -- at top level",
{$td->COMMAND => "qpdf -- --check -- minimal.pdf --"},
{$td->REGEXP => ".*No syntax or stream encoding errors found.*",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
cleanup();
$td->report($n_tests);
|