diff options
author | Jay Berkenbilt <ejb@ql.org> | 2010-08-03 04:29:15 +0200 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2010-08-03 04:29:15 +0200 |
commit | 98765c3b5ceecb2c2540405eab1dd7ae1f02ec31 (patch) | |
tree | da9c53c8af06df58c7dddae7545b7737655fce2a /qpdf | |
parent | 998a6cbee911ee8d49b2ce2f24e0cb4898289492 (diff) | |
download | qpdf-98765c3b5ceecb2c2540405eab1dd7ae1f02ec31.tar.zst |
tested basic stream replacement
git-svn-id: svn+q:///qpdf/trunk@989 71b93d88-0707-0410-a8cf-f5a4172ac649
Diffstat (limited to 'qpdf')
-rw-r--r-- | qpdf/qtest/qpdf.test | 18 | ||||
-rw-r--r-- | qpdf/qtest/qpdf/qstream.pdf | 90 | ||||
-rw-r--r-- | qpdf/qtest/qpdf/replaced-stream-data-flate.out | bin | 0 -> 907 bytes | |||
-rw-r--r-- | qpdf/qtest/qpdf/replaced-stream-data.out | 47 | ||||
-rw-r--r-- | qpdf/test_driver.cc | 40 |
5 files changed, 194 insertions, 1 deletions
diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index 2ac2c112..69c4776e 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -77,7 +77,7 @@ flush_tiff_cache(); show_ntests(); # ---------- $td->notify("--- Miscellaneous Tests ---"); -$n_tests += 22; +$n_tests += 26; $td->runtest("qpdf version", {$td->COMMAND => "qpdf --version"}, @@ -97,6 +97,22 @@ foreach (my $i = 1; $i <= 3; ++$i) $td->NORMALIZE_NEWLINES); } +$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.out"}); + +$td->runtest("replace stream data compressed", + {$td->COMMAND => "test_driver 8 qstream.pdf"}, + {$td->STRING => "test 8 done\n", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +$td->runtest("check output", + {$td->FILE => "a.pdf"}, + {$td->FILE => "replaced-stream-data-flate.out"}); + # Make sure we ignore decode parameters that we don't understand $td->runtest("unknown decode parameters", {$td->COMMAND => "qpdf --check fax-decode-parms.pdf"}, diff --git a/qpdf/qtest/qpdf/qstream.pdf b/qpdf/qtest/qpdf/qstream.pdf new file mode 100644 index 00000000..63989459 --- /dev/null +++ b/qpdf/qtest/qpdf/qstream.pdf @@ -0,0 +1,90 @@ +%PDF-1.3 +1 0 obj +<< + /Type /Catalog + /Pages 2 0 R + /QStream 7 0 R +>> +endobj + +2 0 obj +<< + /Type /Pages + /Kids [ + 3 0 R + ] + /Count 1 +>> +endobj + +3 0 obj +<< + /Type /Page + /Parent 2 0 R + /MediaBox [0 0 612 792] + /Contents 4 0 R + /Resources << + /ProcSet 5 0 R + /Font << + /F1 6 0 R + >> + >> +>> +endobj + +4 0 obj +<< + /Length 44 +>> +stream +BT + /F1 24 Tf + 72 720 Td + (Potato) Tj +ET +endstream +endobj + +5 0 obj +[ + /PDF + /Text +] +endobj + +6 0 obj +<< + /Type /Font + /Subtype /Type1 + /Name /F1 + /BaseFont /Helvetica + /Encoding /WinAnsiEncoding +>> +endobj + +7 0 obj +<< + /Length 29 +>> +stream +This is the old stream data. +endstream +endobj + +xref +0 8 +0000000000 65535 f +0000000009 00000 n +0000000080 00000 n +0000000152 00000 n +0000000324 00000 n +0000000420 00000 n +0000000455 00000 n +0000000573 00000 n +trailer << + /Size 8 + /Root 1 0 R +>> +startxref +654 +%%EOF diff --git a/qpdf/qtest/qpdf/replaced-stream-data-flate.out b/qpdf/qtest/qpdf/replaced-stream-data-flate.out Binary files differnew file mode 100644 index 00000000..8da1663f --- /dev/null +++ b/qpdf/qtest/qpdf/replaced-stream-data-flate.out diff --git a/qpdf/qtest/qpdf/replaced-stream-data.out b/qpdf/qtest/qpdf/replaced-stream-data.out new file mode 100644 index 00000000..14b2dea3 --- /dev/null +++ b/qpdf/qtest/qpdf/replaced-stream-data.out @@ -0,0 +1,47 @@ +%PDF-1.3 +%¿÷¢þ +1 0 obj +<< /Pages 2 0 R /QStream 3 0 R /Type /Catalog >> +endobj +2 0 obj +<< /Count 1 /Kids [ 4 0 R ] /Type /Pages >> +endobj +3 0 obj +<< /Length 20 >> +stream +new data for stream +endstream +endobj +4 0 obj +<< /Contents 5 0 R /MediaBox [ 0 0 612 792 ] /Parent 2 0 R /Resources << /Font << /F1 6 0 R >> /ProcSet 7 0 R >> /Type /Page >> +endobj +5 0 obj +<< /Length 44 >> +stream +BT + /F1 24 Tf + 72 720 Td + (Potato) Tj +ET +endstream +endobj +6 0 obj +<< /BaseFont /Helvetica /Encoding /WinAnsiEncoding /Name /F1 /Subtype /Type1 /Type /Font >> +endobj +7 0 obj +[ /PDF /Text ] +endobj +xref +0 8 +0000000000 65535 f +0000000015 00000 n +0000000079 00000 n +0000000138 00000 n +0000000207 00000 n +0000000350 00000 n +0000000443 00000 n +0000000550 00000 n +trailer << /Root 1 0 R /Size 8 /ID [<31415926535897932384626433832795><31415926535897932384626433832795>] >> +startxref +580 +%%EOF diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc index f4998913..db6a0619 100644 --- a/qpdf/test_driver.cc +++ b/qpdf/test_driver.cc @@ -7,6 +7,7 @@ #include <qpdf/QTC.hh> #include <qpdf/Pl_StdioFile.hh> #include <qpdf/Pl_Buffer.hh> +#include <qpdf/Pl_Flate.hh> #include <qpdf/QPDFWriter.hh> #include <iostream> #include <stdio.h> @@ -309,6 +310,45 @@ void runtest(int n, char const* filename) << (cleartext ? 1 : 0) << std::endl; } + else if (n == 7) + { + QPDFObjectHandle root = pdf.getRoot(); + QPDFObjectHandle qstream = root.getKey("/QStream"); + if (! qstream.isStream()) + { + throw std::logic_error("test 7 run on file with no QStream"); + } + PointerHolder<Buffer> b = new Buffer(20); + unsigned char* bp = b.getPointer()->getBuffer(); + memcpy(bp, (char*)"new data for stream\n", 20); // no null! + qstream.replaceStreamData( + b, QPDFObjectHandle::newNull(), QPDFObjectHandle::newNull()); + QPDFWriter w(pdf, "a.pdf"); + w.setStaticID(true); + w.setStreamDataMode(qpdf_s_preserve); + w.write(); + } + else if (n == 8) + { + QPDFObjectHandle root = pdf.getRoot(); + QPDFObjectHandle qstream = root.getKey("/QStream"); + if (! qstream.isStream()) + { + throw std::logic_error("test 7 run on file with no QStream"); + } + Pl_Buffer p1("buffer"); + Pl_Flate p2("compress", &p1, Pl_Flate::a_deflate); + p2.write((unsigned char*)"new data for stream\n", 20); // no null! + p2.finish(); + PointerHolder<Buffer> b = p1.getBuffer(); + qstream.replaceStreamData( + b, QPDFObjectHandle::newName("/FlateDecode"), + QPDFObjectHandle::newNull()); + QPDFWriter w(pdf, "a.pdf"); + w.setStaticID(true); + w.setStreamDataMode(qpdf_s_preserve); + w.write(); + } else { throw std::runtime_error(std::string("invalid test ") + |