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.
This commit is contained in:
Jay Berkenbilt 2013-03-04 10:59:20 -05:00
parent 119f2a4b68
commit 29f5830325
48 changed files with 56 additions and 52 deletions

View File

@ -102,9 +102,9 @@ class QPDFObjectHandle
// useful for doing rapid type tests (like switch statements) or
// for testing and debugging.
QPDF_DLL
QPDFObject::object_type_e getTypeCode() const;
QPDFObject::object_type_e getTypeCode();
QPDF_DLL
char const* getTypeName() const;
char const* getTypeName();
// Exactly one of these will return true for any object. Operator
// and InlineImage are only allowed in content streams.

View File

@ -87,10 +87,11 @@ QPDFObjectHandle::isInitialized() const
}
QPDFObject::object_type_e
QPDFObjectHandle::getTypeCode() const
QPDFObjectHandle::getTypeCode()
{
if (obj.getPointer())
if (this->initialized)
{
dereference();
return obj->getTypeCode();
}
else
@ -100,10 +101,11 @@ QPDFObjectHandle::getTypeCode() const
}
char const*
QPDFObjectHandle::getTypeName() const
QPDFObjectHandle::getTypeName()
{
if (obj.getPointer())
if (this->initialized)
{
dereference();
return obj->getTypeName();
}
else

View File

@ -2,7 +2,7 @@ WARNING: bad10.pdf: file is damaged
WARNING: bad10.pdf (trailer, file position 712): /Size key in trailer dictionary is not an integer
WARNING: bad10.pdf: Attempting to reconstruct cross-reference table
/QTest is implicit
/QTest is direct
/QTest is direct and has type null (2)
/QTest is null
unparse: null
unparseResolved: null

View File

@ -2,7 +2,7 @@ WARNING: bad11.pdf: file is damaged
WARNING: bad11.pdf (trailer, file position 905): /Prev key in trailer dictionary is not an integer
WARNING: bad11.pdf: Attempting to reconstruct cross-reference table
/QTest is implicit
/QTest is direct
/QTest is direct and has type null (2)
/QTest is null
unparse: null
unparseResolved: null

View File

@ -1,6 +1,6 @@
WARNING: bad12.pdf: reported number of objects (9) inconsistent with actual number of objects (8)
/QTest is implicit
/QTest is direct
/QTest is direct and has type null (2)
/QTest is null
unparse: null
unparseResolved: null

View File

@ -1,6 +1,6 @@
WARNING: bad12.pdf: reported number of objects (9) inconsistent with actual number of objects (8)
/QTest is implicit
/QTest is direct
/QTest is direct and has type null (2)
/QTest is null
unparse: null
unparseResolved: null

View File

@ -2,7 +2,7 @@ WARNING: bad2.pdf: file is damaged
WARNING: bad2.pdf: can't find startxref
WARNING: bad2.pdf: Attempting to reconstruct cross-reference table
/QTest is implicit
/QTest is direct
/QTest is direct and has type null (2)
/QTest is null
unparse: null
unparseResolved: null

View File

@ -1,5 +1,5 @@
WARNING: bad22.pdf (object 4 0, file position 341): attempting to recover stream length
/QTest is indirect
/QTest is indirect and has type stream (10)
/QTest is a stream. Dictionary: << /Qength 44 >>
Raw stream data:
BT

View File

@ -1,5 +1,5 @@
WARNING: bad23.pdf (object 4 0, file position 341): attempting to recover stream length
/QTest is indirect
/QTest is indirect and has type stream (10)
/QTest is a stream. Dictionary: << /Length () >>
Raw stream data:
BT

View File

@ -3,7 +3,7 @@ WARNING: bad25.pdf (object 4 0, file position 307): expected n n obj
WARNING: bad25.pdf: Attempting to reconstruct cross-reference table
WARNING: bad25.pdf: object 4 0 not found in file after regenerating cross reference table
/QTest is implicit
/QTest is indirect
/QTest is indirect and has type null (2)
/QTest is null
unparse: 4 0 R
unparseResolved: null

View File

@ -3,7 +3,7 @@ WARNING: bad26.pdf (object 4 0, file position 307): expected n n obj
WARNING: bad26.pdf: Attempting to reconstruct cross-reference table
WARNING: bad26.pdf: object 4 0 not found in file after regenerating cross reference table
/QTest is implicit
/QTest is indirect
/QTest is indirect and has type null (2)
/QTest is null
unparse: 4 0 R
unparseResolved: null

View File

@ -3,7 +3,7 @@ WARNING: bad27.pdf (object 4 0, file position 307): expected n n obj
WARNING: bad27.pdf: Attempting to reconstruct cross-reference table
WARNING: bad27.pdf: object 4 0 not found in file after regenerating cross reference table
/QTest is implicit
/QTest is indirect
/QTest is indirect and has type null (2)
/QTest is null
unparse: 4 0 R
unparseResolved: null

View File

@ -1,5 +1,5 @@
WARNING: bad28.pdf (object 4 0, file position 395): expected endobj
/QTest is indirect
/QTest is indirect and has type stream (10)
/QTest is a stream. Dictionary: << /Length 44 >>
Raw stream data:
BT

View File

@ -1,5 +1,5 @@
WARNING: bad28.pdf (object 4 0, file position 395): expected endobj
/QTest is indirect
/QTest is indirect and has type stream (10)
/QTest is a stream. Dictionary: << /Length 44 >>
Raw stream data:
BT

View File

@ -2,7 +2,7 @@ WARNING: bad3.pdf: file is damaged
WARNING: bad3.pdf (file position 542): xref not found
WARNING: bad3.pdf: Attempting to reconstruct cross-reference table
/QTest is implicit
/QTest is direct
/QTest is direct and has type null (2)
/QTest is null
unparse: null
unparseResolved: null

View File

@ -1,4 +1,4 @@
/QTest is indirect
/QTest is indirect and has type stream (10)
/QTest is a stream. Dictionary: << /Filter (FlateDecode) /Length 123 >>
Raw stream data:
xœ%<25>11 û¼b;t<>à4| wXIDì Øå÷8G·«Í>rQ¨uŠ êEŒ:©IWìÃPlíµII)Ãr´p4~;§ÎAs/òÒ…jcúú¾÷Žs§åözû»ž<C2BB>T.?®uŽæ§<Ž¼…Ð*6ä

