Skip to content

Commit 2720f42

Browse files
SnipxiText-CI
authored andcommitted
Move most of CssStyleSheetParserTest from pdfHTML to SXP
Autoported commit. Original commit hash: [d15bd79f5]
1 parent 4877a83 commit 2720f42

File tree

22 files changed

+439
-1
lines changed

22 files changed

+439
-1
lines changed
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
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+
using System;
44+
using System.IO;
45+
using iText.IO.Util;
46+
using iText.StyledXmlParser.Css;
47+
using iText.Test;
48+
49+
namespace iText.StyledXmlParser.Css.Parse {
50+
public class CssStyleSheetParserTest : ExtendedITextTest {
51+
private static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
52+
.CurrentContext.TestDirectory) + "/resources/itext/styledxmlparser/css/parse/CssStyleSheetParserTest/";
53+
54+
[NUnit.Framework.Test]
55+
public virtual void Test01() {
56+
String cssFile = sourceFolder + "css01.css";
57+
CssStyleSheet styleSheet = CssStyleSheetParser.Parse(new FileStream(cssFile, FileMode.Open, FileAccess.Read
58+
));
59+
NUnit.Framework.Assert.AreEqual(GetCssFileContents(cssFile), styleSheet.ToString());
60+
}
61+
62+
[NUnit.Framework.Test]
63+
public virtual void Test02() {
64+
String cssFile = sourceFolder + "css02.css";
65+
String cmpFile = sourceFolder + "cmp_css02.css";
66+
CssStyleSheet styleSheet = CssStyleSheetParser.Parse(new FileStream(cssFile, FileMode.Open, FileAccess.Read
67+
));
68+
NUnit.Framework.Assert.AreEqual(GetCssFileContents(cmpFile), styleSheet.ToString());
69+
}
70+
71+
[NUnit.Framework.Test]
72+
public virtual void Test03() {
73+
String cssFile = sourceFolder + "css03.css";
74+
String cmpFile = sourceFolder + "cmp_css03.css";
75+
CssStyleSheet styleSheet = CssStyleSheetParser.Parse(new FileStream(cssFile, FileMode.Open, FileAccess.Read
76+
));
77+
NUnit.Framework.Assert.AreEqual(GetCssFileContents(cmpFile), styleSheet.ToString());
78+
}
79+
80+
[NUnit.Framework.Test]
81+
public virtual void Test04() {
82+
String cssFile = sourceFolder + "css04.css";
83+
CssStyleSheet styleSheet = CssStyleSheetParser.Parse(new FileStream(cssFile, FileMode.Open, FileAccess.Read
84+
));
85+
NUnit.Framework.Assert.AreEqual("", styleSheet.ToString());
86+
}
87+
88+
[NUnit.Framework.Test]
89+
public virtual void Test05() {
90+
String cssFile = sourceFolder + "css05.css";
91+
String cmpFile = sourceFolder + "cmp_css05.css";
92+
CssStyleSheet styleSheet = CssStyleSheetParser.Parse(new FileStream(cssFile, FileMode.Open, FileAccess.Read
93+
));
94+
NUnit.Framework.Assert.AreEqual(GetCssFileContents(cmpFile), styleSheet.ToString());
95+
}
96+
97+
[NUnit.Framework.Test]
98+
public virtual void Test06() {
99+
String cssFile = sourceFolder + "css06.css";
100+
String cmpFile = sourceFolder + "cmp_css06.css";
101+
CssStyleSheet styleSheet = CssStyleSheetParser.Parse(new FileStream(cssFile, FileMode.Open, FileAccess.Read
102+
));
103+
NUnit.Framework.Assert.AreEqual(GetCssFileContents(cmpFile), styleSheet.ToString());
104+
}
105+
106+
[NUnit.Framework.Test]
107+
public virtual void Test07() {
108+
String cssFile = sourceFolder + "css07.css";
109+
CssStyleSheet styleSheet = CssStyleSheetParser.Parse(new FileStream(cssFile, FileMode.Open, FileAccess.Read
110+
));
111+
NUnit.Framework.Assert.AreEqual(GetCssFileContents(cssFile), styleSheet.ToString());
112+
}
113+
114+
[NUnit.Framework.Test]
115+
public virtual void Test08() {
116+
String cssFile = sourceFolder + "css08.css";
117+
String cmpFile = sourceFolder + "cmp_css08.css";
118+
CssStyleSheet styleSheet = CssStyleSheetParser.Parse(new FileStream(cssFile, FileMode.Open, FileAccess.Read
119+
));
120+
NUnit.Framework.Assert.AreEqual(GetCssFileContents(cmpFile), styleSheet.ToString());
121+
}
122+
123+
[NUnit.Framework.Test]
124+
public virtual void Test09() {
125+
String cssFile = sourceFolder + "css09.css";
126+
CssStyleSheet styleSheet = CssStyleSheetParser.Parse(new FileStream(cssFile, FileMode.Open, FileAccess.Read
127+
));
128+
NUnit.Framework.Assert.AreEqual(GetCssFileContents(cssFile), styleSheet.ToString());
129+
}
130+
131+
[NUnit.Framework.Test]
132+
public virtual void Test10() {
133+
String cssFile = sourceFolder + "css10.css";
134+
String cmpFile = sourceFolder + "cmp_css10.css";
135+
CssStyleSheet styleSheet = CssStyleSheetParser.Parse(new FileStream(cssFile, FileMode.Open, FileAccess.Read
136+
));
137+
NUnit.Framework.Assert.AreEqual(GetCssFileContents(cmpFile), styleSheet.ToString());
138+
}
139+
140+
[NUnit.Framework.Test]
141+
public virtual void Test11() {
142+
// TODO in this test declarations of the page at-rule with compound selector are duplicated.
143+
// See CssPageRule#addBodyCssDeclarations() method for the reason and possible solution if this becomes important.
144+
String cssFile = sourceFolder + "css11.css";
145+
String cmpFile = sourceFolder + "cmp_css11.css";
146+
CssStyleSheet styleSheet = CssStyleSheetParser.Parse(new FileStream(cssFile, FileMode.Open, FileAccess.Read
147+
));
148+
NUnit.Framework.Assert.AreEqual(GetCssFileContents(cmpFile), styleSheet.ToString());
149+
}
150+
151+
[NUnit.Framework.Test]
152+
public virtual void Test12() {
153+
String cssFile = sourceFolder + "css12.css";
154+
String cmpFile = sourceFolder + "cmp_css12.css";
155+
CssStyleSheet styleSheet = CssStyleSheetParser.Parse(new FileStream(cssFile, FileMode.Open, FileAccess.Read
156+
));
157+
NUnit.Framework.Assert.AreEqual(GetCssFileContents(cmpFile), styleSheet.ToString());
158+
}
159+
160+
private String GetCssFileContents(String filePath) {
161+
byte[] bytes = StreamUtil.InputStreamToArray(new FileStream(filePath, FileMode.Open, FileAccess.Read));
162+
String content = iText.IO.Util.JavaUtil.GetStringForBytes(bytes);
163+
content = content.Trim();
164+
content = content.Replace("\r\n", "\n");
165+
return content;
166+
}
167+
}
168+
}
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)