Commit 29f5830325f810612b8c683282133c47f5da0b33

Authored by Jay Berkenbilt
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.
include/qpdf/QPDFObjectHandle.hh
... ... @@ -102,9 +102,9 @@ class QPDFObjectHandle
102 102 // useful for doing rapid type tests (like switch statements) or
103 103 // for testing and debugging.
104 104 QPDF_DLL
105   - QPDFObject::object_type_e getTypeCode() const;
  105 + QPDFObject::object_type_e getTypeCode();
106 106 QPDF_DLL
107   - char const* getTypeName() const;
  107 + char const* getTypeName();
108 108  
109 109 // Exactly one of these will return true for any object. Operator
110 110 // and InlineImage are only allowed in content streams.
... ...
libqpdf/QPDFObjectHandle.cc
... ... @@ -87,10 +87,11 @@ QPDFObjectHandle::isInitialized() const
87 87 }
88 88  
89 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 95 return obj->getTypeCode();
95 96 }
96 97 else
... ... @@ -100,10 +101,11 @@ QPDFObjectHandle::getTypeCode() const
100 101 }
101 102  
102 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 109 return obj->getTypeName();
108 110 }
109 111 else
... ...
qpdf/qtest/qpdf/bad10-recover.out
... ... @@ -2,7 +2,7 @@ WARNING: bad10.pdf: file is damaged
2 2 WARNING: bad10.pdf (trailer, file position 712): /Size key in trailer dictionary is not an integer
3 3 WARNING: bad10.pdf: Attempting to reconstruct cross-reference table
4 4 /QTest is implicit
5   -/QTest is direct
  5 +/QTest is direct and has type null (2)
6 6 /QTest is null
7 7 unparse: null
8 8 unparseResolved: null
... ...
qpdf/qtest/qpdf/bad11-recover.out
... ... @@ -2,7 +2,7 @@ WARNING: bad11.pdf: file is damaged
2 2 WARNING: bad11.pdf (trailer, file position 905): /Prev key in trailer dictionary is not an integer
3 3 WARNING: bad11.pdf: Attempting to reconstruct cross-reference table
4 4 /QTest is implicit
5   -/QTest is direct
  5 +/QTest is direct and has type null (2)
6 6 /QTest is null
7 7 unparse: null
8 8 unparseResolved: null
... ...
qpdf/qtest/qpdf/bad12-recover.out
1 1 WARNING: bad12.pdf: reported number of objects (9) inconsistent with actual number of objects (8)
2 2 /QTest is implicit
3   -/QTest is direct
  3 +/QTest is direct and has type null (2)
4 4 /QTest is null
5 5 unparse: null
6 6 unparseResolved: null
... ...
qpdf/qtest/qpdf/bad12.out
1 1 WARNING: bad12.pdf: reported number of objects (9) inconsistent with actual number of objects (8)
2 2 /QTest is implicit
3   -/QTest is direct
  3 +/QTest is direct and has type null (2)
4 4 /QTest is null
5 5 unparse: null
6 6 unparseResolved: null
... ...
qpdf/qtest/qpdf/bad2-recover.out
... ... @@ -2,7 +2,7 @@ WARNING: bad2.pdf: file is damaged
2 2 WARNING: bad2.pdf: can't find startxref
3 3 WARNING: bad2.pdf: Attempting to reconstruct cross-reference table
4 4 /QTest is implicit
5   -/QTest is direct
  5 +/QTest is direct and has type null (2)
6 6 /QTest is null
7 7 unparse: null
8 8 unparseResolved: null
... ...
qpdf/qtest/qpdf/bad22-recover.out
1 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 3 /QTest is a stream. Dictionary: << /Qength 44 >>
4 4 Raw stream data:
5 5 BT
... ...
qpdf/qtest/qpdf/bad23-recover.out
1 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 3 /QTest is a stream. Dictionary: << /Length () >>
4 4 Raw stream data:
5 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 3 WARNING: bad25.pdf: Attempting to reconstruct cross-reference table
4 4 WARNING: bad25.pdf: object 4 0 not found in file after regenerating cross reference table
5 5 /QTest is implicit
6   -/QTest is indirect
  6 +/QTest is indirect and has type null (2)
7 7 /QTest is null
8 8 unparse: 4 0 R
9 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 3 WARNING: bad26.pdf: Attempting to reconstruct cross-reference table
4 4 WARNING: bad26.pdf: object 4 0 not found in file after regenerating cross reference table
5 5 /QTest is implicit
6   -/QTest is indirect
  6 +/QTest is indirect and has type null (2)
7 7 /QTest is null
8 8 unparse: 4 0 R
9 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 3 WARNING: bad27.pdf: Attempting to reconstruct cross-reference table
4 4 WARNING: bad27.pdf: object 4 0 not found in file after regenerating cross reference table
5 5 /QTest is implicit
6   -/QTest is indirect
  6 +/QTest is indirect and has type null (2)
