Skip to content

Commit 496e158

Browse files
Kate IvanovaiText-CI
authored andcommitted
Add log messages handler in svg
DEVSIX-2904 Autoported commit. Original commit hash: [b9a54aa97]
1 parent bef08aa commit 496e158

File tree

26 files changed

+112
-67
lines changed

26 files changed

+112
-67
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using System;
2+
using System.IO;
3+
using iText.StyledXmlParser.Node;
4+
using iText.StyledXmlParser.Node.Impl.Jsoup;
5+
6+
namespace iText.StyledXmlParser.Jsoup {
7+
public class JsoupXmlParserTest {
8+
/// <exception cref="System.IO.IOException"/>
9+
[NUnit.Framework.Test]
10+
public virtual void TestXmlDeclarationAndComment() {
11+
String xml = "<?xml version=\"1.0\" standalone=\"no\"?>\n" + "<!-- just declaration and comment -->";
12+
Stream stream = new MemoryStream(xml.GetBytes());
13+
IDocumentNode node = new JsoupXmlParser().Parse(stream, "UTF-8");
14+
// only text (whitespace) child node shall be fetched.
15+
NUnit.Framework.Assert.AreEqual(1, node.ChildNodes().Count);
16+
}
17+
}
18+
}

itext.tests/itext.svg.tests/itext/svg/converter/SvgConverterIntegrationTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ source product.
5252
using iText.Layout.Element;
5353
using iText.Layout.Font;
5454
using iText.Svg.Dummy.Sdk;
55+
using iText.Svg.Exceptions;
5556
using iText.Svg.Processors;
5657
using iText.Svg.Processors.Impl;
5758
using iText.Svg.Renderers;
5859
using iText.Svg.Renderers.Impl;
5960
using iText.Test;
61+
using iText.Test.Attributes;
6062

