more tests of C API

git-svn-id: svn+q:///qpdf/trunk@728 71b93d88-0707-0410-a8cf-f5a4172ac649
This commit is contained in:
Jay Berkenbilt 2009-09-27 16:55:24 +00:00
parent fe6771e0e5
commit 65bf77fa35
12 changed files with 3694 additions and 0 deletions

View File

@ -1,3 +1,15 @@
2009-09-27 Jay Berkenbilt <ejb@ql.org>
* The function QPDF::getUserPassword returned the user password
with the required padding as specified by the PDF specification.
This is seldom useful to users. This function has been replaced
by QPDF::getPaddedUserPassword. Call the new
QPDF::getTrimmedUserPassword to retreive the user password in a
human-readable format.
* qpdf/qpdf.cc (main): qpdf --check now prints the PDF version
number in addition to its other output.
2009-09-26 Jay Berkenbilt <ejb@ql.org>
* Removed all references to QEXC; now using std::runtime_error and

View File

@ -33,6 +33,105 @@ static void test01(char const* infile,
report_errors();
}
static void test02(char const* infile,
char const* password,
char const* outfile)
{
qpdf_set_suppress_warnings(qpdf, QPDF_TRUE);
qpdf_read(qpdf, infile, password);
if (qpdf_init_write(qpdf, outfile) == QPDF_SUCCESS)
{
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
}
report_errors();
}
static void test03(char const* infile,
char const* password,
char const* outfile)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_content_normalization(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void test04(char const* infile,
char const* password,
char const* outfile)
{
qpdf_set_ignore_xref_streams(qpdf, QPDF_TRUE);
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void test05(char const* infile,
char const* password,
char const* outfile)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_linearization(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void test06(char const* infile,
char const* password,
char const* outfile)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_object_stream_mode(qpdf, QPDF_OBJECT_STREAM_GENERATE);
qpdf_write(qpdf);
report_errors();
}
static void test07(char const* infile,
char const* password,
char const* outfile)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_qdf_mode(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void test08(char const* infile,
char const* password,
char const* outfile)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_qdf_mode(qpdf, QPDF_TRUE);
qpdf_set_suppress_original_object_IDs(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
}
static void test09(char const* infile,
char const* password,
char const* outfile)
{
qpdf_read(qpdf, infile, password);
qpdf_init_write(qpdf, outfile);
qpdf_set_static_ID(qpdf, QPDF_TRUE);
qpdf_set_stream_data_mode(qpdf, QPDF_STREAM_DATA_UNCOMPRESS);
qpdf_write(qpdf);
report_errors();
}
int main(int argc, char* argv[])
{
char* whoami = 0;
@ -67,6 +166,14 @@ int main(int argc, char* argv[])
outfile = argv[4];
fn = ((n == 1) ? test01 :
(n == 2) ? test02 :
(n == 3) ? test03 :
(n == 4) ? test04 :
(n == 5) ? test05 :
(n == 6) ? test06 :
(n == 7) ? test07 :
(n == 8) ? test08 :
(n == 9) ? test09 :
0);
if (fn == 0)

View File

@ -296,6 +296,56 @@ check_pdf("no recompression",
"good17-not-recompressed.pdf",
0);
show_ntests();
# ----------
$td->notify("--- C API Tests ---");
my @capi = (
[2, 'no options'],
[3, 'normalized content'],
[4, 'ignore xref streams'],
[5, 'linearized'],
[6, 'object streams'],
[7, 'qdf'],
[8, 'no original object ids'],
[9, 'uncompressed streams'],
);
$n_tests += (2 * @capi) + 3;
foreach my $d (@capi)
{
my ($n, $description) = @$d;
my $outfile = $description;
$outfile =~ s/ /-/g;
$outfile = "c-$outfile.pdf";
$td->runtest($description,
{$td->COMMAND => "qpdf-ctest $n hybrid-xref.pdf '' a.pdf"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("check $description",
{$td->FILE => "a.pdf"},
{$td->FILE => $outfile});
}
$td->runtest("write to bad file name",
{$td->COMMAND => "qpdf-ctest 2 hybrid-xref.pdf '' /:a:/:b:"},
{$td->REGEXP => "error: open /:a:/:b:: .*",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("write damaged to bad file name",
{$td->COMMAND => "qpdf-ctest 2 append-page-content-damaged.pdf" .
" '' /:a:/:b:"},
{$td->REGEXP =>
"warning:(?s:.*)\n" .
"error: open /:a:/:b:: .*",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("write damaged",
{$td->COMMAND => "qpdf-ctest 2 append-page-content-damaged.pdf" .
" '' a.pdf"},
{$td->FILE => "c-write-damaged.out",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
show_ntests();
# ----------
$td->notify("--- Object Stream Tests ---");

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

1576
qpdf/qtest/qpdf/c-qdf.pdf Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,434 @@
%PDF-1.5
%¿÷¢þ
1 0 obj
<< /Outlines 3 0 R /PageLabels 15 0 R /PageMode /UseOutlines /Pages 16 0 R /Type /Catalog >>
endobj
2 0 obj
<< /Type /ObjStm /Length 2064 /N 13 /First 87 >>
stream
3 0 4 56 5 217 6 334 7 470 8 730 9 882 10 1053 11 1191 12 1329 13 1454 14 1594 15 1730
<< /Count 6 /First 4 0 R /Last 5 0 R /Type /Outlines >>
<< /Count 4 /Dest [ 17 0 R /XYZ null null null ] /First 6 0 R /Last 7 0 R /Next 5 0 R /Parent 3 0 R /Title (Isís 1 -> 5: /XYZ null null null) /Type /Outline >>
<< /Dest [ 18 0 R /XYZ 66 756 3 ] /Parent 3 0 R /Prev 4 0 R /Title (Trepak 2 -> 15: /XYZ 66 756 3) /Type /Outline >>
<< /Count -3 /Dest [ 19 0 R /Fit ] /First 8 0 R /Last 9 0 R /Next 7 0 R /Parent 4 0 R /Title (Amanda 1.1 -> 11: /Fit) /Type /Outline >>
<< /Count 2 /Dest [ 20 0 R /FitH 792 ] /First 13 0 R /Last 14 0 R /Parent 4 0 R /Prev 6 0 R /Title <feff00530061006e00640079002000f703a303b103bd03b403b900f700200031002e00320020002d003e002000310033003a0020002f00460069007400480020003700390032> /Type /Outline >>
<< /Count -2 /Dest [ 21 0 R /FitV 100 ] /First 10 0 R /Last 11 0 R /Next 9 0 R /Parent 6 0 R /Title (Isosicle 1.1.1 -> 12: /FitV 100) /Type /Outline >>
<< /Count 1 /Dest [ 21 0 R /XYZ null null null ] /First 12 0 R /Last 12 0 R /Parent 6 0 R /Prev 8 0 R /Title (Isosicle 1.1.2 -> 12: /XYZ null null null) /Type /Outline >>
<< /Dest [ 22 0 R /XYZ null null null ] /Next 11 0 R /Parent 8 0 R /Title (Isosicle 1.1.1.1 -> 18: /XYZ null null null) /Type /Outline >>
<< /Dest [ 23 0 R /XYZ null null null ] /Parent 8 0 R /Prev 10 0 R /Title (Isosicle 1.1.1.2 -> 19: /XYZ null null null) /Type /Outline >>
<< /Dest [ 24 0 R /XYZ null null null ] /Parent 9 0 R /Title (Isosicle 1.1.2.1 -> 22: /XYZ null null null) /Type /Outline >>
<< /Dest [ 25 0 R /FitR 66 714 180 770 ] /Next 14 0 R /Parent 7 0 R /Title (Trepsichord 1.2.1 -> 1: /FitR 66 714 180 770) /Type /Outline >>
<< /Dest [ 26 0 R /XYZ null null null ] /Parent 7 0 R /Prev 13 0 R /Title (Trepsicle 1.2.2 -> 0: /XYZ null null null) /Type /Outline >>
<< /Nums [ 0 << /P () >> 2 << /S /r /St 1 >> 7 << /P () >> 9 << /S /r /St 6 >> 11 << /P () >> 12 << /S /D /St 2 >> 15 << /S /D /St 6 >> 19 << /P () >> 20 << /S /D /St 12 >> 22 << /S /D /St 16059 >> 23 << /S /r /St 50 >> 29 << /S /r /St 54 >> ] >>
endstream
endobj
16 0 obj
<< /Count 30 /Kids [ 26 0 R 25 0 R 27 0 R 28 0 R 29 0 R 17 0 R 30 0 R 31 0 R 32 0 R 33 0 R 34 0 R 19 0 R 21 0 R 20 0 R 35 0 R 18 0 R 36 0 R 37 0 R 22 0 R 23 0 R 38 0 R 39 0 R 24 0 R 40 0 R 41 0 R 42 0 R 43 0 R 44 0 R 45 0 R 46 0 R ] /Type /Pages >>
endobj
17 0 obj
<< /Contents 47 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
18 0 obj
<< /Contents 50 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
19 0 obj
<< /Contents 51 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
20 0 obj
<< /Contents 52 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
21 0 obj
<< /Contents 53 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
22 0 obj
<< /Contents 54 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
23 0 obj
<< /Contents 55 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
24 0 obj
<< /Contents 56 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
25 0 obj
<< /Contents 57 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
26 0 obj
<< /Contents 58 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
27 0 obj
<< /Contents 59 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
28 0 obj
<< /Contents 60 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
29 0 obj
<< /Contents 61 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
30 0 obj
<< /Contents 62 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
31 0 obj
<< /Contents 63 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
32 0 obj
<< /Contents 64 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
33 0 obj
<< /Contents 65 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
34 0 obj
<< /Contents 66 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
35 0 obj
<< /Contents 67 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
36 0 obj
<< /Contents 68 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
37 0 obj
<< /Contents 69 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
38 0 obj
<< /Contents 70 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
39 0 obj
<< /Contents 71 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
40 0 obj
<< /Contents 72 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
41 0 obj
<< /Contents 73 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
42 0 obj
<< /Contents 74 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
43 0 obj
<< /Contents 75 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
44 0 obj
<< /Contents 76 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
45 0 obj
<< /Contents 77 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
46 0 obj
<< /Contents 78 0 R /MediaBox [ 0 0 612 792 ] /Parent 16 0 R /Resources << /Font << /F1 48 0 R >> /ProcSet 49 0 R >> /Type /Page >>
endobj
47 0 obj
<< /Length 46 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 5) Tj
ET
endstream
endobj
48 0 obj
<< /BaseFont /Helvetica /Encoding /WinAnsiEncoding /Name /F1 /Subtype /Type1 /Type /Font >>
endobj
49 0 obj
[ /PDF /Text ]
endobj
50 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 15) Tj
ET
endstream
endobj
51 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 11) Tj
ET
endstream
endobj
52 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 13) Tj
ET
endstream
endobj
53 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 12) Tj
ET
endstream
endobj
54 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 18) Tj
ET
endstream
endobj
55 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 19) Tj
ET
endstream
endobj
56 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 22) Tj
ET
endstream
endobj
57 0 obj
<< /Length 46 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 1) Tj
ET
endstream
endobj
58 0 obj
<< /Length 46 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 0) Tj
ET
endstream
endobj
59 0 obj
<< /Length 46 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 2) Tj
ET
endstream
endobj
60 0 obj
<< /Length 46 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 3) Tj
ET
endstream
endobj
61 0 obj
<< /Length 46 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 4) Tj
ET
endstream
endobj
62 0 obj
<< /Length 46 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 6) Tj
ET
endstream
endobj
63 0 obj
<< /Length 46 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 7) Tj
ET
endstream
endobj
64 0 obj
<< /Length 46 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 8) Tj
ET
endstream
endobj
65 0 obj
<< /Length 46 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 9) Tj
ET
endstream
endobj
66 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 10) Tj
ET
endstream
endobj
67 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 14) Tj
ET
endstream
endobj
68 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 16) Tj
ET
endstream
endobj
69 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 17) Tj
ET
endstream
endobj
70 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 20) Tj
ET
endstream
endobj
71 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 21) Tj
ET
endstream
endobj
72 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 23) Tj
ET
endstream
endobj
73 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 24) Tj
ET
endstream
endobj
74 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 25) Tj
ET
endstream
endobj
75 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 26) Tj
ET
endstream
endobj
76 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 27) Tj
ET
endstream
endobj
77 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 28) Tj
ET
endstream
endobj
78 0 obj
<< /Length 47 >>
stream
BT
/F1 24 Tf
72 720 Td
(Potato 29) Tj
ET
endstream
endobj
79 0 obj
<< /Type /XRef /Length 320 /W [ 1 2 1 ] /Root 1 0 R /Size 80 /ID [<31415926535897932384626433832795><31415926535897932384626433832795>] >>
stream
{ 
  Ü å
y  ¡ 5 É ] ñ­AÕiý%¹Máu <16>1ÅYí<19>©=<1B> (êK¬ nÏ/<1F>ï O ¯!!o"/"<22>#R$$u%7%˜&Z'
endstream
endobj
startxref
10012
%%EOF

View File

@ -0,0 +1,3 @@
warning: append-page-content-damaged.pdf: offset 0: file is damaged
warning: append-page-content-damaged.pdf: can't find startxref
warning: Attempting to reconstruct cross-reference table