diff --git a/compare-for-test/qpdf-test-compare.cc b/compare-for-test/qpdf-test-compare.cc index 3952381b..5d3e6e28 100644 --- a/compare-for-test/qpdf-test-compare.cc +++ b/compare-for-test/qpdf-test-compare.cc @@ -129,12 +129,12 @@ cleanTrailer(QPDFObjectHandle& trailer) } std::string -compare(char const* actual_filename, char const* expected_filename) +compare(char const* actual_filename, char const* expected_filename, char const* password) { QPDF actual; - actual.processFile(actual_filename); + actual.processFile(actual_filename, password); QPDF expected; - expected.processFile(expected_filename); + expected.processFile(expected_filename, password); // The motivation behind this program is to compare files in a way that allows for // differences in the exact bytes of zlib compression. If all zlib implementations produced // exactly the same output, we would just be able to use straight comparison, but since they @@ -191,16 +191,20 @@ main(int argc, char* argv[]) exit(0); } - if (argc != 3) { + if (argc < 3 || argc > 4) { usage(); } bool show_why = QUtil::get_env("QPDF_COMPARE_WHY"); try { char const* to_output; - auto actual = argv[1]; - auto expected = argv[2]; - auto difference = compare(actual, expected); + char const* actual = argv[1]; + char const* expected = argv[2]; + char const* password{nullptr}; + if (argc == 4) { + password = argv[3]; + } + auto difference = compare(actual, expected, password); if (difference.empty()) { // The files are identical; write the expected file. This way, tests can be written // that compare the output of this program to the expected file. diff --git a/compare-for-test/qtest/compare.test b/compare-for-test/qtest/compare.test index bcf6b788..198cdf6b 100644 --- a/compare-for-test/qtest/compare.test +++ b/compare-for-test/qtest/compare.test @@ -73,7 +73,7 @@ foreach my $f (@diff) } # Repeat for encrypted files. -$n_tests += 3; +$n_tests += 5; $td->runtest("byte-wise compare encrypted files", {$td->COMMAND => "cmp enc1.pdf enc2.pdf"}, {$td->REGEXP => ".*", $td->EXIT_STATUS => "!0"}); @@ -84,6 +84,13 @@ $td->runtest("compare encrypted files (different)", {$td->COMMAND => "env QPDF_COMPARE_WHY=1 qpdf-test-compare enc1.pdf diff-data-enc.pdf"}, {$td->STRING => "4,0: stream data differs\n", $td->EXIT_STATUS => 2}, $td->NORMALIZE_NEWLINES); +$td->runtest("with password (same)", + {$td->COMMAND => "env QPDF_COMPARE_WHY=1 qpdf-test-compare enc1.pdf enc2.pdf o"}, + {$td->FILE => "enc2.pdf", $td->EXIT_STATUS => 0}); +$td->runtest("with password (different)", + {$td->COMMAND => "env QPDF_COMPARE_WHY=1 qpdf-test-compare enc1.pdf diff-data-enc.pdf o"}, + {$td->STRING => "4,0: stream data differs\n", $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); # Object streams $n_tests += 1;