aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2009-09-27 20:28:51 +0200
committerJay Berkenbilt <ejb@ql.org>2009-09-27 20:28:51 +0200
commit40f4b1ef5237a51b38b74b04d53d6aa20819b5d7 (patch)
treeaa91f7a3cbe9a3cba1b28ffc1d381dd94deacce4
parent65bf77fa3537724b646880d7dacd34f4e4c8b67e (diff)
downloadqpdf-40f4b1ef5237a51b38b74b04d53d6aa20819b5d7.tar.zst
more tests of C API
git-svn-id: svn+q:///qpdf/trunk@732 71b93d88-0707-0410-a8cf-f5a4172ac649
-rw-r--r--qpdf/qpdf-ctest.c14
-rw-r--r--qpdf/qtest/qpdf.test31
-rw-r--r--qpdf/qtest/qpdf/bad33-recover.out9
-rw-r--r--qpdf/qtest/qpdf/bad33.out1
-rw-r--r--qpdf/qtest/qpdf/bad33.pdf93
-rw-r--r--qpdf/qtest/qpdf/c-no-recovery.out1
-rw-r--r--qpdf/qtest/qpdf/c-read-errors.out1
-rw-r--r--qpdf/qtest/qpdf/c-read-warnings-and-errors.out4
-rw-r--r--qpdf/qtest/qpdf/c-write-errors.out1
-rw-r--r--qpdf/qtest/qpdf/c-write-warnings-and-errors.out4
-rw-r--r--qpdf/qtest/qpdf/damaged-stream-c-check.out1
11 files changed, 156 insertions, 4 deletions
diff --git a/qpdf/qpdf-ctest.c b/qpdf/qpdf-ctest.c
index d491b2a5..6a4bc2a9 100644
--- a/qpdf/qpdf-ctest.c
+++ b/qpdf/qpdf-ctest.c
@@ -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)
diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test
index 6b576191..73f6dae1 100644
--- a/qpdf/qtest/qpdf.test
+++ b/qpdf/qtest/qpdf.test
@@ -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;
}
diff --git a/qpdf/qtest/qpdf/bad33-recover.out b/qpdf/qtest/qpdf/bad33-recover.out
new file mode 100644
index 00000000..27425f8a
--- /dev/null
+++ b/qpdf/qtest/qpdf/bad33-recover.out
@@ -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%11 b;t4| wXID8G>rQu O E:IWPlII)rp4~;As/҅jcszT.?u<*6
+Uncompressed stream data:
+bad33.pdf: offset 629: invalid filter object type for this stream
diff --git a/qpdf/qtest/qpdf/bad33.out b/qpdf/qtest/qpdf/bad33.out
new file mode 100644
index 00000000..d9cbad38
--- /dev/null
+++ b/qpdf/qtest/qpdf/bad33.out
@@ -0,0 +1 @@
+bad33.pdf: offset 1771: xref not found
diff --git a/qpdf/qtest/qpdf/bad33.pdf b/qpdf/qtest/qpdf/bad33.pdf
new file mode 100644
index 00000000..963d857b
--- /dev/null
+++ b/qpdf/qtest/qpdf/bad33.pdf
@@ -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%11 b;t4| wXID8G>rQu O E:IWPlII)rp4~;As/҅jcszT.?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
diff --git a/qpdf/qtest/qpdf/c-no-recovery.out b/qpdf/qtest/qpdf/c-no-recovery.out
new file mode 100644
index 00000000..4fae9ebf
--- /dev/null
+++ b/qpdf/qtest/qpdf/c-no-recovery.out
@@ -0,0 +1 @@
+error: bad33.pdf: offset 1771: xref not found
diff --git a/qpdf/qtest/qpdf/c-read-errors.out b/qpdf/qtest/qpdf/c-read-errors.out
new file mode 100644
index 00000000..087d5343
--- /dev/null
+++ b/qpdf/qtest/qpdf/c-read-errors.out
@@ -0,0 +1 @@
+error: bad1.pdf: offset 0: not a PDF file
diff --git a/qpdf/qtest/qpdf/c-read-warnings-and-errors.out b/qpdf/qtest/qpdf/c-read-warnings-and-errors.out
new file mode 100644
index 00000000..e0114a45
--- /dev/null
+++ b/qpdf/qtest/qpdf/c-read-warnings-and-errors.out
@@ -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
diff --git a/qpdf/qtest/qpdf/c-write-errors.out b/qpdf/qtest/qpdf/c-write-errors.out
new file mode 100644
index 00000000..6d8ffa77
--- /dev/null
+++ b/qpdf/qtest/qpdf/c-write-errors.out
@@ -0,0 +1 @@
+error: bad30.pdf: offset 629: invalid filter object type for this stream
diff --git a/qpdf/qtest/qpdf/c-write-warnings-and-errors.out b/qpdf/qtest/qpdf/c-write-warnings-and-errors.out
new file mode 100644
index 00000000..2aa9cbb2
--- /dev/null
+++ b/qpdf/qtest/qpdf/c-write-warnings-and-errors.out
@@ -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
diff --git a/qpdf/qtest/qpdf/damaged-stream-c-check.out b/qpdf/qtest/qpdf/damaged-stream-c-check.out
new file mode 100644
index 00000000..b1723623
--- /dev/null
+++ b/qpdf/qtest/qpdf/damaged-stream-c-check.out
@@ -0,0 +1 @@
+warning: damaged-stream.pdf: offset 426: error decoding stream data for object 5 0: LZWDecoder: bad code received