View File

@ -1,4 +1,4 @@
/QTest is indirect
/QTest is indirect and has type stream (10)
/QTest is a stream. Dictionary: << /Filter (FlateDecode) /Length 123 >>
Raw stream data:
xœ%<25>11 û¼b;t<>à4| wXIDì Øå÷8G·«Í>rQ¨uŠ êEŒ:©IWìÃPlíµII)Ãr´p4~;§ÎAs/òÒ…jcúú¾÷Žs§åözû»ž<C2BB>T.?®uŽæ§<Ž¼…Ð*6ä

View File

@ -1,4 +1,4 @@
/QTest is indirect
/QTest is indirect and has type stream (10)
/QTest is a stream. Dictionary: << /Filter [ /Oink /Moo /FlateDecode ] /Length 123 >>
Raw stream data:
xœ%<25>11 û¼b;t<>à4| wXIDì Øå÷8G·«Í>rQ¨uŠ êEŒ:©IWìÃPlíµII)Ãr´p4~;§ÎAs/òÒ…jcúú¾÷Žs§åözû»ž<C2BB>T.?®uŽæ§<Ž¼…Ð*6ä

View File

@ -1,4 +1,4 @@
/QTest is indirect
/QTest is indirect and has type stream (10)
/QTest is a stream. Dictionary: << /Filter [ /Oink /Moo /FlateDecode ] /Length 123 >>
Raw stream data:
xœ%<25>11 û¼b;t<>à4| wXIDì Øå÷8G·«Í>rQ¨uŠ êEŒ:©IWìÃPlíµII)Ãr´p4~;§ÎAs/òÒ…jcúú¾÷Žs§åözû»ž<C2BB>T.?®uŽæ§<Ž¼…Ð*6ä

