Commit 29f5830325f810612b8c683282133c47f5da0b33
1 parent
119f2a4b
Fix getTypeCode and getTypeName work for indirect objects
Remove const qualifier from getTypeCode and get getTypeName methods of QPDFObjectHandle, make them work properly for indirect objects, and exercise them much better in the test suite.
Showing
48 changed files
with
56 additions
and
52 deletions
include/qpdf/QPDFObjectHandle.hh
| @@ -102,9 +102,9 @@ class QPDFObjectHandle | @@ -102,9 +102,9 @@ class QPDFObjectHandle | ||
| 102 | // useful for doing rapid type tests (like switch statements) or | 102 | // useful for doing rapid type tests (like switch statements) or |
| 103 | // for testing and debugging. | 103 | // for testing and debugging. |
| 104 | QPDF_DLL | 104 | QPDF_DLL |
| 105 | - QPDFObject::object_type_e getTypeCode() const; | 105 | + QPDFObject::object_type_e getTypeCode(); |
| 106 | QPDF_DLL | 106 | QPDF_DLL |
| 107 | - char const* getTypeName() const; | 107 | + char const* getTypeName(); |
| 108 | 108 | ||
| 109 | // Exactly one of these will return true for any object. Operator | 109 | // Exactly one of these will return true for any object. Operator |
| 110 | // and InlineImage are only allowed in content streams. | 110 | // and InlineImage are only allowed in content streams. |
libqpdf/QPDFObjectHandle.cc
| @@ -87,10 +87,11 @@ QPDFObjectHandle::isInitialized() const | @@ -87,10 +87,11 @@ QPDFObjectHandle::isInitialized() const | ||
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | QPDFObject::object_type_e | 89 | QPDFObject::object_type_e |
| 90 | -QPDFObjectHandle::getTypeCode() const | 90 | +QPDFObjectHandle::getTypeCode() |
| 91 | { | 91 | { |
| 92 | - if (obj.getPointer()) | 92 | + if (this->initialized) |
| 93 | { | 93 | { |
| 94 | + dereference(); | ||
| 94 | return obj->getTypeCode(); | 95 | return obj->getTypeCode(); |
| 95 | } | 96 | } |
| 96 | else | 97 | else |
| @@ -100,10 +101,11 @@ QPDFObjectHandle::getTypeCode() const | @@ -100,10 +101,11 @@ QPDFObjectHandle::getTypeCode() const | ||
| 100 | } | 101 | } |
| 101 | 102 | ||
| 102 | char const* | 103 | char const* |
| 103 | -QPDFObjectHandle::getTypeName() const | 104 | +QPDFObjectHandle::getTypeName() |
| 104 | { | 105 | { |
| 105 | - if (obj.getPointer()) | 106 | + if (this->initialized) |
| 106 | { | 107 | { |
| 108 | + dereference(); | ||
| 107 | return obj->getTypeName(); | 109 | return obj->getTypeName(); |
| 108 | } | 110 | } |
| 109 | else | 111 | else |
qpdf/qtest/qpdf/bad10-recover.out
| @@ -2,7 +2,7 @@ WARNING: bad10.pdf: file is damaged | @@ -2,7 +2,7 @@ WARNING: bad10.pdf: file is damaged | ||
| 2 | WARNING: bad10.pdf (trailer, file position 712): /Size key in trailer dictionary is not an integer | 2 | WARNING: bad10.pdf (trailer, file position 712): /Size key in trailer dictionary is not an integer |
| 3 | WARNING: bad10.pdf: Attempting to reconstruct cross-reference table | 3 | WARNING: bad10.pdf: Attempting to reconstruct cross-reference table |
| 4 | /QTest is implicit | 4 | /QTest is implicit |
| 5 | -/QTest is direct | 5 | +/QTest is direct and has type null (2) |
| 6 | /QTest is null | 6 | /QTest is null |
| 7 | unparse: null | 7 | unparse: null |
| 8 | unparseResolved: null | 8 | unparseResolved: null |
qpdf/qtest/qpdf/bad11-recover.out
| @@ -2,7 +2,7 @@ WARNING: bad11.pdf: file is damaged | @@ -2,7 +2,7 @@ WARNING: bad11.pdf: file is damaged | ||
| 2 | WARNING: bad11.pdf (trailer, file position 905): /Prev key in trailer dictionary is not an integer | 2 | WARNING: bad11.pdf (trailer, file position 905): /Prev key in trailer dictionary is not an integer |
| 3 | WARNING: bad11.pdf: Attempting to reconstruct cross-reference table | 3 | WARNING: bad11.pdf: Attempting to reconstruct cross-reference table |
| 4 | /QTest is implicit | 4 | /QTest is implicit |
| 5 | -/QTest is direct | 5 | +/QTest is direct and has type null (2) |
| 6 | /QTest is null | 6 | /QTest is null |
| 7 | unparse: null | 7 | unparse: null |
| 8 | unparseResolved: null | 8 | unparseResolved: null |
qpdf/qtest/qpdf/bad12-recover.out
| 1 | WARNING: bad12.pdf: reported number of objects (9) inconsistent with actual number of objects (8) | 1 | WARNING: bad12.pdf: reported number of objects (9) inconsistent with actual number of objects (8) |
| 2 | /QTest is implicit | 2 | /QTest is implicit |
| 3 | -/QTest is direct | 3 | +/QTest is direct and has type null (2) |
| 4 | /QTest is null | 4 | /QTest is null |
| 5 | unparse: null | 5 | unparse: null |
| 6 | unparseResolved: null | 6 | unparseResolved: null |
qpdf/qtest/qpdf/bad12.out
| 1 | WARNING: bad12.pdf: reported number of objects (9) inconsistent with actual number of objects (8) | 1 | WARNING: bad12.pdf: reported number of objects (9) inconsistent with actual number of objects (8) |
| 2 | /QTest is implicit | 2 | /QTest is implicit |
| 3 | -/QTest is direct | 3 | +/QTest is direct and has type null (2) |
| 4 | /QTest is null | 4 | /QTest is null |
| 5 | unparse: null | 5 | unparse: null |
| 6 | unparseResolved: null | 6 | unparseResolved: null |
qpdf/qtest/qpdf/bad2-recover.out
| @@ -2,7 +2,7 @@ WARNING: bad2.pdf: file is damaged | @@ -2,7 +2,7 @@ WARNING: bad2.pdf: file is damaged | ||
| 2 | WARNING: bad2.pdf: can't find startxref | 2 | WARNING: bad2.pdf: can't find startxref |
| 3 | WARNING: bad2.pdf: Attempting to reconstruct cross-reference table | 3 | WARNING: bad2.pdf: Attempting to reconstruct cross-reference table |
| 4 | /QTest is implicit | 4 | /QTest is implicit |
| 5 | -/QTest is direct | 5 | +/QTest is direct and has type null (2) |
| 6 | /QTest is null | 6 | /QTest is null |
| 7 | unparse: null | 7 | unparse: null |
| 8 | unparseResolved: null | 8 | unparseResolved: null |
qpdf/qtest/qpdf/bad22-recover.out
| 1 | WARNING: bad22.pdf (object 4 0, file position 341): attempting to recover stream length | 1 | WARNING: bad22.pdf (object 4 0, file position 341): attempting to recover stream length |
| 2 | -/QTest is indirect | 2 | +/QTest is indirect and has type stream (10) |
| 3 | /QTest is a stream. Dictionary: << /Qength 44 >> | 3 | /QTest is a stream. Dictionary: << /Qength 44 >> |
| 4 | Raw stream data: | 4 | Raw stream data: |
| 5 | BT | 5 | BT |
qpdf/qtest/qpdf/bad23-recover.out
| 1 | WARNING: bad23.pdf (object 4 0, file position 341): attempting to recover stream length | 1 | WARNING: bad23.pdf (object 4 0, file position 341): attempting to recover stream length |
| 2 | -/QTest is indirect | 2 | +/QTest is indirect and has type stream (10) |
| 3 | /QTest is a stream. Dictionary: << /Length () >> | 3 | /QTest is a stream. Dictionary: << /Length () >> |
| 4 | Raw stream data: | 4 | Raw stream data: |
| 5 | BT | 5 | BT |
qpdf/qtest/qpdf/bad25-recover.out
| @@ -3,7 +3,7 @@ WARNING: bad25.pdf (object 4 0, file position 307): expected n n obj | @@ -3,7 +3,7 @@ WARNING: bad25.pdf (object 4 0, file position 307): expected n n obj | ||
| 3 | WARNING: bad25.pdf: Attempting to reconstruct cross-reference table | 3 | WARNING: bad25.pdf: Attempting to reconstruct cross-reference table |
| 4 | WARNING: bad25.pdf: object 4 0 not found in file after regenerating cross reference table | 4 | WARNING: bad25.pdf: object 4 0 not found in file after regenerating cross reference table |
| 5 | /QTest is implicit | 5 | /QTest is implicit |
| 6 | -/QTest is indirect | 6 | +/QTest is indirect and has type null (2) |
| 7 | /QTest is null | 7 | /QTest is null |
| 8 | unparse: 4 0 R | 8 | unparse: 4 0 R |
| 9 | unparseResolved: null | 9 | unparseResolved: null |
qpdf/qtest/qpdf/bad26-recover.out
| @@ -3,7 +3,7 @@ WARNING: bad26.pdf (object 4 0, file position 307): expected n n obj | @@ -3,7 +3,7 @@ WARNING: bad26.pdf (object 4 0, file position 307): expected n n obj | ||
| 3 | WARNING: bad26.pdf: Attempting to reconstruct cross-reference table | 3 | WARNING: bad26.pdf: Attempting to reconstruct cross-reference table |
| 4 | WARNING: bad26.pdf: object 4 0 not found in file after regenerating cross reference table | 4 | WARNING: bad26.pdf: object 4 0 not found in file after regenerating cross reference table |
| 5 | /QTest is implicit | 5 | /QTest is implicit |
| 6 | -/QTest is indirect | 6 | +/QTest is indirect and has type null (2) |
| 7 | /QTest is null | 7 | /QTest is null |
| 8 | unparse: 4 0 R | 8 | unparse: 4 0 R |
| 9 | unparseResolved: null | 9 | unparseResolved: null |
qpdf/qtest/qpdf/bad27-recover.out
| @@ -3,7 +3,7 @@ WARNING: bad27.pdf (object 4 0, file position 307): expected n n obj | @@ -3,7 +3,7 @@ WARNING: bad27.pdf (object 4 0, file position 307): expected n n obj | ||
| 3 | WARNING: bad27.pdf: Attempting to reconstruct cross-reference table | 3 | WARNING: bad27.pdf: Attempting to reconstruct cross-reference table |
| 4 | WARNING: bad27.pdf: object 4 0 not found in file after regenerating cross reference table | 4 | WARNING: bad27.pdf: object 4 0 not found in file after regenerating cross reference table |
| 5 | /QTest is implicit | 5 | /QTest is implicit |
| 6 | -/QTest is indirect | 6 | +/QTest is indirect and has type null (2) |
| 7 | /QTest is null | 7 | /QTest is null |
| 8 | unparse: 4 0 R | 8 | unparse: 4 0 R |
| 9 | unparseResolved: null | 9 | unparseResolved: null |
qpdf/qtest/qpdf/bad28-recover.out
| 1 | WARNING: bad28.pdf (object 4 0, file position 395): expected endobj | 1 | WARNING: bad28.pdf (object 4 0, file position 395): expected endobj |
| 2 | -/QTest is indirect | 2 | +/QTest is indirect and has type stream (10) |
| 3 | /QTest is a stream. Dictionary: << /Length 44 >> | 3 | /QTest is a stream. Dictionary: << /Length 44 >> |
| 4 | Raw stream data: | 4 | Raw stream data: |
| 5 | BT | 5 | BT |
qpdf/qtest/qpdf/bad28.out
| 1 | WARNING: bad28.pdf (object 4 0, file position 395): expected endobj | 1 | WARNING: bad28.pdf (object 4 0, file position 395): expected endobj |
| 2 | -/QTest is indirect | 2 | +/QTest is indirect and has type stream (10) |
| 3 | /QTest is a stream. Dictionary: << /Length 44 >> | 3 | /QTest is a stream. Dictionary: << /Length 44 >> |
| 4 | Raw stream data: | 4 | Raw stream data: |
| 5 | BT | 5 | BT |
qpdf/qtest/qpdf/bad3-recover.out
| @@ -2,7 +2,7 @@ WARNING: bad3.pdf: file is damaged | @@ -2,7 +2,7 @@ WARNING: bad3.pdf: file is damaged | ||
| 2 | WARNING: bad3.pdf (file position 542): xref not found | 2 | WARNING: bad3.pdf (file position 542): xref not found |
| 3 | WARNING: bad3.pdf: Attempting to reconstruct cross-reference table | 3 | WARNING: bad3.pdf: Attempting to reconstruct cross-reference table |
| 4 | /QTest is implicit | 4 | /QTest is implicit |
| 5 | -/QTest is direct | 5 | +/QTest is direct and has type null (2) |
| 6 | /QTest is null | 6 | /QTest is null |
| 7 | unparse: null | 7 | unparse: null |
| 8 | unparseResolved: null | 8 | unparseResolved: null |
qpdf/qtest/qpdf/bad30-recover.out
No preview for this file type
qpdf/qtest/qpdf/bad30.out
No preview for this file type
qpdf/qtest/qpdf/bad31-recover.out
No preview for this file type
qpdf/qtest/qpdf/bad31.out
No preview for this file type
qpdf/qtest/qpdf/bad32-recover.out
| @@ -3,7 +3,7 @@ WARNING: bad32.pdf (object 4 0, file position 307): expected 4 0 obj | @@ -3,7 +3,7 @@ WARNING: bad32.pdf (object 4 0, file position 307): expected 4 0 obj | ||
| 3 | WARNING: bad32.pdf: Attempting to reconstruct cross-reference table | 3 | WARNING: bad32.pdf: Attempting to reconstruct cross-reference table |
| 4 | WARNING: bad32.pdf: object 4 0 not found in file after regenerating cross reference table | 4 | WARNING: bad32.pdf: object 4 0 not found in file after regenerating cross reference table |
| 5 | /QTest is implicit | 5 | /QTest is implicit |
| 6 | -/QTest is indirect | 6 | +/QTest is indirect and has type null (2) |
| 7 | /QTest is null | 7 | /QTest is null |
| 8 | unparse: 4 0 R | 8 | unparse: 4 0 R |
| 9 | unparseResolved: null | 9 | unparseResolved: null |
qpdf/qtest/qpdf/bad33-recover.out
No preview for this file type
qpdf/qtest/qpdf/bad34-recover.out
| 1 | WARNING: bad34.pdf: file is damaged | 1 | WARNING: bad34.pdf: file is damaged |
| 2 | WARNING: bad34.pdf (object 4 0, file position 322): expected n n obj | 2 | WARNING: bad34.pdf (object 4 0, file position 322): expected n n obj |
| 3 | WARNING: bad34.pdf: Attempting to reconstruct cross-reference table | 3 | WARNING: bad34.pdf: Attempting to reconstruct cross-reference table |
| 4 | -/QTest is indirect | 4 | +/QTest is indirect and has type stream (10) |
| 5 | /QTest is a stream. Dictionary: << /Length 44 /Quack 9 0 R >> | 5 | /QTest is a stream. Dictionary: << /Length 44 /Quack 9 0 R >> |
| 6 | Raw stream data: | 6 | Raw stream data: |
| 7 | BT | 7 | BT |
qpdf/qtest/qpdf/bad4-recover.out
| @@ -2,7 +2,7 @@ WARNING: bad4.pdf: file is damaged | @@ -2,7 +2,7 @@ WARNING: bad4.pdf: file is damaged | ||
| 2 | WARNING: bad4.pdf (xref table, file position 547): xref syntax invalid | 2 | WARNING: bad4.pdf (xref table, file position 547): xref syntax invalid |
| 3 | WARNING: bad4.pdf: Attempting to reconstruct cross-reference table | 3 | WARNING: bad4.pdf: Attempting to reconstruct cross-reference table |
| 4 | /QTest is implicit | 4 | /QTest is implicit |
| 5 | -/QTest is direct | 5 | +/QTest is direct and has type null (2) |
| 6 | /QTest is null | 6 | /QTest is null |
| 7 | unparse: null | 7 | unparse: null |
| 8 | unparseResolved: null | 8 | unparseResolved: null |
qpdf/qtest/qpdf/bad5-recover.out
| @@ -2,7 +2,7 @@ WARNING: bad5.pdf: file is damaged | @@ -2,7 +2,7 @@ WARNING: bad5.pdf: file is damaged | ||
| 2 | WARNING: bad5.pdf (xref table, file position 591): invalid xref entry (obj=2) | 2 | WARNING: bad5.pdf (xref table, file position 591): invalid xref entry (obj=2) |
| 3 | WARNING: bad5.pdf: Attempting to reconstruct cross-reference table | 3 | WARNING: bad5.pdf: Attempting to reconstruct cross-reference table |
| 4 | /QTest is implicit | 4 | /QTest is implicit |
| 5 | -/QTest is direct | 5 | +/QTest is direct and has type null (2) |
| 6 | /QTest is null | 6 | /QTest is null |
| 7 | unparse: null | 7 | unparse: null |
| 8 | unparseResolved: null | 8 | unparseResolved: null |
qpdf/qtest/qpdf/bad6-recover.out
qpdf/qtest/qpdf/bad6.out
qpdf/qtest/qpdf/bad8-recover.out
| @@ -2,7 +2,7 @@ WARNING: bad8.pdf: file is damaged | @@ -2,7 +2,7 @@ WARNING: bad8.pdf: file is damaged | ||
| 2 | WARNING: bad8.pdf (file position 543): xref not found | 2 | WARNING: bad8.pdf (file position 543): xref not found |
| 3 | WARNING: bad8.pdf: Attempting to reconstruct cross-reference table | 3 | WARNING: bad8.pdf: Attempting to reconstruct cross-reference table |
| 4 | /QTest is implicit | 4 | /QTest is implicit |
| 5 | -/QTest is direct | 5 | +/QTest is direct and has type null (2) |
| 6 | /QTest is null | 6 | /QTest is null |
| 7 | unparse: null | 7 | unparse: null |
| 8 | unparseResolved: null | 8 | unparseResolved: null |
qpdf/qtest/qpdf/bad9-recover.out
| @@ -2,7 +2,7 @@ WARNING: bad9.pdf: file is damaged | @@ -2,7 +2,7 @@ WARNING: bad9.pdf: file is damaged | ||
| 2 | WARNING: bad9.pdf (trailer, file position 712): trailer dictionary lacks /Size key | 2 | WARNING: bad9.pdf (trailer, file position 712): trailer dictionary lacks /Size key |
| 3 | WARNING: bad9.pdf: Attempting to reconstruct cross-reference table | 3 | WARNING: bad9.pdf: Attempting to reconstruct cross-reference table |
| 4 | /QTest is implicit | 4 | /QTest is implicit |
| 5 | -/QTest is direct | 5 | +/QTest is direct and has type null (2) |
| 6 | /QTest is null | 6 | /QTest is null |
| 7 | unparse: null | 7 | unparse: null |
| 8 | unparseResolved: null | 8 | unparseResolved: null |
qpdf/qtest/qpdf/good1.out
qpdf/qtest/qpdf/good10.out
qpdf/qtest/qpdf/good11.out
qpdf/qtest/qpdf/good12.out
No preview for this file type
qpdf/qtest/qpdf/good13.out
qpdf/qtest/qpdf/good15.out
qpdf/qtest/qpdf/good16.out
qpdf/qtest/qpdf/good17.out
qpdf/qtest/qpdf/good18.out
qpdf/qtest/qpdf/good19.out
qpdf/qtest/qpdf/good2.out
qpdf/qtest/qpdf/good20.out
qpdf/qtest/qpdf/good3.out
qpdf/qtest/qpdf/good4.out
qpdf/qtest/qpdf/good5.out
qpdf/qtest/qpdf/good6.out
qpdf/qtest/qpdf/good7.out
qpdf/qtest/qpdf/good8.out
qpdf/qtest/qpdf/good9.out
qpdf/test_driver.cc
| @@ -232,7 +232,9 @@ void runtest(int n, char const* filename1, char const* arg2) | @@ -232,7 +232,9 @@ void runtest(int n, char const* filename1, char const* arg2) | ||
| 232 | qtest.isIndirect() ? 1 : 0); | 232 | qtest.isIndirect() ? 1 : 0); |
| 233 | std::cout << "/QTest is " | 233 | std::cout << "/QTest is " |
| 234 | << (qtest.isIndirect() ? "in" : "") | 234 | << (qtest.isIndirect() ? "in" : "") |
| 235 | - << "direct" << std::endl; | 235 | + << "direct and has type " |
| 236 | + << qtest.getTypeName() | ||
| 237 | + << " (" << qtest.getTypeCode() << ")" << std::endl; | ||
| 236 | 238 | ||
| 237 | if (qtest.isNull()) | 239 | if (qtest.isNull()) |
| 238 | { | 240 | { |