aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf/qtest/c-api.test
blob: d0776b167b4f7549bc68398d385bc553aec5cd12 (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
67
68
69
70
71
72
73
#!/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('c-api');

my @capi = (
    [2, 'no options'],
    [3, 'normalized content'],
    [4, 'ignore xref streams'],
    [5, 'linearized'],
    [6, 'object streams'],
    [7, 'qdf'],
    [8, 'no original object ids'],
    [9, 'uncompressed streams'],
    );
my $n_tests = (2 * @capi) + 5;
foreach my $d (@capi)
{
    my ($n, $description) = @$d;
    my $outfile = $description;
    $outfile =~ s/ /-/g;
    $outfile = "c-$outfile.pdf";
    $td->runtest($description,
                 {$td->COMMAND => "qpdf-ctest $n hybrid-xref.pdf '' a.pdf"},
                 {$td->STRING => "C test $n done\n", $td->EXIT_STATUS => 0},
                 $td->NORMALIZE_NEWLINES);
    $td->runtest("check $description",
                 {$td->FILE => "a.pdf"},
                 {$td->FILE => $outfile});
}
$td->runtest("write to bad file name",
             {$td->COMMAND => "qpdf-ctest 2 hybrid-xref.pdf '' /:a:/:b:"},
             {$td->REGEXP => "error: open /:a:/:b:: .*",
              $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);

$td->runtest("write damaged to bad file name",
             {$td->COMMAND => "qpdf-ctest 2 append-page-content-damaged.pdf" .
                  " '' /:a:/:b:"},
             {$td->REGEXP =>
                  "warning:(?s:.*)\n" .
                  "error: open /:a:/:b:: .*",
                  $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);

$td->runtest("write damaged",
             {$td->COMMAND => "qpdf-ctest 2 append-page-content-damaged.pdf" .
                  " '' a.pdf"},
             {$td->FILE => "c-write-damaged.out",
              $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);

$td->runtest("empty PDF",
             {$td->COMMAND => "qpdf-ctest 41 - '' a.pdf"},
             {$td->STRING => "C test 41 done\n", $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
$td->runtest("check output",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "c-empty.pdf"});

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