aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf/qtest/replace-input.test
blob: 5c1a9df2e1e1afa2d36fbcd88267170fcb5527dc (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
#!/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('replace-input');

my $n_tests = 8;

# Use Unicode file names to test replace input so we can be sure it
# works for that case.
$td->runtest("create unicode filenames",
             {$td->COMMAND => "test_unicode_filenames"},
             {$td->STRING => "created Unicode filenames\n",
                  $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);

foreach my $d (['auto-ü', 1], ['auto-öπ', 2])
{
    my ($u, $n) = @$d;
    $td->runtest("replace input $u",
                 {$td->COMMAND => "qpdf --deterministic-id" .
                      " --object-streams=generate --replace-input ./$u.pdf"},
                 {$td->STRING => "", $td->EXIT_STATUS => 0},
                 $td->NORMALIZE_NEWLINES);
    # qpdf handles Unicode filenames on Windows, but qpdf-test-compare
    # doesn't.
    rename("$u.pdf", "u.pdf") or die;
    $td->runtest("check output ($u)",
                 {$td->COMMAND => "qpdf-test-compare u.pdf replace-input.pdf"},
                 {$td->FILE => "replace-input.pdf", $td->EXIT_STATUS => 0});
}

system("cp xref-with-short-size.pdf auto-warn.pdf") == 0 or die;
$td->runtest("replace input with warnings",
             {$td->COMMAND =>
                  "qpdf --deterministic-id --replace-input ./auto-warn.pdf"},
             {$td->FILE => "replace-warn.out", $td->EXIT_STATUS => 3},
             $td->NORMALIZE_NEWLINES);

$td->runtest("check output",
             {$td->COMMAND => "qpdf-test-compare auto-warn.pdf warn-replace.pdf"},
             {$td->FILE => "warn-replace.pdf", $td->EXIT_STATUS => 0});
$td->runtest("check orig output",
             {$td->FILE => "auto-warn.pdf.~qpdf-orig"},
             {$td->FILE => "xref-with-short-size.pdf"});

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