View File

@ -3,7 +3,7 @@ WARNING: bad32.pdf (object 4 0, file position 307): expected 4 0 obj
WARNING: bad32.pdf: Attempting to reconstruct cross-reference table
WARNING: bad32.pdf: object 4 0 not found in file after regenerating cross reference table
/QTest is implicit
/QTest is indirect
/QTest is indirect and has type null (2)
/QTest is null
unparse: 4 0 R
unparseResolved: null

View File

@ -1,7 +1,7 @@
WARNING: bad33.pdf: file is damaged
WARNING: bad33.pdf (file position 1771): xref not found
WARNING: bad33.pdf: Attempting to reconstruct cross-reference table
/QTest is indirect
/QTest is indirect and has type stream (10)
/QTest is a stream. Dictionary: << /Filter (FlateDecode) /Length 123 >>
Raw stream data:
xœ%<25>11 û¼b;t<>à4| wXIDì Øå÷8G·«Í>rQ¨uŠ êEŒ:©IWìÃPlíµII)Ãr´p4~;§ÎAs/òÒ…jcúú¾÷Žs§åözû»ž<C2BB>T.?®uŽæ§<Ž¼…Ð*6ä

View File

@ -1,7 +1,7 @@
WARNING: bad34.pdf: file is damaged
WARNING: bad34.pdf (object 4 0, file position 322): expected n n obj
WARNING: bad34.pdf: Attempting to reconstruct cross-reference table
/QTest is indirect
/QTest is indirect and has type stream (10)
/QTest is a stream. Dictionary: << /Length 44 /Quack 9 0 R >>
Raw stream data:
BT

View File

@ -2,7 +2,7 @@ WARNING: bad4.pdf: file is damaged
WARNING: bad4.pdf (xref table, file position 547): xref syntax invalid
WARNING: bad4.pdf: Attempting to reconstruct cross-reference table
/QTest is implicit
/QTest is direct
/QTest is direct and has type null (2)
/QTest is null
unparse: null
unparseResolved: null

View File

@ -2,7 +2,7 @@ WARNING: bad5.pdf: file is damaged
WARNING: bad5.pdf (xref table, file position 591): invalid xref entry (obj=2)
WARNING: bad5.pdf: Attempting to reconstruct cross-reference table
/QTest is implicit
/QTest is direct
/QTest is direct and has type null (2)
/QTest is null
unparse: null
unparseResolved: null

View File

@ -1,5 +1,5 @@
/QTest is implicit
/QTest is direct
/QTest is direct and has type null (2)
/QTest is null
unparse: null
unparseResolved: null

View File

@ -1,5 +1,5 @@
/QTest is implicit
/QTest is direct
/QTest is direct and has type null (2)
/QTest is null
unparse: null
unparseResolved: null

View File

@ -2,7 +2,7 @@ WARNING: bad8.pdf: file is damaged
WARNING: bad8.pdf (file position 543): xref not found
WARNING: bad8.pdf: Attempting to reconstruct cross-reference table
/QTest is implicit
/QTest is direct
/QTest is direct and has type null (2)
/QTest is null
unparse: null
unparseResolved: null

View File

@ -2,7 +2,7 @@ WARNING: bad9.pdf: file is damaged
WARNING: bad9.pdf (trailer, file position 712): trailer dictionary lacks /Size key
WARNING: bad9.pdf: Attempting to reconstruct cross-reference table
/QTest is implicit
/QTest is direct
/QTest is direct and has type null (2)
/QTest is null
unparse: null
unparseResolved: null

View File

@ -1,5 +1,5 @@
/QTest is implicit
/QTest is direct
/QTest is direct and has type null (2)
/QTest is null
unparse: null
unparseResolved: null

View File

@ -1,4 +1,4 @@
/QTest is direct
/QTest is direct and has type array (8)
/QTest is an array with 3 items
item 0 is direct
item 1 is direct

View File

