aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf/qtest/qpdf-json.test
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-05-20 00:46:54 +0200
committerJay Berkenbilt <ejb@ql.org>2022-05-20 15:16:25 +0200
commit7f8c4b183da4d2d177ee08c3be848110361f43f0 (patch)
treececf477454fb65c55dff7c6ba5bc1ca78a86660d /qpdf/qtest/qpdf-json.test
parent6c7326b290462372bb6c23462b2087149cf5fcc6 (diff)
downloadqpdf-7f8c4b183da4d2d177ee08c3be848110361f43f0.tar.zst
Add tests for --json-input
Diffstat (limited to 'qpdf/qtest/qpdf-json.test')
-rw-r--r--qpdf/qtest/qpdf-json.test71
1 files changed, 71 insertions, 0 deletions
diff --git a/qpdf/qtest/qpdf-json.test b/qpdf/qtest/qpdf-json.test
index dbb0c70d..e6a6a18f 100644
--- a/qpdf/qtest/qpdf-json.test
+++ b/qpdf/qtest/qpdf-json.test
@@ -46,5 +46,76 @@ foreach my $f (@badfiles)
$td->NORMALIZE_NEWLINES);
}
+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;
+ }
+ $td->runtest("good: $f -> json",
+ {$td->COMMAND => "qpdf $xargs --decode-level=none" .
+ " --json-output=latest $f a.json"},
+ {$td->STRING => "", $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
+ $td->runtest("good: $f json -> json",
+ {$td->COMMAND =>
+ "qpdf --decode-level=none" .
+ " --json-input --json-output=latest a.json b.json"},
+ {$td->STRING => "", $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
+ $td->runtest("good: $f json -> qdf",
+ {$td->COMMAND =>
+ "qpdf --qdf --json-input --stream-data=preserve" .
+ " --static-id a.json a.pdf"},
+ {$td->STRING => "", $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
+ $td->runtest("good: $f compare json",
+ {$td->FILE => "a.json"},
+ {$td->FILE => "b.json"});
+ my $exp = "json-changed-$f";
+ if (! -f $exp)
+ {
+ $td->runtest("good: $f -> qdf",
+ {$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
+}
+
+
+
cleanup();
$td->report($n_tests);