2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-05-28 07:53:11 +00:00

more tests of C API

git-svn-id: svn+q:///qpdf/trunk@732 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
Jay Berkenbilt 2009-09-27 18:28:51 +00:00
parent 65bf77fa35
commit 40f4b1ef52
11 changed files with 156 additions and 4 deletions

View File

@ -38,8 +38,8 @@ static void test02(char const* infile,
char const* outfile)
{
qpdf_set_suppress_warnings(qpdf, QPDF_TRUE);
qpdf_read(qpdf, infile, password);
if (qpdf_init_write(qpdf, outfile) == QPDF_SUCCESS)
if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) &&
((qpdf_init_write(qpdf, outfile) & QPDF_ERRORS) == 0))
{
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
@ -132,6 +132,15 @@ static void test09(char const* infile,
report_errors();
}
static void test10(char const* infile,
char const* password,
char const* outfile)
{
qpdf_set_attempt_recovery(qpdf, QPDF_FALSE);
qpdf_read(qpdf, infile, password);
report_errors();
}
int main(int argc, char* argv[])
{
char* whoami = 0;
@ -174,6 +183,7 @@ int main(int argc, char* argv[])
(n == 7) ? test07 :
(n == 8) ? test08 :
(n == 9) ? test09 :
(n == 10) ? test10 :
0);
if (fn == 0)

View File

@ -135,9 +135,10 @@ my @badfiles = ("not a PDF file", # 1
"invalid stream /Filter", # 30
"unknown stream /Filter", # 31
"obj/gen mismatch", # 32
"invalid stream /Filter and xref", # 33
);
$n_tests += @badfiles;
$n_tests += @badfiles + 5;
# Test 6 contains errors in the free table consistency, but we no
# longer have any consistency check for this since it is not important
@ -156,6 +157,32 @@ for (my $i = 1; $i <= scalar(@badfiles); ++$i)
$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 and errors",
{$td->COMMAND => "qpdf-ctest 2 bad17.pdf '' a.pdf"},
{$td->FILE => "c-read-warnings-and-errors.out",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("C API: errors writing",
{$td->COMMAND => "qpdf-ctest 2 bad30.pdf '' a.pdf"},
{$td->FILE => "c-write-errors.out",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("C API: errors and warnings writing",
{$td->COMMAND => "qpdf-ctest 2 bad33.pdf '' a.pdf"},
{$td->FILE => "c-write-warnings-and-errors.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);
show_ntests();
# ----------
$td->notify("--- Recovery Tests ---");
@ -167,7 +194,7 @@ $n_tests += @badfiles + 8;
# 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, 13..21, 24..27, 29..30)
for (1, 7, 13..21, 24..27, 29..30, 33)
{
$recover_failures{$_} = 1;
}

View File

@ -0,0 +1,9 @@
WARNING: bad33.pdf: offset 0: file is damaged
WARNING: bad33.pdf: offset 1771: xref not found
WARNING: Attempting to reconstruct cross-reference table
/QTest is indirect
/QTest is a stream. Dictionary: << /Filter (FlateDecode) /Length 123 >>
Raw stream data:
xœ%<25>11 û¼b;t<>à4| wXIDì Øå÷8G·«Í>rQ¨uŠ êEŒ:©IWìÃPlíµII)Ãr´p4~;§ÎAs/òÒ…jcúú¾÷Žs§åözû»ž<C2BB>T.?®uŽæ§<Ž¼…Ð*6ä
Uncompressed stream data:
bad33.pdf: offset 629: invalid filter object type for this stream

View File

@ -0,0 +1 @@
bad33.pdf: offset 1771: xref not found

93
qpdf/qtest/qpdf/bad33.pdf Normal file
View File

@ -0,0 +1,93 @@
%PDF-1.3
1 0 obj
<<
/Type /Catalog
/Pages 2 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
<<
% Comment
/Length
123
/Filter (FlateDecode)
>>
stream
xœ%<25>11 û¼b;t<>à4| wXIDì Øå÷8G·«Í>rQ¨uŠ êEŒ:©IWìÃPlíµII)Ãr´p4~;§ÎAs/òÒ…jcúú¾÷Žs§åözû»ž<C2BB>T.?®uŽæ§<Ž¼…Ð*6ä
endstream
endobj
xref
0 8
0000000000 65535 f
0000000009 00000 n
0000000063 00000 n
0000000135 00000 n
0000000307 00000 n
0000000403 00000 n
0000000438 00000 n
0000000556 00000 n
trailer <<
/Size 8
/Root 1 0 R
/QTest 7 0 R
>>
startxref
1771
%%EOF

View File

@ -0,0 +1 @@
error: bad33.pdf: offset 1771: xref not found

View File

@ -0,0 +1 @@
error: bad1.pdf: offset 0: not a PDF file

View File

@ -0,0 +1,4 @@
warning: bad17.pdf: offset 0: file is damaged
warning: bad17.pdf: offset 753: dictionary ending here has an odd number of elements
warning: Attempting to reconstruct cross-reference table
error: bad17.pdf: offset 753: dictionary ending here has an odd number of elements

View File

@ -0,0 +1 @@
error: bad30.pdf: offset 629: invalid filter object type for this stream

View File

@ -0,0 +1,4 @@
warning: bad33.pdf: offset 0: file is damaged
warning: bad33.pdf: offset 1771: xref not found
warning: Attempting to reconstruct cross-reference table
error: bad33.pdf: offset 629: invalid filter object type for this stream

View File

@ -0,0 +1 @@
warning: damaged-stream.pdf: offset 426: error decoding stream data for object 5 0: LZWDecoder: bad code received