7 7 /QTest is null
8 8 unparse: 4 0 R
9 9 unparseResolved: null
... ...
qpdf/qtest/qpdf/bad28-recover.out
1 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 3 /QTest is a stream. Dictionary: << /Length 44 >>
4 4 Raw stream data:
5 5 BT
... ...
qpdf/qtest/qpdf/bad28.out
1 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 3 /QTest is a stream. Dictionary: << /Length 44 >>
4 4 Raw stream data:
5 5 BT
... ...
qpdf/qtest/qpdf/bad3-recover.out
... ... @@ -2,7 +2,7 @@ WARNING: bad3.pdf: file is damaged
2 2 WARNING: bad3.pdf (file position 542): xref not found
3 3 WARNING: bad3.pdf: Attempting to reconstruct cross-reference table
4 4 /QTest is implicit
5   -/QTest is direct
  5 +/QTest is direct and has type null (2)
6 6 /QTest is null
7 7 unparse: null
8 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 3 WARNING: bad32.pdf: Attempting to reconstruct cross-reference table
4 4 WARNING: bad32.pdf: object 4 0 not found in file after regenerating cross reference table
5 5 /QTest is implicit
6   -/QTest is indirect
  6 +/QTest is indirect and has type null (2)
7 7 /QTest is null
8 8 unparse: 4 0 R
9 9 unparseResolved: null
... ...
qpdf/qtest/qpdf/bad33-recover.out
No preview for this file type
qpdf/qtest/qpdf/bad34-recover.out
1 1 WARNING: bad34.pdf: file is damaged
2 2 WARNING: bad34.pdf (object 4 0, file position 322): expected n n obj
3 3 WARNING: bad34.pdf: Attempting to reconstruct cross-reference table
4   -/QTest is indirect
  4 +/QTest is indirect and has type stream (10)
5 5 /QTest is a stream. Dictionary: << /Length 44 /Quack 9 0 R >>
6 6 Raw stream data:
7 7 BT
... ...
qpdf/qtest/qpdf/bad4-recover.out
... ... @@ -2,7 +2,7 @@ WARNING: bad4.pdf: file is damaged
2 2 WARNING: bad4.pdf (xref table, file position 547): xref syntax invalid
3 3 WARNING: bad4.pdf: Attempting to reconstruct cross-reference table
4 4 /QTest is implicit
5   -/QTest is direct
  5 +/QTest is direct and has type null (2)
6 6 /QTest is null
7 7 unparse: null
8 8 unparseResolved: null
... ...
qpdf/qtest/qpdf/bad5-recover.out
... ... @@ -2,7 +2,7 @@ WARNING: bad5.pdf: file is damaged
2 2 WARNING: bad5.pdf (xref table, file position 591): invalid xref entry (obj=2)
3 3 WARNING: bad5.pdf: Attempting to reconstruct cross-reference table
4 4 /QTest is implicit
5   -/QTest is direct
  5 +/QTest is direct and has type null (2)
6 6 /QTest is null
7 7 unparse: null
8 8 unparseResolved: null
... ...
qpdf/qtest/qpdf/bad6-recover.out
1 1 /QTest is implicit
2   -/QTest is direct
  2 +/QTest is direct and has type null (2)
3 3 /QTest is null
4 4 unparse: null
5 5 unparseResolved: null
... ...
qpdf/qtest/qpdf/bad6.out
1 1 /QTest is implicit
2   -/QTest is direct
  2 +/QTest is direct and has type null (2)
3 3 /QTest is null
4 4 unparse: null
5 5 unparseResolved: null
... ...
qpdf/qtest/qpdf/bad8-recover.out
... ... @@ -2,7 +2,7 @@ WARNING: bad8.pdf: file is damaged
2 2 WARNING: bad8.pdf (file position 543): xref not found
3 3 WARNING: bad8.pdf: Attempting to reconstruct cross-reference table
4 4 /QTest is implicit
5   -/QTest is direct
  5 +/QTest is direct and has type null (2)
6 6 /QTest is null
7 7 unparse: null
8 8 unparseResolved: null
... ...
qpdf/qtest/qpdf/bad9-recover.out
... ... @@ -2,7 +2,7 @@ WARNING: bad9.pdf: file is damaged
2 2 WARNING: bad9.pdf (trailer, file position 712): trailer dictionary lacks /Size key
3 3 WARNING: bad9.pdf: Attempting to reconstruct cross-reference table
4 4 /QTest is implicit
5   -/QTest is direct
  5 +/QTest is direct and has type null (2)
6 6 /QTest is null
7 7 unparse: null
8 8 unparseResolved: null
... ...
qpdf/qtest/qpdf/good1.out
1 1 /QTest is implicit
2   -/QTest is direct
  2 +/QTest is direct and has type null (2)
3 3 /QTest is null
4 4 unparse: null
5 5 unparseResolved: null
... ...
qpdf/qtest/qpdf/good10.out
1   -/QTest is direct
  1 +/QTest is direct and has type array (8)