6163
namespace iText.Svg.Converter {
6264
public class SvgConverterIntegrationTest : SvgIntegrationTest {
@@ -110,6 +112,7 @@ public virtual void BasicIntegrationTest() {
110112
}
111113

112114
[NUnit.Framework.Test]
115+
[LogMessage(SvgLogMessageConstant.UNMAPPEDTAG)]
113116
public virtual void NonExistingTagIntegrationTest() {
114117
String contents = "<svg width='100pt' height='100pt'> <nonExistingTag/> </svg>";
115118
PdfDocument doc = new PdfDocument(new PdfWriter(new MemoryStream()));
@@ -119,6 +122,7 @@ public virtual void NonExistingTagIntegrationTest() {
119122
}
120123

121124
[NUnit.Framework.Test]
125+
[LogMessage(SvgLogMessageConstant.UNMAPPEDTAG, Count = 14)]
122126
public virtual void CaseSensitiveTagTest() {
123127
String contents = "<svg width='100pt' height='100pt'>" + "<altGlyph /><altglyph />" + "<feMergeNode /><femergeNode /><feMergenode /><femergenode />"
124128
+ "<foreignObject /><foreignobject />" + "<glyphRef /><glyphref />" + "<linearGradient /><lineargradient />"

itext.tests/itext.svg.tests/itext/svg/css/SvgStyleResolverIntegrationTest.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,39 @@ public virtual void StylesOfSvgTagProcessingTest() {
135135
expected.Put("d", "M0 100 L0 50 L70 50");
136136
NUnit.Framework.Assert.AreEqual(expected, actual);
137137
}
138+
139+
/// <exception cref="iText.IO.IOException"/>
140+
/// <exception cref="System.Exception"/>
141+
/// <exception cref="System.IO.IOException"/>
142+
[NUnit.Framework.Test]
143+
public virtual void FontResolverIntegrationTest() {
144+
//TODO DEVSIX-2058
145+
ConvertAndCompareVisually(sourceFolder, destinationFolder, "fontssvg");
146+
}
147+
148+
/// <exception cref="iText.IO.IOException"/>
149+
/// <exception cref="System.Exception"/>
150+
/// <exception cref="System.IO.IOException"/>
151+
[NUnit.Framework.Test]
152+
public virtual void ValidLocalFontTest() {
153+
ConvertAndCompareVisually(sourceFolder, destinationFolder, "validLocalFontTest");
154+
}
155+
156+
/// <exception cref="iText.IO.IOException"/>
157+
/// <exception cref="System.Exception"/>
158+
/// <exception cref="System.IO.IOException"/>
159+
[NUnit.Framework.Test]
160+
public virtual void FontWeightTest() {
161+
ConvertAndCompareVisually(sourceFolder, destinationFolder, "fontWeightTest");
162+
}
163+
164+
/// <exception cref="iText.IO.IOException"/>
165+
/// <exception cref="System.Exception"/>
166+
/// <exception cref="System.IO.IOException"/>
167+
[NUnit.Framework.Test]
168+
public virtual void GoogleFontsTest() {
169+
//TODO DEVSIX-2264: that test shall fail after the fix.
170+
ConvertAndCompareVisually(sourceFolder, destinationFolder, "googleFontsTest");
171+
}
138172
}
139173
}

itext.tests/itext.svg.tests/itext/svg/css/SvgStyleResolverTest.cs

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,13 @@ source product.
5151
using iText.Svg;
5252
using iText.Svg.Css.Impl;
5353
using iText.Svg.Processors.Impl;
54-
using iText.Svg.Renderers;
55-
using iText.Test;
5654
using iText.Test.Attributes;
5755

5856
namespace iText.Svg.Css {
59-
public class SvgStyleResolverTest : SvgIntegrationTest {
60-
private static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
57+
public class SvgStyleResolverTest {
58+
private static readonly String baseUri = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
6159
.CurrentContext.TestDirectory) + "/resources/itext/svg/css/SvgStyleResolver/";
6260

63-
private static readonly String destinationFolder = NUnit.Framework.TestContext.CurrentContext.TestDirectory
64-
+ "/test/itext/svg/css/SvgStyleResolver/";
65-
66-
[NUnit.Framework.OneTimeSetUp]
67-
public static void BeforeClass() {
68-
ITextTest.CreateDestinationFolder(destinationFolder);
69-
}
70-
7161
//Single element test
7262
//Inherits values from parent?
7363
//Calculates values from parent
@@ -107,11 +97,11 @@ public virtual void SvgCssResolverXlinkTest() {
10797
imageAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute("xlink:href", "itis.jpg"));
10898
JsoupElementNode node = new JsoupElementNode(jsoupImage);
10999
SvgConverterProperties scp = new SvgConverterProperties();
110-
scp.SetBaseUri(sourceFolder);
100+
scp.SetBaseUri(baseUri);
111101
SvgProcessorContext processorContext = new SvgProcessorContext(scp);
112102
SvgStyleResolver sr = new SvgStyleResolver(node, processorContext);
113103
IDictionary<String, String> attr = sr.ResolveStyles(node, new SvgCssContext());
114-
String fileName = sourceFolder + "itis.jpg";
104+
String fileName = baseUri + "itis.jpg";
115105
String expectedURL = UrlUtil.ToNormalizedURI(fileName).ToString();
116106
NUnit.Framework.Assert.AreEqual(expectedURL, attr.Get("xlink:href"));
117107
}
@@ -124,7 +114,7 @@ public virtual void SvgCssResolveHashXlinkTest() {
124114
imageAttributes.Put(new iText.StyledXmlParser.Jsoup.Nodes.Attribute("xlink:href", "#testid"));
125115
JsoupElementNode node = new JsoupElementNode(jsoupImage);
126116
SvgConverterProperties scp = new SvgConverterProperties();
127-
scp.SetBaseUri(sourceFolder);
117+
scp.SetBaseUri(baseUri);
128118
SvgProcessorContext processorContext = new SvgProcessorContext(scp);
129119
SvgStyleResolver sr = new SvgStyleResolver(node, processorContext);
130120
IDictionary<String, String> attr = sr.ResolveStyles(node, new SvgCssContext());
@@ -191,39 +181,5 @@ public virtual void FontsResolverTagTest() {
191181
NUnit.Framework.Assert.AreEqual(1, fontFaceRuleList.Count);
192182
NUnit.Framework.Assert.AreEqual(2, fontFaceRuleList[0].GetProperties().Count);
193183
}
194-
195-
/// <exception cref="iText.IO.IOException"/>
196-
/// <exception cref="System.Exception"/>
197-
/// <exception cref="System.IO.IOException"/>
198-
[NUnit.Framework.Test]
199-
public virtual void FontResolverIntegrationTest() {
200-
//TODO DEVSIX-2058
201-
ConvertAndCompareVisually(sourceFolder, destinationFolder, "fontssvg");
202-
}
203-
204-
/// <exception cref="iText.IO.IOException"/>
205-
/// <exception cref="System.Exception"/>
206-
/// <exception cref="System.IO.IOException"/>
207-
[NUnit.Framework.Test]
208-
public virtual void ValidLocalFontTest() {
209-
ConvertAndCompareVisually(sourceFolder, destinationFolder, "validLocalFontTest");
210-
}
211-
212-
/// <exception cref="iText.IO.IOException"/>
213-
/// <exception cref="System.Exception"/>
214-
/// <exception cref="System.IO.IOException"/>
215-
[NUnit.Framework.Test]
216-
public virtual void FontWeightTest() {
217-
ConvertAndCompareVisually(sourceFolder, destinationFolder, "fontWeightTest");
218-
}
219-
220-
/// <summary>The following test should fail when RND-1042 is resolved</summary>
221-
/// <exception cref="iText.IO.IOException"/>
222-
/// <exception cref="System.Exception"/>
223-
/// <exception cref="System.IO.IOException"/>
224-
[NUnit.Framework.Test]
225-
public virtual void GoogleFontsTest() {
226-
ConvertAndCompareVisually(sourceFolder, destinationFolder, "googleFontsTest");
227-
}
228184
}
229185
}

itext.tests/itext.svg.tests/itext/svg/processors/impl/font/FontFaceTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ public virtual void FontSelectorTest01() {
111111
/// <exception cref="System.IO.IOException"/>
112112
/// <exception cref="System.Exception"/>
113113
[NUnit.Framework.Test]
114-
[LogMessage(SvgLogMessageConstant.UNABLE_TO_RETRIEVE_STREAM_WITH_GIVEN_BASE_URI)]
115114
public virtual void FontFaceGrammarTest() {
116115
ConvertAndCompareVisually(sourceFolder, destinationFolder, "fontFaceGrammarTest");
117116
}

itext.tests/itext.svg.tests/itext/svg/processors/impl/font/FontSizeTest.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ source product.
4343
using System;
4444
using iText.Svg.Renderers;
4545
using iText.Test;
46+
using iText.Test.Attributes;
4647

4748
namespace iText.Svg.Processors.Impl.Font {
4849
public class FontSizeTest : SvgIntegrationTest {
@@ -68,11 +69,20 @@ public virtual void FontSize01Test() {
6869
/// <exception cref="System.IO.IOException"/>
6970
/// <exception cref="System.Exception"/>
7071
[NUnit.Framework.Test]
72+
[LogMessage(iText.StyledXmlParser.LogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED)]
7173
public virtual void FontSize02Test() {
7274
String name = "fontSizeTest02";
7375
ConvertAndCompareVisually(SOURCE_FOLDER, DESTINATION_FOLDER, name);
7476
}
7577

78+
/// <exception cref="System.IO.IOException"/>
79+
/// <exception cref="System.Exception"/>
80+
[NUnit.Framework.Test]
81+
public virtual void FontSize03Test() {
82+
String name = "fontSizeTest03";
83+
ConvertAndCompareVisually(SOURCE_FOLDER, DESTINATION_FOLDER, name);
84+
}
85+
7686
/// <exception cref="System.IO.IOException"/>
7787
/// <exception cref="System.Exception"/>
7888
[NUnit.Framework.Test]

itext.tests/itext.svg.tests/itext/svg/renderers/SvgIntegrationTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ source product.
4747
using iText.Svg.Converter;
4848
using iText.Svg.Processors;
4949
using iText.Svg.Processors.Impl;
50+
using iText.Test;
5051

5152
namespace iText.Svg.Renderers {
52-
public class SvgIntegrationTest {
53+
public class SvgIntegrationTest : ExtendedITextTest {
5354
/// <exception cref="System.IO.IOException"/>
5455
public virtual void Convert(Stream svg, Stream pdfOutputStream) {
5556
PdfDocument doc = new PdfDocument(new PdfWriter(pdfOutputStream, new WriterProperties().SetCompressionLevel

itext.tests/itext.svg.tests/itext/svg/renderers/impl/LineSvgNodeRendererTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ source product.
5353
using iText.Test.Attributes;
5454

5555
namespace iText.Svg.Renderers.Impl {
56-
public class LineSvgNodeRendererTest {
56+
public class LineSvgNodeRendererTest : SvgIntegrationTest {
5757
public static readonly String sourceFolder = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
5858
.CurrentContext.TestDirectory) + "/resources/itext/svg/renderers/impl/LineSvgNodeRendererTest/";
5959

@@ -132,7 +132,7 @@ public virtual void InvalidAttributeTest01() {
132132

133133
/// <exception cref="System.IO.IOException"/>
134134
[NUnit.Framework.Test]
135-
[LogMessage(iText.StyledXmlParser.LogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED)]
135+
[LogMessage(iText.StyledXmlParser.LogMessageConstant.UNKNOWN_ABSOLUTE_METRIC_LENGTH_PARSED, Count = 2)]
136136
public virtual void InvalidAttributeTest02() {
137137
IDictionary<String, String> lineProperties = new Dictionary<String, String>();
138138
lineProperties.Put("x1", "100");

itext.tests/itext.svg.tests/itext/svg/renderers/impl/NamedObjectsTest.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ source product.
4545
using iText.Svg.Converter;
4646
using iText.Svg.Processors;
4747
using iText.Svg.Processors.Impl;
48+
using iText.Svg.Renderers;
49+
using iText.Test.Attributes;
4850

4951
namespace iText.Svg.Renderers.Impl {
50-
public class NamedObjectsTest {
52+
public class NamedObjectsTest : SvgIntegrationTest {
5153
/// <exception cref="System.IO.IOException"/>
5254
[NUnit.Framework.Test]
55+
[LogMessage(iText.StyledXmlParser.LogMessageConstant.RULE_IS_NOT_SUPPORTED)]
5356
public virtual void AddNamedObject() {
5457
INode parsedSvg = SvgConverter.Parse(new FileStream(iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
5558
.CurrentContext.TestDirectory) + "/resources/itext/svg/renderers/impl/NamedObjectsTest/names.svg", FileMode.Open

itext.tests/itext.svg.tests/itext/svg/renderers/impl/PathSvgNodeRendererLowLevelIntegrationTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@ source product.
4545
using iText.Kernel.Geom;
4646
using iText.Svg;
4747
using iText.Svg.Exceptions;
48+
using iText.Svg.Renderers;
4849
using iText.Svg.Renderers.Path;
4950
using iText.Svg.Renderers.Path.Impl;
5051

5152
namespace iText.Svg.Renderers.Impl {
52-
public class PathSvgNodeRendererLowLevelIntegrationTest {
53+
public class PathSvgNodeRendererLowLevelIntegrationTest : SvgIntegrationTest {
5354
[NUnit.Framework.Test]
5455
public virtual void TestRelativeArcOperatorShapes() {
5556
PathSvgNodeRenderer path = new PathSvgNodeRenderer();

0 commit comments

Comments
 (0)