2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-05 20:00:53 +00:00

Add tests for --json-input

This commit is contained in:
Jay Berkenbilt 2022-05-19 18:46:54 -04:00
parent 6c7326b290
commit 7f8c4b183d
6 changed files with 5283 additions and 1 deletions

View File

@ -46,5 +46,76 @@ foreach my $f (@badfiles)
$td->NORMALIZE_NEWLINES);
}
my @goodfiles = (
'good1.pdf',
'good9.pdf',
'good13.pdf',
'good15.pdf',
'inline-images.pdf',
['20-pages.pdf', '--password=user'],
'outlines-with-actions.pdf',
'form-fields-and-annotations.pdf',
'need-appearances.pdf',
'fxo-blue.pdf',
);
$n_tests += 6 * scalar(@goodfiles);
foreach my $i (@goodfiles)
{
my $f = $i;
my $xargs = "";
if (ref($i) eq 'ARRAY') {
($f, $xargs) = @$i;
}
$td->runtest("good: $f -> json",
{$td->COMMAND => "qpdf $xargs --decode-level=none" .
" --json-output=latest $f a.json"},
{$td->STRING => "", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("good: $f json -> json",
{$td->COMMAND =>
"qpdf --decode-level=none" .
" --json-input --json-output=latest a.json b.json"},
{$td->STRING => "", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("good: $f json -> qdf",
{$td->COMMAND =>
"qpdf --qdf --json-input --stream-data=preserve" .
" --static-id a.json a.pdf"},
{$td->STRING => "", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("good: $f compare json",
{$td->FILE => "a.json"},
{$td->FILE => "b.json"});
my $exp = "json-changed-$f";
if (! -f $exp)
{
$td->runtest("good: $f -> qdf",
{$td->COMMAND =>
"qpdf $xargs --object-streams=disable --qdf" .
" --stream-data=preserve --static-id $f b.pdf"},
{$td->STRING => "", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$exp = "b.pdf";
}
else
{
# Sometimes passing through json may make semantically
# equivalent changes such as
#
# * adding leading 0 to a floating point (.1 -> 0.1)
# * changing the Unicode representation of a string
# * changing the representation of a name (/n#65st -> /nest)
$td->runtest("good: json changes $f",
{$td->STRING => ""},
{$td->STRING => ""});
}
$td->runtest("good: $f compare qdf",
{$td->FILE => "a.pdf"}, # from json
{$td->FILE => $exp}); # from original PDF
}
cleanup();
$td->report($n_tests);

View File

@ -0,0 +1,979 @@
%PDF-1.6
%¿÷¢þ
%QDF-1.0
%% Original object ID: 1 0
1 0 obj
<<
/AcroForm <<
/DR 2 0 R
/Fields [
3 0 R
4 0 R
5 0 R
]
>>
/Names <<
/EmbeddedFiles 6 0 R
>>
/Pages 7 0 R
/Type /Catalog
>>
endobj
%% Original object ID: 2 0
2 0 obj
<<
/Font <<
/F1 8 0 R
>>
>>
endobj
%% Original object ID: 3 0
3 0 obj
<<
/AP <<
/N 9 0 R
>>
/DA (0 0.4 0 rg /F1 18 Tf)
/DR 2 0 R
/DV ()
/FT /Tx
/Ff 0
/Rect [
72
470.774
190.8
484.922
]
/Subtype /Widget
/T (Text Box 1)
/Type /Annot
/V (Formy field)
>>
endobj
%% Original object ID: 4 0
4 0 obj
<<
/AP <<
/N 11 0 R
>>
/DA (0 0.4 0 rg /F1 18 Tf)
/DR 2 0 R
/DV ()
/FT /Tx
/Ff 0
/Rect [
372
330.774
386.148
470.374
]
/Subtype /Widget
/T (Text Box 2)
/Type /Annot
/V (Rot-ccw field)
>>
endobj
%% Original object ID: 5 0
5 0 obj
<<
/DV /1
/FT /Btn
/Ff 49152
/Kids [
13 0 R
14 0 R
15 0 R
]
/T (r1)
/V /2
>>
endobj
%% Original object ID: 6 0
6 0 obj
<<
/Names [
(attachment1.txt)
16 0 R
]
>>
endobj
%% Original object ID: 7 0
7 0 obj
<<
/Count 1
/Kids [
17 0 R
]
/Type /Pages
>>
endobj
%% Original object ID: 8 0
8 0 obj
<<
/BaseFont /Courier
/Encoding /WinAnsiEncoding
/Subtype /Type1
/Type /Font
>>
endobj
%% Original object ID: 9 0
9 0 obj
<<
/BBox [
0
-2.826
118.8
11.322
]
/Resources 2 0 R
/Subtype /Form
/Type /XObject
/Length 10 0 R
>>
stream
/Tx BMC
q
BT
/F1 18 Tf
(Formy field) Tj
ET
Q
EMC
endstream
endobj
10 0 obj
53
endobj
%% Original object ID: 11 0
11 0 obj
<<
/BBox [
0
-2.826
140.4
11.322
]
/Matrix [
0
1
-1
0
0
0
]
/Resources 2 0 R
/Subtype /Form
/Type /XObject
/Length 12 0 R
>>
stream
/Tx BMC
q
BT
/F1 18 Tf
(Rot-ccw field) Tj
ET
Q
EMC
endstream
endobj
12 0 obj
55
endobj
%% Original object ID: 13 0
13 0 obj
<<
/AP <<
/N <<
/1 18 0 R
/Off 20 0 R
>>
>>
/AS /1
/DA (0.18039 0.20392 0.21176 rg /ZaDi 0 Tf)
/DR <<
/Font <<
/ZaDi 22 0 R
>>
>>
/F 4
/FT /Btn
/MK <<
/CA (l)
>>
/Parent 5 0 R
/Rect [
152.749
648.501
164.801
660.549
]
/Subtype /Widget
/Type /Annot
>>
endobj
%% Original object ID: 14 0
14 0 obj
<<
/AP <<
/N <<
/2 23 0 R
/Off 25 0 R
>>
>>
/AS /2
/DA (0.18039 0.20392 0.21176 rg /ZaDi 0 Tf)
/DR <<
/Font <<
/ZaDi 22 0 R
>>
>>
/F 4
/FT /Btn
/MK <<
/CA (l)
>>
/Parent 5 0 R
/Rect [
152.749
627.301
164.801
639.349
]
/Subtype /Widget
/Type /Annot
>>
endobj
%% Original object ID: 15 0
15 0 obj
<<
/AP <<
/N <<
/3 27 0 R
/Off 29 0 R
>>
>>
/AS /3
/DA (0.18039 0.20392 0.21176 rg /ZaDi 0 Tf)
/DR <<
/Font <<
/ZaDi 22 0 R
>>
>>
/F 4
/FT /Btn
/MK <<
/CA (l)
>>
/Parent 5 0 R
/Rect [
151.399
606.501
163.451
618.549
]
/Subtype /Widget
/Type /Annot
>>
endobj
%% Original object ID: 16 0
16 0 obj
<<
/EF <<
/F 31 0 R
/UF 31 0 R
>>
/F (attachment1.txt)
/Type /Filespec
/UF (attachment1.txt)
>>
endobj
%% Page 1
%% Original object ID: 17 0
17 0 obj
<<
/Annots [
33 0 R
3 0 R
34 0 R
4 0 R
35 0 R
36 0 R
37 0 R
38 0 R
13 0 R
14 0 R
15 0 R
]
/Contents 39 0 R
/MediaBox [
0
0
612
792
]
/Parent 7 0 R
/Resources 2 0 R
/Type /Page
>>
endobj
%% Original object ID: 18 0
18 0 obj
<<
/BBox [
0
0
12.05
12.05
]
/Resources 41 0 R
/Subtype /Form
/Type /XObject
/Length 19 0 R
>>
stream
/Tx BMC
q BT
0.18039 0.20392 0.21176 rg /ZaDi 12.05 Tf
0 0 Td
ET
Q
1 0 0 rg
6 8.4 m 7.35 8.4 8.45 7.35 8.45 6 c
8.45 4.65 7.35 3.55 6 3.55 c
4.65 3.55 3.6 4.65 3.6 6 c
3.6 7.35 4.65 8.4 6 8.4 c f*
EMC
endstream
endobj
19 0 obj
202
endobj
%% Original object ID: 20 0
20 0 obj
<<
/BBox [
0
0
12.05
12.05
]
/Resources 41 0 R
/Subtype /Form
/Type /XObject
/Length 21 0 R
>>
stream
/Tx BMC
EMC
endstream
endobj
21 0 obj
12
endobj
%% Original object ID: 22 0
22 0 obj
<<
/BaseFont /ZapfDingbats
/Subtype /Type1
/Type /Font
>>
endobj
%% Original object ID: 23 0
23 0 obj
<<
/BBox [
0
0
12.05
12.05
]
/Resources 41 0 R
/Subtype /Form
/Type /XObject
/Length 24 0 R
>>
stream
/Tx BMC
q BT
0.18039 0.20392 0.21176 rg /ZaDi 12.05 Tf
0 0 Td
ET
Q
0 1 0 rg
6 8.4 m 7.35 8.4 8.45 7.35 8.45 6 c
8.45 4.65 7.35 3.55 6 3.55 c
4.65 3.55 3.6 4.65 3.6 6 c
3.6 7.35 4.65 8.4 6 8.4 c f*
EMC
endstream
endobj
24 0 obj
202
endobj
%% Original object ID: 25 0
25 0 obj
<<
/BBox [
0
0
12.05
12.05
]
/Resources 41 0 R
/Subtype /Form
/Type /XObject
/Length 26 0 R
>>
stream
/Tx BMC
EMC
endstream
endobj
26 0 obj
12
endobj
%% Original object ID: 27 0
27 0 obj
<<
/BBox [
0
0
12.05
12.05
]
/Resources 41 0 R
/Subtype /Form
/Type /XObject
/Length 28 0 R
>>
stream
/Tx BMC
q BT
0.18039 0.20392 0.21176 rg /ZaDi 12.05 Tf
0 0 Td
ET
Q
0 0 1 rg
6 8.4 m 7.35 8.4 8.45 7.35 8.45 6 c
8.45 4.65 7.35 3.55 6 3.55 c
4.65 3.55 3.6 4.65 3.6 6 c
3.6 7.35 4.65 8.4 6 8.4 c f*
EMC
endstream
endobj
28 0 obj
202
endobj
%% Original object ID: 29 0
29 0 obj
<<
/BBox [
0
0
12.05
12.05
]
/Resources 41 0 R
/Subtype /Form
/Type /XObject
/Length 30 0 R
>>
stream
/Tx BMC
EMC
endstream
endobj
30 0 obj
12
endobj
%% Original object ID: 31 0
31 0 obj
<<
/Params <<
/CheckSum <80a33fc110b5a7b8b4d58b8d57e814bc>
/Size 22
/Subtype /text#2fplain
>>
/Type /EmbeddedFile
/Length 32 0 R
>>
stream
content of attachment
endstream
endobj
32 0 obj
22
endobj
%% Original object ID: 33 0
33 0 obj
<<
/A <<
/S /URI
/URI (https://www.qbilt.org/)
>>
/Border [
0
0
0.4
]
/C [
0.8
0.6
0.6
]
/H /I
/Rect [
72
501.832
374.4
520.696
]
/Subtype /Link
/Type /Annot
>>
endobj
%% Original object ID: 34 0
34 0 obj
<<
/AP <<
/N 42 0 R
>>
/Contents (attachment1.txt)
/FS 16 0 R
/NM (attachment1.txt)
/Rect [
72
400
92
420
]
/Subtype /FileAttachment
/Type /Annot
>>
endobj
%% Original object ID: 35 0
35 0 obj
<<
/AP <<
/N 44 0 R
>>
/DA ()
/Rect [
72
350
92
360
]
/Subtype /FreeText
/Type /Annot
>>
endobj
%% Original object ID: 36 0
36 0 obj
<<
/AP <<
/N 46 0 R
>>
/DA ()
/Rect [
102
350
112
370
]
/Subtype /FreeText
/Type /Annot
>>
endobj
%% Original object ID: 37 0
37 0 obj
<<
/AP <<
/N 48 0 R
>>
/DA ()
/Rect [
122
350
142
360
]
/Subtype /FreeText
/Type /Annot
>>
endobj
%% Original object ID: 38 0
38 0 obj
<<
/AP <<
/N 50 0 R
>>
/DA ()
/Rect [
152
350
162
370
]
/Subtype /FreeText
/Type /Annot
>>
endobj
%% Contents for page 1
%% Original object ID: 39 0
39 0 obj
<<
/Length 40 0 R
>>
stream
q
1 1 .7 rg
.5 .5 0 RG
72 470.77 118.8 14.15 re
B
Q
q
0 .5 .5 RG
0 1 1 rg
372 330.77 14.15 139.4 re
B
Q
q
1 0 0 RG
72 310 20 10 re
72 310 5 10 re
S
0 1 0 RG
102 310 10 20 re
102 310 10 5 re
S
0 0 1 RG
122 310 20 10 re
137 310 5 10 re
S
0.5 0 1 RG
152 310 10 20 re
152 325 10 5 re
S
10 w
0.14 .33 .18 RG
5 5 602 782 re
S
Q
BT
/F1 16 Tf
20.6 TL
170 650 Td
(radio button 1) Tj
(radio button 2) '
(radio button 3) '
1 0 0 1 72 546 Tm
/F1 20 Tf
(Thick green border surrounds page.) Tj
0 -40 Td
/F1 24 Tf
0 0 1 rg
(https://www.qbilt.org) Tj
/F1 12 Tf
1 0 0 1 202 474 Tm
(<- Formy field in yellow) Tj
1 0 0 1 392 410 Tm
14.4 TL
(<- Rot-ccw field) Tj
(with "Rot" at bottom) '
(and text going up) '
0 g
1 0 0 1 102 405 Tm
(Arrow to the left points down.) Tj
1 0 0 1 182 310 Tm
(<- Drawn rectangles appear below annotations.) Tj
ET
endstream
endobj
40 0 obj
874
endobj
%% Original object ID: 41 0
41 0 obj
<<
/Font 52 0 R
/ProcSet [
/PDF
/Text
]
>>
endobj
%% Original object ID: 42 0
42 0 obj
<<
/BBox [
0
0
20
20
]
/Resources <<
>>
/Subtype /Form
/Type /XObject
/Length 43 0 R
>>
stream
0 10 m
10 0 l
20 10 l
10 0 m
10 20 l
0 0 20 20 re
S
endstream
endobj
43 0 obj
52
endobj
%% Original object ID: 44 0
44 0 obj
<<
/BBox [
0
0
20
10
]
/Resources 2 0 R
/Subtype /Form
/Type /XObject
/Length 45 0 R
>>
stream
1 0 0 RG
0 0 20 10 re
0 0 5 10 re
S
endstream
endobj
45 0 obj
36
endobj
%% Original object ID: 46 0
46 0 obj
<<
/BBox [
0
0
20
10
]
/Matrix [
0
1
-1
0
0
0
]
/Resources 2 0 R
/Subtype /Form
/Type /XObject
/Length 47 0 R
>>
stream
0 1 0 RG
0 0 20 10 re
0 0 5 10 re
S
endstream
endobj
47 0 obj
36
endobj
%% Original object ID: 48 0
48 0 obj
<<
/BBox [
0
0
20
10
]
/Matrix [
-1
0
0
-1
0
0
]
/Resources 2 0 R
/Subtype /Form
/Type /XObject
/Length 49 0 R
>>
stream
0 0 1 RG
0 0 20 10 re
0 0 5 10 re
S
endstream
endobj
49 0 obj
36
endobj
%% Original object ID: 50 0
50 0 obj
<<
/BBox [
0
0
20
10
]
/Matrix [
0
-1
1
0
0
0
]
/Resources 2 0 R
/Subtype /Form
/Type /XObject
/Length 51 0 R
>>
stream
0.5 0 1 RG
0 0 20 10 re
0 0 5 10 re
S
endstream
endobj
51 0 obj
38
endobj
%% Original object ID: 52 0
52 0 obj
<<
/ZaDi 22 0 R
>>
endobj
xref
0 53
0000000000 65535 f
0000000052 00000 n
0000000265 00000 n
0000000344 00000 n
0000000614 00000 n
0000000890 00000 n
0000001036 00000 n
0000001133 00000 n
0000001233 00000 n
0000001364 00000 n
0000001578 00000 n
0000001626 00000 n
0000001896 00000 n
0000001944 00000 n
0000002324 00000 n
0000002704 00000 n
0000003084 00000 n
0000003253 00000 n
0000003553 00000 n
0000003912 00000 n
0000003961 00000 n
0000004130 00000 n
0000004178 00000 n
0000004287 00000 n
0000004646 00000 n
0000004695 00000 n
0000004864 00000 n
0000004912 00000 n
0000005271 00000 n
0000005320 00000 n
0000005489 00000 n
0000005537 00000 n
0000005745 00000 n
0000005793 00000 n
0000006069 00000 n
0000006301 00000 n
0000006469 00000 n
0000006639 00000 n
0000006809 00000 n
0000007002 00000 n
0000007933 00000 n
0000007982 00000 n
0000008084 00000 n
0000008288 00000 n
0000008336 00000 n
0000008522 00000 n
0000008570 00000 n
0000008809 00000 n
0000008857 00000 n
0000009097 00000 n
0000009145 00000 n
0000009386 00000 n
0000009434 00000 n
trailer <<
/Root 1 0 R
/Size 53
/ID [<a2f146daeb6d814a742556489dab9882><31415926535897932384626433832795>]
>>
startxref
9472
%%EOF

View File

@ -0,0 +1,162 @@
%PDF-2.0
%¿÷¢þ
%QDF-1.0
%% Original object ID: 1 0
1 0 obj
<<
/Pages 3 0 R
/Type /Catalog
>>
endobj
%% Original object ID: 7 0
2 0 obj
<<
/hex#20strings [
(Potato)
<01020300040560>
(AB)
]
/indirect 4 0 R
/names [
/nesting
/hex#20strings
/text#2fplain
]
/nesting <<
/a [
1
2
<<
/x (y)
>>
[
(z)
]
]
/b <<
/ (legal)
/a [
1
2
]
>>
>>
/strings [
(one)
<24a2>
()
(\(\))
(\()
(\))
(a\f\b\t\r\nb)
(")
("")
("\("\)")
<410042>
(a\nb)
(a b)
<feff03c0>
<feffd83edd54>
]
>>
endobj
%% Original object ID: 2 0
3 0 obj
<<
/Count 1
/Kids [
5 0 R
]
/Type /Pages
>>
endobj
%% Original object ID: 8 0
4 0 obj
(hello)
endobj
%% Page 1
%% Original object ID: 3 0
5 0 obj
<<
/Contents 6 0 R
/MediaBox [
0
0
612
792
]
/Parent 3 0 R
/Resources <<
/Font <<
/F1 8 0 R
>>
/ProcSet 9 0 R
>>
/Type /Page
>>
endobj
%% Contents for page 1
%% Original object ID: 4 0
6 0 obj
<<
/Length 7 0 R
>>
stream
BT
/F1 24 Tf
72 720 Td
(Potato) Tj
ET
endstream
endobj
7 0 obj
44
endobj
%% Original object ID: 6 0
8 0 obj
<<
/BaseFont /Helvetica
/Encoding /WinAnsiEncoding
/Name /F1
/Subtype /Type1
/Type /Font
>>
endobj
%% Original object ID: 5 0
9 0 obj
[
/PDF
/Text
]
endobj
xref
0 10
0000000000 65535 f
0000000052 00000 n
0000000133 00000 n
0000000706 00000 n
0000000805 00000 n
0000000866 00000 n
0000001108 00000 n
0000001207 00000 n
0000001253 00000 n
0000001398 00000 n
trailer <<
/QTest 2 0 R
/Root 1 0 R
/Size 10
/ID [<31415926535897932384626433832795><31415926535897932384626433832795>]
>>
startxref
1433
%%EOF

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,120 @@
{
"qpdf-v2": {
"pdfversion": "2.0",
"objects": {
"obj:3 0 R": {
"value": {
"/Contents": "4 0 R",
"/MediaBox": [
0,
0,
612,
792
],
"/Parent": "2 0 R",
"/Resources": {
"/Font": {
"/F1": "6 0 R"
},
"/ProcSet": "5 0 R"
},
"/Type": "/Page"
}
},
"obj:2 0 R": {
"value": {
"/Count": 1,
"/Kids": [
"3 0 R"
],
"/Type": "/Pages"
}
},
"obj:1 0 R": {
"value": {
"/Pages": "2 0 R",
"/Type": "/Catalog"
}
},
"obj:4 0 R": {
"stream": {
"dict": {},
"data": "QlQKICAvRjEgMjQgVGYKICA3MiA3MjAgVGQKICAoUG90YXRvKSBUagpFVAo="
}
},
"obj:5 0 R": {
"value": [
"/PDF",
"/Text"
]
},
"obj:6 0 R": {
"value": {
"/BaseFont": "/Helvetica",
"/Encoding": "/WinAnsiEncoding",
"/Name": "/F1",
"/Subtype": "/Type1",
"/Type": "/Font"
}
},
"trailer": {
"value": {
"/QTest": "7 0 R",
"/Root": "1 0 R",
"/Size": 9
}
},
"obj:7 0 R": {
"value": {
"/hex strings": [
"u:Potato",
"b:01020300040560",
"u:AB"
],
"/indirect": "8 0 R",
"/names": [
"/nesting",
"/hex strings",
"/text/plain"
],
"/nesting": {
"/a": [
1,
2,
{
"/x": "u:y"
},
[
"u:z"
]
],
"/b": {
"/": "u:legal",
"/a": [
1,
2
]
}
},
"/strings": [
"u:one",
"b:24a2",
"u:",
"u:()",
"u:(",
"u:)",
"u:a\f\b\t\r\nb",
"b:410042",
"u:a\nb",
"u:a b",
"u:π",
"u:🥔"
]
}
},
"obj:8 0 R": {
"value": "u:hello"
}
}
}
}

View File

@ -135,7 +135,7 @@ sub get_md5_checksum
sub cleanup
{
system("rm -rf a.json *.ps *.pnm ?.pdf ?.qdf *.enc* tif1 tif2 tiff-cache");
system("rm -rf ?.json *.ps *.pnm ?.pdf ?.qdf *.enc* tif1 tif2 tiff-cache");
system("rm -rf *split-out* ???-kfo.pdf *.tmpout \@file.pdf auto-*");
}