aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf/qtest/decode-levels.test
blob: c4c6f477fd226a829f4e97d311d30fd5e5645c00 (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
#!/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('decode-levels');

my $n_tests = 14;

# image-streams.pdf is the output of examples/pdf-create.
# examples/pdf-create validates the actual image data.
# image-streams-small.pdf was manually created by editing
# pdf-create.cc to reduce width and height to 40x8 and ignoring
# errors. Its purpose was to get a small file with images with
# different filters for fuzz testing.
foreach my $l (qw(none generalized specialized all))
{
    $td->runtest("image-streams: $l",
                 {$td->COMMAND =>
                      "qpdf image-streams.pdf --compress-streams=n" .
                      " --decode-level=$l a.pdf"},
                 {$td->STRING => "", $td->EXIT_STATUS => 0},
                 $td->NORMALIZE_NEWLINES);
    $td->runtest("check image-streams: $l",
                 {$td->COMMAND => "test_driver 39 a.pdf"},
                 {$td->FILE => "image-streams-$l.out", $td->EXIT_STATUS => 0},
                 $td->NORMALIZE_NEWLINES);
}

# C API
$td->runtest("image-streams: C",
             {$td->COMMAND => "qpdf-ctest 20 image-streams.pdf '' a.pdf"},
             {$td->STRING => "C test 20 done\n", $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);
$td->runtest("check image-streams: C",
             {$td->COMMAND => "test_driver 39 a.pdf"},
             {$td->FILE => "image-streams-specialized.out",
              $td->EXIT_STATUS => 0},
             $td->NORMALIZE_NEWLINES);

# Bad JPEG data
$td->runtest("check finds bad jpeg data",
             {$td->COMMAND => "qpdf --check bad-jpeg.pdf"},
             {$td->FILE => "bad-jpeg-check.out",
              $td->EXIT_STATUS => 3},
             $td->NORMALIZE_NEWLINES);
$td->runtest("precheck detects bad jpeg data",
             {$td->COMMAND => "qpdf --static-id --decode-level=all" .
                  " bad-jpeg.pdf a.pdf"},
             {$td->FILE => "bad-jpeg.out", $td->EXIT_STATUS => 3},
             $td->NORMALIZE_NEWLINES);
$td->runtest("check file",
             {$td->FILE => "a.pdf"},
             {$td->FILE => "bad-jpeg-out.pdf"});
$td->runtest("get data",
             {$td->COMMAND => "qpdf --show-object=6" .
                  " --filtered-stream-data bad-jpeg.pdf"},
             {$td->FILE => "bad-jpeg-show.out", $td->EXIT_STATUS => 3},
             $td->NORMALIZE_NEWLINES);

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