mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
Have qpdf-test-compare handle certain /ID differences
Rationale is in comments in the code. Deterministic ID tests explicitly do not use this tool.
This commit is contained in:
parent
a238b4b0fd
commit
647b9831dc
@ -24,7 +24,7 @@ usage()
|
|||||||
<< std::endl
|
<< std::endl
|
||||||
<< "If the files match, the output is the expected file. Otherwise, it is"
|
<< "If the files match, the output is the expected file. Otherwise, it is"
|
||||||
<< std::endl
|
<< std::endl
|
||||||
<< "the actual file. Read comments in the test suite for rationale." << std::endl;
|
<< "the actual file. Read comments in the code for rationale." << std::endl;
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,6 +50,8 @@ compareObjects(std::string const& label, QPDFObjectHandle act, QPDFObjectHandle
|
|||||||
return label + ": different types";
|
return label + ": different types";
|
||||||
}
|
}
|
||||||
if (act.isStream()) {
|
if (act.isStream()) {
|
||||||
|
// Disregard stream lengths. The length of stream data is compared later, and we don't care
|
||||||
|
// about the length of compressed data as long as the uncompressed data matches.
|
||||||
auto act_dict = act.getDict();
|
auto act_dict = act.getDict();
|
||||||
auto exp_dict = exp.getDict();
|
auto exp_dict = exp.getDict();
|
||||||
act_dict.removeKey("/Length");
|
act_dict.removeKey("/Length");
|
||||||
@ -59,6 +61,8 @@ compareObjects(std::string const& label, QPDFObjectHandle act, QPDFObjectHandle
|
|||||||
return label + ": stream dictionaries differ";
|
return label + ": stream dictionaries differ";
|
||||||
}
|
}
|
||||||
if (act_dict.getKey("/Type").isNameAndEquals("/XRef")) {
|
if (act_dict.getKey("/Type").isNameAndEquals("/XRef")) {
|
||||||
|
// Cross-reference streams will generally not match, but we have numerous tests that
|
||||||
|
// meaningfully ensure that xref streams are correct.
|
||||||
QTC::TC("compare", "ignore data for xref stream");
|
QTC::TC("compare", "ignore data for xref stream");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@ -103,6 +107,27 @@ compareObjects(std::string const& label, QPDFObjectHandle act, QPDFObjectHandle
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cleanTrailer(QPDFObjectHandle& trailer)
|
||||||
|
{
|
||||||
|
// If the trailer is an object stream, it will have /Length.
|
||||||
|
trailer.removeKey("/Length");
|
||||||
|
// Disregard the second half of /ID. This doesn't have anything directly to do with zlib, but
|
||||||
|
// lots of tests use --deterministic-id, and that is affected. The deterministic ID tests
|
||||||
|
// meaningfully exercise that deterministic IDs behave as expected, so for the rest of the
|
||||||
|
// tests, it's okay to ignore /ID[1]. If the two halves of /ID are the same, ignore both since
|
||||||
|
// this means qpdf completely generated the /ID rather than preserving the first half.
|
||||||
|
auto id = trailer.getKey("/ID");
|
||||||
|
if (id.isArray() && id.getArrayNItems() == 2) {
|
||||||
|
auto id0 = id.getArrayItem(0).unparse();
|
||||||
|
auto id1 = id.getArrayItem(1).unparse();
|
||||||
|
id.setArrayItem(1, "()"_qpdf);
|
||||||
|
if (id0 == id1) {
|
||||||
|
id.setArrayItem(0, "()"_qpdf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string
|
std::string
|
||||||
compare(char const* actual_filename, char const* expected_filename)
|
compare(char const* actual_filename, char const* expected_filename)
|
||||||
{
|
{
|
||||||
@ -118,8 +143,8 @@ compare(char const* actual_filename, char const* expected_filename)
|
|||||||
|
|
||||||
auto act_trailer = actual.getTrailer();
|
auto act_trailer = actual.getTrailer();
|
||||||
auto exp_trailer = expected.getTrailer();
|
auto exp_trailer = expected.getTrailer();
|
||||||
act_trailer.removeKey("/Length");
|
cleanTrailer(act_trailer);
|
||||||
exp_trailer.removeKey("/Length");
|
cleanTrailer(exp_trailer);
|
||||||
auto trailer_diff = compareObjects("trailer", act_trailer, exp_trailer);
|
auto trailer_diff = compareObjects("trailer", act_trailer, exp_trailer);
|
||||||
if (!trailer_diff.empty()) {
|
if (!trailer_diff.empty()) {
|
||||||
QTC::TC("compare", "different trailer");
|
QTC::TC("compare", "different trailer");
|
||||||
|
@ -52,6 +52,7 @@ my @diff = (
|
|||||||
["diff-data-unc.pdf", "5,0: stream data differs"],
|
["diff-data-unc.pdf", "5,0: stream data differs"],
|
||||||
["diff-stream-dict.pdf", "4,0: stream dictionaries differ"],
|
["diff-stream-dict.pdf", "4,0: stream dictionaries differ"],
|
||||||
["diff-object-type.pdf", "6,0: different types"],
|
["diff-object-type.pdf", "6,0: different types"],
|
||||||
|
["diff-id.pdf", "trailer: object contents differ"],
|
||||||
);
|
);
|
||||||
$n_tests += 2 * scalar(@diff);
|
$n_tests += 2 * scalar(@diff);
|
||||||
|
|
||||||
@ -90,4 +91,12 @@ $td->runtest("compare object stream files (same)",
|
|||||||
{$td->COMMAND => "env QPDF_COMPARE_WHY=1 qpdf-test-compare ostream1.pdf ostream2.pdf"},
|
{$td->COMMAND => "env QPDF_COMPARE_WHY=1 qpdf-test-compare ostream1.pdf ostream2.pdf"},
|
||||||
{$td->FILE => "ostream2.pdf", $td->EXIT_STATUS => 0});
|
{$td->FILE => "ostream2.pdf", $td->EXIT_STATUS => 0});
|
||||||
|
|
||||||
|
$n_tests += 2;
|
||||||
|
$td->runtest("files identical except /ID[1]",
|
||||||
|
{$td->COMMAND => "env QPDF_COMPARE_WHY=1 qpdf-test-compare zlib.pdf zlib-new-id.pdf"},
|
||||||
|
{$td->FILE => "zlib-new-id.pdf", $td->EXIT_STATUS => 0});
|
||||||
|
$td->runtest("/ID[0] = /ID[1]",
|
||||||
|
{$td->COMMAND => "env QPDF_COMPARE_WHY=1 qpdf-test-compare zlib-new-id1.pdf zlib-new-id2.pdf"},
|
||||||
|
{$td->FILE => "zlib-new-id2.pdf", $td->EXIT_STATUS => 0});
|
||||||
|
|
||||||
$td->report($n_tests);
|
$td->report($n_tests);
|
||||||
|
BIN
compare-for-test/qtest/compare/diff-id.pdf
Normal file
BIN
compare-for-test/qtest/compare/diff-id.pdf
Normal file
Binary file not shown.
BIN
compare-for-test/qtest/compare/zlib-new-id.pdf
Normal file
BIN
compare-for-test/qtest/compare/zlib-new-id.pdf
Normal file
Binary file not shown.
BIN
compare-for-test/qtest/compare/zlib-new-id1.pdf
Normal file
BIN
compare-for-test/qtest/compare/zlib-new-id1.pdf
Normal file
Binary file not shown.
BIN
compare-for-test/qtest/compare/zlib-new-id2.pdf
Normal file
BIN
compare-for-test/qtest/compare/zlib-new-id2.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user