Commit a238b4b0fd38c4bf3f218072a9d3174684a9c91e

Authored by Jay Berkenbilt
1 parent c67634af

Ensure there is a meaningful deterministic ID test

If we ignore /ID[1], we need to make sure deterministic IDs are
tested properly.
qpdf/qtest/deterministic-id.test
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 require 5.008; 2 require 5.008;
3 use warnings; 3 use warnings;
4 use strict; 4 use strict;
  5 +use File::Copy;
5 6
6 unshift(@INC, '.'); 7 unshift(@INC, '.');
7 require qpdf_test_helpers; 8 require qpdf_test_helpers;
@@ -14,23 +15,41 @@ cleanup(); @@ -14,23 +15,41 @@ cleanup();
14 15
15 my $td = new TestDriver('deterministic-id'); 16 my $td = new TestDriver('deterministic-id');
16 17
17 -my $n_tests = 11; 18 +my $n_tests = 19;
  19 +
  20 +# Do not use qpdf-test-compare in this test suite since it ignores
  21 +# /ID[1].
18 22
19 foreach my $d ('nn', 'ny', 'yn', 'yy') 23 foreach my $d ('nn', 'ny', 'yn', 'yy')
20 { 24 {
21 my $linearize = ($d =~ m/^y/); 25 my $linearize = ($d =~ m/^y/);
22 my $ostream = ($d =~ m/y$/); 26 my $ostream = ($d =~ m/y$/);
23 - $td->runtest("deterministic ID: linearize/ostream=$d",  
24 - {$td->COMMAND =>  
25 - "qpdf -deterministic-id" .  
26 - ($linearize ? " -linearize" : "") .  
27 - " -object-streams=" . ($ostream ? "generate" : "disable") .  
28 - " deterministic-id-in.pdf a.pdf"},  
29 - {$td->STRING => "",  
30 - $td->EXIT_STATUS => 0}); 27 + # The deterministic ID is a function of all the data in the file.
  28 + # As such, it is affected by which zlib implementation is in use.
  29 + # The important thing is that the ID is the same if a file is
  30 + # generated the same way more than once, so rather than comparing
  31 + # the output file to a known output, compare subsequent outputs
  32 + # with each other.
  33 + foreach my $out ('a.pdf', 'b.pdf')
  34 + {
  35 + $td->runtest("deterministic ID: linearize/ostream=$d",
  36 + {$td->COMMAND =>
  37 + "qpdf -deterministic-id" .
  38 + ($linearize ? " -linearize" : "") .
  39 + " -object-streams=" . ($ostream ? "generate" : "disable") .
  40 + " deterministic-id-in.pdf $out"},
  41 + {$td->STRING => "",
  42 + $td->EXIT_STATUS => 0});
  43 + }
31 $td->runtest("compare files", 44 $td->runtest("compare files",
32 {$td->FILE => "a.pdf"}, 45 {$td->FILE => "a.pdf"},
33 - {$td->FILE => "deterministic-id-$d.pdf"}); 46 + {$td->FILE => "b.pdf"});
  47 + check_id('a.pdf');
  48 + if ($d eq 'nn')
  49 + {
  50 + # Save for the C API test
  51 + copy("a.pdf", 'c.pdf');
  52 + }
34 } 53 }
35 54
36 $td->runtest("deterministic ID with encryption", 55 $td->runtest("deterministic ID with encryption",
@@ -49,7 +68,27 @@ $td->runtest("deterministic ID (C API)", @@ -49,7 +68,27 @@ $td->runtest("deterministic ID (C API)",
49 $td->NORMALIZE_NEWLINES); 68 $td->NORMALIZE_NEWLINES);
50 $td->runtest("compare files", 69 $td->runtest("compare files",
51 {$td->FILE => "a.pdf"}, 70 {$td->FILE => "a.pdf"},
52 - {$td->FILE => "deterministic-id-nn.pdf"}); 71 + {$td->FILE => "c.pdf"});
53 72
54 cleanup(); 73 cleanup();
55 $td->report($n_tests); 74 $td->report($n_tests);
  75 +
  76 +sub check_id
  77 +{
  78 + my $f = shift;
  79 + chomp(my $id = `qpdf --show-object=trailer $f`);
  80 + if ($id =~ m,.*/ID \[ <(9b1c69409fc9a5f50e44b9588e3e60f8)> <(.{32})>,)
  81 + {
  82 + my $id0 = $1;
  83 + my $id1 = $2;
  84 + $td->runtest("ID fields differ",
  85 + {$td->STRING => $id0 ne $id1 ? "YES\n" : "$id0 $id1\n"},
  86 + {$td->STRING => "YES\n"});
  87 + }
  88 + else
  89 + {
  90 + $td->runtest("checked ID",
  91 + {$td->STRING => "YES\n"},
  92 + {$td->STRING => "$id\n"});
  93 + }
  94 +}
qpdf/qtest/qpdf/deterministic-id-nn.pdf deleted
No preview for this file type
qpdf/qtest/qpdf/deterministic-id-ny.pdf deleted
No preview for this file type
qpdf/qtest/qpdf/deterministic-id-yn.pdf deleted
No preview for this file type
qpdf/qtest/qpdf/deterministic-id-yy.pdf deleted
No preview for this file type