Skip to content

Commit d15bd79

Browse files
SnipxiText-CI
authored andcommitted
Move most of CssStyleSheetParserTest from pdfHTML to SXP
1 parent 29b1d0d commit d15bd79

File tree

21 files changed

+434
-0
lines changed

21 files changed

+434
-0
lines changed
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2019 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.styledxmlparser.css.parse;
44+
45+
import com.itextpdf.io.util.StreamUtil;
46+
import com.itextpdf.styledxmlparser.css.CssStyleSheet;
47+
import com.itextpdf.test.ExtendedITextTest;
48+
import com.itextpdf.test.annotations.type.UnitTest;
49+
import org.junit.Assert;
50+
import org.junit.Test;
51+
import org.junit.experimental.categories.Category;
52+
53+
import java.io.FileInputStream;
54+
import java.io.IOException;
55+
56+
@Category(UnitTest.class)
57+
public class CssStyleSheetParserTest extends ExtendedITextTest {
58+
59+
private static final String sourceFolder = "./src/test/resources/com/itextpdf/styledxmlparser/css/parse/CssStyleSheetParserTest/";
60+
61+
@Test
62+
public void test01() throws IOException {
63+
String cssFile = sourceFolder + "css01.css";
64+
CssStyleSheet styleSheet = CssStyleSheetParser.parse(new FileInputStream(cssFile));
65+
Assert.assertEquals(getCssFileContents(cssFile), styleSheet.toString());
66+
}
67+
68+
@Test
69+
public void test02() throws IOException {
70+
String cssFile = sourceFolder + "css02.css";
71+
String cmpFile = sourceFolder + "cmp_css02.css";
72+
CssStyleSheet styleSheet = CssStyleSheetParser.parse(new FileInputStream(cssFile));
73+
Assert.assertEquals(getCssFileContents(cmpFile), styleSheet.toString());
74+
}
75+
76+
@Test
77+
public void test03() throws IOException {
78+
String cssFile = sourceFolder + "css03.css";
79+
String cmpFile = sourceFolder + "cmp_css03.css";
80+
CssStyleSheet styleSheet = CssStyleSheetParser.parse(new FileInputStream(cssFile));
81+
Assert.assertEquals(getCssFileContents(cmpFile), styleSheet.toString());
82+
}
83+
84+
@Test
85+
public void test04() throws IOException {
86+
String cssFile = sourceFolder + "css04.css";
87+
CssStyleSheet styleSheet = CssStyleSheetParser.parse(new FileInputStream(cssFile));
88+
Assert.assertEquals("", styleSheet.toString());
89+
}
90+
91+
@Test
92+
public void test05() throws IOException {
93+
String cssFile = sourceFolder + "css05.css";
94+
String cmpFile = sourceFolder + "cmp_css05.css";
95+
CssStyleSheet styleSheet = CssStyleSheetParser.parse(new FileInputStream(cssFile));
96+
Assert.assertEquals(getCssFileContents(cmpFile), styleSheet.toString());
97+
}
98+
99+
@Test
100+
public void test06() throws IOException {
101+
String cssFile = sourceFolder + "css06.css";
102+
String cmpFile = sourceFolder + "cmp_css06.css";
103+
CssStyleSheet styleSheet = CssStyleSheetParser.parse(new FileInputStream(cssFile));
104+
Assert.assertEquals(getCssFileContents(cmpFile), styleSheet.toString());
105+
}
106+
107+
@Test
108+
public void test07() throws IOException {
109+
String cssFile = sourceFolder + "css07.css";
110+
CssStyleSheet styleSheet = CssStyleSheetParser.parse(new FileInputStream(cssFile));
111+
Assert.assertEquals(getCssFileContents(cssFile), styleSheet.toString());
112+
}
113+
114+
@Test
115+
public void test08() throws IOException {
116+
String cssFile = sourceFolder + "css08.css";
117+
String cmpFile = sourceFolder + "cmp_css08.css";
118+
CssStyleSheet styleSheet = CssStyleSheetParser.parse(new FileInputStream(cssFile));
119+
Assert.assertEquals(getCssFileContents(cmpFile), styleSheet.toString());
120+
}
121+
122+
@Test
123+
public void test09() throws IOException {
124+
String cssFile = sourceFolder + "css09.css";
125+
CssStyleSheet styleSheet = CssStyleSheetParser.parse(new FileInputStream(cssFile));
126+
Assert.assertEquals(getCssFileContents(cssFile), styleSheet.toString());
127+
}
128+
129+
@Test
130+
public void test10() throws IOException {
131+
String cssFile = sourceFolder + "css10.css";
132+
String cmpFile = sourceFolder + "cmp_css10.css";
133+
CssStyleSheet styleSheet = CssStyleSheetParser.parse(new FileInputStream(cssFile));
134+
Assert.assertEquals(getCssFileContents(cmpFile), styleSheet.toString());
135+
}
136+
137+
@Test
138+
public void test11() throws IOException {
139+
// TODO in this test declarations of the page at-rule with compound selector are duplicated.
140+
// See CssPageRule#addBodyCssDeclarations() method for the reason and possible solution if this becomes important.
141+
142+
String cssFile = sourceFolder + "css11.css";
143+
String cmpFile = sourceFolder + "cmp_css11.css";
144+
CssStyleSheet styleSheet = CssStyleSheetParser.parse(new FileInputStream(cssFile));
145+
Assert.assertEquals(getCssFileContents(cmpFile), styleSheet.toString());
146+
}
147+
148+
@Test
149+
public void test12() throws IOException {
150+
String cssFile = sourceFolder + "css12.css";
151+
String cmpFile = sourceFolder + "cmp_css12.css";
152+
CssStyleSheet styleSheet = CssStyleSheetParser.parse(new FileInputStream(cssFile));
153+
Assert.assertEquals(getCssFileContents(cmpFile), styleSheet.toString());
154+
}
155+
156+
private String getCssFileContents(String filePath) throws IOException {
157+
byte[] bytes = StreamUtil.inputStreamToArray(new FileInputStream(filePath));
158+
String content = new String(bytes);
159+
content = content.trim();
160+
content = content.replace("\r\n", "\n");
161+
return content;
162+
}
163+
164+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
div {
2+
font-size: 2em
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
p {
2+
color: green;
3+
font-size: 10pt
4+
}
5+
@media screen {
6+
p {
7+
color: red
8+
}
9+
}
10+
.blue {
11+
color: blue
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@media print {
2+
#navigation {
3+
display: none
4+
}
5+
@media (max-width: 12cm) {
6+
.note {
7+
float: none
8+
}
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
div {
2+
font-size: 10pt;
3+
color: red
4+
}
5+
p {
6+
font-size: 10pt;
7+
color: red
8+
}
9+
#navbar {
10+
font-size: 10pt;
11+
color: red
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
a[rel="nofollow"] {
2+
3+
}
4+
a[rel="nofollow"] {
5+
6+
}
7+
a[rel="nofollow"] {
8+
9+
}
10+
object[type^="image/"] {
11+
12+
}
13+
a[href$=".html"] {
14+
15+
}
16+
p[title*="hello"] {
17+
18+
}
19+
e[foo~="bar"] {
20+
21+
}
22+
e[foo|="en"] {
23+
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
blockquote {
2+
margin: 1em 40px
3+
}
4+
blockquote {
5+
padding: 1em 40px
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
@page {
2+
size: a4
3+
}
4+
@page :first {
5+
size: landscape;
6+
margin: 3in
7+
}
8+
@page {
9+
size: a5;
10+
border: solid 1px
11+
}
12+
@page :left {
13+
margin: 1in
14+
}
15+
@page asdjf, auTo, customPageName:right:right,:left {
16+
@left-bottom {
17+
color: red;
18+
content: "Left content."
19+
color: red;
20+
content: "Left content."
21+
color: red;
22+
content: "Left content."
23+
color: red;
24+
content: "Left content."
25+
}
26+
size: a5 landscape;
27+
margin: 0.5in 1in 0.5in 0.5in
28+
size: a5 landscape;
29+
margin: 0.5in 1in 0.5in 0.5in
30+
size: a5 landscape;
31+
margin: 0.5in 1in 0.5in 0.5in
32+
size: a5 landscape;
33+
margin: 0.5in 1in 0.5in 0.5in
34+
}
35+
@page :left:left:first {
36+
margin-left: 1in
37+
}
38+
@media print {
39+
@page :right:right {
40+
@top-left {
41+
content: "Some header text " counter(chapter)
42+
}
43+
margin-left: 1in
44+
}
45+
}
46+
@page :right {
47+
margin: 0.5in
48+
}
49+
@page :right {
50+
background-color: #ccc
51+
}
52+
@page :left {
53+
background-color: #ccf
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@font-face {
2+
font-family: "Font";
3+
src: url(http://some-font.eot) format("embedded-opentype"),url(data:application/font-woff;base64,2CBPCRXmgywtV1t4oWwjBju0kqkvfhPs0cYdMgFtDSY5uL7MIGT5wiGs078HrvBHekp0Yf=) format("truetype");
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
div {
2+
font-size: 2em
3+
}
4+

0 commit comments

Comments
 (0)