138572d66483b7986c6222edee573bc99960f64f
[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                 // let's tolerate a few differences
44                 private const float Delta = 0.0003f;
45
46                 private void CheckEmpty (string prefix, GraphicsPath gp)
47                 {
48                         Assert.AreEqual (0, gp.PathData.Points.Length, "PathData.Points");
49                         Assert.AreEqual (0, gp.PathData.Types.Length, "PathData.Types");
50                         Assert.AreEqual (0, gp.PointCount, prefix + "PointCount");
51                 }
52
53                 [Test]
54                 public void Constructor_InvalidFillMode ()
55                 {
56                         GraphicsPath gp = new GraphicsPath ((FillMode) Int32.MinValue);
57                         Assert.AreEqual (Int32.MinValue, (int) gp.FillMode, "FillMode");
58                         CheckEmpty ("InvalidFillMode.", gp);
59                 }
60
61                 [Test]
62                 [ExpectedException (typeof (ArgumentNullException))]
63                 public void Constructor_Point_Null_Byte ()
64                 {
65                         new GraphicsPath ((Point[]) null, new byte[1]);
66                 }
67
68                 [Test]
69                 [ExpectedException (typeof (NullReferenceException))]
70                 public void Constructor_Point_Byte_Null ()
71                 {
72                         new GraphicsPath (new Point[1], null);
73                 }
74
75                 [Test]
76                 [ExpectedException (typeof (ArgumentException))]
77                 public void Constructor_Point_Byte_LengthMismatch ()
78                 {
79                         new GraphicsPath (new Point[1], new byte [2]);
80                 }
81
82                 [Test]
83                 [ExpectedException (typeof (ArgumentNullException))]
84                 public void Constructor_PointF_Null_Byte ()
85                 {
86                         new GraphicsPath ((PointF[])null, new byte [1]);
87                 }
88
89                 [Test]
90                 [ExpectedException (typeof (NullReferenceException))]
91                 public void Constructor_PointF_Byte_Null ()
92                 {
93                         new GraphicsPath ( new PointF[1], null);
94                 }
95
96                 [Test]
97                 [ExpectedException (typeof (ArgumentException))]
98                 public void Constructor_PointF_Byte_LengthMismatch ()
99                 {
100                         new GraphicsPath (new PointF[2], new byte [1]);
101                 }
102
103                 [Test]
104                 public void GraphicsPath_Empty ()
105                 {
106                         GraphicsPath gp = new GraphicsPath ();
107                         Assert.AreEqual (FillMode.Alternate, gp.FillMode, "Empty.FillMode");
108                         CheckEmpty ("Empty.", gp);
109
110                         GraphicsPath clone = (GraphicsPath) gp.Clone ();
111                         Assert.AreEqual (FillMode.Alternate, gp.FillMode, "Clone.FillMode");
112                         CheckEmpty ("Clone.", gp);
113                 }
114
115                 [Test]
116                 [ExpectedException (typeof (ArgumentException))]
117                 public void GraphicsPath_Empty_PathPoints ()
118                 {
119                         Assert.IsNull (new GraphicsPath ().PathPoints);
120                 }
121
122                 [Test]
123                 [ExpectedException (typeof (ArgumentException))]
124                 public void GraphicsPath_Empty_PathTypes ()
125                 {
126                         Assert.IsNull (new GraphicsPath ().PathTypes);
127                 }
128
129                 [Test]
130                 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
131                 public void FillMode_Invalid ()
132                 {
133                         // constructor accept an invalid FillMode
134                         GraphicsPath gp = new GraphicsPath ((FillMode) Int32.MaxValue);
135                         Assert.AreEqual (Int32.MaxValue, (int) gp.FillMode, "MaxValue");
136                         // but you can't set the FillMode property to an invalid value ;-)
137                         gp.FillMode = (FillMode) Int32.MaxValue;
138                 }
139
140                 [Test]
141                 public void PathData_CannotChange ()
142                 {
143                         GraphicsPath gp = new GraphicsPath ();
144                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
145
146                         Assert.AreEqual (1f, gp.PathData.Points[0].X, "Points[0].X");
147                         Assert.AreEqual (1f, gp.PathData.Points[0].Y, "Points[0].Y");
148
149                         // now try to change the first point
150                         gp.PathData.Points[0] = new Point (0, 0);
151                         // the changes isn't reflected in the property
152                         Assert.AreEqual (1f, gp.PathData.Points[0].X, "Points[0].X-1");
153                         Assert.AreEqual (1f, gp.PathData.Points[0].Y, "Points[0].Y-1");
154                 }
155
156                 [Test]
157                 public void PathPoints_CannotChange ()
158                 {
159                         GraphicsPath gp = new GraphicsPath ();
160                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
161
162                         Assert.AreEqual (1f, gp.PathPoints[0].X, "PathPoints[0].X");
163                         Assert.AreEqual (1f, gp.PathPoints[0].Y, "PathPoints[0].Y");
164
165                         // now try to change the first point
166                         gp.PathPoints[0] = new Point (0, 0);
167                         // the changes isn't reflected in the property
168                         Assert.AreEqual (1f, gp.PathPoints[0].X, "PathPoints[0].X-1");
169                         Assert.AreEqual (1f, gp.PathPoints[0].Y, "PathPoints[0].Y-1");
170                 }
171
172                 [Test]
173                 public void PathTypes_CannotChange ()
174                 {
175                         GraphicsPath gp = new GraphicsPath ();
176                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
177
178                         Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
179
180                         // now try to change the first type
181                         gp.PathTypes[0] = 1;
182                         // the changes isn't reflected in the property
183                         Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]-1");
184                 }
185
186                 private void CheckArc (GraphicsPath path)
187                 {
188                         Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
189                         Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
190                         Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
191
192                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
193                         RectangleF rect = path.GetBounds ();
194                         Assert.AreEqual (2.999624f, rect.X, "Bounds.X");
195                         Assert.AreEqual (2.013707f, rect.Y, "Bounds.Y");
196                         Assert.AreEqual (0f, rect.Width, Delta, "Bounds.Width");
197                         Assert.AreEqual (0.01370478f, rect.Height, "Bounds.Height");
198
199                         Assert.AreEqual (2.999906f, path.PathData.Points[0].X, "Points[0].X");
200                         Assert.AreEqual (2.013707f, path.PathPoints[0].Y, "Points[0].Y");
201                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
202                         Assert.AreEqual (2.999843f, path.PathData.Points[1].X, "Points[1].X");
203                         Assert.AreEqual (2.018276f, path.PathPoints[1].Y, "Points[1].Y");
204                         Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
205                         Assert.AreEqual (2.99974918f, path.PathData.Points[2].X, "Points[2].X");
206                         Assert.AreEqual (2.02284455f, path.PathPoints[2].Y, "Points[2].Y");
207                         Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
208                         Assert.AreEqual (2.999624f, path.PathData.Points[3].X, "Points[3].X");
209                         Assert.AreEqual (2.027412f, path.PathPoints[3].Y, "Points[3].Y");
210                         Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
211                 }
212
213                 [Test]
214                 public void AddArc_Rectangle ()
215                 {
216                         GraphicsPath gp = new GraphicsPath ();
217                         gp.AddArc (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
218                         CheckArc (gp);
219                 }
220
221                 [Test]
222                 public void AddArc_RectangleF ()
223                 {
224                         GraphicsPath gp = new GraphicsPath ();
225                         gp.AddArc (new RectangleF (1f, 1f, 2f, 2f), Pi4, Pi4);
226                         CheckArc (gp);
227                 }
228
229                 [Test]
230                 public void AddArc_Int ()
231                 {
232                         GraphicsPath gp = new GraphicsPath ();
233                         gp.AddArc (1, 1, 2, 2, Pi4, Pi4);
234                         CheckArc (gp);
235                 }
236
237                 [Test]
238                 public void AddArc_Float ()
239                 {
240                         GraphicsPath gp = new GraphicsPath ();
241                         gp.AddArc (1f, 1f, 2f, 2f, Pi4, Pi4);
242                         CheckArc (gp);
243                 }
244
245                 private void CheckBezier (GraphicsPath path)
246                 {
247                         Assert.AreEqual (4, path.PointCount, "PointCount");
248                         Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
249                         Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
250                         Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
251
252                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
253                         RectangleF rect = path.GetBounds ();
254                         Assert.AreEqual (1f, rect.X, "Bounds.X");
255                         Assert.AreEqual (1f, rect.Y, "Bounds.Y");
256                         Assert.AreEqual (3f, rect.Width, "Bounds.Width");
257                         Assert.AreEqual (3f, rect.Height, "Bounds.Height");
258
259                         Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
260                         Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
261                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
262                         Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
263                         Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
264                         Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
265                         Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
266                         Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
267                         Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
268                         Assert.AreEqual (4f, path.PathData.Points[3].X, "Points[3].X");
269                         Assert.AreEqual (4f, path.PathPoints[3].Y, "Points[3].Y");
270                         Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
271                 }
272
273                 [Test]
274                 public void AddBezier_Point ()
275                 {
276                         GraphicsPath gp = new GraphicsPath ();
277                         gp.AddBezier (new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4));
278                         CheckBezier (gp);
279                 }
280
281                 [Test]
282                 public void AddBezier_PointF ()
283                 {
284                         GraphicsPath gp = new GraphicsPath ();
285                         gp.AddBezier (new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f));
286                         CheckBezier (gp);
287                 }
288
289                 [Test]
290                 public void AddBezier_Int ()
291                 {
292                         GraphicsPath gp = new GraphicsPath ();
293                         gp.AddBezier (1, 1, 2, 2, 3, 3, 4, 4);
294                         CheckBezier (gp);
295                 }
296
297                 [Test]
298                 public void AddBezier_Float ()
299                 {
300                         GraphicsPath gp = new GraphicsPath ();
301                         gp.AddBezier (1f, 1f, 2f, 2f, 3f, 3f, 4f, 4f);
302                         CheckBezier (gp);
303                 }
304
305                 [Test]
306                 [ExpectedException (typeof (ArgumentNullException))]
307                 public void AddBeziers_Point_Null ()
308                 {
309                         new GraphicsPath ().AddBeziers ((Point[]) null);
310                 }
311
312                 [Test]
313                 [ExpectedException (typeof (ArgumentException))]
314                 public void AddBeziers_3_Points ()
315                 {
316                         GraphicsPath gp = new GraphicsPath ();
317                         gp.AddBeziers (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
318                 }
319
320                 [Test]
321                 public void AddBeziers_Point ()
322                 {
323                         GraphicsPath gp = new GraphicsPath ();
324                         gp.AddBeziers (new Point[4] { new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4) });
325                         CheckBezier (gp);
326                 }
327
328                 [Test]
329                 [ExpectedException (typeof (ArgumentNullException))]
330                 public void AddBeziers_PointF_Null ()
331                 {
332                         new GraphicsPath ().AddBeziers ((PointF[]) null);
333                 }
334
335                 [Test]
336                 [ExpectedException (typeof (ArgumentException))]
337                 public void AddBeziers_3_PointFs ()
338                 {
339                         GraphicsPath gp = new GraphicsPath ();
340                         gp.AddBeziers (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
341                 }
342
343                 [Test]
344                 public void AddBeziers_PointF ()
345                 {
346                         GraphicsPath gp = new GraphicsPath ();
347                         gp.AddBeziers (new PointF[4] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f) });
348                         CheckBezier (gp);
349                 }
350
351                 private void CheckEllipse (GraphicsPath path)
352                 {
353                         Assert.AreEqual (13, path.PathPoints.Length, "PathPoints");
354                         Assert.AreEqual (13, path.PathTypes.Length, "PathPoints");
355                         Assert.AreEqual (13, path.PathData.Points.Length, "PathData");
356
357                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
358                         RectangleF rect = path.GetBounds ();
359                         Assert.AreEqual (1f, rect.X, "Bounds.X");
360                         Assert.AreEqual (1f, rect.Y, "Bounds.Y");
361                         Assert.AreEqual (2f, rect.Width, "Bounds.Width");
362                         Assert.AreEqual (2f, rect.Height, "Bounds.Height");
363
364                         Assert.AreEqual (0, path.PathData.Types[0], "PathData.Types[0]");
365                         for (int i = 1; i < 12; i++)
366                                 Assert.AreEqual (3, path.PathTypes[i], "PathTypes" + i.ToString ());
367                         Assert.AreEqual (131, path.PathData.Types[12], "PathData.Types[12]");
368                 }
369
370                 [Test]
371                 public void AddEllipse_Rectangle ()
372                 {
373                         GraphicsPath gp = new GraphicsPath ();
374                         gp.AddEllipse (new Rectangle (1, 1, 2, 2));
375                         CheckEllipse (gp);
376                 }
377
378                 [Test]
379                 public void AddEllipse_RectangleF ()
380                 {
381                         GraphicsPath gp = new GraphicsPath ();
382                         gp.AddEllipse (new RectangleF (1f, 1f, 2f, 2f));
383                         CheckEllipse (gp);
384                 }
385
386                 [Test]
387                 public void AddEllipse_Int ()
388                 {
389                         GraphicsPath gp = new GraphicsPath ();
390                         gp.AddEllipse (1, 1, 2, 2);
391                         CheckEllipse (gp);
392                 }
393
394                 [Test]
395                 public void AddEllipse_Float ()
396                 {
397                         GraphicsPath gp = new GraphicsPath ();
398                         gp.AddEllipse (1f, 1f, 2f, 2f);
399                         CheckEllipse (gp);
400                 }
401
402                 private void CheckLine (GraphicsPath path)
403                 {
404                         Assert.AreEqual (2, path.PathPoints.Length, "PathPoints");
405                         Assert.AreEqual (2, path.PathTypes.Length, "PathPoints");
406                         Assert.AreEqual (2, path.PathData.Points.Length, "PathData");
407
408                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
409                         RectangleF rect = path.GetBounds ();
410                         Assert.AreEqual (1f, rect.X, "Bounds.X");
411                         Assert.AreEqual (1f, rect.Y, "Bounds.Y");
412                         Assert.AreEqual (1f, rect.Width, "Bounds.Width");
413                         Assert.AreEqual (1f, rect.Height, "Bounds.Height");
414
415                         Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
416                         Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
417                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
418                         Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
419                         Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
420                         Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
421                 }
422
423                 [Test]
424                 public void AddLine_Point ()
425                 {
426                         GraphicsPath gp = new GraphicsPath ();
427                         gp.AddLine (new Point (1, 1), new Point (2, 2));
428                         CheckLine (gp);
429                 }
430
431                 [Test]
432                 public void AddLine_PointF ()
433                 {
434                         GraphicsPath gp = new GraphicsPath ();
435                         gp.AddLine (new PointF (1f, 1f), new PointF (2f, 2f));
436                         CheckLine (gp);
437                 }
438
439                 [Test]
440                 public void AddLine_Int ()
441                 {
442                         GraphicsPath gp = new GraphicsPath ();
443                         gp.AddLine (1, 1, 2, 2);
444                         CheckLine (gp);
445                 }
446
447                 [Test]
448                 public void AddLine_Float ()
449                 {
450                         GraphicsPath gp = new GraphicsPath ();
451                         gp.AddLine (1f, 1f, 2f, 2f);
452                         CheckLine (gp);
453                 }
454
455                 [Test]
456                 public void AddLine_SamePoint ()
457                 {
458                         GraphicsPath gp = new GraphicsPath ();
459                         gp.AddLine (new Point (1, 1), new Point (1, 1));
460                         Assert.AreEqual (2, gp.PointCount, "PointCount");
461                         Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
462                         Assert.AreEqual (1, gp.PathTypes[1], "PathTypes[1]");
463                 }
464
465                 [Test]
466                 [ExpectedException (typeof (ArgumentNullException))]
467                 public void AddLines_Point_Null ()
468                 {
469                         new GraphicsPath ().AddLines ((Point[])null);
470                 }
471
472                 [Test]
473                 [ExpectedException (typeof (ArgumentException))]
474                 public void AddLines_Point_0 ()
475                 {
476                         GraphicsPath gp = new GraphicsPath ();
477                         gp.AddLines (new Point[0]);
478                         CheckLine (gp);
479                 }
480
481                 [Test]
482                 [Category ("NotWorking")]
483                 public void AddLines_Point_1 ()
484                 {
485                         GraphicsPath gp = new GraphicsPath ();
486                         gp.AddLines (new Point[1] { new Point (1, 1) });
487                         // Special case - a line with a single point is valid
488                         Assert.AreEqual (1, gp.PointCount, "PointCount");
489                         Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
490                 }
491
492                 [Test]
493                 public void AddLines_Point ()
494                 {
495                         GraphicsPath gp = new GraphicsPath ();
496                         gp.AddLines (new Point[2] { new Point (1, 1), new Point (2, 2) });
497                         CheckLine (gp);
498                 }
499
500                 [Test]
501                 [ExpectedException (typeof (ArgumentNullException))]
502                 public void AddLines_PointF_Null ()
503                 {
504                         new GraphicsPath ().AddLines ((PointF[]) null);
505                 }
506
507                 [Test]
508                 [ExpectedException (typeof (ArgumentException))]
509                 public void AddLines_PointF_0 ()
510                 {
511                         GraphicsPath gp = new GraphicsPath ();
512                         gp.AddLines (new PointF[0]);
513                         CheckLine (gp);
514                 }
515
516                 [Test]
517                 [Category ("NotWorking")]
518                 public void AddLines_PointF_1 ()
519                 {
520                         GraphicsPath gp = new GraphicsPath ();
521                         gp.AddLines (new PointF[1] { new PointF (1f, 1f) });
522                         // Special case - a line with a single point is valid
523                         Assert.AreEqual (1, gp.PointCount, "PointCount");
524                         Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
525                 }
526
527                 [Test]
528                 public void AddLines_PointF ()
529                 {
530                         GraphicsPath gp = new GraphicsPath ();
531                         gp.AddLines (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
532                         CheckLine (gp);
533                 }
534
535                 private void CheckPie (GraphicsPath path)
536                 {
537                         // the number of points generated for a Pie isn't the same between Mono and MS
538 #if false
539                         Assert.AreEqual (5, path.PathPoints.Length, "PathPoints");
540                         Assert.AreEqual (5, path.PathTypes.Length, "PathPoints");
541                         Assert.AreEqual (5, path.PathData.Points.Length, "PathData");
542
543                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
544                         RectangleF rect = path.GetBounds ();
545                         Assert.AreEqual (2f, rect.X, "Bounds.X");
546                         Assert.AreEqual (2f, rect.Y, "Bounds.Y");
547                         Assert.AreEqual (0.9999058f, rect.Width, "Bounds.Width");
548                         Assert.AreEqual (0.0274119377f, rect.Height, "Bounds.Height");
549
550                         Assert.AreEqual (2f, path.PathData.Points[0].X, "Points[0].X");
551                         Assert.AreEqual (2f, path.PathPoints[0].Y, "Points[0].Y");
552                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
553                         Assert.AreEqual (2.99990582f, path.PathData.Points[1].X, "Points[1].X");
554                         Assert.AreEqual (2.01370716f, path.PathPoints[1].Y, "Points[1].Y");
555                         Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
556                         Assert.AreEqual (2.99984312f, path.PathData.Points[2].X, "Points[2].X");
557                         Assert.AreEqual (2.018276f, path.PathPoints[2].Y, "Points[2].Y");
558                         Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
559                         Assert.AreEqual (2.99974918f, path.PathData.Points[3].X, "Points[2].X");
560                         Assert.AreEqual (2.02284455f, path.PathPoints[3].Y, "Points[2].Y");
561                         Assert.AreEqual (3, path.PathData.Types[3], "Types[2]");
562                         Assert.AreEqual (2.999624f, path.PathData.Points[4].X, "Points[3].X");
563                         Assert.AreEqual (2.027412f, path.PathPoints[4].Y, "Points[3].Y");
564                         Assert.AreEqual (131, path.PathTypes[4], "Types[3]");
565 #endif
566                 }
567
568                 [Test]
569                 public void AddPie_Rect ()
570                 {
571                         GraphicsPath gp = new GraphicsPath ();
572                         gp.AddPie (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
573                         CheckPie (gp);
574                 }
575
576                 [Test]
577                 public void AddPie_Int ()
578                 {
579                         GraphicsPath gp = new GraphicsPath ();
580                         gp.AddPie (1, 1, 2, 2, Pi4, Pi4);
581                         CheckPie (gp);
582                 }
583
584                 [Test]
585                 public void AddPie_Float ()
586                 {
587                         GraphicsPath gp = new GraphicsPath ();
588                         gp.AddPie (1f, 1f, 2f, 2f, Pi4, Pi4);
589                         CheckPie (gp);
590                 }
591
592                 private void CheckPolygon (GraphicsPath path)
593                 {
594                         // an extra point is generated by Mono (libgdiplus)
595 #if false
596                         Assert.AreEqual (3, path.PathPoints.Length, "PathPoints");
597                         Assert.AreEqual (3, path.PathTypes.Length, "PathPoints");
598                         Assert.AreEqual (3, path.PathData.Points.Length, "PathData");
599 #endif
600                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
601                         RectangleF rect = path.GetBounds ();
602                         Assert.AreEqual (1f, rect.X, "Bounds.X");
603                         Assert.AreEqual (1f, rect.Y, "Bounds.Y");
604                         Assert.AreEqual (2f, rect.Width, "Bounds.Width");
605                         Assert.AreEqual (2f, rect.Height, "Bounds.Height");
606
607                         Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
608                         Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
609                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
610                         Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
611                         Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
612                         Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
613                         Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
614                         Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
615                         // the extra point change the type of the last point
616 #if false
617                         Assert.AreEqual (129, path.PathData.Types[2], "Types[2]");
618 #endif
619                 }
620
621                 [Test]
622                 [ExpectedException (typeof (ArgumentNullException))]
623                 public void AddPolygon_Point_Null ()
624                 {
625                         new GraphicsPath ().AddPolygon ((Point[]) null);
626                 }
627
628                 [Test]
629                 [ExpectedException (typeof (ArgumentException))]
630                 public void AddPolygon_Point_Empty ()
631                 {
632                         new GraphicsPath ().AddPolygon (new Point[0]);
633                 }
634
635                 [Test]
636                 [ExpectedException (typeof (ArgumentException))]
637                 public void AddPolygon_Point_1 ()
638                 {
639                         GraphicsPath gp = new GraphicsPath ();
640                         gp.AddPolygon (new Point[1] { new Point (1, 1) });
641                 }
642
643                 [Test]
644                 [ExpectedException (typeof (ArgumentException))]
645                 public void AddPolygon_Point_2 ()
646                 {
647                         GraphicsPath gp = new GraphicsPath ();
648                         gp.AddPolygon (new Point[2] { new Point (1, 1), new Point (2, 2) });
649                 }
650
651                 [Test]
652                 public void AddPolygon_Point_3 ()
653                 {
654                         GraphicsPath gp = new GraphicsPath ();
655                         gp.AddPolygon (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
656                         CheckPolygon (gp);
657                 }
658
659                 [Test]
660                 [ExpectedException (typeof (ArgumentNullException))]
661                 public void AddPolygon_PointF_Null ()
662                 {
663                         new GraphicsPath ().AddPolygon ((PointF[]) null);
664                 }
665
666                 [Test]
667                 [ExpectedException (typeof (ArgumentException))]
668                 public void AddPolygon_PointF_Empty ()
669                 {
670                         new GraphicsPath ().AddPolygon (new PointF[0]);
671                 }
672
673                 [Test]
674                 [ExpectedException (typeof (ArgumentException))]
675                 public void AddPolygon_PointF_1 ()
676                 {
677                         GraphicsPath gp = new GraphicsPath ();
678                         gp.AddPolygon (new PointF[1] { new PointF (1f, 1f) });
679                 }
680
681                 [Test]
682                 [ExpectedException (typeof (ArgumentException))]
683                 public void AddPolygon_PointF_2 ()
684                 {
685                         GraphicsPath gp = new GraphicsPath ();
686                         gp.AddPolygon (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
687                 }
688
689                 [Test]
690                 public void AddPolygon_PointF_3 ()
691                 {
692                         GraphicsPath gp = new GraphicsPath ();
693                         gp.AddPolygon (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
694                         CheckPolygon (gp);
695                 }
696
697                 private void CheckRectangle (GraphicsPath path, int count)
698                 {
699                         Assert.AreEqual (count, path.PathPoints.Length, "PathPoints");
700                         Assert.AreEqual (count, path.PathTypes.Length, "PathPoints");
701                         Assert.AreEqual (count, path.PathData.Points.Length, "PathData");
702
703                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
704                         RectangleF rect = path.GetBounds ();
705                         Assert.AreEqual (1f, rect.X, "Bounds.X");
706                         Assert.AreEqual (1f, rect.Y, "Bounds.Y");
707                         Assert.AreEqual (2f, rect.Width, "Bounds.Width");
708                         Assert.AreEqual (2f, rect.Height, "Bounds.Height");
709
710                         // check first four points (first rectangle)
711                         Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
712                         Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
713                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
714                         Assert.AreEqual (3f, path.PathData.Points[1].X, "Points[1].X");
715                         Assert.AreEqual (1f, path.PathPoints[1].Y, "Points[1].Y");
716                         Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
717                         Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
718                         Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
719                         Assert.AreEqual (1, path.PathData.Types[2], "Types[2]");
720                         Assert.AreEqual (1f, path.PathData.Points[3].X, "Points[3].X");
721                         Assert.AreEqual (3f, path.PathPoints[3].Y, "Points[3].Y");
722                         Assert.AreEqual (129, path.PathTypes[3], "Types[3]");
723                 }
724
725                 [Test]
726                 public void AddRectangle_Int ()
727                 {
728                         GraphicsPath gp = new GraphicsPath ();
729                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
730                         CheckRectangle (gp, 4);
731                 }
732
733                 [Test]
734                 public void AddRectangle_Float ()
735                 {
736                         GraphicsPath gp = new GraphicsPath ();
737                         gp.AddRectangle (new RectangleF (1f, 1f, 2f, 2f));
738                         CheckRectangle (gp, 4);
739                 }
740
741                 [Test]
742                 [ExpectedException (typeof (ArgumentNullException))]
743                 public void AddRectangles_Int_Null ()
744                 {
745                         GraphicsPath gp = new GraphicsPath ();
746                         gp.AddRectangles ((Rectangle[]) null);
747                 }
748
749                 [Test]
750                 [ExpectedException (typeof (ArgumentException))]
751                 public void AddRectangles_Int_Empty ()
752                 {
753                         GraphicsPath gp = new GraphicsPath ();
754                         gp.AddRectangles (new Rectangle[0]);
755                         CheckRectangle (gp, 4);
756                 }
757
758                 [Test]
759                 public void AddRectangles_Int ()
760                 {
761                         GraphicsPath gp = new GraphicsPath ();
762                         gp.AddRectangles (new Rectangle[1] { new Rectangle (1, 1, 2, 2) });
763                         CheckRectangle (gp, 4);
764                 }
765
766                 [Test]
767                 [ExpectedException (typeof (ArgumentNullException))]
768                 public void AddRectangles_Float_Null ()
769                 {
770                         GraphicsPath gp = new GraphicsPath ();
771                         gp.AddRectangles ((RectangleF[]) null);
772                 }
773
774                 [Test]
775                 [ExpectedException (typeof (ArgumentException))]
776                 public void AddRectangles_Float_Empty ()
777                 {
778                         GraphicsPath gp = new GraphicsPath ();
779                         gp.AddRectangles ( new RectangleF[0]);
780                         CheckRectangle (gp, 4);
781                 }
782
783                 [Test]
784                 public void AddRectangles_Float ()
785                 {
786                         GraphicsPath gp = new GraphicsPath ();
787                         gp.AddRectangles (new RectangleF [1] { new RectangleF (1f, 1f, 2f, 2f) });
788                         CheckRectangle (gp, 4);
789                 }
790
791                 [Test]
792                 public void AddRectangles_Two ()
793                 {
794                         GraphicsPath gp = new GraphicsPath ();
795                         gp.AddRectangles (new RectangleF[2] {
796                                 new RectangleF (1f, 1f, 2f, 2f),
797                                 new RectangleF (2f, 2f, 1f, 1f) } );
798                         RectangleF rect = gp.GetBounds ();
799                         Assert.AreEqual (1f, rect.X, "Bounds.X");
800                         Assert.AreEqual (1f, rect.Y, "Bounds.Y");
801                         Assert.AreEqual (2f, rect.Width, "Bounds.Width");
802                         Assert.AreEqual (2f, rect.Height, "Bounds.Height");
803                         // second rectangle is completely within the first one
804                         CheckRectangle (gp, 8);
805                 }
806
807                 [Test]
808                 [ExpectedException (typeof (ArgumentNullException))]
809                 public void AddPath_Null ()
810                 {
811                         new GraphicsPath ().AddPath (null, false);
812                 }
813
814                 [Test]
815                 public void AddPath ()
816                 {
817                         GraphicsPath gpr = new GraphicsPath ();
818                         gpr.AddRectangle (new Rectangle (1, 1, 2, 2));
819                         GraphicsPath gp = new GraphicsPath ();
820                         gp.AddPath (gpr, true);
821                         CheckRectangle (gp, 4);
822                 }
823
824                 private void CheckClosedCurve (GraphicsPath path)
825                 {
826                         Assert.AreEqual (10, path.PathPoints.Length, "PathPoints");
827                         Assert.AreEqual (10, path.PathTypes.Length, "PathPoints");
828                         Assert.AreEqual (10, path.PathData.Points.Length, "PathData");
829
830                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
831                         RectangleF rect = path.GetBounds ();
832                         Assert.AreEqual (0.8333333f, rect.X, "Bounds.X");
833                         Assert.AreEqual (0.8333333f, rect.Y, "Bounds.Y");
834                         Assert.AreEqual (2.33333278f, rect.Width, "Bounds.Width");
835                         Assert.AreEqual (2.33333278f, rect.Height, "Bounds.Height");
836
837                         Assert.AreEqual (0, path.PathData.Types[0], "PathData.Types[0]");
838                         for (int i = 1; i < 9; i++)
839                                 Assert.AreEqual (3, path.PathTypes[i], "PathTypes" + i.ToString ());
840                         Assert.AreEqual (131, path.PathData.Types[9], "PathData.Types[9]");
841                 }
842
843                 [Test]
844                 [ExpectedException (typeof (ArgumentNullException))]
845                 public void AddClosedCurve_Point_Null ()
846                 {
847                         new GraphicsPath ().AddClosedCurve ((Point[])null);
848                 }
849
850                 [Test]
851                 [ExpectedException (typeof (ArgumentException))]
852                 public void AddClosedCurve_Point_0 ()
853                 {
854                         GraphicsPath gp = new GraphicsPath ();
855                         gp.AddClosedCurve (new Point [0]);
856                 }
857
858                 [Test]
859                 [ExpectedException (typeof (ArgumentException))]
860                 public void AddClosedCurve_Point_1 ()
861                 {
862                         GraphicsPath gp = new GraphicsPath ();
863                         gp.AddClosedCurve (new Point[1] { new Point (1, 1) });
864                 }
865
866                 [Test]
867                 [ExpectedException (typeof (ArgumentException))]
868                 public void AddClosedCurve_Point_2 ()
869                 {
870                         GraphicsPath gp = new GraphicsPath ();
871                         gp.AddClosedCurve (new Point[2] { new Point (1, 1), new Point (2, 2) });
872                 }
873
874                 [Test]
875                 public void AddClosedCurve_Point_3 ()
876                 {
877                         GraphicsPath gp = new GraphicsPath ();
878                         gp.AddClosedCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
879                         CheckClosedCurve (gp);
880                 }
881
882                 [Test]
883                 [ExpectedException (typeof (ArgumentNullException))]
884                 public void AddClosedCurve_PointF_Null ()
885                 {
886                         new GraphicsPath ().AddClosedCurve ((PointF[]) null);
887                 }
888
889                 [Test]
890                 [ExpectedException (typeof (ArgumentException))]
891                 public void AddClosedCurve_PointF_0 ()
892                 {
893                         GraphicsPath gp = new GraphicsPath ();
894                         gp.AddClosedCurve (new PointF[0]);
895                 }
896
897                 [Test]
898                 [ExpectedException (typeof (ArgumentException))]
899                 public void AddClosedCurve_PointF_1 ()
900                 {
901                         GraphicsPath gp = new GraphicsPath ();
902                         gp.AddClosedCurve (new PointF[1] { new PointF (1f, 1f) });
903                 }
904
905                 [Test]
906                 [ExpectedException (typeof (ArgumentException))]
907                 public void AddClosedCurve_PointF_2 ()
908                 {
909                         GraphicsPath gp = new GraphicsPath ();
910                         gp.AddClosedCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
911                 }
912
913                 [Test]
914                 public void AddClosedCurve_PointF_3 ()
915                 {
916                         GraphicsPath gp = new GraphicsPath ();
917                         gp.AddClosedCurve (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
918                         CheckClosedCurve (gp);
919                 }
920
921                 private void CheckCurve (GraphicsPath path)
922                 {
923                         Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
924                         Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
925                         Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
926
927                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
928                         RectangleF rect = path.GetBounds ();
929                         Assert.AreEqual (1.0f, rect.X, "Bounds.X");
930                         Assert.AreEqual (1.0f, rect.Y, "Bounds.Y");
931                         Assert.AreEqual (1.0f, rect.Width, "Bounds.Width");
932                         Assert.AreEqual (1.0f, rect.Height, "Bounds.Height");
933
934                         Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
935                         Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
936                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
937                         // Mono has wrong? results
938 #if false
939                         Assert.AreEqual (1.16666663f, path.PathData.Points[1].X, "Points[1].X");
940                         Assert.AreEqual (1.16666663f, path.PathPoints[1].Y, "Points[1].Y");
941 #endif
942                         Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
943                         // Mono has wrong? results
944 #if false
945                         Assert.AreEqual (1.83333325f, path.PathData.Points[2].X, "Points[2].X");
946                         Assert.AreEqual (1.83333325f, path.PathPoints[2].Y, "Points[2].Y");
947 #endif
948                         Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
949                         Assert.AreEqual (2f, path.PathData.Points[3].X, "Points[3].X");
950                         Assert.AreEqual (2f, path.PathPoints[3].Y, "Points[3].Y");
951                         Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
952                 }
953
954                 [Test]
955                 [ExpectedException (typeof (ArgumentNullException))]
956                 public void AddCurve_Point_Null ()
957                 {
958                         new GraphicsPath ().AddCurve ((Point[]) null);
959                 }
960
961                 [Test]
962                 [ExpectedException (typeof (ArgumentException))]
963                 public void AddCurve_Point_0 ()
964                 {
965                         GraphicsPath gp = new GraphicsPath ();
966                         gp.AddCurve (new Point[0]);
967                 }
968
969                 [Test]
970                 [ExpectedException (typeof (ArgumentException))]
971                 public void AddCurve_Point_1 ()
972                 {
973                         GraphicsPath gp = new GraphicsPath ();
974                         gp.AddCurve (new Point[1] { new Point (1, 1) });
975                 }
976
977                 [Test]
978                 public void AddCurve_Point_2 ()
979                 {
980                         GraphicsPath gp = new GraphicsPath ();
981                         gp.AddCurve (new Point[2] { new Point (1, 1), new Point (2, 2) });
982                         CheckCurve (gp);
983                 }
984
985                 [Test]
986                 [ExpectedException (typeof (ArgumentNullException))]
987                 public void AddCurve_PointF_Null ()
988                 {
989                         new GraphicsPath ().AddCurve ((PointF[]) null);
990                 }
991
992                 [Test]
993                 [ExpectedException (typeof (ArgumentException))]
994                 public void AddCurve_PointF_0 ()
995                 {
996                         GraphicsPath gp = new GraphicsPath ();
997                         gp.AddCurve (new PointF[0]);
998                 }
999
1000                 [Test]
1001                 [ExpectedException (typeof (ArgumentException))]
1002                 public void AddCurve_PointF_1 ()
1003                 {
1004                         GraphicsPath gp = new GraphicsPath ();
1005                         gp.AddCurve (new PointF[1] { new PointF (1f, 1f) });
1006                 }
1007
1008                 [Test]
1009                 public void AddCurve_PointF_2 ()
1010                 {
1011                         GraphicsPath gp = new GraphicsPath ();
1012                         gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
1013                         CheckCurve (gp);
1014                 }
1015
1016                 [Test]
1017                 [ExpectedException (typeof (NullReferenceException))]
1018                 public void AddString_NullString ()
1019                 {
1020                         GraphicsPath gp = new GraphicsPath ();
1021                         gp.AddString (null, FontFamily.GenericMonospace, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
1022                 }
1023
1024                 [Test]
1025                 public void AddString_EmptyString ()
1026                 {
1027                         GraphicsPath gp = new GraphicsPath ();
1028                         gp.AddString (String.Empty, FontFamily.GenericMonospace, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
1029                         Assert.AreEqual (0, gp.PointCount, "PointCount");
1030                 }
1031
1032                 [Test]
1033                 [ExpectedException (typeof (ArgumentException))]
1034                 public void AddString_NullFontFamily ()
1035                 {
1036                         GraphicsPath gp = new GraphicsPath ();
1037                         gp.AddString ("mono", null, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
1038                 }
1039
1040                 [Test]
1041                 public void AddString_NegativeSize ()
1042                 {
1043                         GraphicsPath gp = new GraphicsPath ();
1044                         gp.AddString ("mono", FontFamily.GenericMonospace, 0, -10, new Point (10, 10), StringFormat.GenericDefault);
1045                         Assert.IsTrue (gp.PointCount > 0, "PointCount");
1046                 }
1047
1048                 [Test]
1049                 [Category ("NotWorking")] // StringFormat not yet supported in libgdiplus
1050                 public void AddString_StringFormat ()
1051                 {
1052                         // null maps to ?
1053                         GraphicsPath gp1 = new GraphicsPath ();
1054                         gp1.AddString ("mono", FontFamily.GenericMonospace, 0, 10, new RectangleF (10, 10, 10, 10), null);
1055
1056                         // StringFormat.GenericDefault
1057                         GraphicsPath gp2 = new GraphicsPath ();
1058                         gp2.AddString ("mono", FontFamily.GenericMonospace, 0, 10, new RectangleF (10, 10, 10, 10), StringFormat.GenericDefault);
1059                         Assert.AreEqual (gp1.PointCount, gp2.PointCount, "GenericDefault");
1060
1061                         // StringFormat.GenericTypographic
1062                         GraphicsPath gp3 = new GraphicsPath ();
1063                         gp3.AddString ("mono", FontFamily.GenericMonospace, 0, 10, new RectangleF (10, 10, 10, 10), StringFormat.GenericTypographic);
1064                         Assert.IsFalse (gp1.PointCount == gp3.PointCount, "GenericTypographic");
1065                 }
1066
1067                 [Test]
1068                 public void GetBounds_Empty_Empty ()
1069                 {
1070                         GraphicsPath gp = new GraphicsPath ();
1071                         RectangleF rect = gp.GetBounds ();
1072                         Assert.AreEqual (0.0f, rect.X, "Bounds.X");
1073                         Assert.AreEqual (0.0f, rect.Y, "Bounds.Y");
1074                         Assert.AreEqual (0.0f, rect.Width, "Bounds.Width");
1075                         Assert.AreEqual (0.0f, rect.Height, "Bounds.Height");
1076                 }
1077
1078                 private void CheckRectangleBounds (RectangleF rect)
1079                 {
1080                         Assert.AreEqual (1.0f, rect.X, "Bounds.X");
1081                         Assert.AreEqual (1.0f, rect.Y, "Bounds.Y");
1082                         Assert.AreEqual (2.0f, rect.Width, "Bounds.Width");
1083                         Assert.AreEqual (2.0f, rect.Height, "Bounds.Height");
1084                 }
1085
1086                 [Test]
1087                 public void GetBounds_Empty_Rectangle ()
1088                 {
1089                         GraphicsPath gp = new GraphicsPath ();
1090                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1091                         CheckRectangleBounds (gp.GetBounds ());
1092                 }
1093
1094                 [Test]
1095                 public void GetBounds_Null_Rectangle ()
1096                 {
1097                         GraphicsPath gp = new GraphicsPath ();
1098                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1099                         CheckRectangleBounds (gp.GetBounds (null));
1100                 }
1101
1102                 [Test]
1103                 public void GetBounds_MatrixEmpty_Rectangle ()
1104                 {
1105                         GraphicsPath gp = new GraphicsPath ();
1106                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1107                         CheckRectangleBounds (gp.GetBounds (new Matrix ()));
1108                 }
1109
1110                 [Test]
1111                 public void GetBounds_NullNull_Rectangle ()
1112                 {
1113                         GraphicsPath gp = new GraphicsPath ();
1114                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1115                         CheckRectangleBounds (gp.GetBounds (null, null));
1116                 }
1117
1118                 [Test]
1119                 [Category ("NotWorking")] // bounds+pen support is missing in libgdiplus
1120                 public void GetBounds_WithPen ()
1121                 {
1122                         Rectangle rect = new Rectangle (1, 1, 2, 2);
1123                         Pen p = new Pen (Color.Aqua, 0);
1124                         GraphicsPath gp = new GraphicsPath ();
1125                         gp.AddRectangle (rect);
1126
1127                         RectangleF bounds = gp.GetBounds (null, p);
1128                         Assert.AreEqual (-6.09999943f, bounds.X, "NullMatrix.Bounds.X");
1129                         Assert.AreEqual (-6.09999943f, bounds.Y, "NullMatrix.Bounds.Y");
1130                         Assert.AreEqual (16.1999989f, bounds.Width, "NullMatrix.Bounds.Width");
1131                         Assert.AreEqual (16.1999989f, bounds.Height, "NullMatrix.Bounds.Height");
1132
1133                         Matrix m = new Matrix ();
1134                         // an empty matrix is different than a null matrix
1135                         bounds = gp.GetBounds (m, p);
1136                         Assert.AreEqual (-0.419999957f, bounds.X, "EmptyMatrix.Bounds.X");
1137                         Assert.AreEqual (-0.419999957f, bounds.Y, "EmptyMatrix.Bounds.Y");
1138                         Assert.AreEqual (4.83999968f, bounds.Width, "EmptyMatrix.Bounds.Width");
1139                         Assert.AreEqual (4.83999968f, bounds.Height, "EmptyMatrix.Bounds.Height");
1140
1141                         gp = new GraphicsPath ();
1142                         gp.AddRectangle (rect);
1143                         gp.Widen (p);
1144                         bounds = gp.GetBounds (null);
1145                         Assert.AreEqual (0.499999523f, bounds.X, "WidenNullMatrix.Bounds.X");
1146                         Assert.AreEqual (0.499999523f, bounds.Y, "WidenNullMatrix.Bounds.Y");
1147                         Assert.AreEqual (3.000001f, bounds.Width, "WidenNullMatrix.Bounds.Width");
1148                         Assert.AreEqual (3.000001f, bounds.Height, "WidenNullMatrix.Bounds.Height");
1149
1150                         bounds = gp.GetBounds (m);
1151                         Assert.AreEqual (0.499999523f, bounds.X, "WidenEmptyMatrix.Bounds.X");
1152                         Assert.AreEqual (0.499999523f, bounds.Y, "WidenEmptyMatrix.Bounds.Y");
1153                         Assert.AreEqual (3.000001f, bounds.Width, "WidenEmptyMatrix.Bounds.Width");
1154                         Assert.AreEqual (3.000001f, bounds.Height, "WidenEmptyMatrix.Bounds.Height");
1155                 }
1156
1157                 [Test]
1158                 [ExpectedException (typeof (ArgumentNullException))]
1159                 public void Transform_Null ()
1160                 {
1161                         new GraphicsPath ().Transform (null);
1162                 }
1163
1164                 [Test]
1165                 public void Transform_Empty ()
1166                 {
1167                         // no points in path and no exception
1168                         new GraphicsPath ().Transform (new Matrix ());
1169                 }
1170
1171                 private void ComparePaths (GraphicsPath expected, GraphicsPath actual)
1172                 {
1173                         Assert.AreEqual (expected.PointCount, actual.PointCount, "PointCount");
1174                         for (int i = 0; i < expected.PointCount; i++) {
1175                                 Assert.AreEqual (expected.PathPoints[i], actual.PathPoints[i], "PathPoints-" + i.ToString ());
1176                                 Assert.AreEqual (expected.PathTypes[i], actual.PathTypes[i], "PathTypes-" + i.ToString ());
1177                         }
1178                 }
1179
1180                 private void CompareFlats (GraphicsPath flat, GraphicsPath original)
1181                 {
1182                         Assert.IsTrue (flat.PointCount >= original.PointCount, "PointCount");
1183                         for (int i = 0; i < flat.PointCount; i++) {
1184                                 Assert.IsTrue (flat.PathTypes[i] != 3, "PathTypes-" + i.ToString ());
1185                         }
1186                 }
1187
1188                 [Test]
1189                 public void Flatten_Empty ()
1190                 {
1191                         GraphicsPath path = new GraphicsPath ();
1192                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1193                         // this is a no-op as there's nothing in the path
1194                         path.Flatten ();
1195                         ComparePaths (path, clone);
1196                 }
1197
1198                 [Test]
1199                 public void Flatten_Null ()
1200                 {
1201                         GraphicsPath path = new GraphicsPath ();
1202                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1203                         // this is a no-op as there's nothing in the path
1204                         // an no matrix to apply
1205                         path.Flatten (null);
1206                         ComparePaths (path, clone);
1207                 }
1208
1209                 [Test]
1210                 public void Flatten_NullFloat ()
1211                 {
1212                         GraphicsPath path = new GraphicsPath ();
1213                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1214                         // this is a no-op as there's nothing in the path
1215                         // an no matrix to apply
1216                         path.Flatten (null, 1f);
1217                         ComparePaths (path, clone);
1218                 }
1219
1220                 [Test]
1221                 public void Flatten_Arc ()
1222                 {
1223                         GraphicsPath path = new GraphicsPath ();
1224                         path.AddArc (0f, 0f, 100f, 100f, 30, 30);
1225                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1226                         path.Flatten ();
1227                         CompareFlats (path, clone);
1228                 }
1229
1230                 [Test]
1231                 public void Flatten_Bezier ()
1232                 {
1233                         GraphicsPath path = new GraphicsPath ();
1234                         path.AddBezier (0, 0, 100, 100, 30, 30, 60, 60);
1235                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1236                         path.Flatten ();
1237                         CompareFlats (path, clone);
1238                 }
1239
1240                 [Test]
1241                 public void Flatten_ClosedCurve ()
1242                 {
1243                         GraphicsPath path = new GraphicsPath ();
1244                         path.AddClosedCurve (new Point[4] { 
1245                                 new Point (0, 0), new Point (40, 20),
1246                                 new Point (20, 40), new Point (40, 40)
1247                                 });
1248                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1249                         path.Flatten ();
1250                         CompareFlats (path, clone);
1251                 }
1252
1253                 [Test]
1254                 public void Flatten_Curve ()
1255                 {
1256                         GraphicsPath path = new GraphicsPath ();
1257                         path.AddCurve (new Point[4] { 
1258                                 new Point (0, 0), new Point (40, 20),
1259                                 new Point (20, 40), new Point (40, 40)
1260                                 });
1261                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1262                         path.Flatten ();
1263                         CompareFlats (path, clone);
1264                 }
1265
1266                 [Test]
1267                 public void Flatten_Ellipse ()
1268                 {
1269                         GraphicsPath path = new GraphicsPath ();
1270                         path.AddEllipse (10f, 10f, 100f, 100f);
1271                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1272                         path.Flatten ();
1273                         CompareFlats (path, clone);
1274                 }
1275
1276                 [Test]
1277                 public void Flatten_Line ()
1278                 {
1279                         GraphicsPath path = new GraphicsPath ();
1280                         path.AddLine (10f, 10f, 100f, 100f);
1281                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1282                         path.Flatten ();
1283                         ComparePaths (path, clone);
1284                 }
1285
1286                 [Test]
1287                 public void Flatten_Pie ()
1288                 {
1289                         GraphicsPath path = new GraphicsPath ();
1290                         path.AddPie (0, 0, 100, 100, 30, 30);
1291                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1292                         path.Flatten ();
1293                         CompareFlats (path, clone);
1294                 }
1295
1296                 [Test]
1297                 public void Flatten_Polygon ()
1298                 {
1299                         GraphicsPath path = new GraphicsPath ();
1300                         path.AddPolygon (new Point[4] { 
1301                                 new Point (0, 0), new Point (10, 10),
1302                                 new Point (20, 20), new Point (40, 40)
1303                                 });
1304                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1305                         path.Flatten ();
1306                         ComparePaths (path, clone);
1307                 }
1308
1309                 [Test]
1310                 public void Flatten_Rectangle ()
1311                 {
1312                         GraphicsPath path = new GraphicsPath ();
1313                         path.AddRectangle (new Rectangle (0, 0, 100, 100));
1314                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1315                         path.Flatten ();
1316                         ComparePaths (path, clone);
1317                 }
1318
1319                 private void CheckWrap (GraphicsPath path)
1320                 {
1321                         Assert.AreEqual (3, path.PointCount, "Count");
1322
1323                         PointF[] pts = path.PathPoints;
1324                         Assert.AreEqual (0, pts[0].X, 1e-30, "0.X");
1325                         Assert.AreEqual (0, pts[0].Y, 1e-30, "0.Y");
1326                         Assert.AreEqual (0, pts[1].X, 1e-30, "1.X");
1327                         Assert.AreEqual (0, pts[1].Y, 1e-30, "1.Y");
1328                         Assert.AreEqual (0, pts[2].X, 1e-30, "2.X");
1329                         Assert.AreEqual (0, pts[2].Y, 1e-30, "2.Y");
1330
1331                         byte[] types = path.PathTypes;
1332                         Assert.AreEqual (0, types[0], "0");
1333                         Assert.AreEqual (1, types[1], "1");
1334                         Assert.AreEqual (129, types[2], "2");
1335                 }
1336
1337                 private void CheckWrapNaN (GraphicsPath path, bool closed)
1338                 {
1339                         Assert.AreEqual (3, path.PointCount, "Count");
1340
1341                         PointF[] pts = path.PathPoints;
1342                         Assert.AreEqual (Single.NaN, pts[0].X, "0.X");
1343                         Assert.AreEqual (Single.NaN, pts[0].Y, "0.Y");
1344                         Assert.AreEqual (Single.NaN, pts[1].X, "1.X");
1345                         Assert.AreEqual (Single.NaN, pts[1].Y, "1.Y");
1346                         Assert.AreEqual (Single.NaN, pts[2].X, "2.X");
1347                         Assert.AreEqual (Single.NaN, pts[2].Y, "2.Y");
1348
1349                         byte[] types = path.PathTypes;
1350                         Assert.AreEqual (0, types[0], "0");
1351                         Assert.AreEqual (1, types[1], "1");
1352                         Assert.AreEqual (closed ? 129 : 1, types[2], "2");
1353                 }
1354
1355                 [Test]
1356                 [ExpectedException (typeof (ArgumentNullException))]
1357                 public void Warp_Null ()
1358                 {
1359                         new GraphicsPath ().Warp (null, new RectangleF ());
1360                 }
1361
1362                 [Test]
1363                 [ExpectedException (typeof (ArgumentException))]
1364                 public void Warp_NoPoints ()
1365                 {
1366                         new GraphicsPath ().Warp (new PointF[0], new RectangleF ());
1367                 }
1368
1369                 [Test]
1370                 [Category ("NotWorking")]
1371                 public void Warp_NullMatrix ()
1372                 {
1373                         PointF[] pts = new PointF[1] { new PointF (0,0) };
1374                         GraphicsPath path = new GraphicsPath ();
1375                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1376                         RectangleF r = new RectangleF (10, 20, 30, 40);
1377                         path.Warp (pts, r, null);
1378                         CheckWrap (path);
1379                 }
1380
1381                 [Test]
1382                 [Category ("NotWorking")]
1383                 public void Warp_EmptyMatrix ()
1384                 {
1385                         PointF[] pts = new PointF[1] { new PointF (0, 0) };
1386                         GraphicsPath path = new GraphicsPath ();
1387                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1388                         RectangleF r = new RectangleF (10, 20, 30, 40);
1389                         path.Warp (pts, r, new Matrix ());
1390                         CheckWrap (path);
1391                 }
1392
1393                 [Test]
1394                 [Category ("NotWorking")]
1395                 public void Warp_Rectangle_Empty ()
1396                 {
1397                         PointF[] pts = new PointF[1] { new PointF (0, 0) };
1398                         GraphicsPath path = new GraphicsPath ();
1399                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1400                         path.Warp (pts, new RectangleF (), null);
1401                         CheckWrapNaN (path, true);
1402                 }
1403
1404                 [Test]
1405                 [Category ("NotWorking")]
1406                 public void Warp_Rectangle_NegativeWidthHeight ()
1407                 {
1408                         PointF[] pts = new PointF[1] { new PointF (0, 0) };
1409                         GraphicsPath path = new GraphicsPath ();
1410                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1411                         RectangleF r = new RectangleF (10, 20, -30, -40);
1412                         path.Warp (pts, r, null);
1413                         Assert.AreEqual (3, path.PointCount, "Count");
1414
1415                         pts = path.PathPoints;
1416                         Assert.AreEqual (1.131355e-39, pts[0].X, 1e40, "0.X");
1417                         Assert.AreEqual (-2.0240637E-33, pts[0].Y, 1e40, "0.Y");
1418                         Assert.AreEqual (1.070131E-39, pts[1].X, 1e40, "1.X");
1419                         Assert.AreEqual (-2.02406389E-33, pts[1].Y, 1e40, "1.Y");
1420                         Assert.AreEqual (3.669146E-40, pts[2].X, 1e40, "2.X");
1421                         Assert.AreEqual (-6.746879E-34, pts[2].Y, 1e40, "2.Y");
1422                         byte[] types = path.PathTypes;
1423                         Assert.AreEqual (0, types[0], "0");
1424                         Assert.AreEqual (1, types[1], "1");
1425                         Assert.AreEqual (129, types[2], "2");
1426                 }
1427
1428                 [Test]
1429                 [Category ("NotWorking")]
1430                 public void Warp_Matrix_NonInvertible ()
1431                 {
1432                         Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
1433                         Assert.IsFalse (matrix.IsInvertible, "!IsInvertible");
1434                         PointF[] pts = new PointF[1] { new PointF (0, 0) };
1435                         GraphicsPath path = new GraphicsPath ();
1436                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1437                         RectangleF r = new RectangleF (10, 20, 30, 40);
1438                         path.Warp (pts, r, matrix);
1439
1440                         Assert.AreEqual (3, path.PointCount, "Count");
1441                         pts = path.PathPoints;
1442                         Assert.AreEqual (47, pts[0].X, "0.X");
1443                         Assert.AreEqual (30, pts[0].Y, "0.Y");
1444                         Assert.AreEqual (47, pts[1].X, "1.X");
1445                         Assert.AreEqual (30, pts[1].Y, "1.Y");
1446                         Assert.AreEqual (47, pts[2].X, "2.X");
1447                         Assert.AreEqual (30, pts[2].Y, "2.Y");
1448                         byte[] types = path.PathTypes;
1449                         Assert.AreEqual (0, types[0], "0");
1450                         Assert.AreEqual (1, types[1], "1");
1451                         Assert.AreEqual (129, types[2], "2");
1452                 }
1453
1454                 [Test]
1455                 [Category ("NotWorking")]
1456                 public void Warp_Bilinear ()
1457                 {
1458                         PointF[] pts = new PointF[1] { new PointF (0, 0) };
1459                         GraphicsPath path = new GraphicsPath ();
1460                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1461                         RectangleF r = new RectangleF (10, 20, 30, 40);
1462                         path.Warp (pts, r, new Matrix (), WarpMode.Bilinear);
1463                         // note that the last point is no more closed
1464                         CheckWrapNaN (path, false);
1465                 }
1466
1467                 [Test]
1468                 [Category ("NotWorking")]
1469                 public void Warp_Perspective ()
1470                 {
1471                         PointF[] pts = new PointF[1] { new PointF (0, 0) };
1472                         GraphicsPath path = new GraphicsPath ();
1473                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1474                         RectangleF r = new RectangleF (10, 20, 30, 40);
1475                         path.Warp (pts, r, new Matrix (), WarpMode.Perspective);
1476                         CheckWrap (path);
1477                 }
1478
1479                 [Test]
1480                 public void Warp_Invalid ()
1481                 {
1482                         PointF[] pts = new PointF[1] { new PointF (0, 0) };
1483                         GraphicsPath path = new GraphicsPath ();
1484                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1485                         RectangleF r = new RectangleF (10, 20, 30, 40);
1486                         path.Warp (pts, r, new Matrix (), (WarpMode) Int32.MinValue);
1487                         Assert.AreEqual (0, path.PointCount, "Count");
1488                 }
1489
1490                 [Test]
1491                 [Category ("NotWorking")]
1492                 public void Warp_Flatness_Negative ()
1493                 {
1494                         PointF[] pts = new PointF[1] { new PointF (0, 0) };
1495                         GraphicsPath path = new GraphicsPath ();
1496                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1497                         RectangleF r = new RectangleF (10, 20, 30, 40);
1498                         path.Warp (pts, r, new Matrix (), WarpMode.Perspective, -1f);
1499                         CheckWrap (path);
1500                 }
1501
1502                 [Test]
1503                 [Category ("NotWorking")]
1504                 public void Warp_Flatness_OverOne ()
1505                 {
1506                         PointF[] pts = new PointF[1] { new PointF (0, 0) };
1507                         GraphicsPath path = new GraphicsPath ();
1508                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1509                         RectangleF r = new RectangleF (10, 20, 30, 40);
1510                         path.Warp (pts, r, new Matrix (), WarpMode.Perspective, 2.0f);
1511                         CheckWrap (path);
1512                 }
1513
1514                 [Test]
1515                 public void SetMarkers_EmptyPath ()
1516                 {
1517                         new GraphicsPath ().SetMarkers ();
1518                 }
1519
1520                 [Test]
1521                 public void ClearMarkers_EmptyPath ()
1522                 {
1523                         new GraphicsPath ().ClearMarkers ();
1524                 }
1525
1526                 [Test]
1527                 public void CloseFigure_EmptyPath ()
1528                 {
1529                         new GraphicsPath ().CloseFigure ();
1530                 }
1531
1532                 [Test]
1533                 public void CloseAllFigures_EmptyPath ()
1534                 {
1535                         new GraphicsPath ().CloseAllFigures ();
1536                 }
1537
1538                 [Test]
1539                 public void StartClose_AddArc ()
1540                 {
1541                         GraphicsPath path = new GraphicsPath ();
1542                         path.AddLine (1, 1, 2, 2);
1543                         path.AddArc (10, 10, 100, 100, 90, 180);
1544                         path.AddLine (10, 10, 20, 20);
1545                         byte[] types = path.PathTypes;
1546                         // check first types
1547                         Assert.AreEqual (0, types[0], "start/Line");
1548                         Assert.AreEqual (1, types[2], "start/Arc");
1549                         // check last types
1550                         Assert.AreEqual (3, types[path.PointCount - 3], "end/Arc");
1551                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1552                 }
1553
1554                 [Test]
1555                 public void StartClose_AddBezier ()
1556                 {
1557                         GraphicsPath path = new GraphicsPath ();
1558                         path.AddLine (1, 1, 2, 2);
1559                         path.AddBezier (10, 10, 100, 100, 20, 20, 200, 200);
1560                         path.AddLine (10, 10, 20, 20);
1561                         byte[] types = path.PathTypes;
1562                         // check first types
1563                         Assert.AreEqual (0, types[0], "start/Line");
1564                         Assert.AreEqual (1, types[2], "start/Bezier");
1565                         // check last types
1566                         Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier");
1567                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1568                 }
1569
1570                 [Test]
1571                 public void StartClose_AddBeziers ()
1572                 {
1573                         GraphicsPath path = new GraphicsPath ();
1574                         path.AddLine (1, 1, 2, 2);
1575                         path.AddBeziers (new Point[7] { new Point (10, 10), 
1576                                 new Point (20, 10), new Point (20, 20), new Point (30, 20),
1577                                 new Point (40, 40), new Point (50, 40), new Point (50, 50)
1578                         });
1579                         path.AddLine (10, 10, 20, 20);
1580                         byte[] types = path.PathTypes;
1581                         // check first types
1582                         Assert.AreEqual (0, types[0], "start/Line");
1583                         Assert.AreEqual (1, types[2], "start/Bezier");
1584                         // check last types
1585                         Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier");
1586                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1587                 }
1588
1589                 [Test]
1590                 public void StartClose_AddClosedCurve ()
1591                 {
1592                         GraphicsPath path = new GraphicsPath ();
1593                         path.AddLine (1, 1, 2, 2);
1594                         path.AddClosedCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
1595                         path.AddLine (10, 10, 20, 20);
1596                         byte[] types = path.PathTypes;
1597                         // check first types
1598                         Assert.AreEqual (0, types[0], "start/Line");
1599                         Assert.AreEqual (0, types[2], "start/ClosedCurve");
1600                         // check last types
1601                         Assert.AreEqual (131, types[path.PointCount - 3], "end/ClosedCurve");
1602                         Assert.AreEqual (0, types[path.PointCount - 2], "start/Line3");
1603                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line3");
1604                 }
1605
1606                 [Test]
1607                 public void StartClose_AddCurve ()
1608                 {
1609                         GraphicsPath path = new GraphicsPath ();
1610                         path.AddLine (1, 1, 2, 2);
1611                         path.AddCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
1612                         path.AddLine (10, 10, 20, 20);
1613                         byte[] types = path.PathTypes;
1614                         // check first types
1615                         Assert.AreEqual (0, types[0], "start/Line");
1616                         Assert.AreEqual (1, types[2], "start/Curve");
1617                         // check last types
1618                         Assert.AreEqual (3, types[path.PointCount - 3], "end/Curve");
1619                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1620                 }
1621
1622                 [Test]
1623                 public void StartClose_AddEllipse ()
1624                 {
1625                         GraphicsPath path = new GraphicsPath ();
1626                         path.AddLine (1, 1, 2, 2);
1627                         path.AddEllipse (10, 10, 100, 100);
1628                         path.AddLine (10, 10, 20, 20);
1629                         byte[] types = path.PathTypes;
1630                         // check first types
1631                         Assert.AreEqual (0, types[0], "start/Line");
1632                         Assert.AreEqual (0, types[2], "start/Ellipse");
1633                         // check last types
1634                         Assert.AreEqual (131, types[path.PointCount - 3], "end/Ellipse");
1635                         Assert.AreEqual (0, types[path.PointCount - 2], "start/Line3");
1636                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line3");
1637                 }
1638
1639                 [Test]
1640                 public void StartClose_AddLine ()
1641                 {
1642                         GraphicsPath path = new GraphicsPath ();
1643                         path.AddLine (1, 1, 2, 2);
1644                         path.AddLine (5, 5, 10, 10);
1645                         path.AddLine (10, 10, 20, 20);
1646                         byte[] types = path.PathTypes;
1647                         // check first types
1648                         Assert.AreEqual (0, types[0], "start/Line");
1649                         Assert.AreEqual (1, types[2], "start/Line2");
1650                         // check last types
1651                         Assert.AreEqual (1, types[path.PointCount - 3], "end/Line2");
1652                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1653                 }
1654
1655                 [Test]
1656                 public void StartClose_AddLines ()
1657                 {
1658                         GraphicsPath path = new GraphicsPath ();
1659                         path.AddLine (1, 1, 2, 2);
1660                         path.AddLines (new Point[4] { new Point (10, 10), new Point (20, 10), new Point (20, 20), new Point (30, 20) });
1661                         path.AddLine (10, 10, 20, 20);
1662                         byte[] types = path.PathTypes;
1663                         // check first types
1664                         Assert.AreEqual (0, types[0], "start/Line");
1665                         Assert.AreEqual (1, types[2], "start/Lines");
1666                         // check last types
1667                         Assert.AreEqual (1, types[path.PointCount - 3], "end/Lines");
1668                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1669                 }
1670
1671                 [Test]
1672                 public void StartClose_AddPath_Connect ()
1673                 {
1674                         GraphicsPath inner = new GraphicsPath ();
1675                         inner.AddArc (10, 10, 100, 100, 90, 180);
1676                         GraphicsPath path = new GraphicsPath ();
1677                         path.AddLine (1, 1, 2, 2);
1678                         path.AddPath (inner, true);
1679                         path.AddLine (10, 10, 20, 20);
1680                         byte[] types = path.PathTypes;
1681                         // check first types
1682                         Assert.AreEqual (0, types[0], "start/Line");
1683                         Assert.AreEqual (1, types[2], "start/Path");
1684                         // check last types
1685                         Assert.AreEqual (3, types[path.PointCount - 3], "end/Path");
1686                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1687                 }
1688
1689                 [Test]
1690                 public void StartClose_AddPath_NoConnect ()
1691                 {
1692                         GraphicsPath inner = new GraphicsPath ();
1693                         inner.AddArc (10, 10, 100, 100, 90, 180);
1694                         GraphicsPath path = new GraphicsPath ();
1695                         path.AddLine (1, 1, 2, 2);
1696                         path.AddPath (inner, false);
1697                         path.AddLine (10, 10, 20, 20);
1698                         byte[] types = path.PathTypes;
1699                         // check first types
1700                         Assert.AreEqual (0, types[0], "start/Line");
1701                         Assert.AreEqual (0, types[2], "start/Path");
1702                         // check last types
1703                         Assert.AreEqual (3, types[path.PointCount - 3], "end/Path");
1704                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1705                 }
1706
1707                 [Test]
1708                 public void StartClose_AddPie ()
1709                 {
1710                         GraphicsPath path = new GraphicsPath ();
1711                         path.AddLine (1, 1, 2, 2);
1712                         path.AddPie (10, 10, 10, 10, 90, 180);
1713                         path.AddLine (10, 10, 20, 20);
1714                         byte[] types = path.PathTypes;
1715                         // check first types
1716                         Assert.AreEqual (0, types[0], "start/Line");
1717                         Assert.AreEqual (0, types[2], "start/Pie");
1718                         // check last types
1719                         // libgdiplus draws pie by ending with a line (not a curve) section
1720                         Assert.IsTrue ((types[path.PointCount - 3] & 128) == 128, "end/Pie");
1721                         Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
1722                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
1723                 }
1724
1725                 [Test]
1726                 public void StartClose_AddPolygon ()
1727                 {
1728                         GraphicsPath path = new GraphicsPath ();
1729                         path.AddLine (1, 1, 2, 2);
1730                         path.AddPolygon (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
1731                         path.AddLine (10, 10, 20, 20);
1732                         byte[] types = path.PathTypes;
1733                         // check first types
1734                         Assert.AreEqual (0, types[0], "start/Line");
1735                         Assert.AreEqual (0, types[2], "start/Polygon");
1736                         // check last types
1737                         Assert.AreEqual (129, types[path.PointCount - 3], "end/Polygon");
1738                         Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
1739                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
1740                 }
1741
1742                 [Test]
1743                 public void StartClose_AddRectangle ()
1744                 {
1745                         GraphicsPath path = new GraphicsPath ();
1746                         path.AddLine (1, 1, 2, 2);
1747                         path.AddRectangle (new RectangleF (10, 10, 20, 20));
1748                         path.AddLine (10, 10, 20, 20);
1749                         byte[] types = path.PathTypes;
1750                         // check first types
1751                         Assert.AreEqual (0, types[0], "start/Line");
1752                         Assert.AreEqual (0, types[2], "start/Rectangle");
1753                         // check last types
1754                         Assert.AreEqual (129, types[path.PointCount - 3], "end/Rectangle");
1755                         Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
1756                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
1757                 }
1758
1759                 [Test]
1760                 public void StartClose_AddRectangles ()
1761                 {
1762                         GraphicsPath path = new GraphicsPath ();
1763                         path.AddLine (1, 1, 2, 2);
1764                         path.AddRectangles (new RectangleF[2] {
1765                                 new RectangleF (10, 10, 20, 20),
1766                                 new RectangleF (20, 20, 10, 10) });
1767                         path.AddLine (10, 10, 20, 20);
1768                         byte[] types = path.PathTypes;
1769                         // check first types
1770                         Assert.AreEqual (0, types[0], "start/Line");
1771                         Assert.AreEqual (0, types[2], "start/Rectangles");
1772                         // check last types
1773                         Assert.AreEqual (129, types[path.PointCount - 3], "end/Rectangles");
1774                         Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
1775                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
1776                 }
1777
1778                 [Test]
1779                 [Category ("NotWorking")]
1780                 public void StartClose_AddString ()
1781                 {
1782                         GraphicsPath path = new GraphicsPath ();
1783                         path.AddLine (1, 1, 2, 2);
1784                         path.AddString ("mono", FontFamily.GenericMonospace, 0, 10, new Point (20,20), StringFormat.GenericDefault);
1785                         path.AddLine (10, 10, 20, 20);
1786                         byte[] types = path.PathTypes;
1787                         // check first types
1788                         Assert.AreEqual (0, types[0], "start/Line");
1789                         Assert.AreEqual (0, types[2], "start/String");
1790                         // check last types
1791                         Assert.AreEqual (163, types[path.PointCount - 3], "end/String");
1792                         Assert.AreEqual (1, types[path.PointCount - 2], "start/Line2");
1793                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
1794                 }
1795
1796                 [Test]
1797                 [ExpectedException (typeof (ArgumentNullException))]
1798                 public void Widen_Pen_Null ()
1799                 {
1800                         new GraphicsPath ().Widen (null);
1801                 }
1802
1803                 [Test]
1804                 [Category ("NotWorking")]
1805                 public void Widen_Pen ()
1806                 {
1807                         Pen pen = new Pen (Color.Blue);
1808                         GraphicsPath path = new GraphicsPath ();
1809                         path.AddRectangle (new Rectangle (1, 1, 2, 2));
1810                         Assert.AreEqual (4, path.PointCount, "Count-1");
1811                         path.Widen (pen);
1812                         Assert.AreEqual (12, path.PointCount, "Count-2");
1813
1814                         PointF[] pts = path.PathPoints;
1815                         Assert.AreEqual (0.5, pts[0].X, 0.25, "0.X");
1816                         Assert.AreEqual (0.5, pts[0].Y, 0.25, "0.Y");
1817                         Assert.AreEqual (3.5, pts[1].X, 0.25, "1.X");
1818                         Assert.AreEqual (0.5, pts[1].Y, 0.25, "1.Y");
1819                         Assert.AreEqual (3.5, pts[2].X, 0.25, "2.X");
1820                         Assert.AreEqual (3.5, pts[2].Y, 0.25, "2.Y");
1821                         Assert.AreEqual (0.5, pts[3].X, 0.25, "3.X");
1822                         Assert.AreEqual (3.5, pts[3].Y, 0.25, "3.Y");
1823                         Assert.AreEqual (1.5, pts[4].X, 0.25, "4.X");
1824                         Assert.AreEqual (3.0, pts[4].Y, 0.25, "4.Y");
1825                         Assert.AreEqual (1.0, pts[5].X, 0.25, "5.X");
1826                         Assert.AreEqual (2.5, pts[5].Y, 0.25, "5.Y");
1827                         Assert.AreEqual (3.0, pts[6].X, 0.25, "6.X");
1828                         Assert.AreEqual (2.5, pts[6].Y, 0.25, "6.Y");
1829                         Assert.AreEqual (2.5, pts[7].X, 0.25, "7.X");
1830                         Assert.AreEqual (3.0, pts[7].Y, 0.25, "7.Y");
1831                         Assert.AreEqual (2.5, pts[8].X, 0.25, "8.X");
1832                         Assert.AreEqual (1.0, pts[8].Y, 0.25, "8.Y");
1833                         Assert.AreEqual (3.0, pts[9].X, 0.25, "9.X");
1834                         Assert.AreEqual (1.5, pts[9].Y, 0.25, "9.Y");
1835                         Assert.AreEqual (1.0, pts[10].X, 0.25, "10.X");
1836                         Assert.AreEqual (1.5, pts[10].Y, 0.25, "10.Y");
1837                         Assert.AreEqual (1.5, pts[11].X, 0.25, "11.X");
1838                         Assert.AreEqual (1.0, pts[11].Y, 0.25, "11.Y");
1839
1840                         byte[] types = path.PathTypes;
1841                         Assert.AreEqual (0, types[0], "0");
1842                         Assert.AreEqual (1, types[1], "1");
1843                         Assert.AreEqual (1, types[2], "2");
1844                         Assert.AreEqual (129, types[3], "3");
1845                         Assert.AreEqual (0, types[4], "4");
1846                         Assert.AreEqual (1, types[5], "5");
1847                         Assert.AreEqual (1, types[6], "6");
1848                         Assert.AreEqual (1, types[7], "7");
1849                         Assert.AreEqual (1, types[8], "8");
1850                         Assert.AreEqual (1, types[9], "9");
1851                         Assert.AreEqual (1, types[10], "10");
1852                         Assert.AreEqual (129, types[11], "11");
1853                 }
1854
1855                 [Test]
1856                 [ExpectedException (typeof (ArgumentNullException))]
1857                 public void Widen_Pen_Null_Matrix ()
1858                 {
1859                         new GraphicsPath ().Widen (null, new Matrix ());
1860                 }
1861
1862                 private void CheckWiden3 (GraphicsPath path)
1863                 {
1864                         PointF[] pts = path.PathPoints;
1865                         Assert.AreEqual (4.2, pts[0].X, 0.25, "0.X");
1866                         Assert.AreEqual (4.5, pts[0].Y, 0.25, "0.Y");
1867                         Assert.AreEqual (15.8, pts[1].X, 0.25, "1.X");
1868                         Assert.AreEqual (4.5, pts[1].Y, 0.25, "1.Y");
1869                         Assert.AreEqual (10.0, pts[2].X, 0.25, "2.X");
1870                         Assert.AreEqual (16.1, pts[2].Y, 0.25, "2.Y");
1871                         Assert.AreEqual (10.4, pts[3].X, 0.25, "3.X");
1872                         Assert.AreEqual (14.8, pts[3].Y, 0.25, "3.Y");
1873                         Assert.AreEqual (9.6, pts[4].X, 0.25, "4.X");
1874                         Assert.AreEqual (14.8, pts[4].Y, 0.25, "4.Y");
1875                         Assert.AreEqual (14.6, pts[5].X, 0.25, "7.X");
1876                         Assert.AreEqual (4.8, pts[5].Y, 0.25, "7.Y");
1877                         Assert.AreEqual (15.0, pts[6].X, 0.25, "5.X");
1878                         Assert.AreEqual (5.5, pts[6].Y, 0.25, "5.Y");
1879                         Assert.AreEqual (5.0, pts[7].X, 0.25, "6.X");
1880                         Assert.AreEqual (5.5, pts[7].Y, 0.25, "6.Y");
1881                         Assert.AreEqual (5.4, pts[8].X, 0.25, "8.X");
1882                         Assert.AreEqual (4.8, pts[8].Y, 0.25, "8.Y");
1883
1884                         byte[] types = path.PathTypes;
1885                         Assert.AreEqual (0, types[0], "0");
1886                         Assert.AreEqual (1, types[1], "1");
1887                         Assert.AreEqual (129, types[2], "2");
1888                         Assert.AreEqual (0, types[3], "3");
1889                         Assert.AreEqual (1, types[4], "4");
1890                         Assert.AreEqual (1, types[5], "5");
1891                         Assert.AreEqual (1, types[6], "6");
1892                         Assert.AreEqual (1, types[7], "7");
1893                         Assert.AreEqual (129, types[8], "8");
1894                 }
1895
1896                 [Test]
1897                 [Category ("NotWorking")]
1898                 public void Widen_Pen_Matrix_Null ()
1899                 {
1900                         Pen pen = new Pen (Color.Blue);
1901                         GraphicsPath path = new GraphicsPath ();
1902                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1903                         path.Widen (pen, null);
1904                         Assert.AreEqual (9, path.PointCount, "Count");
1905                         CheckWiden3 (path);
1906                 }
1907
1908                 [Test]
1909                 [Category ("NotWorking")]
1910                 public void Widen_Pen_Matrix_Empty ()
1911                 {
1912                         Pen pen = new Pen (Color.Blue);
1913                         GraphicsPath path = new GraphicsPath ();
1914                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1915                         path.Widen (pen, new Matrix ());
1916                         Assert.AreEqual (9, path.PointCount, "Count");
1917                         CheckWiden3 (path);
1918                 }
1919
1920                 [Test]
1921                 public void Widen_Pen_Matrix_NonInvertible ()
1922                 {
1923                         Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
1924                         Assert.IsFalse (matrix.IsInvertible, "!IsInvertible");
1925                         GraphicsPath path = new GraphicsPath ();
1926                         path.Widen (new Pen (Color.Blue), matrix);
1927                         Assert.AreEqual (0, path.PointCount, "Points");
1928                 }
1929         }
1930 }