Commit 3470c5f1c809bb012bef10914ccb081a45d0d2ab
Committed by
m-holger
1 parent
dacabd3b
Add unit tests for compression handling on empty streams
Showing
3 changed files
with
81 additions
and
1 deletions
qpdf/qtest/object-stream.test
| @@ -16,7 +16,7 @@ cleanup(); | @@ -16,7 +16,7 @@ cleanup(); | ||
| 16 | 16 | ||
| 17 | my $td = new TestDriver('object-stream'); | 17 | my $td = new TestDriver('object-stream'); |
| 18 | 18 | ||
| 19 | -my $n_tests = 10 + (36 * 4) + (12 * 2); | 19 | +my $n_tests = 10 + (36 * 4) + (12 * 2) + 4; |
| 20 | my $n_compare_pdfs = 36; | 20 | my $n_compare_pdfs = 36; |
| 21 | 21 | ||
| 22 | for (my $n = 16; $n <= 19; ++$n) | 22 | for (my $n = 16; $n <= 19; ++$n) |
| @@ -126,5 +126,23 @@ $td->runtest("adjacent compressed objects", | @@ -126,5 +126,23 @@ $td->runtest("adjacent compressed objects", | ||
| 126 | $td->EXIT_STATUS => 0}, | 126 | $td->EXIT_STATUS => 0}, |
| 127 | $td->NORMALIZE_NEWLINES); | 127 | $td->NORMALIZE_NEWLINES); |
| 128 | 128 | ||
| 129 | +# Never compress empty streams | ||
| 130 | +$td->runtest("never compress empty streams", | ||
| 131 | + {$td->COMMAND => "qpdf --compress-streams=y --static-id" . | ||
| 132 | + " empty-stream-uncompressed.pdf a.pdf"}, | ||
| 133 | + {$td->STRING => "", $td->EXIT_STATUS => 0}); | ||
| 134 | +$td->runtest("check file", | ||
| 135 | + {$td->FILE => "a.pdf"}, | ||
| 136 | + {$td->FILE => "empty-stream-uncompressed.pdf"}); | ||
| 137 | + | ||
| 138 | +# Always remove filters from compressed empty streams | ||
| 139 | +$td->runtest("always remove filters from empty streams", | ||
| 140 | + {$td->COMMAND => "qpdf --compress-streams=y --static-id" . | ||
| 141 | + " empty-stream-compressed.pdf a.pdf"}, | ||
| 142 | + {$td->STRING => "", $td->EXIT_STATUS => 0}); | ||
| 143 | +$td->runtest("check file", | ||
| 144 | + {$td->FILE => "a.pdf"}, | ||
| 145 | + {$td->FILE => "empty-stream-uncompressed.pdf"}); | ||
| 146 | + | ||
| 129 | cleanup(); | 147 | cleanup(); |
| 130 | $td->report(calc_ntests($n_tests, $n_compare_pdfs)); | 148 | $td->report(calc_ntests($n_tests, $n_compare_pdfs)); |
qpdf/qtest/qpdf/empty-stream-compressed.pdf
0 → 100644
| 1 | +%PDF-1.4 | ||
| 2 | +%¿÷¢þ | ||
| 3 | +1 0 obj | ||
| 4 | +<< /Pages 3 0 R /Type /Catalog /ViewerPreferences << /DisplayDocTitle true /Type /ViewerPreferences >> >> | ||
| 5 | +endobj | ||
| 6 | +2 0 obj | ||
| 7 | +<< /CreationDate (D:20250409064524+00'00') /Creator (Mozilla/5.0 \(X11; Linux x86_64\) AppleWebKit/537.36 \(KHTML, like Gecko\) Chrome/135.0.0.0 Safari/537.36) /ModDate (D:20250409064524+00'00') /Producer (Skia/PDF m135) /Title (about:blank) >> | ||
| 8 | +endobj | ||
| 9 | +3 0 obj | ||
| 10 | +<< /Count 1 /Kids [ 4 0 R ] /Type /Pages >> | ||
| 11 | +endobj | ||
| 12 | +4 0 obj | ||
| 13 | +<< /Contents 5 0 R /MediaBox [ 0 0 594.95996 841.91998 ] /Parent 3 0 R /Resources << /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /StructParents 0 /Tabs /S /Type /Page >> | ||
| 14 | +endobj | ||
| 15 | +5 0 obj | ||
| 16 | +<< /Length 0 /Filter /FlateDecode >> | ||
| 17 | +stream | ||
| 18 | +endstream | ||
| 19 | +endobj | ||
| 20 | +xref | ||
| 21 | +0 6 | ||
| 22 | +0000000000 65535 f | ||
| 23 | +0000000015 00000 n | ||
| 24 | +0000000136 00000 n | ||
| 25 | +0000000396 00000 n | ||
| 26 | +0000000455 00000 n | ||
| 27 | +0000000647 00000 n | ||
| 28 | +trailer << /Info 2 0 R /Root 1 0 R /Size 6 /ID [<c1d8baf5144c3a51530c879d5c908f31><31415926535897932384626433832795>] >> | ||
| 29 | +startxref | ||
| 30 | +716 | ||
| 31 | +%%EOF |
qpdf/qtest/qpdf/empty-stream-uncompressed.pdf
0 → 100644
| 1 | +%PDF-1.4 | ||
| 2 | +%¿÷¢þ | ||
| 3 | +1 0 obj | ||
| 4 | +<< /Pages 3 0 R /Type /Catalog /ViewerPreferences << /DisplayDocTitle true /Type /ViewerPreferences >> >> | ||
| 5 | +endobj | ||
| 6 | +2 0 obj | ||
| 7 | +<< /CreationDate (D:20250409064524+00'00') /Creator (Mozilla/5.0 \(X11; Linux x86_64\) AppleWebKit/537.36 \(KHTML, like Gecko\) Chrome/135.0.0.0 Safari/537.36) /ModDate (D:20250409064524+00'00') /Producer (Skia/PDF m135) /Title (about:blank) >> | ||
| 8 | +endobj | ||
| 9 | +3 0 obj | ||
| 10 | +<< /Count 1 /Kids [ 4 0 R ] /Type /Pages >> | ||
| 11 | +endobj | ||
| 12 | +4 0 obj | ||
| 13 | +<< /Contents 5 0 R /MediaBox [ 0 0 594.95996 841.91998 ] /Parent 3 0 R /Resources << /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /StructParents 0 /Tabs /S /Type /Page >> | ||
| 14 | +endobj | ||
| 15 | +5 0 obj | ||
| 16 | +<< /Length 0 >> | ||
| 17 | +stream | ||
| 18 | +endstream | ||
| 19 | +endobj | ||
| 20 | +xref | ||
| 21 | +0 6 | ||
| 22 | +0000000000 65535 f | ||
| 23 | +0000000015 00000 n | ||
| 24 | +0000000136 00000 n | ||
| 25 | +0000000396 00000 n | ||
| 26 | +0000000455 00000 n | ||
| 27 | +0000000647 00000 n | ||
| 28 | +trailer << /Info 2 0 R /Root 1 0 R /Size 6 /ID [<c1d8baf5144c3a51530c879d5c908f31><31415926535897932384626433832795>] >> | ||
| 29 | +startxref | ||
| 30 | +695 | ||
| 31 | +%%EOF |