This repository was archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathGraphicsPathIteratorTests.cs
More file actions
429 lines (383 loc) · 17.3 KB
/
GraphicsPathIteratorTests.cs
File metadata and controls
429 lines (383 loc) · 17.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
// Licensed to the .NET Foundation under one or more agreements.
// See the LICENSE file in the project root for more information.
//
// Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Collections.Generic;
using Xunit;
namespace System.Drawing.Drawing2D.Tests
{
public class GraphicsPathIteratorTests
{
private readonly PointF[] _twoPoints = new PointF[2] { new PointF(1, 2), new PointF(20, 30) };
[ConditionalFact(Helpers.IsDrawingSupported)]
public void Ctor_Path_Success()
{
byte[] types = new byte[] { 0, 1 };
using (GraphicsPath gp = new GraphicsPath(_twoPoints, types))
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
Assert.Equal(2, gpi.Count);
}
}
[ConditionalFact(Helpers.IsDrawingSupported)]
public void Ctor_EmptyPath_Success()
{
using (GraphicsPath gp = new GraphicsPath())
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
Assert.Equal(0, gpi.Count);
}
}
[ConditionalFact(Helpers.IsDrawingSupported)]
public void Ctor_NullPath_Success()
{
using (GraphicsPathIterator gpi = new GraphicsPathIterator(null))
{
Assert.Equal(0, gpi.Count);
}
}
[ActiveIssue(20884, TestPlatforms.AnyUnix)]
[ConditionalFact(Helpers.IsDrawingSupported)]
public void NextSubpath_PathFigureNotClosed_ReturnsExpeced()
{
using (GraphicsPath gp = new GraphicsPath())
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
gp.AddLines(_twoPoints);
Assert.Equal(0, gpi.NextSubpath(gp, out bool isClosed));
Assert.False(isClosed);
}
}
[ConditionalFact(Helpers.IsDrawingSupported)]
public void NextSubpath_PathFigureClosed_ReturnsExpeced()
{
using (GraphicsPath gp = new GraphicsPath(_twoPoints, new byte[] { 0, 129 }))
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
Assert.Equal(2, gpi.NextSubpath(gp, out bool isClosed));
Assert.True(isClosed);
}
}
[ActiveIssue(20884, TestPlatforms.AnyUnix)]
[ConditionalFact(Helpers.IsDrawingSupported)]
public void NextSubpath_NullPath_ReturnsExpected()
{
using (GraphicsPathIterator gpi = new GraphicsPathIterator(null))
{
Assert.Equal(0, gpi.NextSubpath(null, out bool isClosed));
Assert.False(isClosed);
}
}
[ActiveIssue(20884, TestPlatforms.AnyUnix)]
[ConditionalFact(Helpers.IsDrawingSupported)]
public void NextSubpath_FigureNotClosed_ReturnsExpeced()
{
using (GraphicsPath gp = new GraphicsPath())
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
gp.AddLines(_twoPoints);
Assert.Equal(0, gpi.NextSubpath(out int startIndex, out int endIndex, out bool isClosed));
Assert.False(isClosed);
Assert.Equal(0, startIndex);
Assert.Equal(0, endIndex);
}
}
[ConditionalFact(Helpers.IsDrawingSupported)]
public void NextSubpath_FigureClosed_ReturnsExpeced()
{
using (GraphicsPath gp = new GraphicsPath(_twoPoints, new byte[] { 0, 129 }))
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
Assert.Equal(2, gpi.NextSubpath(out int startIndex, out int endIndex, out bool isClosed));
Assert.True(isClosed);
Assert.Equal(0, startIndex);
Assert.Equal(1, endIndex);
}
}
[ConditionalFact(Helpers.IsDrawingSupported)]
public void NextMarker_ReturnsExpected()
{
using (GraphicsPath gp = new GraphicsPath(_twoPoints, new byte[] { 0, 1 }))
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
Assert.Equal(2, gpi.NextMarker(out int startIndex, out int endIndex));
Assert.Equal(0, startIndex);
Assert.Equal(1, endIndex);
}
}
[ConditionalFact(Helpers.IsDrawingSupported)]
public void NextMarker_Empty_ReturnsExpected()
{
using (GraphicsPath gp = new GraphicsPath())
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
gp.AddLines(_twoPoints);
Assert.Equal(0, gpi.NextMarker(out int startIndex, out int endIndex));
Assert.Equal(0, startIndex);
Assert.Equal(0, endIndex);
}
}
[ConditionalFact(Helpers.IsDrawingSupported)]
public void NextMarker_NullPath_ReturnsExpected()
{
using (GraphicsPath gp = new GraphicsPath())
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
gp.AddLines(_twoPoints);
Assert.Equal(0, gpi.NextMarker(null));
}
}
[ConditionalFact(Helpers.IsDrawingSupported)]
public void NextMarker_EmptyPath_ReturnsExpected()
{
using (GraphicsPath gp = new GraphicsPath())
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
gp.AddLines(_twoPoints);
Assert.Equal(0, gpi.NextMarker(gp));
}
}
[ConditionalFact(Helpers.IsDrawingSupported)]
public void NextMarker_Path_ReturnsExpected()
{
using (GraphicsPath gp = new GraphicsPath(_twoPoints, new byte[] { 0, 1 }))
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
Assert.Equal(2, gpi.NextMarker(gp));
}
}
[ConditionalFact(Helpers.IsDrawingSupported)]
public void Count_ReturnsExpected()
{
using (GraphicsPath gp = new GraphicsPath(_twoPoints, new byte[] { 0, 1 }))
using (GraphicsPath gpEmpty = new GraphicsPath())
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
using (GraphicsPathIterator gpiEmpty = new GraphicsPathIterator(gpEmpty))
using (GraphicsPathIterator gpiNull = new GraphicsPathIterator(null))
{
Assert.Equal(2, gpi.Count);
Assert.Equal(0, gpiEmpty.Count);
Assert.Equal(0, gpiNull.Count);
}
}
[ConditionalFact(Helpers.IsDrawingSupported)]
public void SubpathCount_ReturnsExpected()
{
using (GraphicsPath gp = new GraphicsPath())
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
using (GraphicsPathIterator gpiNull = new GraphicsPathIterator(null))
{
Assert.Equal(0, gpi.SubpathCount);
Assert.Equal(0, gpiNull.SubpathCount);
gp.AddLine(0, 1, 2, 3);
gp.SetMarkers();
gp.StartFigure();
gp.AddLine(20, 21, 22, 23);
gp.AddBezier(5, 6, 7, 8, 9, 10, 11, 12);
using (GraphicsPathIterator gpiWithSubpaths = new GraphicsPathIterator(gp))
{
Assert.Equal(2, gpiWithSubpaths.SubpathCount);
}
}
}
[ConditionalFact(Helpers.IsDrawingSupported)]
public void HasCurve_ReturnsExpected()
{
Point[] points = new Point[] { new Point(1, 1), new Point(2, 2), new Point(3, 3), new Point(4, 4) };
byte[] types = new byte[] { 0, 3, 3, 3 };
using (GraphicsPath gp = new GraphicsPath(points, types))
using (GraphicsPath gpEmpty = new GraphicsPath())
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
using (GraphicsPathIterator gpiEmpty = new GraphicsPathIterator(gpEmpty))
using (GraphicsPathIterator gpiNull = new GraphicsPathIterator(null))
{
Assert.True(gpi.HasCurve());
Assert.False(gpiEmpty.HasCurve());
Assert.False(gpiNull.HasCurve());
}
}
[ActiveIssue(20884, TestPlatforms.AnyUnix)]
[ConditionalFact(Helpers.IsDrawingSupported)]
public void Rewind_Success()
{
using (GraphicsPath gp = new GraphicsPath())
using (GraphicsPath inner = new GraphicsPath())
{
gp.AddLine(0, 1, 2, 3);
gp.SetMarkers();
gp.StartFigure();
gp.AddLine(20, 21, 22, 23);
gp.AddBezier(5, 6, 7, 8, 9, 10, 11, 12);
byte[] types = new byte[] { 0, 3, 3, 3, 1, 33, 0, 1 };
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
Assert.Equal(2, gpi.SubpathCount);
Assert.Equal(2, gpi.NextMarker(gp));
Assert.Equal(6, gpi.NextMarker(gp));
Assert.Equal(0, gpi.NextMarker(gp));
gpi.Rewind();
Assert.Equal(8, gpi.NextMarker(gp));
Assert.Equal(0, gpi.NextMarker(gp));
}
}
}
[ConditionalFact(Helpers.IsDrawingSupported)]
public void Enumerate_ZeroPoints_ReturnsExpected()
{
PointF[] points = new PointF[0];
byte[] types = new byte[0];
using (GraphicsPath gp = new GraphicsPath())
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
Assert.Equal(0, gpi.Enumerate(ref points, ref types));
Assert.Equal(0, points.Length);
Assert.Equal(0, types.Length);
}
}
[ConditionalFact(Helpers.IsDrawingSupported)]
public void Enumerate_ReturnsExpected()
{
PointF[] points = new PointF[] { new PointF(1f, 1f), new PointF(2f, 2f), new PointF(3f, 3f), new PointF(4f, 4f) };
byte[] types = new byte[] { 0, 3, 3, 3 };
PointF[] actualPoints = new PointF[4];
byte[] actualTypes = new byte[4];
using (GraphicsPath gp = new GraphicsPath(points, types))
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
Assert.Equal(4, gpi.Enumerate(ref actualPoints, ref actualTypes));
Assert.Equal(gp.PathPoints, actualPoints);
Assert.Equal(gp.PathTypes, actualTypes);
}
}
public static IEnumerable<object[]> PointsTypesLenghtMismatch_TestData()
{
yield return new object[] { new PointF[1], new byte[2] };
yield return new object[] { new PointF[2], new byte[1] };
}
[ConditionalTheory(Helpers.IsDrawingSupported)]
[MemberData(nameof(PointsTypesLenghtMismatch_TestData))]
public void Enumerate_PointsTypesMismatch_ThrowsArgumentException(PointF[] points, byte[] types)
{
using (GraphicsPath gp = new GraphicsPath())
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
AssertExtensions.Throws<ArgumentException>(null, () => gpi.Enumerate(ref points, ref types));
}
}
public static IEnumerable<object[]> NullPointsTypes_TestData()
{
yield return new object[] { null, new byte[1] };
yield return new object[] { new PointF[1], null };
yield return new object[] { null, null };
}
[ConditionalTheory(Helpers.IsDrawingSupported)]
[MemberData(nameof(NullPointsTypes_TestData))]
public void Enumerate_NullPointsTypes_ThrowsNullReferenceException(PointF[] points, byte[] types)
{
using (GraphicsPath gp = new GraphicsPath())
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
Assert.Throws<NullReferenceException>(() => gpi.Enumerate(ref points, ref types));
}
}
[ConditionalTheory(Helpers.IsDrawingSupported)]
[MemberData(nameof(PointsTypesLenghtMismatch_TestData))]
public void CopyData_PointsTypesMismatch_ThrowsArgumentException(PointF[] points, byte[] types)
{
using (GraphicsPath gp = new GraphicsPath())
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
AssertExtensions.Throws<ArgumentException>(null, () => gpi.CopyData(ref points, ref types, 0, points.Length));
}
}
[ConditionalTheory(Helpers.IsDrawingSupported)]
[MemberData(nameof(NullPointsTypes_TestData))]
public void CopyData_NullPointsTypes_ThrowsNullReferenceException(PointF[] points, byte[] types)
{
using (GraphicsPath gp = new GraphicsPath())
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
Assert.Throws<NullReferenceException>(() => gpi.CopyData(ref points, ref types, 0, 1));
}
}
[ConditionalTheory(Helpers.IsDrawingSupported)]
[InlineData(-1, 2)]
[InlineData(0, 3)]
public void CopyData_StartEndIndexesOutOfRange_ThrowsArgumentException(int startIndex, int endIndex)
{
PointF[] resultPoints = new PointF[0];
byte[] resultTypes = new byte[0];
using (GraphicsPath gp = new GraphicsPath())
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
AssertExtensions.Throws<ArgumentException>(null, () => gpi.CopyData(ref resultPoints, ref resultTypes, startIndex, endIndex));
}
}
public static IEnumerable<object[]> CopyData_StartEndIndexesOutOfRange_TestData()
{
yield return new object[] { new PointF[3], new byte[3], int.MinValue, 2 };
yield return new object[] { new PointF[3], new byte[3], 0, int.MaxValue };
yield return new object[] { new PointF[3], new byte[3], 2, 0 };
}
[ConditionalTheory(Helpers.IsDrawingSupported)]
[MemberData(nameof(CopyData_StartEndIndexesOutOfRange_TestData))]
public void CopyData_StartEndIndexesOutOfRange_ReturnsExpeced(PointF[] points, byte[] types, int startIndex, int endIndex)
{
PointF[] resultPoints = new PointF[points.Length];
byte[] resultTypes = new byte[points.Length];
using (GraphicsPath gp = new GraphicsPath(points, types))
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
Assert.Equal(0, gpi.CopyData(ref resultPoints, ref resultTypes, startIndex, endIndex));
}
}
[ConditionalFact(Helpers.IsDrawingSupported)]
public void CopyData_EqualStartEndIndexes_ReturnsExpeced()
{
PointF[] points = new PointF[] { new PointF(1f, 1f), new PointF(2f, 2f), new PointF(3f, 3f), new PointF(4f, 4f) };
byte[] types = new byte[] { 0, 3, 3, 3 };
PointF[] actualPoints = new PointF[1];
byte[] actualTypes = new byte[1];
using (GraphicsPath gp = new GraphicsPath(points, types))
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
Assert.Equal(1, gpi.CopyData(ref actualPoints, ref actualTypes, 0, 0));
Assert.Equal(gp.PathPoints[0], actualPoints[0]);
Assert.Equal(gp.PathTypes[0], actualTypes[0]);
}
}
[ConditionalFact(Helpers.IsDrawingSupported)]
public void CopyData_ReturnsExpected()
{
PointF[] points = new PointF[] { new PointF(1f, 1f), new PointF(2f, 2f), new PointF(3f, 3f), new PointF(4f, 4f) };
byte[] types = new byte[] { 0, 3, 3, 3 };
PointF[] actualPoints = new PointF[3];
byte[] actualTypes = new byte[3];
using (GraphicsPath gp = new GraphicsPath(points, types))
using (GraphicsPathIterator gpi = new GraphicsPathIterator(gp))
{
Assert.Equal(3, gpi.CopyData(ref actualPoints, ref actualTypes, 0, 2));
}
}
}
}