Skip to content

Commit 9842aa3

Browse files
Move tests for flattening of rotated fields to a separate class
DEVSIX-1741
1 parent 59efd39 commit 9842aa3

File tree

34 files changed

+100
-104
lines changed

34 files changed

+100
-104
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2018 iText Group NV
4+
Authors: iText Software.
5+
6+
This program is free software; you can redistribute it and/or modify
7+
it under the terms of the GNU Affero General Public License version 3
8+
as published by the Free Software Foundation with the addition of the
9+
following permission added to Section 15 as permitted in Section 7(a):
10+
FOR ANY PART OF THE COVERED WORK IN WHICH THE COPYRIGHT IS OWNED BY
11+
ITEXT GROUP. ITEXT GROUP DISCLAIMS THE WARRANTY OF NON INFRINGEMENT
12+
OF THIRD PARTY RIGHTS
13+
14+
This program is distributed in the hope that it will be useful, but
15+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16+
or FITNESS FOR A PARTICULAR PURPOSE.
17+
See the GNU Affero General Public License for more details.
18+
You should have received a copy of the GNU Affero General Public License
19+
along with this program; if not, see http://www.gnu.org/licenses or write to
20+
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21+
Boston, MA, 02110-1301 USA, or download the license from the following URL:
22+
http://itextpdf.com/terms-of-use/
23+
24+
The interactive user interfaces in modified source and object code versions
25+
of this program must display Appropriate Legal Notices, as required under
26+
Section 5 of the GNU Affero General Public License.
27+
28+
In accordance with Section 7(b) of the GNU Affero General Public License,
29+
a covered work must retain the producer line in every PDF that is created
30+
or manipulated using iText.
31+
32+
You can be released from the requirements of the license by purchasing
33+
a commercial license. Buying such a license is mandatory as soon as you
34+
develop commercial activities involving the iText software without
35+
disclosing the source code of your own applications.
36+
These activities include: offering paid services to customers as an ASP,
37+
serving PDFs on the fly in a web application, shipping iText with a closed
38+
source product.
39+
40+
For more information, please contact iText Software Corp. at this
41+
42+
*/
43+
package com.itextpdf.forms;
44+
45+
import com.itextpdf.forms.fields.PdfFormField;
46+
import com.itextpdf.io.util.MessageFormatUtil;
47+
import com.itextpdf.kernel.pdf.PdfDocument;
48+
import com.itextpdf.kernel.pdf.PdfReader;
49+
import com.itextpdf.kernel.pdf.PdfWriter;
50+
import com.itextpdf.kernel.utils.CompareTool;
51+
import com.itextpdf.test.ExtendedITextTest;
52+
import com.itextpdf.test.annotations.type.IntegrationTest;
53+
import java.io.IOException;
54+
import org.junit.Assert;
55+
import org.junit.BeforeClass;
56+
import org.junit.Test;
57+
import org.junit.experimental.categories.Category;
58+
59+
@Category(IntegrationTest.class)
60+
public class FlatteningRotatedTest extends ExtendedITextTest {
61+
62+
public static final String sourceFolder = "./src/test/resources/com/itextpdf/forms/FlatteningRotatedTest/";
63+
public static final String destinationFolder = "./target/test/com/itextpdf/forms/FlatteningRotatedTest/";
64+
65+
@BeforeClass
66+
public static void beforeClass() {
67+
createOrClearDestinationFolder(destinationFolder);
68+
}
69+
70+
@Test
71+
public void formFlatteningTest_DefaultAppearanceGeneration_Rot() throws IOException, InterruptedException {
72+
String srcFilePatternPattern = "FormFlatteningDefaultAppearance_{0}_";
73+
String destPatternPattern = "FormFlatteningDefaultAppearance_{0}_";
74+
75+
String[] rotAngle = new String[] {"0", "90", "180", "270"};
76+
77+
for (String angle : rotAngle) {
78+
String srcFilePattern = MessageFormatUtil.format(srcFilePatternPattern, angle);
79+
String destPattern = MessageFormatUtil.format(destPatternPattern, angle);
80+
for (int i = 0; i < 360; i += 90) {
81+
String src = sourceFolder + srcFilePattern + i + ".pdf";
82+
String dest = destinationFolder + destPattern + i + "_flattened.pdf";
83+
String cmp = sourceFolder + "cmp_" + srcFilePattern + i + ".pdf";
84+
PdfDocument doc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
85+
86+
PdfAcroForm form = PdfAcroForm.getAcroForm(doc, true);
87+
for (PdfFormField field : form.getFormFields().values()) {
88+
field.setValue("Test");
89+
}
90+
form.flattenFields();
91+
92+
doc.close();
93+
94+
Assert.assertNull(new CompareTool().compareByContent(dest, cmp, destinationFolder, "diff_"));
95+
}
96+
}
97+
}
98+
}

forms/src/test/java/com/itextpdf/forms/FormFieldFlatteningTest.java

Lines changed: 2 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,23 @@ This file is part of the iText (R) project.
4242
*/
4343
package com.itextpdf.forms;
4444

45-
import com.itextpdf.forms.fields.PdfFormField;
46-
import com.itextpdf.kernel.geom.Rectangle;
47-
import com.itextpdf.kernel.pdf.PdfArray;
4845
import com.itextpdf.kernel.pdf.PdfDocument;
4946
import com.itextpdf.kernel.pdf.PdfReader;
50-
import com.itextpdf.kernel.pdf.PdfString;
5147
import com.itextpdf.kernel.pdf.PdfWriter;
5248
import com.itextpdf.kernel.utils.CompareTool;
5349
import com.itextpdf.test.ExtendedITextTest;
5450
import com.itextpdf.test.annotations.type.IntegrationTest;
51+
import java.io.IOException;
5552
import org.junit.Assert;
5653
import org.junit.BeforeClass;
5754
import org.junit.Test;
5855
import org.junit.experimental.categories.Category;
5956