@ -1,4 +1,4 @@
/QTest is direct
/QTest is direct and has type dictionary (9)
/QTest is a dictionary
/a is direct
unparse: << /a (a) /b 8 0 R >>

View File

@ -1,4 +1,4 @@
/QTest is indirect
/QTest is indirect and has type stream (10)
/QTest is a stream. Dictionary: << /Filter /FlateDecode /Length 123 >>
Raw stream data:
xœ%<25>11 û¼b;t<>à4| wXIDì Øå÷8G·«Í>rQ¨uŠ êEŒ:©IWìÃPlíµII)Ãr´p4~;§ÎAs/òÒ…jcúú¾÷Žs§åözû»ž<C2BB>T.?®uŽæ§<Ž¼…Ð*6ä

View File

@ -1,4 +1,4 @@
/QTest is indirect
/QTest is indirect and has type dictionary (9)
/QTest is a dictionary
/hex strings is direct
/indirect is indirect

View File

@ -1,4 +1,4 @@
/QTest is direct
/QTest is direct and has type name (7)
/QTest is a name with value /oink
unparse: /oink
unparseResolved: /oink

View File

@ -1,5 +1,5 @@
/QTest is implicit
/QTest is direct
/QTest is direct and has type null (2)
/QTest is null
unparse: null
unparseResolved: null

View File

@ -1,5 +1,5 @@
/QTest is implicit
/QTest is direct
/QTest is direct and has type null (2)
/QTest is null
unparse: null
unparseResolved: null

View File

@ -1,5 +1,5 @@
/QTest is implicit
/QTest is direct
/QTest is direct and has type null (2)
/QTest is null
unparse: null
unparseResolved: null

View File

@ -1,5 +1,5 @@
/QTest is implicit
/QTest is direct
/QTest is direct and has type null (2)
/QTest is null
unparse: null
unparseResolved: null

View File

@ -1,5 +1,5 @@
/QTest is implicit
/QTest is direct
/QTest is direct and has type null (2)
/QTest is null
unparse: null
unparseResolved: null

View File

@ -1,5 +1,5 @@
/QTest is implicit
/QTest is direct
/QTest is direct and has type null (2)
/QTest is null
unparse: null
unparseResolved: null

View File

@ -1,5 +1,5 @@
/QTest is implicit
/QTest is indirect
/QTest is indirect and has type null (2)
/QTest is null
unparse: 7 0 R
unparseResolved: null

View File

@ -1,5 +1,5 @@
/QTest is implicit
/QTest is indirect
/QTest is indirect and has type null (2)
/QTest is null
unparse: 7 0 R
unparseResolved: null

View File

@ -1,4 +1,4 @@
/QTest is indirect
/QTest is indirect and has type boolean (3)
/QTest is Boolean with value true
unparse: 7 0 R
unparseResolved: true

View File

@ -1,4 +1,4 @@
/QTest is direct
/QTest is direct and has type boolean (3)
/QTest is Boolean with value false
unparse: false
unparseResolved: false

View File

@ -1,4 +1,4 @@
/QTest is direct
/QTest is direct and has type integer (4)
/QTest is an integer with value 16059
unparse: 16059
unparseResolved: 16059

View File

@ -1,4 +1,4 @@
/QTest is indirect
/QTest is indirect and has type real (5)
/QTest is a real number with value 3.14159
unparse: 7 0 R
unparseResolved: 3.14159

View File

@ -1,4 +1,4 @@
/QTest is direct
/QTest is direct and has type string (6)
/QTest is a string with value ¡Hola!
unparse: (¡Hola!)
unparseResolved: (¡Hola!)

View File

@ -232,7 +232,9 @@ void runtest(int n, char const* filename1, char const* arg2)
qtest.isIndirect() ? 1 : 0);
std::cout << "/QTest is "
<< (qtest.isIndirect() ? "in" : "")
<< "direct" << std::endl;
<< "direct and has type "
<< qtest.getTypeName()
<< " (" << qtest.getTypeCode() << ")" << std::endl;
if (qtest.isNull())
{