Skip to content

Commit 5549bd8

Browse files
Kate IvanovaiText-CI
authored andcommitted
Improve layout's Style code coverage
DEVSIX-3864 Autoported commit. Original commit hash: [0e7828753]
1 parent d44c099 commit 5549bd8

File tree

3 files changed

+519
-1
lines changed

3 files changed

+519
-1
lines changed
Lines changed: 346 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,346 @@
1+
using iText.Layout.Properties;
2+
using iText.Test;
3+
4+
namespace iText.Layout {
5+
public class StyleUnitTest : ExtendedITextTest {
6+
public static float EPS = 0.0001f;
7+
8+
[NUnit.Framework.Test]
9+
public virtual void SetAndGetMarginsTest() {
10+
float expectedMarginTop = 92;
11+
float expectedMarginRight = 90;
12+
float expectedMarginBottom = 86;
13+
float expectedMarginLeft = 88;
14+
Style style = new Style();
15+
NUnit.Framework.Assert.IsNull(style.GetMarginTop());
16+
NUnit.Framework.Assert.IsNull(style.GetMarginRight());
17+
NUnit.Framework.Assert.IsNull(style.GetMarginBottom());
18+
NUnit.Framework.Assert.IsNull(style.GetMarginLeft());
19+
style.SetMargins(expectedMarginTop, expectedMarginRight, expectedMarginBottom, expectedMarginLeft);
20+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedMarginTop), style.GetMarginTop());
21+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedMarginRight), style.GetMarginRight());
22+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedMarginBottom), style.GetMarginBottom());
23+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedMarginLeft), style.GetMarginLeft());
24+
}
25+
26+
[NUnit.Framework.Test]
27+
public virtual void SetMarginTest() {
28+
float expectedMargin = 90;
29+
Style style = new Style();
30+
NUnit.Framework.Assert.IsNull(style.GetMarginTop());
31+
NUnit.Framework.Assert.IsNull(style.GetMarginRight());
32+
NUnit.Framework.Assert.IsNull(style.GetMarginBottom());
33+
NUnit.Framework.Assert.IsNull(style.GetMarginLeft());
34+
style.SetMargin(expectedMargin);
35+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedMargin), style.GetMarginTop());
36+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedMargin), style.GetMarginRight());
37+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedMargin), style.GetMarginBottom());
38+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedMargin), style.GetMarginLeft());
39+
}
40+
41+
[NUnit.Framework.Test]
42+
public virtual void GetMarginLeftTest() {
43+
float expLeftMargin = 88;
44+
Style style = new Style();
45+
NUnit.Framework.Assert.IsNull(style.GetMarginLeft());
46+
style.SetMarginLeft(expLeftMargin);
47+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expLeftMargin), style.GetMarginLeft());
48+
}
49+
50+
[NUnit.Framework.Test]
51+
public virtual void GetMarginRightTest() {
52+
float expRightMargin = 90;
53+
Style style = new Style();
54+
NUnit.Framework.Assert.IsNull(style.GetMarginRight());
55+
style.SetMarginRight(expRightMargin);
56+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expRightMargin), style.GetMarginRight());
57+
}
58+
59+
[NUnit.Framework.Test]
60+
public virtual void GetMarginTopTest() {
61+
float expTopMargin = 92;
62+
Style style = new Style();
63+
NUnit.Framework.Assert.IsNull(style.GetMarginTop());
64+
style.SetMarginTop(expTopMargin);
65+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expTopMargin), style.GetMarginTop());
66+
}
67+
68+
[NUnit.Framework.Test]
69+
public virtual void GetMarginBottomTest() {
70+
float expBottomMargin = 86;
71+
Style style = new Style();
72+
NUnit.Framework.Assert.IsNull(style.GetMarginTop());
73+
style.SetMarginBottom(expBottomMargin);
74+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expBottomMargin), style.GetMarginBottom());
75+
}
76+
77+
[NUnit.Framework.Test]
78+
public virtual void GetPaddingLeftTest() {
79+
float expLeftPadding = 6;
80+
Style style = new Style();
81+
NUnit.Framework.Assert.IsNull(style.GetPaddingLeft());
82+
style.SetPaddingLeft(expLeftPadding);
83+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expLeftPadding), style.GetPaddingLeft());
84+
}
85+
86+
[NUnit.Framework.Test]
87+
public virtual void GetPaddingRightTest() {
88+
float expRightPadding = 8;
89+
Style style = new Style();
90+
NUnit.Framework.Assert.IsNull(style.GetPaddingRight());
91+
style.SetPaddingRight(expRightPadding);
92+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expRightPadding), style.GetPaddingRight());
93+
}
94+
95+
[NUnit.Framework.Test]
96+
public virtual void GetPaddingTopTest() {
97+
float expTopPadding = 10;
98+
Style style = new Style();
99+
NUnit.Framework.Assert.IsNull(style.GetPaddingTop());
100+
style.SetPaddingTop(expTopPadding);
101+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expTopPadding), style.GetPaddingTop());
102+
}
103+
104+
[NUnit.Framework.Test]
105+
public virtual void GetPaddingBottomTest() {
106+
float expBottomPadding = 5;
107+
Style style = new Style();
108+
NUnit.Framework.Assert.IsNull(style.GetPaddingBottom());
109+
style.SetPaddingBottom(expBottomPadding);
110+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expBottomPadding), style.GetPaddingBottom());
111+
}
112+
113+
[NUnit.Framework.Test]
114+
public virtual void SetPaddingTest() {
115+
float expPadding = 10;
116+
Style style = new Style();
117+
NUnit.Framework.Assert.IsNull(style.GetPaddingTop());
118+
NUnit.Framework.Assert.IsNull(style.GetPaddingRight());
119+
NUnit.Framework.Assert.IsNull(style.GetPaddingBottom());
120+
NUnit.Framework.Assert.IsNull(style.GetPaddingLeft());
121+
style.SetPadding(expPadding);
122+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expPadding), style.GetPaddingTop());
123+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expPadding), style.GetPaddingRight());
124+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expPadding), style.GetPaddingBottom());
125+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expPadding), style.GetPaddingLeft());
126+
}
127+
128+
[NUnit.Framework.Test]
129+
public virtual void SetPaddingsTest() {
130+
float expPaddingTop = 10;
131+
float expPaddingRight = 8;
132+
float expPaddingBottom = 5;
133+
float expPaddingLeft = 6;
134+
Style style = new Style();
135+
NUnit.Framework.Assert.IsNull(style.GetPaddingTop());
136+
NUnit.Framework.Assert.IsNull(style.GetPaddingRight());
137+
NUnit.Framework.Assert.IsNull(style.GetPaddingBottom());
138+
NUnit.Framework.Assert.IsNull(style.GetPaddingLeft());
139+
style.SetPaddings(expPaddingTop, expPaddingRight, expPaddingBottom, expPaddingLeft);
140+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expPaddingLeft), style.GetPaddingLeft());
141+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expPaddingBottom), style.GetPaddingBottom());
142+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expPaddingTop), style.GetPaddingTop());
143+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expPaddingRight), style.GetPaddingRight());
144+
}
145+
146+
[NUnit.Framework.Test]
147+
public virtual void SetVerticalAlignmentMiddleTest() {
148+
VerticalAlignment? expectedAlignment = VerticalAlignment.MIDDLE;
149+
Style style = new Style();
150+
NUnit.Framework.Assert.IsNull(style.GetProperty<VerticalAlignment?>(Property.VERTICAL_ALIGNMENT));
151+
style.SetVerticalAlignment(expectedAlignment);
152+
NUnit.Framework.Assert.AreEqual(expectedAlignment, style.GetProperty<VerticalAlignment?>(Property.VERTICAL_ALIGNMENT
153+
));
154+
}
155+
156+
[NUnit.Framework.Test]
157+
public virtual void SetVerticalAlignmentTopTest() {
158+
VerticalAlignment? expectedAlignment = VerticalAlignment.TOP;
159+
Style style = new Style();
160+
NUnit.Framework.Assert.IsNull(style.GetProperty<VerticalAlignment?>(Property.VERTICAL_ALIGNMENT));
161+
style.SetVerticalAlignment(expectedAlignment);
162+
NUnit.Framework.Assert.AreEqual(expectedAlignment, style.GetProperty<VerticalAlignment?>(Property.VERTICAL_ALIGNMENT
163+
));
164+
}
165+
166+
[NUnit.Framework.Test]
167+
public virtual void SetVerticalAlignmentBottomTest() {
168+
VerticalAlignment? expectedAlignment = VerticalAlignment.BOTTOM;
169+
Style style = new Style();
170+
NUnit.Framework.Assert.IsNull(style.GetProperty<VerticalAlignment?>(Property.VERTICAL_ALIGNMENT));
171+
style.SetVerticalAlignment(expectedAlignment);
172+
NUnit.Framework.Assert.AreEqual(expectedAlignment, style.GetProperty<VerticalAlignment?>(Property.VERTICAL_ALIGNMENT
173+
));
174+
}
175+
176+
[NUnit.Framework.Test]
177+
public virtual void SetSpacingRatioTest() {
178+
float expectedSpacingRatio = 0.5f;
179+
Style style = new Style();
180+
NUnit.Framework.Assert.IsNull(style.GetProperty<float?>(Property.SPACING_RATIO));
181+
style.SetSpacingRatio(expectedSpacingRatio);
182+
NUnit.Framework.Assert.AreEqual(expectedSpacingRatio, (float)style.GetProperty<float?>(Property.SPACING_RATIO
183+
), EPS);
184+
}
185+
186+
[NUnit.Framework.Test]
187+
public virtual void SetKeepTogetherTrueTest() {
188+
Style style = new Style();
189+
NUnit.Framework.Assert.IsNull(style.GetProperty<bool?>(Property.KEEP_TOGETHER));
190+
style.SetKeepTogether(true);
191+
NUnit.Framework.Assert.AreEqual(true, style.GetProperty<bool?>(Property.KEEP_TOGETHER));
192+
}
193+
194+
[NUnit.Framework.Test]
195+
public virtual void SetKeepTogetherFalseTest() {
196+
Style style = new Style();
197+
NUnit.Framework.Assert.IsNull(style.GetProperty<bool?>(Property.KEEP_TOGETHER));
198+
style.SetKeepTogether(false);
199+
NUnit.Framework.Assert.AreEqual(false, style.GetProperty<bool?>(Property.KEEP_TOGETHER));
200+
}
201+
202+
[NUnit.Framework.Test]
203+
public virtual void IsKeepTogetherTest() {
204+
Style style = new Style();
205+
NUnit.Framework.Assert.IsNull(style.GetProperty<bool?>(Property.KEEP_TOGETHER));
206+
style.SetKeepTogether(true);
207+
NUnit.Framework.Assert.AreEqual(true, style.IsKeepTogether());
208+
}
209+
210+
[NUnit.Framework.Test]
211+
public virtual void SetRotationAngleFloatTest() {
212+
float expectedRotationAngle = 20f;
213+
Style style = new Style();
214+
NUnit.Framework.Assert.IsNull(style.GetProperty<float?>(Property.ROTATION_ANGLE));
215+
style.SetRotationAngle(expectedRotationAngle);
216+
NUnit.Framework.Assert.AreEqual(expectedRotationAngle, (float)style.GetProperty<float?>(Property.ROTATION_ANGLE
217+
), EPS);
218+
}
219+
220+
[NUnit.Framework.Test]
221+
public virtual void SetRotationAngleDoubleTest() {
222+
double expectedRotationAngle = 20.0;
223+
Style style = new Style();
224+
NUnit.Framework.Assert.IsNull(style.GetProperty<float?>(Property.ROTATION_ANGLE));
225+
style.SetRotationAngle(expectedRotationAngle);
226+
NUnit.Framework.Assert.AreEqual(expectedRotationAngle, (float)style.GetProperty<float?>(Property.ROTATION_ANGLE
227+
), EPS);
228+
}
229+
230+
[NUnit.Framework.Test]
231+
public virtual void SetAndGetWidthTest() {
232+
float expectedWidth = 100;
233+
Style style = new Style();
234+
NUnit.Framework.Assert.IsNull(style.GetWidth());
235+
style.SetWidth(expectedWidth);
236+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedWidth), style.GetWidth());
237+
}
238+
239+
[NUnit.Framework.Test]
240+
public virtual void SetAndGetWidthUnitValueTest() {
241+
float expectedWidth = 50;
242+
Style style = new Style();
243+
NUnit.Framework.Assert.IsNull(style.GetWidth());
244+
style.SetWidth(UnitValue.CreatePointValue(expectedWidth));
245+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedWidth), style.GetWidth());
246+
}
247+
248+
[NUnit.Framework.Test]
249+
public virtual void SetAndGetHeightTest() {
250+
float expectedHeight = 100;
251+
Style style = new Style();
252+
NUnit.Framework.Assert.IsNull(style.GetHeight());
253+
style.SetHeight(expectedHeight);
254+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedHeight), style.GetHeight());
255+
}
256+
257+
[NUnit.Framework.Test]
258+
public virtual void SetAndGetHeightUnitValueTest() {
259+
float expectedHeight = 50;
260+
Style style = new Style();
261+
NUnit.Framework.Assert.IsNull(style.GetHeight());
262+
style.SetHeight(UnitValue.CreatePointValue(expectedHeight));
263+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedHeight), style.GetHeight());
264+
}
265+
266+
[NUnit.Framework.Test]
267+
public virtual void SetMaxHeightTest() {
268+
float expectedMaxHeight = 80;
269+
Style style = new Style();
270+
NUnit.Framework.Assert.IsNull(style.GetProperty<UnitValue>(Property.MAX_HEIGHT));
271+
style.SetMaxHeight(expectedMaxHeight);
272+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedMaxHeight), style.GetProperty<UnitValue
273+
>(Property.MAX_HEIGHT));
274+
}
275+
276+
[NUnit.Framework.Test]
277+
public virtual void SetMaxHeightUnitValueTest() {
278+
float expectedMaxHeight = 50;
279+
Style style = new Style();
280+
NUnit.Framework.Assert.IsNull(style.GetProperty<UnitValue>(Property.MAX_HEIGHT));
281+
style.SetMaxHeight(UnitValue.CreatePointValue(expectedMaxHeight));
282+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedMaxHeight), style.GetProperty<UnitValue
283+
>(Property.MAX_HEIGHT));
284+
}
285+
286+
[NUnit.Framework.Test]
287+
public virtual void SetMinHeightTest() {
288+
float expectedMinHeight = 50;
289+
Style style = new Style();
290+
NUnit.Framework.Assert.IsNull(style.GetProperty<UnitValue>(Property.MIN_HEIGHT));
291+
style.SetMinHeight(expectedMinHeight);
292+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedMinHeight), style.GetProperty<UnitValue
293+
>(Property.MIN_HEIGHT));
294+
}
295+
296+
[NUnit.Framework.Test]
297+
public virtual void SetMinHeightUnitValueTest() {
298+
float expectedMinHeight = 30;
299+
Style style = new Style();
300+
NUnit.Framework.Assert.IsNull(style.GetProperty<UnitValue>(Property.MIN_HEIGHT));
301+
style.SetMinHeight(UnitValue.CreatePointValue(expectedMinHeight));
302+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedMinHeight), style.GetProperty<UnitValue
303+
>(Property.MIN_HEIGHT));
304+
}
305+
306+
[NUnit.Framework.Test]
307+
public virtual void SetMaxWidthTest() {
308+
float expectedMaxWidth = 200;
309+
Style style = new Style();
310+
NUnit.Framework.Assert.IsNull(style.GetProperty<UnitValue>(Property.MAX_WIDTH));
311+
style.SetMaxWidth(expectedMaxWidth);
312+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedMaxWidth), style.GetProperty<UnitValue>
313+
(Property.MAX_WIDTH));
314+
}
315+
316+
[NUnit.Framework.Test]
317+
public virtual void SetMaxWidthUnitValueTest() {
318+
float expectedMaxWidth = 150;
319+
Style style = new Style();
320+
NUnit.Framework.Assert.IsNull(style.GetProperty<UnitValue>(Property.MAX_WIDTH));
321+
style.SetMaxWidth(UnitValue.CreatePointValue(expectedMaxWidth));
322+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedMaxWidth), style.GetProperty<UnitValue>
323+
(Property.MAX_WIDTH));
324+
}
325+
326+
[NUnit.Framework.Test]
327+
public virtual void SetMinWidthTest() {
328+
float expectedMinWidth = 50;
329+
Style style = new Style();
330+
NUnit.Framework.Assert.IsNull(style.GetProperty<UnitValue>(Property.MIN_WIDTH));
331+
style.SetMinWidth(expectedMinWidth);
332+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedMinWidth), style.GetProperty<UnitValue>
333+
(Property.MIN_WIDTH));
334+
}
335+
336+
[NUnit.Framework.Test]
337+
public virtual void SetMinWidthUnitValueTest() {
338+
float expectedMinWidth = 30;
339+
Style style = new Style();
340+
NUnit.Framework.Assert.IsNull(style.GetProperty<UnitValue>(Property.MIN_WIDTH));
341+
style.SetMinWidth(UnitValue.CreatePointValue(expectedMinWidth));
342+
NUnit.Framework.Assert.AreEqual(UnitValue.CreatePointValue(expectedMinWidth), style.GetProperty<UnitValue>
343+
(Property.MIN_WIDTH));
344+
}
345+
}
346+
}

0 commit comments

Comments
 (0)