diff options
author | Jay Berkenbilt <ejb@ql.org> | 2018-02-17 17:51:10 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2018-02-19 03:06:27 +0100 |
commit | 2780a1871d2603e9b273580fb7978d277832c2fc (patch) | |
tree | 270b1195eed7eb93e5a339a965c08b549239958d /qpdf | |
parent | b72a38bf5ff3adf9bf02046b1106e1b524afa922 (diff) | |
download | qpdf-2780a1871d2603e9b273580fb7978d277832c2fc.tar.zst |
Add C API for checking PDF files
Diffstat (limited to 'qpdf')
-rw-r--r-- | qpdf/qpdf-ctest.c | 13 | ||||
-rw-r--r-- | qpdf/qpdf.testcov | 1 | ||||
-rw-r--r-- | qpdf/qtest/qpdf.test | 15 | ||||
-rw-r--r-- | qpdf/qtest/qpdf/c-check-clear-in.pdf | 79 | ||||
-rw-r--r-- | qpdf/qtest/qpdf/c-check-clear.out | 1 | ||||
-rw-r--r-- | qpdf/qtest/qpdf/c-check-warn-in.pdf | 79 | ||||
-rw-r--r-- | qpdf/qtest/qpdf/c-check-warn.out | 19 |
7 files changed, 207 insertions, 0 deletions
diff --git a/qpdf/qpdf-ctest.c b/qpdf/qpdf-ctest.c index f7bfb5c4..8b9c36ce 100644 --- a/qpdf/qpdf-ctest.c +++ b/qpdf/qpdf-ctest.c @@ -484,6 +484,18 @@ static void test22(char const* infile, report_errors(); } +static void test23(char const* infile, + char const* password, + char const* outfile, + char const* outfile2) +{ + QPDF_ERROR_CODE status = 0; + qpdf_read(qpdf, infile, password); + status = qpdf_check_pdf(qpdf); + printf("status: %d\n", status); + report_errors(); +} + int main(int argc, char* argv[]) { char* p = 0; @@ -546,6 +558,7 @@ int main(int argc, char* argv[]) (n == 20) ? test20 : (n == 21) ? test21 : (n == 22) ? test22 : + (n == 23) ? test23 : 0); if (fn == 0) diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov index 67cbfe7f..7e60953e 100644 --- a/qpdf/qpdf.testcov +++ b/qpdf/qpdf.testcov @@ -333,3 +333,4 @@ QPDFObjectHandle dictionary ignoring removeKey 0 QPDFObjectHandle dictionary ignoring removereplace 0 QPDFObjectHandle numeric non-numeric 0 QPDFObjectHandle erase array bounds 0 +qpdf-c called qpdf_check_pdf 0 diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index bd341079..6854e651 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -2495,6 +2495,21 @@ foreach my $d (@enc_key) show_ntests(); # ---------- +$td->notify("--- Check from C API ---"); +my @c_check_types = qw(warn clear); +$n_tests += scalar(@c_check_types); + +foreach my $i (@c_check_types) +{ + $td->runtest("C check $i", + {$td->COMMAND => "qpdf-ctest 23 c-check-$i-in.pdf '' -"}, + {$td->FILE => "c-check-$i.out", + $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); +} + +show_ntests(); +# ---------- $td->notify("--- Content Preservation Tests ---"); # $n_tests incremented below diff --git a/qpdf/qtest/qpdf/c-check-clear-in.pdf b/qpdf/qtest/qpdf/c-check-clear-in.pdf new file mode 100644 index 00000000..a7e01f91 --- /dev/null +++ b/qpdf/qtest/qpdf/c-check-clear-in.pdf @@ -0,0 +1,79 @@ +%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 + +xref +0 7 +0000000000 65535 f +0000000009 00000 n +0000000063 00000 n +0000000135 00000 n +0000000307 00000 n +0000000403 00000 n +0000000438 00000 n +trailer << + /Size 7 + /Root 1 0 R +>> +startxref +556 +%%EOF diff --git a/qpdf/qtest/qpdf/c-check-clear.out b/qpdf/qtest/qpdf/c-check-clear.out new file mode 100644 index 00000000..934014b3 --- /dev/null +++ b/qpdf/qtest/qpdf/c-check-clear.out @@ -0,0 +1 @@ +status: 0 diff --git a/qpdf/qtest/qpdf/c-check-warn-in.pdf b/qpdf/qtest/qpdf/c-check-warn-in.pdf new file mode 100644 index 00000000..e8a7042c --- /dev/null +++ b/qpdf/qtest/qpdf/c-check-warn-in.pdf @@ -0,0 +1,79 @@ +%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 + +xref +0 7 +0000000000 65535 f +0000000009 00000 n +0000000063 00000 n +0000000135 00000 n +0000000307 00000 n +0000000403 00000 n +0000000438 00000 n +trailer << + /Size 7 + /Root 1 0 R +>> +startxref +1556 +%%EOF diff --git a/qpdf/qtest/qpdf/c-check-warn.out b/qpdf/qtest/qpdf/c-check-warn.out new file mode 100644 index 00000000..40e8eb35 --- /dev/null +++ b/qpdf/qtest/qpdf/c-check-warn.out @@ -0,0 +1,19 @@ +WARNING: c-check-warn-in.pdf: file is damaged +WARNING: c-check-warn-in.pdf (offset 1556): xref not found +WARNING: c-check-warn-in.pdf: Attempting to reconstruct cross-reference table +status: 1 +warning: c-check-warn-in.pdf: file is damaged + code: 5 + file: c-check-warn-in.pdf + pos : 0 + text: file is damaged +warning: c-check-warn-in.pdf (offset 1556): xref not found + code: 5 + file: c-check-warn-in.pdf + pos : 1556 + text: xref not found +warning: c-check-warn-in.pdf: Attempting to reconstruct cross-reference table + code: 5 + file: c-check-warn-in.pdf + pos : 0 + text: Attempting to reconstruct cross-reference table |