You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ms...@apache.org on 2014/11/23 20:17:48 UTC

svn commit: r1641245 - /pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java

Author: msahyoun
Date: Sun Nov 23 19:17:48 2014
New Revision: 1641245

URL: http://svn.apache.org/r1641245
Log:
PDFBOX-2516 enhance unit test to assert for default value DV

Modified:
    pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java

Modified: pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java?rev=1641245&r1=1641244&r2=1641245&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java (original)
+++ pdfbox/trunk/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestFields.java Sun Nov 23 19:17:48 2014
@@ -16,12 +16,14 @@
  */
 package org.apache.pdfbox.pdmodel.interactive.form;
 
+import java.io.File;
 import java.io.IOException;
 
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 
+import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.PDDocument;
 
 /**
@@ -34,6 +36,9 @@ public class TestFields extends TestCase
 {
     //private static Logger log = Logger.getLogger(TestFDF.class);
 
+    private static final String PATH_OF_PDF = "src/test/resources/org/apache/pdfbox/pdmodel/interactive/form/AcroFormsBasicFields.pdf";
+
+    
     /**
      * Constructor.
      *
@@ -110,11 +115,6 @@ public class TestFields extends TestCase
             assertTrue( textBox.isComb() );
             textBox.setComb( true );
             assertTrue( textBox.isComb() );
-
-
-
-
-
         }
         finally
         {
@@ -124,5 +124,44 @@ public class TestFields extends TestCase
             }
         }
     }
-
-}
+    
+    /**
+     * This will test some form fields functionality based with 
+     * a sample form.
+     *
+     * @throws IOException If there is an error creating the field.
+     */
+    public void testAcroFormsBasicFields() throws IOException
+    {
+        PDDocument doc = null;
+        
+        try
+        {
+            doc = PDDocument.load(new File(PATH_OF_PDF));
+            
+            // get and assert that there is a form
+            PDAcroForm form = doc.getDocumentCatalog().getAcroForm();
+            assertNotNull(form);
+            
+            // get the RadioButton with a DV entry
+            PDFieldTreeNode field = form.getField("RadioButtonGroup-DefaultValue");
+            assertNotNull(field);
+            assertEquals(field.getDefaultValue(),COSName.getPDFName("RadioButton01"));
+            assertEquals(field.getDefaultValue(),field.getDictionary().getDictionaryObject(COSName.DV));
+
+            // get the Checkbox with a DV entry
+            field = form.getField("Checkbox-DefaultValue");
+            assertNotNull(field);
+            assertEquals(field.getDefaultValue(),COSName.getPDFName("Yes"));
+            assertEquals(field.getDefaultValue(),field.getDictionary().getDictionaryObject(COSName.DV));
+            
+        }
+        finally
+        {
+            if( doc != null )
+            {
+                doc.close();
+            }
+        }
+    }
+}
\ No newline at end of file