Skip to content

Commit 7c971d5

Browse files
Kate IvanovaiText-CI
authored andcommitted
Improve test coverage for StopSvgNodeRenderer class
DEVSIX-4828 Autoported commit. Original commit hash: [aa468ca5b]
1 parent 39768c2 commit 7c971d5

File tree

2 files changed

+241
-1
lines changed

2 files changed

+241
-1
lines changed
Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
/*
2+
This file is part of the iText (R) project.
3+
Copyright (c) 1998-2020 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.Collections.Generic;
45+
using iText.Svg;
46+
using iText.Svg.Renderers;
47+
using iText.Test;
48+
49+
namespace iText.Svg.Renderers.Impl {
50+
public class StopSvgNodeRendererUnitTest : ExtendedITextTest {
51+
private const float DELTA = 0;
52+
53+
[NUnit.Framework.Test]
54+
public virtual void GetOffsetPercentageValueTest() {
55+
IDictionary<String, String> styles = new Dictionary<String, String>();
56+
styles.Put(SvgConstants.Attributes.OFFSET, "50%");
57+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
58+
renderer.SetAttributesAndStyles(styles);
59+
double expected = 0.5;
60+
NUnit.Framework.Assert.AreEqual(expected, renderer.GetOffset(), DELTA);
61+
}
62+
63+
[NUnit.Framework.Test]
64+
public virtual void GetOffsetNumericValueTest() {
65+
IDictionary<String, String> styles = new Dictionary<String, String>();
66+
styles.Put(SvgConstants.Attributes.OFFSET, "0.5");
67+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
68+
renderer.SetAttributesAndStyles(styles);
69+
double expected = 0.5;
70+
NUnit.Framework.Assert.AreEqual(expected, renderer.GetOffset(), DELTA);
71+
}
72+
73+
[NUnit.Framework.Test]
74+
public virtual void GetOffsetMoreThanOneValueTest() {
75+
IDictionary<String, String> styles = new Dictionary<String, String>();
76+
styles.Put(SvgConstants.Attributes.OFFSET, "2");
77+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
78+
renderer.SetAttributesAndStyles(styles);
79+
double expected = 1;
80+
NUnit.Framework.Assert.AreEqual(expected, renderer.GetOffset(), DELTA);
81+
}
82+
83+
[NUnit.Framework.Test]
84+
public virtual void GetOffsetLessThanZeroValueTest() {
85+
IDictionary<String, String> styles = new Dictionary<String, String>();
86+
styles.Put(SvgConstants.Attributes.OFFSET, "-2");
87+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
88+
renderer.SetAttributesAndStyles(styles);
89+
double expected = 0;
90+
NUnit.Framework.Assert.AreEqual(expected, renderer.GetOffset(), DELTA);
91+
}
92+
93+
[NUnit.Framework.Test]
94+
public virtual void GetOffsetNoneValueTest() {
95+
IDictionary<String, String> styles = new Dictionary<String, String>();
96+
styles.Put(SvgConstants.Attributes.OFFSET, null);
97+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
98+
renderer.SetAttributesAndStyles(styles);
99+
double expected = 0;
100+
NUnit.Framework.Assert.AreEqual(expected, renderer.GetOffset(), DELTA);
101+
}
102+
103+
[NUnit.Framework.Test]
104+
public virtual void GetOffsetRandomStringValueTest() {
105+
IDictionary<String, String> styles = new Dictionary<String, String>();
106+
styles.Put(SvgConstants.Attributes.OFFSET, "Hello");
107+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
108+
renderer.SetAttributesAndStyles(styles);
109+
double expected = 0;
110+
NUnit.Framework.Assert.AreEqual(expected, renderer.GetOffset(), DELTA);
111+
}
112+
113+
[NUnit.Framework.Test]
114+
public virtual void GetOffsetEmptyStringValueTest() {
115+
IDictionary<String, String> styles = new Dictionary<String, String>();
116+
styles.Put(SvgConstants.Attributes.OFFSET, "");
117+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
118+
renderer.SetAttributesAndStyles(styles);
119+
double expected = 0;
120+
NUnit.Framework.Assert.AreEqual(expected, renderer.GetOffset(), DELTA);
121+
}
122+
123+
[NUnit.Framework.Test]
124+
public virtual void GetStopColorTest() {
125+
IDictionary<String, String> styles = new Dictionary<String, String>();
126+
styles.Put(SvgConstants.Tags.STOP_COLOR, "red");
127+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
128+
renderer.SetAttributesAndStyles(styles);
129+
float[] expected = new float[] { 1, 0, 0, 1 };
130+
float[] actual = renderer.GetStopColor();
131+
NUnit.Framework.Assert.AreEqual(expected, actual);
132+
}
133+
134+
[NUnit.Framework.Test]
135+
public virtual void GetStopColorNoneValueTest() {
136+
IDictionary<String, String> styles = new Dictionary<String, String>();
137+
styles.Put(SvgConstants.Tags.STOP_COLOR, null);
138+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
139+
renderer.SetAttributesAndStyles(styles);
140+
float[] expected = new float[] { 0, 0, 0, 1 };
141+
float[] actual = renderer.GetStopColor();
142+
NUnit.Framework.Assert.AreEqual(expected, actual);
143+
}
144+
145+
[NUnit.Framework.Test]
146+
public virtual void GetStopColorRandomStringValueTest() {
147+
IDictionary<String, String> styles = new Dictionary<String, String>();
148+
styles.Put(SvgConstants.Tags.STOP_COLOR, "Hello");
149+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
150+
renderer.SetAttributesAndStyles(styles);
151+
float[] expected = new float[] { 0, 0, 0, 1 };
152+
float[] actual = renderer.GetStopColor();
153+
NUnit.Framework.Assert.AreEqual(expected, actual);
154+
}
155+
156+
[NUnit.Framework.Test]
157+
public virtual void GetStopColorEmptyStringTest() {
158+
IDictionary<String, String> styles = new Dictionary<String, String>();
159+
styles.Put(SvgConstants.Tags.STOP_COLOR, "");
160+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
161+
renderer.SetAttributesAndStyles(styles);
162+
float[] expected = new float[] { 0, 0, 0, 1 };
163+
float[] actual = renderer.GetStopColor();
164+
NUnit.Framework.Assert.AreEqual(expected, actual);
165+
}
166+
167+
[NUnit.Framework.Test]
168+
public virtual void GetStopColorOpacityTest() {
169+
IDictionary<String, String> styles = new Dictionary<String, String>();
170+
styles.Put(SvgConstants.Tags.STOP_COLOR, "rgba(0.5, 0.5, 0.5, 0.5)");
171+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
172+
renderer.SetAttributesAndStyles(styles);
173+
float[] expected = new float[] { 0, 0, 0, 1 };
174+
float[] actual = renderer.GetStopColor();
175+
NUnit.Framework.Assert.AreEqual(expected, actual);
176+
}
177+
178+
[NUnit.Framework.Test]
179+
public virtual void GetStopOpacityTest() {
180+
IDictionary<String, String> styles = new Dictionary<String, String>();
181+
styles.Put(SvgConstants.Tags.STOP_OPACITY, "1");
182+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
183+
renderer.SetAttributesAndStyles(styles);
184+
float expected = 1;
185+
NUnit.Framework.Assert.AreEqual(expected, renderer.GetStopOpacity(), DELTA);
186+
}
187+
188+
[NUnit.Framework.Test]
189+
public virtual void GetStopOpacityNoneValueTest() {
190+
IDictionary<String, String> styles = new Dictionary<String, String>();
191+
styles.Put(SvgConstants.Tags.STOP_OPACITY, null);
192+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
193+
renderer.SetAttributesAndStyles(styles);
194+
float expected = 1;
195+
NUnit.Framework.Assert.AreEqual(expected, renderer.GetStopOpacity(), DELTA);
196+
}
197+
198+
[NUnit.Framework.Test]
199+
public virtual void GetStopOpacityRandomStringValueTest() {
200+
IDictionary<String, String> styles = new Dictionary<String, String>();
201+
styles.Put(SvgConstants.Tags.STOP_OPACITY, "Hello");
202+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
203+
renderer.SetAttributesAndStyles(styles);
204+
float expected = 1;
205+
NUnit.Framework.Assert.AreEqual(expected, renderer.GetStopOpacity(), DELTA);
206+
}
207+
208+
[NUnit.Framework.Test]
209+
public virtual void GetStopOpacityEmptyStringTest() {
210+
IDictionary<String, String> styles = new Dictionary<String, String>();
211+
styles.Put(SvgConstants.Tags.STOP_OPACITY, "");
212+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
213+
renderer.SetAttributesAndStyles(styles);
214+
float expected = 1;
215+
NUnit.Framework.Assert.AreEqual(expected, renderer.GetStopOpacity(), DELTA);
216+
}
217+
218+
[NUnit.Framework.Test]
219+
public virtual void CreateDeepCopyTest() {
220+
IDictionary<String, String> styles = new Dictionary<String, String>();
221+
styles.Put(SvgConstants.Attributes.OFFSET, "0.5");
222+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
223+
renderer.SetAttributesAndStyles(styles);
224+
ISvgNodeRenderer copy = renderer.CreateDeepCopy();
225+
NUnit.Framework.Assert.AreNotSame(renderer, copy);
226+
NUnit.Framework.Assert.AreEqual(renderer.GetType(), copy.GetType());
227+
NUnit.Framework.Assert.AreEqual(renderer.GetAttributeMapCopy(), copy.GetAttributeMapCopy());
228+
}
229+
230+
[NUnit.Framework.Test]
231+
public virtual void DoDrawTest() {
232+
StopSvgNodeRenderer renderer = new StopSvgNodeRenderer();
233+
NUnit.Framework.Assert.That(() => {
234+
renderer.DoDraw(new SvgDrawContext(null, null));
235+
}
236+
, NUnit.Framework.Throws.InstanceOf<NotSupportedException>().With.Message.EqualTo("Can't draw current SvgNodeRenderer."))
237+
;
238+
}
239+
}
240+
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c009330458ecdd99237dac9fb8f0d3961b7ddffd
1+
aa468ca5b908d00757ebee9e3163935487d35fec

0 commit comments

Comments
 (0)