2022-05-15 16:34:27 +00:00
|
|
|
#!/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('qpdf-json');
|
|
|
|
|
|
|
|
my $n_tests = 0;
|
|
|
|
|
|
|
|
my @badfiles = (
|
|
|
|
'no-qpdf-object',
|
|
|
|
'no-pdf-version',
|
|
|
|
'top-level-scalar',
|
|
|
|
'bad-pdf-version1',
|
|
|
|
'bad-pdf-version2',
|
|
|
|
'top-level-array',
|
|
|
|
'objects-not-dict',
|
|
|
|
'bad-object-key',
|
|
|
|
'object-not-dict',
|
|
|
|
'stream-not-dict',
|
|
|
|
'stream-dict-not-dict',
|
|
|
|
'trailer-not-dict',
|
|
|
|
'trailer-stream',
|
2022-05-15 21:38:06 +00:00
|
|
|
'missing-trailer',
|
|
|
|
'missing-objects',
|
|
|
|
'obj-key-errors',
|
2022-05-15 16:34:27 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$n_tests += scalar(@badfiles);
|
|
|
|
|
|
|
|
foreach my $f (@badfiles)
|
|
|
|
{
|
|
|
|
$td->runtest("bad: $f",
|
|
|
|
{$td->COMMAND =>
|
2022-05-18 22:22:57 +00:00
|
|
|
"qpdf --json-input qjson-$f.json a.pdf"},
|
2022-05-15 16:34:27 +00:00
|
|
|
{$td->FILE => "qjson-$f.out", $td->EXIT_STATUS => 2},
|
|
|
|
$td->NORMALIZE_NEWLINES);
|
|
|
|
}
|
|
|
|
|
2022-05-19 22:46:54 +00:00
|
|
|
my @goodfiles = (
|
|
|
|
'good1.pdf',
|
|
|
|
'good9.pdf',
|
|
|
|
'good13.pdf',
|
|
|
|
'good15.pdf',
|
|
|
|
'inline-images.pdf',
|
|
|
|
['20-pages.pdf', '--password=user'],
|
|
|
|
'outlines-with-actions.pdf',
|
|
|
|
'form-fields-and-annotations.pdf',
|
|
|
|
'need-appearances.pdf',
|
|
|
|
'fxo-blue.pdf',
|
|
|
|
);
|
|
|
|
$n_tests += 6 * scalar(@goodfiles);
|
|
|
|
|
|
|
|
foreach my $i (@goodfiles)
|
|
|
|
{
|
|
|
|
my $f = $i;
|
|
|
|
my $xargs = "";
|
|
|
|
if (ref($i) eq 'ARRAY') {
|
|
|
|
($f, $xargs) = @$i;
|
|
|
|
}
|
2022-05-19 23:22:32 +00:00
|
|
|
$td->runtest("good: $f -> JSON",
|
2022-05-19 22:46:54 +00:00
|
|
|
{$td->COMMAND => "qpdf $xargs --decode-level=none" .
|
|
|
|
" --json-output=latest $f a.json"},
|
|
|
|
{$td->STRING => "", $td->EXIT_STATUS => 0},
|
|
|
|
$td->NORMALIZE_NEWLINES);
|
2022-05-19 23:22:32 +00:00
|
|
|
$td->runtest("good: $f JSON -> JSON",
|
2022-05-19 22:46:54 +00:00
|
|
|
{$td->COMMAND =>
|
|
|
|
"qpdf --decode-level=none" .
|
|
|
|
" --json-input --json-output=latest a.json b.json"},
|
|
|
|
{$td->STRING => "", $td->EXIT_STATUS => 0},
|
|
|
|
$td->NORMALIZE_NEWLINES);
|
2022-05-19 23:22:32 +00:00
|
|
|
$td->runtest("good: $f JSON -> QDF",
|
2022-05-19 22:46:54 +00:00
|
|
|
{$td->COMMAND =>
|
|
|
|
"qpdf --qdf --json-input --stream-data=preserve" .
|
|
|
|
" --static-id a.json a.pdf"},
|
|
|
|
{$td->STRING => "", $td->EXIT_STATUS => 0},
|
|
|
|
$td->NORMALIZE_NEWLINES);
|
2022-05-19 23:22:32 +00:00
|
|
|
$td->runtest("good: $f compare JSON",
|
2022-05-19 22:46:54 +00:00
|
|
|
{$td->FILE => "a.json"},
|
|
|
|
{$td->FILE => "b.json"});
|
|
|
|
my $exp = "json-changed-$f";
|
|
|
|
if (! -f $exp)
|
|
|
|
{
|
2022-05-19 23:22:32 +00:00
|
|
|
$td->runtest("good: $f -> aqdf",
|
2022-05-19 22:46:54 +00:00
|
|
|
{$td->COMMAND =>
|
|
|
|
"qpdf $xargs --object-streams=disable --qdf" .
|
|
|
|
" --stream-data=preserve --static-id $f b.pdf"},
|
|
|
|
{$td->STRING => "", $td->EXIT_STATUS => 0},
|
|
|
|
$td->NORMALIZE_NEWLINES);
|
|
|
|
$exp = "b.pdf";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# Sometimes passing through json may make semantically
|
|
|
|
# equivalent changes such as
|
|
|
|
#
|
|
|
|
# * adding leading 0 to a floating point (.1 -> 0.1)
|
|
|
|
# * changing the Unicode representation of a string
|
|
|
|
# * changing the representation of a name (/n#65st -> /nest)
|
|
|
|
$td->runtest("good: json changes $f",
|
|
|
|
{$td->STRING => ""},
|
|
|
|
{$td->STRING => ""});
|
|
|
|
}
|
|
|
|
$td->runtest("good: $f compare qdf",
|
|
|
|
{$td->FILE => "a.pdf"}, # from json
|
|
|
|
{$td->FILE => $exp}); # from original PDF
|
|
|
|
}
|
|
|
|
|
2022-05-19 23:22:32 +00:00
|
|
|
$n_tests += 6;
|
|
|
|
$td->runtest("manual JSON to PDF",
|
|
|
|
{$td->COMMAND => "qpdf --json-input --static-id --qdf" .
|
|
|
|
" manual-qpdf-json.json a.pdf"},
|
|
|
|
{$td->STRING => "", $td->EXIT_STATUS => 0},
|
|
|
|
$td->NORMALIZE_NEWLINES);
|
|
|
|
$td->runtest("check manual JSON to PDF",
|
|
|
|
{$td->FILE => "a.pdf"},
|
|
|
|
{$td->FILE => "manual-qpdf-json.pdf"});
|
|
|
|
$td->runtest("check manual JSON to PDF to JSON",
|
|
|
|
{$td->COMMAND => "qpdf --json-output=2 a.pdf -"},
|
|
|
|
{$td->FILE => "manual-qpdf-json-pdf.json", $td->EXIT_STATUS => 0},
|
|
|
|
$td->NORMALIZE_NEWLINES);
|
|
|
|
$td->runtest("manual JSON to JSON",
|
|
|
|
{$td->COMMAND => "qpdf --json-input --json-output=2" .
|
|
|
|
" manual-qpdf-json.json a.json"},
|
|
|
|
{$td->STRING => "", $td->EXIT_STATUS => 0},
|
|
|
|
$td->NORMALIZE_NEWLINES);
|
|
|
|
$td->runtest("check manual JSON to JSON",
|
|
|
|
{$td->FILE => "a.json"},
|
|
|
|
{$td->FILE => "manual-qpdf-json-out.json"},
|
|
|
|
$td->NORMALIZE_NEWLINES);
|
|
|
|
$td->runtest("check manual JSON to JSON to JSON",
|
|
|
|
{$td->COMMAND => "qpdf --json-output=2 --json-input a.json -"},
|
|
|
|
{$td->FILE => "a.json", $td->EXIT_STATUS => 0},
|
|
|
|
$td->NORMALIZE_NEWLINES);
|
2022-05-19 22:46:54 +00:00
|
|
|
|
2022-05-19 23:22:32 +00:00
|
|
|
# QXXXQ file
|
2022-05-19 22:46:54 +00:00
|
|
|
|
2022-05-15 16:34:27 +00:00
|
|
|
cleanup();
|
|
|
|
$td->report($n_tests);
|