Commit 38042fa2736f3a639b2e1362464dd1a832cafb7b
1 parent
321f9e79
Allow comparison of password-protected files
Showing
2 changed files
with
19 additions
and
8 deletions
compare-for-test/qpdf-test-compare.cc
| @@ -129,12 +129,12 @@ cleanTrailer(QPDFObjectHandle& trailer) | @@ -129,12 +129,12 @@ cleanTrailer(QPDFObjectHandle& trailer) | ||
| 129 | } | 129 | } |
| 130 | 130 | ||
| 131 | std::string | 131 | std::string |
| 132 | -compare(char const* actual_filename, char const* expected_filename) | 132 | +compare(char const* actual_filename, char const* expected_filename, char const* password) |
| 133 | { | 133 | { |
| 134 | QPDF actual; | 134 | QPDF actual; |
| 135 | - actual.processFile(actual_filename); | 135 | + actual.processFile(actual_filename, password); |
| 136 | QPDF expected; | 136 | QPDF expected; |
| 137 | - expected.processFile(expected_filename); | 137 | + expected.processFile(expected_filename, password); |
| 138 | // The motivation behind this program is to compare files in a way that allows for | 138 | // The motivation behind this program is to compare files in a way that allows for |
| 139 | // differences in the exact bytes of zlib compression. If all zlib implementations produced | 139 | // differences in the exact bytes of zlib compression. If all zlib implementations produced |
| 140 | // exactly the same output, we would just be able to use straight comparison, but since they | 140 | // 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[]) | @@ -191,16 +191,20 @@ main(int argc, char* argv[]) | ||
| 191 | exit(0); | 191 | exit(0); |
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | - if (argc != 3) { | 194 | + if (argc < 3 || argc > 4) { |
| 195 | usage(); | 195 | usage(); |
| 196 | } | 196 | } |
| 197 | 197 | ||
| 198 | bool show_why = QUtil::get_env("QPDF_COMPARE_WHY"); | 198 | bool show_why = QUtil::get_env("QPDF_COMPARE_WHY"); |
| 199 | try { | 199 | try { |
| 200 | char const* to_output; | 200 | char const* to_output; |
| 201 | - auto actual = argv[1]; | ||
| 202 | - auto expected = argv[2]; | ||
| 203 | - auto difference = compare(actual, expected); | 201 | + char const* actual = argv[1]; |
| 202 | + char const* expected = argv[2]; | ||
| 203 | + char const* password{nullptr}; | ||
| 204 | + if (argc == 4) { | ||
| 205 | + password = argv[3]; | ||
| 206 | + } | ||
| 207 | + auto difference = compare(actual, expected, password); | ||
| 204 | if (difference.empty()) { | 208 | if (difference.empty()) { |
| 205 | // The files are identical; write the expected file. This way, tests can be written | 209 | // The files are identical; write the expected file. This way, tests can be written |
| 206 | // that compare the output of this program to the expected file. | 210 | // that compare the output of this program to the expected file. |
compare-for-test/qtest/compare.test
| @@ -73,7 +73,7 @@ foreach my $f (@diff) | @@ -73,7 +73,7 @@ foreach my $f (@diff) | ||
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | # Repeat for encrypted files. | 75 | # Repeat for encrypted files. |
| 76 | -$n_tests += 3; | 76 | +$n_tests += 5; |
| 77 | $td->runtest("byte-wise compare encrypted files", | 77 | $td->runtest("byte-wise compare encrypted files", |
| 78 | {$td->COMMAND => "cmp enc1.pdf enc2.pdf"}, | 78 | {$td->COMMAND => "cmp enc1.pdf enc2.pdf"}, |
| 79 | {$td->REGEXP => ".*", $td->EXIT_STATUS => "!0"}); | 79 | {$td->REGEXP => ".*", $td->EXIT_STATUS => "!0"}); |
| @@ -84,6 +84,13 @@ $td->runtest("compare encrypted files (different)", | @@ -84,6 +84,13 @@ $td->runtest("compare encrypted files (different)", | ||
| 84 | {$td->COMMAND => "env QPDF_COMPARE_WHY=1 qpdf-test-compare enc1.pdf diff-data-enc.pdf"}, | 84 | {$td->COMMAND => "env QPDF_COMPARE_WHY=1 qpdf-test-compare enc1.pdf diff-data-enc.pdf"}, |
| 85 | {$td->STRING => "4,0: stream data differs\n", $td->EXIT_STATUS => 2}, | 85 | {$td->STRING => "4,0: stream data differs\n", $td->EXIT_STATUS => 2}, |
| 86 | $td->NORMALIZE_NEWLINES); | 86 | $td->NORMALIZE_NEWLINES); |
| 87 | +$td->runtest("with password (same)", | ||
| 88 | + {$td->COMMAND => "env QPDF_COMPARE_WHY=1 qpdf-test-compare enc1.pdf enc2.pdf o"}, | ||
| 89 | + {$td->FILE => "enc2.pdf", $td->EXIT_STATUS => 0}); | ||
| 90 | +$td->runtest("with password (different)", | ||
| 91 | + {$td->COMMAND => "env QPDF_COMPARE_WHY=1 qpdf-test-compare enc1.pdf diff-data-enc.pdf o"}, | ||
| 92 | + {$td->STRING => "4,0: stream data differs\n", $td->EXIT_STATUS => 2}, | ||
| 93 | + $td->NORMALIZE_NEWLINES); | ||
| 87 | 94 | ||
| 88 | # Object streams | 95 | # Object streams |
| 89 | $n_tests += 1; | 96 | $n_tests += 1; |