KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > pdfbox > pdmodel > interactive > form > TestFields


1 /**
2  * Copyright (c) 2005, www.pdfbox.org
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * 3. Neither the name of pdfbox; nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * http://www.pdfbox.org
29  *
30  */

31 package test.pdfbox.pdmodel.interactive.form;
32
33 import java.io.IOException JavaDoc;
34
35 import junit.framework.Test;
36 import junit.framework.TestCase;
37 import junit.framework.TestSuite;
38
39 import org.pdfbox.pdmodel.PDDocument;
40 import org.pdfbox.pdmodel.interactive.form.PDAcroForm;
41 import org.pdfbox.pdmodel.interactive.form.PDTextbox;
42
43 /**
44  * This will test the form fields in PDFBox.
45  *
46  * @author <a HREF="mailto:ben@benlitchfield.com">Ben Litchfield</a>
47  * @version $Revision: 1.4 $
48  */

49 public class TestFields extends TestCase
50 {
51     //private static Logger log = Logger.getLogger(TestFDF.class);
52

53     /**
54      * Constructor.
55      *
56      * @param name The name of the test to run.
57      */

58     public TestFields( String JavaDoc name )
59     {
60         super( name );
61     }
62
63     /**
64      * This will get the suite of test that this class holds.
65      *
66      * @return All of the tests that this class holds.
67      */

68     public static Test suite()
69     {
70         return new TestSuite( TestFields.class );
71     }
72
73     /**
74      * infamous main method.
75      *
76      * @param args The command line arguments.
77      */

78     public static void main( String JavaDoc[] args )
79     {
80         String JavaDoc[] arg = {TestFields.class.getName() };
81         junit.textui.TestRunner.main( arg );
82     }
83
84     /**
85      * This will test setting field flags on the PDField.
86      *
87      * @throws IOException If there is an error creating the field.
88      */

89     public void testFlags() throws IOException JavaDoc
90     {
91         PDDocument doc = null;
92         try
93         {
94             doc = new PDDocument();
95             PDAcroForm form = new PDAcroForm( doc );
96             PDTextbox textBox = new PDTextbox(form);
97             
98             //assert that default is false.
99
assertFalse( textBox.shouldComb() );
100             
101             //try setting and clearing a single field
102
textBox.setComb( true );
103             assertTrue( textBox.shouldComb() );
104             textBox.setComb( false );
105             assertFalse( textBox.shouldComb() );
106             
107             //try setting and clearing multiple fields
108
textBox.setComb( true );
109             textBox.setDoNotScroll( true );
110             assertTrue( textBox.shouldComb() );
111             assertTrue( textBox.doNotScroll() );
112             
113             textBox.setComb( false );
114             textBox.setDoNotScroll( false );
115             assertFalse( textBox.shouldComb() );
116             assertFalse( textBox.doNotScroll() );
117             
118             //assert that setting a field to false multiple times works
119
textBox.setComb( false );
120             assertFalse( textBox.shouldComb() );
121             textBox.setComb( false );
122             assertFalse( textBox.shouldComb() );
123             
124             //assert that setting a field to true multiple times works
125
textBox.setComb( true );
126             assertTrue( textBox.shouldComb() );
127             textBox.setComb( true );
128             assertTrue( textBox.shouldComb() );
129             
130             
131             
132             
133             
134         }
135         finally
136         {
137             if( doc != null )
138             {
139                 doc.close();
140             }
141         }
142     }
143     
144 }
Popular Tags