Commit 40f4b1ef5237a51b38b74b04d53d6aa20819b5d7
1 parent
65bf77fa
more tests of C API
git-svn-id: svn+q:///qpdf/trunk@732 71b93d88-0707-0410-a8cf-f5a4172ac649
Showing
11 changed files
with
156 additions
and
4 deletions
qpdf/qpdf-ctest.c
| @@ -38,8 +38,8 @@ static void test02(char const* infile, | @@ -38,8 +38,8 @@ static void test02(char const* infile, | ||
| 38 | char const* outfile) | 38 | char const* outfile) |
| 39 | { | 39 | { |
| 40 | qpdf_set_suppress_warnings(qpdf, QPDF_TRUE); | 40 | qpdf_set_suppress_warnings(qpdf, QPDF_TRUE); |
| 41 | - qpdf_read(qpdf, infile, password); | ||
| 42 | - if (qpdf_init_write(qpdf, outfile) == QPDF_SUCCESS) | 41 | + if (((qpdf_read(qpdf, infile, password) & QPDF_ERRORS) == 0) && |
| 42 | + ((qpdf_init_write(qpdf, outfile) & QPDF_ERRORS) == 0)) | ||
| 43 | { | 43 | { |
| 44 | qpdf_set_static_ID(qpdf, QPDF_TRUE); | 44 | qpdf_set_static_ID(qpdf, QPDF_TRUE); |
| 45 | qpdf_write(qpdf); | 45 | qpdf_write(qpdf); |
| @@ -132,6 +132,15 @@ static void test09(char const* infile, | @@ -132,6 +132,15 @@ static void test09(char const* infile, | ||
| 132 | report_errors(); | 132 | report_errors(); |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | +static void test10(char const* infile, | ||
| 136 | + char const* password, | ||
| 137 | + char const* outfile) | ||
| 138 | +{ | ||
| 139 | + qpdf_set_attempt_recovery(qpdf, QPDF_FALSE); | ||
| 140 | + qpdf_read(qpdf, infile, password); | ||
| 141 | + report_errors(); | ||
| 142 | +} | ||
| 143 | + | ||
| 135 | int main(int argc, char* argv[]) | 144 | int main(int argc, char* argv[]) |
| 136 | { | 145 | { |
| 137 | char* whoami = 0; | 146 | char* whoami = 0; |
| @@ -174,6 +183,7 @@ int main(int argc, char* argv[]) | @@ -174,6 +183,7 @@ int main(int argc, char* argv[]) | ||
| 174 | (n == 7) ? test07 : | 183 | (n == 7) ? test07 : |
| 175 | (n == 8) ? test08 : | 184 | (n == 8) ? test08 : |
| 176 | (n == 9) ? test09 : | 185 | (n == 9) ? test09 : |
| 186 | + (n == 10) ? test10 : | ||
| 177 | 0); | 187 | 0); |
| 178 | 188 | ||
| 179 | if (fn == 0) | 189 | if (fn == 0) |
qpdf/qtest/qpdf.test
| @@ -135,9 +135,10 @@ my @badfiles = ("not a PDF file", # 1 | @@ -135,9 +135,10 @@ my @badfiles = ("not a PDF file", # 1 | ||
| 135 | "invalid stream /Filter", # 30 | 135 | "invalid stream /Filter", # 30 |
| 136 | "unknown stream /Filter", # 31 | 136 | "unknown stream /Filter", # 31 |
| 137 | "obj/gen mismatch", # 32 | 137 | "obj/gen mismatch", # 32 |
| 138 | + "invalid stream /Filter and xref", # 33 | ||
| 138 | ); | 139 | ); |
| 139 | 140 | ||
| 140 | -$n_tests += @badfiles; | 141 | +$n_tests += @badfiles + 5; |
| 141 | 142 | ||
| 142 | # Test 6 contains errors in the free table consistency, but we no | 143 | # Test 6 contains errors in the free table consistency, but we no |
| 143 | # longer have any consistency check for this since it is not important | 144 | # longer have any consistency check for this since it is not important |
| @@ -156,6 +157,32 @@ for (my $i = 1; $i <= scalar(@badfiles); ++$i) | @@ -156,6 +157,32 @@ for (my $i = 1; $i <= scalar(@badfiles); ++$i) | ||
| 156 | $td->NORMALIZE_NEWLINES); | 157 | $td->NORMALIZE_NEWLINES); |
| 157 | } | 158 | } |
| 158 | 159 | ||
| 160 | +$td->runtest("C API: errors", | ||
| 161 | + {$td->COMMAND => "qpdf-ctest 2 bad1.pdf '' a.pdf"}, | ||
| 162 | + {$td->FILE => "c-read-errors.out", | ||
| 163 | + $td->EXIT_STATUS => 0}, | ||
| 164 | + $td->NORMALIZE_NEWLINES); | ||
| 165 | +$td->runtest("C API: warnings and errors", | ||
| 166 | + {$td->COMMAND => "qpdf-ctest 2 bad17.pdf '' a.pdf"}, | ||
| 167 | + {$td->FILE => "c-read-warnings-and-errors.out", | ||
| 168 | + $td->EXIT_STATUS => 0}, | ||
| 169 | + $td->NORMALIZE_NEWLINES); | ||
| 170 | +$td->runtest("C API: errors writing", | ||
| 171 | + {$td->COMMAND => "qpdf-ctest 2 bad30.pdf '' a.pdf"}, | ||
| 172 | + {$td->FILE => "c-write-errors.out", | ||
| 173 | + $td->EXIT_STATUS => 0}, | ||
| 174 | + $td->NORMALIZE_NEWLINES); | ||
| 175 | +$td->runtest("C API: errors and warnings writing", | ||
| 176 | + {$td->COMMAND => "qpdf-ctest 2 bad33.pdf '' a.pdf"}, | ||
| 177 | + {$td->FILE => "c-write-warnings-and-errors.out", | ||
| 178 | + $td->EXIT_STATUS => 0}, | ||
| 179 | + $td->NORMALIZE_NEWLINES); | ||
| 180 | +$td->runtest("C API: no recovery", | ||
| 181 | + {$td->COMMAND => "qpdf-ctest 10 bad33.pdf '' a.pdf"}, | ||
| 182 | + {$td->FILE => "c-no-recovery.out", | ||
| 183 | + $td->EXIT_STATUS => 0}, | ||
| 184 | + $td->NORMALIZE_NEWLINES); | ||
| 185 | + | ||
| 159 | show_ntests(); | 186 | show_ntests(); |
| 160 | # ---------- | 187 | # ---------- |
| 161 | $td->notify("--- Recovery Tests ---"); | 188 | $td->notify("--- Recovery Tests ---"); |
| @@ -167,7 +194,7 @@ $n_tests += @badfiles + 8; | @@ -167,7 +194,7 @@ $n_tests += @badfiles + 8; | ||
| 167 | # though in some cases it may. Acrobat Reader would not be able to | 194 | # though in some cases it may. Acrobat Reader would not be able to |
| 168 | # recover any of these files any better. | 195 | # recover any of these files any better. |
| 169 | my %recover_failures = (); | 196 | my %recover_failures = (); |
| 170 | -for (1, 7, 13..21, 24..27, 29..30) | 197 | +for (1, 7, 13..21, 24..27, 29..30, 33) |
| 171 | { | 198 | { |
| 172 | $recover_failures{$_} = 1; | 199 | $recover_failures{$_} = 1; |
| 173 | } | 200 | } |
qpdf/qtest/qpdf/bad33-recover.out
0 → 100644
No preview for this file type
qpdf/qtest/qpdf/bad33.out
0 → 100644
| 1 | +bad33.pdf: offset 1771: xref not found |
qpdf/qtest/qpdf/bad33.pdf
0 → 100644
No preview for this file type
qpdf/qtest/qpdf/c-no-recovery.out
0 → 100644
| 1 | +error: bad33.pdf: offset 1771: xref not found |
qpdf/qtest/qpdf/c-read-errors.out
0 → 100644
| 1 | +error: bad1.pdf: offset 0: not a PDF file |
qpdf/qtest/qpdf/c-read-warnings-and-errors.out
0 → 100644
qpdf/qtest/qpdf/c-write-errors.out
0 → 100644
| 1 | +error: bad30.pdf: offset 629: invalid filter object type for this stream |
qpdf/qtest/qpdf/c-write-warnings-and-errors.out
0 → 100644
qpdf/qtest/qpdf/damaged-stream-c-check.out
0 → 100644
| 1 | +warning: damaged-stream.pdf: offset 426: error decoding stream data for object 5 0: LZWDecoder: bad code received |