60-
import java.io.FileNotFoundException;
61-
import java.io.IOException;
62-
import java.util.Arrays;
63-
6457
@Category(IntegrationTest.class)
6558
public class FormFieldFlatteningTest extends ExtendedITextTest {
6659

67-
public static final String sourceFolder = "./src/test/resources/com/itextpdf/forms/FormFieldFlatteningTest/";
6860
public static final String destinationFolder = "./target/test/com/itextpdf/forms/FormFieldFlatteningTest/";
61+
public static final String sourceFolder = "./src/test/resources/com/itextpdf/forms/FormFieldFlatteningTest/";
6962

7063
@BeforeClass
7164
public static void beforeClass() {
@@ -106,101 +99,6 @@ public void formFlatteningChoiceFieldTest01() throws IOException, InterruptedExc
10699
}
107100
}
108101

109-
@Test
110-
public void formFlatteningTest_DefaultAppearanceGeneration_Rot0() throws IOException, InterruptedException {
111-
String srcFilePattern = "FormFlatteningDefaultAppearance_0_";
112-
String destPattern = "FormFlatteningDefaultAppearance_0_";
113-
114-
for (int i = 0; i < 360; i += 90) {
115-
String src = sourceFolder + srcFilePattern + i + ".pdf";
116-
String dest = destinationFolder + destPattern + i + "_flattened.pdf";
117-
String cmp = sourceFolder + "cmp_" + srcFilePattern + i + ".pdf";
118-
PdfDocument doc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
119-
120-
PdfAcroForm form = PdfAcroForm.getAcroForm(doc, true);
121-
for (PdfFormField field : form.getFormFields().values()) {
122-
field.setValue("Test");
123-
}
124-
form.flattenFields();
125-
126-
doc.close();
127-
128-
Assert.assertNull(new CompareTool().compareByContent(dest, cmp, destinationFolder, "diff_"));
129-
}
130-
131-
}
132-
133-
@Test
134-
public void formFlatteningTest_DefaultAppearanceGeneration_Rot90() throws IOException, InterruptedException {
135-
String srcFilePattern = "FormFlatteningDefaultAppearance_90_";
136-
String destPattern = "FormFlatteningDefaultAppearance_90_";
137-
138-
for (int i = 0; i < 360; i += 90) {
139-
String src = sourceFolder + srcFilePattern + i + ".pdf";
140-
String dest = destinationFolder + destPattern + i + "_flattened.pdf";
141-
String cmp = sourceFolder + "cmp_" + srcFilePattern + i + ".pdf";
142-
PdfDocument doc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
143-
144-
PdfAcroForm form = PdfAcroForm.getAcroForm(doc, true);
145-
for (PdfFormField field : form.getFormFields().values()) {
146-
field.setValue("Test");
147-
}
148-
form.flattenFields();
149-
150-
doc.close();
151-
152-
Assert.assertNull(new CompareTool().compareByContent(dest, cmp, destinationFolder, "diff_"));
153-
}
154-
155-
}
156-
157-
@Test
158-
public void formFlatteningTest_DefaultAppearanceGeneration_Rot180() throws IOException, InterruptedException {
159-
String srcFilePattern = "FormFlatteningDefaultAppearance_180_";
160-
String destPattern = "FormFlatteningDefaultAppearance_180_";
161-
162-
for (int i = 0; i < 360; i += 90) {
163-
String src = sourceFolder + srcFilePattern + i + ".pdf";
164-
String dest = destinationFolder + destPattern + i + "_flattened.pdf";
165-
String cmp = sourceFolder + "cmp_" + srcFilePattern + i + ".pdf";
166-
PdfDocument doc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
167-
168-
PdfAcroForm form = PdfAcroForm.getAcroForm(doc, true);
169-
for (PdfFormField field : form.getFormFields().values()) {
170-
field.setValue("Test");
171-
}
172-
form.flattenFields();
173-
174-
doc.close();
175-
176-
Assert.assertNull(new CompareTool().compareByContent(dest, cmp, destinationFolder, "diff_"));
177-
}
178-
179-
}
180-
181-
@Test
182-
public void formFlatteningTest_DefaultAppearanceGeneration_Rot270() throws IOException, InterruptedException {
183-
String srcFilePattern = "FormFlatteningDefaultAppearance_270_";
184-
String destPattern = "FormFlatteningDefaultAppearance_270_";
185-
186-
for (int i = 0; i < 360; i += 90) {
187-
String src = sourceFolder + srcFilePattern + i + ".pdf";
188-
String dest = destinationFolder + destPattern + i + "_flattened.pdf";
189-
String cmp = sourceFolder + "cmp_" + srcFilePattern + i + ".pdf";
190-
PdfDocument doc = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
191-
192-
PdfAcroForm form = PdfAcroForm.getAcroForm(doc, true);
193-
for (PdfFormField field : form.getFormFields().values()) {
194-
field.setValue("Test");
195-
}
196-
form.flattenFields();
197-
198-
doc.close();
199-
200-
Assert.assertNull(new CompareTool().compareByContent(dest, cmp, destinationFolder, "diff_"));
201-
}
202-
}
203-
204102
@Test
205103
public void multiLineFormFieldClippingTest() throws IOException, InterruptedException {
206104

0 commit comments

Comments
 (0)