From 6c5e590673331aa685afe8aa997b0b7e64996004 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Thu, 19 May 2022 17:27:41 -0400 Subject: Rename all test files: _ to - --- qpdf/qtest/appearance-streams.test | 89 +++++++++++++ qpdf/qtest/appearance_streams.test | 89 ------------- qpdf/qtest/arg-parsing.test | 90 +++++++++++++ qpdf/qtest/arg_parsing.test | 90 ------------- qpdf/qtest/basic-parsing.test | 77 +++++++++++ qpdf/qtest/basic_parsing.test | 77 ----------- qpdf/qtest/bound-checks.test | 38 ++++++ qpdf/qtest/bound_checks.test | 38 ------ qpdf/qtest/c-api-check.test | 30 +++++ qpdf/qtest/c-api-key.test | 40 ++++++ qpdf/qtest/c-api-object-handle.test | 75 +++++++++++ qpdf/qtest/c-api-page.test | 45 +++++++ qpdf/qtest/c-api-stream.test | 43 ++++++ qpdf/qtest/c-api.test | 73 +++++++++++ qpdf/qtest/c_api.test | 73 ----------- qpdf/qtest/c_api_check.test | 30 ----- qpdf/qtest/c_api_key.test | 40 ------ qpdf/qtest/c_api_object_handle.test | 75 ----------- qpdf/qtest/c_api_page.test | 45 ------- qpdf/qtest/c_api_stream.test | 43 ------ qpdf/qtest/character-encoding.test | 40 ++++++ qpdf/qtest/character_encoding.test | 40 ------ qpdf/qtest/check-encryption.test | 60 +++++++++ qpdf/qtest/check_encryption.test | 60 --------- qpdf/qtest/cleartext-metadata.test | 72 ++++++++++ qpdf/qtest/cleartext_metadata.test | 72 ---------- qpdf/qtest/coalesce-contents.test | 53 ++++++++ qpdf/qtest/coalesce_contents.test | 53 -------- qpdf/qtest/compare-pdfs.test | 31 +++++ qpdf/qtest/compare_pdfs.test | 31 ----- qpdf/qtest/compression-level.test | 29 ++++ qpdf/qtest/compression_level.test | 29 ---- qpdf/qtest/content-preservation.test | 101 ++++++++++++++ qpdf/qtest/content_preservation.test | 101 -------------- qpdf/qtest/copy-annotations.test | 186 ++++++++++++++++++++++++++ qpdf/qtest/copy-foreign-objects.test | 63 +++++++++ qpdf/qtest/copy_annotations.test | 186 -------------------------- qpdf/qtest/copy_foreign_objects.test | 63 --------- qpdf/qtest/custom-pipeline.test | 28 ++++ qpdf/qtest/custom_pipeline.test | 28 ---- qpdf/qtest/dangling-refs.test | 31 +++++ qpdf/qtest/dangling_refs.test | 31 ----- qpdf/qtest/decode-levels.test | 71 ++++++++++ qpdf/qtest/decode-parameters.test | 48 +++++++ qpdf/qtest/decode_levels.test | 71 ---------- qpdf/qtest/decode_parameters.test | 48 ------- qpdf/qtest/deterministic-id.test | 55 ++++++++ qpdf/qtest/deterministic_id.test | 55 -------- qpdf/qtest/disable-filter-on-write.test | 28 ++++ qpdf/qtest/disable_filter_on_write.test | 28 ---- qpdf/qtest/encryption-parameters.test | 88 +++++++++++++ qpdf/qtest/encryption_parameters.test | 88 ------------- qpdf/qtest/error-condition.test | 211 ++++++++++++++++++++++++++++++ qpdf/qtest/error_condition.test | 211 ------------------------------ qpdf/qtest/extensions-dictionary.test | 64 +++++++++ qpdf/qtest/extensions_dictionary.test | 64 --------- qpdf/qtest/filter-abbreviations.test | 30 +++++ qpdf/qtest/filter_abbreviations.test | 30 ----- qpdf/qtest/final-version.test | 25 ++++ qpdf/qtest/final_version.test | 25 ---- qpdf/qtest/fix-qdf.test | 37 ++++++ qpdf/qtest/fix_qdf.test | 37 ------ qpdf/qtest/flatten-annotations.test | 94 +++++++++++++ qpdf/qtest/flatten_annotations.test | 94 ------------- qpdf/qtest/form-xobject.test | 101 ++++++++++++++ qpdf/qtest/form_xobject.test | 101 -------------- qpdf/qtest/from-scratch.test | 27 ++++ qpdf/qtest/from_scratch.test | 27 ---- qpdf/qtest/get-xref.test | 32 +++++ qpdf/qtest/get_xref.test | 32 ----- qpdf/qtest/image-optimization.test | 60 +++++++++ qpdf/qtest/image_optimization.test | 60 --------- qpdf/qtest/inline-images.test | 110 ++++++++++++++++ qpdf/qtest/inline_images.test | 110 ---------------- qpdf/qtest/interactive-form.test | 74 +++++++++++ qpdf/qtest/interactive_form.test | 74 ----------- qpdf/qtest/invalid-objects.test | 37 ++++++ qpdf/qtest/invalid_objects.test | 37 ------ qpdf/qtest/keep-files-open.test | 60 +++++++++ qpdf/qtest/keep_files_open.test | 60 --------- qpdf/qtest/large-file.test | 132 +++++++++++++++++++ qpdf/qtest/large_file.test | 132 ------------------- qpdf/qtest/library-version.test | 35 +++++ qpdf/qtest/library_version.test | 35 ----- qpdf/qtest/linearize-pass1.test | 31 +++++ qpdf/qtest/linearize_pass1.test | 31 ----- qpdf/qtest/merge-and-split.test | 186 ++++++++++++++++++++++++++ qpdf/qtest/merge-dictionary.test | 32 +++++ qpdf/qtest/merge_and_split.test | 186 -------------------------- qpdf/qtest/merge_dictionary.test | 32 ----- qpdf/qtest/multiple-indirection.test | 34 +++++ qpdf/qtest/multiple_indirection.test | 34 ----- qpdf/qtest/name-normalization.test | 52 ++++++++ qpdf/qtest/name-number-trees.test | 43 ++++++ qpdf/qtest/name_normalization.test | 52 -------- qpdf/qtest/name_number_trees.test | 43 ------ qpdf/qtest/newline-before-endstream.test | 59 +++++++++ qpdf/qtest/newline_before_endstream.test | 59 --------- qpdf/qtest/numbers-and-strings.test | 29 ++++ qpdf/qtest/numbers_and_strings.test | 29 ---- qpdf/qtest/object-copying.test | 55 ++++++++ qpdf/qtest/object-handle-api.test | 29 ++++ qpdf/qtest/object-stream.test | 91 +++++++++++++ qpdf/qtest/object_copying.test | 55 -------- qpdf/qtest/object_handle_api.test | 29 ---- qpdf/qtest/object_stream.test | 91 ------------- qpdf/qtest/output-redirection.test | 32 +++++ qpdf/qtest/output_redirection.test | 32 ----- qpdf/qtest/overwrite-self.test | 38 ++++++ qpdf/qtest/overwrite_self.test | 38 ------ qpdf/qtest/page-api.test | 62 +++++++++ qpdf/qtest/page-errors.test | 40 ++++++ qpdf/qtest/page-labels.test | 33 +++++ qpdf/qtest/page-without-contents.test | 43 ++++++ qpdf/qtest/page_api.test | 62 --------- qpdf/qtest/page_errors.test | 40 ------ qpdf/qtest/page_labels.test | 33 ----- qpdf/qtest/page_without_contents.test | 43 ------ qpdf/qtest/pages-tree.test | 71 ++++++++++ qpdf/qtest/pages_tree.test | 71 ---------- qpdf/qtest/parsed-offset.test | 32 +++++ qpdf/qtest/parsed_offset.test | 32 ----- qpdf/qtest/positive-p.test | 41 ++++++ qpdf/qtest/positive_p.test | 41 ------ qpdf/qtest/precheck-streams.test | 28 ++++ qpdf/qtest/precheck_streams.test | 28 ---- qpdf/qtest/preserve-unref.test | 41 ++++++ qpdf/qtest/preserve_unref.test | 41 ------ qpdf/qtest/progress-reporting.test | 26 ++++ qpdf/qtest/progress_reporting.test | 26 ---- qpdf/qtest/qpdf-json.test | 50 +++++++ qpdf/qtest/qpdf_json.test | 50 ------- qpdf/qtest/renumber-objects.test | 74 +++++++++++ qpdf/qtest/renumber_objects.test | 74 ----------- qpdf/qtest/replace-input.test | 56 ++++++++ qpdf/qtest/replace_input.test | 56 -------- qpdf/qtest/rotate-pages.test | 104 +++++++++++++++ qpdf/qtest/rotate_pages.test | 104 --------------- qpdf/qtest/signature-dictionary.test | 132 +++++++++++++++++++ qpdf/qtest/signature_dictionary.test | 132 ------------------- qpdf/qtest/specialized-filter.test | 44 +++++++ qpdf/qtest/specialized_filter.test | 44 ------- qpdf/qtest/specific-bugs.test | 82 ++++++++++++ qpdf/qtest/specific-file.test | 67 ++++++++++ qpdf/qtest/specific_bugs.test | 82 ------------ qpdf/qtest/specific_file.test | 67 ---------- qpdf/qtest/split-pages.test | 213 ++++++++++++++++++++++++++++++ qpdf/qtest/split_pages.test | 213 ------------------------------ qpdf/qtest/stream-data.test | 29 ++++ qpdf/qtest/stream-line-terminators.test | 31 +++++ qpdf/qtest/stream-replacements.test | 56 ++++++++ qpdf/qtest/stream_data.test | 29 ---- qpdf/qtest/stream_line_terminators.test | 31 ----- qpdf/qtest/stream_replacements.test | 56 -------- qpdf/qtest/swap-and-replace.test | 37 ++++++ qpdf/qtest/swap_and_replace.test | 37 ------ qpdf/qtest/token-filters.test | 28 ++++ qpdf/qtest/token_filters.test | 28 ---- qpdf/qtest/type-checks.test | 48 +++++++ qpdf/qtest/type_checks.test | 48 ------- qpdf/qtest/unicode-filenames.test | 36 +++++ qpdf/qtest/unicode-password.test | 218 +++++++++++++++++++++++++++++++ qpdf/qtest/unicode_filenames.test | 36 ----- qpdf/qtest/unicode_password.test | 218 ------------------------------- qpdf/qtest/weak-cryptography.test | 40 ++++++ qpdf/qtest/weak_cryptography.test | 40 ------ qpdf/qtest/windows-shell-globbing.test | 25 ++++ qpdf/qtest/windows_shell_globbing.test | 25 ---- qpdf/qtest/writer-version.test | 58 ++++++++ qpdf/qtest/writer_version.test | 58 -------- qpdf/qtest/xref-errors.test | 66 ++++++++++ qpdf/qtest/xref-streams.test | 37 ++++++ qpdf/qtest/xref_errors.test | 66 ---------- qpdf/qtest/xref_streams.test | 37 ------ 174 files changed, 5372 insertions(+), 5372 deletions(-) create mode 100644 qpdf/qtest/appearance-streams.test delete mode 100644 qpdf/qtest/appearance_streams.test create mode 100644 qpdf/qtest/arg-parsing.test delete mode 100644 qpdf/qtest/arg_parsing.test create mode 100644 qpdf/qtest/basic-parsing.test delete mode 100644 qpdf/qtest/basic_parsing.test create mode 100644 qpdf/qtest/bound-checks.test delete mode 100644 qpdf/qtest/bound_checks.test create mode 100644 qpdf/qtest/c-api-check.test create mode 100644 qpdf/qtest/c-api-key.test create mode 100644 qpdf/qtest/c-api-object-handle.test create mode 100644 qpdf/qtest/c-api-page.test create mode 100644 qpdf/qtest/c-api-stream.test create mode 100644 qpdf/qtest/c-api.test delete mode 100644 qpdf/qtest/c_api.test delete mode 100644 qpdf/qtest/c_api_check.test delete mode 100644 qpdf/qtest/c_api_key.test delete mode 100644 qpdf/qtest/c_api_object_handle.test delete mode 100644 qpdf/qtest/c_api_page.test delete mode 100644 qpdf/qtest/c_api_stream.test create mode 100644 qpdf/qtest/character-encoding.test delete mode 100644 qpdf/qtest/character_encoding.test create mode 100644 qpdf/qtest/check-encryption.test delete mode 100644 qpdf/qtest/check_encryption.test create mode 100644 qpdf/qtest/cleartext-metadata.test delete mode 100644 qpdf/qtest/cleartext_metadata.test create mode 100644 qpdf/qtest/coalesce-contents.test delete mode 100644 qpdf/qtest/coalesce_contents.test create mode 100644 qpdf/qtest/compare-pdfs.test delete mode 100644 qpdf/qtest/compare_pdfs.test create mode 100644 qpdf/qtest/compression-level.test delete mode 100644 qpdf/qtest/compression_level.test create mode 100644 qpdf/qtest/content-preservation.test delete mode 100644 qpdf/qtest/content_preservation.test create mode 100644 qpdf/qtest/copy-annotations.test create mode 100644 qpdf/qtest/copy-foreign-objects.test delete mode 100644 qpdf/qtest/copy_annotations.test delete mode 100644 qpdf/qtest/copy_foreign_objects.test create mode 100644 qpdf/qtest/custom-pipeline.test delete mode 100644 qpdf/qtest/custom_pipeline.test create mode 100644 qpdf/qtest/dangling-refs.test delete mode 100644 qpdf/qtest/dangling_refs.test create mode 100644 qpdf/qtest/decode-levels.test create mode 100644 qpdf/qtest/decode-parameters.test delete mode 100644 qpdf/qtest/decode_levels.test delete mode 100644 qpdf/qtest/decode_parameters.test create mode 100644 qpdf/qtest/deterministic-id.test delete mode 100644 qpdf/qtest/deterministic_id.test create mode 100644 qpdf/qtest/disable-filter-on-write.test delete mode 100644 qpdf/qtest/disable_filter_on_write.test create mode 100644 qpdf/qtest/encryption-parameters.test delete mode 100644 qpdf/qtest/encryption_parameters.test create mode 100644 qpdf/qtest/error-condition.test delete mode 100644 qpdf/qtest/error_condition.test create mode 100644 qpdf/qtest/extensions-dictionary.test delete mode 100644 qpdf/qtest/extensions_dictionary.test create mode 100644 qpdf/qtest/filter-abbreviations.test delete mode 100644 qpdf/qtest/filter_abbreviations.test create mode 100644 qpdf/qtest/final-version.test delete mode 100644 qpdf/qtest/final_version.test create mode 100644 qpdf/qtest/fix-qdf.test delete mode 100644 qpdf/qtest/fix_qdf.test create mode 100644 qpdf/qtest/flatten-annotations.test delete mode 100644 qpdf/qtest/flatten_annotations.test create mode 100644 qpdf/qtest/form-xobject.test delete mode 100644 qpdf/qtest/form_xobject.test create mode 100644 qpdf/qtest/from-scratch.test delete mode 100644 qpdf/qtest/from_scratch.test create mode 100644 qpdf/qtest/get-xref.test delete mode 100644 qpdf/qtest/get_xref.test create mode 100644 qpdf/qtest/image-optimization.test delete mode 100644 qpdf/qtest/image_optimization.test create mode 100644 qpdf/qtest/inline-images.test delete mode 100644 qpdf/qtest/inline_images.test create mode 100644 qpdf/qtest/interactive-form.test delete mode 100644 qpdf/qtest/interactive_form.test create mode 100644 qpdf/qtest/invalid-objects.test delete mode 100644 qpdf/qtest/invalid_objects.test create mode 100644 qpdf/qtest/keep-files-open.test delete mode 100644 qpdf/qtest/keep_files_open.test create mode 100644 qpdf/qtest/large-file.test delete mode 100644 qpdf/qtest/large_file.test create mode 100644 qpdf/qtest/library-version.test delete mode 100644 qpdf/qtest/library_version.test create mode 100644 qpdf/qtest/linearize-pass1.test delete mode 100644 qpdf/qtest/linearize_pass1.test create mode 100644 qpdf/qtest/merge-and-split.test create mode 100644 qpdf/qtest/merge-dictionary.test delete mode 100644 qpdf/qtest/merge_and_split.test delete mode 100644 qpdf/qtest/merge_dictionary.test create mode 100644 qpdf/qtest/multiple-indirection.test delete mode 100644 qpdf/qtest/multiple_indirection.test create mode 100644 qpdf/qtest/name-normalization.test create mode 100644 qpdf/qtest/name-number-trees.test delete mode 100644 qpdf/qtest/name_normalization.test delete mode 100644 qpdf/qtest/name_number_trees.test create mode 100644 qpdf/qtest/newline-before-endstream.test delete mode 100644 qpdf/qtest/newline_before_endstream.test create mode 100644 qpdf/qtest/numbers-and-strings.test delete mode 100644 qpdf/qtest/numbers_and_strings.test create mode 100644 qpdf/qtest/object-copying.test create mode 100644 qpdf/qtest/object-handle-api.test create mode 100644 qpdf/qtest/object-stream.test delete mode 100644 qpdf/qtest/object_copying.test delete mode 100644 qpdf/qtest/object_handle_api.test delete mode 100644 qpdf/qtest/object_stream.test create mode 100644 qpdf/qtest/output-redirection.test delete mode 100644 qpdf/qtest/output_redirection.test create mode 100644 qpdf/qtest/overwrite-self.test delete mode 100644 qpdf/qtest/overwrite_self.test create mode 100644 qpdf/qtest/page-api.test create mode 100644 qpdf/qtest/page-errors.test create mode 100644 qpdf/qtest/page-labels.test create mode 100644 qpdf/qtest/page-without-contents.test delete mode 100644 qpdf/qtest/page_api.test delete mode 100644 qpdf/qtest/page_errors.test delete mode 100644 qpdf/qtest/page_labels.test delete mode 100644 qpdf/qtest/page_without_contents.test create mode 100644 qpdf/qtest/pages-tree.test delete mode 100644 qpdf/qtest/pages_tree.test create mode 100644 qpdf/qtest/parsed-offset.test delete mode 100644 qpdf/qtest/parsed_offset.test create mode 100644 qpdf/qtest/positive-p.test delete mode 100644 qpdf/qtest/positive_p.test create mode 100644 qpdf/qtest/precheck-streams.test delete mode 100644 qpdf/qtest/precheck_streams.test create mode 100644 qpdf/qtest/preserve-unref.test delete mode 100644 qpdf/qtest/preserve_unref.test create mode 100644 qpdf/qtest/progress-reporting.test delete mode 100644 qpdf/qtest/progress_reporting.test create mode 100644 qpdf/qtest/qpdf-json.test delete mode 100644 qpdf/qtest/qpdf_json.test create mode 100644 qpdf/qtest/renumber-objects.test delete mode 100644 qpdf/qtest/renumber_objects.test create mode 100644 qpdf/qtest/replace-input.test delete mode 100644 qpdf/qtest/replace_input.test create mode 100644 qpdf/qtest/rotate-pages.test delete mode 100644 qpdf/qtest/rotate_pages.test create mode 100644 qpdf/qtest/signature-dictionary.test delete mode 100644 qpdf/qtest/signature_dictionary.test create mode 100644 qpdf/qtest/specialized-filter.test delete mode 100644 qpdf/qtest/specialized_filter.test create mode 100644 qpdf/qtest/specific-bugs.test create mode 100644 qpdf/qtest/specific-file.test delete mode 100644 qpdf/qtest/specific_bugs.test delete mode 100644 qpdf/qtest/specific_file.test create mode 100644 qpdf/qtest/split-pages.test delete mode 100644 qpdf/qtest/split_pages.test create mode 100644 qpdf/qtest/stream-data.test create mode 100644 qpdf/qtest/stream-line-terminators.test create mode 100644 qpdf/qtest/stream-replacements.test delete mode 100644 qpdf/qtest/stream_data.test delete mode 100644 qpdf/qtest/stream_line_terminators.test delete mode 100644 qpdf/qtest/stream_replacements.test create mode 100644 qpdf/qtest/swap-and-replace.test delete mode 100644 qpdf/qtest/swap_and_replace.test create mode 100644 qpdf/qtest/token-filters.test delete mode 100644 qpdf/qtest/token_filters.test create mode 100644 qpdf/qtest/type-checks.test delete mode 100644 qpdf/qtest/type_checks.test create mode 100644 qpdf/qtest/unicode-filenames.test create mode 100644 qpdf/qtest/unicode-password.test delete mode 100644 qpdf/qtest/unicode_filenames.test delete mode 100644 qpdf/qtest/unicode_password.test create mode 100644 qpdf/qtest/weak-cryptography.test delete mode 100644 qpdf/qtest/weak_cryptography.test create mode 100644 qpdf/qtest/windows-shell-globbing.test delete mode 100644 qpdf/qtest/windows_shell_globbing.test create mode 100644 qpdf/qtest/writer-version.test delete mode 100644 qpdf/qtest/writer_version.test create mode 100644 qpdf/qtest/xref-errors.test create mode 100644 qpdf/qtest/xref-streams.test delete mode 100644 qpdf/qtest/xref_errors.test delete mode 100644 qpdf/qtest/xref_streams.test diff --git a/qpdf/qtest/appearance-streams.test b/qpdf/qtest/appearance-streams.test new file mode 100644 index 00000000..25232c65 --- /dev/null +++ b/qpdf/qtest/appearance-streams.test @@ -0,0 +1,89 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('appearance-streams'); + +my $n_tests = 12; + +foreach my $f ('need-appearances', + 'need-appearances-more', + 'need-appearances-more2', + 'need-appearances-more3') +{ + $td->runtest("generate appearances and flatten ($f)", + {$td->COMMAND => + "qpdf --qdf --no-original-object-ids --static-id" . + " --generate-appearances --flatten-annotations=all" . + " $f.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + my $exp = 'appearances-a'; + if ($f =~ m/appearances(-.*)$/) + { + $exp .= $1; + } + $exp .= '.pdf'; + $td->runtest("compare files", + {$td->FILE => "a.pdf"}, + {$td->FILE => $exp}); +} + +$td->runtest("more choices", + {$td->COMMAND => + "qpdf --qdf --no-original-object-ids --static-id" . + " --generate-appearances" . + " more-choices.pdf b.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +# b.pdf still has forms +$td->runtest("compare files", + {$td->FILE => "b.pdf"}, + {$td->FILE => "appearances-b.pdf"}); + +my @choice_values = qw(1 2 11 12 quack); +$n_tests += 3 * scalar(@choice_values); +foreach my $i (@choice_values) +{ + # b.pdf was generated by qpdf and needs appearances + # test_driver 52 writes a.pdf + $td->runtest("set value to $i", + {$td->COMMAND => "test_driver 52 b.pdf $i"}, + {$td->STRING => "setting list1 value\ntest 52 done\n", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("regenerate appearances", + {$td->COMMAND => + "qpdf --qdf --no-original-object-ids --static-id" . + " --generate-appearances" . + " a.pdf b.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("compare files", + {$td->FILE => "b.pdf"}, + {$td->FILE => "appearances-$i.pdf"}); +} + +$td->runtest("Update resources from /DR", + {$td->COMMAND => + "qpdf --qdf --no-original-object-ids --static-id" . + " --generate-appearances" . + " resource-from-dr.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("compare files", + {$td->FILE => "a.pdf"}, + {$td->FILE => "resource-from-dr-out.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/appearance_streams.test b/qpdf/qtest/appearance_streams.test deleted file mode 100644 index 764a34c7..00000000 --- a/qpdf/qtest/appearance_streams.test +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('appearance_streams'); - -my $n_tests = 12; - -foreach my $f ('need-appearances', - 'need-appearances-more', - 'need-appearances-more2', - 'need-appearances-more3') -{ - $td->runtest("generate appearances and flatten ($f)", - {$td->COMMAND => - "qpdf --qdf --no-original-object-ids --static-id" . - " --generate-appearances --flatten-annotations=all" . - " $f.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - my $exp = 'appearances-a'; - if ($f =~ m/appearances(-.*)$/) - { - $exp .= $1; - } - $exp .= '.pdf'; - $td->runtest("compare files", - {$td->FILE => "a.pdf"}, - {$td->FILE => $exp}); -} - -$td->runtest("more choices", - {$td->COMMAND => - "qpdf --qdf --no-original-object-ids --static-id" . - " --generate-appearances" . - " more-choices.pdf b.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -# b.pdf still has forms -$td->runtest("compare files", - {$td->FILE => "b.pdf"}, - {$td->FILE => "appearances-b.pdf"}); - -my @choice_values = qw(1 2 11 12 quack); -$n_tests += 3 * scalar(@choice_values); -foreach my $i (@choice_values) -{ - # b.pdf was generated by qpdf and needs appearances - # test_driver 52 writes a.pdf - $td->runtest("set value to $i", - {$td->COMMAND => "test_driver 52 b.pdf $i"}, - {$td->STRING => "setting list1 value\ntest 52 done\n", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("regenerate appearances", - {$td->COMMAND => - "qpdf --qdf --no-original-object-ids --static-id" . - " --generate-appearances" . - " a.pdf b.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("compare files", - {$td->FILE => "b.pdf"}, - {$td->FILE => "appearances-$i.pdf"}); -} - -$td->runtest("Update resources from /DR", - {$td->COMMAND => - "qpdf --qdf --no-original-object-ids --static-id" . - " --generate-appearances" . - " resource-from-dr.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("compare files", - {$td->FILE => "a.pdf"}, - {$td->FILE => "resource-from-dr-out.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/arg-parsing.test b/qpdf/qtest/arg-parsing.test new file mode 100644 index 00000000..b8bd1051 --- /dev/null +++ b/qpdf/qtest/arg-parsing.test @@ -0,0 +1,90 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; +use File::Copy; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('arg-parsing'); + +my $n_tests = 13; + +$td->runtest("required argument", + {$td->COMMAND => "qpdf --password minimal.pdf"}, + {$td->REGEXP => "must be given as --password=pass", + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); +$td->runtest("required argument with choices", + {$td->COMMAND => "qpdf --decode-level minimal.pdf"}, + {$td->REGEXP => "must be given as --decode-level=\\{.*all.*\\}", + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); +$td->runtest("required argument with choices", + {$td->COMMAND => "qpdf --decode-level minimal.pdf"}, + {$td->REGEXP => "must be given as --decode-level=\\{.*all.*\\}", + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); +copy("minimal.pdf", '@file.pdf'); +$td->runtest("\@file exists and file doesn't", + {$td->COMMAND => "qpdf --check \@file.pdf"}, + {$td->FILE => "check-at-file.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("missing underlay filename", + {$td->COMMAND => "qpdf --underlay --"}, + {$td->REGEXP => ".*underlay file not specified.*", + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); +$td->runtest("extra overlay filename", + {$td->COMMAND => "qpdf --overlay x x --"}, + {$td->REGEXP => ".*overlay file already specified.*", + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); +$td->runtest("multiple pages options", + {$td->COMMAND => "qpdf --pages . --password=x -- --pages . --"}, + {$td->REGEXP => ".*--pages may only be specified one time.*", + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); +$td->runtest("bad numeric range detects unclosed --pages", + {$td->COMMAND => "qpdf --pages . --pages . --"}, + {$td->REGEXP => ".*pages options must be terminated with --.*", + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); +$td->runtest("bad file detected as unclosed --pages", + {$td->COMMAND => "qpdf --pages . 1 --xyz out"}, + {$td->REGEXP => ".*pages options must be terminated with --.*", + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); +$td->runtest("misplaced pages password 1", + {$td->COMMAND => "qpdf --pages . 1 --password=z --"}, + {$td->REGEXP => ".*password must immediately follow a file name.*", + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); +$td->runtest("misplaced pages password 2", + {$td->COMMAND => "qpdf --pages --password=z . 1 --"}, + {$td->REGEXP => ".*password must immediately follow a file name.*", + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); +$td->runtest("duplicated pages password", + {$td->COMMAND => "qpdf --pages . --password=z --password=z --"}, + {$td->REGEXP => ".*password already specified.*", + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); +# Ignoring -- at the top level was never intended but turned out to +# have been there for a long time so that people relied on it. It is +# intentionally not documented. +$td->runtest("ignore -- at top level", + {$td->COMMAND => "qpdf -- --check -- minimal.pdf --"}, + {$td->REGEXP => ".*No syntax or stream encoding errors found.*", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/arg_parsing.test b/qpdf/qtest/arg_parsing.test deleted file mode 100644 index edf24d4f..00000000 --- a/qpdf/qtest/arg_parsing.test +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; -use File::Copy; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('arg_parsing'); - -my $n_tests = 13; - -$td->runtest("required argument", - {$td->COMMAND => "qpdf --password minimal.pdf"}, - {$td->REGEXP => "must be given as --password=pass", - $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); -$td->runtest("required argument with choices", - {$td->COMMAND => "qpdf --decode-level minimal.pdf"}, - {$td->REGEXP => "must be given as --decode-level=\\{.*all.*\\}", - $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); -$td->runtest("required argument with choices", - {$td->COMMAND => "qpdf --decode-level minimal.pdf"}, - {$td->REGEXP => "must be given as --decode-level=\\{.*all.*\\}", - $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); -copy("minimal.pdf", '@file.pdf'); -$td->runtest("\@file exists and file doesn't", - {$td->COMMAND => "qpdf --check \@file.pdf"}, - {$td->FILE => "check-at-file.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("missing underlay filename", - {$td->COMMAND => "qpdf --underlay --"}, - {$td->REGEXP => ".*underlay file not specified.*", - $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); -$td->runtest("extra overlay filename", - {$td->COMMAND => "qpdf --overlay x x --"}, - {$td->REGEXP => ".*overlay file already specified.*", - $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); -$td->runtest("multiple pages options", - {$td->COMMAND => "qpdf --pages . --password=x -- --pages . --"}, - {$td->REGEXP => ".*--pages may only be specified one time.*", - $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); -$td->runtest("bad numeric range detects unclosed --pages", - {$td->COMMAND => "qpdf --pages . --pages . --"}, - {$td->REGEXP => ".*pages options must be terminated with --.*", - $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); -$td->runtest("bad file detected as unclosed --pages", - {$td->COMMAND => "qpdf --pages . 1 --xyz out"}, - {$td->REGEXP => ".*pages options must be terminated with --.*", - $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); -$td->runtest("misplaced pages password 1", - {$td->COMMAND => "qpdf --pages . 1 --password=z --"}, - {$td->REGEXP => ".*password must immediately follow a file name.*", - $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); -$td->runtest("misplaced pages password 2", - {$td->COMMAND => "qpdf --pages --password=z . 1 --"}, - {$td->REGEXP => ".*password must immediately follow a file name.*", - $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); -$td->runtest("duplicated pages password", - {$td->COMMAND => "qpdf --pages . --password=z --password=z --"}, - {$td->REGEXP => ".*password already specified.*", - $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); -# Ignoring -- at the top level was never intended but turned out to -# have been there for a long time so that people relied on it. It is -# intentionally not documented. -$td->runtest("ignore -- at top level", - {$td->COMMAND => "qpdf -- --check -- minimal.pdf --"}, - {$td->REGEXP => ".*No syntax or stream encoding errors found.*", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/basic-parsing.test b/qpdf/qtest/basic-parsing.test new file mode 100644 index 00000000..7d432367 --- /dev/null +++ b/qpdf/qtest/basic-parsing.test @@ -0,0 +1,77 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('basic-parsing'); + +my @goodfiles = ("implicit null", # 1 + "direct null", # 2 + "unresolved null", # 3 + "indirect null", # 4 + "indirect bool, real", # 5 + "direct bool", # 6 + "integer", # 7 + "real, ASCIIHexDecode", # 8 + "string", # 9 + "array", # 10 + "dictionary", # 11 + "stream", # 12 + "nesting, strings, names", # 13 + "tokenizing pipeline", # 14 + "name", # 15 + "object-stream", # 16 + "hybrid xref", # 17 + "hybrid xref old mode", # 18 + "xref with prev", # 19 + "lots of compressible objects", # 20 + "array with indirect nulls", # 21 + ); + +my $n_tests = (3 * @goodfiles) + 6; + +my %goodtest_overrides = ('14' => 3); +my %goodtest_flags = + ('18' => '-ignore-xref-streams', + '20' => '-object-streams=generate', + ); +for (my $i = 1; $i <= scalar(@goodfiles); ++$i) +{ + my $n = $goodtest_overrides{$i} || 1; + $td->runtest("$goodfiles[$i-1]", + {$td->COMMAND => "test_driver $n good$i.pdf"}, + {$td->FILE => "good$i.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + my $xflags = $goodtest_flags{$i} || ''; + check_pdf($td, "create qdf", + "qpdf --static-id -qdf $xflags good$i.pdf", + "good$i.qdf", 0); +} + +check_pdf($td, "no normalization", + "qpdf -qdf --static-id --normalize-content=n good7.pdf", + "good7-not-normalized.qdf", + 0); + +check_pdf($td, "no qdf", + "qpdf --static-id good17.pdf", + "good17-not-qdf.pdf", + 0); + +check_pdf($td, "no recompression", + "qpdf --static-id --stream-data=preserve good17.pdf", + "good17-not-recompressed.pdf", + 0); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/basic_parsing.test b/qpdf/qtest/basic_parsing.test deleted file mode 100644 index d150ba9e..00000000 --- a/qpdf/qtest/basic_parsing.test +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('basic_parsing'); - -my @goodfiles = ("implicit null", # 1 - "direct null", # 2 - "unresolved null", # 3 - "indirect null", # 4 - "indirect bool, real", # 5 - "direct bool", # 6 - "integer", # 7 - "real, ASCIIHexDecode", # 8 - "string", # 9 - "array", # 10 - "dictionary", # 11 - "stream", # 12 - "nesting, strings, names", # 13 - "tokenizing pipeline", # 14 - "name", # 15 - "object-stream", # 16 - "hybrid xref", # 17 - "hybrid xref old mode", # 18 - "xref with prev", # 19 - "lots of compressible objects", # 20 - "array with indirect nulls", # 21 - ); - -my $n_tests = (3 * @goodfiles) + 6; - -my %goodtest_overrides = ('14' => 3); -my %goodtest_flags = - ('18' => '-ignore-xref-streams', - '20' => '-object-streams=generate', - ); -for (my $i = 1; $i <= scalar(@goodfiles); ++$i) -{ - my $n = $goodtest_overrides{$i} || 1; - $td->runtest("$goodfiles[$i-1]", - {$td->COMMAND => "test_driver $n good$i.pdf"}, - {$td->FILE => "good$i.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - my $xflags = $goodtest_flags{$i} || ''; - check_pdf($td, "create qdf", - "qpdf --static-id -qdf $xflags good$i.pdf", - "good$i.qdf", 0); -} - -check_pdf($td, "no normalization", - "qpdf -qdf --static-id --normalize-content=n good7.pdf", - "good7-not-normalized.qdf", - 0); - -check_pdf($td, "no qdf", - "qpdf --static-id good17.pdf", - "good17-not-qdf.pdf", - 0); - -check_pdf($td, "no recompression", - "qpdf --static-id --stream-data=preserve good17.pdf", - "good17-not-recompressed.pdf", - 0); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/bound-checks.test b/qpdf/qtest/bound-checks.test new file mode 100644 index 00000000..46f8637d --- /dev/null +++ b/qpdf/qtest/bound-checks.test @@ -0,0 +1,38 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('bound-checks'); + +my $n_tests = 3; + +$td->runtest("bounds check linearization data 1", + {$td->COMMAND => "qpdf --check linearization-bounds-1.pdf"}, + {$td->FILE => "linearization-bounds-1.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("bounds check linearization data 2", + {$td->COMMAND => "qpdf --check linearization-bounds-2.pdf"}, + {$td->FILE => "linearization-bounds-2.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +# Throws runtime error, not bad_alloc +$td->runtest("sanity check array size", + {$td->COMMAND => + "qpdf --check linearization-large-vector-alloc.pdf"}, + {$td->FILE => "linearization-large-vector-alloc.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/bound_checks.test b/qpdf/qtest/bound_checks.test deleted file mode 100644 index 50cef2c5..00000000 --- a/qpdf/qtest/bound_checks.test +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('bound_checks'); - -my $n_tests = 3; - -$td->runtest("bounds check linearization data 1", - {$td->COMMAND => "qpdf --check linearization-bounds-1.pdf"}, - {$td->FILE => "linearization-bounds-1.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("bounds check linearization data 2", - {$td->COMMAND => "qpdf --check linearization-bounds-2.pdf"}, - {$td->FILE => "linearization-bounds-2.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -# Throws runtime error, not bad_alloc -$td->runtest("sanity check array size", - {$td->COMMAND => - "qpdf --check linearization-large-vector-alloc.pdf"}, - {$td->FILE => "linearization-large-vector-alloc.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/c-api-check.test b/qpdf/qtest/c-api-check.test new file mode 100644 index 00000000..916bd12f --- /dev/null +++ b/qpdf/qtest/c-api-check.test @@ -0,0 +1,30 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('c-api-check'); + +my @c_check_types = qw(warn clear); +my $n_tests = scalar(@c_check_types); + +foreach my $i (@c_check_types) +{ + $td->runtest("C check $i", + {$td->COMMAND => "qpdf-ctest 23 c-check-$i-in.pdf '' -"}, + {$td->FILE => "c-check-$i.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +} + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/c-api-key.test b/qpdf/qtest/c-api-key.test new file mode 100644 index 00000000..88b8058d --- /dev/null +++ b/qpdf/qtest/c-api-key.test @@ -0,0 +1,40 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('c-api-key'); + +my $n_tests = 4; + +$td->runtest("C API info key functions", + {$td->COMMAND => "qpdf-ctest 16 minimal.pdf '' a.pdf"}, + {$td->FILE => "c-info1.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "c-info-out.pdf"}); +unlink "a.pdf" or die; + +$td->runtest("C API info key functions", + {$td->COMMAND => "qpdf-ctest 16 c-info2-in.pdf '' a.pdf"}, + {$td->FILE => "c-info2.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "c-info-out.pdf"}); +unlink "a.pdf" or die; + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/c-api-object-handle.test b/qpdf/qtest/c-api-object-handle.test new file mode 100644 index 00000000..40511df1 --- /dev/null +++ b/qpdf/qtest/c-api-object-handle.test @@ -0,0 +1,75 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('c-api-object-handle'); + +my $n_tests = 13; + +$td->runtest("C check object handles", + {$td->COMMAND => "qpdf-ctest 24 minimal.pdf '' a.pdf"}, + {$td->FILE => "c-object-handles.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => 'a.pdf'}, + {$td->FILE => 'c-object-handles-out.pdf'}); + +$td->runtest("C check object handle creation", + {$td->COMMAND => "qpdf-ctest 25 minimal.pdf '' a.pdf"}, + {$td->STRING => "C test 25 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => 'a.pdf'}, + {$td->FILE => 'c-object-handle-creation-out.pdf'}); + +$td->runtest("C indirect objects", + {$td->COMMAND => "qpdf-ctest 33 minimal.pdf '' a.pdf"}, + {$td->STRING => "C test 33 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => 'a.pdf'}, + {$td->FILE => 'c-indirect-objects-out.pdf'}); + +$td->runtest("C uninitialized objects", + {$td->COMMAND => "qpdf-ctest 26 '' '' ''"}, + {$td->FILE => "c-oh-uninitialized-objects.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("C string with embedded null", + {$td->COMMAND => "qpdf-ctest 27 '' '' ''"}, + {$td->STRING => "C test 27 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("C wrap and clone objects", + {$td->COMMAND => "qpdf-ctest 28 minimal.pdf '' ''"}, + {$td->STRING => "C test 28 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("C object handle errors", + {$td->COMMAND => "qpdf-ctest 29 minimal.pdf '' ''"}, + {$td->FILE => "c-oh-errors.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("C unhandled error warning", + {$td->COMMAND => "qpdf-ctest 30 bad1.pdf '' ''"}, + {$td->FILE => "c-unhandled-error.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("C type mismatch warning", + {$td->COMMAND => "qpdf-ctest 31 minimal.pdf '' ''"}, + {$td->FILE => "c-type-warning.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("C get object by ID", + {$td->COMMAND => "qpdf-ctest 32 minimal.pdf '' ''"}, + {$td->STRING => "C test 32 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/c-api-page.test b/qpdf/qtest/c-api-page.test new file mode 100644 index 00000000..5b68b058 --- /dev/null +++ b/qpdf/qtest/c-api-page.test @@ -0,0 +1,45 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('c-api-page'); + +my $n_tests = 5; + +$td->runtest("C page normal", + {$td->COMMAND => + "qpdf-ctest 34 11-pages.pdf '' a.pdf minimal.pdf"}, + {$td->STRING => "C test 34 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => 'a.pdf'}, + {$td->FILE => 'c-pages.pdf'}); + +$td->runtest("C page errors", + {$td->COMMAND => + "qpdf-ctest 35 11-pages.pdf '' ''"}, + {$td->FILE => "c-page-errors.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("C inherited page resources", + {$td->COMMAND => + "qpdf-ctest 36 inherited-rotate.pdf '' ''"}, + {$td->STRING => "C test 36 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("C pages cache", + {$td->COMMAND => + "qpdf-ctest 37 11-pages.pdf '' ''"}, + {$td->STRING => "C test 37 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/c-api-stream.test b/qpdf/qtest/c-api-stream.test new file mode 100644 index 00000000..1ea2c95f --- /dev/null +++ b/qpdf/qtest/c-api-stream.test @@ -0,0 +1,43 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('c-api-stream'); + +my $n_tests = 5; + +$td->runtest("C read streams", + {$td->COMMAND => + "qpdf-ctest 38 11-pages.pdf '' ''"}, + {$td->FILE => "c-get-stream.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("C foreign object", + {$td->COMMAND => + "qpdf-ctest 39 11-pages.pdf '' a.pdf minimal.pdf"}, + {$td->STRING => "C test 39 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => 'a.pdf'}, + {$td->FILE => 'c-foreign.pdf'}); + +$td->runtest("C new stream", + {$td->COMMAND => + "qpdf-ctest 40 minimal.pdf '' a.pdf"}, + {$td->STRING => "C test 40 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => 'a.pdf'}, + {$td->FILE => 'c-new-stream.pdf'}); +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/c-api.test b/qpdf/qtest/c-api.test new file mode 100644 index 00000000..d0776b16 --- /dev/null +++ b/qpdf/qtest/c-api.test @@ -0,0 +1,73 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('c-api'); + +my @capi = ( + [2, 'no options'], + [3, 'normalized content'], + [4, 'ignore xref streams'], + [5, 'linearized'], + [6, 'object streams'], + [7, 'qdf'], + [8, 'no original object ids'], + [9, 'uncompressed streams'], + ); +my $n_tests = (2 * @capi) + 5; +foreach my $d (@capi) +{ + my ($n, $description) = @$d; + my $outfile = $description; + $outfile =~ s/ /-/g; + $outfile = "c-$outfile.pdf"; + $td->runtest($description, + {$td->COMMAND => "qpdf-ctest $n hybrid-xref.pdf '' a.pdf"}, + {$td->STRING => "C test $n done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("check $description", + {$td->FILE => "a.pdf"}, + {$td->FILE => $outfile}); +} +$td->runtest("write to bad file name", + {$td->COMMAND => "qpdf-ctest 2 hybrid-xref.pdf '' /:a:/:b:"}, + {$td->REGEXP => "error: open /:a:/:b:: .*", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("write damaged to bad file name", + {$td->COMMAND => "qpdf-ctest 2 append-page-content-damaged.pdf" . + " '' /:a:/:b:"}, + {$td->REGEXP => + "warning:(?s:.*)\n" . + "error: open /:a:/:b:: .*", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("write damaged", + {$td->COMMAND => "qpdf-ctest 2 append-page-content-damaged.pdf" . + " '' a.pdf"}, + {$td->FILE => "c-write-damaged.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("empty PDF", + {$td->COMMAND => "qpdf-ctest 41 - '' a.pdf"}, + {$td->STRING => "C test 41 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "c-empty.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/c_api.test b/qpdf/qtest/c_api.test deleted file mode 100644 index c834e7d2..00000000 --- a/qpdf/qtest/c_api.test +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('c_api'); - -my @capi = ( - [2, 'no options'], - [3, 'normalized content'], - [4, 'ignore xref streams'], - [5, 'linearized'], - [6, 'object streams'], - [7, 'qdf'], - [8, 'no original object ids'], - [9, 'uncompressed streams'], - ); -my $n_tests = (2 * @capi) + 5; -foreach my $d (@capi) -{ - my ($n, $description) = @$d; - my $outfile = $description; - $outfile =~ s/ /-/g; - $outfile = "c-$outfile.pdf"; - $td->runtest($description, - {$td->COMMAND => "qpdf-ctest $n hybrid-xref.pdf '' a.pdf"}, - {$td->STRING => "C test $n done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("check $description", - {$td->FILE => "a.pdf"}, - {$td->FILE => $outfile}); -} -$td->runtest("write to bad file name", - {$td->COMMAND => "qpdf-ctest 2 hybrid-xref.pdf '' /:a:/:b:"}, - {$td->REGEXP => "error: open /:a:/:b:: .*", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("write damaged to bad file name", - {$td->COMMAND => "qpdf-ctest 2 append-page-content-damaged.pdf" . - " '' /:a:/:b:"}, - {$td->REGEXP => - "warning:(?s:.*)\n" . - "error: open /:a:/:b:: .*", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("write damaged", - {$td->COMMAND => "qpdf-ctest 2 append-page-content-damaged.pdf" . - " '' a.pdf"}, - {$td->FILE => "c-write-damaged.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("empty PDF", - {$td->COMMAND => "qpdf-ctest 41 - '' a.pdf"}, - {$td->STRING => "C test 41 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "c-empty.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/c_api_check.test b/qpdf/qtest/c_api_check.test deleted file mode 100644 index 29c8746a..00000000 --- a/qpdf/qtest/c_api_check.test +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('c_api_check'); - -my @c_check_types = qw(warn clear); -my $n_tests = scalar(@c_check_types); - -foreach my $i (@c_check_types) -{ - $td->runtest("C check $i", - {$td->COMMAND => "qpdf-ctest 23 c-check-$i-in.pdf '' -"}, - {$td->FILE => "c-check-$i.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -} - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/c_api_key.test b/qpdf/qtest/c_api_key.test deleted file mode 100644 index 4a47b132..00000000 --- a/qpdf/qtest/c_api_key.test +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('c_api_key'); - -my $n_tests = 4; - -$td->runtest("C API info key functions", - {$td->COMMAND => "qpdf-ctest 16 minimal.pdf '' a.pdf"}, - {$td->FILE => "c-info1.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "c-info-out.pdf"}); -unlink "a.pdf" or die; - -$td->runtest("C API info key functions", - {$td->COMMAND => "qpdf-ctest 16 c-info2-in.pdf '' a.pdf"}, - {$td->FILE => "c-info2.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "c-info-out.pdf"}); -unlink "a.pdf" or die; - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/c_api_object_handle.test b/qpdf/qtest/c_api_object_handle.test deleted file mode 100644 index 2a257abd..00000000 --- a/qpdf/qtest/c_api_object_handle.test +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('c_api_object_handle'); - -my $n_tests = 13; - -$td->runtest("C check object handles", - {$td->COMMAND => "qpdf-ctest 24 minimal.pdf '' a.pdf"}, - {$td->FILE => "c-object-handles.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => 'a.pdf'}, - {$td->FILE => 'c-object-handles-out.pdf'}); - -$td->runtest("C check object handle creation", - {$td->COMMAND => "qpdf-ctest 25 minimal.pdf '' a.pdf"}, - {$td->STRING => "C test 25 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => 'a.pdf'}, - {$td->FILE => 'c-object-handle-creation-out.pdf'}); - -$td->runtest("C indirect objects", - {$td->COMMAND => "qpdf-ctest 33 minimal.pdf '' a.pdf"}, - {$td->STRING => "C test 33 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => 'a.pdf'}, - {$td->FILE => 'c-indirect-objects-out.pdf'}); - -$td->runtest("C uninitialized objects", - {$td->COMMAND => "qpdf-ctest 26 '' '' ''"}, - {$td->FILE => "c-oh-uninitialized-objects.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("C string with embedded null", - {$td->COMMAND => "qpdf-ctest 27 '' '' ''"}, - {$td->STRING => "C test 27 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("C wrap and clone objects", - {$td->COMMAND => "qpdf-ctest 28 minimal.pdf '' ''"}, - {$td->STRING => "C test 28 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("C object handle errors", - {$td->COMMAND => "qpdf-ctest 29 minimal.pdf '' ''"}, - {$td->FILE => "c-oh-errors.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("C unhandled error warning", - {$td->COMMAND => "qpdf-ctest 30 bad1.pdf '' ''"}, - {$td->FILE => "c-unhandled-error.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("C type mismatch warning", - {$td->COMMAND => "qpdf-ctest 31 minimal.pdf '' ''"}, - {$td->FILE => "c-type-warning.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("C get object by ID", - {$td->COMMAND => "qpdf-ctest 32 minimal.pdf '' ''"}, - {$td->STRING => "C test 32 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/c_api_page.test b/qpdf/qtest/c_api_page.test deleted file mode 100644 index 4fbc8dbd..00000000 --- a/qpdf/qtest/c_api_page.test +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('c_api_page'); - -my $n_tests = 5; - -$td->runtest("C page normal", - {$td->COMMAND => - "qpdf-ctest 34 11-pages.pdf '' a.pdf minimal.pdf"}, - {$td->STRING => "C test 34 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => 'a.pdf'}, - {$td->FILE => 'c-pages.pdf'}); - -$td->runtest("C page errors", - {$td->COMMAND => - "qpdf-ctest 35 11-pages.pdf '' ''"}, - {$td->FILE => "c-page-errors.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("C inherited page resources", - {$td->COMMAND => - "qpdf-ctest 36 inherited-rotate.pdf '' ''"}, - {$td->STRING => "C test 36 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("C pages cache", - {$td->COMMAND => - "qpdf-ctest 37 11-pages.pdf '' ''"}, - {$td->STRING => "C test 37 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/c_api_stream.test b/qpdf/qtest/c_api_stream.test deleted file mode 100644 index a2b041f3..00000000 --- a/qpdf/qtest/c_api_stream.test +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('c_api_stream'); - -my $n_tests = 5; - -$td->runtest("C read streams", - {$td->COMMAND => - "qpdf-ctest 38 11-pages.pdf '' ''"}, - {$td->FILE => "c-get-stream.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("C foreign object", - {$td->COMMAND => - "qpdf-ctest 39 11-pages.pdf '' a.pdf minimal.pdf"}, - {$td->STRING => "C test 39 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => 'a.pdf'}, - {$td->FILE => 'c-foreign.pdf'}); - -$td->runtest("C new stream", - {$td->COMMAND => - "qpdf-ctest 40 minimal.pdf '' a.pdf"}, - {$td->STRING => "C test 40 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => 'a.pdf'}, - {$td->FILE => 'c-new-stream.pdf'}); -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/character-encoding.test b/qpdf/qtest/character-encoding.test new file mode 100644 index 00000000..4626d1f0 --- /dev/null +++ b/qpdf/qtest/character-encoding.test @@ -0,0 +1,40 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('character-encoding'); + +my $n_tests = 4; + +$td->runtest("PDF doc encoding to Unicode", + {$td->COMMAND => "test_pdf_doc_encoding pdf-doc-to-utf8.in"}, + {$td->FILE => "pdf-doc-to-utf8.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("UTF-16 encoding", + {$td->COMMAND => "test_pdf_unicode unicode.in"}, + {$td->FILE => "unicode.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("UTF-16 encoding errors", + {$td->COMMAND => "test_pdf_unicode unicode-errors.in"}, + {$td->FILE => "unicode-errors.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +# UTF-16LE is not allowed by the PDF spec, but it seems that most +# readers accept it. +$td->runtest("UTF-16LE strings", + {$td->COMMAND => "qpdf --list-attachments --verbose utf16le.pdf"}, + {$td->FILE => "utf16le-attachments.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/character_encoding.test b/qpdf/qtest/character_encoding.test deleted file mode 100644 index 71a3b2c2..00000000 --- a/qpdf/qtest/character_encoding.test +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('character_encoding'); - -my $n_tests = 4; - -$td->runtest("PDF doc encoding to Unicode", - {$td->COMMAND => "test_pdf_doc_encoding pdf-doc-to-utf8.in"}, - {$td->FILE => "pdf-doc-to-utf8.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("UTF-16 encoding", - {$td->COMMAND => "test_pdf_unicode unicode.in"}, - {$td->FILE => "unicode.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("UTF-16 encoding errors", - {$td->COMMAND => "test_pdf_unicode unicode-errors.in"}, - {$td->FILE => "unicode-errors.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -# UTF-16LE is not allowed by the PDF spec, but it seems that most -# readers accept it. -$td->runtest("UTF-16LE strings", - {$td->COMMAND => "qpdf --list-attachments --verbose utf16le.pdf"}, - {$td->FILE => "utf16le-attachments.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/check-encryption.test b/qpdf/qtest/check-encryption.test new file mode 100644 index 00000000..ac061b7a --- /dev/null +++ b/qpdf/qtest/check-encryption.test @@ -0,0 +1,60 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('check-encryption'); + +my @check_encryption_password = ( + # file, password, is-encrypted, requires-password + ["minimal.pdf", "", 2, 2], + ["20-pages.pdf", "", 0, 0], + ["20-pages.pdf", "user", 0, 3], + ); +my $n_tests = 3 * scalar(@check_encryption_password); +foreach my $d (@check_encryption_password) +{ + my ($file, $pass, $is_encrypted, $requires_password) = @$d; + $td->runtest("is encrypted ($file, pass=$pass)", + {$td->COMMAND => "qpdf --is-encrypted --password=$pass $file"}, + {$td->STRING => "", $td->EXIT_STATUS => $is_encrypted}); + $td->runtest("requires password ($file, pass=$pass)", + {$td->COMMAND => "qpdf --requires-password" . + " --password=$pass $file"}, + {$td->STRING => "", $td->EXIT_STATUS => $requires_password}); +} + +# Exercise reading password from file +open(F, ">args") or die; +print F "user\n"; +close(F); +$td->runtest("password from file)", + {$td->COMMAND => "qpdf --check --password-file=args 20-pages.pdf"}, + {$td->FILE => "20-pages-check.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +open(F, ">>args") or die; +print F "ignored\n"; +close(F); +$td->runtest("ignore extra args from file)", + {$td->COMMAND => "qpdf --check --password-file=args 20-pages.pdf"}, + {$td->FILE => "20-pages-check-password-warning.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +unlink "args"; +$td->runtest("password from stdin)", + {$td->COMMAND => "echo user |" . + " qpdf --check --password-file=- 20-pages.pdf"}, + {$td->FILE => "20-pages-check.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/check_encryption.test b/qpdf/qtest/check_encryption.test deleted file mode 100644 index fc26f0a2..00000000 --- a/qpdf/qtest/check_encryption.test +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('check_encryption'); - -my @check_encryption_password = ( - # file, password, is-encrypted, requires-password - ["minimal.pdf", "", 2, 2], - ["20-pages.pdf", "", 0, 0], - ["20-pages.pdf", "user", 0, 3], - ); -my $n_tests = 3 * scalar(@check_encryption_password); -foreach my $d (@check_encryption_password) -{ - my ($file, $pass, $is_encrypted, $requires_password) = @$d; - $td->runtest("is encrypted ($file, pass=$pass)", - {$td->COMMAND => "qpdf --is-encrypted --password=$pass $file"}, - {$td->STRING => "", $td->EXIT_STATUS => $is_encrypted}); - $td->runtest("requires password ($file, pass=$pass)", - {$td->COMMAND => "qpdf --requires-password" . - " --password=$pass $file"}, - {$td->STRING => "", $td->EXIT_STATUS => $requires_password}); -} - -# Exercise reading password from file -open(F, ">args") or die; -print F "user\n"; -close(F); -$td->runtest("password from file)", - {$td->COMMAND => "qpdf --check --password-file=args 20-pages.pdf"}, - {$td->FILE => "20-pages-check.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -open(F, ">>args") or die; -print F "ignored\n"; -close(F); -$td->runtest("ignore extra args from file)", - {$td->COMMAND => "qpdf --check --password-file=args 20-pages.pdf"}, - {$td->FILE => "20-pages-check-password-warning.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -unlink "args"; -$td->runtest("password from stdin)", - {$td->COMMAND => "echo user |" . - " qpdf --check --password-file=- 20-pages.pdf"}, - {$td->FILE => "20-pages-check.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/cleartext-metadata.test b/qpdf/qtest/cleartext-metadata.test new file mode 100644 index 00000000..ce6c7f92 --- /dev/null +++ b/qpdf/qtest/cleartext-metadata.test @@ -0,0 +1,72 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('cleartext-metadata'); + +my $n_tests = 58; + +# args: file, exp_encrypted, exp_cleartext +check_metadata($td, "compressed-metadata.pdf", 0, 0); +check_metadata($td, "enc-base.pdf", 0, 1); + +foreach my $f (qw(compressed-metadata.pdf enc-base.pdf)) +{ + foreach my $w (qw(compress preserve)) + { + $td->runtest("$w streams ($f)", + {$td->COMMAND => "qpdf --stream-data=$w $f a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); + check_metadata($td, "a.pdf", 0, 1); + $td->runtest("encrypt normally", + {$td->COMMAND => + "qpdf --allow-weak-crypto" . + " --encrypt '' o 128 -- a.pdf b.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); + check_metadata($td, "b.pdf", 1, 0); + unlink "b.pdf"; + $td->runtest("encrypt V4", + {$td->COMMAND => + "qpdf --allow-weak-crypto" . + " --encrypt '' o 128 --force-V4 -- a.pdf b.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); + check_metadata($td, "b.pdf", 1, 0); + unlink "b.pdf"; + $td->runtest("encrypt with cleartext metadata", + {$td->COMMAND => + "qpdf --allow-weak-crypto" . + " --encrypt '' o 128 --cleartext-metadata --" . + " a.pdf b.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); + check_metadata($td, "b.pdf", 1, 1); + $td->runtest("preserve encryption", + {$td->COMMAND => "qpdf b.pdf c.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); + check_metadata($td, "c.pdf", 1, 1); + unlink "b.pdf", "c.pdf"; + $td->runtest("encrypt with aes and cleartext metadata", + {$td->COMMAND => + "qpdf --encrypt '' o 128" . + " --cleartext-metadata --use-aes=y -- a.pdf b.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); + check_metadata($td, "b.pdf", 1, 1); + $td->runtest("preserve encryption", + {$td->COMMAND => "qpdf b.pdf c.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); + check_metadata($td, "c.pdf", 1, 1); + unlink "b.pdf", "c.pdf"; + } +} + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/cleartext_metadata.test b/qpdf/qtest/cleartext_metadata.test deleted file mode 100644 index 6b07e592..00000000 --- a/qpdf/qtest/cleartext_metadata.test +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('cleartext_metadata'); - -my $n_tests = 58; - -# args: file, exp_encrypted, exp_cleartext -check_metadata($td, "compressed-metadata.pdf", 0, 0); -check_metadata($td, "enc-base.pdf", 0, 1); - -foreach my $f (qw(compressed-metadata.pdf enc-base.pdf)) -{ - foreach my $w (qw(compress preserve)) - { - $td->runtest("$w streams ($f)", - {$td->COMMAND => "qpdf --stream-data=$w $f a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); - check_metadata($td, "a.pdf", 0, 1); - $td->runtest("encrypt normally", - {$td->COMMAND => - "qpdf --allow-weak-crypto" . - " --encrypt '' o 128 -- a.pdf b.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); - check_metadata($td, "b.pdf", 1, 0); - unlink "b.pdf"; - $td->runtest("encrypt V4", - {$td->COMMAND => - "qpdf --allow-weak-crypto" . - " --encrypt '' o 128 --force-V4 -- a.pdf b.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); - check_metadata($td, "b.pdf", 1, 0); - unlink "b.pdf"; - $td->runtest("encrypt with cleartext metadata", - {$td->COMMAND => - "qpdf --allow-weak-crypto" . - " --encrypt '' o 128 --cleartext-metadata --" . - " a.pdf b.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); - check_metadata($td, "b.pdf", 1, 1); - $td->runtest("preserve encryption", - {$td->COMMAND => "qpdf b.pdf c.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); - check_metadata($td, "c.pdf", 1, 1); - unlink "b.pdf", "c.pdf"; - $td->runtest("encrypt with aes and cleartext metadata", - {$td->COMMAND => - "qpdf --encrypt '' o 128" . - " --cleartext-metadata --use-aes=y -- a.pdf b.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); - check_metadata($td, "b.pdf", 1, 1); - $td->runtest("preserve encryption", - {$td->COMMAND => "qpdf b.pdf c.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); - check_metadata($td, "c.pdf", 1, 1); - unlink "b.pdf", "c.pdf"; - } -} - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/coalesce-contents.test b/qpdf/qtest/coalesce-contents.test new file mode 100644 index 00000000..57890f28 --- /dev/null +++ b/qpdf/qtest/coalesce-contents.test @@ -0,0 +1,53 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('coalesce-contents'); + +my $n_tests = 8; + +$td->runtest("qdf with normalize warnings", + {$td->COMMAND => + "qpdf --qdf --static-id split-tokens.pdf a.pdf"}, + {$td->FILE => "normalize-warnings.out", $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "split-tokens.qdf"}); +$td->runtest("coalesce to qdf", + {$td->COMMAND => + "qpdf --qdf --static-id coalesce.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "coalesce.qdf"}); +$td->runtest("coalesce contents with qdf", + {$td->COMMAND => + "qpdf --qdf --static-id" . + " --coalesce-contents coalesce.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "coalesce-out.qdf"}); +$td->runtest("coalesce contents without qdf", + {$td->COMMAND => + "qpdf --static-id" . + " --coalesce-contents coalesce.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "coalesce-out.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/coalesce_contents.test b/qpdf/qtest/coalesce_contents.test deleted file mode 100644 index c98e6d28..00000000 --- a/qpdf/qtest/coalesce_contents.test +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('coalesce_contents'); - -my $n_tests = 8; - -$td->runtest("qdf with normalize warnings", - {$td->COMMAND => - "qpdf --qdf --static-id split-tokens.pdf a.pdf"}, - {$td->FILE => "normalize-warnings.out", $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "split-tokens.qdf"}); -$td->runtest("coalesce to qdf", - {$td->COMMAND => - "qpdf --qdf --static-id coalesce.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "coalesce.qdf"}); -$td->runtest("coalesce contents with qdf", - {$td->COMMAND => - "qpdf --qdf --static-id" . - " --coalesce-contents coalesce.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "coalesce-out.qdf"}); -$td->runtest("coalesce contents without qdf", - {$td->COMMAND => - "qpdf --static-id" . - " --coalesce-contents coalesce.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "coalesce-out.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/compare-pdfs.test b/qpdf/qtest/compare-pdfs.test new file mode 100644 index 00000000..3265ce4a --- /dev/null +++ b/qpdf/qtest/compare-pdfs.test @@ -0,0 +1,31 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; +use Digest::MD5; +use File::Copy; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('compare-pdfs'); + +my $n_compare_pdfs = 5; + +# Check compare_pdfs to make sure that it works properly. Each call +# to compare_pdfs is worth three test cases. +compare_pdfs($td, "p1-a-p2-b.pdf", "p1-a-p2-b.pdf"); +compare_pdfs($td, "p1-a.pdf", "p1-a.pdf"); +compare_pdfs($td, "p1-a.pdf", "p1-b.pdf", 1); +compare_pdfs($td, "p1-a.pdf", "p1-a-p2-b.pdf", 1); +compare_pdfs($td, "p1-a-p2-a.pdf", "p1-a-p2-b.pdf", 1); +flush_tiff_cache(); + +cleanup(); +$td->report(calc_ntests(0, $n_compare_pdfs)); diff --git a/qpdf/qtest/compare_pdfs.test b/qpdf/qtest/compare_pdfs.test deleted file mode 100644 index cb7555f4..00000000 --- a/qpdf/qtest/compare_pdfs.test +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; -use Digest::MD5; -use File::Copy; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('compare_pdfs'); - -my $n_compare_pdfs = 5; - -# Check compare_pdfs to make sure that it works properly. Each call -# to compare_pdfs is worth three test cases. -compare_pdfs($td, "p1-a-p2-b.pdf", "p1-a-p2-b.pdf"); -compare_pdfs($td, "p1-a.pdf", "p1-a.pdf"); -compare_pdfs($td, "p1-a.pdf", "p1-b.pdf", 1); -compare_pdfs($td, "p1-a.pdf", "p1-a-p2-b.pdf", 1); -compare_pdfs($td, "p1-a-p2-a.pdf", "p1-a-p2-b.pdf", 1); -flush_tiff_cache(); - -cleanup(); -$td->report(calc_ntests(0, $n_compare_pdfs)); diff --git a/qpdf/qtest/compression-level.test b/qpdf/qtest/compression-level.test new file mode 100644 index 00000000..aac6f6ca --- /dev/null +++ b/qpdf/qtest/compression-level.test @@ -0,0 +1,29 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('compression-level'); + +my $n_tests = 4; + +check_pdf($td, "recompress with level", + "qpdf --static-id --recompress-flate --compression-level=9" . + " --object-streams=generate minimal.pdf", + "minimal-9.pdf", 0); +check_pdf($td, "recompress with level", + "qpdf --static-id --recompress-flate --compression-level=1" . + " --object-streams=generate minimal.pdf", + "minimal-1.pdf", 0); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/compression_level.test b/qpdf/qtest/compression_level.test deleted file mode 100644 index d8fdfffd..00000000 --- a/qpdf/qtest/compression_level.test +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('compression_level'); - -my $n_tests = 4; - -check_pdf($td, "recompress with level", - "qpdf --static-id --recompress-flate --compression-level=9" . - " --object-streams=generate minimal.pdf", - "minimal-9.pdf", 0); -check_pdf($td, "recompress with level", - "qpdf --static-id --recompress-flate --compression-level=1" . - " --object-streams=generate minimal.pdf", - "minimal-1.pdf", 0); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/content-preservation.test b/qpdf/qtest/content-preservation.test new file mode 100644 index 00000000..348d8ec0 --- /dev/null +++ b/qpdf/qtest/content-preservation.test @@ -0,0 +1,101 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; +use Digest::MD5; +use File::Basename; +use File::Copy; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('content-preservation'); + +my @files = ("encrypted-with-images.pdf", # encrypted + "inline-images.pdf", + "lin-special.pdf", + "object-stream.pdf", + "hybrid-xref.pdf"); +my @flags = (["-qdf", # 1 + "qdf"], + ["-qdf --normalize-content=n", # 2 + "qdf not normalized"], + ["-qdf --stream-data=preserve", # 3 + "qdf not uncompressed"], + ["-qdf --stream-data=preserve --normalize-content=n", # 4 + "qdf not normalized or uncompressed"], + ["--stream-data=uncompress", # 5 + "uncompresed"], + ["--normalize-content=y", # 6 + "normalized"], + ["--stream-data=uncompress --normalize-content=y", # 7 + "uncompressed and normalized"], + ["-decrypt", # 8 + "decrypted"], + ["-linearize", # 9 + "linearized"], + ["-allow-weak-crypto -encrypt \"\" owner 128 --", # 10 + "encrypted"], + ["-linearize -allow-weak-crypto -encrypt \"\" o 128 --", # 11 + "linearized and encrypted"], + ["", # 12 + "no arguments"], + ); + +my $n_tests = 1 + (@files * @flags * 2 * 3); +my $n_compare_pdfs = 1 + (@files * @flags * 2); + +foreach my $file (@files) +{ + my $base = basename($file, '.pdf'); + + foreach my $o (qw(disable generate)) + { + my $n = 0; + my $oflags = "--object-streams=$o"; + my $odescrip = "os:" . substr($o, 0, 1); + my $osuf = ($o eq 'generate' ? "-ogen" : ""); + foreach my $d (@flags) + { + my ($flags, $fdescrip) = @$d; + ++$n; + system("rm -f *.pnm"); + + $td->runtest("$file ($odescrip $fdescrip)", + {$td->COMMAND => "qpdf $flags $oflags $file a.pdf"}, + {$td->STRING => "", + $td->EXIT_STATUS => 0}); + + $td->runtest("check status", + {$td->COMMAND => "qpdf --check a.pdf"}, + {$td->FILE => "$base.$n$osuf.check", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + + $td->runtest("check with C API", + {$td->COMMAND => [qw(qpdf-ctest 1 a.pdf), "", ""]}, + {$td->FILE => "$base.$n$osuf.c-check", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + + compare_pdfs($td, $file, "a.pdf"); + } + flush_tiff_cache(); + } +} + +$td->runtest("convert inline-images to qdf", + {$td->COMMAND => "qpdf --static-id --no-original-object-ids" . + " --qdf inline-images.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); + +compare_pdfs($td, "inline-images.pdf", "a.pdf"); + +cleanup(); +$td->report(calc_ntests($n_tests, $n_compare_pdfs)); diff --git a/qpdf/qtest/content_preservation.test b/qpdf/qtest/content_preservation.test deleted file mode 100644 index 0cce54c2..00000000 --- a/qpdf/qtest/content_preservation.test +++ /dev/null @@ -1,101 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; -use Digest::MD5; -use File::Basename; -use File::Copy; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('content_preservation'); - -my @files = ("encrypted-with-images.pdf", # encrypted - "inline-images.pdf", - "lin-special.pdf", - "object-stream.pdf", - "hybrid-xref.pdf"); -my @flags = (["-qdf", # 1 - "qdf"], - ["-qdf --normalize-content=n", # 2 - "qdf not normalized"], - ["-qdf --stream-data=preserve", # 3 - "qdf not uncompressed"], - ["-qdf --stream-data=preserve --normalize-content=n", # 4 - "qdf not normalized or uncompressed"], - ["--stream-data=uncompress", # 5 - "uncompresed"], - ["--normalize-content=y", # 6 - "normalized"], - ["--stream-data=uncompress --normalize-content=y", # 7 - "uncompressed and normalized"], - ["-decrypt", # 8 - "decrypted"], - ["-linearize", # 9 - "linearized"], - ["-allow-weak-crypto -encrypt \"\" owner 128 --", # 10 - "encrypted"], - ["-linearize -allow-weak-crypto -encrypt \"\" o 128 --", # 11 - "linearized and encrypted"], - ["", # 12 - "no arguments"], - ); - -my $n_tests = 1 + (@files * @flags * 2 * 3); -my $n_compare_pdfs = 1 + (@files * @flags * 2); - -foreach my $file (@files) -{ - my $base = basename($file, '.pdf'); - - foreach my $o (qw(disable generate)) - { - my $n = 0; - my $oflags = "--object-streams=$o"; - my $odescrip = "os:" . substr($o, 0, 1); - my $osuf = ($o eq 'generate' ? "-ogen" : ""); - foreach my $d (@flags) - { - my ($flags, $fdescrip) = @$d; - ++$n; - system("rm -f *.pnm"); - - $td->runtest("$file ($odescrip $fdescrip)", - {$td->COMMAND => "qpdf $flags $oflags $file a.pdf"}, - {$td->STRING => "", - $td->EXIT_STATUS => 0}); - - $td->runtest("check status", - {$td->COMMAND => "qpdf --check a.pdf"}, - {$td->FILE => "$base.$n$osuf.check", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - - $td->runtest("check with C API", - {$td->COMMAND => [qw(qpdf-ctest 1 a.pdf), "", ""]}, - {$td->FILE => "$base.$n$osuf.c-check", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - - compare_pdfs($td, $file, "a.pdf"); - } - flush_tiff_cache(); - } -} - -$td->runtest("convert inline-images to qdf", - {$td->COMMAND => "qpdf --static-id --no-original-object-ids" . - " --qdf inline-images.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); - -compare_pdfs($td, "inline-images.pdf", "a.pdf"); - -cleanup(); -$td->report(calc_ntests($n_tests, $n_compare_pdfs)); diff --git a/qpdf/qtest/copy-annotations.test b/qpdf/qtest/copy-annotations.test new file mode 100644 index 00000000..f43f84be --- /dev/null +++ b/qpdf/qtest/copy-annotations.test @@ -0,0 +1,186 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('copy-annotations'); + +my $n_tests = 39; + +$td->runtest("complex copy annotations", + {$td->COMMAND => + "qpdf --qdf --static-id --no-original-object-ids" . + " fxo-red.pdf --overlay form-fields-and-annotations.pdf" . + " --repeat=1 -- a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "overlay-copy-annotations.pdf"}); + +foreach my $page (1, 2, 5, 6) +{ + $td->runtest("copy annotations single page ($page)", + {$td->COMMAND => + "qpdf --qdf --static-id --no-original-object-ids" . + " --pages . $page --" . + " fxo-red.pdf --overlay form-fields-and-annotations.pdf" . + " --repeat=1 -- a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "overlay-copy-annotations-p$page.pdf"}); +} + +foreach my $d ([1, "appearances-1.pdf"], + [2, "appearances-1-rotated.pdf"]) +{ + my ($n, $file1) = @$d; + $td->runtest("copy/transfer with defaults", + {$td->COMMAND => "test_driver 80 $file1 minimal.pdf"}, + {$td->STRING => "test 80 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("check output A", + {$td->FILE => "a.pdf"}, + {$td->FILE => "test80a$n.pdf"}); + $td->runtest("check output B", + {$td->FILE => "b.pdf"}, + {$td->FILE => "test80b$n.pdf"}); +} + +$td->runtest("page extraction with fields", + {$td->COMMAND => + "qpdf --static-id --empty" . + " --pages fields-two-pages.pdf -- a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "fields-pages-out.pdf"}); +$td->runtest("page splitting with fields", + {$td->COMMAND => + "qpdf --static-id" . + " --split-pages fields-two-pages.pdf split-out.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +for (my $i = 1; $i <= 2; ++$i) +{ + $td->runtest("check output", + {$td->FILE => "split-out-$i.pdf"}, + {$td->FILE => "fields-split-$i.pdf"}); +} +$td->runtest("keeping some fields", + {$td->COMMAND => + "qpdf --static-id fields-two-pages.pdf" . + " --pages . 1 minimal.pdf -- a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "kept-some-fields.pdf"}); +$td->runtest("not keeping any fields", + {$td->COMMAND => + "qpdf --static-id kept-some-fields.pdf" . + " --pages . 2 -- a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "kept-no-fields.pdf"}); +$td->runtest("other file first", + {$td->COMMAND => + "qpdf --qdf --no-original-object-ids" . + " --static-id fields-two-pages.pdf" . + " --pages ./fields-two-pages.pdf . 1 -- a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "other-file-first.pdf"}); + +$td->runtest("field conflict resolution", + {$td->COMMAND => + "qpdf form-fields-and-annotations.pdf" . + " --pages . 1,1 ./form-fields-and-annotations.pdf 1,1 --" . + " --qdf --static-id --no-original-object-ids a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "resolved-field-conflicts.pdf"}); + +# field-resource-conflict.pdf was crafted so that an appearance stream +# had an existing resource that it actually referenced in the +# appearance stream whose name, /F1_1, clashed with the result of +# resolving conflicts in /DR. It's a crazy corner case, but it if it +# ever happened, it would be really hard to track down, and it could +# arise through multiple passes through qpdf with intervening edits. +$td->runtest("appearance stream resource conflict", + {$td->COMMAND => + "qpdf field-resource-conflict.pdf" . + " --pages . 1,1 ./field-resource-conflict.pdf --" . + " --qdf --static-id --no-original-object-ids a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "resolved-appearance-conflicts.pdf"}); + +$td->runtest("resource conflicts + flatten", + {$td->COMMAND => + "qpdf field-resource-conflict.pdf" . + " --pages . 1,1 ./field-resource-conflict.pdf --" . + " --generate-appearances --flatten-annotations=all" . + " --qdf --static-id --no-original-object-ids a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "resolved-appearance-conflicts-generate.pdf"}); + +$td->runtest("default DA/Q", + {$td->COMMAND => + "qpdf form-fields-and-annotations.pdf" . + " --pages . default-da-q.pdf --" . + " --qdf --static-id --no-original-object-ids" . + " --generate-appearances a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "default-da-q-out.pdf"}); + +$td->runtest("DA/appearance stream errors", + {$td->COMMAND => + "qpdf field-parse-errors.pdf" . + " --pages ./field-parse-errors.pdf --" . + " --qdf --static-id --no-original-object-ids a.pdf"}, + {$td->FILE => "field-parse-errors.out", $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "field-parse-errors-out.pdf"}); + +$td->runtest("Direct DR and annotations", + {$td->COMMAND => + "qpdf direct-dr.pdf --split-pages" . + " --qdf --static-id --no-original-object-ids" . + " split-out.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "split-out-1.pdf"}, + {$td->FILE => "direct-dr-out.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/copy-foreign-objects.test b/qpdf/qtest/copy-foreign-objects.test new file mode 100644 index 00000000..e7419e4f --- /dev/null +++ b/qpdf/qtest/copy-foreign-objects.test @@ -0,0 +1,63 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('copy-foreign-objects'); + +my $n_tests = 11; + +foreach my $d ([25, 1], [26, 2], [27, 3]) +{ + my ($testn, $outn) = @$d; + $td->runtest("copy objects $outn", + {$td->COMMAND => "test_driver $testn" . + " minimal.pdf copy-foreign-objects-in.pdf"}, + {$td->FILE => "copy-foreign-objects-$testn.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "copy-foreign-objects-out$outn.pdf"}); +} +$td->runtest("copy objects error", + {$td->COMMAND => "test_driver 28" . + " copy-foreign-objects-in.pdf minimal.pdf"}, + {$td->FILE => "copy-foreign-objects-errors.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +# Issue 449 involved indirect /Filter or /DecodeParms in streams that +# had their stream data replaced. The hand-generated +# indirect-filter.pdf file more or less reproduces the situation but +# doesn't result in the same internal error that 449 did with 10.0.1. +# The file issue-449.pdf was minimized by hand from a test case and +# does produce an internal error, though the exact reason is unclear. +# It seems to just have to do with the order in which things are +# copied. +$td->runtest("indirect filters", + {$td->COMMAND => "test_driver 69 indirect-filter.pdf"}, + {$td->STRING => "test 69 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +foreach my $i (0, 1) +{ + $td->runtest("check output", + {$td->FILE => "auto-$i.pdf"}, + {$td->FILE => "indirect-filter-out-$i.pdf"}); +} +$td->runtest("issue 449", + {$td->COMMAND => "test_driver 69 issue-449.pdf"}, + {$td->STRING => "test 69 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/copy_annotations.test b/qpdf/qtest/copy_annotations.test deleted file mode 100644 index eea4fe7e..00000000 --- a/qpdf/qtest/copy_annotations.test +++ /dev/null @@ -1,186 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('copy_annotations'); - -my $n_tests = 39; - -$td->runtest("complex copy annotations", - {$td->COMMAND => - "qpdf --qdf --static-id --no-original-object-ids" . - " fxo-red.pdf --overlay form-fields-and-annotations.pdf" . - " --repeat=1 -- a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "overlay-copy-annotations.pdf"}); - -foreach my $page (1, 2, 5, 6) -{ - $td->runtest("copy annotations single page ($page)", - {$td->COMMAND => - "qpdf --qdf --static-id --no-original-object-ids" . - " --pages . $page --" . - " fxo-red.pdf --overlay form-fields-and-annotations.pdf" . - " --repeat=1 -- a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "overlay-copy-annotations-p$page.pdf"}); -} - -foreach my $d ([1, "appearances-1.pdf"], - [2, "appearances-1-rotated.pdf"]) -{ - my ($n, $file1) = @$d; - $td->runtest("copy/transfer with defaults", - {$td->COMMAND => "test_driver 80 $file1 minimal.pdf"}, - {$td->STRING => "test 80 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("check output A", - {$td->FILE => "a.pdf"}, - {$td->FILE => "test80a$n.pdf"}); - $td->runtest("check output B", - {$td->FILE => "b.pdf"}, - {$td->FILE => "test80b$n.pdf"}); -} - -$td->runtest("page extraction with fields", - {$td->COMMAND => - "qpdf --static-id --empty" . - " --pages fields-two-pages.pdf -- a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "fields-pages-out.pdf"}); -$td->runtest("page splitting with fields", - {$td->COMMAND => - "qpdf --static-id" . - " --split-pages fields-two-pages.pdf split-out.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -for (my $i = 1; $i <= 2; ++$i) -{ - $td->runtest("check output", - {$td->FILE => "split-out-$i.pdf"}, - {$td->FILE => "fields-split-$i.pdf"}); -} -$td->runtest("keeping some fields", - {$td->COMMAND => - "qpdf --static-id fields-two-pages.pdf" . - " --pages . 1 minimal.pdf -- a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "kept-some-fields.pdf"}); -$td->runtest("not keeping any fields", - {$td->COMMAND => - "qpdf --static-id kept-some-fields.pdf" . - " --pages . 2 -- a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "kept-no-fields.pdf"}); -$td->runtest("other file first", - {$td->COMMAND => - "qpdf --qdf --no-original-object-ids" . - " --static-id fields-two-pages.pdf" . - " --pages ./fields-two-pages.pdf . 1 -- a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "other-file-first.pdf"}); - -$td->runtest("field conflict resolution", - {$td->COMMAND => - "qpdf form-fields-and-annotations.pdf" . - " --pages . 1,1 ./form-fields-and-annotations.pdf 1,1 --" . - " --qdf --static-id --no-original-object-ids a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "resolved-field-conflicts.pdf"}); - -# field-resource-conflict.pdf was crafted so that an appearance stream -# had an existing resource that it actually referenced in the -# appearance stream whose name, /F1_1, clashed with the result of -# resolving conflicts in /DR. It's a crazy corner case, but it if it -# ever happened, it would be really hard to track down, and it could -# arise through multiple passes through qpdf with intervening edits. -$td->runtest("appearance stream resource conflict", - {$td->COMMAND => - "qpdf field-resource-conflict.pdf" . - " --pages . 1,1 ./field-resource-conflict.pdf --" . - " --qdf --static-id --no-original-object-ids a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "resolved-appearance-conflicts.pdf"}); - -$td->runtest("resource conflicts + flatten", - {$td->COMMAND => - "qpdf field-resource-conflict.pdf" . - " --pages . 1,1 ./field-resource-conflict.pdf --" . - " --generate-appearances --flatten-annotations=all" . - " --qdf --static-id --no-original-object-ids a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "resolved-appearance-conflicts-generate.pdf"}); - -$td->runtest("default DA/Q", - {$td->COMMAND => - "qpdf form-fields-and-annotations.pdf" . - " --pages . default-da-q.pdf --" . - " --qdf --static-id --no-original-object-ids" . - " --generate-appearances a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "default-da-q-out.pdf"}); - -$td->runtest("DA/appearance stream errors", - {$td->COMMAND => - "qpdf field-parse-errors.pdf" . - " --pages ./field-parse-errors.pdf --" . - " --qdf --static-id --no-original-object-ids a.pdf"}, - {$td->FILE => "field-parse-errors.out", $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "field-parse-errors-out.pdf"}); - -$td->runtest("Direct DR and annotations", - {$td->COMMAND => - "qpdf direct-dr.pdf --split-pages" . - " --qdf --static-id --no-original-object-ids" . - " split-out.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "split-out-1.pdf"}, - {$td->FILE => "direct-dr-out.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/copy_foreign_objects.test b/qpdf/qtest/copy_foreign_objects.test deleted file mode 100644 index e12d814e..00000000 --- a/qpdf/qtest/copy_foreign_objects.test +++ /dev/null @@ -1,63 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('copy_foreign_objects'); - -my $n_tests = 11; - -foreach my $d ([25, 1], [26, 2], [27, 3]) -{ - my ($testn, $outn) = @$d; - $td->runtest("copy objects $outn", - {$td->COMMAND => "test_driver $testn" . - " minimal.pdf copy-foreign-objects-in.pdf"}, - {$td->FILE => "copy-foreign-objects-$testn.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "copy-foreign-objects-out$outn.pdf"}); -} -$td->runtest("copy objects error", - {$td->COMMAND => "test_driver 28" . - " copy-foreign-objects-in.pdf minimal.pdf"}, - {$td->FILE => "copy-foreign-objects-errors.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -# Issue 449 involved indirect /Filter or /DecodeParms in streams that -# had their stream data replaced. The hand-generated -# indirect-filter.pdf file more or less reproduces the situation but -# doesn't result in the same internal error that 449 did with 10.0.1. -# The file issue-449.pdf was minimized by hand from a test case and -# does produce an internal error, though the exact reason is unclear. -# It seems to just have to do with the order in which things are -# copied. -$td->runtest("indirect filters", - {$td->COMMAND => "test_driver 69 indirect-filter.pdf"}, - {$td->STRING => "test 69 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -foreach my $i (0, 1) -{ - $td->runtest("check output", - {$td->FILE => "auto-$i.pdf"}, - {$td->FILE => "indirect-filter-out-$i.pdf"}); -} -$td->runtest("issue 449", - {$td->COMMAND => "test_driver 69 issue-449.pdf"}, - {$td->STRING => "test 69 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/custom-pipeline.test b/qpdf/qtest/custom-pipeline.test new file mode 100644 index 00000000..7cf94784 --- /dev/null +++ b/qpdf/qtest/custom-pipeline.test @@ -0,0 +1,28 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('custom-pipeline'); + +my $n_tests = 2; + +$td->runtest("output to custom pipeline", + {$td->COMMAND => "test_driver 33 minimal.pdf"}, + {$td->STRING => "test 33 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "custom-pipeline.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/custom_pipeline.test b/qpdf/qtest/custom_pipeline.test deleted file mode 100644 index 3aef1e05..00000000 --- a/qpdf/qtest/custom_pipeline.test +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('custom_pipeline'); - -my $n_tests = 2; - -$td->runtest("output to custom pipeline", - {$td->COMMAND => "test_driver 33 minimal.pdf"}, - {$td->STRING => "test 33 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "custom-pipeline.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/dangling-refs.test b/qpdf/qtest/dangling-refs.test new file mode 100644 index 00000000..44d39212 --- /dev/null +++ b/qpdf/qtest/dangling-refs.test @@ -0,0 +1,31 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('dangling-refs'); + +my @dangling = (qw(minimal dangling-refs)); +my $n_tests = 2 * scalar(@dangling); + +foreach my $f (@dangling) +{ + $td->runtest("dangling refs: $f", + {$td->COMMAND => "test_driver 53 $f.pdf"}, + {$td->FILE => "$f-dangling.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "$f-dangling-out.pdf"}); +} +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/dangling_refs.test b/qpdf/qtest/dangling_refs.test deleted file mode 100644 index cdc6f2c1..00000000 --- a/qpdf/qtest/dangling_refs.test +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('dangling_refs'); - -my @dangling = (qw(minimal dangling-refs)); -my $n_tests = 2 * scalar(@dangling); - -foreach my $f (@dangling) -{ - $td->runtest("dangling refs: $f", - {$td->COMMAND => "test_driver 53 $f.pdf"}, - {$td->FILE => "$f-dangling.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "$f-dangling-out.pdf"}); -} -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/decode-levels.test b/qpdf/qtest/decode-levels.test new file mode 100644 index 00000000..c4c6f477 --- /dev/null +++ b/qpdf/qtest/decode-levels.test @@ -0,0 +1,71 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('decode-levels'); + +my $n_tests = 14; + +# image-streams.pdf is the output of examples/pdf-create. +# examples/pdf-create validates the actual image data. +# image-streams-small.pdf was manually created by editing +# pdf-create.cc to reduce width and height to 40x8 and ignoring +# errors. Its purpose was to get a small file with images with +# different filters for fuzz testing. +foreach my $l (qw(none generalized specialized all)) +{ + $td->runtest("image-streams: $l", + {$td->COMMAND => + "qpdf image-streams.pdf --compress-streams=n" . + " --decode-level=$l a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("check image-streams: $l", + {$td->COMMAND => "test_driver 39 a.pdf"}, + {$td->FILE => "image-streams-$l.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +} + +# C API +$td->runtest("image-streams: C", + {$td->COMMAND => "qpdf-ctest 20 image-streams.pdf '' a.pdf"}, + {$td->STRING => "C test 20 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check image-streams: C", + {$td->COMMAND => "test_driver 39 a.pdf"}, + {$td->FILE => "image-streams-specialized.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +# Bad JPEG data +$td->runtest("check finds bad jpeg data", + {$td->COMMAND => "qpdf --check bad-jpeg.pdf"}, + {$td->FILE => "bad-jpeg-check.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("precheck detects bad jpeg data", + {$td->COMMAND => "qpdf --static-id --decode-level=all" . + " bad-jpeg.pdf a.pdf"}, + {$td->FILE => "bad-jpeg.out", $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check file", + {$td->FILE => "a.pdf"}, + {$td->FILE => "bad-jpeg-out.pdf"}); +$td->runtest("get data", + {$td->COMMAND => "qpdf --show-object=6" . + " --filtered-stream-data bad-jpeg.pdf"}, + {$td->FILE => "bad-jpeg-show.out", $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/decode-parameters.test b/qpdf/qtest/decode-parameters.test new file mode 100644 index 00000000..8fed1a12 --- /dev/null +++ b/qpdf/qtest/decode-parameters.test @@ -0,0 +1,48 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('decode-parameters'); + +my $n_tests = 6; + +# Make sure we ignore decode parameters that we don't understand +$td->runtest("unknown decode parameters", + {$td->COMMAND => "qpdf --check fax-decode-parms.pdf"}, + {$td->FILE => "fax-decode-parms.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("ignore broken decode parms with no filters", + {$td->COMMAND => "qpdf --check broken-decode-parms-no-filter.pdf"}, + {$td->FILE => "broken-decode-parms-no-filter.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("stream with indirect decode parms", + {$td->COMMAND => + "qpdf --static-id indirect-decode-parms.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check file", + {$td->FILE => "a.pdf"}, + {$td->FILE => "indirect-decode-parms-out.pdf"}); + +$td->runtest("decode parameters empty list", + {$td->COMMAND => "qpdf --static-id empty-decode-parms.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check file", + {$td->FILE => "a.pdf"}, + {$td->FILE => "empty-decode-parms-out.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/decode_levels.test b/qpdf/qtest/decode_levels.test deleted file mode 100644 index a4fd08b0..00000000 --- a/qpdf/qtest/decode_levels.test +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('decode_levels'); - -my $n_tests = 14; - -# image-streams.pdf is the output of examples/pdf-create. -# examples/pdf-create validates the actual image data. -# image-streams-small.pdf was manually created by editing -# pdf-create.cc to reduce width and height to 40x8 and ignoring -# errors. Its purpose was to get a small file with images with -# different filters for fuzz testing. -foreach my $l (qw(none generalized specialized all)) -{ - $td->runtest("image-streams: $l", - {$td->COMMAND => - "qpdf image-streams.pdf --compress-streams=n" . - " --decode-level=$l a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("check image-streams: $l", - {$td->COMMAND => "test_driver 39 a.pdf"}, - {$td->FILE => "image-streams-$l.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -} - -# C API -$td->runtest("image-streams: C", - {$td->COMMAND => "qpdf-ctest 20 image-streams.pdf '' a.pdf"}, - {$td->STRING => "C test 20 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check image-streams: C", - {$td->COMMAND => "test_driver 39 a.pdf"}, - {$td->FILE => "image-streams-specialized.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -# Bad JPEG data -$td->runtest("check finds bad jpeg data", - {$td->COMMAND => "qpdf --check bad-jpeg.pdf"}, - {$td->FILE => "bad-jpeg-check.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("precheck detects bad jpeg data", - {$td->COMMAND => "qpdf --static-id --decode-level=all" . - " bad-jpeg.pdf a.pdf"}, - {$td->FILE => "bad-jpeg.out", $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check file", - {$td->FILE => "a.pdf"}, - {$td->FILE => "bad-jpeg-out.pdf"}); -$td->runtest("get data", - {$td->COMMAND => "qpdf --show-object=6" . - " --filtered-stream-data bad-jpeg.pdf"}, - {$td->FILE => "bad-jpeg-show.out", $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/decode_parameters.test b/qpdf/qtest/decode_parameters.test deleted file mode 100644 index f0b181af..00000000 --- a/qpdf/qtest/decode_parameters.test +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('decode_parameters'); - -my $n_tests = 6; - -# Make sure we ignore decode parameters that we don't understand -$td->runtest("unknown decode parameters", - {$td->COMMAND => "qpdf --check fax-decode-parms.pdf"}, - {$td->FILE => "fax-decode-parms.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("ignore broken decode parms with no filters", - {$td->COMMAND => "qpdf --check broken-decode-parms-no-filter.pdf"}, - {$td->FILE => "broken-decode-parms-no-filter.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("stream with indirect decode parms", - {$td->COMMAND => - "qpdf --static-id indirect-decode-parms.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check file", - {$td->FILE => "a.pdf"}, - {$td->FILE => "indirect-decode-parms-out.pdf"}); - -$td->runtest("decode parameters empty list", - {$td->COMMAND => "qpdf --static-id empty-decode-parms.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check file", - {$td->FILE => "a.pdf"}, - {$td->FILE => "empty-decode-parms-out.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/deterministic-id.test b/qpdf/qtest/deterministic-id.test new file mode 100644 index 00000000..9aeb7f38 --- /dev/null +++ b/qpdf/qtest/deterministic-id.test @@ -0,0 +1,55 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('deterministic-id'); + +my $n_tests = 11; + +foreach my $d ('nn', 'ny', 'yn', 'yy') +{ + my $linearize = ($d =~ m/^y/); + my $ostream = ($d =~ m/y$/); + $td->runtest("deterministic ID: linearize/ostream=$d", + {$td->COMMAND => + "qpdf -deterministic-id" . + ($linearize ? " -linearize" : "") . + " -object-streams=" . ($ostream ? "generate" : "disable") . + " deterministic-id-in.pdf a.pdf"}, + {$td->STRING => "", + $td->EXIT_STATUS => 0}); + $td->runtest("compare files", + {$td->FILE => "a.pdf"}, + {$td->FILE => "deterministic-id-$d.pdf"}); +} + +$td->runtest("deterministic ID with encryption", + {$td->COMMAND => "qpdf -deterministic-id encrypted-with-images.pdf a.pdf"}, + {$td->STRING => "qpdf: INTERNAL ERROR: QPDFWriter::generateID" . + " has no data for deterministic ID." . + " This may happen if deterministic ID and" . + " file encryption are requested together.\n", + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); +$td->runtest("deterministic ID (C API)", + {$td->COMMAND => + "qpdf-ctest 19 deterministic-id-in.pdf '' a.pdf"}, + {$td->STRING => "C test 19 done\n", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("compare files", + {$td->FILE => "a.pdf"}, + {$td->FILE => "deterministic-id-nn.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/deterministic_id.test b/qpdf/qtest/deterministic_id.test deleted file mode 100644 index d61722f2..00000000 --- a/qpdf/qtest/deterministic_id.test +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('deterministic_id'); - -my $n_tests = 11; - -foreach my $d ('nn', 'ny', 'yn', 'yy') -{ - my $linearize = ($d =~ m/^y/); - my $ostream = ($d =~ m/y$/); - $td->runtest("deterministic ID: linearize/ostream=$d", - {$td->COMMAND => - "qpdf -deterministic-id" . - ($linearize ? " -linearize" : "") . - " -object-streams=" . ($ostream ? "generate" : "disable") . - " deterministic-id-in.pdf a.pdf"}, - {$td->STRING => "", - $td->EXIT_STATUS => 0}); - $td->runtest("compare files", - {$td->FILE => "a.pdf"}, - {$td->FILE => "deterministic-id-$d.pdf"}); -} - -$td->runtest("deterministic ID with encryption", - {$td->COMMAND => "qpdf -deterministic-id encrypted-with-images.pdf a.pdf"}, - {$td->STRING => "qpdf: INTERNAL ERROR: QPDFWriter::generateID" . - " has no data for deterministic ID." . - " This may happen if deterministic ID and" . - " file encryption are requested together.\n", - $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); -$td->runtest("deterministic ID (C API)", - {$td->COMMAND => - "qpdf-ctest 19 deterministic-id-in.pdf '' a.pdf"}, - {$td->STRING => "C test 19 done\n", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("compare files", - {$td->FILE => "a.pdf"}, - {$td->FILE => "deterministic-id-nn.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/disable-filter-on-write.test b/qpdf/qtest/disable-filter-on-write.test new file mode 100644 index 00000000..01928958 --- /dev/null +++ b/qpdf/qtest/disable-filter-on-write.test @@ -0,0 +1,28 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('disable-filter-on-write'); + +my $n_tests = 2; + +$td->runtest("no filter on write", + {$td->COMMAND => "test_driver 70 filter-on-write.pdf"}, + {$td->STRING => "test 70 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "filter-on-write-out.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/disable_filter_on_write.test b/qpdf/qtest/disable_filter_on_write.test deleted file mode 100644 index b513992a..00000000 --- a/qpdf/qtest/disable_filter_on_write.test +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('disable_filter_on_write'); - -my $n_tests = 2; - -$td->runtest("no filter on write", - {$td->COMMAND => "test_driver 70 filter-on-write.pdf"}, - {$td->STRING => "test 70 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "filter-on-write-out.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/encryption-parameters.test b/qpdf/qtest/encryption-parameters.test new file mode 100644 index 00000000..f6d852c0 --- /dev/null +++ b/qpdf/qtest/encryption-parameters.test @@ -0,0 +1,88 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('encryption-parameters'); + +my $n_tests = 13; + +# Encrypt files whose /ID strings are other than 32 bytes long (bug +# 2991412). Also linearize these files, which was reported in a +# separate bug by email. +foreach my $file (qw(short-id long-id)) +{ + $td->runtest("encrypt $file.pdf", + {$td->COMMAND => + "qpdf --allow-weak-crypto". + " --encrypt '' pass 40 -- $file.pdf a.pdf"}, + {$td->STRING => "", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + + $td->runtest("check $file.pdf", + {$td->COMMAND => "qpdf --check --show-encryption-key a.pdf"}, + {$td->FILE => "$file-check.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + + $td->runtest("linearize $file.pdf", + {$td->COMMAND => + "qpdf --deterministic-id --linearize $file.pdf a.pdf"}, + {$td->STRING => "", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + + $td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "$file-linearized.pdf"}); + + $td->runtest("check $file.pdf", + {$td->COMMAND => "qpdf --check a.pdf"}, + {$td->FILE => "$file-linearized-check.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +} + +# A user provided a file that was missing /ID in its trailer even +# though it is encrypted and also has a space instead of a newline +# after its xref keyword. This file has those same properties. +$td->runtest("check broken file", + {$td->COMMAND => "qpdf --check invalid-id-xref.pdf"}, + {$td->FILE => "invalid-id-xref.out", $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); + +# A file was emailed privately with issue 96. short-O-U.pdf was +# created by copying encryption parameters from that file. It exhibits +# the same behavior as the original file. +$td->runtest("short /O or /U", + {$td->COMMAND => + "qpdf --password=19723102477 --check short-O-U.pdf"}, + {$td->FILE => "short-O-U.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +# A file was sent to me privately as part of issue 212. This file was +# encrypted and had /R=3 and /V=1 and was using a 40-bit key. qpdf was +# failing to work properly on files with /R=3 and 40-bit keys. The +# test file is not this private file, but the encryption parameters +# were copied from it. Like the bug file, qpdf < 8.1 can't decrypt it. +$td->runtest("/R 3 with 40-bit key", + {$td->COMMAND => + "qpdf --password=623 --check --show-encryption-key" . + " encrypted-40-bit-R3.pdf"}, + {$td->FILE => "encrypted-40-bit-R3.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/encryption_parameters.test b/qpdf/qtest/encryption_parameters.test deleted file mode 100644 index 20258b15..00000000 --- a/qpdf/qtest/encryption_parameters.test +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('encryption_parameters'); - -my $n_tests = 13; - -# Encrypt files whose /ID strings are other than 32 bytes long (bug -# 2991412). Also linearize these files, which was reported in a -# separate bug by email. -foreach my $file (qw(short-id long-id)) -{ - $td->runtest("encrypt $file.pdf", - {$td->COMMAND => - "qpdf --allow-weak-crypto". - " --encrypt '' pass 40 -- $file.pdf a.pdf"}, - {$td->STRING => "", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - - $td->runtest("check $file.pdf", - {$td->COMMAND => "qpdf --check --show-encryption-key a.pdf"}, - {$td->FILE => "$file-check.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - - $td->runtest("linearize $file.pdf", - {$td->COMMAND => - "qpdf --deterministic-id --linearize $file.pdf a.pdf"}, - {$td->STRING => "", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - - $td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "$file-linearized.pdf"}); - - $td->runtest("check $file.pdf", - {$td->COMMAND => "qpdf --check a.pdf"}, - {$td->FILE => "$file-linearized-check.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -} - -# A user provided a file that was missing /ID in its trailer even -# though it is encrypted and also has a space instead of a newline -# after its xref keyword. This file has those same properties. -$td->runtest("check broken file", - {$td->COMMAND => "qpdf --check invalid-id-xref.pdf"}, - {$td->FILE => "invalid-id-xref.out", $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); - -# A file was emailed privately with issue 96. short-O-U.pdf was -# created by copying encryption parameters from that file. It exhibits -# the same behavior as the original file. -$td->runtest("short /O or /U", - {$td->COMMAND => - "qpdf --password=19723102477 --check short-O-U.pdf"}, - {$td->FILE => "short-O-U.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -# A file was sent to me privately as part of issue 212. This file was -# encrypted and had /R=3 and /V=1 and was using a 40-bit key. qpdf was -# failing to work properly on files with /R=3 and 40-bit keys. The -# test file is not this private file, but the encryption parameters -# were copied from it. Like the bug file, qpdf < 8.1 can't decrypt it. -$td->runtest("/R 3 with 40-bit key", - {$td->COMMAND => - "qpdf --password=623 --check --show-encryption-key" . - " encrypted-40-bit-R3.pdf"}, - {$td->FILE => "encrypted-40-bit-R3.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/error-condition.test b/qpdf/qtest/error-condition.test new file mode 100644 index 00000000..1184deb2 --- /dev/null +++ b/qpdf/qtest/error-condition.test @@ -0,0 +1,211 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('error-condition'); + +my $n_tests = 0; +# $n_tests incremented after initialization of badfiles below. + +my @badfiles = ("not a PDF file", # 1 + "no startxref", # 2 + "bad primary xref offset", # 3 + "invalid xref syntax", # 4 + "invalid xref entry", # 5 + "free table inconsistency", # 6 + "no trailer dictionary", # 7 + "bad secondary xref", # 8 + "no /Size in trailer", # 9 + "/Size not integer", # 10 + "/Prev not integer", # 11 + "/Size inconsistency", # 12 + "bad {", # 13 + "bad }", # 14 + "bad ]", # 15 + "bad >>", # 16 + "dictionary errors", # 17 + "bad )", # 18 + "bad >", # 19 + "invalid hexstring character", # 20 + "invalid name token", # 21 + "no /Length for stream dictionary", # 22 + "/Length not integer", # 23 + "expected endstream", # 24 + "bad obj declaration (objid)", # 25 + "bad obj declaration (generation)", # 26 + "bad obj declaration (obj)", # 27 + "expected endobj", # 28 + "null in name", # 29 + "invalid stream /Filter", # 30 + "unknown stream /Filter", # 31 + "obj/gen mismatch", # 32 + "invalid stream /Filter and xref", # 33 + "obj/gen in wrong place", # 34 + "object stream of wrong type", # 35 + "bad dictionary key", # 36 + "space before xref", # 37 + "startxref to space then eof", # 38 + ); + +$n_tests += @badfiles + 8; + +# Test 6 contains errors in the free table consistency, but we no +# longer have any consistency check for this since it is not important +# neither Acrobat nor other PDF viewers really care. Tests 12 and 28 +# have error conditions that used to be fatal but are now considered +# non-fatal. +my %badtest_overrides = (); +for(6, 12..15, 17, 18..32, 34..37) +{ + $badtest_overrides{$_} = 0; +} + +for (my $i = 1; $i <= scalar(@badfiles); ++$i) +{ + my $status = $badtest_overrides{$i}; + $status = 2 unless defined $status; + $td->runtest($badfiles[$i-1], + {$td->COMMAND => "test_driver 0 bad$i.pdf"}, + {$td->FILE => "bad$i.out", + $td->EXIT_STATUS => $status}, + $td->NORMALIZE_NEWLINES); +} + +$td->runtest("Suppress warnings", + {$td->COMMAND => "qpdf --no-warn bad14.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 3}); +$td->runtest("Suppress warnings", + {$td->COMMAND => + "qpdf --no-warn --warning-exit-0 bad14.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("Suppress warnings with --check", + {$td->COMMAND => "qpdf --check --no-warn bad14.pdf"}, + {$td->FILE => "bad14-check-no-warn.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("C API: errors", + {$td->COMMAND => "qpdf-ctest 2 bad1.pdf '' a.pdf"}, + {$td->FILE => "c-read-errors.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("C API: warnings writing", + {$td->COMMAND => "qpdf-ctest 2 bad33.pdf '' a.pdf"}, + {$td->FILE => "c-write-warnings.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("C API: no recovery", + {$td->COMMAND => "qpdf-ctest 10 bad33.pdf '' a.pdf"}, + {$td->FILE => "c-no-recovery.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("integer type checks", + {$td->COMMAND => "test_driver 62 minimal.pdf"}, + {$td->STRING => "test 62 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("getValueAs... accessor checks", + {$td->COMMAND => "test_driver 85 -"}, + {$td->STRING => "test 85 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$n_tests += @badfiles + 11; + +# Recovery tests. These are mostly after-the-fact -- when recovery +# was implemented, some degree of recovery was possible on many of the +# files. Mostly the recovery does not actually repair the error, +# though in some cases it may. Acrobat Reader would not be able to +# recover any of these files any better. +my %recover_failures = (); +for (1, 7, 16) +{ + $recover_failures{$_} = 1; +} +for (my $i = 1; $i <= scalar(@badfiles); ++$i) +{ + my $status = 0; + if (exists $recover_failures{$i}) + { + $status = 2; + } + $td->runtest("recover " . $badfiles[$i-1], + {$td->COMMAND => "test_driver 1 bad$i.pdf"}, + {$td->FILE => "bad$i-recover.out", + $td->EXIT_STATUS => $status}, + $td->NORMALIZE_NEWLINES); +} + +# See if we can recover the cross reference table on a file that has +# been appended to even when it deletes and reuses objects. We can't +# completely do it in the case of deleted objects, but we can get +# mostly there. +$td->runtest("good replaced page contents", + {$td->COMMAND => + "qpdf --static-id -qdf --no-original-object-ids" . + " append-page-content.pdf a.pdf"}, + {$td->STRING => "", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "append-page-content-good.qdf"}); +$td->runtest("damaged replaced page contents", + {$td->COMMAND => + "qpdf --static-id -qdf --no-original-object-ids" . + " append-page-content-damaged.pdf a.pdf"}, + {$td->FILE => "append-page-content-damaged.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "append-page-content-damaged.qdf"}); +$td->runtest("run check on damaged file", + {$td->COMMAND => "qpdf --check append-page-content-damaged.pdf"}, + {$td->FILE => "append-page-content-damaged-check.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check with C API", + {$td->COMMAND => + "qpdf-ctest 1 append-page-content-damaged.pdf '' ''"}, + {$td->FILE => "append-page-content-damaged-c-check.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("recoverable xref errors", + {$td->COMMAND => + "qpdf --check --show-xref xref-errors.pdf"}, + {$td->FILE => "xref-errors.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("xref loop with append", + {$td->COMMAND => + "qpdf --deterministic-id append-xref-loop.pdf a.pdf"}, + {$td->FILE => "append-xref-loop.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "append-xref-loop-fixed.pdf"}); + +$td->runtest("endobj not at newline", + {$td->COMMAND => + "qpdf --deterministic-id endobj-at-eol.pdf a.pdf"}, + {$td->FILE => "endobj-at-eol.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "endobj-at-eol-fixed.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/error_condition.test b/qpdf/qtest/error_condition.test deleted file mode 100644 index 3e243bb6..00000000 --- a/qpdf/qtest/error_condition.test +++ /dev/null @@ -1,211 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('error_condition'); - -my $n_tests = 0; -# $n_tests incremented after initialization of badfiles below. - -my @badfiles = ("not a PDF file", # 1 - "no startxref", # 2 - "bad primary xref offset", # 3 - "invalid xref syntax", # 4 - "invalid xref entry", # 5 - "free table inconsistency", # 6 - "no trailer dictionary", # 7 - "bad secondary xref", # 8 - "no /Size in trailer", # 9 - "/Size not integer", # 10 - "/Prev not integer", # 11 - "/Size inconsistency", # 12 - "bad {", # 13 - "bad }", # 14 - "bad ]", # 15 - "bad >>", # 16 - "dictionary errors", # 17 - "bad )", # 18 - "bad >", # 19 - "invalid hexstring character", # 20 - "invalid name token", # 21 - "no /Length for stream dictionary", # 22 - "/Length not integer", # 23 - "expected endstream", # 24 - "bad obj declaration (objid)", # 25 - "bad obj declaration (generation)", # 26 - "bad obj declaration (obj)", # 27 - "expected endobj", # 28 - "null in name", # 29 - "invalid stream /Filter", # 30 - "unknown stream /Filter", # 31 - "obj/gen mismatch", # 32 - "invalid stream /Filter and xref", # 33 - "obj/gen in wrong place", # 34 - "object stream of wrong type", # 35 - "bad dictionary key", # 36 - "space before xref", # 37 - "startxref to space then eof", # 38 - ); - -$n_tests += @badfiles + 8; - -# Test 6 contains errors in the free table consistency, but we no -# longer have any consistency check for this since it is not important -# neither Acrobat nor other PDF viewers really care. Tests 12 and 28 -# have error conditions that used to be fatal but are now considered -# non-fatal. -my %badtest_overrides = (); -for(6, 12..15, 17, 18..32, 34..37) -{ - $badtest_overrides{$_} = 0; -} - -for (my $i = 1; $i <= scalar(@badfiles); ++$i) -{ - my $status = $badtest_overrides{$i}; - $status = 2 unless defined $status; - $td->runtest($badfiles[$i-1], - {$td->COMMAND => "test_driver 0 bad$i.pdf"}, - {$td->FILE => "bad$i.out", - $td->EXIT_STATUS => $status}, - $td->NORMALIZE_NEWLINES); -} - -$td->runtest("Suppress warnings", - {$td->COMMAND => "qpdf --no-warn bad14.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 3}); -$td->runtest("Suppress warnings", - {$td->COMMAND => - "qpdf --no-warn --warning-exit-0 bad14.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("Suppress warnings with --check", - {$td->COMMAND => "qpdf --check --no-warn bad14.pdf"}, - {$td->FILE => "bad14-check-no-warn.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("C API: errors", - {$td->COMMAND => "qpdf-ctest 2 bad1.pdf '' a.pdf"}, - {$td->FILE => "c-read-errors.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("C API: warnings writing", - {$td->COMMAND => "qpdf-ctest 2 bad33.pdf '' a.pdf"}, - {$td->FILE => "c-write-warnings.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("C API: no recovery", - {$td->COMMAND => "qpdf-ctest 10 bad33.pdf '' a.pdf"}, - {$td->FILE => "c-no-recovery.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("integer type checks", - {$td->COMMAND => "test_driver 62 minimal.pdf"}, - {$td->STRING => "test 62 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("getValueAs... accessor checks", - {$td->COMMAND => "test_driver 85 -"}, - {$td->STRING => "test 85 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$n_tests += @badfiles + 11; - -# Recovery tests. These are mostly after-the-fact -- when recovery -# was implemented, some degree of recovery was possible on many of the -# files. Mostly the recovery does not actually repair the error, -# though in some cases it may. Acrobat Reader would not be able to -# recover any of these files any better. -my %recover_failures = (); -for (1, 7, 16) -{ - $recover_failures{$_} = 1; -} -for (my $i = 1; $i <= scalar(@badfiles); ++$i) -{ - my $status = 0; - if (exists $recover_failures{$i}) - { - $status = 2; - } - $td->runtest("recover " . $badfiles[$i-1], - {$td->COMMAND => "test_driver 1 bad$i.pdf"}, - {$td->FILE => "bad$i-recover.out", - $td->EXIT_STATUS => $status}, - $td->NORMALIZE_NEWLINES); -} - -# See if we can recover the cross reference table on a file that has -# been appended to even when it deletes and reuses objects. We can't -# completely do it in the case of deleted objects, but we can get -# mostly there. -$td->runtest("good replaced page contents", - {$td->COMMAND => - "qpdf --static-id -qdf --no-original-object-ids" . - " append-page-content.pdf a.pdf"}, - {$td->STRING => "", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "append-page-content-good.qdf"}); -$td->runtest("damaged replaced page contents", - {$td->COMMAND => - "qpdf --static-id -qdf --no-original-object-ids" . - " append-page-content-damaged.pdf a.pdf"}, - {$td->FILE => "append-page-content-damaged.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "append-page-content-damaged.qdf"}); -$td->runtest("run check on damaged file", - {$td->COMMAND => "qpdf --check append-page-content-damaged.pdf"}, - {$td->FILE => "append-page-content-damaged-check.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check with C API", - {$td->COMMAND => - "qpdf-ctest 1 append-page-content-damaged.pdf '' ''"}, - {$td->FILE => "append-page-content-damaged-c-check.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("recoverable xref errors", - {$td->COMMAND => - "qpdf --check --show-xref xref-errors.pdf"}, - {$td->FILE => "xref-errors.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("xref loop with append", - {$td->COMMAND => - "qpdf --deterministic-id append-xref-loop.pdf a.pdf"}, - {$td->FILE => "append-xref-loop.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "append-xref-loop-fixed.pdf"}); - -$td->runtest("endobj not at newline", - {$td->COMMAND => - "qpdf --deterministic-id endobj-at-eol.pdf a.pdf"}, - {$td->FILE => "endobj-at-eol.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "endobj-at-eol-fixed.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/extensions-dictionary.test b/qpdf/qtest/extensions-dictionary.test new file mode 100644 index 00000000..b16cce33 --- /dev/null +++ b/qpdf/qtest/extensions-dictionary.test @@ -0,0 +1,64 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('extensions-dictionary'); + +my @ext_inputs = ('minimal.pdf', 'extensions-adbe.pdf', + 'extensions-other.pdf', 'extensions-adbe-other.pdf'); +my @new_versions = ('1.3', '1.6', '1.7.1', '1.7.2', '1.7.3', + '1.8', '1.8.0', '1.8.2', '1.8.5'); +my $n_tests = (4 * @new_versions + 3) * @ext_inputs; +foreach my $input (@ext_inputs) +{ + my $base = $input; + $base =~ s/\.pdf$//; + if ($base eq 'minimal') + { + $base = 'extensions-none'; + } + foreach my $version (@new_versions) + { + foreach my $op (qw(min force)) + { + $td->runtest("$input: $op version to $version", + {$td->COMMAND => + "qpdf --static-id" . + " --$op-version=$version $input a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); + $td->runtest("check version information ($op $version)", + {$td->COMMAND => "test_driver 34 a.pdf"}, + {$td->FILE => "$base-$op-$version.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + if (($op eq 'force') && ($version eq '1.8.5')) + { + # Look at the actual file for a few cases to make sure + # qdf and non-qdf output are okay + $td->runtest("check file", + {$td->FILE => "a.pdf"}, + {$td->FILE => "$base-$op-$version.pdf"}); + $td->runtest("$input: $op version to $version", + {$td->COMMAND => + "qpdf --qdf --static-id" . + " --$op-version=$version $input a.qdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); + $td->runtest("check file", + {$td->FILE => "a.qdf"}, + {$td->FILE => "$base-$op-$version.qdf"}); + } + } + } +} +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/extensions_dictionary.test b/qpdf/qtest/extensions_dictionary.test deleted file mode 100644 index f7187a56..00000000 --- a/qpdf/qtest/extensions_dictionary.test +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('extensions_dictionary'); - -my @ext_inputs = ('minimal.pdf', 'extensions-adbe.pdf', - 'extensions-other.pdf', 'extensions-adbe-other.pdf'); -my @new_versions = ('1.3', '1.6', '1.7.1', '1.7.2', '1.7.3', - '1.8', '1.8.0', '1.8.2', '1.8.5'); -my $n_tests = (4 * @new_versions + 3) * @ext_inputs; -foreach my $input (@ext_inputs) -{ - my $base = $input; - $base =~ s/\.pdf$//; - if ($base eq 'minimal') - { - $base = 'extensions-none'; - } - foreach my $version (@new_versions) - { - foreach my $op (qw(min force)) - { - $td->runtest("$input: $op version to $version", - {$td->COMMAND => - "qpdf --static-id" . - " --$op-version=$version $input a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); - $td->runtest("check version information ($op $version)", - {$td->COMMAND => "test_driver 34 a.pdf"}, - {$td->FILE => "$base-$op-$version.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - if (($op eq 'force') && ($version eq '1.8.5')) - { - # Look at the actual file for a few cases to make sure - # qdf and non-qdf output are okay - $td->runtest("check file", - {$td->FILE => "a.pdf"}, - {$td->FILE => "$base-$op-$version.pdf"}); - $td->runtest("$input: $op version to $version", - {$td->COMMAND => - "qpdf --qdf --static-id" . - " --$op-version=$version $input a.qdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); - $td->runtest("check file", - {$td->FILE => "a.qdf"}, - {$td->FILE => "$base-$op-$version.qdf"}); - } - } - } -} -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/filter-abbreviations.test b/qpdf/qtest/filter-abbreviations.test new file mode 100644 index 00000000..cb552b87 --- /dev/null +++ b/qpdf/qtest/filter-abbreviations.test @@ -0,0 +1,30 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('filter-abbreviations'); + +my $n_tests = 2; + +# Stream filter abbreviations from table H.1 +$td->runtest("stream filter abbreviations", + {$td->COMMAND => "qpdf --static-id filter-abbreviation.pdf a.pdf"}, + {$td->STRING => "", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "filter-abbreviation.out"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/filter_abbreviations.test b/qpdf/qtest/filter_abbreviations.test deleted file mode 100644 index 54e42166..00000000 --- a/qpdf/qtest/filter_abbreviations.test +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('filter_abbreviations'); - -my $n_tests = 2; - -# Stream filter abbreviations from table H.1 -$td->runtest("stream filter abbreviations", - {$td->COMMAND => "qpdf --static-id filter-abbreviation.pdf a.pdf"}, - {$td->STRING => "", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "filter-abbreviation.out"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/final-version.test b/qpdf/qtest/final-version.test new file mode 100644 index 00000000..fe3f576c --- /dev/null +++ b/qpdf/qtest/final-version.test @@ -0,0 +1,25 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('final-version'); + +my $n_tests = 1; + +$td->runtest("check final version", + {$td->COMMAND => "test_driver 54 minimal.pdf"}, + {$td->STRING => "test 54 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/final_version.test b/qpdf/qtest/final_version.test deleted file mode 100644 index 1fe65feb..00000000 --- a/qpdf/qtest/final_version.test +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('final_version'); - -my $n_tests = 1; - -$td->runtest("check final version", - {$td->COMMAND => "test_driver 54 minimal.pdf"}, - {$td->STRING => "test 54 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/fix-qdf.test b/qpdf/qtest/fix-qdf.test new file mode 100644 index 00000000..e46ee9c1 --- /dev/null +++ b/qpdf/qtest/fix-qdf.test @@ -0,0 +1,37 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('fix-qdf'); + +my $n_tests = 5; + +for (my $n = 1; $n <= 2; ++$n) +{ + $td->runtest("fix-qdf $n", + {$td->COMMAND => "fix-qdf fix$n.qdf"}, + {$td->FILE => "fix$n.qdf.out", + $td->EXIT_STATUS => 0}); + + $td->runtest("identity fix-qdf $n", + {$td->COMMAND => "fix-qdf fix$n.qdf.out"}, + {$td->FILE => "fix$n.qdf.out", + $td->EXIT_STATUS => 0}); +} +$td->runtest("fix-qdf with big object stream", # > 255 objects in a stream + {$td->COMMAND => "fix-qdf big-ostream.pdf"}, + {$td->FILE => "big-ostream.pdf", + $td->EXIT_STATUS => 0}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/fix_qdf.test b/qpdf/qtest/fix_qdf.test deleted file mode 100644 index cd63e2af..00000000 --- a/qpdf/qtest/fix_qdf.test +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('fix_qdf'); - -my $n_tests = 5; - -for (my $n = 1; $n <= 2; ++$n) -{ - $td->runtest("fix-qdf $n", - {$td->COMMAND => "fix-qdf fix$n.qdf"}, - {$td->FILE => "fix$n.qdf.out", - $td->EXIT_STATUS => 0}); - - $td->runtest("identity fix-qdf $n", - {$td->COMMAND => "fix-qdf fix$n.qdf.out"}, - {$td->FILE => "fix$n.qdf.out", - $td->EXIT_STATUS => 0}); -} -$td->runtest("fix-qdf with big object stream", # > 255 objects in a stream - {$td->COMMAND => "fix-qdf big-ostream.pdf"}, - {$td->FILE => "big-ostream.pdf", - $td->EXIT_STATUS => 0}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/flatten-annotations.test b/qpdf/qtest/flatten-annotations.test new file mode 100644 index 00000000..5d071dba --- /dev/null +++ b/qpdf/qtest/flatten-annotations.test @@ -0,0 +1,94 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('flatten-annotations'); + +my $n_tests = 0; + +# manual-appearances was created by hand-coding appearance streams +# with graphics that make it easy to test matrix calculations. The +# result of flattening the annotations was compared visually with +# okular. Some PDF viewers don't actually display the original version +# correctly. The pages are as follows: +# - page 1: normal +# - page 2: rotate 90 with /F 20 (NoRotate) +# - page 3: non-trivial matrix +# - page 4: non-trivial matrix, rotate +# - page 5: rotate 180 with /F 20 +# - page 6: rotate 90, /F 20, non-trivial matrix +# - page 7: flags: top is print, middle is screen, bottom is hidden +# - page 8: rotate 270 with /F 20 +# - page 9: normal -- available for additional testing +# +# form-filled-by-acrobat was filled in using the Acrobat Reader +# android app. One of its appearance streams is actually an image. +# +# need-appearances.pdf is based on field-types.pdf with manual edits +# to turn on NeedAppearances, change /V for several fields, and add +# the comment annotation from comment-annotation.pdf. The test output +# includes a flattened version of the comment annotation but not of +# the form fields. Changes: +# - field-types.pdf has /NeedAppearances true +# - text1: blank -> abc +# - r1: 1 -> 2 +# - list1: blank -> five +# - combolist1: blank -> pi +# - drop1: blank -> elephant +# - combodrop1: blank -> delta + +my @annotation_files = ( + 'manual-appearances', + 'form-filled-by-acrobat', + 'comment-annotation', + 'comment-annotation-direct', + 'sample-form', + 'need-appearances', + 'need-appearances-more', + ); +$n_tests += 2 * scalar(@annotation_files); + +foreach my $f (@annotation_files) +{ + my $exp_out = {$td->STRING => "", $td->EXIT_STATUS => 0}; + if (-f "$f-warn.out") + { + $exp_out = {$td->FILE => "$f-warn.out", $td->EXIT_STATUS => 3}; + } + $td->runtest("flatten $f", + {$td->COMMAND => + "qpdf --qdf --static-id --no-original-object-ids" . + " --flatten-annotations=all $f.pdf a.pdf"}, + $exp_out, + $td->NORMALIZE_NEWLINES); + $td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "$f-out.pdf"}); +} + +$n_tests += 4; +foreach my $f (qw(screen print)) +{ + $td->runtest("flatten for $f", + {$td->COMMAND => + "qpdf --qdf --static-id --no-original-object-ids" . + " --flatten-annotations=$f manual-appearances.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "manual-appearances-$f-out.pdf"}); +} + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/flatten_annotations.test b/qpdf/qtest/flatten_annotations.test deleted file mode 100644 index 700ed226..00000000 --- a/qpdf/qtest/flatten_annotations.test +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('flatten_annotations'); - -my $n_tests = 0; - -# manual-appearances was created by hand-coding appearance streams -# with graphics that make it easy to test matrix calculations. The -# result of flattening the annotations was compared visually with -# okular. Some PDF viewers don't actually display the original version -# correctly. The pages are as follows: -# - page 1: normal -# - page 2: rotate 90 with /F 20 (NoRotate) -# - page 3: non-trivial matrix -# - page 4: non-trivial matrix, rotate -# - page 5: rotate 180 with /F 20 -# - page 6: rotate 90, /F 20, non-trivial matrix -# - page 7: flags: top is print, middle is screen, bottom is hidden -# - page 8: rotate 270 with /F 20 -# - page 9: normal -- available for additional testing -# -# form-filled-by-acrobat was filled in using the Acrobat Reader -# android app. One of its appearance streams is actually an image. -# -# need-appearances.pdf is based on field-types.pdf with manual edits -# to turn on NeedAppearances, change /V for several fields, and add -# the comment annotation from comment-annotation.pdf. The test output -# includes a flattened version of the comment annotation but not of -# the form fields. Changes: -# - field-types.pdf has /NeedAppearances true -# - text1: blank -> abc -# - r1: 1 -> 2 -# - list1: blank -> five -# - combolist1: blank -> pi -# - drop1: blank -> elephant -# - combodrop1: blank -> delta - -my @annotation_files = ( - 'manual-appearances', - 'form-filled-by-acrobat', - 'comment-annotation', - 'comment-annotation-direct', - 'sample-form', - 'need-appearances', - 'need-appearances-more', - ); -$n_tests += 2 * scalar(@annotation_files); - -foreach my $f (@annotation_files) -{ - my $exp_out = {$td->STRING => "", $td->EXIT_STATUS => 0}; - if (-f "$f-warn.out") - { - $exp_out = {$td->FILE => "$f-warn.out", $td->EXIT_STATUS => 3}; - } - $td->runtest("flatten $f", - {$td->COMMAND => - "qpdf --qdf --static-id --no-original-object-ids" . - " --flatten-annotations=all $f.pdf a.pdf"}, - $exp_out, - $td->NORMALIZE_NEWLINES); - $td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "$f-out.pdf"}); -} - -$n_tests += 4; -foreach my $f (qw(screen print)) -{ - $td->runtest("flatten for $f", - {$td->COMMAND => - "qpdf --qdf --static-id --no-original-object-ids" . - " --flatten-annotations=$f manual-appearances.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "manual-appearances-$f-out.pdf"}); -} - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/form-xobject.test b/qpdf/qtest/form-xobject.test new file mode 100644 index 00000000..3183a219 --- /dev/null +++ b/qpdf/qtest/form-xobject.test @@ -0,0 +1,101 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('form-xobject'); + +my $n_tests = 22; + +$td->runtest("form xobject creation", + {$td->COMMAND => "test_driver 55 fxo-red.pdf"}, + {$td->STRING => "test 55 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("compare files", + {$td->FILE => "a.pdf"}, + {$td->FILE => "form-xobjects-out.pdf"}); +foreach (my $i = 56; $i <= 59; ++$i) +{ + # See comments in test_driver.cc for a verbal description of what + # the resulting files should look like. + $td->runtest("overlay transformations", + {$td->COMMAND => "test_driver $i fxo-red.pdf fxo-blue.pdf"}, + {$td->STRING => "test $i done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("compare files", + {$td->FILE => "a.pdf"}, + {$td->FILE => "fx-overlay-$i.pdf"}); +} +foreach (my $i = 64; $i <= 67; ++$i) +{ + # See comments in test_driver.cc for a verbal description of what + # the resulting files should look like. + $td->runtest("overlay shrink/expand", + {$td->COMMAND => + "test_driver $i fxo-bigsmall.pdf fxo-smallbig.pdf"}, + {$td->STRING => "test $i done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("compare files", + {$td->FILE => "a.pdf"}, + {$td->FILE => "fx-overlay-$i.pdf"}); +} + +my @uo_cases = ( + '--underlay fxo-green.pdf --repeat=z --to=1-14 --' . + ' --overlay fxo-blue.pdf --', # 1 + '--overlay fxo-green.pdf --from= --repeat=r2,r1 --' . + ' --underlay fxo-blue.pdf --from=z-1 --', # 2 + '--overlay fxo-green.pdf --from= --repeat=r2,r1 --' . + ' --underlay fxo-blue.pdf --from=z-1 -- --coalesce-contents', # 3 + '--overlay fxo-green.pdf --', # 4 + '--underlay fxo-green.pdf --to=3-7 --', # 5 + '--overlay fxo-blue.pdf --to=1,1,1,1 --from=1-4 --' . + ' --pages . 1 --', #6 + '--overlay 20-pages.pdf --password=user --', #7 + ); +$n_tests += 2 * scalar(@uo_cases); +for (my $i = 1; $i <= scalar(@uo_cases); ++$i) +{ + my $args = $uo_cases[$i-1]; + my $outbase = "uo-$i"; + $td->runtest("overlay/underlay $i", + {$td->COMMAND => + "qpdf --static-id --qdf --no-original-object-ids" . + " --verbose fxo-red.pdf a.pdf $args"}, + {$td->FILE => "$outbase.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("compare files", + {$td->FILE => "a.pdf"}, + {$td->FILE => "$outbase.pdf"}); +} +$td->runtest("foreach", + {$td->COMMAND => "test_driver 71 nested-form-xobjects.pdf"}, + {$td->FILE => "nested-form-xobjects.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("page operations on form xobject", + {$td->COMMAND => "test_driver 72 nested-form-xobjects.pdf"}, + {$td->FILE => "page-ops-on-form-xobject.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("overlay on page with no resources", + {$td->COMMAND => + "qpdf --deterministic-id page-with-no-resources.pdf" . + " --overlay minimal.pdf -- a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check overlay with no resources output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "overlay-no-resources.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/form_xobject.test b/qpdf/qtest/form_xobject.test deleted file mode 100644 index 2f5817b6..00000000 --- a/qpdf/qtest/form_xobject.test +++ /dev/null @@ -1,101 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('form_xobject'); - -my $n_tests = 22; - -$td->runtest("form xobject creation", - {$td->COMMAND => "test_driver 55 fxo-red.pdf"}, - {$td->STRING => "test 55 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("compare files", - {$td->FILE => "a.pdf"}, - {$td->FILE => "form-xobjects-out.pdf"}); -foreach (my $i = 56; $i <= 59; ++$i) -{ - # See comments in test_driver.cc for a verbal description of what - # the resulting files should look like. - $td->runtest("overlay transformations", - {$td->COMMAND => "test_driver $i fxo-red.pdf fxo-blue.pdf"}, - {$td->STRING => "test $i done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("compare files", - {$td->FILE => "a.pdf"}, - {$td->FILE => "fx-overlay-$i.pdf"}); -} -foreach (my $i = 64; $i <= 67; ++$i) -{ - # See comments in test_driver.cc for a verbal description of what - # the resulting files should look like. - $td->runtest("overlay shrink/expand", - {$td->COMMAND => - "test_driver $i fxo-bigsmall.pdf fxo-smallbig.pdf"}, - {$td->STRING => "test $i done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("compare files", - {$td->FILE => "a.pdf"}, - {$td->FILE => "fx-overlay-$i.pdf"}); -} - -my @uo_cases = ( - '--underlay fxo-green.pdf --repeat=z --to=1-14 --' . - ' --overlay fxo-blue.pdf --', # 1 - '--overlay fxo-green.pdf --from= --repeat=r2,r1 --' . - ' --underlay fxo-blue.pdf --from=z-1 --', # 2 - '--overlay fxo-green.pdf --from= --repeat=r2,r1 --' . - ' --underlay fxo-blue.pdf --from=z-1 -- --coalesce-contents', # 3 - '--overlay fxo-green.pdf --', # 4 - '--underlay fxo-green.pdf --to=3-7 --', # 5 - '--overlay fxo-blue.pdf --to=1,1,1,1 --from=1-4 --' . - ' --pages . 1 --', #6 - '--overlay 20-pages.pdf --password=user --', #7 - ); -$n_tests += 2 * scalar(@uo_cases); -for (my $i = 1; $i <= scalar(@uo_cases); ++$i) -{ - my $args = $uo_cases[$i-1]; - my $outbase = "uo-$i"; - $td->runtest("overlay/underlay $i", - {$td->COMMAND => - "qpdf --static-id --qdf --no-original-object-ids" . - " --verbose fxo-red.pdf a.pdf $args"}, - {$td->FILE => "$outbase.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("compare files", - {$td->FILE => "a.pdf"}, - {$td->FILE => "$outbase.pdf"}); -} -$td->runtest("foreach", - {$td->COMMAND => "test_driver 71 nested-form-xobjects.pdf"}, - {$td->FILE => "nested-form-xobjects.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("page operations on form xobject", - {$td->COMMAND => "test_driver 72 nested-form-xobjects.pdf"}, - {$td->FILE => "page-ops-on-form-xobject.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("overlay on page with no resources", - {$td->COMMAND => - "qpdf --deterministic-id page-with-no-resources.pdf" . - " --overlay minimal.pdf -- a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check overlay with no resources output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "overlay-no-resources.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/from-scratch.test b/qpdf/qtest/from-scratch.test new file mode 100644 index 00000000..94120528 --- /dev/null +++ b/qpdf/qtest/from-scratch.test @@ -0,0 +1,27 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('from-scratch'); + +my $n_tests = 2; + +$td->runtest("basic qpdf from scratch", + {$td->COMMAND => "pdf_from_scratch 0"}, + {$td->STRING => "test 0 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "from-scratch-0.pdf"}); +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/from_scratch.test b/qpdf/qtest/from_scratch.test deleted file mode 100644 index 2bb097df..00000000 --- a/qpdf/qtest/from_scratch.test +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('from_scratch'); - -my $n_tests = 2; - -$td->runtest("basic qpdf from scratch", - {$td->COMMAND => "pdf_from_scratch 0"}, - {$td->STRING => "test 0 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "from-scratch-0.pdf"}); -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/get-xref.test b/qpdf/qtest/get-xref.test new file mode 100644 index 00000000..23411109 --- /dev/null +++ b/qpdf/qtest/get-xref.test @@ -0,0 +1,32 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('get-xref'); + +my $n_tests = 2; + +$td->runtest("without object streams", + {$td->COMMAND => "test_xref minimal.pdf"}, + {$td->FILE => "minimal-xref.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("with object streams", + {$td->COMMAND => "test_xref digitally-signed.pdf"}, + {$td->FILE => "digitally-signed-xref.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/get_xref.test b/qpdf/qtest/get_xref.test deleted file mode 100644 index dc7432d4..00000000 --- a/qpdf/qtest/get_xref.test +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('get_xref'); - -my $n_tests = 2; - -$td->runtest("without object streams", - {$td->COMMAND => "test_xref minimal.pdf"}, - {$td->FILE => "minimal-xref.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("with object streams", - {$td->COMMAND => "test_xref digitally-signed.pdf"}, - {$td->FILE => "digitally-signed-xref.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/image-optimization.test b/qpdf/qtest/image-optimization.test new file mode 100644 index 00000000..1b3901e6 --- /dev/null +++ b/qpdf/qtest/image-optimization.test @@ -0,0 +1,60 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('image-optimization'); + +my @image_opt = ( + ['image-streams', 'image-streams', ''], + ['small-images', 'defaults', ''], + ['small-images', 'min-width', + '--oi-min-width=150 --oi-min-height=0 --oi-min-area=0'], + ['small-images', 'min-height', + '--oi-min-width=0 --oi-min-height=150 --oi-min-area=0'], + ['small-images', 'min-area', + '--oi-min-width=0 --oi-min-height=0 --oi-min-area=30000'], + ['small-images', 'min-area-all', + '--oi-min-width=0 --oi-min-height=0 --oi-min-area=30000'], + ['large-inline-image', 'inline-images', + '--ii-min-bytes=0'], + ['large-inline-image', 'inline-images-all-size', + '--oi-min-width=0 --oi-min-height=0 --oi-min-area=0 --ii-min-bytes=0'], + ['large-inline-image', 'inline-images-keep-some', ''], + ['large-inline-image', 'inline-images-keep-all', '--keep-inline-images'], + ['unsupported-optimization', 'unsupported', + '--oi-min-width=0 --oi-min-height=0 --oi-min-area=0'], + ); + +my $n_tests = 2 * scalar(@image_opt); + +foreach my $d (@image_opt) +{ + my ($f, $description, $args) = @$d; + + $td->runtest("optimize images: $description", + {$td->COMMAND => + "qpdf --static-id --optimize-images --verbose" . + " $args $f.pdf a.pdf", + $td->FILTER => "perl filter-optimize-images.pl"}, + {$td->FILE => "optimize-images-$description.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("check json: $description", + {$td->COMMAND => "qpdf --json --json-key=pages a.pdf"}, + {$td->FILE => "optimize-images-$description-json.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +} + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/image_optimization.test b/qpdf/qtest/image_optimization.test deleted file mode 100644 index a4671bf6..00000000 --- a/qpdf/qtest/image_optimization.test +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('image_optimization'); - -my @image_opt = ( - ['image-streams', 'image-streams', ''], - ['small-images', 'defaults', ''], - ['small-images', 'min-width', - '--oi-min-width=150 --oi-min-height=0 --oi-min-area=0'], - ['small-images', 'min-height', - '--oi-min-width=0 --oi-min-height=150 --oi-min-area=0'], - ['small-images', 'min-area', - '--oi-min-width=0 --oi-min-height=0 --oi-min-area=30000'], - ['small-images', 'min-area-all', - '--oi-min-width=0 --oi-min-height=0 --oi-min-area=30000'], - ['large-inline-image', 'inline-images', - '--ii-min-bytes=0'], - ['large-inline-image', 'inline-images-all-size', - '--oi-min-width=0 --oi-min-height=0 --oi-min-area=0 --ii-min-bytes=0'], - ['large-inline-image', 'inline-images-keep-some', ''], - ['large-inline-image', 'inline-images-keep-all', '--keep-inline-images'], - ['unsupported-optimization', 'unsupported', - '--oi-min-width=0 --oi-min-height=0 --oi-min-area=0'], - ); - -my $n_tests = 2 * scalar(@image_opt); - -foreach my $d (@image_opt) -{ - my ($f, $description, $args) = @$d; - - $td->runtest("optimize images: $description", - {$td->COMMAND => - "qpdf --static-id --optimize-images --verbose" . - " $args $f.pdf a.pdf", - $td->FILTER => "perl filter-optimize-images.pl"}, - {$td->FILE => "optimize-images-$description.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("check json: $description", - {$td->COMMAND => "qpdf --json --json-key=pages a.pdf"}, - {$td->FILE => "optimize-images-$description-json.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -} - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/inline-images.test b/qpdf/qtest/inline-images.test new file mode 100644 index 00000000..c8552ab3 --- /dev/null +++ b/qpdf/qtest/inline-images.test @@ -0,0 +1,110 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; +use Digest::MD5; +use File::Copy; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('inline-images'); + +my $n_compare_pdfs = 0; +my $n_tests = 10; + +# The file large-inline-image.pdf is a hand-crafted file with several +# inline images of various sizes including one that is two megabytes, +# encoded in base85, and has a base85-encoding that contains EI +# surrounded by delimiters several times. This exercises the EI +# detection code added in qpdf 8.4. + +$td->runtest("complex inline image parsing", + {$td->COMMAND => + "qpdf --qdf --static-id large-inline-image.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "large-inline-image.qdf"}); + +$td->runtest("eof in inline image", + {$td->COMMAND => + "qpdf --qdf --static-id eof-in-inline-image.pdf a.pdf"}, + {$td->FILE => "eof-inline-qdf.out", $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "eof-in-inline-image.qdf"}); +$td->runtest("externalize eof in inline image", + {$td->COMMAND => + "qpdf --qdf --externalize-inline-images" . + " --static-id eof-in-inline-image.pdf a.pdf"}, + {$td->FILE => "eof-inline-qdf.out", $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "eof-in-inline-image-ii.qdf"}); +$td->runtest("externalize damaged image", + {$td->COMMAND => + "qpdf --externalize-inline-images" . + " --compress-streams=n --static-id" . + " damaged-inline-image.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "damaged-inline-image-out.pdf"}); +$td->runtest("named colorspace", + {$td->COMMAND => + "qpdf --static-id --externalize-inline-images" . + " --ii-min-bytes=0 inline-image-colorspace-lookup.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "inline-image-colorspace-lookup-out.pdf"}); + + +my @eii_tests = ( + ['inline-images', 80], + ['large-inline-image', 1024], + ['nested-form-xobjects-inline-images', 20], + ); +$n_tests += 4 * scalar(@eii_tests); +$n_compare_pdfs += 2 * scalar(@eii_tests); + +foreach my $d (@eii_tests) +{ + my ($file, $threshold) = @$d; + $td->runtest("inline image $file (all)", + {$td->COMMAND => + "qpdf --qdf --static-id --externalize-inline-images" . + " --ii-min-bytes=0 $file.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "$file-ii-all.pdf"}); + compare_pdfs($td, "$file.pdf", "a.pdf"); + + $td->runtest("inline image $file (some)", + {$td->COMMAND => + "qpdf --qdf --static-id --externalize-inline-images" . + " --ii-min-bytes=$threshold $file.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "$file-ii-some.pdf"}); + compare_pdfs($td, "$file.pdf", "a.pdf"); +} + +cleanup(); +$td->report(calc_ntests($n_tests, $n_compare_pdfs)); diff --git a/qpdf/qtest/inline_images.test b/qpdf/qtest/inline_images.test deleted file mode 100644 index b868f748..00000000 --- a/qpdf/qtest/inline_images.test +++ /dev/null @@ -1,110 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; -use Digest::MD5; -use File::Copy; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('inline_images'); - -my $n_compare_pdfs = 0; -my $n_tests = 10; - -# The file large-inline-image.pdf is a hand-crafted file with several -# inline images of various sizes including one that is two megabytes, -# encoded in base85, and has a base85-encoding that contains EI -# surrounded by delimiters several times. This exercises the EI -# detection code added in qpdf 8.4. - -$td->runtest("complex inline image parsing", - {$td->COMMAND => - "qpdf --qdf --static-id large-inline-image.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "large-inline-image.qdf"}); - -$td->runtest("eof in inline image", - {$td->COMMAND => - "qpdf --qdf --static-id eof-in-inline-image.pdf a.pdf"}, - {$td->FILE => "eof-inline-qdf.out", $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "eof-in-inline-image.qdf"}); -$td->runtest("externalize eof in inline image", - {$td->COMMAND => - "qpdf --qdf --externalize-inline-images" . - " --static-id eof-in-inline-image.pdf a.pdf"}, - {$td->FILE => "eof-inline-qdf.out", $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "eof-in-inline-image-ii.qdf"}); -$td->runtest("externalize damaged image", - {$td->COMMAND => - "qpdf --externalize-inline-images" . - " --compress-streams=n --static-id" . - " damaged-inline-image.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "damaged-inline-image-out.pdf"}); -$td->runtest("named colorspace", - {$td->COMMAND => - "qpdf --static-id --externalize-inline-images" . - " --ii-min-bytes=0 inline-image-colorspace-lookup.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "inline-image-colorspace-lookup-out.pdf"}); - - -my @eii_tests = ( - ['inline-images', 80], - ['large-inline-image', 1024], - ['nested-form-xobjects-inline-images', 20], - ); -$n_tests += 4 * scalar(@eii_tests); -$n_compare_pdfs += 2 * scalar(@eii_tests); - -foreach my $d (@eii_tests) -{ - my ($file, $threshold) = @$d; - $td->runtest("inline image $file (all)", - {$td->COMMAND => - "qpdf --qdf --static-id --externalize-inline-images" . - " --ii-min-bytes=0 $file.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "$file-ii-all.pdf"}); - compare_pdfs($td, "$file.pdf", "a.pdf"); - - $td->runtest("inline image $file (some)", - {$td->COMMAND => - "qpdf --qdf --static-id --externalize-inline-images" . - " --ii-min-bytes=$threshold $file.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "$file-ii-some.pdf"}); - compare_pdfs($td, "$file.pdf", "a.pdf"); -} - -cleanup(); -$td->report(calc_ntests($n_tests, $n_compare_pdfs)); diff --git a/qpdf/qtest/interactive-form.test b/qpdf/qtest/interactive-form.test new file mode 100644 index 00000000..59c4af66 --- /dev/null +++ b/qpdf/qtest/interactive-form.test @@ -0,0 +1,74 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('interactive-form'); + +my @form_tests = ( + 'minimal', + 'form-empty-from-odt', + 'form-mod1', + # Atril (MATE Document Viewer) 1.20.1 dumps appearance streams + # when modifying form fields, leaving /NeedAppearances true. + 'form-filled-with-atril', + 'form-bad-fields-array', + 'form-errors', + 'form-document-defaults', + ); + +my $n_tests = scalar(@form_tests) + 6; + +# Many of the form*.pdf files were created by converting the +# LibreOffice document storage/form.odt to PDF and then manually +# modifying the resulting PDF in various ways. That file would be good +# starting point for generation of more complex forms should that be +# required in the future. The file storage/form.pdf is a direct export +# from LibreOffice with no modifications. The files +# storage/field-types.odt and storage/field-types.pdf are the basis of +# field-types.pdf used elsewhere in the test suite. + +foreach my $f (@form_tests) +{ + $td->runtest("form test: $f", + {$td->COMMAND => "test_driver 43 $f.pdf"}, + {$td->FILE => "form-$f.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +} + +$td->runtest("fill fields", + {$td->COMMAND => "test_driver 44 form-no-need-appearances.pdf"}, + {$td->FILE => "form-no-need-appearances.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("compare files", + {$td->FILE => "a.pdf"}, + {$td->FILE => "form-no-need-appearances-filled.pdf"}); + +$td->runtest("button fields", + {$td->COMMAND => "test_driver 51 button-set.pdf"}, + {$td->FILE => "button-set.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("compare files", + {$td->FILE => "a.pdf"}, + {$td->FILE => "button-set-out.pdf"}); + +$td->runtest("broken button fields", + {$td->COMMAND => "test_driver 51 button-set-broken.pdf"}, + {$td->FILE => "button-set-broken.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("compare files", + {$td->FILE => "a.pdf"}, + {$td->FILE => "button-set-broken-out.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/interactive_form.test b/qpdf/qtest/interactive_form.test deleted file mode 100644 index 009f560b..00000000 --- a/qpdf/qtest/interactive_form.test +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('interactive_form'); - -my @form_tests = ( - 'minimal', - 'form-empty-from-odt', - 'form-mod1', - # Atril (MATE Document Viewer) 1.20.1 dumps appearance streams - # when modifying form fields, leaving /NeedAppearances true. - 'form-filled-with-atril', - 'form-bad-fields-array', - 'form-errors', - 'form-document-defaults', - ); - -my $n_tests = scalar(@form_tests) + 6; - -# Many of the form*.pdf files were created by converting the -# LibreOffice document storage/form.odt to PDF and then manually -# modifying the resulting PDF in various ways. That file would be good -# starting point for generation of more complex forms should that be -# required in the future. The file storage/form.pdf is a direct export -# from LibreOffice with no modifications. The files -# storage/field-types.odt and storage/field-types.pdf are the basis of -# field-types.pdf used elsewhere in the test suite. - -foreach my $f (@form_tests) -{ - $td->runtest("form test: $f", - {$td->COMMAND => "test_driver 43 $f.pdf"}, - {$td->FILE => "form-$f.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -} - -$td->runtest("fill fields", - {$td->COMMAND => "test_driver 44 form-no-need-appearances.pdf"}, - {$td->FILE => "form-no-need-appearances.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("compare files", - {$td->FILE => "a.pdf"}, - {$td->FILE => "form-no-need-appearances-filled.pdf"}); - -$td->runtest("button fields", - {$td->COMMAND => "test_driver 51 button-set.pdf"}, - {$td->FILE => "button-set.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("compare files", - {$td->FILE => "a.pdf"}, - {$td->FILE => "button-set-out.pdf"}); - -$td->runtest("broken button fields", - {$td->COMMAND => "test_driver 51 button-set-broken.pdf"}, - {$td->FILE => "button-set-broken.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("compare files", - {$td->FILE => "a.pdf"}, - {$td->FILE => "button-set-broken-out.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/invalid-objects.test b/qpdf/qtest/invalid-objects.test new file mode 100644 index 00000000..6491ccdb --- /dev/null +++ b/qpdf/qtest/invalid-objects.test @@ -0,0 +1,37 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('invalid-objects'); + +my $n_tests = 3; + +$td->runtest("closed input source", + {$td->COMMAND => "test_driver 73 minimal.pdf"}, + {$td->FILE => "test73.out", + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("empty object", + {$td->COMMAND => "qpdf -show-object=7,0 empty-object.pdf"}, + {$td->FILE => "empty-object.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("object with zero offset", + {$td->COMMAND => "qpdf --check zero-offset.pdf"}, + {$td->FILE => "zero-offset.out", $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/invalid_objects.test b/qpdf/qtest/invalid_objects.test deleted file mode 100644 index c7914501..00000000 --- a/qpdf/qtest/invalid_objects.test +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('invalid_objects'); - -my $n_tests = 3; - -$td->runtest("closed input source", - {$td->COMMAND => "test_driver 73 minimal.pdf"}, - {$td->FILE => "test73.out", - $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("empty object", - {$td->COMMAND => "qpdf -show-object=7,0 empty-object.pdf"}, - {$td->FILE => "empty-object.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("object with zero offset", - {$td->COMMAND => "qpdf --check zero-offset.pdf"}, - {$td->FILE => "zero-offset.out", $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/keep-files-open.test b/qpdf/qtest/keep-files-open.test new file mode 100644 index 00000000..7218312f --- /dev/null +++ b/qpdf/qtest/keep-files-open.test @@ -0,0 +1,60 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('keep-files-open'); + +my $n_tests = 4; + +{ # local scope + open(F, "; + close(F); + for (my $i = 1; $i <= 51; ++$i) + { + open(F, sprintf(">%03d-kfo.pdf", $i)) or die; + binmode F; + print F $content; + close(F); + } +} +$td->runtest("automatic disable keep files open", + {$td->COMMAND => + "qpdf --verbose --static-id --empty" . + " --keep-files-open-threshold=50" . + " --pages *kfo.pdf -- a.pdf"}, + {$td->FILE => "disable-kfo.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("don't disable keep files open", + {$td->COMMAND => + "qpdf --verbose --static-id --empty" . + " --pages 01*kfo.pdf -- a.pdf"}, + {$td->FILE => "enable-kfo.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("explict keep files open", + {$td->COMMAND => + "qpdf --verbose --static-id --keep-files-open=y --empty" . + " --pages 00?-kfo.pdf -- a.pdf"}, + {$td->FILE => "kfo-y.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("explicit keep files open = n", + {$td->COMMAND => + "qpdf --verbose --static-id --keep-files-open=n --empty" . + " --pages 00?-kfo.pdf -- a.pdf"}, + {$td->FILE => "kfo-n.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/keep_files_open.test b/qpdf/qtest/keep_files_open.test deleted file mode 100644 index 026e648f..00000000 --- a/qpdf/qtest/keep_files_open.test +++ /dev/null @@ -1,60 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('keep_files_open'); - -my $n_tests = 4; - -{ # local scope - open(F, "; - close(F); - for (my $i = 1; $i <= 51; ++$i) - { - open(F, sprintf(">%03d-kfo.pdf", $i)) or die; - binmode F; - print F $content; - close(F); - } -} -$td->runtest("automatic disable keep files open", - {$td->COMMAND => - "qpdf --verbose --static-id --empty" . - " --keep-files-open-threshold=50" . - " --pages *kfo.pdf -- a.pdf"}, - {$td->FILE => "disable-kfo.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("don't disable keep files open", - {$td->COMMAND => - "qpdf --verbose --static-id --empty" . - " --pages 01*kfo.pdf -- a.pdf"}, - {$td->FILE => "enable-kfo.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("explict keep files open", - {$td->COMMAND => - "qpdf --verbose --static-id --keep-files-open=y --empty" . - " --pages 00?-kfo.pdf -- a.pdf"}, - {$td->FILE => "kfo-y.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("explicit keep files open = n", - {$td->COMMAND => - "qpdf --verbose --static-id --keep-files-open=n --empty" . - " --pages 00?-kfo.pdf -- a.pdf"}, - {$td->FILE => "kfo-n.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/large-file.test b/qpdf/qtest/large-file.test new file mode 100644 index 00000000..855e7e14 --- /dev/null +++ b/qpdf/qtest/large-file.test @@ -0,0 +1,132 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('large-file'); + +my $large_file_test_path = $ENV{'QPDF_LARGE_FILE_TEST_PATH'} || undef; +if (defined($large_file_test_path)) +{ + $large_file_test_path = File::Spec->rel2abs($large_file_test_path); + $large_file_test_path =~ s!\\!/!g; +} + + +my $nlarge = 1; +if (defined $large_file_test_path) +{ + $nlarge = 2; +} +else +{ + $td->notify("--- Skipping tests on actual large files ---"); +} + +my $n_tests = $nlarge * 13; +for (my $large = 0; $large < $nlarge; ++$large) +{ + if ($large) + { + $td->notify("--- Running tests on actual large files ---"); + } + else + { + $td->notify("--- Running large file tests on small files ---"); + } + my $size = ($large ? "large" : "small"); + my $file = $large ? "$large_file_test_path/a.pdf" : "a.pdf"; + $td->runtest("write test file", + {$td->COMMAND => "test_large_file write $size '$file'"}, + {$td->FILE => "large_file.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("read test file", + {$td->COMMAND => "test_large_file read $size '$file'"}, + {$td->FILE => "large_file.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("check", + {$td->COMMAND => "qpdf --suppress-recovery --check '$file'", + $td->FILTER => "grep -v checking"}, + {$td->FILE => "large_file-check-normal.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + + for my $ostream (0, 1) + { + for my $linearize (0, 1) + { + if (($ostream == 0) && ($linearize == 0)) + { + # Original file has no object streams and is not linearized. + next; + } + my $args = ""; + my $omode = $ostream ? "generate" : "disable"; + my $lin = $linearize ? "--linearize" : ""; + my $newfile = "$file-new"; + + $td->runtest("transform: ostream=$ostream, linearize=$linearize", + {$td->COMMAND => + "qpdf --stream-data=preserve" . + " --object-streams=$omode" . + " $lin '$file' '$newfile'"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); + $td->runtest("read: ostream=$ostream, linearize=$linearize", + {$td->COMMAND => + "test_large_file read $size '$newfile'"}, + {$td->FILE => "large_file.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + my $check_out = + ($linearize + ? ($ostream + ? "large_file-check-ostream-linearized.out" + : "large_file-check-linearized.out") + : ($ostream + ? "large_file-check-ostream.out" + : "large_file-check-normal.out")); + $td->runtest("check: ostream=$ostream, linearize=$linearize", + {$td->COMMAND => + "qpdf --suppress-recovery --check '$newfile'", + $td->FILTER => "grep -v checking"}, + {$td->FILE => $check_out, $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + unlink $newfile; + } + } + + # Clobber xref + open(F, "+<$file") or die; + seek(F, -50, 2); + my $pos = tell F; + my $buf; + read(F, $buf, 50); + die unless $buf =~ m/^(.*startxref\n)\d+/s; + $pos += length($1); + seek(F, $pos, 0) or die; + print F "oops" or die; + close(F); + + my $cmd = +{$td->COMMAND => "test_large_file read $size '$file'"}; + if ($large) + { + $cmd->{$td->FILTER} = "sed -e 's,$large_file_test_path/,,'"; + } + $td->runtest("reconstruct xref table", + $cmd, + {$td->FILE => "large_file_xref_reconstruct.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + unlink $file; +} + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/large_file.test b/qpdf/qtest/large_file.test deleted file mode 100644 index 89598d3d..00000000 --- a/qpdf/qtest/large_file.test +++ /dev/null @@ -1,132 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('large_file'); - -my $large_file_test_path = $ENV{'QPDF_LARGE_FILE_TEST_PATH'} || undef; -if (defined($large_file_test_path)) -{ - $large_file_test_path = File::Spec->rel2abs($large_file_test_path); - $large_file_test_path =~ s!\\!/!g; -} - - -my $nlarge = 1; -if (defined $large_file_test_path) -{ - $nlarge = 2; -} -else -{ - $td->notify("--- Skipping tests on actual large files ---"); -} - -my $n_tests = $nlarge * 13; -for (my $large = 0; $large < $nlarge; ++$large) -{ - if ($large) - { - $td->notify("--- Running tests on actual large files ---"); - } - else - { - $td->notify("--- Running large file tests on small files ---"); - } - my $size = ($large ? "large" : "small"); - my $file = $large ? "$large_file_test_path/a.pdf" : "a.pdf"; - $td->runtest("write test file", - {$td->COMMAND => "test_large_file write $size '$file'"}, - {$td->FILE => "large_file.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("read test file", - {$td->COMMAND => "test_large_file read $size '$file'"}, - {$td->FILE => "large_file.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("check", - {$td->COMMAND => "qpdf --suppress-recovery --check '$file'", - $td->FILTER => "grep -v checking"}, - {$td->FILE => "large_file-check-normal.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - - for my $ostream (0, 1) - { - for my $linearize (0, 1) - { - if (($ostream == 0) && ($linearize == 0)) - { - # Original file has no object streams and is not linearized. - next; - } - my $args = ""; - my $omode = $ostream ? "generate" : "disable"; - my $lin = $linearize ? "--linearize" : ""; - my $newfile = "$file-new"; - - $td->runtest("transform: ostream=$ostream, linearize=$linearize", - {$td->COMMAND => - "qpdf --stream-data=preserve" . - " --object-streams=$omode" . - " $lin '$file' '$newfile'"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); - $td->runtest("read: ostream=$ostream, linearize=$linearize", - {$td->COMMAND => - "test_large_file read $size '$newfile'"}, - {$td->FILE => "large_file.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - my $check_out = - ($linearize - ? ($ostream - ? "large_file-check-ostream-linearized.out" - : "large_file-check-linearized.out") - : ($ostream - ? "large_file-check-ostream.out" - : "large_file-check-normal.out")); - $td->runtest("check: ostream=$ostream, linearize=$linearize", - {$td->COMMAND => - "qpdf --suppress-recovery --check '$newfile'", - $td->FILTER => "grep -v checking"}, - {$td->FILE => $check_out, $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - unlink $newfile; - } - } - - # Clobber xref - open(F, "+<$file") or die; - seek(F, -50, 2); - my $pos = tell F; - my $buf; - read(F, $buf, 50); - die unless $buf =~ m/^(.*startxref\n)\d+/s; - $pos += length($1); - seek(F, $pos, 0) or die; - print F "oops" or die; - close(F); - - my $cmd = +{$td->COMMAND => "test_large_file read $size '$file'"}; - if ($large) - { - $cmd->{$td->FILTER} = "sed -e 's,$large_file_test_path/,,'"; - } - $td->runtest("reconstruct xref table", - $cmd, - {$td->FILE => "large_file_xref_reconstruct.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - unlink $file; -} - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/library-version.test b/qpdf/qtest/library-version.test new file mode 100644 index 00000000..a01c0e3e --- /dev/null +++ b/qpdf/qtest/library-version.test @@ -0,0 +1,35 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('library-version'); + +my $n_tests = 3; + +$td->runtest("qpdf version", + {$td->COMMAND => "qpdf --version"}, + {$td->REGEXP => ".*qpdf version \\S+\n.*", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("qpdf copyright contains version too", + {$td->COMMAND => "qpdf --copyright"}, + {$td->REGEXP => "(?s)qpdf version \\S+\n.*Apache.*", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("C API: qpdf version", + {$td->COMMAND => "qpdf-ctest --version"}, + {$td->REGEXP => "qpdf-ctest version \\S+\n", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/library_version.test b/qpdf/qtest/library_version.test deleted file mode 100644 index 8651551b..00000000 --- a/qpdf/qtest/library_version.test +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('library_version'); - -my $n_tests = 3; - -$td->runtest("qpdf version", - {$td->COMMAND => "qpdf --version"}, - {$td->REGEXP => ".*qpdf version \\S+\n.*", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("qpdf copyright contains version too", - {$td->COMMAND => "qpdf --copyright"}, - {$td->REGEXP => "(?s)qpdf version \\S+\n.*Apache.*", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("C API: qpdf version", - {$td->COMMAND => "qpdf-ctest --version"}, - {$td->REGEXP => "qpdf-ctest version \\S+\n", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/linearize-pass1.test b/qpdf/qtest/linearize-pass1.test new file mode 100644 index 00000000..dfdd2d9b --- /dev/null +++ b/qpdf/qtest/linearize-pass1.test @@ -0,0 +1,31 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('linearize-pass1'); + +my $n_tests = 3; + +$td->runtest("linearize pass 1 file", + {$td->COMMAND => "qpdf --linearize --static-id" . + " --linearize-pass1=b.pdf minimal.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "minimal-linearized.pdf"}); +$td->runtest("check pass1 file", + {$td->FILE => "b.pdf"}, + {$td->FILE => "minimal-linearize-pass1.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/linearize_pass1.test b/qpdf/qtest/linearize_pass1.test deleted file mode 100644 index ed1695b9..00000000 --- a/qpdf/qtest/linearize_pass1.test +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('linearize_pass1'); - -my $n_tests = 3; - -$td->runtest("linearize pass 1 file", - {$td->COMMAND => "qpdf --linearize --static-id" . - " --linearize-pass1=b.pdf minimal.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "minimal-linearized.pdf"}); -$td->runtest("check pass1 file", - {$td->FILE => "b.pdf"}, - {$td->FILE => "minimal-linearize-pass1.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/merge-and-split.test b/qpdf/qtest/merge-and-split.test new file mode 100644 index 00000000..8de1f9da --- /dev/null +++ b/qpdf/qtest/merge-and-split.test @@ -0,0 +1,186 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('merge-and-split'); + +my $n_tests = 28; + +# Select pages from the same file multiple times including selecting +# twice from an encrypted file and specifying the password only the +# first time. The file 20-pages.pdf is specified with two different +# paths to duplicate a page. +my $pages_options = "--pages page-labels-and-outlines.pdf 1,3,5-7,z" . + " 20-pages.pdf --password=user z-15" . + " page-labels-and-outlines.pdf 12" . + " 20-pages.pdf 10" . + " ./20-pages.pdf --password=owner 10" . + " minimal.pdf 1 --"; + +$td->runtest("merge three files", + {$td->COMMAND => "qpdf page-labels-and-outlines.pdf a.pdf" . + " $pages_options --static-id --verbose --progress", + $td->FILTER => "perl filter-progress.pl"}, + {$td->FILE => "verbose-merge.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +# Manually verified about this file: make sure that outline entries +# that pointed to pages that were preserved still work in the copy, +# and verify that all pages are as expected. page-labels-and-outlines +# as well as 20-pages have text on page n (from 1) that shows its page +# position from 0, so page 1 says it's page 0. +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "merge-three-files-1.pdf"}); +# Select the same pages but add them to an empty file +$td->runtest("merge three files", + {$td->COMMAND => "qpdf --empty a.pdf" . + " $pages_options --static-id"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +# Manually verified about this file: it has the same pages but does +# not contain outlines or other things from the original file. +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "merge-three-files-2.pdf"}); +$td->runtest("avoid respecification of password", + {$td->COMMAND => + "qpdf --empty a.pdf --copy-encryption=20-pages.pdf" . + " --allow-weak-crypto" . + " --encryption-file-password=user" . + " --pages 20-pages.pdf 1,z -- --static-id"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "pages-copy-encryption.pdf"}); +$td->runtest("merge with implicit ranges", + {$td->COMMAND => + "qpdf --empty a.pdf" . + " --pages minimal.pdf 20-pages.pdf --password=user" . + " page-labels-and-outlines.pdf --" . + " --static-id"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "merge-implicit-ranges.pdf"}); +$td->runtest("merge with . and implicit ranges", + {$td->COMMAND => + "qpdf minimal.pdf a.pdf --pages minimal.pdf . 1 --" . + " --static-id"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "merge-dot-implicit-ranges.pdf"}); +$td->runtest("merge with multiple labels", + {$td->COMMAND => + "qpdf --empty a.pdf" . + " --pages 11-pages-with-labels.pdf 8-11" . + " minimal.pdf " . + " page-labels-and-outlines.pdf 17-19 --" . + " --static-id"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "merge-multiple-labels.pdf"}); +$td->runtest("remove labels", + {$td->COMMAND => + "qpdf --empty a.pdf" . + " --remove-page-labels" . + " --pages 11-pages-with-labels.pdf 8-11" . + " minimal.pdf " . + " page-labels-and-outlines.pdf 17-19 --" . + " --static-id"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "remove-labels.pdf"}); + +$td->runtest("split with shared resources", + {$td->COMMAND => + "qpdf --qdf --static-id" . + " --remove-unreferenced-resources=yes" . + " shared-images.pdf --pages . 1,3" . + " ./shared-images.pdf 1,2 -- a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "shared-images-pages-out.pdf"}); + +$td->runtest("split with really shared resources", + {$td->COMMAND => + "qpdf --qdf --static-id" . + " --remove-unreferenced-resources=yes" . + " shared-images.pdf --pages . 1,3" . + " . 1,2 -- a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "really-shared-images-pages-out.pdf"}); + +$td->runtest("shared resources relevant errors", + {$td->COMMAND => + "qpdf --qdf --static-id" . + " shared-images-errors.pdf --pages . 2 -- a.pdf"}, + {$td->FILE => "shared-images-errors-2.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "shared-images-errors-2-out.pdf"}); + +# This test used to generate warnings about images on pages we didn't +# care about, but qpdf was modified not to process those pages, so the +# "irrelevant" errors went away. +$td->runtest("shared resources irrelevant errors", + {$td->COMMAND => + "qpdf --qdf --static-id" . + " shared-images-errors.pdf --pages . 1 -- a.pdf"}, + {$td->STRING => "", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "shared-images-errors-1-out.pdf"}); + +$td->runtest("don't remove shared resources", + {$td->COMMAND => + "qpdf --qdf --static-id --preserve-unreferenced-resources" . + " shared-images.pdf --pages . 1,3 -- a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "shared-images-errors-1-3-out.pdf"}); + +$td->runtest("duplicate pages", + {$td->COMMAND => + "qpdf --qdf --static-id 11-pages-with-labels.pdf" . + " --pages . 6,5,6 . 5 minimal.pdf 1,1 minimal.pdf 1 --" . + " a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "duplicate-pages.pdf"}); + +# See https://github.com/qpdf/qpdf/issues/399 -- we don't want to +# break this, especially if we ever implement deduplication of +# identical streams. +$td->runtest("force full page duplication", + {$td->COMMAND => "qpdf --static-id minimal.pdf" . + " --pages . ./minimal.pdf -- a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "deep-duplicate-pages.pdf"}); + + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/merge-dictionary.test b/qpdf/qtest/merge-dictionary.test new file mode 100644 index 00000000..ef8dcdb2 --- /dev/null +++ b/qpdf/qtest/merge-dictionary.test @@ -0,0 +1,32 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('merge-dictionary'); + +my $n_tests = 3; + +$td->runtest("merge dictionary", + {$td->COMMAND => "test_driver 50 merge-dict.pdf"}, + {$td->FILE => "merge-dict.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("unique resource name", + {$td->COMMAND => "test_driver 60 minimal.pdf"}, + {$td->FILE => "test60.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "unique-resources.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/merge_and_split.test b/qpdf/qtest/merge_and_split.test deleted file mode 100644 index 6ffa2e66..00000000 --- a/qpdf/qtest/merge_and_split.test +++ /dev/null @@ -1,186 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('merge_and_split'); - -my $n_tests = 28; - -# Select pages from the same file multiple times including selecting -# twice from an encrypted file and specifying the password only the -# first time. The file 20-pages.pdf is specified with two different -# paths to duplicate a page. -my $pages_options = "--pages page-labels-and-outlines.pdf 1,3,5-7,z" . - " 20-pages.pdf --password=user z-15" . - " page-labels-and-outlines.pdf 12" . - " 20-pages.pdf 10" . - " ./20-pages.pdf --password=owner 10" . - " minimal.pdf 1 --"; - -$td->runtest("merge three files", - {$td->COMMAND => "qpdf page-labels-and-outlines.pdf a.pdf" . - " $pages_options --static-id --verbose --progress", - $td->FILTER => "perl filter-progress.pl"}, - {$td->FILE => "verbose-merge.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -# Manually verified about this file: make sure that outline entries -# that pointed to pages that were preserved still work in the copy, -# and verify that all pages are as expected. page-labels-and-outlines -# as well as 20-pages have text on page n (from 1) that shows its page -# position from 0, so page 1 says it's page 0. -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "merge-three-files-1.pdf"}); -# Select the same pages but add them to an empty file -$td->runtest("merge three files", - {$td->COMMAND => "qpdf --empty a.pdf" . - " $pages_options --static-id"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -# Manually verified about this file: it has the same pages but does -# not contain outlines or other things from the original file. -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "merge-three-files-2.pdf"}); -$td->runtest("avoid respecification of password", - {$td->COMMAND => - "qpdf --empty a.pdf --copy-encryption=20-pages.pdf" . - " --allow-weak-crypto" . - " --encryption-file-password=user" . - " --pages 20-pages.pdf 1,z -- --static-id"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "pages-copy-encryption.pdf"}); -$td->runtest("merge with implicit ranges", - {$td->COMMAND => - "qpdf --empty a.pdf" . - " --pages minimal.pdf 20-pages.pdf --password=user" . - " page-labels-and-outlines.pdf --" . - " --static-id"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "merge-implicit-ranges.pdf"}); -$td->runtest("merge with . and implicit ranges", - {$td->COMMAND => - "qpdf minimal.pdf a.pdf --pages minimal.pdf . 1 --" . - " --static-id"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "merge-dot-implicit-ranges.pdf"}); -$td->runtest("merge with multiple labels", - {$td->COMMAND => - "qpdf --empty a.pdf" . - " --pages 11-pages-with-labels.pdf 8-11" . - " minimal.pdf " . - " page-labels-and-outlines.pdf 17-19 --" . - " --static-id"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "merge-multiple-labels.pdf"}); -$td->runtest("remove labels", - {$td->COMMAND => - "qpdf --empty a.pdf" . - " --remove-page-labels" . - " --pages 11-pages-with-labels.pdf 8-11" . - " minimal.pdf " . - " page-labels-and-outlines.pdf 17-19 --" . - " --static-id"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "remove-labels.pdf"}); - -$td->runtest("split with shared resources", - {$td->COMMAND => - "qpdf --qdf --static-id" . - " --remove-unreferenced-resources=yes" . - " shared-images.pdf --pages . 1,3" . - " ./shared-images.pdf 1,2 -- a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "shared-images-pages-out.pdf"}); - -$td->runtest("split with really shared resources", - {$td->COMMAND => - "qpdf --qdf --static-id" . - " --remove-unreferenced-resources=yes" . - " shared-images.pdf --pages . 1,3" . - " . 1,2 -- a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "really-shared-images-pages-out.pdf"}); - -$td->runtest("shared resources relevant errors", - {$td->COMMAND => - "qpdf --qdf --static-id" . - " shared-images-errors.pdf --pages . 2 -- a.pdf"}, - {$td->FILE => "shared-images-errors-2.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "shared-images-errors-2-out.pdf"}); - -# This test used to generate warnings about images on pages we didn't -# care about, but qpdf was modified not to process those pages, so the -# "irrelevant" errors went away. -$td->runtest("shared resources irrelevant errors", - {$td->COMMAND => - "qpdf --qdf --static-id" . - " shared-images-errors.pdf --pages . 1 -- a.pdf"}, - {$td->STRING => "", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "shared-images-errors-1-out.pdf"}); - -$td->runtest("don't remove shared resources", - {$td->COMMAND => - "qpdf --qdf --static-id --preserve-unreferenced-resources" . - " shared-images.pdf --pages . 1,3 -- a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "shared-images-errors-1-3-out.pdf"}); - -$td->runtest("duplicate pages", - {$td->COMMAND => - "qpdf --qdf --static-id 11-pages-with-labels.pdf" . - " --pages . 6,5,6 . 5 minimal.pdf 1,1 minimal.pdf 1 --" . - " a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "duplicate-pages.pdf"}); - -# See https://github.com/qpdf/qpdf/issues/399 -- we don't want to -# break this, especially if we ever implement deduplication of -# identical streams. -$td->runtest("force full page duplication", - {$td->COMMAND => "qpdf --static-id minimal.pdf" . - " --pages . ./minimal.pdf -- a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "deep-duplicate-pages.pdf"}); - - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/merge_dictionary.test b/qpdf/qtest/merge_dictionary.test deleted file mode 100644 index 64d3ff77..00000000 --- a/qpdf/qtest/merge_dictionary.test +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('merge_dictionary'); - -my $n_tests = 3; - -$td->runtest("merge dictionary", - {$td->COMMAND => "test_driver 50 merge-dict.pdf"}, - {$td->FILE => "merge-dict.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("unique resource name", - {$td->COMMAND => "test_driver 60 minimal.pdf"}, - {$td->FILE => "test60.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "unique-resources.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/multiple-indirection.test b/qpdf/qtest/multiple-indirection.test new file mode 100644 index 00000000..3cceba15 --- /dev/null +++ b/qpdf/qtest/multiple-indirection.test @@ -0,0 +1,34 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('multiple-indirection'); + +my $n_tests = 2; + +# Handle file with object stream containing an unreferenced object +# that in turn contains an indirect scalar (bug 2974522). +$td->runtest("unreferenced indirect scalar", + {$td->COMMAND => + "qpdf --qdf --static-id --preserve-unreferenced" . + " --object-streams=preserve" . + " unreferenced-indirect-scalar.pdf a.qdf"}, + {$td->STRING => "", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.qdf"}, + {$td->FILE => "unreferenced-indirect-scalar.out"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/multiple_indirection.test b/qpdf/qtest/multiple_indirection.test deleted file mode 100644 index c77e1490..00000000 --- a/qpdf/qtest/multiple_indirection.test +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('multiple_indirection'); - -my $n_tests = 2; - -# Handle file with object stream containing an unreferenced object -# that in turn contains an indirect scalar (bug 2974522). -$td->runtest("unreferenced indirect scalar", - {$td->COMMAND => - "qpdf --qdf --static-id --preserve-unreferenced" . - " --object-streams=preserve" . - " unreferenced-indirect-scalar.pdf a.qdf"}, - {$td->STRING => "", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.qdf"}, - {$td->FILE => "unreferenced-indirect-scalar.out"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/name-normalization.test b/qpdf/qtest/name-normalization.test new file mode 100644 index 00000000..9d76f5c2 --- /dev/null +++ b/qpdf/qtest/name-normalization.test @@ -0,0 +1,52 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('name-normalization'); + +my $n_tests = 6; + +$td->runtest("check pound in name", + {$td->COMMAND => + "test_driver 1 pound-in-name.pdf"}, + {$td->FILE => "pound-in-name.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("convert pound in name", + {$td->COMMAND => "qpdf --static-id --qdf" . + " pound-in-name.pdf a.pdf"}, + {$td->FILE => "pound-in-name-qdf.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "pound-in-name.qdf"}); + +$td->runtest("check pound in image names", + {$td->COMMAND => + "qpdf --check name-pound-images.pdf"}, + {$td->FILE => "name-pound-images.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("convert pound in image names", + {$td->COMMAND => "qpdf --static-id --qdf" . + " name-pound-images.pdf a.pdf"}, + {$td->FILE => "name-pound-images-qdf.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "name-pound-images.qdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/name-number-trees.test b/qpdf/qtest/name-number-trees.test new file mode 100644 index 00000000..8e6a559e --- /dev/null +++ b/qpdf/qtest/name-number-trees.test @@ -0,0 +1,43 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('name-number-trees'); + +my $n_tests = 6; + +$td->runtest("number trees", + {$td->COMMAND => "test_driver 46 number-tree.pdf"}, + {$td->FILE => "number-tree.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("name trees", + {$td->COMMAND => "test_driver 48 name-tree.pdf"}, + {$td->FILE => "name-tree.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("nntree split", + {$td->COMMAND => "test_driver 74 split-nntree.pdf"}, + {$td->FILE => "split-nntree.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check file", + {$td->FILE => "a.pdf"}, + {$td->FILE => "split-nntree-out.pdf"}); +$td->runtest("nntree erase", + {$td->COMMAND => "test_driver 75 erase-nntree.pdf"}, + {$td->FILE => "erase-nntree.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check file", + {$td->FILE => "a.pdf"}, + {$td->FILE => "erase-nntree-out.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/name_normalization.test b/qpdf/qtest/name_normalization.test deleted file mode 100644 index 72ad5bd8..00000000 --- a/qpdf/qtest/name_normalization.test +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('name_normalization'); - -my $n_tests = 6; - -$td->runtest("check pound in name", - {$td->COMMAND => - "test_driver 1 pound-in-name.pdf"}, - {$td->FILE => "pound-in-name.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("convert pound in name", - {$td->COMMAND => "qpdf --static-id --qdf" . - " pound-in-name.pdf a.pdf"}, - {$td->FILE => "pound-in-name-qdf.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "pound-in-name.qdf"}); - -$td->runtest("check pound in image names", - {$td->COMMAND => - "qpdf --check name-pound-images.pdf"}, - {$td->FILE => "name-pound-images.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("convert pound in image names", - {$td->COMMAND => "qpdf --static-id --qdf" . - " name-pound-images.pdf a.pdf"}, - {$td->FILE => "name-pound-images-qdf.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "name-pound-images.qdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/name_number_trees.test b/qpdf/qtest/name_number_trees.test deleted file mode 100644 index ae3fa7f5..00000000 --- a/qpdf/qtest/name_number_trees.test +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('name_number_trees'); - -my $n_tests = 6; - -$td->runtest("number trees", - {$td->COMMAND => "test_driver 46 number-tree.pdf"}, - {$td->FILE => "number-tree.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("name trees", - {$td->COMMAND => "test_driver 48 name-tree.pdf"}, - {$td->FILE => "name-tree.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("nntree split", - {$td->COMMAND => "test_driver 74 split-nntree.pdf"}, - {$td->FILE => "split-nntree.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check file", - {$td->FILE => "a.pdf"}, - {$td->FILE => "split-nntree-out.pdf"}); -$td->runtest("nntree erase", - {$td->COMMAND => "test_driver 75 erase-nntree.pdf"}, - {$td->FILE => "erase-nntree.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check file", - {$td->FILE => "a.pdf"}, - {$td->FILE => "erase-nntree-out.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/newline-before-endstream.test b/qpdf/qtest/newline-before-endstream.test new file mode 100644 index 00000000..667a0dd6 --- /dev/null +++ b/qpdf/qtest/newline-before-endstream.test @@ -0,0 +1,59 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('newline-before-endstream'); + +my $n_tests = 12; + +# From issue 133, http://verapdf.org/software/ is an open source +# package that can verify PDF/A compliance. This could potentially be +# useful for manual or automated verification that qpdf doesn't break +# PDF/A compliance should that ever be desired. + +foreach my $d ( + ['--qdf', 'qdf', 'qdf'], + ['--newline-before-endstream', 'newline', 'nl'], + ['--qdf --newline-before-endstream', 'newline and qdf', 'nl-qdf'], + ['--object-streams=generate --newline-before-endstream', + 'newline and object streams', 'nl-objstm'], + ) +{ + my ($flags, $description, $suffix) = @$d; + $td->runtest("newline before endstream: $description", + {$td->COMMAND => "qpdf --static-id --stream-data=preserve" . + " $flags streams-with-newlines.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("check output ($description)", + {$td->FILE => "a.pdf"}, + {$td->FILE => "newline-before-endstream-$suffix.pdf"}); + if ($flags =~ /qdf/) + { + $td->runtest("fix-qdf", + {$td->COMMAND => "fix-qdf a.pdf"}, + {$td->FILE => "a.pdf", $td->EXIT_STATUS => 0}); + } +} + +$td->runtest("newline before endstream (C)", + {$td->COMMAND => + "qpdf-ctest 22 streams-with-newlines.pdf '' a.pdf"}, + {$td->STRING => "C test 22 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "newline-before-endstream-nl.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/newline_before_endstream.test b/qpdf/qtest/newline_before_endstream.test deleted file mode 100644 index 7ac8d361..00000000 --- a/qpdf/qtest/newline_before_endstream.test +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('newline_before_endstream'); - -my $n_tests = 12; - -# From issue 133, http://verapdf.org/software/ is an open source -# package that can verify PDF/A compliance. This could potentially be -# useful for manual or automated verification that qpdf doesn't break -# PDF/A compliance should that ever be desired. - -foreach my $d ( - ['--qdf', 'qdf', 'qdf'], - ['--newline-before-endstream', 'newline', 'nl'], - ['--qdf --newline-before-endstream', 'newline and qdf', 'nl-qdf'], - ['--object-streams=generate --newline-before-endstream', - 'newline and object streams', 'nl-objstm'], - ) -{ - my ($flags, $description, $suffix) = @$d; - $td->runtest("newline before endstream: $description", - {$td->COMMAND => "qpdf --static-id --stream-data=preserve" . - " $flags streams-with-newlines.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("check output ($description)", - {$td->FILE => "a.pdf"}, - {$td->FILE => "newline-before-endstream-$suffix.pdf"}); - if ($flags =~ /qdf/) - { - $td->runtest("fix-qdf", - {$td->COMMAND => "fix-qdf a.pdf"}, - {$td->FILE => "a.pdf", $td->EXIT_STATUS => 0}); - } -} - -$td->runtest("newline before endstream (C)", - {$td->COMMAND => - "qpdf-ctest 22 streams-with-newlines.pdf '' a.pdf"}, - {$td->STRING => "C test 22 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "newline-before-endstream-nl.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/numbers-and-strings.test b/qpdf/qtest/numbers-and-strings.test new file mode 100644 index 00000000..8be5b997 --- /dev/null +++ b/qpdf/qtest/numbers-and-strings.test @@ -0,0 +1,29 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('numbers-and-strings'); + +my $n_tests = 3; + +foreach (my $i = 1; $i <= 3; ++$i) +{ + $td->runtest("numbers and strings", + {$td->COMMAND => "test_driver 5 numeric-and-string-$i.pdf"}, + {$td->FILE => "numeric-and-string-$i.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +} + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/numbers_and_strings.test b/qpdf/qtest/numbers_and_strings.test deleted file mode 100644 index 7f939460..00000000 --- a/qpdf/qtest/numbers_and_strings.test +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('numbers_and_strings'); - -my $n_tests = 3; - -foreach (my $i = 1; $i <= 3; ++$i) -{ - $td->runtest("numbers and strings", - {$td->COMMAND => "test_driver 5 numeric-and-string-$i.pdf"}, - {$td->FILE => "numeric-and-string-$i.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -} - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/object-copying.test b/qpdf/qtest/object-copying.test new file mode 100644 index 00000000..54d41b15 --- /dev/null +++ b/qpdf/qtest/object-copying.test @@ -0,0 +1,55 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('object-copying'); + +my $n_tests = 9; + +$td->runtest("shallow copy an array", + {$td->COMMAND => "test_driver 20 shallow_array.pdf"}, + {$td->STRING => "test 20 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "shallow_array-out.pdf"}); +$td->runtest("shallow copy a stream", + {$td->COMMAND => "test_driver 21 shallow_array.pdf"}, + {$td->FILE => "shallow_stream.out", $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); +$td->runtest("warn for unknown key in Pages", + {$td->COMMAND => "test_driver 23 lin-special.pdf"}, + {$td->FILE => "pages-warning.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("reserved objects", + {$td->COMMAND => "test_driver 24 minimal.pdf"}, + {$td->FILE => "reserved-objects.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "reserved-objects.pdf"}); +$td->runtest("detect foreign object in write", + {$td->COMMAND => "test_driver 29" . + " copy-foreign-objects-in.pdf minimal.pdf"}, + {$td->FILE => "foreign-in-write.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("copy a stream", + {$td->COMMAND => "test_driver 79 minimal.pdf"}, + {$td->STRING => "test 79 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "test79.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/object-handle-api.test b/qpdf/qtest/object-handle-api.test new file mode 100644 index 00000000..3de5f909 --- /dev/null +++ b/qpdf/qtest/object-handle-api.test @@ -0,0 +1,29 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('object-handle-api'); + +my $n_tests = 2; + +$td->runtest("dictionary keys", + {$td->COMMAND => "test_driver 87 - -"}, + {$td->STRING => "test 87 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("fluent interfaces", + {$td->COMMAND => "test_driver 88 minimal.pdf -"}, + {$td->FILE => "test88.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/object-stream.test b/qpdf/qtest/object-stream.test new file mode 100644 index 00000000..04d1bb0d --- /dev/null +++ b/qpdf/qtest/object-stream.test @@ -0,0 +1,91 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; +use Digest::MD5; +use File::Copy; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('object-stream'); + +my $n_tests = 3 + (36 * 4) + (12 * 2); +my $n_compare_pdfs = 36; + +for (my $n = 16; $n <= 19; ++$n) +{ + my $in = "good$n.pdf"; + foreach my $flags ('-object-streams=disable', + '-object-streams=preserve', + '-object-streams=generate') + { + foreach my $qdf ('-qdf', '', '-allow-weak-crypto -encrypt "" x 128 --') + { + # 4 tests + 1 compare_pdfs * 36 cases + # 2 additional tests * 12 cases + $td->runtest("object stream mode", + {$td->COMMAND => + "qpdf --static-id $flags $qdf $in a.pdf"}, + {$td->STRING => "", + $td->EXIT_STATUS => 0}); + compare_pdfs($td, "good$n.pdf", "a.pdf"); + if ($qdf eq '-qdf') + { + $td->runtest("fix-qdf identity check", + {$td->COMMAND => "fix-qdf a.pdf >| b.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); + $td->runtest("compare files", + {$td->FILE => "a.pdf"}, + {$td->FILE => "b.pdf"}); + } + $td->runtest("convert to qdf", + {$td->COMMAND => + "qpdf --static-id --no-original-object-ids" . + " -qdf -decrypt" . + " -object-streams=disable $in a.qdf"}, + {$td->STRING => "", + $td->EXIT_STATUS => 0}); + $td->runtest("convert output to qdf", + {$td->COMMAND => + "qpdf --static-id --no-original-object-ids" . + " -qdf -object-streams=disable a.pdf b.qdf"}, + {$td->STRING => "", + $td->EXIT_STATUS => 0}); + $td->runtest("compare files", + {$td->FILE => "a.qdf"}, + {$td->FILE => "b.qdf"}); + } + } + flush_tiff_cache(); +} + +# The file override-compressed-object.pdf contains an object stream +# with four strings in it. The file is then appended. The appended +# section overrides one of the four strings with a string in another +# object stream and another one in an uncompressed object. The other +# two strings are left alone. The test case exercises that all four +# objects have the correct value. +$td->runtest("overridden compressed objects", + {$td->COMMAND => "test_driver 38 override-compressed-object.pdf"}, + {$td->FILE => "override-compressed-object.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("generate object streams for gen > 0", + {$td->COMMAND => "qpdf --qdf --static-id" . + " --object-streams=generate gen1.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check file", + {$td->FILE => "a.pdf"}, + {$td->FILE => "gen1.qdf"}); + + +cleanup(); +$td->report(calc_ntests($n_tests, $n_compare_pdfs)); diff --git a/qpdf/qtest/object_copying.test b/qpdf/qtest/object_copying.test deleted file mode 100644 index 88bdf29a..00000000 --- a/qpdf/qtest/object_copying.test +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('object_copying'); - -my $n_tests = 9; - -$td->runtest("shallow copy an array", - {$td->COMMAND => "test_driver 20 shallow_array.pdf"}, - {$td->STRING => "test 20 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "shallow_array-out.pdf"}); -$td->runtest("shallow copy a stream", - {$td->COMMAND => "test_driver 21 shallow_array.pdf"}, - {$td->FILE => "shallow_stream.out", $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); -$td->runtest("warn for unknown key in Pages", - {$td->COMMAND => "test_driver 23 lin-special.pdf"}, - {$td->FILE => "pages-warning.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("reserved objects", - {$td->COMMAND => "test_driver 24 minimal.pdf"}, - {$td->FILE => "reserved-objects.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "reserved-objects.pdf"}); -$td->runtest("detect foreign object in write", - {$td->COMMAND => "test_driver 29" . - " copy-foreign-objects-in.pdf minimal.pdf"}, - {$td->FILE => "foreign-in-write.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("copy a stream", - {$td->COMMAND => "test_driver 79 minimal.pdf"}, - {$td->STRING => "test 79 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "test79.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/object_handle_api.test b/qpdf/qtest/object_handle_api.test deleted file mode 100644 index e8c5bf6c..00000000 --- a/qpdf/qtest/object_handle_api.test +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('object_handle_api'); - -my $n_tests = 2; - -$td->runtest("dictionary keys", - {$td->COMMAND => "test_driver 87 - -"}, - {$td->STRING => "test 87 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("fluent interfaces", - {$td->COMMAND => "test_driver 88 minimal.pdf -"}, - {$td->FILE => "test88.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/object_stream.test b/qpdf/qtest/object_stream.test deleted file mode 100644 index d207944c..00000000 --- a/qpdf/qtest/object_stream.test +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; -use Digest::MD5; -use File::Copy; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('object_stream'); - -my $n_tests = 3 + (36 * 4) + (12 * 2); -my $n_compare_pdfs = 36; - -for (my $n = 16; $n <= 19; ++$n) -{ - my $in = "good$n.pdf"; - foreach my $flags ('-object-streams=disable', - '-object-streams=preserve', - '-object-streams=generate') - { - foreach my $qdf ('-qdf', '', '-allow-weak-crypto -encrypt "" x 128 --') - { - # 4 tests + 1 compare_pdfs * 36 cases - # 2 additional tests * 12 cases - $td->runtest("object stream mode", - {$td->COMMAND => - "qpdf --static-id $flags $qdf $in a.pdf"}, - {$td->STRING => "", - $td->EXIT_STATUS => 0}); - compare_pdfs($td, "good$n.pdf", "a.pdf"); - if ($qdf eq '-qdf') - { - $td->runtest("fix-qdf identity check", - {$td->COMMAND => "fix-qdf a.pdf >| b.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); - $td->runtest("compare files", - {$td->FILE => "a.pdf"}, - {$td->FILE => "b.pdf"}); - } - $td->runtest("convert to qdf", - {$td->COMMAND => - "qpdf --static-id --no-original-object-ids" . - " -qdf -decrypt" . - " -object-streams=disable $in a.qdf"}, - {$td->STRING => "", - $td->EXIT_STATUS => 0}); - $td->runtest("convert output to qdf", - {$td->COMMAND => - "qpdf --static-id --no-original-object-ids" . - " -qdf -object-streams=disable a.pdf b.qdf"}, - {$td->STRING => "", - $td->EXIT_STATUS => 0}); - $td->runtest("compare files", - {$td->FILE => "a.qdf"}, - {$td->FILE => "b.qdf"}); - } - } - flush_tiff_cache(); -} - -# The file override-compressed-object.pdf contains an object stream -# with four strings in it. The file is then appended. The appended -# section overrides one of the four strings with a string in another -# object stream and another one in an uncompressed object. The other -# two strings are left alone. The test case exercises that all four -# objects have the correct value. -$td->runtest("overridden compressed objects", - {$td->COMMAND => "test_driver 38 override-compressed-object.pdf"}, - {$td->FILE => "override-compressed-object.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("generate object streams for gen > 0", - {$td->COMMAND => "qpdf --qdf --static-id" . - " --object-streams=generate gen1.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check file", - {$td->FILE => "a.pdf"}, - {$td->FILE => "gen1.qdf"}); - - -cleanup(); -$td->report(calc_ntests($n_tests, $n_compare_pdfs)); diff --git a/qpdf/qtest/output-redirection.test b/qpdf/qtest/output-redirection.test new file mode 100644 index 00000000..13ad88a0 --- /dev/null +++ b/qpdf/qtest/output-redirection.test @@ -0,0 +1,32 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('output-redirection'); + +my $n_tests = 2; + +$td->runtest("error/output redirection to null", + {$td->COMMAND => "test_driver 12 linearized-and-warnings.pdf"}, + {$td->FILE => "linearized-and-warnings-1.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("error/output redirection to strings", + {$td->COMMAND => "test_driver 13 linearized-and-warnings.pdf"}, + {$td->FILE => "linearized-and-warnings-2.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/output_redirection.test b/qpdf/qtest/output_redirection.test deleted file mode 100644 index c9d4a609..00000000 --- a/qpdf/qtest/output_redirection.test +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('output_redirection'); - -my $n_tests = 2; - -$td->runtest("error/output redirection to null", - {$td->COMMAND => "test_driver 12 linearized-and-warnings.pdf"}, - {$td->FILE => "linearized-and-warnings-1.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("error/output redirection to strings", - {$td->COMMAND => "test_driver 13 linearized-and-warnings.pdf"}, - {$td->FILE => "linearized-and-warnings-2.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/overwrite-self.test b/qpdf/qtest/overwrite-self.test new file mode 100644 index 00000000..1a150ce6 --- /dev/null +++ b/qpdf/qtest/overwrite-self.test @@ -0,0 +1,38 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; +use File::Copy; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('overwrite-self'); + +my $n_tests = 3; + +copy("minimal.pdf", "a.pdf"); +copy("minimal.pdf", "split-out.pdf"); +# Also tests @- for reading args from stdin +$td->runtest("don't overwrite self", + {$td->COMMAND => "(echo a.pdf; echo a.pdf) | qpdf \@-"}, + {$td->REGEXP => "input file and output file are the same.*", + $td->EXIT_STATUS => 2}); +$td->runtest("output is not really output for split", + {$td->COMMAND => "qpdf --split-pages split-out.pdf split-out.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("don't overwrite self (split)", + {$td->COMMAND => + "qpdf --split-pages split-out-1.pdf split-out.pdf"}, + {$td->REGEXP => + ".*split pages would overwrite.* split-out-1.pdf", + $td->EXIT_STATUS => 2}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/overwrite_self.test b/qpdf/qtest/overwrite_self.test deleted file mode 100644 index 05e0af56..00000000 --- a/qpdf/qtest/overwrite_self.test +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; -use File::Copy; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('overwrite_self'); - -my $n_tests = 3; - -copy("minimal.pdf", "a.pdf"); -copy("minimal.pdf", "split-out.pdf"); -# Also tests @- for reading args from stdin -$td->runtest("don't overwrite self", - {$td->COMMAND => "(echo a.pdf; echo a.pdf) | qpdf \@-"}, - {$td->REGEXP => "input file and output file are the same.*", - $td->EXIT_STATUS => 2}); -$td->runtest("output is not really output for split", - {$td->COMMAND => "qpdf --split-pages split-out.pdf split-out.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("don't overwrite self (split)", - {$td->COMMAND => - "qpdf --split-pages split-out-1.pdf split-out.pdf"}, - {$td->REGEXP => - ".*split pages would overwrite.* split-out-1.pdf", - $td->EXIT_STATUS => 2}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/page-api.test b/qpdf/qtest/page-api.test new file mode 100644 index 00000000..0bfff47d --- /dev/null +++ b/qpdf/qtest/page-api.test @@ -0,0 +1,62 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('page-api'); + +my $n_tests = 11; + +$td->runtest("basic page API", + {$td->COMMAND => "test_driver 15 page_api_1.pdf"}, + {$td->STRING => "test 15 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "page_api_1-out.pdf"}); +$td->runtest("manual page manipulation", + {$td->COMMAND => "test_driver 16 page_api_1.pdf"}, + {$td->STRING => "test 16 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "page_api_1-out2.pdf"}); +$td->runtest("duplicate page", + {$td->COMMAND => "test_driver 17 page_api_2.pdf"}, + {$td->FILE => "page_api_2.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("delete and re-add a page", + {$td->COMMAND => "test_driver 18 page_api_1.pdf"}, + {$td->STRING => "test 18 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "page_api_1-out3.pdf"}); +$td->runtest("duplicate page", + {$td->COMMAND => "test_driver 19 page_api_1.pdf"}, + {$td->FILE => "page_api_1.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("remove page we don't have", + {$td->COMMAND => "test_driver 22 page_api_1.pdf"}, + {$td->FILE => "page_api_1.out2", $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); +$td->runtest("flatten rotation", + {$td->COMMAND => "qpdf --static-id --qdf". + " --no-original-object-ids" . + " --flatten-rotation boxes.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "boxes-flattened.pdf"}); +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/page-errors.test b/qpdf/qtest/page-errors.test new file mode 100644 index 00000000..7e210d73 --- /dev/null +++ b/qpdf/qtest/page-errors.test @@ -0,0 +1,40 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('page-errors'); + +my $n_tests = 5; + +$td->runtest("handle page no with contents", + {$td->COMMAND => "qpdf --show-pages page-no-content.pdf"}, + {$td->FILE => "page-no-content.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check no type key for page nodes", + {$td->COMMAND => "qpdf --check no-pages-types.pdf"}, + {$td->FILE => "no-pages-types.out", $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("no type key for page nodes", + {$td->COMMAND => "qpdf --static-id --split-pages no-pages-types.pdf a-split-out.pdf"}, + {$td->FILE => "no-pages-types-fix.out", $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a-split-out-1.pdf"}, + {$td->FILE => "no-pages-types-fixed.pdf"}); +$td->runtest("detect loops in pages structure", + {$td->COMMAND => "qpdf --check pages-loop.pdf"}, + {$td->FILE => "pages-loop.out", $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/page-labels.test b/qpdf/qtest/page-labels.test new file mode 100644 index 00000000..616dcb6a --- /dev/null +++ b/qpdf/qtest/page-labels.test @@ -0,0 +1,33 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('page-labels'); + +my $n_tests = 3; + +$td->runtest("complex page labels", + {$td->COMMAND => "test_driver 47 page-labels-num-tree.pdf"}, + {$td->FILE => "page-labels-num-tree.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("no zero entry for page labels", + {$td->COMMAND => "test_driver 47 page-labels-no-zero.pdf"}, + {$td->FILE => "page-labels-no-zero.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("no page labels", + {$td->COMMAND => "test_driver 47 minimal.pdf"}, + {$td->FILE => "no-page-labels.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/page-without-contents.test b/qpdf/qtest/page-without-contents.test new file mode 100644 index 00000000..51f4eb79 --- /dev/null +++ b/qpdf/qtest/page-without-contents.test @@ -0,0 +1,43 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('page-without-contents'); + +my $n_tests = 7; + +$td->runtest("check no contents", + {$td->COMMAND => "qpdf --check no-contents.pdf"}, + {$td->FILE => "no-contents-check.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +foreach my $arg ('--qdf', '--coalesce-contents', '') +{ + $td->runtest("convert no contents ($arg)", + {$td->COMMAND => + "qpdf $arg --static-id no-contents.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); + + my $suf = $arg; + $suf =~ s/--//; + if ($suf eq '') + { + $suf = "none"; + } + $td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "no-contents-$suf.pdf"}); +} + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/page_api.test b/qpdf/qtest/page_api.test deleted file mode 100644 index 6bae2782..00000000 --- a/qpdf/qtest/page_api.test +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('page_api'); - -my $n_tests = 11; - -$td->runtest("basic page API", - {$td->COMMAND => "test_driver 15 page_api_1.pdf"}, - {$td->STRING => "test 15 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "page_api_1-out.pdf"}); -$td->runtest("manual page manipulation", - {$td->COMMAND => "test_driver 16 page_api_1.pdf"}, - {$td->STRING => "test 16 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "page_api_1-out2.pdf"}); -$td->runtest("duplicate page", - {$td->COMMAND => "test_driver 17 page_api_2.pdf"}, - {$td->FILE => "page_api_2.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("delete and re-add a page", - {$td->COMMAND => "test_driver 18 page_api_1.pdf"}, - {$td->STRING => "test 18 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "page_api_1-out3.pdf"}); -$td->runtest("duplicate page", - {$td->COMMAND => "test_driver 19 page_api_1.pdf"}, - {$td->FILE => "page_api_1.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("remove page we don't have", - {$td->COMMAND => "test_driver 22 page_api_1.pdf"}, - {$td->FILE => "page_api_1.out2", $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); -$td->runtest("flatten rotation", - {$td->COMMAND => "qpdf --static-id --qdf". - " --no-original-object-ids" . - " --flatten-rotation boxes.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "boxes-flattened.pdf"}); -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/page_errors.test b/qpdf/qtest/page_errors.test deleted file mode 100644 index c63e58e2..00000000 --- a/qpdf/qtest/page_errors.test +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('page_errors'); - -my $n_tests = 5; - -$td->runtest("handle page no with contents", - {$td->COMMAND => "qpdf --show-pages page-no-content.pdf"}, - {$td->FILE => "page-no-content.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check no type key for page nodes", - {$td->COMMAND => "qpdf --check no-pages-types.pdf"}, - {$td->FILE => "no-pages-types.out", $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("no type key for page nodes", - {$td->COMMAND => "qpdf --static-id --split-pages no-pages-types.pdf a-split-out.pdf"}, - {$td->FILE => "no-pages-types-fix.out", $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a-split-out-1.pdf"}, - {$td->FILE => "no-pages-types-fixed.pdf"}); -$td->runtest("detect loops in pages structure", - {$td->COMMAND => "qpdf --check pages-loop.pdf"}, - {$td->FILE => "pages-loop.out", $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/page_labels.test b/qpdf/qtest/page_labels.test deleted file mode 100644 index 3c6741a8..00000000 --- a/qpdf/qtest/page_labels.test +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('page_labels'); - -my $n_tests = 3; - -$td->runtest("complex page labels", - {$td->COMMAND => "test_driver 47 page-labels-num-tree.pdf"}, - {$td->FILE => "page-labels-num-tree.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("no zero entry for page labels", - {$td->COMMAND => "test_driver 47 page-labels-no-zero.pdf"}, - {$td->FILE => "page-labels-no-zero.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("no page labels", - {$td->COMMAND => "test_driver 47 minimal.pdf"}, - {$td->FILE => "no-page-labels.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/page_without_contents.test b/qpdf/qtest/page_without_contents.test deleted file mode 100644 index 94db4fee..00000000 --- a/qpdf/qtest/page_without_contents.test +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('page_without_contents'); - -my $n_tests = 7; - -$td->runtest("check no contents", - {$td->COMMAND => "qpdf --check no-contents.pdf"}, - {$td->FILE => "no-contents-check.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -foreach my $arg ('--qdf', '--coalesce-contents', '') -{ - $td->runtest("convert no contents ($arg)", - {$td->COMMAND => - "qpdf $arg --static-id no-contents.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); - - my $suf = $arg; - $suf =~ s/--//; - if ($suf eq '') - { - $suf = "none"; - } - $td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "no-contents-$suf.pdf"}); -} - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/pages-tree.test b/qpdf/qtest/pages-tree.test new file mode 100644 index 00000000..4ad260ef --- /dev/null +++ b/qpdf/qtest/pages-tree.test @@ -0,0 +1,71 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('pages-tree'); + +my $n_tests = 11; + +$td->runtest("linearize duplicated pages", + {$td->COMMAND => + "qpdf --static-id --linearize" . + " page_api_2.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("compare files", + {$td->FILE => "a.pdf"}, + {$td->FILE => "linearize-duplicate-page.pdf"}); +$td->runtest("extract duplicated pages", + {$td->COMMAND => + "qpdf --static-id page_api_2.pdf" . + " --pages . -- a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("compare files", + {$td->FILE => "a.pdf"}, + {$td->FILE => "extract-duplicate-page.pdf"}); +$td->runtest("direct pages", + {$td->COMMAND => + "qpdf --static-id direct-pages.pdf --pages . -- a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "direct-pages-fixed.pdf"}); +$td->runtest("show direct pages", + {$td->COMMAND => + "qpdf --show-pages direct-pages.pdf"}, + {$td->FILE => "direct-pages.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +# Json mode for direct and duplicated pages illustrates that the +# "objects" section the original objects before correction when +# "pages" is not output but after correct when it is. +foreach my $f (qw(page_api_2 direct-pages)) +{ + $td->runtest("json for $f (objects only)", + {$td->COMMAND => + "qpdf --json=latest $f.pdf" . + " --json-key=objects"}, + {$td->FILE => "$f-json-objects.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("json for $f (with pages)", + {$td->COMMAND => + "qpdf --json=latest $f.pdf" . + " --json-key=objects --json-key=pages"}, + {$td->FILE => "$f-json-pages.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +} + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/pages_tree.test b/qpdf/qtest/pages_tree.test deleted file mode 100644 index c0f4b77f..00000000 --- a/qpdf/qtest/pages_tree.test +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('pages_tree'); - -my $n_tests = 11; - -$td->runtest("linearize duplicated pages", - {$td->COMMAND => - "qpdf --static-id --linearize" . - " page_api_2.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("compare files", - {$td->FILE => "a.pdf"}, - {$td->FILE => "linearize-duplicate-page.pdf"}); -$td->runtest("extract duplicated pages", - {$td->COMMAND => - "qpdf --static-id page_api_2.pdf" . - " --pages . -- a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("compare files", - {$td->FILE => "a.pdf"}, - {$td->FILE => "extract-duplicate-page.pdf"}); -$td->runtest("direct pages", - {$td->COMMAND => - "qpdf --static-id direct-pages.pdf --pages . -- a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "direct-pages-fixed.pdf"}); -$td->runtest("show direct pages", - {$td->COMMAND => - "qpdf --show-pages direct-pages.pdf"}, - {$td->FILE => "direct-pages.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -# Json mode for direct and duplicated pages illustrates that the -# "objects" section the original objects before correction when -# "pages" is not output but after correct when it is. -foreach my $f (qw(page_api_2 direct-pages)) -{ - $td->runtest("json for $f (objects only)", - {$td->COMMAND => - "qpdf --json=latest $f.pdf" . - " --json-key=objects"}, - {$td->FILE => "$f-json-objects.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("json for $f (with pages)", - {$td->COMMAND => - "qpdf --json=latest $f.pdf" . - " --json-key=objects --json-key=pages"}, - {$td->FILE => "$f-json-pages.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -} - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/parsed-offset.test b/qpdf/qtest/parsed-offset.test new file mode 100644 index 00000000..fdcc0f8a --- /dev/null +++ b/qpdf/qtest/parsed-offset.test @@ -0,0 +1,32 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('parsed-offset'); + +my $n_tests = 2; + +$td->runtest("parsed offset without object streams", + {$td->COMMAND => "test_parsedoffset minimal.pdf"}, + {$td->FILE => "minimal-parsedoffset.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("parsed offset with object streams", + {$td->COMMAND => "test_parsedoffset digitally-signed.pdf"}, + {$td->FILE => "digitally-signed-parsedoffset.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/parsed_offset.test b/qpdf/qtest/parsed_offset.test deleted file mode 100644 index c7fad9f3..00000000 --- a/qpdf/qtest/parsed_offset.test +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('parsed_offset'); - -my $n_tests = 2; - -$td->runtest("parsed offset without object streams", - {$td->COMMAND => "test_parsedoffset minimal.pdf"}, - {$td->FILE => "minimal-parsedoffset.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("parsed offset with object streams", - {$td->COMMAND => "test_parsedoffset digitally-signed.pdf"}, - {$td->FILE => "digitally-signed-parsedoffset.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/positive-p.test b/qpdf/qtest/positive-p.test new file mode 100644 index 00000000..ab0bcff0 --- /dev/null +++ b/qpdf/qtest/positive-p.test @@ -0,0 +1,41 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('positive-p'); + +my $n_tests = 4; + +# Files have been seen where /P in the encryption dictionary was an +# unsigned rather than a signed integer. To create +# encrypted-positive-P.pdf, I temporarily modified QPDFWriter.cc to +# introduce this error. + +$td->runtest("decrypt positive P", + {$td->COMMAND => + "qpdf --decrypt --static-id encrypted-positive-P.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "decrypted-positive-P.pdf"}); +$td->runtest("copy encryption positive P", + {$td->COMMAND => + "qpdf --static-id --static-aes-iv" . + " encrypted-positive-P.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "copied-positive-P.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/positive_p.test b/qpdf/qtest/positive_p.test deleted file mode 100644 index 0250a47b..00000000 --- a/qpdf/qtest/positive_p.test +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('positive_p'); - -my $n_tests = 4; - -# Files have been seen where /P in the encryption dictionary was an -# unsigned rather than a signed integer. To create -# encrypted-positive-P.pdf, I temporarily modified QPDFWriter.cc to -# introduce this error. - -$td->runtest("decrypt positive P", - {$td->COMMAND => - "qpdf --decrypt --static-id encrypted-positive-P.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "decrypted-positive-P.pdf"}); -$td->runtest("copy encryption positive P", - {$td->COMMAND => - "qpdf --static-id --static-aes-iv" . - " encrypted-positive-P.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "copied-positive-P.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/precheck-streams.test b/qpdf/qtest/precheck-streams.test new file mode 100644 index 00000000..c0353b50 --- /dev/null +++ b/qpdf/qtest/precheck-streams.test @@ -0,0 +1,28 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('precheck-streams'); + +my $n_tests = 2; + +$td->runtest("bad stream", + {$td->COMMAND => "qpdf --static-id bad-data.pdf a.pdf"}, + {$td->FILE => "bad-data.out", $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "bad-data-out.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/precheck_streams.test b/qpdf/qtest/precheck_streams.test deleted file mode 100644 index 28ece016..00000000 --- a/qpdf/qtest/precheck_streams.test +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('precheck_streams'); - -my $n_tests = 2; - -$td->runtest("bad stream", - {$td->COMMAND => "qpdf --static-id bad-data.pdf a.pdf"}, - {$td->FILE => "bad-data.out", $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "bad-data-out.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/preserve-unref.test b/qpdf/qtest/preserve-unref.test new file mode 100644 index 00000000..3a290841 --- /dev/null +++ b/qpdf/qtest/preserve-unref.test @@ -0,0 +1,41 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('preserve-unref'); + +my $n_tests = 6; + +$td->runtest("drop unused objects", + {$td->COMMAND => "qpdf --static-id unreferenced-objects.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "unreferenced-dropped.pdf"}); +$td->runtest("keep unused objects", + {$td->COMMAND => "qpdf --static-id --preserve-unreferenced" . + " unreferenced-objects.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "unreferenced-preserved.pdf"}); +$td->runtest("keep unused objects (C)", + {$td->COMMAND => + "qpdf-ctest 21 unreferenced-objects.pdf '' a.pdf"}, + {$td->STRING => "C test 21 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "unreferenced-preserved.pdf"}); +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/preserve_unref.test b/qpdf/qtest/preserve_unref.test deleted file mode 100644 index d2f804df..00000000 --- a/qpdf/qtest/preserve_unref.test +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('preserve_unref'); - -my $n_tests = 6; - -$td->runtest("drop unused objects", - {$td->COMMAND => "qpdf --static-id unreferenced-objects.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "unreferenced-dropped.pdf"}); -$td->runtest("keep unused objects", - {$td->COMMAND => "qpdf --static-id --preserve-unreferenced" . - " unreferenced-objects.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "unreferenced-preserved.pdf"}); -$td->runtest("keep unused objects (C)", - {$td->COMMAND => - "qpdf-ctest 21 unreferenced-objects.pdf '' a.pdf"}, - {$td->STRING => "C test 21 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "unreferenced-preserved.pdf"}); -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/progress-reporting.test b/qpdf/qtest/progress-reporting.test new file mode 100644 index 00000000..3c7fb2cf --- /dev/null +++ b/qpdf/qtest/progress-reporting.test @@ -0,0 +1,26 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('progress-reporting'); + +my $n_tests = 1; + +$td->runtest("progress report on small file", + {$td->COMMAND => "qpdf --progress minimal.pdf a.pdf", + $td->FILTER => "perl filter-progress.pl"}, + {$td->FILE => "small-progress.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/progress_reporting.test b/qpdf/qtest/progress_reporting.test deleted file mode 100644 index cbef4c15..00000000 --- a/qpdf/qtest/progress_reporting.test +++ /dev/null @@ -1,26 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('progress_reporting'); - -my $n_tests = 1; - -$td->runtest("progress report on small file", - {$td->COMMAND => "qpdf --progress minimal.pdf a.pdf", - $td->FILTER => "perl filter-progress.pl"}, - {$td->FILE => "small-progress.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/qpdf-json.test b/qpdf/qtest/qpdf-json.test new file mode 100644 index 00000000..dbb0c70d --- /dev/null +++ b/qpdf/qtest/qpdf-json.test @@ -0,0 +1,50 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('qpdf-json'); + +my $n_tests = 0; + +my @badfiles = ( + 'no-qpdf-object', + 'no-pdf-version', + 'top-level-scalar', + 'bad-pdf-version1', + 'bad-pdf-version2', + 'top-level-array', + 'objects-not-dict', + 'bad-object-key', + 'object-not-dict', + 'stream-not-dict', + 'stream-dict-not-dict', + 'trailer-not-dict', + 'trailer-stream', + 'missing-trailer', + 'missing-objects', + 'obj-key-errors', + ); + +$n_tests += scalar(@badfiles); + +foreach my $f (@badfiles) +{ + $td->runtest("bad: $f", + {$td->COMMAND => + "qpdf --json-input qjson-$f.json a.pdf"}, + {$td->FILE => "qjson-$f.out", $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); +} + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/qpdf_json.test b/qpdf/qtest/qpdf_json.test deleted file mode 100644 index dbb0c70d..00000000 --- a/qpdf/qtest/qpdf_json.test +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('qpdf-json'); - -my $n_tests = 0; - -my @badfiles = ( - 'no-qpdf-object', - 'no-pdf-version', - 'top-level-scalar', - 'bad-pdf-version1', - 'bad-pdf-version2', - 'top-level-array', - 'objects-not-dict', - 'bad-object-key', - 'object-not-dict', - 'stream-not-dict', - 'stream-dict-not-dict', - 'trailer-not-dict', - 'trailer-stream', - 'missing-trailer', - 'missing-objects', - 'obj-key-errors', - ); - -$n_tests += scalar(@badfiles); - -foreach my $f (@badfiles) -{ - $td->runtest("bad: $f", - {$td->COMMAND => - "qpdf --json-input qjson-$f.json a.pdf"}, - {$td->FILE => "qjson-$f.out", $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); -} - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/renumber-objects.test b/qpdf/qtest/renumber-objects.test new file mode 100644 index 00000000..25998d48 --- /dev/null +++ b/qpdf/qtest/renumber-objects.test @@ -0,0 +1,74 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('renumber-objects'); + +my $n_tests = 8; + +$td->runtest("w/o objstm", + {$td->COMMAND => "test_renumber minimal.pdf"}, + {$td->REGEXP => "succeeded\n", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("w/ objstm", + {$td->COMMAND => "test_renumber digitally-signed.pdf"}, + {$td->REGEXP => "succeeded\n", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("w/o objstm, --object-streams=generate", + {$td->COMMAND => + "test_renumber --object-streams=generate minimal.pdf"}, + {$td->REGEXP => "succeeded\n", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("w/ objstm, --object-streams=generate", + {$td->COMMAND => + "test_renumber --object-streams=generate digitally-signed.pdf"}, + {$td->REGEXP => "succeeded\n", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("w/o objstm, --linearize", + {$td->COMMAND => + "test_renumber --linearize minimal.pdf"}, + {$td->REGEXP => "succeeded\n", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("w/ objstm, --linearize", + {$td->COMMAND => + "test_renumber --linearize digitally-signed.pdf"}, + {$td->REGEXP => "succeeded\n", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("w/o objstm, --preserve-unreferenced", + {$td->COMMAND => + "test_renumber --preserve-unreferenced minimal.pdf"}, + {$td->REGEXP => "succeeded\n", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("w/ objstm, --preserve-unreferenced", + {$td->COMMAND => + "test_renumber --preserve-unreferenced digitally-signed.pdf"}, + {$td->REGEXP => "succeeded\n", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/renumber_objects.test b/qpdf/qtest/renumber_objects.test deleted file mode 100644 index b71715c1..00000000 --- a/qpdf/qtest/renumber_objects.test +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('renumber_objects'); - -my $n_tests = 8; - -$td->runtest("w/o objstm", - {$td->COMMAND => "test_renumber minimal.pdf"}, - {$td->REGEXP => "succeeded\n", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("w/ objstm", - {$td->COMMAND => "test_renumber digitally-signed.pdf"}, - {$td->REGEXP => "succeeded\n", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("w/o objstm, --object-streams=generate", - {$td->COMMAND => - "test_renumber --object-streams=generate minimal.pdf"}, - {$td->REGEXP => "succeeded\n", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("w/ objstm, --object-streams=generate", - {$td->COMMAND => - "test_renumber --object-streams=generate digitally-signed.pdf"}, - {$td->REGEXP => "succeeded\n", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("w/o objstm, --linearize", - {$td->COMMAND => - "test_renumber --linearize minimal.pdf"}, - {$td->REGEXP => "succeeded\n", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("w/ objstm, --linearize", - {$td->COMMAND => - "test_renumber --linearize digitally-signed.pdf"}, - {$td->REGEXP => "succeeded\n", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("w/o objstm, --preserve-unreferenced", - {$td->COMMAND => - "test_renumber --preserve-unreferenced minimal.pdf"}, - {$td->REGEXP => "succeeded\n", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("w/ objstm, --preserve-unreferenced", - {$td->COMMAND => - "test_renumber --preserve-unreferenced digitally-signed.pdf"}, - {$td->REGEXP => "succeeded\n", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/replace-input.test b/qpdf/qtest/replace-input.test new file mode 100644 index 00000000..70a37cc2 --- /dev/null +++ b/qpdf/qtest/replace-input.test @@ -0,0 +1,56 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('replace-input'); + +my $n_tests = 8; + +# Use Unicode file names to test replace input so we can be sure it +# works for that case. +$td->runtest("create unicode filenames", + {$td->COMMAND => "test_unicode_filenames"}, + {$td->STRING => "created Unicode filenames\n", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +foreach my $d (['auto-ü', 1], ['auto-öπ', 2]) +{ + my ($u, $n) = @$d; + $td->runtest("replace input $u", + {$td->COMMAND => "qpdf --deterministic-id" . + " --object-streams=generate --replace-input ./$u.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("check output ($u)", + {$td->FILE => "$u.pdf"}, + {$td->FILE => "replace-input.pdf"}, + $td->NORMALIZE_NEWLINES); +} + +system("cp xref-with-short-size.pdf auto-warn.pdf") == 0 or die; +$td->runtest("replace input with warnings", + {$td->COMMAND => + "qpdf --deterministic-id --replace-input ./auto-warn.pdf"}, + {$td->FILE => "replace-warn.out", $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("check output", + {$td->FILE => "auto-warn.pdf"}, + {$td->FILE => "warn-replace.pdf"}); +$td->runtest("check orig output", + {$td->FILE => "auto-warn.pdf.~qpdf-orig"}, + {$td->FILE => "xref-with-short-size.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/replace_input.test b/qpdf/qtest/replace_input.test deleted file mode 100644 index b4f01ac4..00000000 --- a/qpdf/qtest/replace_input.test +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('replace_input'); - -my $n_tests = 8; - -# Use Unicode file names to test replace input so we can be sure it -# works for that case. -$td->runtest("create unicode filenames", - {$td->COMMAND => "test_unicode_filenames"}, - {$td->STRING => "created Unicode filenames\n", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -foreach my $d (['auto-ü', 1], ['auto-öπ', 2]) -{ - my ($u, $n) = @$d; - $td->runtest("replace input $u", - {$td->COMMAND => "qpdf --deterministic-id" . - " --object-streams=generate --replace-input ./$u.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("check output ($u)", - {$td->FILE => "$u.pdf"}, - {$td->FILE => "replace-input.pdf"}, - $td->NORMALIZE_NEWLINES); -} - -system("cp xref-with-short-size.pdf auto-warn.pdf") == 0 or die; -$td->runtest("replace input with warnings", - {$td->COMMAND => - "qpdf --deterministic-id --replace-input ./auto-warn.pdf"}, - {$td->FILE => "replace-warn.out", $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("check output", - {$td->FILE => "auto-warn.pdf"}, - {$td->FILE => "warn-replace.pdf"}); -$td->runtest("check orig output", - {$td->FILE => "auto-warn.pdf.~qpdf-orig"}, - {$td->FILE => "xref-with-short-size.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/rotate-pages.test b/qpdf/qtest/rotate-pages.test new file mode 100644 index 00000000..c5e293e8 --- /dev/null +++ b/qpdf/qtest/rotate-pages.test @@ -0,0 +1,104 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('rotate-pages'); + +my $n_tests = 18; + +# Do absolute, positive, and negative on ranges that include +# inherited and non-inherited. +# Pages 11-15 inherit /Rotate 90 +# Pages 1 and 2 have explicit /Rotate 270 +# Pages 16 and 17 have explicit /Rotate 180 + +$td->runtest("page rotation", + {$td->COMMAND => "qpdf --static-id to-rotate.pdf a.pdf" . + " --rotate=+90:1,4,11,16" . + " --rotate=180:2,5,12-13" . + " --rotate=-90:3,15,17,18"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "rotated.pdf"}); + +$td->runtest("remove rotation", + {$td->COMMAND => "qpdf --static-id rotated.pdf a.pdf" . + " --qdf --no-original-object-ids --rotate=0"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "unrotated.pdf"}); + +$td->runtest("rotate all pages", + {$td->COMMAND => + "qpdf --static-id --rotate=180 minimal.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "minimal-rotated.pdf"}); + +$td->runtest("flatten with inherited rotate", + {$td->COMMAND => + "qpdf --static-id --flatten-rotation" . + " inherited-rotate.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "inherited-flattened.pdf"}); + +foreach my $angle (qw(90 180 270)) +{ + $td->runtest("rotate annotations", + {$td->COMMAND => + "qpdf --static-id --qdf --rotate=$angle" . + " --flatten-rotation --no-original-object-ids" . + " form-fields-and-annotations.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); + $td->runtest("check output (flatten $angle)", + {$td->FILE => "a.pdf"}, + {$td->FILE => "annotations-rotated-$angle.pdf"}); +} + +# The file form-fields-and-annotations-shared.pdf contains some +# annotations that appear in multiple pages /Annots, some non-shared +# things that share appearance streams, some form fields appear on +# multiple pages, and an indirect /Annotations array. It is out of +# spec in several ways but still works in most viewers. These test +# make sure we don't make anything worse and also end up exercising +# some cases of things being copied more than once, though we also +# exercise that with legitimate test cases using overlay. + +$td->runtest("shared annotations 1 page", + {$td->COMMAND => + "qpdf --qdf --no-original-object-ids --static-id" . + " --rotate=90:1 form-fields-and-annotations-shared.pdf" . + " a.pdf --flatten-rotation"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "rotated-shared-annotations-1.pdf"}); +$td->runtest("shared annotations 2 pages", + {$td->COMMAND => + "qpdf --qdf --no-original-object-ids --static-id" . + " --rotate=90:1,2 form-fields-and-annotations-shared.pdf" . + " a.pdf --flatten-rotation"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "rotated-shared-annotations-2.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/rotate_pages.test b/qpdf/qtest/rotate_pages.test deleted file mode 100644 index 9d92c047..00000000 --- a/qpdf/qtest/rotate_pages.test +++ /dev/null @@ -1,104 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('rotate_pages'); - -my $n_tests = 18; - -# Do absolute, positive, and negative on ranges that include -# inherited and non-inherited. -# Pages 11-15 inherit /Rotate 90 -# Pages 1 and 2 have explicit /Rotate 270 -# Pages 16 and 17 have explicit /Rotate 180 - -$td->runtest("page rotation", - {$td->COMMAND => "qpdf --static-id to-rotate.pdf a.pdf" . - " --rotate=+90:1,4,11,16" . - " --rotate=180:2,5,12-13" . - " --rotate=-90:3,15,17,18"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "rotated.pdf"}); - -$td->runtest("remove rotation", - {$td->COMMAND => "qpdf --static-id rotated.pdf a.pdf" . - " --qdf --no-original-object-ids --rotate=0"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "unrotated.pdf"}); - -$td->runtest("rotate all pages", - {$td->COMMAND => - "qpdf --static-id --rotate=180 minimal.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "minimal-rotated.pdf"}); - -$td->runtest("flatten with inherited rotate", - {$td->COMMAND => - "qpdf --static-id --flatten-rotation" . - " inherited-rotate.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "inherited-flattened.pdf"}); - -foreach my $angle (qw(90 180 270)) -{ - $td->runtest("rotate annotations", - {$td->COMMAND => - "qpdf --static-id --qdf --rotate=$angle" . - " --flatten-rotation --no-original-object-ids" . - " form-fields-and-annotations.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); - $td->runtest("check output (flatten $angle)", - {$td->FILE => "a.pdf"}, - {$td->FILE => "annotations-rotated-$angle.pdf"}); -} - -# The file form-fields-and-annotations-shared.pdf contains some -# annotations that appear in multiple pages /Annots, some non-shared -# things that share appearance streams, some form fields appear on -# multiple pages, and an indirect /Annotations array. It is out of -# spec in several ways but still works in most viewers. These test -# make sure we don't make anything worse and also end up exercising -# some cases of things being copied more than once, though we also -# exercise that with legitimate test cases using overlay. - -$td->runtest("shared annotations 1 page", - {$td->COMMAND => - "qpdf --qdf --no-original-object-ids --static-id" . - " --rotate=90:1 form-fields-and-annotations-shared.pdf" . - " a.pdf --flatten-rotation"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "rotated-shared-annotations-1.pdf"}); -$td->runtest("shared annotations 2 pages", - {$td->COMMAND => - "qpdf --qdf --no-original-object-ids --static-id" . - " --rotate=90:1,2 form-fields-and-annotations-shared.pdf" . - " a.pdf --flatten-rotation"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "rotated-shared-annotations-2.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/signature-dictionary.test b/qpdf/qtest/signature-dictionary.test new file mode 100644 index 00000000..2c710793 --- /dev/null +++ b/qpdf/qtest/signature-dictionary.test @@ -0,0 +1,132 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('signature-dictionary'); + +my $n_tests = 0; + +$n_tests += 6; +foreach my $i (qw(preserve disable generate)) +{ + $td->runtest("sig dict contents hex (object-streams=$i)", + {$td->COMMAND => + "qpdf --object-streams=$i digitally-signed.pdf a.pdf"}, + {$td->STRING => "", + $td->EXIT_STATUS => 0}); + # Use grep -f rather than writing something in test_driver because + # the point of the test is to ensure that the contents appears in + # the output file in the correct format. + $td->runtest("find desired contents (object-streams=$i)", + {$td->COMMAND => + "grep -f digitally-signed-sig-dict-contents.out a.pdf"}, + {$td->REGEXP => ".*", + $td->EXIT_STATUS => 0}); +} + +$n_tests += 4; +foreach my $i (qw(preserve disable)) +{ + $td->runtest("non sig dict contents text string (object-streams=$i)", + {$td->COMMAND => + "qpdf --object-streams=$i comment-annotation.pdf a.pdf"}, + {$td->STRING => "", + $td->EXIT_STATUS => 0}); + $td->runtest("find desired contents as non hex (object-streams=$i)", + {$td->COMMAND => + "grep \"/Contents (Salad)\" a.pdf"}, + {$td->REGEXP => ".*", + $td->EXIT_STATUS => 0}); +} + +$n_tests += 2; + $td->runtest("non sig dict contents text string (object-streams=generate)", + {$td->COMMAND => + "qpdf --object-streams=generate comment-annotation.pdf a.pdf"}, + {$td->STRING => "", + $td->EXIT_STATUS => 0}); + $td->runtest("plain text not found due to compression (object-streams=generate)", + {$td->COMMAND => + "grep \"/Contents (Salad)\" a.pdf"}, + {$td->REGEXP => ".*", + $td->EXIT_STATUS => 1}); + +$n_tests += 12; +foreach my $i (qw(40 128 256)) +{ + my $x = ""; + if ($i < 256) + { + $x = "--allow-weak-crypto"; + } + $td->runtest("encrypt $i", + {$td->COMMAND => + "qpdf $x --encrypt '' o $i --" . + " digitally-signed.pdf a.pdf"}, + {$td->STRING => "", + $td->EXIT_STATUS => 0}); + $td->runtest("find desired contents (encrypt $i)", + {$td->COMMAND => + "grep -f digitally-signed-sig-dict-contents.out a.pdf"}, + {$td->REGEXP => ".*", + $td->EXIT_STATUS => 0}); + $td->runtest("decrypt", + {$td->COMMAND => + "qpdf --decrypt a.pdf b.pdf"}, + {$td->REGEXP => ".*", + $td->EXIT_STATUS => 0}); + $td->runtest("find desired contents (decrypt $i)", + {$td->COMMAND => + "grep -f digitally-signed-sig-dict-contents.out b.pdf"}, + {$td->REGEXP => ".*", + $td->EXIT_STATUS => 0}); +} + +$n_tests += 15; +foreach my $i (qw(40 128 256)) +{ + my $x = ""; + if ($i < 256) + { + $x = "--allow-weak-crypto"; + } + $td->runtest("non sig dict encrypt $i", + {$td->COMMAND => + "qpdf $x --encrypt '' o $i --" . + " comment-annotation.pdf a.pdf"}, + {$td->STRING => "", + $td->EXIT_STATUS => 0}); + $td->runtest("plain text not found due to encryption (non sig dict encrypt $i)", + {$td->COMMAND => + "grep \"/Contents (Salad)\" a.pdf"}, + {$td->REGEXP => ".*", + $td->EXIT_STATUS => 1}); + $td->runtest("find encrypted contents (non sig dict encrypt $i)", + {$td->COMMAND => + "grep \"/Contents <.*>\" a.pdf"}, + {$td->REGEXP => ".*", + $td->EXIT_STATUS => 0}); + $td->runtest("non sig dict decrypt", + {$td->COMMAND => + "qpdf --decrypt a.pdf b.pdf"}, + {$td->REGEXP => ".*", + $td->EXIT_STATUS => 0}); + $td->runtest("find desired contents (non sig dict decrypt $i)", + {$td->COMMAND => + "grep \"/Contents (Salad)\" b.pdf"}, + {$td->REGEXP => ".*", + $td->EXIT_STATUS => 0}); +} + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/signature_dictionary.test b/qpdf/qtest/signature_dictionary.test deleted file mode 100644 index 54acf671..00000000 --- a/qpdf/qtest/signature_dictionary.test +++ /dev/null @@ -1,132 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('signature_dictionary'); - -my $n_tests = 0; - -$n_tests += 6; -foreach my $i (qw(preserve disable generate)) -{ - $td->runtest("sig dict contents hex (object-streams=$i)", - {$td->COMMAND => - "qpdf --object-streams=$i digitally-signed.pdf a.pdf"}, - {$td->STRING => "", - $td->EXIT_STATUS => 0}); - # Use grep -f rather than writing something in test_driver because - # the point of the test is to ensure that the contents appears in - # the output file in the correct format. - $td->runtest("find desired contents (object-streams=$i)", - {$td->COMMAND => - "grep -f digitally-signed-sig-dict-contents.out a.pdf"}, - {$td->REGEXP => ".*", - $td->EXIT_STATUS => 0}); -} - -$n_tests += 4; -foreach my $i (qw(preserve disable)) -{ - $td->runtest("non sig dict contents text string (object-streams=$i)", - {$td->COMMAND => - "qpdf --object-streams=$i comment-annotation.pdf a.pdf"}, - {$td->STRING => "", - $td->EXIT_STATUS => 0}); - $td->runtest("find desired contents as non hex (object-streams=$i)", - {$td->COMMAND => - "grep \"/Contents (Salad)\" a.pdf"}, - {$td->REGEXP => ".*", - $td->EXIT_STATUS => 0}); -} - -$n_tests += 2; - $td->runtest("non sig dict contents text string (object-streams=generate)", - {$td->COMMAND => - "qpdf --object-streams=generate comment-annotation.pdf a.pdf"}, - {$td->STRING => "", - $td->EXIT_STATUS => 0}); - $td->runtest("plain text not found due to compression (object-streams=generate)", - {$td->COMMAND => - "grep \"/Contents (Salad)\" a.pdf"}, - {$td->REGEXP => ".*", - $td->EXIT_STATUS => 1}); - -$n_tests += 12; -foreach my $i (qw(40 128 256)) -{ - my $x = ""; - if ($i < 256) - { - $x = "--allow-weak-crypto"; - } - $td->runtest("encrypt $i", - {$td->COMMAND => - "qpdf $x --encrypt '' o $i --" . - " digitally-signed.pdf a.pdf"}, - {$td->STRING => "", - $td->EXIT_STATUS => 0}); - $td->runtest("find desired contents (encrypt $i)", - {$td->COMMAND => - "grep -f digitally-signed-sig-dict-contents.out a.pdf"}, - {$td->REGEXP => ".*", - $td->EXIT_STATUS => 0}); - $td->runtest("decrypt", - {$td->COMMAND => - "qpdf --decrypt a.pdf b.pdf"}, - {$td->REGEXP => ".*", - $td->EXIT_STATUS => 0}); - $td->runtest("find desired contents (decrypt $i)", - {$td->COMMAND => - "grep -f digitally-signed-sig-dict-contents.out b.pdf"}, - {$td->REGEXP => ".*", - $td->EXIT_STATUS => 0}); -} - -$n_tests += 15; -foreach my $i (qw(40 128 256)) -{ - my $x = ""; - if ($i < 256) - { - $x = "--allow-weak-crypto"; - } - $td->runtest("non sig dict encrypt $i", - {$td->COMMAND => - "qpdf $x --encrypt '' o $i --" . - " comment-annotation.pdf a.pdf"}, - {$td->STRING => "", - $td->EXIT_STATUS => 0}); - $td->runtest("plain text not found due to encryption (non sig dict encrypt $i)", - {$td->COMMAND => - "grep \"/Contents (Salad)\" a.pdf"}, - {$td->REGEXP => ".*", - $td->EXIT_STATUS => 1}); - $td->runtest("find encrypted contents (non sig dict encrypt $i)", - {$td->COMMAND => - "grep \"/Contents <.*>\" a.pdf"}, - {$td->REGEXP => ".*", - $td->EXIT_STATUS => 0}); - $td->runtest("non sig dict decrypt", - {$td->COMMAND => - "qpdf --decrypt a.pdf b.pdf"}, - {$td->REGEXP => ".*", - $td->EXIT_STATUS => 0}); - $td->runtest("find desired contents (non sig dict decrypt $i)", - {$td->COMMAND => - "grep \"/Contents (Salad)\" b.pdf"}, - {$td->REGEXP => ".*", - $td->EXIT_STATUS => 0}); -} - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/specialized-filter.test b/qpdf/qtest/specialized-filter.test new file mode 100644 index 00000000..284d5195 --- /dev/null +++ b/qpdf/qtest/specialized-filter.test @@ -0,0 +1,44 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; +use Digest::MD5; +use File::Copy; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('specialized-filter'); + +my $n_tests = 3; +my $n_compare_pdfs = 1; + +# The PDF file was submitted on bug #83 on github. All the PNG filters +# are exercised. The test suite does not exercise PNG predictors with +# LZW because I don't have a way to create such a file, but it's very +# likely that it will work since the handling of the PNG filters is +# separate from the regular decompression. +$td->runtest("decode png-filtering", + {$td->COMMAND => "qpdf --static-id" . + " --compress-streams=n --decode-level=generalized" . + " png-filters.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "png-filters-decoded.pdf"}); +compare_pdfs($td, "png-filters.pdf", "a.pdf"); + +$td->runtest("stream with tiff predictor", + {$td->COMMAND => "qpdf --check tiff-predictor.pdf"}, + {$td->FILE => "tiff-predictor.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report(calc_ntests($n_tests, $n_compare_pdfs)); diff --git a/qpdf/qtest/specialized_filter.test b/qpdf/qtest/specialized_filter.test deleted file mode 100644 index 36bcbf0c..00000000 --- a/qpdf/qtest/specialized_filter.test +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; -use Digest::MD5; -use File::Copy; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('specialized_filter'); - -my $n_tests = 3; -my $n_compare_pdfs = 1; - -# The PDF file was submitted on bug #83 on github. All the PNG filters -# are exercised. The test suite does not exercise PNG predictors with -# LZW because I don't have a way to create such a file, but it's very -# likely that it will work since the handling of the PNG filters is -# separate from the regular decompression. -$td->runtest("decode png-filtering", - {$td->COMMAND => "qpdf --static-id" . - " --compress-streams=n --decode-level=generalized" . - " png-filters.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "png-filters-decoded.pdf"}); -compare_pdfs($td, "png-filters.pdf", "a.pdf"); - -$td->runtest("stream with tiff predictor", - {$td->COMMAND => "qpdf --check tiff-predictor.pdf"}, - {$td->FILE => "tiff-predictor.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report(calc_ntests($n_tests, $n_compare_pdfs)); diff --git a/qpdf/qtest/specific-bugs.test b/qpdf/qtest/specific-bugs.test new file mode 100644 index 00000000..326b3e98 --- /dev/null +++ b/qpdf/qtest/specific-bugs.test @@ -0,0 +1,82 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('specific-bugs'); + +# The number is the github issue number in which the bug was reported. +my @bug_tests = ( + ["51", "resolve loop", 3], + ["99", "object 0", 2], + ["99b", "object 0", 2], + ["100", "xref reconstruction loop", 2], + ["101", "resolve for exception text", 2], + ["117", "other infinite loop", 3], + ["118", "other infinite loop", 2], + ["119", "other infinite loop", 3], + ["120", "other infinite loop", 3], + ["106", "zlib data error", 3], + ["141a", "/W entry size 0", 2], + ["141b", "/W entry size 0", 2], + ["143", "self-referential ostream", 3, "--preserve-unreferenced"], + ["146", "very deeply nested array", 2], + ["147", "previously caused memory error", 2], + ["148", "free memory on bad flate", 2], + ["149", "xref prev pointer loop", 3], + ["150", "integer overflow", 2], + ["202", "even more deeply nested dictionary", 2], + ["263", "empty xref stream", 2], + ["335a", "ozz-fuzz-12152", 2], + ["335b", "ozz-fuzz-14845", 2], + ["fuzz-16214", "stream in object stream", 3, "--preserve-unreferenced"], + # When adding to this list, consider adding to CORPUS_FROM_TEST in + # fuzz/CMakeLists.txt and updating the count in + # fuzz/qtest/fuzz.test. + ); +my $n_tests = scalar(@bug_tests); +foreach my $d (@bug_tests) +{ + my ($n, $description, $exit_status, $xargs) = @$d; + if (! defined $xargs) + { + $xargs = ""; + } + if (-f "issue-$n.obfuscated") + { + # Some of the PDF files in the test suite trigger anti-virus + # warnings (MAL/PDFEx-H) and are quarantined or deleted by + # some antivirus software. These files are not actually + # infected files with malicious intent. They are present in + # the test suite to ensure that qpdf does not crash when + # process those files. Base64-encode them and pass them to + # stdin to prevent anti-virus programs from messing up the + # extracted sources. Search for "obfuscated" in test_driver.cc + # for instructions on how to obfuscate input files. + $td->runtest($description, + {$td->COMMAND => "test_driver 45 issue-$n"}, + {$td->FILE => "issue-$n.out", + $td->EXIT_STATUS => $exit_status}, + $td->NORMALIZE_NEWLINES); + } + else + { + my $base = (-f "issue-$n.pdf") ? "issue-$n" : "$n"; + $td->runtest($description, + {$td->COMMAND => "qpdf $xargs $base.pdf a.pdf"}, + {$td->FILE => "$base.out", + $td->EXIT_STATUS => $exit_status}, + $td->NORMALIZE_NEWLINES); + } +} +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/specific-file.test b/qpdf/qtest/specific-file.test new file mode 100644 index 00000000..188f4dd5 --- /dev/null +++ b/qpdf/qtest/specific-file.test @@ -0,0 +1,67 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('specific-file'); + +my $n_tests = 11; + +# Special PDF files that caused problems at some point + +$td->runtest("damaged stream", + {$td->COMMAND => "qpdf --check damaged-stream.pdf"}, + {$td->FILE => "damaged-stream.out", $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("damaged stream (C)", + {$td->COMMAND => "qpdf-ctest 2 damaged-stream.pdf '' a.pdf"}, + {$td->FILE => "damaged-stream-c-check.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("compress objstm and xref", + {$td->COMMAND => + "qpdf --static-id --stream-data=compress". + " --object-streams=generate minimal.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "compress-objstm-xref.pdf"}); +$td->runtest("qdf + preserved-unreferenced + xref streams", + {$td->COMMAND => "qpdf --qdf --preserve-unreferenced" . + " --static-id compress-objstm-xref.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "compress-objstm-xref-qdf.pdf"}); +$td->runtest("check fix-qdf idempotency", + {$td->COMMAND => "fix-qdf a.pdf"}, + {$td->FILE => "a.pdf", $td->EXIT_STATUS => 0}); +$td->runtest("pages points to page", + {$td->COMMAND => + "qpdf --static-id --linearize pages-is-page.pdf a.pdf"}, + {$td->FILE => "pages-is-page.out", $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "pages-is-page-out.pdf"}); +$td->runtest("Acroform /DR with indirect subkey", + {$td->COMMAND => + "qpdf --static-id --empty" . + " --pages dr-with-indirect-item.pdf -- a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "dr-with-indirect-item-out.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/specific_bugs.test b/qpdf/qtest/specific_bugs.test deleted file mode 100644 index 6ae62428..00000000 --- a/qpdf/qtest/specific_bugs.test +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('specific_bugs'); - -# The number is the github issue number in which the bug was reported. -my @bug_tests = ( - ["51", "resolve loop", 3], - ["99", "object 0", 2], - ["99b", "object 0", 2], - ["100", "xref reconstruction loop", 2], - ["101", "resolve for exception text", 2], - ["117", "other infinite loop", 3], - ["118", "other infinite loop", 2], - ["119", "other infinite loop", 3], - ["120", "other infinite loop", 3], - ["106", "zlib data error", 3], - ["141a", "/W entry size 0", 2], - ["141b", "/W entry size 0", 2], - ["143", "self-referential ostream", 3, "--preserve-unreferenced"], - ["146", "very deeply nested array", 2], - ["147", "previously caused memory error", 2], - ["148", "free memory on bad flate", 2], - ["149", "xref prev pointer loop", 3], - ["150", "integer overflow", 2], - ["202", "even more deeply nested dictionary", 2], - ["263", "empty xref stream", 2], - ["335a", "ozz-fuzz-12152", 2], - ["335b", "ozz-fuzz-14845", 2], - ["fuzz-16214", "stream in object stream", 3, "--preserve-unreferenced"], - # When adding to this list, consider adding to CORPUS_FROM_TEST in - # fuzz/CMakeLists.txt and updating the count in - # fuzz/qtest/fuzz.test. - ); -my $n_tests = scalar(@bug_tests); -foreach my $d (@bug_tests) -{ - my ($n, $description, $exit_status, $xargs) = @$d; - if (! defined $xargs) - { - $xargs = ""; - } - if (-f "issue-$n.obfuscated") - { - # Some of the PDF files in the test suite trigger anti-virus - # warnings (MAL/PDFEx-H) and are quarantined or deleted by - # some antivirus software. These files are not actually - # infected files with malicious intent. They are present in - # the test suite to ensure that qpdf does not crash when - # process those files. Base64-encode them and pass them to - # stdin to prevent anti-virus programs from messing up the - # extracted sources. Search for "obfuscated" in test_driver.cc - # for instructions on how to obfuscate input files. - $td->runtest($description, - {$td->COMMAND => "test_driver 45 issue-$n"}, - {$td->FILE => "issue-$n.out", - $td->EXIT_STATUS => $exit_status}, - $td->NORMALIZE_NEWLINES); - } - else - { - my $base = (-f "issue-$n.pdf") ? "issue-$n" : "$n"; - $td->runtest($description, - {$td->COMMAND => "qpdf $xargs $base.pdf a.pdf"}, - {$td->FILE => "$base.out", - $td->EXIT_STATUS => $exit_status}, - $td->NORMALIZE_NEWLINES); - } -} -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/specific_file.test b/qpdf/qtest/specific_file.test deleted file mode 100644 index ce170e12..00000000 --- a/qpdf/qtest/specific_file.test +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('specific_file'); - -my $n_tests = 11; - -# Special PDF files that caused problems at some point - -$td->runtest("damaged stream", - {$td->COMMAND => "qpdf --check damaged-stream.pdf"}, - {$td->FILE => "damaged-stream.out", $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("damaged stream (C)", - {$td->COMMAND => "qpdf-ctest 2 damaged-stream.pdf '' a.pdf"}, - {$td->FILE => "damaged-stream-c-check.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("compress objstm and xref", - {$td->COMMAND => - "qpdf --static-id --stream-data=compress". - " --object-streams=generate minimal.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "compress-objstm-xref.pdf"}); -$td->runtest("qdf + preserved-unreferenced + xref streams", - {$td->COMMAND => "qpdf --qdf --preserve-unreferenced" . - " --static-id compress-objstm-xref.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "compress-objstm-xref-qdf.pdf"}); -$td->runtest("check fix-qdf idempotency", - {$td->COMMAND => "fix-qdf a.pdf"}, - {$td->FILE => "a.pdf", $td->EXIT_STATUS => 0}); -$td->runtest("pages points to page", - {$td->COMMAND => - "qpdf --static-id --linearize pages-is-page.pdf a.pdf"}, - {$td->FILE => "pages-is-page.out", $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "pages-is-page-out.pdf"}); -$td->runtest("Acroform /DR with indirect subkey", - {$td->COMMAND => - "qpdf --static-id --empty" . - " --pages dr-with-indirect-item.pdf -- a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "dr-with-indirect-item-out.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/split-pages.test b/qpdf/qtest/split-pages.test new file mode 100644 index 00000000..46515c4f --- /dev/null +++ b/qpdf/qtest/split-pages.test @@ -0,0 +1,213 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; +use Digest::MD5; +use File::Copy; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('split-pages'); + +my $n_tests = 42; +my $n_compare_pdfs = 2; + +# sp = split-pages +my @sp_cases = ( + [11, '%d at beginning', '', '%d_split-out.zdf'], + [11, '%d at end', '--qdf', 'split-out.zdf_%d'], + [11, '%d in middle', '--allow-weak-crypto --encrypt u o 128 --', + 'a-%d-split-out.zdf'], + [11, 'pdf extension', '', 'split-out.Pdf'], + [4, 'fallback', '--pages 11-pages.pdf 1-3 minimal.pdf --', 'split-out'], + [1, 'broken data', '--pages broken-lzw.pdf --', 'split-out.pdf', + {$td->FILE => "broken-lzw.out", $td->EXIT_STATUS => 3}], + ); +for (@sp_cases) +{ + $n_tests += 1 + $_->[0]; +} + +$td->runtest("split page group > 1", + {$td->COMMAND => "qpdf --static-id --split-pages=5 11-pages.pdf" . + " --verbose split-out-group.pdf"}, + {$td->FILE => "split-pages-group.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +foreach my $f ('01-05', '06-10', '11-11') +{ + $td->runtest("check out group $f", + {$td->FILE => "split-out-group-$f.pdf"}, + {$td->FILE => "split-exp-group-$f.pdf"}); +} + +$td->runtest("no split-pages to stdout", + {$td->COMMAND => "qpdf --split-pages 11-pages.pdf -"}, + {$td->FILE => "split-pages-stdout.out", $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("split page with shared resources", + {$td->COMMAND => "qpdf --qdf --static-id --split-pages=4". + " shared-images.pdf split-out-shared.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +foreach my $i (qw(01-04 05-08 09-10)) +{ + $td->runtest("check output ($i)", + {$td->FILE => "split-out-shared-$i.pdf"}, + {$td->FILE => "shared-split-$i.pdf"}); +} + +$td->runtest("split page with labels", + {$td->COMMAND => "qpdf --qdf --static-id --split-pages=6". + " 11-pages-with-labels.pdf split-out-labels.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +foreach my $i (qw(01-06 07-11)) +{ + $td->runtest("check output ($i)", + {$td->FILE => "split-out-labels-$i.pdf"}, + {$td->FILE => "labels-split-$i.pdf"}); +} + +# See comments in TODO about these expected failures. Search for +# "split page with outlines". +$td->runtest("split page with outlines", + {$td->COMMAND => "qpdf --qdf --static-id --split-pages=10". + " outlines-with-actions.pdf split-out-outlines.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +foreach my $i (qw(01-10 11-20 21-30)) +{ + $td->runtest("check output ($i)", + {$td->FILE => "split-out-outlines-$i.pdf"}, + {$td->FILE => "outlines-split-$i.pdf"}, + $td->EXPECT_FAILURE) +} + +foreach my $d (@sp_cases) +{ + my ($n, $description, $xargs, $out, $exp) = @$d; + if (! defined $exp) + { + $exp = {$td->STRING => "", $td->EXIT_STATUS => 0}; + } + $td->runtest("split pages " . $description, + {$td->COMMAND => + "qpdf --static-id --split-pages 11-pages.pdf" . + " $xargs $out"}, + $exp, + $td->NORMALIZE_NEWLINES); + my $pattern = $out; + my $nlen = length($n); + if ($pattern =~ m/\%d/) + { + $pattern =~ s/\%d/\%0${nlen}d/; + } + elsif ($pattern =~ m/\.pdf$/i) + { + $pattern =~ s/(\.pdf$)/-%0${nlen}d$1/i; + } + else + { + $pattern .= "-%0${nlen}d"; + } + for (my $i = 1; $i <= $n; ++$i) + { + my $actual = sprintf($pattern, $i); + my $expected = $actual; + $expected =~ s/split-out/split-exp/; + $td->runtest("check output page $i ($description)", + {$td->FILE => $actual}, + {$td->FILE => $expected}); + } +} + +$td->runtest("split shared font, xobject", + {$td->COMMAND => + "qpdf --static-id --qdf --no-original-object-ids" . + " --split-pages shared-font-xobject.pdf" . + " split-out-shared-font-xobject.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +foreach my $i (qw(1 2 3 4)) +{ + $td->runtest("check output ($i)", + {$td->FILE => "split-out-shared-font-xobject-$i.pdf"}, + {$td->FILE => "shared-font-xobject-split-$i.pdf"}); +} + +$td->runtest("unreferenced resources with bad token", + {$td->COMMAND => + "qpdf --qdf --static-id --split-pages=2" . + " --remove-unreferenced-resources=yes" . + " split-tokens.pdf split-out-bad-token.pdf"}, + {$td->FILE => "split-tokens-split.out", $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "split-out-bad-token-1-2.pdf"}, + {$td->FILE => "split-tokens-split-1-2.pdf"}); +$td->runtest("--no-warn with proxied warnings during split", + {$td->COMMAND => + "qpdf --qdf --static-id --split-pages=2" . + " --no-warn --remove-unreferenced-resources=yes" . + " split-tokens.pdf split-out-bad-token.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("shared images in form xobject", + {$td->COMMAND => "qpdf --qdf --static-id --split-pages". + " shared-form-images.pdf split-out-shared-form.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +foreach my $i (qw(1 2 3 4 5 6)) +{ + $td->runtest("check output ($i)", + {$td->FILE => "split-out-shared-form-$i.pdf"}, + {$td->FILE => "shared-form-split-$i.pdf"}); +} +$td->runtest("merge for compare", + {$td->COMMAND => "qpdf --static-id --empty --pages" . + " split-out-shared-form*.pdf -- a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "shared-form-images-merged.pdf"}); +compare_pdfs($td, "shared-form-images.pdf", "a.pdf"); + +$td->runtest("shared form xobject subkey", + {$td->COMMAND => "qpdf --qdf --static-id --split-pages". + " shared-form-images-xobject.pdf" . + " split-out-shared-form-xobject.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +foreach my $i (qw(1 2)) +{ + $td->runtest("check output ($i)", + {$td->FILE => "split-out-shared-form-xobject-$i.pdf"}, + {$td->FILE => "shared-form-xobject-split-$i.pdf"}); +} + +my @fo_resources = (['form-xobjects-no-resources', 1], + ['form-xobjects-some-resources1', 0], + ['form-xobjects-some-resources2', 0]); +foreach my $d (@fo_resources) +{ + my ($f, $compare) = @$d; + $td->runtest("split $f", + {$td->COMMAND => + "qpdf --empty --static-id --pages $f.pdf 1 --" . + " --remove-unreferenced-resources=yes a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + $td->runtest("check output ($f)", + {$td->FILE => "a.pdf"}, + {$td->FILE => "$f-out.pdf"}); + if ($compare) + { + compare_pdfs($td, "$f.pdf", "a.pdf"); + } +} + +cleanup(); +$td->report(calc_ntests($n_tests, $n_compare_pdfs)); diff --git a/qpdf/qtest/split_pages.test b/qpdf/qtest/split_pages.test deleted file mode 100644 index 05f8788d..00000000 --- a/qpdf/qtest/split_pages.test +++ /dev/null @@ -1,213 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; -use Digest::MD5; -use File::Copy; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('split_pages'); - -my $n_tests = 42; -my $n_compare_pdfs = 2; - -# sp = split-pages -my @sp_cases = ( - [11, '%d at beginning', '', '%d_split-out.zdf'], - [11, '%d at end', '--qdf', 'split-out.zdf_%d'], - [11, '%d in middle', '--allow-weak-crypto --encrypt u o 128 --', - 'a-%d-split-out.zdf'], - [11, 'pdf extension', '', 'split-out.Pdf'], - [4, 'fallback', '--pages 11-pages.pdf 1-3 minimal.pdf --', 'split-out'], - [1, 'broken data', '--pages broken-lzw.pdf --', 'split-out.pdf', - {$td->FILE => "broken-lzw.out", $td->EXIT_STATUS => 3}], - ); -for (@sp_cases) -{ - $n_tests += 1 + $_->[0]; -} - -$td->runtest("split page group > 1", - {$td->COMMAND => "qpdf --static-id --split-pages=5 11-pages.pdf" . - " --verbose split-out-group.pdf"}, - {$td->FILE => "split-pages-group.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -foreach my $f ('01-05', '06-10', '11-11') -{ - $td->runtest("check out group $f", - {$td->FILE => "split-out-group-$f.pdf"}, - {$td->FILE => "split-exp-group-$f.pdf"}); -} - -$td->runtest("no split-pages to stdout", - {$td->COMMAND => "qpdf --split-pages 11-pages.pdf -"}, - {$td->FILE => "split-pages-stdout.out", $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("split page with shared resources", - {$td->COMMAND => "qpdf --qdf --static-id --split-pages=4". - " shared-images.pdf split-out-shared.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -foreach my $i (qw(01-04 05-08 09-10)) -{ - $td->runtest("check output ($i)", - {$td->FILE => "split-out-shared-$i.pdf"}, - {$td->FILE => "shared-split-$i.pdf"}); -} - -$td->runtest("split page with labels", - {$td->COMMAND => "qpdf --qdf --static-id --split-pages=6". - " 11-pages-with-labels.pdf split-out-labels.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -foreach my $i (qw(01-06 07-11)) -{ - $td->runtest("check output ($i)", - {$td->FILE => "split-out-labels-$i.pdf"}, - {$td->FILE => "labels-split-$i.pdf"}); -} - -# See comments in TODO about these expected failures. Search for -# "split page with outlines". -$td->runtest("split page with outlines", - {$td->COMMAND => "qpdf --qdf --static-id --split-pages=10". - " outlines-with-actions.pdf split-out-outlines.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -foreach my $i (qw(01-10 11-20 21-30)) -{ - $td->runtest("check output ($i)", - {$td->FILE => "split-out-outlines-$i.pdf"}, - {$td->FILE => "outlines-split-$i.pdf"}, - $td->EXPECT_FAILURE) -} - -foreach my $d (@sp_cases) -{ - my ($n, $description, $xargs, $out, $exp) = @$d; - if (! defined $exp) - { - $exp = {$td->STRING => "", $td->EXIT_STATUS => 0}; - } - $td->runtest("split pages " . $description, - {$td->COMMAND => - "qpdf --static-id --split-pages 11-pages.pdf" . - " $xargs $out"}, - $exp, - $td->NORMALIZE_NEWLINES); - my $pattern = $out; - my $nlen = length($n); - if ($pattern =~ m/\%d/) - { - $pattern =~ s/\%d/\%0${nlen}d/; - } - elsif ($pattern =~ m/\.pdf$/i) - { - $pattern =~ s/(\.pdf$)/-%0${nlen}d$1/i; - } - else - { - $pattern .= "-%0${nlen}d"; - } - for (my $i = 1; $i <= $n; ++$i) - { - my $actual = sprintf($pattern, $i); - my $expected = $actual; - $expected =~ s/split-out/split-exp/; - $td->runtest("check output page $i ($description)", - {$td->FILE => $actual}, - {$td->FILE => $expected}); - } -} - -$td->runtest("split shared font, xobject", - {$td->COMMAND => - "qpdf --static-id --qdf --no-original-object-ids" . - " --split-pages shared-font-xobject.pdf" . - " split-out-shared-font-xobject.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -foreach my $i (qw(1 2 3 4)) -{ - $td->runtest("check output ($i)", - {$td->FILE => "split-out-shared-font-xobject-$i.pdf"}, - {$td->FILE => "shared-font-xobject-split-$i.pdf"}); -} - -$td->runtest("unreferenced resources with bad token", - {$td->COMMAND => - "qpdf --qdf --static-id --split-pages=2" . - " --remove-unreferenced-resources=yes" . - " split-tokens.pdf split-out-bad-token.pdf"}, - {$td->FILE => "split-tokens-split.out", $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "split-out-bad-token-1-2.pdf"}, - {$td->FILE => "split-tokens-split-1-2.pdf"}); -$td->runtest("--no-warn with proxied warnings during split", - {$td->COMMAND => - "qpdf --qdf --static-id --split-pages=2" . - " --no-warn --remove-unreferenced-resources=yes" . - " split-tokens.pdf split-out-bad-token.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("shared images in form xobject", - {$td->COMMAND => "qpdf --qdf --static-id --split-pages". - " shared-form-images.pdf split-out-shared-form.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -foreach my $i (qw(1 2 3 4 5 6)) -{ - $td->runtest("check output ($i)", - {$td->FILE => "split-out-shared-form-$i.pdf"}, - {$td->FILE => "shared-form-split-$i.pdf"}); -} -$td->runtest("merge for compare", - {$td->COMMAND => "qpdf --static-id --empty --pages" . - " split-out-shared-form*.pdf -- a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "shared-form-images-merged.pdf"}); -compare_pdfs($td, "shared-form-images.pdf", "a.pdf"); - -$td->runtest("shared form xobject subkey", - {$td->COMMAND => "qpdf --qdf --static-id --split-pages". - " shared-form-images-xobject.pdf" . - " split-out-shared-form-xobject.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -foreach my $i (qw(1 2)) -{ - $td->runtest("check output ($i)", - {$td->FILE => "split-out-shared-form-xobject-$i.pdf"}, - {$td->FILE => "shared-form-xobject-split-$i.pdf"}); -} - -my @fo_resources = (['form-xobjects-no-resources', 1], - ['form-xobjects-some-resources1', 0], - ['form-xobjects-some-resources2', 0]); -foreach my $d (@fo_resources) -{ - my ($f, $compare) = @$d; - $td->runtest("split $f", - {$td->COMMAND => - "qpdf --empty --static-id --pages $f.pdf 1 --" . - " --remove-unreferenced-resources=yes a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - $td->runtest("check output ($f)", - {$td->FILE => "a.pdf"}, - {$td->FILE => "$f-out.pdf"}); - if ($compare) - { - compare_pdfs($td, "$f.pdf", "a.pdf"); - } -} - -cleanup(); -$td->report(calc_ntests($n_tests, $n_compare_pdfs)); diff --git a/qpdf/qtest/stream-data.test b/qpdf/qtest/stream-data.test new file mode 100644 index 00000000..cd0b45c6 --- /dev/null +++ b/qpdf/qtest/stream-data.test @@ -0,0 +1,29 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('stream-data'); + +my $n_tests = 2; + +$td->runtest("get stream data", + {$td->COMMAND => "test_driver 11 stream-data.pdf"}, + {$td->FILE => "test11.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("get stream data fails on jpeg", + {$td->COMMAND => "test_driver 68 jpeg-qstream.pdf"}, + {$td->FILE => "test68.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/stream-line-terminators.test b/qpdf/qtest/stream-line-terminators.test new file mode 100644 index 00000000..80318897 --- /dev/null +++ b/qpdf/qtest/stream-line-terminators.test @@ -0,0 +1,31 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('stream-line-terminators'); + +my $n_tests = 2; + +$td->runtest("odd terminators for stream keyword", + {$td->COMMAND => + "qpdf --qdf --static-id" . + " stream-line-enders.pdf a.qdf"}, + {$td->FILE => "stream-line-enders.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.qdf"}, + {$td->FILE => "stream-line-enders.qdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/stream-replacements.test b/qpdf/qtest/stream-replacements.test new file mode 100644 index 00000000..8a9874dc --- /dev/null +++ b/qpdf/qtest/stream-replacements.test @@ -0,0 +1,56 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('stream-replacements'); + +my $n_tests = 10; + +$td->runtest("replace stream data", + {$td->COMMAND => "test_driver 7 qstream.pdf"}, + {$td->STRING => "test 7 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "replaced-stream-data.pdf"}); +$td->runtest("replace stream data compressed", + {$td->COMMAND => "test_driver 8 qstream.pdf"}, + {$td->FILE => "test8.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "replaced-stream-data-flate.pdf"}); +$td->runtest("new streams", + {$td->COMMAND => "test_driver 9 minimal.pdf"}, + {$td->FILE => "test9.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("new stream", + {$td->FILE => "a.pdf"}, + {$td->FILE => "new-streams.pdf"}); +$td->runtest("add page contents", + {$td->COMMAND => "test_driver 10 minimal.pdf"}, + {$td->STRING => "test 10 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("new stream", + {$td->FILE => "a.pdf"}, + {$td->FILE => "add-contents.pdf"}); +$td->runtest("functional replace stream data", + {$td->COMMAND => "test_driver 78 minimal.pdf"}, + {$td->FILE => "test78.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "test78.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/stream_data.test b/qpdf/qtest/stream_data.test deleted file mode 100644 index fdd91c3e..00000000 --- a/qpdf/qtest/stream_data.test +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('stream_data'); - -my $n_tests = 2; - -$td->runtest("get stream data", - {$td->COMMAND => "test_driver 11 stream-data.pdf"}, - {$td->FILE => "test11.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("get stream data fails on jpeg", - {$td->COMMAND => "test_driver 68 jpeg-qstream.pdf"}, - {$td->FILE => "test68.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/stream_line_terminators.test b/qpdf/qtest/stream_line_terminators.test deleted file mode 100644 index 3af93b42..00000000 --- a/qpdf/qtest/stream_line_terminators.test +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('stream_line_terminators'); - -my $n_tests = 2; - -$td->runtest("odd terminators for stream keyword", - {$td->COMMAND => - "qpdf --qdf --static-id" . - " stream-line-enders.pdf a.qdf"}, - {$td->FILE => "stream-line-enders.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.qdf"}, - {$td->FILE => "stream-line-enders.qdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/stream_replacements.test b/qpdf/qtest/stream_replacements.test deleted file mode 100644 index a67c8c03..00000000 --- a/qpdf/qtest/stream_replacements.test +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('stream_replacements'); - -my $n_tests = 10; - -$td->runtest("replace stream data", - {$td->COMMAND => "test_driver 7 qstream.pdf"}, - {$td->STRING => "test 7 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "replaced-stream-data.pdf"}); -$td->runtest("replace stream data compressed", - {$td->COMMAND => "test_driver 8 qstream.pdf"}, - {$td->FILE => "test8.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "replaced-stream-data-flate.pdf"}); -$td->runtest("new streams", - {$td->COMMAND => "test_driver 9 minimal.pdf"}, - {$td->FILE => "test9.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("new stream", - {$td->FILE => "a.pdf"}, - {$td->FILE => "new-streams.pdf"}); -$td->runtest("add page contents", - {$td->COMMAND => "test_driver 10 minimal.pdf"}, - {$td->STRING => "test 10 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("new stream", - {$td->FILE => "a.pdf"}, - {$td->FILE => "add-contents.pdf"}); -$td->runtest("functional replace stream data", - {$td->COMMAND => "test_driver 78 minimal.pdf"}, - {$td->FILE => "test78.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "test78.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/swap-and-replace.test b/qpdf/qtest/swap-and-replace.test new file mode 100644 index 00000000..fd136933 --- /dev/null +++ b/qpdf/qtest/swap-and-replace.test @@ -0,0 +1,37 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('swap-and-replace'); + +my $n_tests = 3; + +$td->runtest("swap and replace", + {$td->COMMAND => "test_driver 14 test14-in.pdf"}, + {$td->FILE => "test14.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "test14-out.pdf"}); + +# Most of the test suite uses static or deterministic ID. This test +# case exercises regular ID generation. Test 14 also exercises writing +# to memory without static ID. +$td->runtest("check non-static ID version", + {$td->COMMAND => "sh ./diff-ignore-ID-version a.pdf b.pdf"}, + {$td->STRING => "okay\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/swap_and_replace.test b/qpdf/qtest/swap_and_replace.test deleted file mode 100644 index c8b08d48..00000000 --- a/qpdf/qtest/swap_and_replace.test +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('swap_and_replace'); - -my $n_tests = 3; - -$td->runtest("swap and replace", - {$td->COMMAND => "test_driver 14 test14-in.pdf"}, - {$td->FILE => "test14.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "test14-out.pdf"}); - -# Most of the test suite uses static or deterministic ID. This test -# case exercises regular ID generation. Test 14 also exercises writing -# to memory without static ID. -$td->runtest("check non-static ID version", - {$td->COMMAND => "sh ./diff-ignore-ID-version a.pdf b.pdf"}, - {$td->STRING => "okay\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/token-filters.test b/qpdf/qtest/token-filters.test new file mode 100644 index 00000000..a209b808 --- /dev/null +++ b/qpdf/qtest/token-filters.test @@ -0,0 +1,28 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('token-filters'); + +my $n_tests = 2; + +$td->runtest("token filter", + {$td->COMMAND => "test_driver 41 coalesce.pdf"}, + {$td->STRING => "test 41 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "token-filters-out.pdf"}); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/token_filters.test b/qpdf/qtest/token_filters.test deleted file mode 100644 index 17d343ad..00000000 --- a/qpdf/qtest/token_filters.test +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('token_filters'); - -my $n_tests = 2; - -$td->runtest("token filter", - {$td->COMMAND => "test_driver 41 coalesce.pdf"}, - {$td->STRING => "test 41 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check output", - {$td->FILE => "a.pdf"}, - {$td->FILE => "token-filters-out.pdf"}); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/type-checks.test b/qpdf/qtest/type-checks.test new file mode 100644 index 00000000..03d75a6c --- /dev/null +++ b/qpdf/qtest/type-checks.test @@ -0,0 +1,48 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('type-checks'); + +my $n_tests = 5; + +# Whenever object-types.pdf is edited, object-types-os.pdf should be +# regenerated. +$td->runtest("ensure object-types-os is up-to-date", + {$td->COMMAND => + "qpdf" . + " --object-streams=generate" . + " --deterministic-id" . + " --stream-data=uncompress" . + " object-types.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}); +$td->runtest("check file", + {$td->FILE => "a.pdf"}, + {$td->FILE => "object-types-os.pdf"}); +$td->runtest("type checks", + {$td->COMMAND => "test_driver 42 object-types.pdf"}, + {$td->FILE => "object-types.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("type checks with object streams", + {$td->COMMAND => "test_driver 42 object-types-os.pdf"}, + {$td->FILE => "object-types-os.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("compound type checks", + {$td->COMMAND => "test_driver 82 object-types-os.pdf"}, + {$td->STRING => "test 82 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/type_checks.test b/qpdf/qtest/type_checks.test deleted file mode 100644 index 09047ca1..00000000 --- a/qpdf/qtest/type_checks.test +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('type_checks'); - -my $n_tests = 5; - -# Whenever object-types.pdf is edited, object-types-os.pdf should be -# regenerated. -$td->runtest("ensure object-types-os is up-to-date", - {$td->COMMAND => - "qpdf" . - " --object-streams=generate" . - " --deterministic-id" . - " --stream-data=uncompress" . - " object-types.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}); -$td->runtest("check file", - {$td->FILE => "a.pdf"}, - {$td->FILE => "object-types-os.pdf"}); -$td->runtest("type checks", - {$td->COMMAND => "test_driver 42 object-types.pdf"}, - {$td->FILE => "object-types.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("type checks with object streams", - {$td->COMMAND => "test_driver 42 object-types-os.pdf"}, - {$td->FILE => "object-types-os.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("compound type checks", - {$td->COMMAND => "test_driver 82 object-types-os.pdf"}, - {$td->STRING => "test 82 done\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/unicode-filenames.test b/qpdf/qtest/unicode-filenames.test new file mode 100644 index 00000000..2237b748 --- /dev/null +++ b/qpdf/qtest/unicode-filenames.test @@ -0,0 +1,36 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('unicode-filenames'); + +my $n_tests = 3; + +$td->runtest("create unicode filenames", + {$td->COMMAND => "test_unicode_filenames"}, + {$td->STRING => "created Unicode filenames\n", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +foreach my $d (['auto-ü', 1], ['auto-öπ', 2]) +{ + my ($u, $n) = @$d; + $td->runtest("unicode filename $u", + {$td->COMMAND => "qpdf --check $u.pdf"}, + {$td->FILE => "check-unicode-filename-$n.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +} + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/unicode-password.test b/qpdf/qtest/unicode-password.test new file mode 100644 index 00000000..eb78de42 --- /dev/null +++ b/qpdf/qtest/unicode-password.test @@ -0,0 +1,218 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('unicode-password'); + +my $n_tests = 0; +# $n_tests incremented below + +# Files with each of these passwords when properly encoded have been +# tested manually with multiple PDF viewers. Adobe Reader, chrome, +# xpdf, and gv can open all of them except R3 with "single-byte", +# which can be opened by xpdf and gv but not the others. As of +# 2019-01-19, okular and atril (evince) are not able to open R=6 files +# with Unicode passwords as generated by qpdf but can open the R=3 +# files. + +# [bits, password-or-password-name, write-encoding, actual-encoding, xargs, +# [[read-encoding, strict?, fail?, tried-others, xargs]]] +my @unicode_pw_cases = ( + [128, 'simple', 'pdf-doc', 'pdf-doc', '', + [['utf8', 0, 0, 1, ''], + ['utf8', 1, 1, 0, ''], + ['pdf-doc', 1, 0, 0, ''], + ]], + [128, 'simple', 'utf8', 'utf8', '--password-mode=bytes', + [['pdf-doc', 0, 0, 1, ''], + ['pdf-doc', 1, 1, 0, ''], + ['utf8', 1, 0, 0, ''], + ]], + [128, 'simple', 'utf8', 'pdf-doc', '--password-mode=unicode', + [['pdf-doc', 1, 0, 0, ''], + ]], + [128, 'simple', 'utf8', 'pdf-doc', '--password-mode=auto', + [['pdf-doc', 1, 0, 0, ''], + ]], + [128, 'single-byte', 'utf8', 'pdf-doc', '', + [['pdf-doc', 1, 0, 0, ''], + ['win-ansi', 0, 0, 1, ''], + ]], + [128, 'single-byte', 'utf8', 'pdf-doc', '--password-mode=unicode', + [['pdf-doc', 1, 0, 0, ''], + ['win-ansi', 0, 0, 1, ''], + ]], + [128, 'single-byte', 'win-ansi', '', '--password-mode=unicode', + "supplied password is not valid UTF-8\n", + ], + [128, 'single-byte', 'win-ansi', 'win-ansi', '', + [['win-ansi', 1, 0, 0, ''], + ]], + [128, 'single-byte', 'pdf-doc', 'pdf-doc', '', + [['pdf-doc', 1, 0, 0, ''], + ['win-ansi', 0, 0, 1, ''], + ['pdf-doc-hex', 1, 0, 0, '--password-mode=hex-bytes'], + ]], + [128, 'complex', 'utf8', '', '--password-mode=unicode', + "supplied password cannot be encoded for 40-bit or" . + " 128-bit encryption formats\n" + ], + [128, 'complex', 'utf8', 'utf8', '--password-mode=bytes', + [['utf8', 1, 0, 0, ''], + ]], + [256, 'single-byte', 'win-ansi', '', '--password-mode=unicode', + "supplied password is not valid UTF-8\n", + ], + [256, 'single-byte', 'win-ansi', '', '--password-mode=auto', + "supplied password is not a valid Unicode password, which is" . + " required for 256-bit encryption; to really use this password," . + " rerun with the --password-mode=bytes option\n", + ], + [256, 'single-byte', 'win-ansi', 'win-ansi', '--password-mode=bytes', + [['utf8', 0, 0, 1, ''], + ['utf8', 1, 1, 0, ''], + ['win-ansi', 1, 0, 0, ''], + ['win-ansi', 0, 0, 0, ''], + ['pdf-doc', 0, 0, 1, ''], + ['pdf-doc-hex', 0, 0, 1, '--password-mode=hex-bytes'], + ]], + [256, 'complex', 'utf8', 'utf8', '', + [['utf8', 1, 0, 0, ''], + ['utf8-hex', 1, 0, 0, '--password-mode=hex-bytes'], + ]], + [256, 'complex', 'utf8-hex', 'utf8', '--password-mode=hex-bytes', + [['utf8', 1, 0, 0, ''], + ['utf8-hex', 1, 0, 0, '--password-mode=hex-bytes'], + ]], + [256, 'complex', 'utf8', 'utf8', '--password-mode=unicode', + [['utf8', 1, 0, 0, ''], + ['password-arg-simple-utf8', 0, 1, 1, ''], + ]], + ); + +for my $d (@unicode_pw_cases) +{ + my $decode_cases = $d->[5]; + $n_tests += 1; + if (ref($decode_cases) eq 'ARRAY') + { + $n_tests += scalar(@$decode_cases); + } +} + +foreach my $d (@unicode_pw_cases) +{ + my ($bits, $pw, $w_encoding, $a_encoding, $xargs, $decode_cases) = @$d; + my $w_pfile = "password-bare-$pw-$w_encoding"; + my $upass; + if (-f $w_pfile) + { + $upass = '@' . $w_pfile; + } + else + { + $upass = "$pw"; + } + my $outbase = "unicode-pw-$bits-$pw-$w_encoding-$xargs"; + my $exp = ''; + if (ref($decode_cases) ne 'ARRAY') + { + $exp = "qpdf: $decode_cases"; + $decode_cases = []; + } + $td->runtest("encode $bits, $pw, $w_encoding", + {$td->COMMAND => + "qpdf $xargs --static-id --static-aes-iv" . + " --allow-weak-crypto" . + " --encrypt $upass o $bits -- minimal.pdf a.pdf"}, + {$td->STRING => $exp, $td->EXIT_STATUS => ($exp ? 2 : 0)}, + $td->NORMALIZE_NEWLINES); + foreach my $d2 (@$decode_cases) + { + my ($r_encoding, $strict, $xfail, $tried_others, $r_xargs) = @$d2; + my $r_pfile = "password-arg-$pw-$r_encoding"; + if (! -f $r_pfile) + { + $r_pfile = $r_encoding; + } + my $r_output = ""; + $r_output .= "trying other\n" if $tried_others; + if ($xfail) + { + $r_output .= "qpdf: a.pdf: invalid password\n"; + } + else + { + $r_output .= "R = " . ($bits == 128 ? '3' : '6') . "\n"; + open(F, "); + close(F); + $r_output .= "User password = $apw\n"; + } + $r_xargs .= $strict ? ' --suppress-password-recovery' : ''; + $td->runtest("decrypt $pw, $r_encoding, strict=$strict", + {$td->COMMAND => + "qpdf --show-encryption --verbose" . + " $r_xargs a.pdf \@$r_pfile", + $td->FILTER => "perl show-unicode-encryption.pl"}, + {$td->STRING => "$r_output", + $td->EXIT_STATUS => ($xfail ? 2 : 0)}, + $td->NORMALIZE_NEWLINES); + } +} + +$n_tests += 5; + +$td->runtest("bytes fallback warning", + {$td->COMMAND => + "qpdf --allow-weak-crypto" . + " --encrypt \@password-bare-complex-utf8 o 128 --" . + " minimal.pdf a.pdf"}, + {$td->FILE => "bytes-fallback.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +{ # local scope + my $r_output = ""; + $r_output .= "R = 3\n"; + open(F, "); + close(F); + $r_output .= "User password = $apw\n"; + $td->runtest("decrypt bytes fallback", + {$td->COMMAND => + "qpdf --show-encryption --verbose" . + " a.pdf \@password-arg-complex-utf8" . + " --password-mode=bytes", + $td->FILTER => "perl show-unicode-encryption.pl"}, + {$td->STRING => "$r_output", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +} + +# Exercise passing Unicode passwords via the command line. This tests +# wmain for Windows and assumes a UTF-8 locale for other platforms. +$td->runtest("Unicode at CLI", + {$td->COMMAND => + "qpdf --encrypt π ʬ 256 --" . + " minimal.pdf a.pdf"}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("Decrypt using user password", + {$td->COMMAND => "qpdf --show-encryption a.pdf --password=π"}, + {$td->FILE => "unicode-up.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("Decrypt using owner password", + {$td->COMMAND => "qpdf --show-encryption a.pdf --password=ʬ"}, + {$td->FILE => "unicode-op.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/unicode_filenames.test b/qpdf/qtest/unicode_filenames.test deleted file mode 100644 index 19590482..00000000 --- a/qpdf/qtest/unicode_filenames.test +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('unicode_filenames'); - -my $n_tests = 3; - -$td->runtest("create unicode filenames", - {$td->COMMAND => "test_unicode_filenames"}, - {$td->STRING => "created Unicode filenames\n", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -foreach my $d (['auto-ü', 1], ['auto-öπ', 2]) -{ - my ($u, $n) = @$d; - $td->runtest("unicode filename $u", - {$td->COMMAND => "qpdf --check $u.pdf"}, - {$td->FILE => "check-unicode-filename-$n.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -} - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/unicode_password.test b/qpdf/qtest/unicode_password.test deleted file mode 100644 index 2a80fea3..00000000 --- a/qpdf/qtest/unicode_password.test +++ /dev/null @@ -1,218 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('unicode_password'); - -my $n_tests = 0; -# $n_tests incremented below - -# Files with each of these passwords when properly encoded have been -# tested manually with multiple PDF viewers. Adobe Reader, chrome, -# xpdf, and gv can open all of them except R3 with "single-byte", -# which can be opened by xpdf and gv but not the others. As of -# 2019-01-19, okular and atril (evince) are not able to open R=6 files -# with Unicode passwords as generated by qpdf but can open the R=3 -# files. - -# [bits, password-or-password-name, write-encoding, actual-encoding, xargs, -# [[read-encoding, strict?, fail?, tried-others, xargs]]] -my @unicode_pw_cases = ( - [128, 'simple', 'pdf-doc', 'pdf-doc', '', - [['utf8', 0, 0, 1, ''], - ['utf8', 1, 1, 0, ''], - ['pdf-doc', 1, 0, 0, ''], - ]], - [128, 'simple', 'utf8', 'utf8', '--password-mode=bytes', - [['pdf-doc', 0, 0, 1, ''], - ['pdf-doc', 1, 1, 0, ''], - ['utf8', 1, 0, 0, ''], - ]], - [128, 'simple', 'utf8', 'pdf-doc', '--password-mode=unicode', - [['pdf-doc', 1, 0, 0, ''], - ]], - [128, 'simple', 'utf8', 'pdf-doc', '--password-mode=auto', - [['pdf-doc', 1, 0, 0, ''], - ]], - [128, 'single-byte', 'utf8', 'pdf-doc', '', - [['pdf-doc', 1, 0, 0, ''], - ['win-ansi', 0, 0, 1, ''], - ]], - [128, 'single-byte', 'utf8', 'pdf-doc', '--password-mode=unicode', - [['pdf-doc', 1, 0, 0, ''], - ['win-ansi', 0, 0, 1, ''], - ]], - [128, 'single-byte', 'win-ansi', '', '--password-mode=unicode', - "supplied password is not valid UTF-8\n", - ], - [128, 'single-byte', 'win-ansi', 'win-ansi', '', - [['win-ansi', 1, 0, 0, ''], - ]], - [128, 'single-byte', 'pdf-doc', 'pdf-doc', '', - [['pdf-doc', 1, 0, 0, ''], - ['win-ansi', 0, 0, 1, ''], - ['pdf-doc-hex', 1, 0, 0, '--password-mode=hex-bytes'], - ]], - [128, 'complex', 'utf8', '', '--password-mode=unicode', - "supplied password cannot be encoded for 40-bit or" . - " 128-bit encryption formats\n" - ], - [128, 'complex', 'utf8', 'utf8', '--password-mode=bytes', - [['utf8', 1, 0, 0, ''], - ]], - [256, 'single-byte', 'win-ansi', '', '--password-mode=unicode', - "supplied password is not valid UTF-8\n", - ], - [256, 'single-byte', 'win-ansi', '', '--password-mode=auto', - "supplied password is not a valid Unicode password, which is" . - " required for 256-bit encryption; to really use this password," . - " rerun with the --password-mode=bytes option\n", - ], - [256, 'single-byte', 'win-ansi', 'win-ansi', '--password-mode=bytes', - [['utf8', 0, 0, 1, ''], - ['utf8', 1, 1, 0, ''], - ['win-ansi', 1, 0, 0, ''], - ['win-ansi', 0, 0, 0, ''], - ['pdf-doc', 0, 0, 1, ''], - ['pdf-doc-hex', 0, 0, 1, '--password-mode=hex-bytes'], - ]], - [256, 'complex', 'utf8', 'utf8', '', - [['utf8', 1, 0, 0, ''], - ['utf8-hex', 1, 0, 0, '--password-mode=hex-bytes'], - ]], - [256, 'complex', 'utf8-hex', 'utf8', '--password-mode=hex-bytes', - [['utf8', 1, 0, 0, ''], - ['utf8-hex', 1, 0, 0, '--password-mode=hex-bytes'], - ]], - [256, 'complex', 'utf8', 'utf8', '--password-mode=unicode', - [['utf8', 1, 0, 0, ''], - ['password-arg-simple-utf8', 0, 1, 1, ''], - ]], - ); - -for my $d (@unicode_pw_cases) -{ - my $decode_cases = $d->[5]; - $n_tests += 1; - if (ref($decode_cases) eq 'ARRAY') - { - $n_tests += scalar(@$decode_cases); - } -} - -foreach my $d (@unicode_pw_cases) -{ - my ($bits, $pw, $w_encoding, $a_encoding, $xargs, $decode_cases) = @$d; - my $w_pfile = "password-bare-$pw-$w_encoding"; - my $upass; - if (-f $w_pfile) - { - $upass = '@' . $w_pfile; - } - else - { - $upass = "$pw"; - } - my $outbase = "unicode-pw-$bits-$pw-$w_encoding-$xargs"; - my $exp = ''; - if (ref($decode_cases) ne 'ARRAY') - { - $exp = "qpdf: $decode_cases"; - $decode_cases = []; - } - $td->runtest("encode $bits, $pw, $w_encoding", - {$td->COMMAND => - "qpdf $xargs --static-id --static-aes-iv" . - " --allow-weak-crypto" . - " --encrypt $upass o $bits -- minimal.pdf a.pdf"}, - {$td->STRING => $exp, $td->EXIT_STATUS => ($exp ? 2 : 0)}, - $td->NORMALIZE_NEWLINES); - foreach my $d2 (@$decode_cases) - { - my ($r_encoding, $strict, $xfail, $tried_others, $r_xargs) = @$d2; - my $r_pfile = "password-arg-$pw-$r_encoding"; - if (! -f $r_pfile) - { - $r_pfile = $r_encoding; - } - my $r_output = ""; - $r_output .= "trying other\n" if $tried_others; - if ($xfail) - { - $r_output .= "qpdf: a.pdf: invalid password\n"; - } - else - { - $r_output .= "R = " . ($bits == 128 ? '3' : '6') . "\n"; - open(F, "); - close(F); - $r_output .= "User password = $apw\n"; - } - $r_xargs .= $strict ? ' --suppress-password-recovery' : ''; - $td->runtest("decrypt $pw, $r_encoding, strict=$strict", - {$td->COMMAND => - "qpdf --show-encryption --verbose" . - " $r_xargs a.pdf \@$r_pfile", - $td->FILTER => "perl show-unicode-encryption.pl"}, - {$td->STRING => "$r_output", - $td->EXIT_STATUS => ($xfail ? 2 : 0)}, - $td->NORMALIZE_NEWLINES); - } -} - -$n_tests += 5; - -$td->runtest("bytes fallback warning", - {$td->COMMAND => - "qpdf --allow-weak-crypto" . - " --encrypt \@password-bare-complex-utf8 o 128 --" . - " minimal.pdf a.pdf"}, - {$td->FILE => "bytes-fallback.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -{ # local scope - my $r_output = ""; - $r_output .= "R = 3\n"; - open(F, "); - close(F); - $r_output .= "User password = $apw\n"; - $td->runtest("decrypt bytes fallback", - {$td->COMMAND => - "qpdf --show-encryption --verbose" . - " a.pdf \@password-arg-complex-utf8" . - " --password-mode=bytes", - $td->FILTER => "perl show-unicode-encryption.pl"}, - {$td->STRING => "$r_output", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -} - -# Exercise passing Unicode passwords via the command line. This tests -# wmain for Windows and assumes a UTF-8 locale for other platforms. -$td->runtest("Unicode at CLI", - {$td->COMMAND => - "qpdf --encrypt π ʬ 256 --" . - " minimal.pdf a.pdf"}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("Decrypt using user password", - {$td->COMMAND => "qpdf --show-encryption a.pdf --password=π"}, - {$td->FILE => "unicode-up.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("Decrypt using owner password", - {$td->COMMAND => "qpdf --show-encryption a.pdf --password=ʬ"}, - {$td->FILE => "unicode-op.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/weak-cryptography.test b/qpdf/qtest/weak-cryptography.test new file mode 100644 index 00000000..10e72f27 --- /dev/null +++ b/qpdf/qtest/weak-cryptography.test @@ -0,0 +1,40 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('weak-cryptography-cryptography'); + +my $n_tests = 4; + +$td->runtest("256-bit: no warning", + {$td->COMMAND => 'qpdf --encrypt "" "" 256 -- minimal.pdf a.pdf'}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("128-bit with AES: no warning", + {$td->COMMAND => 'qpdf --encrypt "" "" 128 --use-aes=y --' . + ' minimal.pdf a.pdf'}, + {$td->STRING => "", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("128-bit without AES: error", + {$td->COMMAND => 'qpdf --encrypt "" "" 128 -- minimal.pdf a.pdf'}, + {$td->REGEXP => "Pass --allow-weak-crypto to enable", + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); +$td->runtest("40-bit: error", + {$td->COMMAND => 'qpdf --encrypt "" "" 40 -- minimal.pdf a.pdf'}, + {$td->REGEXP => "Pass --allow-weak-crypto to enable", + $td->EXIT_STATUS => 2}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/weak_cryptography.test b/qpdf/qtest/weak_cryptography.test deleted file mode 100644 index c7491a0e..00000000 --- a/qpdf/qtest/weak_cryptography.test +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('weak_cryptography_cryptography'); - -my $n_tests = 4; - -$td->runtest("256-bit: no warning", - {$td->COMMAND => 'qpdf --encrypt "" "" 256 -- minimal.pdf a.pdf'}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("128-bit with AES: no warning", - {$td->COMMAND => 'qpdf --encrypt "" "" 128 --use-aes=y --' . - ' minimal.pdf a.pdf'}, - {$td->STRING => "", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("128-bit without AES: error", - {$td->COMMAND => 'qpdf --encrypt "" "" 128 -- minimal.pdf a.pdf'}, - {$td->REGEXP => "Pass --allow-weak-crypto to enable", - $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); -$td->runtest("40-bit: error", - {$td->COMMAND => 'qpdf --encrypt "" "" 40 -- minimal.pdf a.pdf'}, - {$td->REGEXP => "Pass --allow-weak-crypto to enable", - $td->EXIT_STATUS => 2}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/windows-shell-globbing.test b/qpdf/qtest/windows-shell-globbing.test new file mode 100644 index 00000000..d2b7851d --- /dev/null +++ b/qpdf/qtest/windows-shell-globbing.test @@ -0,0 +1,25 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('windows-shell-globbing'); + +my $n_tests = 1; + +$td->runtest("shell wildcard expansion", + {$td->COMMAND => "test_shell_glob 'good*.pdf'"}, + {$td->STRING => "PASSED\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/windows_shell_globbing.test b/qpdf/qtest/windows_shell_globbing.test deleted file mode 100644 index bd58c1eb..00000000 --- a/qpdf/qtest/windows_shell_globbing.test +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('windows_shell_globbing'); - -my $n_tests = 1; - -$td->runtest("shell wildcard expansion", - {$td->COMMAND => "test_shell_glob 'good*.pdf'"}, - {$td->STRING => "PASSED\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/writer-version.test b/qpdf/qtest/writer-version.test new file mode 100644 index 00000000..a491065c --- /dev/null +++ b/qpdf/qtest/writer-version.test @@ -0,0 +1,58 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('writer-version'); + +my $n_tests = 7; + +# Min/Force version +$td->runtest("set min version", + {$td->COMMAND => "qpdf --verbose --min-version=1.6 good1.pdf a.pdf"}, + {$td->STRING => "qpdf: wrote file a.pdf\n", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check version", + {$td->COMMAND => "qpdf --check a.pdf"}, + {$td->FILE => "min-version.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("force version", + {$td->COMMAND => "qpdf --force-version=1.4 a.pdf b.pdf"}, + {$td->STRING => "", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check version", + {$td->COMMAND => "qpdf --check b.pdf"}, + {$td->FILE => "forced-version.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +unlink "a.pdf", "b.pdf" or die; +$td->runtest("C API: min/force versions", + {$td->COMMAND => "qpdf-ctest 14 object-stream.pdf '' a.pdf b.pdf"}, + {$td->STRING => "C test 14 done\n", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("C check version 1", + {$td->COMMAND => "qpdf-ctest 1 a.pdf '' ''"}, + {$td->FILE => "c-min-version.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("C check version 2", + {$td->COMMAND => "qpdf --check b.pdf"}, + {$td->FILE => "forced-version.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/writer_version.test b/qpdf/qtest/writer_version.test deleted file mode 100644 index fc208e63..00000000 --- a/qpdf/qtest/writer_version.test +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('writer_version'); - -my $n_tests = 7; - -# Min/Force version -$td->runtest("set min version", - {$td->COMMAND => "qpdf --verbose --min-version=1.6 good1.pdf a.pdf"}, - {$td->STRING => "qpdf: wrote file a.pdf\n", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check version", - {$td->COMMAND => "qpdf --check a.pdf"}, - {$td->FILE => "min-version.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("force version", - {$td->COMMAND => "qpdf --force-version=1.4 a.pdf b.pdf"}, - {$td->STRING => "", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("check version", - {$td->COMMAND => "qpdf --check b.pdf"}, - {$td->FILE => "forced-version.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -unlink "a.pdf", "b.pdf" or die; -$td->runtest("C API: min/force versions", - {$td->COMMAND => "qpdf-ctest 14 object-stream.pdf '' a.pdf b.pdf"}, - {$td->STRING => "C test 14 done\n", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("C check version 1", - {$td->COMMAND => "qpdf-ctest 1 a.pdf '' ''"}, - {$td->FILE => "c-min-version.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -$td->runtest("C check version 2", - {$td->COMMAND => "qpdf --check b.pdf"}, - {$td->FILE => "forced-version.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/xref-errors.test b/qpdf/qtest/xref-errors.test new file mode 100644 index 00000000..9db27114 --- /dev/null +++ b/qpdf/qtest/xref-errors.test @@ -0,0 +1,66 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('xref-errors'); + +my $n_tests = 6; + +# Handle file with invalid xref table and object 0 as a regular object +# (bug 3159950). +$td->runtest("check obj0.pdf", + {$td->COMMAND => "qpdf --check obj0.pdf"}, + {$td->FILE => "obj0-check.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); + +# Demonstrate show-xref after check and not after check to illustrate +# that it can dump the real xref or the recovered xref. +$td->runtest("dump bad xref", + {$td->COMMAND => "qpdf --show-xref bad-xref-entry.pdf"}, + {$td->FILE => "bad-xref-entry.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +# Test @file here too. +open(F, ">args") or die; +print F "--check\n"; +print F "--show-xref\n"; +close(F); +$td->runtest("dump corrected bad xref", + {$td->COMMAND => "qpdf \@args bad-xref-entry.pdf"}, + {$td->FILE => "bad-xref-entry-corrected.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +unlink "args"; + +$td->runtest("combine show and --pages", + {$td->COMMAND => + "qpdf --empty --pages minimal.pdf -- --show-pages"}, + {$td->FILE => "show-pages-pages.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +$td->runtest("show number of pages", + {$td->COMMAND => + "qpdf --show-npages 20-pages.pdf --password=user"}, + {$td->STRING => "20\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +# Issue 482 -- don't range check fields[2] for xref entry type 0. +$td->runtest("out of range in deleted object", + {$td->COMMAND => "qpdf --check xref-range.pdf"}, + {$td->FILE => "xref-range.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/xref-streams.test b/qpdf/qtest/xref-streams.test new file mode 100644 index 00000000..10a32763 --- /dev/null +++ b/qpdf/qtest/xref-streams.test @@ -0,0 +1,37 @@ +#!/usr/bin/env perl +require 5.008; +use warnings; +use strict; + +unshift(@INC, '.'); +require qpdf_test_helpers; + +chdir("qpdf") or die "chdir testdir failed: $!\n"; + +require TestDriver; + +cleanup(); + +my $td = new TestDriver('xref-streams'); + +my $n_tests = 3; + +# Handle xref stream with more entries than reported (bug 2872265) +$td->runtest("xref with short size", + {$td->COMMAND => "qpdf --show-xref xref-with-short-size.pdf"}, + {$td->FILE => "xref-with-short-size.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("recover xref with short size", + {$td->COMMAND => "qpdf xref-with-short-size.pdf a.pdf"}, + {$td->FILE => "xref-with-short-size-recover.out", + $td->EXIT_STATUS => 3}, + $td->NORMALIZE_NEWLINES); +$td->runtest("show new xref stream", + {$td->COMMAND => "qpdf --show-xref a.pdf"}, + {$td->FILE => "xref-with-short-size-new.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); + +cleanup(); +$td->report($n_tests); diff --git a/qpdf/qtest/xref_errors.test b/qpdf/qtest/xref_errors.test deleted file mode 100644 index 4eb8cd37..00000000 --- a/qpdf/qtest/xref_errors.test +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('xref_errors'); - -my $n_tests = 6; - -# Handle file with invalid xref table and object 0 as a regular object -# (bug 3159950). -$td->runtest("check obj0.pdf", - {$td->COMMAND => "qpdf --check obj0.pdf"}, - {$td->FILE => "obj0-check.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); - -# Demonstrate show-xref after check and not after check to illustrate -# that it can dump the real xref or the recovered xref. -$td->runtest("dump bad xref", - {$td->COMMAND => "qpdf --show-xref bad-xref-entry.pdf"}, - {$td->FILE => "bad-xref-entry.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); -# Test @file here too. -open(F, ">args") or die; -print F "--check\n"; -print F "--show-xref\n"; -close(F); -$td->runtest("dump corrected bad xref", - {$td->COMMAND => "qpdf \@args bad-xref-entry.pdf"}, - {$td->FILE => "bad-xref-entry-corrected.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -unlink "args"; - -$td->runtest("combine show and --pages", - {$td->COMMAND => - "qpdf --empty --pages minimal.pdf -- --show-pages"}, - {$td->FILE => "show-pages-pages.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -$td->runtest("show number of pages", - {$td->COMMAND => - "qpdf --show-npages 20-pages.pdf --password=user"}, - {$td->STRING => "20\n", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -# Issue 482 -- don't range check fields[2] for xref entry type 0. -$td->runtest("out of range in deleted object", - {$td->COMMAND => "qpdf --check xref-range.pdf"}, - {$td->FILE => "xref-range.out", $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); diff --git a/qpdf/qtest/xref_streams.test b/qpdf/qtest/xref_streams.test deleted file mode 100644 index 46808869..00000000 --- a/qpdf/qtest/xref_streams.test +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env perl -require 5.008; -use warnings; -use strict; - -unshift(@INC, '.'); -require qpdf_test_helpers; - -chdir("qpdf") or die "chdir testdir failed: $!\n"; - -require TestDriver; - -cleanup(); - -my $td = new TestDriver('xref_streams'); - -my $n_tests = 3; - -# Handle xref stream with more entries than reported (bug 2872265) -$td->runtest("xref with short size", - {$td->COMMAND => "qpdf --show-xref xref-with-short-size.pdf"}, - {$td->FILE => "xref-with-short-size.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("recover xref with short size", - {$td->COMMAND => "qpdf xref-with-short-size.pdf a.pdf"}, - {$td->FILE => "xref-with-short-size-recover.out", - $td->EXIT_STATUS => 3}, - $td->NORMALIZE_NEWLINES); -$td->runtest("show new xref stream", - {$td->COMMAND => "qpdf --show-xref a.pdf"}, - {$td->FILE => "xref-with-short-size-new.out", - $td->EXIT_STATUS => 0}, - $td->NORMALIZE_NEWLINES); - -cleanup(); -$td->report($n_tests); -- cgit v1.2.3-54-g00ecf