tested basic stream replacement

git-svn-id: svn+q:///qpdf/trunk@989 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
Jay Berkenbilt 2010-08-03 02:29:15 +00:00
parent 998a6cbee9
commit 98765c3b5c
5 changed files with 194 additions and 1 deletions

View File

@ -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"},

View File

@ -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

Binary file not shown.

View File

@ -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

View File

@ -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 ") +