2006-01-13 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing.Drawing2D / GraphicsPathTest.cs
1 //
2 // System.Drawing.GraphicsPath unit tests
3 //
4 // Authors:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System;
30 using SC = System.ComponentModel;
31 using System.Drawing;
32 using System.Drawing.Drawing2D;
33 using System.Security.Permissions;
34 using NUnit.Framework;
35
36 namespace MonoTests.System.Drawing.Drawing2D {
37
38         [TestFixture]
39         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
40         public class GraphicsPathTest {
41
42                 private const float Pi4 = (float) (Math.PI / 4);
43
44                 private void CheckEmpty (string prefix, GraphicsPath gp)
45                 {
46                         Assert.AreEqual (0, gp.PathData.Points.Length, "PathData.Points");
47                         Assert.AreEqual (0, gp.PathData.Types.Length, "PathData.Types");
48                         Assert.AreEqual (0, gp.PointCount, prefix + "PointCount");
49                 }
50
51                 [Test]
52                 public void Constructor_InvalidFillMode ()
53                 {
54                         GraphicsPath gp = new GraphicsPath ((FillMode) Int32.MinValue);
55                         Assert.AreEqual (Int32.MinValue, (int) gp.FillMode, "FillMode");
56                         CheckEmpty ("InvalidFillMode.", gp);
57                 }
58
59                 [Test]
60                 [ExpectedException (typeof (ArgumentNullException))]
61                 public void Constructor_Point_Null_Byte ()
62                 {
63                         new GraphicsPath ((Point[]) null, new byte[1]);
64                 }
65
66                 [Test]
67                 [ExpectedException (typeof (NullReferenceException))]
68                 public void Constructor_Point_Byte_Null ()
69                 {
70                         new GraphicsPath (new Point[1], null);
71                 }
72
73                 [Test]
74                 [ExpectedException (typeof (ArgumentException))]
75                 public void Constructor_Point_Byte_LengthMismatch ()
76                 {
77                         new GraphicsPath (new Point[1], new byte [2]);
78                 }
79
80                 [Test]
81                 [ExpectedException (typeof (ArgumentNullException))]
82                 public void Constructor_PointF_Null_Byte ()
83                 {
84                         new GraphicsPath ((PointF[])null, new byte [1]);
85                 }
86
87                 [Test]
88                 [ExpectedException (typeof (NullReferenceException))]
89                 public void Constructor_PointF_Byte_Null ()
90                 {
91                         new GraphicsPath ( new PointF[1], null);
92                 }
93
94                 [Test]
95                 [ExpectedException (typeof (ArgumentException))]
96                 public void Constructor_PointF_Byte_LengthMismatch ()
97                 {
98                         new GraphicsPath (new PointF[2], new byte [1]);
99                 }
100
101                 [Test]
102                 public void GraphicsPath_Empty ()
103                 {
104                         GraphicsPath gp = new GraphicsPath ();
105                         Assert.AreEqual (FillMode.Alternate, gp.FillMode, "Empty.FillMode");
106                         CheckEmpty ("Empty.", gp);
107
108                         GraphicsPath clone = (GraphicsPath) gp.Clone ();
109                         Assert.AreEqual (FillMode.Alternate, gp.FillMode, "Clone.FillMode");
110                         CheckEmpty ("Clone.", gp);
111                 }
112
113                 [Test]
114                 [ExpectedException (typeof (ArgumentException))]
115                 public void GraphicsPath_Empty_PathPoints ()
116                 {
117                         Assert.IsNull (new GraphicsPath ().PathPoints);
118                 }
119
120                 [Test]
121                 [ExpectedException (typeof (ArgumentException))]
122                 public void GraphicsPath_Empty_PathTypes ()
123                 {
124                         Assert.IsNull (new GraphicsPath ().PathTypes);
125                 }
126
127                 [Test]
128                 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
129                 public void FillMode_Invalid ()
130                 {
131                         // constructor accept an invalid FillMode
132                         GraphicsPath gp = new GraphicsPath ((FillMode) Int32.MaxValue);
133                         Assert.AreEqual (Int32.MaxValue, (int) gp.FillMode, "MaxValue");
134                         // but you can't set the FillMode property to an invalid value ;-)
135                         gp.FillMode = (FillMode) Int32.MaxValue;
136                 }
137
138                 [Test]
139                 public void PathData_CannotChange ()
140                 {
141                         GraphicsPath gp = new GraphicsPath ();
142                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
143
144                         Assert.AreEqual (1f, gp.PathData.Points[0].X, "Points[0].X");
145                         Assert.AreEqual (1f, gp.PathData.Points[0].Y, "Points[0].Y");
146
147                         // now try to change the first point
148                         gp.PathData.Points[0] = new Point (0, 0);
149                         // the changes isn't reflected in the property
150                         Assert.AreEqual (1f, gp.PathData.Points[0].X, "Points[0].X-1");
151                         Assert.AreEqual (1f, gp.PathData.Points[0].Y, "Points[0].Y-1");
152                 }
153
154                 [Test]
155                 public void PathPoints_CannotChange ()
156                 {
157                         GraphicsPath gp = new GraphicsPath ();
158                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
159
160                         Assert.AreEqual (1f, gp.PathPoints[0].X, "PathPoints[0].X");
161                         Assert.AreEqual (1f, gp.PathPoints[0].Y, "PathPoints[0].Y");
162
163                         // now try to change the first point
164                         gp.PathPoints[0] = new Point (0, 0);
165                         // the changes isn't reflected in the property
166                         Assert.AreEqual (1f, gp.PathPoints[0].X, "PathPoints[0].X-1");
167                         Assert.AreEqual (1f, gp.PathPoints[0].Y, "PathPoints[0].Y-1");
168                 }
169
170                 [Test]
171                 public void PathTypes_CannotChange ()
172                 {
173                         GraphicsPath gp = new GraphicsPath ();
174                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
175
176                         Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
177
178                         // now try to change the first type
179                         gp.PathTypes[0] = 1;
180                         // the changes isn't reflected in the property
181                         Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]-1");
182                 }
183
184                 private void CheckArc (GraphicsPath path)
185                 {
186                         Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
187                         Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
188                         Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
189
190                         Assert.AreEqual (2.999906f, path.PathData.Points[0].X, "Points[0].X");
191                         Assert.AreEqual (2.013707f, path.PathPoints[0].Y, "Points[0].Y");
192                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
193                         Assert.AreEqual (2.999843f, path.PathData.Points[1].X, "Points[1].X");
194                         Assert.AreEqual (2.018276f, path.PathPoints[1].Y, "Points[1].Y");
195                         Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
196                         Assert.AreEqual (2.99974918f, path.PathData.Points[2].X, "Points[2].X");
197                         Assert.AreEqual (2.02284455f, path.PathPoints[2].Y, "Points[2].Y");
198                         Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
199                         Assert.AreEqual (2.999624f, path.PathData.Points[3].X, "Points[3].X");
200                         Assert.AreEqual (2.027412f, path.PathPoints[3].Y, "Points[3].Y");
201                         Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
202                 }
203
204                 [Test]
205                 public void AddArc_Rectangle ()
206                 {
207                         GraphicsPath gp = new GraphicsPath ();
208                         gp.AddArc (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
209                         CheckArc (gp);
210                 }
211
212                 [Test]
213                 public void AddArc_RectangleF ()
214                 {
215                         GraphicsPath gp = new GraphicsPath ();
216                         gp.AddArc (new RectangleF (1f, 1f, 2f, 2f), Pi4, Pi4);
217                         CheckArc (gp);
218                 }
219
220                 [Test]
221                 public void AddArc_Int ()
222                 {
223                         GraphicsPath gp = new GraphicsPath ();
224                         gp.AddArc (1, 1, 2, 2, Pi4, Pi4);
225                         CheckArc (gp);
226                 }
227
228                 [Test]
229                 public void AddArc_Float ()
230                 {
231                         GraphicsPath gp = new GraphicsPath ();
232                         gp.AddArc (1f, 1f, 2f, 2f, Pi4, Pi4);
233                         CheckArc (gp);
234                 }
235
236                 private void CheckBezier (GraphicsPath path)
237                 {
238                         Assert.AreEqual (4, path.PointCount, "PointCount");
239                         Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
240                         Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
241                         Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
242
243                         Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
244                         Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
245                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
246                         Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
247                         Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
248                         Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
249                         Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
250                         Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
251                         Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
252                         Assert.AreEqual (4f, path.PathData.Points[3].X, "Points[3].X");
253                         Assert.AreEqual (4f, path.PathPoints[3].Y, "Points[3].Y");
254                         Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
255                 }
256
257                 [Test]
258                 public void AddBezier_Point ()
259                 {
260                         GraphicsPath gp = new GraphicsPath ();
261                         gp.AddBezier (new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4));
262                         CheckBezier (gp);
263                 }
264
265                 [Test]
266                 public void AddBezier_PointF ()
267                 {
268                         GraphicsPath gp = new GraphicsPath ();
269                         gp.AddBezier (new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f));
270                         CheckBezier (gp);
271                 }
272
273                 [Test]
274                 public void AddBezier_Int ()
275                 {
276                         GraphicsPath gp = new GraphicsPath ();
277                         gp.AddBezier (1, 1, 2, 2, 3, 3, 4, 4);
278                         CheckBezier (gp);
279                 }
280
281                 [Test]
282                 public void AddBezier_Float ()
283                 {
284                         GraphicsPath gp = new GraphicsPath ();
285                         gp.AddBezier (1f, 1f, 2f, 2f, 3f, 3f, 4f, 4f);
286                         CheckBezier (gp);
287                 }
288
289                 [Test]
290                 [ExpectedException (typeof (ArgumentNullException))]
291                 public void AddBeziers_Point_Null ()
292                 {
293                         new GraphicsPath ().AddBeziers ((Point[]) null);
294                 }
295
296                 [Test]
297                 [ExpectedException (typeof (ArgumentException))]
298                 public void AddBeziers_3_Points ()
299                 {
300                         GraphicsPath gp = new GraphicsPath ();
301                         gp.AddBeziers (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
302                 }
303
304                 [Test]
305                 public void AddBeziers_Point ()
306                 {
307                         GraphicsPath gp = new GraphicsPath ();
308                         gp.AddBeziers (new Point[4] { new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4) });
309                         CheckBezier (gp);
310                 }
311
312                 [Test]
313                 [ExpectedException (typeof (ArgumentNullException))]
314                 public void AddBeziers_PointF_Null ()
315                 {
316                         new GraphicsPath ().AddBeziers ((PointF[]) null);
317                 }
318
319                 [Test]
320                 [ExpectedException (typeof (ArgumentException))]
321                 public void AddBeziers_3_PointFs ()
322                 {
323                         GraphicsPath gp = new GraphicsPath ();
324                         gp.AddBeziers (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
325                 }
326
327                 [Test]
328                 public void AddBeziers_PointF ()
329                 {
330                         GraphicsPath gp = new GraphicsPath ();
331                         gp.AddBeziers (new PointF[4] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f) });
332                         CheckBezier (gp);
333                 }
334
335                 private void CheckEllipse (GraphicsPath path)
336                 {
337                         Assert.AreEqual (13, path.PathPoints.Length, "PathPoints");
338                         Assert.AreEqual (13, path.PathTypes.Length, "PathPoints");
339                         Assert.AreEqual (13, path.PathData.Points.Length, "PathData");
340 #if false
341                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
342                         RectangleF rect = path.GetBounds ();
343                         Assert.AreEqual (1f, rect.X, "Bounds.X");
344                         Assert.AreEqual (1f, rect.Y, "Bounds.Y");
345                         Assert.AreEqual (2f, rect.Width, "Bounds.Width");
346                         Assert.AreEqual (2f, rect.Height, "Bounds.Height");
347 #endif
348                         Assert.AreEqual (0, path.PathData.Types[0], "PathData.Types[0]");
349                         for (int i = 1; i < 12; i++)
350                                 Assert.AreEqual (3, path.PathTypes[i], "PathTypes" + i.ToString ());
351                         Assert.AreEqual (131, path.PathData.Types[12], "PathData.Types[12]");
352                 }
353
354                 [Test]
355                 public void AddEllipse_Rectangle ()
356                 {
357                         GraphicsPath gp = new GraphicsPath ();
358                         gp.AddEllipse (new Rectangle (1, 1, 2, 2));
359                         CheckEllipse (gp);
360                 }
361
362                 [Test]
363                 public void AddEllipse_RectangleF ()
364                 {
365                         GraphicsPath gp = new GraphicsPath ();
366                         gp.AddEllipse (new RectangleF (1f, 1f, 2f, 2f));
367                         CheckEllipse (gp);
368                 }
369
370                 [Test]
371                 public void AddEllipse_Int ()
372                 {
373                         GraphicsPath gp = new GraphicsPath ();
374                         gp.AddEllipse (1, 1, 2, 2);
375                         CheckEllipse (gp);
376                 }
377
378                 [Test]
379                 public void AddEllipse_Float ()
380                 {
381                         GraphicsPath gp = new GraphicsPath ();
382                         gp.AddEllipse (1f, 1f, 2f, 2f);
383                         CheckEllipse (gp);
384                 }
385
386                 private void CheckLine (GraphicsPath path)
387                 {
388                         Assert.AreEqual (2, path.PathPoints.Length, "PathPoints");
389                         Assert.AreEqual (2, path.PathTypes.Length, "PathPoints");
390                         Assert.AreEqual (2, path.PathData.Points.Length, "PathData");
391
392                         Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
393                         Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
394                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
395                         Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
396                         Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
397                         Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
398                 }
399
400                 [Test]
401                 public void AddLine_Point ()
402                 {
403                         GraphicsPath gp = new GraphicsPath ();
404                         gp.AddLine (new Point (1, 1), new Point (2, 2));
405                         CheckLine (gp);
406                 }
407
408                 [Test]
409                 public void AddLine_PointF ()
410                 {
411                         GraphicsPath gp = new GraphicsPath ();
412                         gp.AddLine (new PointF (1f, 1f), new PointF (2f, 2f));
413                         CheckLine (gp);
414                 }
415
416                 [Test]
417                 public void AddLine_Int ()
418                 {
419                         GraphicsPath gp = new GraphicsPath ();
420                         gp.AddLine (1, 1, 2, 2);
421                         CheckLine (gp);
422                 }
423
424                 [Test]
425                 public void AddLine_Float ()
426                 {
427                         GraphicsPath gp = new GraphicsPath ();
428                         gp.AddLine (1f, 1f, 2f, 2f);
429                         CheckLine (gp);
430                 }
431
432                 [Test]
433                 public void AddLine_SamePoint ()
434                 {
435                         GraphicsPath gp = new GraphicsPath ();
436                         gp.AddLine (new Point (1, 1), new Point (1, 1));
437                         Assert.AreEqual (2, gp.PointCount, "PointCount");
438                         Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
439                         Assert.AreEqual (1, gp.PathTypes[1], "PathTypes[1]");
440                 }
441
442                 [Test]
443                 [ExpectedException (typeof (ArgumentNullException))]
444                 public void AddLines_Point_Null ()
445                 {
446                         new GraphicsPath ().AddLines ((Point[])null);
447                 }
448
449                 [Test]
450                 [ExpectedException (typeof (ArgumentException))]
451                 public void AddLines_Point_0 ()
452                 {
453                         GraphicsPath gp = new GraphicsPath ();
454                         gp.AddLines (new Point[0]);
455                         CheckLine (gp);
456                 }
457
458                 [Test]
459                 [Category ("NotWorking")]
460                 public void AddLines_Point_1 ()
461                 {
462                         GraphicsPath gp = new GraphicsPath ();
463                         gp.AddLines (new Point[1] { new Point (1, 1) });
464                         // Special case - a line with a single point is valid
465                         Assert.AreEqual (1, gp.PointCount, "PointCount");
466                         Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
467                 }
468
469                 [Test]
470                 public void AddLines_Point ()
471                 {
472                         GraphicsPath gp = new GraphicsPath ();
473                         gp.AddLines (new Point[2] { new Point (1, 1), new Point (2, 2) });
474                         CheckLine (gp);
475                 }
476
477                 [Test]
478                 [ExpectedException (typeof (ArgumentNullException))]
479                 public void AddLines_PointF_Null ()
480                 {
481                         new GraphicsPath ().AddLines ((PointF[]) null);
482                 }
483
484                 [Test]
485                 [ExpectedException (typeof (ArgumentException))]
486                 public void AddLines_PointF_0 ()
487                 {
488                         GraphicsPath gp = new GraphicsPath ();
489                         gp.AddLines (new PointF[0]);
490                         CheckLine (gp);
491                 }
492
493                 [Test]
494                 [Category ("NotWorking")]
495                 public void AddLines_PointF_1 ()
496                 {
497                         GraphicsPath gp = new GraphicsPath ();
498                         gp.AddLines (new PointF[1] { new PointF (1f, 1f) });
499                         // Special case - a line with a single point is valid
500                         Assert.AreEqual (1, gp.PointCount, "PointCount");
501                         Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
502                 }
503
504                 [Test]
505                 public void AddLines_PointF ()
506                 {
507                         GraphicsPath gp = new GraphicsPath ();
508                         gp.AddLines (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
509                         CheckLine (gp);
510                 }
511
512                 private void CheckPie (GraphicsPath path)
513                 {
514                         // the number of points generated for a Pie isn't the same between Mono and MS
515 #if false
516                         Assert.AreEqual (5, path.PathPoints.Length, "PathPoints");
517                         Assert.AreEqual (5, path.PathTypes.Length, "PathPoints");
518                         Assert.AreEqual (5, path.PathData.Points.Length, "PathData");
519
520                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
521                         RectangleF rect = path.GetBounds ();
522                         Assert.AreEqual (2f, rect.X, "Bounds.X");
523                         Assert.AreEqual (2f, rect.Y, "Bounds.Y");
524                         Assert.AreEqual (0.9999058f, rect.Width, "Bounds.Width");
525                         Assert.AreEqual (0.0274119377f, rect.Height, "Bounds.Height");
526
527                         Assert.AreEqual (2f, path.PathData.Points[0].X, "Points[0].X");
528                         Assert.AreEqual (2f, path.PathPoints[0].Y, "Points[0].Y");
529                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
530                         Assert.AreEqual (2.99990582f, path.PathData.Points[1].X, "Points[1].X");
531                         Assert.AreEqual (2.01370716f, path.PathPoints[1].Y, "Points[1].Y");
532                         Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
533                         Assert.AreEqual (2.99984312f, path.PathData.Points[2].X, "Points[2].X");
534                         Assert.AreEqual (2.018276f, path.PathPoints[2].Y, "Points[2].Y");
535                         Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
536                         Assert.AreEqual (2.99974918f, path.PathData.Points[3].X, "Points[2].X");
537                         Assert.AreEqual (2.02284455f, path.PathPoints[3].Y, "Points[2].Y");
538                         Assert.AreEqual (3, path.PathData.Types[3], "Types[2]");
539                         Assert.AreEqual (2.999624f, path.PathData.Points[4].X, "Points[3].X");
540                         Assert.AreEqual (2.027412f, path.PathPoints[4].Y, "Points[3].Y");
541                         Assert.AreEqual (131, path.PathTypes[4], "Types[3]");
542 #endif
543                 }
544
545                 [Test]
546                 public void AddPie_Rect ()
547                 {
548                         GraphicsPath gp = new GraphicsPath ();
549                         gp.AddPie (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
550                         CheckPie (gp);
551                 }
552
553                 [Test]
554                 public void AddPie_Int ()
555                 {
556                         GraphicsPath gp = new GraphicsPath ();
557                         gp.AddPie (1, 1, 2, 2, Pi4, Pi4);
558                         CheckPie (gp);
559                 }
560
561                 [Test]
562                 public void AddPie_Float ()
563                 {
564                         GraphicsPath gp = new GraphicsPath ();
565                         gp.AddPie (1f, 1f, 2f, 2f, Pi4, Pi4);
566                         CheckPie (gp);
567                 }
568
569                 private void CheckPolygon (GraphicsPath path)
570                 {
571                         // an extra point is generated by Mono (libgdiplus)
572 #if false
573                         Assert.AreEqual (3, path.PathPoints.Length, "PathPoints");
574                         Assert.AreEqual (3, path.PathTypes.Length, "PathPoints");
575                         Assert.AreEqual (3, path.PathData.Points.Length, "PathData");
576
577                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
578                         RectangleF rect = path.GetBounds ();
579                         Assert.AreEqual (1f, rect.X, "Bounds.X");
580                         Assert.AreEqual (1f, rect.Y, "Bounds.Y");
581                         Assert.AreEqual (2f, rect.Width, "Bounds.Width");
582                         Assert.AreEqual (2f, rect.Height, "Bounds.Height");
583 #endif
584                         Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
585                         Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
586                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
587                         Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
588                         Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
589                         Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
590                         Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
591                         Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
592                         // the extra point change the type of the last point
593 #if false
594                         Assert.AreEqual (129, path.PathData.Types[2], "Types[2]");
595 #endif
596                 }
597
598                 [Test]
599                 [ExpectedException (typeof (ArgumentNullException))]
600                 public void AddPolygon_Point_Null ()
601                 {
602                         new GraphicsPath ().AddPolygon ((Point[]) null);
603                 }
604
605                 [Test]
606                 [ExpectedException (typeof (ArgumentException))]
607                 public void AddPolygon_Point_Empty ()
608                 {
609                         new GraphicsPath ().AddPolygon (new Point[0]);
610                 }
611
612                 [Test]
613                 [ExpectedException (typeof (ArgumentException))]
614                 public void AddPolygon_Point_1 ()
615                 {
616                         GraphicsPath gp = new GraphicsPath ();
617                         gp.AddPolygon (new Point[1] { new Point (1, 1) });
618                 }
619
620                 [Test]
621                 [ExpectedException (typeof (ArgumentException))]
622                 public void AddPolygon_Point_2 ()
623                 {
624                         GraphicsPath gp = new GraphicsPath ();
625                         gp.AddPolygon (new Point[2] { new Point (1, 1), new Point (2, 2) });
626                 }
627
628                 [Test]
629                 public void AddPolygon_Point_3 ()
630                 {
631                         GraphicsPath gp = new GraphicsPath ();
632                         gp.AddPolygon (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
633                         CheckPolygon (gp);
634                 }
635
636                 [Test]
637                 [ExpectedException (typeof (ArgumentNullException))]
638                 public void AddPolygon_PointF_Null ()
639                 {
640                         new GraphicsPath ().AddPolygon ((PointF[]) null);
641                 }
642
643                 [Test]
644                 [ExpectedException (typeof (ArgumentException))]
645                 public void AddPolygon_PointF_Empty ()
646                 {
647                         new GraphicsPath ().AddPolygon (new PointF[0]);
648                 }
649
650                 [Test]
651                 [ExpectedException (typeof (ArgumentException))]
652                 public void AddPolygon_PointF_1 ()
653                 {
654                         GraphicsPath gp = new GraphicsPath ();
655                         gp.AddPolygon (new PointF[1] { new PointF (1f, 1f) });
656                 }
657
658                 [Test]
659                 [ExpectedException (typeof (ArgumentException))]
660                 public void AddPolygon_PointF_2 ()
661                 {
662                         GraphicsPath gp = new GraphicsPath ();
663                         gp.AddPolygon (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
664                 }
665
666                 [Test]
667                 public void AddPolygon_PointF_3 ()
668                 {
669                         GraphicsPath gp = new GraphicsPath ();
670                         gp.AddPolygon (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
671                         CheckPolygon (gp);
672                 }
673
674                 private void CheckRectangle (GraphicsPath path)
675                 {
676                         Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
677                         Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
678                         Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
679
680                         Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
681                         Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
682                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
683                         Assert.AreEqual (3f, path.PathData.Points[1].X, "Points[1].X");
684                         Assert.AreEqual (1f, path.PathPoints[1].Y, "Points[1].Y");
685                         Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
686                         Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
687                         Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
688                         Assert.AreEqual (1, path.PathData.Types[2], "Types[2]");
689                         Assert.AreEqual (1f, path.PathData.Points[3].X, "Points[3].X");
690                         Assert.AreEqual (3f, path.PathPoints[3].Y, "Points[3].Y");
691                         Assert.AreEqual (129, path.PathTypes[3], "Types[3]");
692                 }
693
694                 [Test]
695                 public void AddRectangle_Int ()
696                 {
697                         GraphicsPath gp = new GraphicsPath ();
698                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
699                         CheckRectangle (gp);
700                 }
701
702                 [Test]
703                 public void AddRectangle_Float ()
704                 {
705                         GraphicsPath gp = new GraphicsPath ();
706                         gp.AddRectangle (new RectangleF (1f, 1f, 2f, 2f));
707                         CheckRectangle (gp);
708                 }
709
710                 [Test]
711                 [ExpectedException (typeof (ArgumentNullException))]
712                 public void AddRectangles_Int_Null ()
713                 {
714                         GraphicsPath gp = new GraphicsPath ();
715                         gp.AddRectangles ((Rectangle[]) null);
716                 }
717
718                 [Test]
719                 [ExpectedException (typeof (ArgumentException))]
720                 public void AddRectangles_Int_Empty ()
721                 {
722                         GraphicsPath gp = new GraphicsPath ();
723                         gp.AddRectangles (new Rectangle[0]);
724                         CheckRectangle (gp);
725                 }
726
727                 [Test]
728                 public void AddRectangles_Int ()
729                 {
730                         GraphicsPath gp = new GraphicsPath ();
731                         gp.AddRectangles (new Rectangle[1] { new Rectangle (1, 1, 2, 2) });
732                         CheckRectangle (gp);
733                 }
734
735                 [Test]
736                 [ExpectedException (typeof (ArgumentNullException))]
737                 public void AddRectangles_Float_Null ()
738                 {
739                         GraphicsPath gp = new GraphicsPath ();
740                         gp.AddRectangles ((RectangleF[]) null);
741                 }
742
743                 [Test]
744                 [ExpectedException (typeof (ArgumentException))]
745                 public void AddRectangles_Float_Empty ()
746                 {
747                         GraphicsPath gp = new GraphicsPath ();
748                         gp.AddRectangles ( new RectangleF[0]);
749                         CheckRectangle (gp);
750                 }
751
752                 [Test]
753                 public void AddRectangles_Float ()
754                 {
755                         GraphicsPath gp = new GraphicsPath ();
756                         gp.AddRectangles (new RectangleF [1] { new RectangleF (1f, 1f, 2f, 2f) });
757                         CheckRectangle (gp);
758                 }
759
760                 [Test]
761                 [ExpectedException (typeof (ArgumentNullException))]
762                 public void AddPath_Null ()
763                 {
764                         new GraphicsPath ().AddPath (null, false);
765                 }
766
767                 [Test]
768                 public void AddPath ()
769                 {
770                         GraphicsPath gpr = new GraphicsPath ();
771                         gpr.AddRectangle (new Rectangle (1, 1, 2, 2));
772                         GraphicsPath gp = new GraphicsPath ();
773                         gp.AddPath (gpr, true);
774                         CheckRectangle (gp);
775                 }
776
777                 private void CheckClosedCurve (GraphicsPath path)
778                 {
779                         Assert.AreEqual (10, path.PathPoints.Length, "PathPoints");
780                         Assert.AreEqual (10, path.PathTypes.Length, "PathPoints");
781                         Assert.AreEqual (10, path.PathData.Points.Length, "PathData");
782 #if false
783                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
784                         RectangleF rect = path.GetBounds ();
785                         Assert.AreEqual (0.8333333f, rect.X, "Bounds.X");
786                         Assert.AreEqual (0.8333333f, rect.Y, "Bounds.Y");
787                         Assert.AreEqual (2.33333278f, rect.Width, "Bounds.Width");
788                         Assert.AreEqual (2.33333278f, rect.Height, "Bounds.Height");
789 #endif
790                         Assert.AreEqual (0, path.PathData.Types[0], "PathData.Types[0]");
791                         for (int i = 1; i < 9; i++)
792                                 Assert.AreEqual (3, path.PathTypes[i], "PathTypes" + i.ToString ());
793                         Assert.AreEqual (131, path.PathData.Types[9], "PathData.Types[9]");
794                 }
795
796                 [Test]
797                 [ExpectedException (typeof (ArgumentNullException))]
798                 public void AddClosedCurve_Point_Null ()
799                 {
800                         new GraphicsPath ().AddClosedCurve ((Point[])null);
801                 }
802
803                 [Test]
804                 [ExpectedException (typeof (ArgumentException))]
805                 public void AddClosedCurve_Point_0 ()
806                 {
807                         GraphicsPath gp = new GraphicsPath ();
808                         gp.AddClosedCurve (new Point [0]);
809                 }
810
811                 [Test]
812                 [ExpectedException (typeof (ArgumentException))]
813                 public void AddClosedCurve_Point_1 ()
814                 {
815                         GraphicsPath gp = new GraphicsPath ();
816                         gp.AddClosedCurve (new Point[1] { new Point (1, 1) });
817                 }
818
819                 [Test]
820                 [ExpectedException (typeof (ArgumentException))]
821                 public void AddClosedCurve_Point_2 ()
822                 {
823                         GraphicsPath gp = new GraphicsPath ();
824                         gp.AddClosedCurve (new Point[2] { new Point (1, 1), new Point (2, 2) });
825                 }
826
827                 [Test]
828                 public void AddClosedCurve_Point_3 ()
829                 {
830                         GraphicsPath gp = new GraphicsPath ();
831                         gp.AddClosedCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
832                         CheckClosedCurve (gp);
833                 }
834
835                 [Test]
836                 [ExpectedException (typeof (ArgumentNullException))]
837                 public void AddClosedCurve_PointF_Null ()
838                 {
839                         new GraphicsPath ().AddClosedCurve ((PointF[]) null);
840                 }
841
842                 [Test]
843                 [ExpectedException (typeof (ArgumentException))]
844                 public void AddClosedCurve_PointF_0 ()
845                 {
846                         GraphicsPath gp = new GraphicsPath ();
847                         gp.AddClosedCurve (new PointF[0]);
848                 }
849
850                 [Test]
851                 [ExpectedException (typeof (ArgumentException))]
852                 public void AddClosedCurve_PointF_1 ()
853                 {
854                         GraphicsPath gp = new GraphicsPath ();
855                         gp.AddClosedCurve (new PointF[1] { new PointF (1f, 1f) });
856                 }
857
858                 [Test]
859                 [ExpectedException (typeof (ArgumentException))]
860                 public void AddClosedCurve_PointF_2 ()
861                 {
862                         GraphicsPath gp = new GraphicsPath ();
863                         gp.AddClosedCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
864                 }
865
866                 [Test]
867                 public void AddClosedCurve_PointF_3 ()
868                 {
869                         GraphicsPath gp = new GraphicsPath ();
870                         gp.AddClosedCurve (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
871                         CheckClosedCurve (gp);
872                 }
873
874                 private void CheckCurve (GraphicsPath path)
875                 {
876                         Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
877                         Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
878                         Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
879 #if false
880                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
881                         RectangleF rect = path.GetBounds ();
882                         Assert.AreEqual (1.0f, rect.X, "Bounds.X");
883                         Assert.AreEqual (1.0f, rect.Y, "Bounds.Y");
884                         Assert.AreEqual (1.0f, rect.Width, "Bounds.Width");
885                         Assert.AreEqual (1.0f, rect.Height, "Bounds.Height");
886 #endif
887                         Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
888                         Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
889                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
890                         // Mono has wrong? results
891 #if false
892                         Assert.AreEqual (1.16666663f, path.PathData.Points[1].X, "Points[1].X");
893                         Assert.AreEqual (1.16666663f, path.PathPoints[1].Y, "Points[1].Y");
894 #endif
895                         Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
896                         // Mono has wrong? results
897 #if false
898                         Assert.AreEqual (1.83333325f, path.PathData.Points[2].X, "Points[2].X");
899                         Assert.AreEqual (1.83333325f, path.PathPoints[2].Y, "Points[2].Y");
900 #endif
901                         Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
902                         Assert.AreEqual (2f, path.PathData.Points[3].X, "Points[3].X");
903                         Assert.AreEqual (2f, path.PathPoints[3].Y, "Points[3].Y");
904                         Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
905                 }
906
907                 [Test]
908                 [ExpectedException (typeof (ArgumentNullException))]
909                 public void AddCurve_Point_Null ()
910                 {
911                         new GraphicsPath ().AddCurve ((Point[]) null);
912                 }
913
914                 [Test]
915                 [ExpectedException (typeof (ArgumentException))]
916                 public void AddCurve_Point_0 ()
917                 {
918                         GraphicsPath gp = new GraphicsPath ();
919                         gp.AddCurve (new Point[0]);
920                 }
921
922                 [Test]
923                 [ExpectedException (typeof (ArgumentException))]
924                 public void AddCurve_Point_1 ()
925                 {
926                         GraphicsPath gp = new GraphicsPath ();
927                         gp.AddCurve (new Point[1] { new Point (1, 1) });
928                 }
929
930                 [Test]
931                 public void AddCurve_Point_2 ()
932                 {
933                         GraphicsPath gp = new GraphicsPath ();
934                         gp.AddCurve (new Point[2] { new Point (1, 1), new Point (2, 2) });
935                         CheckCurve (gp);
936                 }
937
938                 [Test]
939                 [ExpectedException (typeof (ArgumentNullException))]
940                 public void AddCurve_PointF_Null ()
941                 {
942                         new GraphicsPath ().AddCurve ((PointF[]) null);
943                 }
944
945                 [Test]
946                 [ExpectedException (typeof (ArgumentException))]
947                 public void AddCurve_PointF_0 ()
948                 {
949                         GraphicsPath gp = new GraphicsPath ();
950                         gp.AddCurve (new PointF[0]);
951                 }
952
953                 [Test]
954                 [ExpectedException (typeof (ArgumentException))]
955                 public void AddCurve_PointF_1 ()
956                 {
957                         GraphicsPath gp = new GraphicsPath ();
958                         gp.AddCurve (new PointF[1] { new PointF (1f, 1f) });
959                 }
960
961                 [Test]
962                 public void AddCurve_PointF_2 ()
963                 {
964                         GraphicsPath gp = new GraphicsPath ();
965                         gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
966                         CheckCurve (gp);
967                 }
968
969                 [Test]
970                 [ExpectedException (typeof (ArgumentNullException))]
971                 public void Transform_Null ()
972                 {
973                         new GraphicsPath ().Transform (null);
974                 }
975
976                 [Test]
977                 [Category ("NotWorking")]
978                 public void Flatten_Null ()
979                 {
980                         new GraphicsPath ().Flatten (null);
981                         // no ArgumentNullException or NullReferenceException
982                 }
983
984                 [Test]
985                 [Category ("NotWorking")]
986                 public void Flatten_NullFloat ()
987                 {
988                         new GraphicsPath ().Flatten (null, 1f);
989                         // no ArgumentNullException or NullReferenceException
990                 }
991
992                 [Test]
993                 [ExpectedException (typeof (ArgumentNullException))]
994                 public void Warp_Null ()
995                 {
996                         new GraphicsPath ().Warp (null, new RectangleF ());
997                 }
998         }
999 }