2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-06-14 16:12:20 +00:00

Tests with manually constructed qpdf json

This commit is contained in:
Jay Berkenbilt 2022-05-19 19:22:32 -04:00
parent 7f8c4b183d
commit a83b7b0611
6 changed files with 481 additions and 11 deletions

4
TODO
View File

@ -97,10 +97,6 @@ General things to remember:
* Add json to the large file tests.
* Object representation tests
* "b:cf80", "b:CF80", "u:π", "u:\u03c0"
* "b:d83edd54", "u:🥔", "u:\ud83e\udd54"
JSON to PDF:
Have --json-input and --update-from-json. With --json-input, the json

View File

@ -67,30 +67,30 @@ foreach my $i (@goodfiles)
if (ref($i) eq 'ARRAY') {
($f, $xargs) = @$i;
}
$td->runtest("good: $f -> json",
$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->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->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->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->runtest("good: $f -> aqdf",
{$td->COMMAND =>
"qpdf $xargs --object-streams=disable --qdf" .
" --stream-data=preserve --static-id $f b.pdf"},
@ -115,7 +115,34 @@ foreach my $i (@goodfiles)
{$td->FILE => $exp}); # from original PDF
}
$n_tests += 6;
$td->runtest("manual JSON to PDF",
{$td->COMMAND => "qpdf --json-input --static-id --qdf" .
" manual-qpdf-json.json a.pdf"},
{$td->STRING => "", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("check manual JSON to PDF",
{$td->FILE => "a.pdf"},
{$td->FILE => "manual-qpdf-json.pdf"});
$td->runtest("check manual JSON to PDF to JSON",
{$td->COMMAND => "qpdf --json-output=2 a.pdf -"},
{$td->FILE => "manual-qpdf-json-pdf.json", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("manual JSON to JSON",
{$td->COMMAND => "qpdf --json-input --json-output=2" .
" manual-qpdf-json.json a.json"},
{$td->STRING => "", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
$td->runtest("check manual JSON to JSON",
{$td->FILE => "a.json"},
{$td->FILE => "manual-qpdf-json-out.json"},
$td->NORMALIZE_NEWLINES);
$td->runtest("check manual JSON to JSON to JSON",
{$td->COMMAND => "qpdf --json-output=2 --json-input a.json -"},
{$td->FILE => "a.json", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
# QXXXQ file
cleanup();
$td->report($n_tests);

View File

@ -0,0 +1,133 @@
{
"qpdf-v2": {
"pdfversion": "2.0",
"maxobjectid": 8,
"objects": {
"obj:1 0 R": {
"value": {
"/Pages": "2 0 R",
"/Type": "/Catalog"
}
},
"obj:2 0 R": {
"value": {
"/Count": 1,
"/Kids": [
"3 0 R"
],
"/Type": "/Pages"
}
},
"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:4 0 R": {
"stream": {
"data": "QlQKICAvRjEgMjQgVGYKICA3MiA3MjAgVGQKICAoUG90YXRvKSBUagpFVAo=",
"dict": {}
}
},
"obj:5 0 R": {
"value": [
"/PDF",
"/Text"
]
},
"obj:6 0 R": {
"value": {
"/BaseFont": "/Helvetica",
"/Encoding": "/WinAnsiEncoding",
"/Name": "/F1",
"/Subtype": "/Type1",
"/Type": "/Font"
}
},
"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",
"u:\"",
"u:\"\"",
"u:\"(\")\"",
"b:410042",
"u:a\nb",
"u:a b",
[
"u:π",
"u:π",
"u:π",
"u:π"
],
[
"u:🥔",
"u:🥔",
"u:🥔"
]
]
}
},
"obj:8 0 R": {
"value": "u:hello"
},
"trailer": {
"value": {
"/QTest": "7 0 R",
"/Root": "1 0 R",
"/Size": 9
}
}
}
}
}

View File

@ -0,0 +1,140 @@
{
"qpdf-v2": {
"pdfversion": "2.0",
"maxobjectid": 9,
"objects": {
"obj:1 0 R": {
"value": {
"/Pages": "3 0 R",
"/Type": "/Catalog"
}
},
"obj:2 0 R": {
"value": {
"/hex strings": [
"u:Potato",
"b:01020300040560",
"u:AB"
],
"/indirect": "4 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",
"u:\"",
"u:\"\"",
"u:\"(\")\"",
"b:410042",
"u:a\nb",
"u:a b",
[
"u:π",
"u:π",
"u:π",
"u:π"
],
[
"u:🥔",
"u:🥔",
"u:🥔"
]
]
}
},
"obj:3 0 R": {
"value": {
"/Count": 1,
"/Kids": [
"5 0 R"
],
"/Type": "/Pages"
}
},
"obj:4 0 R": {
"value": "u:hello"
},
"obj:5 0 R": {
"value": {
"/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"
}
},
"obj:6 0 R": {
"stream": {
"data": "QlQKICAvRjEgMjQgVGYKICA3MiA3MjAgVGQKICAoUG90YXRvKSBUagpFVAo=",
"dict": {}
}
},
"obj:7 0 R": {
"value": 44
},
"obj:8 0 R": {
"value": {
"/BaseFont": "/Helvetica",
"/Encoding": "/WinAnsiEncoding",
"/Name": "/F1",
"/Subtype": "/Type1",
"/Type": "/Font"
}
},
"obj:9 0 R": {
"value": [
"/PDF",
"/Text"
]
},
"trailer": {
"value": {
"/ID": [
"b:31415926535897932384626433832795",
"b:31415926535897932384626433832795"
],
"/QTest": "2 0 R",
"/Root": "1 0 R",
"/Size": 10
}
}
}
}
}

View File

@ -104,11 +104,14 @@
"u:(",
"u:)",
"u:a\f\b\t\r\nb",
"u:\"",
"u:\"\"",
"u:\"(\")\"",
"b:410042",
"u:a\nb",
"u:a b",
"u:π",
"u:🥔"
["u:π", "u:\u03c0", "b:EFBBBFCF80", "b:feff03c0"],
["u:🥔", "u:\ud83e\udd54", "b:feffd83eDD54"]
]
}
},

View File

@ -0,0 +1,171 @@
%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>
<feff03c0>
<efbbbfcf80>
<feff03c0>
]
[
<feffd83edd54>
<feffd83edd54>
<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
0000000829 00000 n
0000000928 00000 n
0000000989 00000 n
0000001231 00000 n
0000001330 00000 n
0000001376 00000 n
0000001521 00000 n
trailer <<
/QTest 2 0 R
/Root 1 0 R
/Size 10
/ID [<31415926535897932384626433832795><31415926535897932384626433832795>]
>>
startxref
1556
%%EOF