001: /**
002: * Copyright (c) 2005, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package test.pdfbox.pdmodel.interactive.form;
031:
032: import java.io.IOException;
033:
034: import junit.framework.Test;
035: import junit.framework.TestCase;
036: import junit.framework.TestSuite;
037:
038: import org.pdfbox.pdmodel.PDDocument;
039: import org.pdfbox.pdmodel.interactive.form.PDAcroForm;
040: import org.pdfbox.pdmodel.interactive.form.PDTextbox;
041:
042: /**
043: * This will test the form fields in PDFBox.
044: *
045: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
046: * @version $Revision: 1.4 $
047: */
048: public class TestFields extends TestCase {
049: //private static Logger log = Logger.getLogger(TestFDF.class);
050:
051: /**
052: * Constructor.
053: *
054: * @param name The name of the test to run.
055: */
056: public TestFields(String name) {
057: super (name);
058: }
059:
060: /**
061: * This will get the suite of test that this class holds.
062: *
063: * @return All of the tests that this class holds.
064: */
065: public static Test suite() {
066: return new TestSuite(TestFields.class);
067: }
068:
069: /**
070: * infamous main method.
071: *
072: * @param args The command line arguments.
073: */
074: public static void main(String[] args) {
075: String[] arg = { TestFields.class.getName() };
076: junit.textui.TestRunner.main(arg);
077: }
078:
079: /**
080: * This will test setting field flags on the PDField.
081: *
082: * @throws IOException If there is an error creating the field.
083: */
084: public void testFlags() throws IOException {
085: PDDocument doc = null;
086: try {
087: doc = new PDDocument();
088: PDAcroForm form = new PDAcroForm(doc);
089: PDTextbox textBox = new PDTextbox(form);
090:
091: //assert that default is false.
092: assertFalse(textBox.shouldComb());
093:
094: //try setting and clearing a single field
095: textBox.setComb(true);
096: assertTrue(textBox.shouldComb());
097: textBox.setComb(false);
098: assertFalse(textBox.shouldComb());
099:
100: //try setting and clearing multiple fields
101: textBox.setComb(true);
102: textBox.setDoNotScroll(true);
103: assertTrue(textBox.shouldComb());
104: assertTrue(textBox.doNotScroll());
105:
106: textBox.setComb(false);
107: textBox.setDoNotScroll(false);
108: assertFalse(textBox.shouldComb());
109: assertFalse(textBox.doNotScroll());
110:
111: //assert that setting a field to false multiple times works
112: textBox.setComb(false);
113: assertFalse(textBox.shouldComb());
114: textBox.setComb(false);
115: assertFalse(textBox.shouldComb());
116:
117: //assert that setting a field to true multiple times works
118: textBox.setComb(true);
119: assertTrue(textBox.shouldComb());
120: textBox.setComb(true);
121: assertTrue(textBox.shouldComb());
122:
123: } finally {
124: if (doc != null) {
125: doc.close();
126: }
127: }
128: }
129:
130: }
|