2022-05-14 20:16:20 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
require 5.008;
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2023-12-20 11:50:44 +00:00
|
|
|
use File::Copy;
|
2022-05-14 20:16:20 +00:00
|
|
|
|
|
|
|
unshift(@INC, '.');
|
|
|
|
require qpdf_test_helpers;
|
|
|
|
|
|
|
|
chdir("qpdf") or die "chdir testdir failed: $!\n";
|
|
|
|
|
|
|
|
require TestDriver;
|
|
|
|
|
|
|
|
cleanup();
|
|
|
|
|
2022-05-19 21:27:41 +00:00
|
|
|
my $td = new TestDriver('deterministic-id');
|
2022-05-14 20:16:20 +00:00
|
|
|
|
2023-12-20 11:50:44 +00:00
|
|
|
my $n_tests = 19;
|
|
|
|
|
|
|
|
# Do not use qpdf-test-compare in this test suite since it ignores
|
|
|
|
# /ID[1].
|
2022-05-14 20:16:20 +00:00
|
|
|
|
|
|
|
foreach my $d ('nn', 'ny', 'yn', 'yy')
|
|
|
|
{
|
|
|
|
my $linearize = ($d =~ m/^y/);
|
|
|
|
my $ostream = ($d =~ m/y$/);
|
2023-12-20 11:50:44 +00:00
|
|
|
# The deterministic ID is a function of all the data in the file.
|
|
|
|
# As such, it is affected by which zlib implementation is in use.
|
|
|
|
# The important thing is that the ID is the same if a file is
|
|
|
|
# generated the same way more than once, so rather than comparing
|
|
|
|
# the output file to a known output, compare subsequent outputs
|
|
|
|
# with each other.
|
|
|
|
foreach my $out ('a.pdf', 'b.pdf')
|
|
|
|
{
|
|
|
|
$td->runtest("deterministic ID: linearize/ostream=$d",
|
|
|
|
{$td->COMMAND =>
|
|
|
|
"qpdf -deterministic-id" .
|
|
|
|
($linearize ? " -linearize" : "") .
|
|
|
|
" -object-streams=" . ($ostream ? "generate" : "disable") .
|
|
|
|
" deterministic-id-in.pdf $out"},
|
|
|
|
{$td->STRING => "",
|
|
|
|
$td->EXIT_STATUS => 0});
|
|
|
|
}
|
2022-05-14 20:16:20 +00:00
|
|
|
$td->runtest("compare files",
|
|
|
|
{$td->FILE => "a.pdf"},
|
2023-12-20 11:50:44 +00:00
|
|
|
{$td->FILE => "b.pdf"});
|
|
|
|
check_id('a.pdf');
|
|
|
|
if ($d eq 'nn')
|
|
|
|
{
|
|
|
|
# Save for the C API test
|
|
|
|
copy("a.pdf", 'c.pdf');
|
|
|
|
}
|
2022-05-14 20:16:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$td->runtest("deterministic ID with encryption",
|
|
|
|
{$td->COMMAND => "qpdf -deterministic-id encrypted-with-images.pdf a.pdf"},
|
|
|
|
{$td->STRING => "qpdf: INTERNAL ERROR: QPDFWriter::generateID" .
|
|
|
|
" has no data for deterministic ID." .
|
|
|
|
" This may happen if deterministic ID and" .
|
|
|
|
" file encryption are requested together.\n",
|
|
|
|
$td->EXIT_STATUS => 2},
|
|
|
|
$td->NORMALIZE_NEWLINES);
|
|
|
|
$td->runtest("deterministic ID (C API)",
|
|
|
|
{$td->COMMAND =>
|
|
|
|
"qpdf-ctest 19 deterministic-id-in.pdf '' a.pdf"},
|
|
|
|
{$td->STRING => "C test 19 done\n",
|
|
|
|
$td->EXIT_STATUS => 0},
|
|
|
|
$td->NORMALIZE_NEWLINES);
|
|
|
|
$td->runtest("compare files",
|
|
|
|
{$td->FILE => "a.pdf"},
|
2023-12-20 11:50:44 +00:00
|
|
|
{$td->FILE => "c.pdf"});
|
2022-05-14 20:16:20 +00:00
|
|
|
|
|
|
|
cleanup();
|
|
|
|
$td->report($n_tests);
|
2023-12-20 11:50:44 +00:00
|
|
|
|
|
|
|
sub check_id
|
|
|
|
{
|
|
|
|
my $f = shift;
|
|
|
|
chomp(my $id = `qpdf --show-object=trailer $f`);
|
|
|
|
if ($id =~ m,.*/ID \[ <(9b1c69409fc9a5f50e44b9588e3e60f8)> <(.{32})>,)
|
|
|
|
{
|
|
|
|
my $id0 = $1;
|
|
|
|
my $id1 = $2;
|
|
|
|
$td->runtest("ID fields differ",
|
|
|
|
{$td->STRING => $id0 ne $id1 ? "YES\n" : "$id0 $id1\n"},
|
|
|
|
{$td->STRING => "YES\n"});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$td->runtest("checked ID",
|
|
|
|
{$td->STRING => "YES\n"},
|
|
|
|
{$td->STRING => "$id\n"});
|
|
|
|
}
|
|
|
|
}
|