Author: tilman
Date: Sun Sep 13 07:48:12 2026
New Revision: 1938164
Log:
PDFBOX-6261: improve test to cover more attributes
Modified:
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureElementTest.java
Modified:
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureElementTest.java
==============================================================================
---
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureElementTest.java
Sun Sep 13 07:48:09 2026 (r1938163)
+++
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/documentinterchange/logicalstructure/PDStructureElementTest.java
Sun Sep 13 07:48:12 2026 (r1938164)
@@ -62,7 +62,7 @@ public class PDStructureElementTest
doc.close();
// collect attributes and check their count.
- assertEquals(117, attributeSet.size());
+ assertEquals(108, attributeSet.size());
int cnt = 0;
for (Revisions<PDAttributeObject> attributes : attributeSet)
{
@@ -111,20 +111,20 @@ public class PDStructureElementTest
}
// collect attributes and check their count.
- assertEquals(72, attributeSet.size());
+ assertEquals(50, attributeSet.size());
int cnt = 0;
for (Revisions<PDAttributeObject> attributes : attributeSet)
{
cnt += attributes.size();
}
- assertEquals(45, cnt);
- assertEquals(10, classSet.size());
+ assertEquals(54, cnt);
+ assertEquals(12, classSet.size());
}
// Each element can be an array, a dictionary or a number.
// See PDF specification Table 323 - Entries in a structure element
dictionary
private void checkElement(COSBase base,
Set<Revisions<PDAttributeObject>>attributeSet,
- Map<String, Object> classMap, Set<String> classSet)
+ Map<String, Object> classMap, Set<String>
classSet)
{
if (base instanceof COSArray)
{
@@ -140,31 +140,48 @@ public class PDStructureElementTest
else if (base instanceof COSDictionary)
{
COSDictionary kdict = (COSDictionary) base;
- if (kdict.containsKey(COSName.PG))
+ PDStructureElement structureElement = new
PDStructureElement(kdict);
+ Revisions<PDAttributeObject> attributes =
structureElement.getAttributes();
+ if (attributes.size() > 0)
{
- PDStructureElement structureElement = new
PDStructureElement(kdict);
- Revisions<PDAttributeObject> attributes =
structureElement.getAttributes();
attributeSet.add(attributes);
- Revisions<String> classNames =
structureElement.getClassNames();
-
- // "If both the A and C entries are present and a given
attribute is specified by both,
- // the one specified by the A entry shall take precedence."
- if (kdict.containsKey(COSName.C) &&
!kdict.containsKey(COSName.A))
+ PDAttributeObject obj0 = attributes.getObject(0);
+ if (obj0 instanceof PDTableAttributeObject) // Table 349
{
- for (int i = 0; i < classNames.size(); ++i)
+ if (obj0 instanceof PDTableAttributeObject)
{
- String className = classNames.getObject(i);
- classSet.add(className);
- assertTrue("'" + className + "' not in ClassMap " +
classMap, classMap.containsKey(className));
+ String[] headers = ((PDTableAttributeObject)
obj0).getHeaders();
+ if (headers != null)
+ {
+ for (String header : headers)
+ {
+ // not a real test, just so that we have
something with table headers
+ // after doing TIKA-4891 / PDFBOX-6261
+ assertTrue(header.startsWith("node0"));
+ }
+ }
}
}
}
+ Revisions<String> classNames = structureElement.getClassNames();
+
+ // "If both the A and C entries are present and a given attribute
is specified by both,
+ // the one specified by the A entry shall take precedence."
+ if (kdict.containsKey(COSName.C) && !kdict.containsKey(COSName.A))
+ {
+ for (int i = 0; i < classNames.size(); ++i)
+ {
+ String className = classNames.getObject(i);
+ classSet.add(className);
+ assertTrue("'" + className + "' not in ClassMap " +
classMap, classMap.containsKey(className));
+ }
+ }
if (kdict.containsKey(COSName.K))
{
checkElement(kdict.getDictionaryObject(COSName.K),
attributeSet, classMap, classSet);
}
}
- }
+ }
@Test
public void testSimple()