aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf/qtest/json.test
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-05-14 22:16:20 +0200
committerJay Berkenbilt <ejb@ql.org>2022-05-14 23:35:06 +0200
commit173b944ef8f1dd3f971a6089a52fcd1ae07ca8f1 (patch)
treead6f8c53b76b6975ddb8abe1cdc64d7677d58aee /qpdf/qtest/json.test
parent4b642caf1114f6a354c21444d1fdccba3cb894b9 (diff)
downloadqpdf-173b944ef8f1dd3f971a6089a52fcd1ae07ca8f1.tar.zst
Split qpdf.test into multiple test suites
This makes it a lot easier to run parts of the test suite.
Diffstat (limited to 'qpdf/qtest/json.test')
-rw-r--r--qpdf/qtest/json.test169
1 files changed, 169 insertions, 0 deletions
diff --git a/qpdf/qtest/json.test b/qpdf/qtest/json.test
new file mode 100644
index 00000000..fc52ad65
--- /dev/null
+++ b/qpdf/qtest/json.test
@@ -0,0 +1,169 @@
+#!/usr/bin/env perl
+require 5.008;
+use warnings;
+use strict;
+use File::Compare;
+
+unshift(@INC, '.');
+require qpdf_test_helpers;
+
+chdir("qpdf") or die "chdir testdir failed: $!\n";
+
+require TestDriver;
+
+cleanup();
+
+my $td = new TestDriver('json');
+
+my @json_files = (
+ ['outlines-with-actions', []],
+ ['outlines-with-old-root-dests', []],
+ ['page-labels-and-outlines', []],
+ ['page-labels-num-tree', []],
+ ['image-streams', []],
+ ['image-streams-small', []],
+ ['field-types', []],
+ ['field-types', ['--show-encryption-key']],
+ ['image-streams', ['--decode-level=all']],
+ ['image-streams', ['--decode-level=specialized']],
+ ['page-labels-and-outlines', ['--json-key=qpdf']],
+ ['page-labels-and-outlines', ['--json-key=pages']],
+ ['page-labels-and-outlines', ['--json-key=pagelabels']],
+ ['page-labels-and-outlines', ['--json-key=outlines']],
+ ['page-labels-and-outlines',
+ ['--json-key=outlines', '--json-key=pages']],
+ ['page-labels-and-outlines',
+ ['--json-key=qpdf', '--json-object=trailer']],
+ ['page-labels-and-outlines',
+ ['--json-key=qpdf', '--json-object=trailer', '--json-object=2 0 R']],
+ ['field-types', ['--json-key=acroform']],
+ ['need-appearances', ['--json-key=acroform']],
+ ['V4-aes', ['--json-key=encrypt']],
+ ['V4-aes', ['--json-key=encrypt', '--show-encryption-key']],
+);
+my $n_tests = 25 + (2 * scalar(@json_files));
+foreach my $d (@json_files)
+{
+ my ($file, $xargs) = @$d;
+ my $out = "json-$file";
+ my @v1_xargs = ();
+ foreach my $x (@$xargs)
+ {
+ my $y = $x;
+ $y =~ s/^.*=//;
+ $y =~ s/\s.*//;
+ $out .= "-$y";
+ if ($x eq '--json-key=qpdf')
+ {
+ push(@v1_xargs, '--json-key=objects');
+ }
+ else
+ {
+ push(@v1_xargs, $x);
+ }
+ }
+ my $in = "$file.pdf";
+ $td->runtest("json v1 $out",
+ {$td->COMMAND =>
+ ['qpdf', '--json=1', '--test-json-schema',
+ @v1_xargs, $in]},
+ {$td->FILE => "$out-v1.out", $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
+ $td->runtest("json v2 $out",
+ {$td->COMMAND =>
+ ['qpdf', '--json=2', '--test-json-schema', @$xargs, $in]},
+ {$td->FILE => "$out-v2.out", $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
+}
+
+$td->runtest("bad json stream data (inline)",
+ {$td->COMMAND =>
+ "qpdf --json=2 --test-json-schema" .
+ " --json-stream-data=inline bad-data.pdf > a.json"},
+ {$td->FILE => "bad-data-json.out", $td->EXIT_STATUS => 3},
+ $td->NORMALIZE_NEWLINES);
+$td->runtest("check (inline)",
+ {$td->FILE => "a.json"},
+ {$td->FILE => "json-bad-data-json-inline-v2.out"},
+ $td->NORMALIZE_NEWLINES);
+$td->runtest("bad json stream data (file)",
+ {$td->COMMAND =>
+ "qpdf --json=2 --test-json-schema" .
+ " --json-stream-data=file --json-stream-prefix=auto" .
+ " bad-data.pdf > a.json"},
+ {$td->FILE => "bad-data-json.out", $td->EXIT_STATUS => 3},
+ $td->NORMALIZE_NEWLINES);
+$td->runtest("check (file)",
+ {$td->FILE => "a.json"},
+ {$td->FILE => "json-bad-data-json-file-v2.out"},
+ $td->NORMALIZE_NEWLINES);
+$td->runtest("check stream (file)",
+ {$td->FILE => "auto-4"},
+ {$td->FILE => "bad-data-4.out"});
+
+foreach my $l (qw(none generalized specialized all))
+{
+ if ($l ne 'all')
+ {
+ # We don't want a dependency on the exact value of the
+ # uncompressed jpeg, which can differ depending on which jpeg
+ # library is use.
+ $td->runtest("image-streams json inline: $l",
+ {$td->COMMAND =>
+ "qpdf image-streams-small.pdf --json=2" .
+ " --decode-level=$l --json-stream-data=inline"},
+ {$td->FILE => "json-image-streams-$l-inline-v2.out",
+ $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
+ }
+ $td->runtest("image-streams json file: $l",
+ {$td->COMMAND =>
+ "qpdf image-streams-small.pdf --json=2" .
+ " --decode-level=$l --json-stream-data=file" .
+ " --json-stream-prefix=auto --json-key=qpdf" .
+ " --json-object=12 --json-object=16 --json-object=18"},
+ {$td->FILE => "json-image-streams-$l-file-v2.out",
+ $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
+ # object 12: /FlateDecode
+ # object 16: /DCTDecode
+ # object 18: /RunLengthDecode
+ my %exp_compression = (
+ '12' => {'none' => 1},
+ '16' => {'none' => 1, 'generalized' => 1, 'specialized' => 1},
+ '18' => {'none' => 1, 'generalized' => 1},
+ );
+
+ foreach my $obj (qw(12 16 18))
+ {
+ my $compressed = (exists $exp_compression{$obj}{$l});
+ my $suf = $compressed ? "compressed" : "uncompressed";
+ if (($obj eq '16') && (! $compressed))
+ {
+ # Rather than testing the uncompressed DCT, just make sure
+ # it is different from the compressed DCT.
+ my $same = (compare(
+ "auto-$obj",
+ "image-streams-small-$obj-compressed.out") ?
+ "same" : "different");
+ $td->runtest("check stream data ($obj, $l)",
+ {$td->STRING => $same},
+ {$td->STRING => "same"});
+ }
+ else
+ {
+ $td->runtest("check stream data ($obj, $l)",
+ {$td->FILE => "auto-$obj"},
+ {$td->FILE => "image-streams-small-$obj-$suf.out"});
+ }
+ }
+}
+
+$td->runtest("use --to-json option",
+ {$td->COMMAND => "qpdf --to-json image-streams-small.pdf"},
+ {$td->FILE => "image-streams-small-to-json.out",
+ $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
+
+cleanup();
+$td->report($n_tests);