2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 10:58:58 +00:00

Remove compression from linearization tests where possible

By combining --linearize with --compress-streams=n, we ensure that no
new compressed data will appear in linearized output, which makes the
output independent of zlib's output. There are other tests to ensure
that linearization works correctly with compression. This commit
involves changing some test outputs and test code as well just
updating test suites.
This commit is contained in:
Jay Berkenbilt 2023-12-20 13:37:21 -05:00
parent 7e679ab8b6
commit 4ee393d1fa
18 changed files with 16 additions and 5 deletions

View File

@ -44,6 +44,7 @@ main(int argc, char* argv[])
->endPages() ->endPages()
->linearize() ->linearize()
->staticId() // for testing only ->staticId() // for testing only
->compressStreams("n") // avoid dependency on zlib output
->checkConfiguration(); ->checkConfiguration();
j.run(); j.run();
std::cout << "out1 status: " << j.getExitCode() << std::endl; std::cout << "out1 status: " << j.getExitCode() << std::endl;
@ -63,6 +64,7 @@ main(int argc, char* argv[])
"1", "1",
"--", "--",
"--static-id", "--static-id",
"--compress-streams=n", // avoid dependency on zlib output
nullptr}; nullptr};
QPDFJob j; QPDFJob j;
j.initializeFromArgv(new_argv); j.initializeFromArgv(new_argv);
@ -81,6 +83,7 @@ main(int argc, char* argv[])
"outputFile": "out3.pdf", "outputFile": "out3.pdf",
"staticId": "", "staticId": "",
"linearize": "", "linearize": "",
"compressStreams": "n",
"pages": [ "pages": [
{ {
"file": ".", "file": ".",

View File

@ -19,7 +19,7 @@ main(int argc, char* argv[])
{ {
char* infile = NULL; char* infile = NULL;
char* outfile = NULL; char* outfile = NULL;
char const* new_argv[6]; char const* new_argv[7];
int r = 0; int r = 0;
char* p = 0; char* p = 0;
@ -43,7 +43,8 @@ main(int argc, char* argv[])
new_argv[2] = outfile; new_argv[2] = outfile;
new_argv[3] = "--linearize"; new_argv[3] = "--linearize";
new_argv[4] = "--static-id"; /* for testing only */ new_argv[4] = "--static-id"; /* for testing only */
new_argv[5] = NULL; new_argv[5] = "--compress-streams=n"; /* avoid dependency on zlib output */
new_argv[6] = NULL;
/* See qpdf-job.cc for a C++ example of using the json interface. To use that from C just like /* See qpdf-job.cc for a C++ example of using the json interface. To use that from C just like
* the argv one, call qpdfjob_run_from_json instead and pass the json string as a single char * the argv one, call qpdfjob_run_from_json instead and pass the json string as a single char

Binary file not shown.

View File

@ -200,6 +200,7 @@ test05(char const* infile, char const* password, char const* outfile, char const
qpdf_register_progress_reporter(qpdf, count_progress, (void*)&count); qpdf_register_progress_reporter(qpdf, count_progress, (void*)&count);
qpdf_set_static_ID(qpdf, QPDF_TRUE); qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_linearization(qpdf, QPDF_TRUE); qpdf_set_linearization(qpdf, QPDF_TRUE);
qpdf_set_compress_streams(qpdf, QPDF_FALSE); // Don't depend on zlib
qpdf_write(qpdf); qpdf_write(qpdf);
/* make sure progress reporter was called */ /* make sure progress reporter was called */
assert(count > 0); assert(count > 0);

View File

@ -37,7 +37,8 @@ foreach my $file (qw(short-id long-id))
$td->runtest("linearize $file.pdf", $td->runtest("linearize $file.pdf",
{$td->COMMAND => {$td->COMMAND =>
"qpdf --deterministic-id --linearize $file.pdf a.pdf"}, "qpdf --deterministic-id --compress-streams=n" .
" --linearize $file.pdf a.pdf"},
{$td->STRING => "", {$td->STRING => "",
$td->EXIT_STATUS => 0}, $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES); $td->NORMALIZE_NEWLINES);

View File

@ -18,6 +18,7 @@ my $n_tests = 3;
$td->runtest("linearize pass 1 file", $td->runtest("linearize pass 1 file",
{$td->COMMAND => "qpdf --linearize --static-id" . {$td->COMMAND => "qpdf --linearize --static-id" .
" --compress-streams=n" .
" --linearize-pass1=b.pdf minimal.pdf a.pdf"}, " --linearize-pass1=b.pdf minimal.pdf a.pdf"},
{$td->STRING => "", $td->EXIT_STATUS => 0}); {$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check output", $td->runtest("check output",

View File

@ -18,7 +18,7 @@ my $n_tests = 17;
$td->runtest("linearize duplicated pages", $td->runtest("linearize duplicated pages",
{$td->COMMAND => {$td->COMMAND =>
"qpdf --static-id --linearize" . "qpdf --static-id --linearize --compress-streams=n" .
" page_api_2.pdf a.pdf"}, " page_api_2.pdf a.pdf"},
{$td->FILE => "duplicate-page-warning.out", {$td->FILE => "duplicate-page-warning.out",
$td->EXIT_STATUS => 3}, $td->EXIT_STATUS => 3},

Binary file not shown.

View File

@ -47,7 +47,8 @@ $td->runtest("check fix-qdf idempotency",
{$td->FILE => "a.pdf", $td->EXIT_STATUS => 0}); {$td->FILE => "a.pdf", $td->EXIT_STATUS => 0});
$td->runtest("pages points to page", $td->runtest("pages points to page",
{$td->COMMAND => {$td->COMMAND =>
"qpdf --static-id --linearize pages-is-page.pdf a.pdf"}, "qpdf --static-id --linearize --compress-streams=n" .
" pages-is-page.pdf a.pdf"},
{$td->FILE => "pages-is-page.out", $td->EXIT_STATUS => 3}, {$td->FILE => "pages-is-page.out", $td->EXIT_STATUS => 3},
$td->NORMALIZE_NEWLINES); $td->NORMALIZE_NEWLINES);
$td->runtest("check output", $td->runtest("check output",

View File

@ -1211,6 +1211,9 @@ test_32(QPDF& pdf, char const* arg2)
<< "linearized: " << (linearized ? "yes" : "no") << std::endl << "linearized: " << (linearized ? "yes" : "no") << std::endl
<< "newline: " << (newline ? "yes" : "no") << std::endl; << "newline: " << (newline ? "yes" : "no") << std::endl;
w.setLinearization(linearized); w.setLinearization(linearized);
if (linearized) {
w.setCompressStreams(false); // avoid dependency on zlib's output
}
w.setExtraHeaderText(newline ? "%% Comment with newline\n" : "%% Comment\n% No newline"); w.setExtraHeaderText(newline ? "%% Comment with newline\n" : "%% Comment\n% No newline");
w.write(); w.write();
} }