Skip to content

Commit

Permalink
PDFBOX-5894: add test
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1921708 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
THausherr committed Oct 31, 2024
1 parent a934b7d commit c3bb464
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions pdfbox/src/test/java/org/apache/pdfbox/pdmodel/TestFDF.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
package org.apache.pdfbox.pdmodel;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
Expand All @@ -26,9 +24,15 @@
import java.util.List;

import org.apache.pdfbox.Loader;
import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.cos.COSObject;
import org.apache.pdfbox.pdmodel.fdf.FDFDocument;
import org.apache.pdfbox.pdmodel.fdf.FDFField;
import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

/**
Expand All @@ -54,6 +58,26 @@ void testLoad2() throws URISyntaxException, IOException
checkFields("/org/apache/pdfbox/pdfparser/nocatalog.fdf");
}

/**
* PDFBOX-5894: check that premature file close bug is fixed.
*
* @throws IOException
*/
@Test
void testPDFBox5894() throws IOException
{
try (FDFDocument fdf = Loader.loadFDF(new File("target/pdfs/PDFBOX-5894.fdf")))
{
List<COSObject> objectsByType = fdf.getDocument().getObjectsByType(COSName.ANNOT);
assertEquals(4, objectsByType.size());
for (COSObject obj : objectsByType)
{
COSBase base = obj.getObject();
assertEquals(COSName.ANNOT, ((COSDictionary) base).getDictionaryObject(COSName.TYPE));
}
}
}

private void checkFields(String name) throws IOException, URISyntaxException
{
try (FDFDocument fdf = Loader.loadFDF(new File(TestFDF.class.getResource(name).toURI())))
Expand Down

0 comments on commit c3bb464

Please sign in to comment.