2 2 /QTest is an array with 3 items
3 3 item 0 is direct
4 4 item 1 is direct
... ...
qpdf/qtest/qpdf/good11.out
1   -/QTest is direct
  1 +/QTest is direct and has type dictionary (9)
2 2 /QTest is a dictionary
3 3 /a is direct
4 4 unparse: << /a (a) /b 8 0 R >>
... ...
qpdf/qtest/qpdf/good12.out
No preview for this file type
qpdf/qtest/qpdf/good13.out
1   -/QTest is indirect
  1 +/QTest is indirect and has type dictionary (9)
2 2 /QTest is a dictionary
3 3 /hex strings is direct
4 4 /indirect is indirect
... ...
qpdf/qtest/qpdf/good15.out
1   -/QTest is direct
  1 +/QTest is direct and has type name (7)
2 2 /QTest is a name with value /oink
3 3 unparse: /oink
4 4 unparseResolved: /oink
... ...
qpdf/qtest/qpdf/good16.out
1 1 /QTest is implicit
2   -/QTest is direct
  2 +/QTest is direct and has type null (2)
3 3 /QTest is null
4 4 unparse: null
5 5 unparseResolved: null
... ...
qpdf/qtest/qpdf/good17.out
1 1 /QTest is implicit
2   -/QTest is direct
  2 +/QTest is direct and has type null (2)
3 3 /QTest is null
4 4 unparse: null
5 5 unparseResolved: null
... ...
qpdf/qtest/qpdf/good18.out
1 1 /QTest is implicit
2   -/QTest is direct
  2 +/QTest is direct and has type null (2)
3 3 /QTest is null
4 4 unparse: null
5 5 unparseResolved: null
... ...
qpdf/qtest/qpdf/good19.out
1 1 /QTest is implicit
2   -/QTest is direct
  2 +/QTest is direct and has type null (2)
3 3 /QTest is null
4 4 unparse: null
5 5 unparseResolved: null
... ...
qpdf/qtest/qpdf/good2.out
1 1 /QTest is implicit
2   -/QTest is direct
  2 +/QTest is direct and has type null (2)
3 3 /QTest is null
4 4 unparse: null
5 5 unparseResolved: null
... ...
qpdf/qtest/qpdf/good20.out
1 1 /QTest is implicit
2   -/QTest is direct
  2 +/QTest is direct and has type null (2)
3 3 /QTest is null
4 4 unparse: null
5 5 unparseResolved: null
... ...
qpdf/qtest/qpdf/good3.out
1 1 /QTest is implicit
2   -/QTest is indirect
  2 +/QTest is indirect and has type null (2)
3 3 /QTest is null
4 4 unparse: 7 0 R
5 5 unparseResolved: null
... ...
qpdf/qtest/qpdf/good4.out
1 1 /QTest is implicit
2   -/QTest is indirect
  2 +/QTest is indirect and has type null (2)
3 3 /QTest is null
4 4 unparse: 7 0 R
5 5 unparseResolved: null
... ...
qpdf/qtest/qpdf/good5.out
1   -/QTest is indirect
  1 +/QTest is indirect and has type boolean (3)
2 2 /QTest is Boolean with value true
3 3 unparse: 7 0 R
4 4 unparseResolved: true
... ...
qpdf/qtest/qpdf/good6.out
1   -/QTest is direct
  1 +/QTest is direct and has type boolean (3)
2 2 /QTest is Boolean with value false
3 3 unparse: false
4 4 unparseResolved: false
... ...
qpdf/qtest/qpdf/good7.out
1   -/QTest is direct
  1 +/QTest is direct and has type integer (4)
2 2 /QTest is an integer with value 16059
3 3 unparse: 16059
4 4 unparseResolved: 16059
... ...
qpdf/qtest/qpdf/good8.out
1   -/QTest is indirect
  1 +/QTest is indirect and has type real (5)
2 2 /QTest is a real number with value 3.14159
3 3 unparse: 7 0 R
4 4 unparseResolved: 3.14159
... ...
qpdf/qtest/qpdf/good9.out
1   -/QTest is direct
  1 +/QTest is direct and has type string (6)
2 2 /QTest is a string with value ¡Hola!
3 3 unparse: (¡Hola!)
4 4 unparseResolved: (¡Hola!)
... ...
qpdf/test_driver.cc
... ... @@ -232,7 +232,9 @@ void runtest(int n, char const* filename1, char const* arg2)
232 232 qtest.isIndirect() ? 1 : 0);
233 233 std::cout << "/QTest is "
234 234 << (qtest.isIndirect() ? "in" : "")
235   - << "direct" << std::endl;
  235 + << "direct and has type "
  236 + << qtest.getTypeName()
  237 + << " (" << qtest.getTypeCode() << ")" << std::endl;
236 238  
237 239 if (qtest.isNull())
238 240 {
... ...