Commit 65bf77fa3537724b646880d7dacd34f4e4c8b67e
1 parent
fe6771e0
more tests of C API
git-svn-id: svn+q:///qpdf/trunk@728 71b93d88-0707-0410-a8cf-f5a4172ac649
Showing
12 changed files
with
3694 additions
and
0 deletions
ChangeLog
| 1 | +2009-09-27 Jay Berkenbilt <ejb@ql.org> | |
| 2 | + | |
| 3 | + * The function QPDF::getUserPassword returned the user password | |
| 4 | + with the required padding as specified by the PDF specification. | |
| 5 | + This is seldom useful to users. This function has been replaced | |
| 6 | + by QPDF::getPaddedUserPassword. Call the new | |
| 7 | + QPDF::getTrimmedUserPassword to retreive the user password in a | |
| 8 | + human-readable format. | |
| 9 | + | |
| 10 | + * qpdf/qpdf.cc (main): qpdf --check now prints the PDF version | |
| 11 | + number in addition to its other output. | |
| 12 | + | |
| 1 | 13 | 2009-09-26 Jay Berkenbilt <ejb@ql.org> |
| 2 | 14 | |
| 3 | 15 | * Removed all references to QEXC; now using std::runtime_error and | ... | ... |
qpdf/qpdf-ctest.c
| ... | ... | @@ -33,6 +33,105 @@ static void test01(char const* infile, |
| 33 | 33 | report_errors(); |
| 34 | 34 | } |
| 35 | 35 | |
| 36 | +static void test02(char const* infile, | |
| 37 | + char const* password, | |
| 38 | + char const* outfile) | |
| 39 | +{ | |
| 40 | + qpdf_set_suppress_warnings(qpdf, QPDF_TRUE); | |
| 41 | + qpdf_read(qpdf, infile, password); | |
| 42 | + if (qpdf_init_write(qpdf, outfile) == QPDF_SUCCESS) | |
| 43 | + { | |
| 44 | + qpdf_set_static_ID(qpdf, QPDF_TRUE); | |
| 45 | + qpdf_write(qpdf); | |
| 46 | + } | |
| 47 | + report_errors(); | |
| 48 | +} | |
| 49 | + | |
| 50 | +static void test03(char const* infile, | |
| 51 | + char const* password, | |
| 52 | + char const* outfile) | |
| 53 | +{ | |
| 54 | + qpdf_read(qpdf, infile, password); | |
| 55 | + qpdf_init_write(qpdf, outfile); | |
| 56 | + qpdf_set_static_ID(qpdf, QPDF_TRUE); | |
| 57 | + qpdf_set_content_normalization(qpdf, QPDF_TRUE); | |
| 58 | + qpdf_write(qpdf); | |
| 59 | + report_errors(); | |
| 60 | +} | |
| 61 | + | |
| 62 | +static void test04(char const* infile, | |
| 63 | + char const* password, | |
| 64 | + char const* outfile) | |
| 65 | +{ | |
| 66 | + qpdf_set_ignore_xref_streams(qpdf, QPDF_TRUE); | |
| 67 | + qpdf_read(qpdf, infile, password); | |
| 68 | + qpdf_init_write(qpdf, outfile); | |
| 69 | + qpdf_set_static_ID(qpdf, QPDF_TRUE); | |
| 70 | + qpdf_write(qpdf); | |
| 71 | + report_errors(); | |
| 72 | +} | |
| 73 | + | |
| 74 | +static void test05(char const* infile, | |
| 75 | + char const* password, | |
| 76 | + char const* outfile) | |
| 77 | +{ | |
| 78 | + qpdf_read(qpdf, infile, password); | |
| 79 | + qpdf_init_write(qpdf, outfile); | |
| 80 | + qpdf_set_static_ID(qpdf, QPDF_TRUE); | |
| 81 | + qpdf_set_linearization(qpdf, QPDF_TRUE); | |
| 82 | + qpdf_write(qpdf); | |
| 83 | + report_errors(); | |
| 84 | +} | |
| 85 | + | |
| 86 | +static void test06(char const* infile, | |
| 87 | + char const* password, | |
| 88 | + char const* outfile) | |
| 89 | +{ | |
| 90 | + qpdf_read(qpdf, infile, password); | |
| 91 | + qpdf_init_write(qpdf, outfile); | |
| 92 | + qpdf_set_static_ID(qpdf, QPDF_TRUE); | |
| 93 | + qpdf_set_object_stream_mode(qpdf, QPDF_OBJECT_STREAM_GENERATE); | |
| 94 | + qpdf_write(qpdf); | |
| 95 | + report_errors(); | |
| 96 | +} | |
| 97 | + | |
| 98 | +static void test07(char const* infile, | |
| 99 | + char const* password, | |
| 100 | + char const* outfile) | |
| 101 | +{ | |
| 102 | + qpdf_read(qpdf, infile, password); | |
| 103 | + qpdf_init_write(qpdf, outfile); | |
| 104 | + qpdf_set_static_ID(qpdf, QPDF_TRUE); | |
| 105 | + qpdf_set_qdf_mode(qpdf, QPDF_TRUE); | |
| 106 | + qpdf_write(qpdf); | |
| 107 | + report_errors(); | |
| 108 | +} | |
| 109 | + | |
| 110 | +static void test08(char const* infile, | |
| 111 | + char const* password, | |
| 112 | + char const* outfile) | |
| 113 | +{ | |
| 114 | + qpdf_read(qpdf, infile, password); | |
| 115 | + qpdf_init_write(qpdf, outfile); | |
| 116 | + qpdf_set_static_ID(qpdf, QPDF_TRUE); | |
| 117 | + qpdf_set_qdf_mode(qpdf, QPDF_TRUE); | |
| 118 | + qpdf_set_suppress_original_object_IDs(qpdf, QPDF_TRUE); | |
| 119 | + qpdf_write(qpdf); | |
| 120 | + report_errors(); | |
| 121 | +} | |
| 122 | + | |
| 123 | +static void test09(char const* infile, | |
| 124 | + char const* password, | |
| 125 | + char const* outfile) | |
| 126 | +{ | |
| 127 | + qpdf_read(qpdf, infile, password); | |
| 128 | + qpdf_init_write(qpdf, outfile); | |
| 129 | + qpdf_set_static_ID(qpdf, QPDF_TRUE); | |
| 130 | + qpdf_set_stream_data_mode(qpdf, QPDF_STREAM_DATA_UNCOMPRESS); | |
| 131 | + qpdf_write(qpdf); | |
| 132 | + report_errors(); | |
| 133 | +} | |
| 134 | + | |
| 36 | 135 | int main(int argc, char* argv[]) |
| 37 | 136 | { |
| 38 | 137 | char* whoami = 0; |
| ... | ... | @@ -67,6 +166,14 @@ int main(int argc, char* argv[]) |
| 67 | 166 | outfile = argv[4]; |
| 68 | 167 | |
| 69 | 168 | fn = ((n == 1) ? test01 : |
| 169 | + (n == 2) ? test02 : | |
| 170 | + (n == 3) ? test03 : | |
| 171 | + (n == 4) ? test04 : | |
| 172 | + (n == 5) ? test05 : | |
| 173 | + (n == 6) ? test06 : | |
| 174 | + (n == 7) ? test07 : | |
| 175 | + (n == 8) ? test08 : | |
| 176 | + (n == 9) ? test09 : | |
| 70 | 177 | 0); |
| 71 | 178 | |
| 72 | 179 | if (fn == 0) | ... | ... |
qpdf/qtest/qpdf.test
| ... | ... | @@ -298,6 +298,56 @@ check_pdf("no recompression", |
| 298 | 298 | |
| 299 | 299 | show_ntests(); |
| 300 | 300 | # ---------- |
| 301 | +$td->notify("--- C API Tests ---"); | |
| 302 | + | |
| 303 | +my @capi = ( | |
| 304 | + [2, 'no options'], | |
| 305 | + [3, 'normalized content'], | |
| 306 | + [4, 'ignore xref streams'], | |
| 307 | + [5, 'linearized'], | |
| 308 | + [6, 'object streams'], | |
| 309 | + [7, 'qdf'], | |
| 310 | + [8, 'no original object ids'], | |
| 311 | + [9, 'uncompressed streams'], | |
| 312 | + ); | |
| 313 | +$n_tests += (2 * @capi) + 3; | |
| 314 | +foreach my $d (@capi) | |
| 315 | +{ | |
| 316 | + my ($n, $description) = @$d; | |
| 317 | + my $outfile = $description; | |
| 318 | + $outfile =~ s/ /-/g; | |
| 319 | + $outfile = "c-$outfile.pdf"; | |
| 320 | + $td->runtest($description, | |
| 321 | + {$td->COMMAND => "qpdf-ctest $n hybrid-xref.pdf '' a.pdf"}, | |
| 322 | + {$td->STRING => "", $td->EXIT_STATUS => 0}); | |
| 323 | + $td->runtest("check $description", | |
| 324 | + {$td->FILE => "a.pdf"}, | |
| 325 | + {$td->FILE => $outfile}); | |
| 326 | +} | |
| 327 | +$td->runtest("write to bad file name", | |
| 328 | + {$td->COMMAND => "qpdf-ctest 2 hybrid-xref.pdf '' /:a:/:b:"}, | |
| 329 | + {$td->REGEXP => "error: open /:a:/:b:: .*", | |
| 330 | + $td->EXIT_STATUS => 0}, | |
| 331 | + $td->NORMALIZE_NEWLINES); | |
| 332 | + | |
| 333 | +$td->runtest("write damaged to bad file name", | |
| 334 | + {$td->COMMAND => "qpdf-ctest 2 append-page-content-damaged.pdf" . | |
| 335 | + " '' /:a:/:b:"}, | |
| 336 | + {$td->REGEXP => | |
| 337 | + "warning:(?s:.*)\n" . | |
| 338 | + "error: open /:a:/:b:: .*", | |
| 339 | + $td->EXIT_STATUS => 0}, | |
| 340 | + $td->NORMALIZE_NEWLINES); | |
| 341 | + | |
| 342 | +$td->runtest("write damaged", | |
| 343 | + {$td->COMMAND => "qpdf-ctest 2 append-page-content-damaged.pdf" . | |
| 344 | + " '' a.pdf"}, | |
| 345 | + {$td->FILE => "c-write-damaged.out", | |
| 346 | + $td->EXIT_STATUS => 0}, | |
| 347 | + $td->NORMALIZE_NEWLINES); | |
| 348 | + | |
| 349 | +show_ntests(); | |
| 350 | +# ---------- | |
| 301 | 351 | $td->notify("--- Object Stream Tests ---"); |
| 302 | 352 | $n_tests += (36 * 4) + (12 * 2); |
| 303 | 353 | $n_compare_pdfs += 36; | ... | ... |
qpdf/qtest/qpdf/c-ignore-xref-streams.pdf
0 → 100644
No preview for this file type
qpdf/qtest/qpdf/c-linearized.pdf
0 → 100644
No preview for this file type
qpdf/qtest/qpdf/c-no-options.pdf
0 → 100644
No preview for this file type
qpdf/qtest/qpdf/c-no-original-object-ids.pdf
0 → 100644
No preview for this file type
qpdf/qtest/qpdf/c-normalized-content.pdf
0 → 100644
No preview for this file type
qpdf/qtest/qpdf/c-object-streams.pdf
0 → 100644
No preview for this file type
qpdf/qtest/qpdf/c-qdf.pdf
0 → 100644
No preview for this file type
qpdf/qtest/qpdf/c-uncompressed-streams.pdf
0 → 100644
No preview for this file type
qpdf/qtest/qpdf/c-write-damaged.out
0 → 100644