aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf/qtest/appearance-streams.test
blob: 25232c65f6f2685adf008ac96bf76a94fdf5c7ad (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/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('appearance-streams');

my $n_tests = 12;

foreach my $f ('need-appearances',
               'need-appearances-more',
               'need-appearances-more2',
               'need-appearances-more3')
{
    $td->runtest("generate appearances and flatten ($f)",
                 {$td->COMMAND =>
                      "qpdf --qdf --no-original-object-ids --static-id" .
                      " --generate-appearances --flatten-annotations=all" .
                      " $f.pdf a.pdf"},
                 {$td->STRING => "", $td->EXIT_STATUS => 0},
                 $td->NORMALIZE_NEWLINES);
    my $exp = 'appearances-a';
    if ($f =~ m/appearances(-.*)$/)
    {
        $exp .= $1;
    }
    $exp .= '.pdf';
    $td->runtest("compare files",
                 {$td->FILE => "a.pdf"},
                 {$td->FILE => $exp});
}

$td->runtest("more choices",
             {$td->COMMAND =>
                  "qpdf --qdf --no-original-object-ids --static-id" .
                  " --generate-appearances" .
                  " more-choices.pdf b.pdf"},
             {$td->STRING => "", $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
# b.pdf still has forms
$td->runtest("compare files",
             {$td->FILE => "b.pdf"},
             {$td->FILE => "appearances-b.pdf"});

my @choice_values = qw(1 2 11 12 quack);
$n_tests += 3 * scalar(@choice_values);
foreach my $i (@choice_values)
{
    # b.pdf was generated by qpdf and needs appearances
    # test_driver 52 writes a.pdf
    $td->runtest("set value to $i",
                 {$td->COMMAND => "test_driver 52 b.pdf $i"},
                 {$td->STRING => "setting list1 value\ntest 52 done\n",
                      $td->EXIT_STATUS => 0},
                 $td->NORMALIZE_NEWLINES);
    $td->runtest("regenerate appearances",
                 {$td->COMMAND =>
                      "qpdf --qdf --no-original-object-ids --static-id" .
                      " --generate-appearances" .
                      " a.pdf b.pdf"},
                 {$td->STRING => "", $td->EXIT_STATUS => 0},
                 $td->NORMALIZE_NEWLINES);
    $td->runtest("compare files",
                 {$td->FILE => "b.pdf"},
                 {$td->FILE => "appearances-$i.pdf"});
}

$td->runtest("Update resources from /DR",
             {$td->COMMAND =>
                      "qpdf --qdf --no-original-object-ids --static-id" .
                      " --generate-appearances" .
                      " resource-from-dr.pdf a.pdf"},
             {$td->STRING => "", $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
$td->runtest("compare files",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "resource-from-dr-out.pdf"});

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