You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2020/08/24 17:07:54 UTC
svn commit: r1881150 - in /pdfbox/branches/2.0/pdfbox/src:
main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java
Author: tilman
Date: Mon Aug 24 17:07:53 2020
New Revision: 1881150
URL: http://svn.apache.org/viewvc?rev=1881150&view=rev
Log:
PDFBOX-4941: increment index when going through export values; expand test
Modified:
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java?rev=1881150&r1=1881149&r2=1881150&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java Mon Aug 24 17:07:53 2020
@@ -116,6 +116,7 @@ public final class PDRadioButton extends
{
selectedExportValues.add(exportValues.get(idx));
}
+ ++idx;
}
return selectedExportValues;
}
Modified: pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java?rev=1881150&r1=1881149&r2=1881150&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/TestRadioButtons.java Mon Aug 24 17:07:53 2020
@@ -25,8 +25,13 @@ import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.pdfbox.cos.COSArray;
+import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceEntry;
+import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceStream;
/**
* This will test the functionality of Radio Buttons in PDFBox.
@@ -92,6 +97,44 @@ public class TestRadioButtons extends Te
options.add("Value02");
radioButton.setExportValues(options);
+ // Test getSelectedExportValues()
+ List<PDAnnotationWidget> widgets = new ArrayList<PDAnnotationWidget>();
+ for (int i = 0; i < options.size(); i++)
+ {
+ PDAnnotationWidget widget = new PDAnnotationWidget();
+ COSDictionary apNDict = new COSDictionary();
+ apNDict.setItem(COSName.Off, new PDAppearanceStream(doc));
+ apNDict.setItem(options.get(i), new PDAppearanceStream(doc));
+
+ PDAppearanceDictionary appearance = new PDAppearanceDictionary();
+ PDAppearanceEntry appearanceNEntry = new PDAppearanceEntry(apNDict);
+ appearance.setNormalAppearance(appearanceNEntry);
+ widget.setAppearance(appearance);
+ widget.setAppearanceState("Off");
+ widgets.add(widget);
+ }
+ radioButton.setWidgets(widgets);
+
+ radioButton.setValue("Value01");
+ assertEquals("Value01", radioButton.getValue());
+ assertEquals(1, radioButton.getSelectedExportValues().size());
+ assertEquals("Value01", radioButton.getSelectedExportValues().get(0));
+ assertEquals("Value01", widgets.get(0).getAppearanceState().getName());
+ assertEquals("Off", widgets.get(1).getAppearanceState().getName());
+
+ radioButton.setValue("Value02");
+ assertEquals("Value02", radioButton.getValue());
+ assertEquals(1, radioButton.getSelectedExportValues().size());
+ assertEquals("Value02", radioButton.getSelectedExportValues().get(0));
+ assertEquals("Off", widgets.get(0).getAppearanceState().getName());
+ assertEquals("Value02", widgets.get(1).getAppearanceState().getName());
+
+ radioButton.setValue("Off");
+ assertEquals("Off", radioButton.getValue());
+ assertEquals(0, radioButton.getSelectedExportValues().size());
+ assertEquals("Off", widgets.get(0).getAppearanceState().getName());
+ assertEquals("Off", widgets.get(1).getAppearanceState().getName());
+
COSArray optItem = (COSArray) radioButton.getCOSObject().getItem(COSName.OPT);
// assert that the values have been correctly set