pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1832640 - /pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormTest.java
Date Thu, 31 May 2018 18:25:51 GMT
Author: tilman
Date: Thu May 31 18:25:51 2018
New Revision: 1832640

URL: http://svn.apache.org/viewvc?rev=1832640&view=rev
Log:
PDFBOX-4235: test to check that IllegalArgumentException is thrown and no NPE

Modified:
    pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormTest.java

Modified: pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormTest.java?rev=1832640&r1=1832639&r2=1832640&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormTest.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroFormTest.java
Thu May 31 18:25:51 2018
@@ -39,6 +39,7 @@ import org.apache.pdfbox.pdmodel.interac
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
 import org.apache.pdfbox.rendering.TestPDFToImage;
 import org.junit.After;
+import static org.junit.Assert.fail;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -243,7 +244,54 @@ public class PDAcroFormTest
             return;
         }
     }
-    
+
+    /**
+     * PDFBOX-4235: a bad /DA string should not result in an NPE.
+     * 
+     * @throws IOException 
+     */
+    @Test
+    public void testBadDA() throws IOException
+    {
+        PDDocument doc = new PDDocument();
+
+        PDPage page = new PDPage();
+        doc.addPage(page);
+
+        PDAcroForm acroForm = new PDAcroForm(document);
+        doc.getDocumentCatalog().setAcroForm(acroForm);
+        acroForm.setDefaultResources(new PDResources());
+
+        PDTextField textBox = new PDTextField(acroForm);
+        textBox.setPartialName("SampleField");
+
+        // https://stackoverflow.com/questions/50609478/
+        // "tf" is a typo, should have been "Tf" and this results that no font is chosen
+        textBox.setDefaultAppearance("/Helv 0 tf 0 g");
+        acroForm.getFields().add(textBox);
+
+        PDAnnotationWidget widget = textBox.getWidgets().get(0);
+        PDRectangle rect = new PDRectangle(50, 750, 200, 20);
+        widget.setRectangle(rect);
+        widget.setPage(page);
+
+        page.getAnnotations().add(widget);
+
+        try
+        {
+            textBox.setValue("huhu");
+        }
+        catch (IllegalArgumentException ex)
+        {
+            return;
+        }
+        finally
+        {
+            doc.close();
+        }
+        fail("IllegalArgumentException should have been thrown");
+    }
+
     @After
     public void tearDown() throws IOException
     {



Mime
View raw message