New test.
[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                         gp.Reverse ();
115                         CheckEmpty ("Reverse.", gp);
116                 }
117
118                 [Test]
119                 [ExpectedException (typeof (ArgumentException))]
120                 public void GraphicsPath_Empty_PathPoints ()
121                 {
122                         Assert.IsNull (new GraphicsPath ().PathPoints);
123                 }
124
125                 [Test]
126                 [ExpectedException (typeof (ArgumentException))]
127                 public void GraphicsPath_Empty_PathTypes ()
128                 {
129                         Assert.IsNull (new GraphicsPath ().PathTypes);
130                 }
131
132                 [Test]
133                 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
134                 public void FillMode_Invalid ()
135                 {
136                         // constructor accept an invalid FillMode
137                         GraphicsPath gp = new GraphicsPath ((FillMode) Int32.MaxValue);
138                         Assert.AreEqual (Int32.MaxValue, (int) gp.FillMode, "MaxValue");
139                         // but you can't set the FillMode property to an invalid value ;-)
140                         gp.FillMode = (FillMode) Int32.MaxValue;
141                 }
142
143                 [Test]
144                 public void PathData_CannotChange ()
145                 {
146                         GraphicsPath gp = new GraphicsPath ();
147                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
148
149                         Assert.AreEqual (1f, gp.PathData.Points[0].X, "Points[0].X");
150                         Assert.AreEqual (1f, gp.PathData.Points[0].Y, "Points[0].Y");
151
152                         // now try to change the first point
153                         gp.PathData.Points[0] = new Point (0, 0);
154                         // the changes isn't reflected in the property
155                         Assert.AreEqual (1f, gp.PathData.Points[0].X, "Points[0].X-1");
156                         Assert.AreEqual (1f, gp.PathData.Points[0].Y, "Points[0].Y-1");
157                 }
158
159                 [Test]
160                 public void PathPoints_CannotChange ()
161                 {
162                         GraphicsPath gp = new GraphicsPath ();
163                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
164
165                         Assert.AreEqual (1f, gp.PathPoints[0].X, "PathPoints[0].X");
166                         Assert.AreEqual (1f, gp.PathPoints[0].Y, "PathPoints[0].Y");
167
168                         // now try to change the first point
169                         gp.PathPoints[0] = new Point (0, 0);
170                         // the changes isn't reflected in the property
171                         Assert.AreEqual (1f, gp.PathPoints[0].X, "PathPoints[0].X-1");
172                         Assert.AreEqual (1f, gp.PathPoints[0].Y, "PathPoints[0].Y-1");
173                 }
174
175                 [Test]
176                 public void PathTypes_CannotChange ()
177                 {
178                         GraphicsPath gp = new GraphicsPath ();
179                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
180
181                         Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
182
183                         // now try to change the first type
184                         gp.PathTypes[0] = 1;
185                         // the changes isn't reflected in the property
186                         Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]-1");
187                 }
188
189                 private void CheckArc (GraphicsPath path)
190                 {
191                         Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
192                         Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
193                         Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
194
195                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
196                         RectangleF rect = path.GetBounds ();
197                         Assert.AreEqual (2.999624f, rect.X, "Bounds.X");
198                         Assert.AreEqual (2.013707f, rect.Y, "Bounds.Y");
199                         Assert.AreEqual (0f, rect.Width, Delta, "Bounds.Width");
200                         Assert.AreEqual (0.01370478f, rect.Height, "Bounds.Height");
201
202                         Assert.AreEqual (2.999906f, path.PathData.Points[0].X, "Points[0].X");
203                         Assert.AreEqual (2.013707f, path.PathPoints[0].Y, "Points[0].Y");
204                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
205                         Assert.AreEqual (2.999843f, path.PathData.Points[1].X, "Points[1].X");
206                         Assert.AreEqual (2.018276f, path.PathPoints[1].Y, "Points[1].Y");
207                         Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
208                         Assert.AreEqual (2.99974918f, path.PathData.Points[2].X, "Points[2].X");
209                         Assert.AreEqual (2.02284455f, path.PathPoints[2].Y, "Points[2].Y");
210                         Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
211                         Assert.AreEqual (2.999624f, path.PathData.Points[3].X, "Points[3].X");
212                         Assert.AreEqual (2.027412f, path.PathPoints[3].Y, "Points[3].Y");
213                         Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
214                 }
215
216                 [Test]
217                 public void AddArc_Rectangle ()
218                 {
219                         GraphicsPath gp = new GraphicsPath ();
220                         gp.AddArc (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
221                         CheckArc (gp);
222                 }
223
224                 [Test]
225                 public void AddArc_RectangleF ()
226                 {
227                         GraphicsPath gp = new GraphicsPath ();
228                         gp.AddArc (new RectangleF (1f, 1f, 2f, 2f), Pi4, Pi4);
229                         CheckArc (gp);
230                 }
231
232                 [Test]
233                 public void AddArc_Int ()
234                 {
235                         GraphicsPath gp = new GraphicsPath ();
236                         gp.AddArc (1, 1, 2, 2, Pi4, Pi4);
237                         CheckArc (gp);
238                 }
239
240                 [Test]
241                 public void AddArc_Float ()
242                 {
243                         GraphicsPath gp = new GraphicsPath ();
244                         gp.AddArc (1f, 1f, 2f, 2f, Pi4, Pi4);
245                         CheckArc (gp);
246                 }
247
248                 private void CheckBezier (GraphicsPath path)
249                 {
250                         Assert.AreEqual (4, path.PointCount, "PointCount");
251                         Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
252                         Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
253                         Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
254
255                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
256                         RectangleF rect = path.GetBounds ();
257                         Assert.AreEqual (1f, rect.X, "Bounds.X");
258                         Assert.AreEqual (1f, rect.Y, "Bounds.Y");
259                         Assert.AreEqual (3f, rect.Width, "Bounds.Width");
260                         Assert.AreEqual (3f, rect.Height, "Bounds.Height");
261
262                         Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
263                         Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
264                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
265                         Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
266                         Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
267                         Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
268                         Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
269                         Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
270                         Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
271                         Assert.AreEqual (4f, path.PathData.Points[3].X, "Points[3].X");
272                         Assert.AreEqual (4f, path.PathPoints[3].Y, "Points[3].Y");
273                         Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
274                 }
275
276                 [Test]
277                 public void AddBezier_Point ()
278                 {
279                         GraphicsPath gp = new GraphicsPath ();
280                         gp.AddBezier (new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4));
281                         CheckBezier (gp);
282                 }
283
284                 [Test]
285                 public void AddBezier_PointF ()
286                 {
287                         GraphicsPath gp = new GraphicsPath ();
288                         gp.AddBezier (new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f));
289                         CheckBezier (gp);
290                 }
291
292                 [Test]
293                 public void AddBezier_Int ()
294                 {
295                         GraphicsPath gp = new GraphicsPath ();
296                         gp.AddBezier (1, 1, 2, 2, 3, 3, 4, 4);
297                         CheckBezier (gp);
298                 }
299
300                 [Test]
301                 public void AddBezier_Float ()
302                 {
303                         GraphicsPath gp = new GraphicsPath ();
304                         gp.AddBezier (1f, 1f, 2f, 2f, 3f, 3f, 4f, 4f);
305                         CheckBezier (gp);
306                 }
307
308                 [Test]
309                 [ExpectedException (typeof (ArgumentNullException))]
310                 public void AddBeziers_Point_Null ()
311                 {
312                         new GraphicsPath ().AddBeziers ((Point[]) null);
313                 }
314
315                 [Test]
316                 [ExpectedException (typeof (ArgumentException))]
317                 public void AddBeziers_3_Points ()
318                 {
319                         GraphicsPath gp = new GraphicsPath ();
320                         gp.AddBeziers (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
321                 }
322
323                 [Test]
324                 public void AddBeziers_Point ()
325                 {
326                         GraphicsPath gp = new GraphicsPath ();
327                         gp.AddBeziers (new Point[4] { new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4) });
328                         CheckBezier (gp);
329                 }
330
331                 [Test]
332                 [ExpectedException (typeof (ArgumentNullException))]
333                 public void AddBeziers_PointF_Null ()
334                 {
335                         new GraphicsPath ().AddBeziers ((PointF[]) null);
336                 }
337
338                 [Test]
339                 [ExpectedException (typeof (ArgumentException))]
340                 public void AddBeziers_3_PointFs ()
341                 {
342                         GraphicsPath gp = new GraphicsPath ();
343                         gp.AddBeziers (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
344                 }
345
346                 [Test]
347                 public void AddBeziers_PointF ()
348                 {
349                         GraphicsPath gp = new GraphicsPath ();
350                         gp.AddBeziers (new PointF[4] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f) });
351                         CheckBezier (gp);
352                 }
353
354                 private void CheckEllipse (GraphicsPath path)
355                 {
356                         Assert.AreEqual (13, path.PathPoints.Length, "PathPoints");
357                         Assert.AreEqual (13, path.PathTypes.Length, "PathPoints");
358                         Assert.AreEqual (13, path.PathData.Points.Length, "PathData");
359
360                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
361                         RectangleF rect = path.GetBounds ();
362                         Assert.AreEqual (1f, rect.X, "Bounds.X");
363                         Assert.AreEqual (1f, rect.Y, "Bounds.Y");
364                         Assert.AreEqual (2f, rect.Width, "Bounds.Width");
365                         Assert.AreEqual (2f, rect.Height, "Bounds.Height");
366
367                         Assert.AreEqual (0, path.PathData.Types[0], "PathData.Types[0]");
368                         for (int i = 1; i < 12; i++)
369                                 Assert.AreEqual (3, path.PathTypes[i], "PathTypes" + i.ToString ());
370                         Assert.AreEqual (131, path.PathData.Types[12], "PathData.Types[12]");
371                 }
372
373                 [Test]
374                 public void AddEllipse_Rectangle ()
375                 {
376                         GraphicsPath gp = new GraphicsPath ();
377                         gp.AddEllipse (new Rectangle (1, 1, 2, 2));
378                         CheckEllipse (gp);
379                 }
380
381                 [Test]
382                 public void AddEllipse_RectangleF ()
383                 {
384                         GraphicsPath gp = new GraphicsPath ();
385                         gp.AddEllipse (new RectangleF (1f, 1f, 2f, 2f));
386                         CheckEllipse (gp);
387                 }
388
389                 [Test]
390                 public void AddEllipse_Int ()
391                 {
392                         GraphicsPath gp = new GraphicsPath ();
393                         gp.AddEllipse (1, 1, 2, 2);
394                         CheckEllipse (gp);
395                 }
396
397                 [Test]
398                 public void AddEllipse_Float ()
399                 {
400                         GraphicsPath gp = new GraphicsPath ();
401                         gp.AddEllipse (1f, 1f, 2f, 2f);
402                         CheckEllipse (gp);
403                 }
404
405                 private void CheckLine (GraphicsPath path)
406                 {
407                         Assert.AreEqual (2, path.PathPoints.Length, "PathPoints");
408                         Assert.AreEqual (2, path.PathTypes.Length, "PathPoints");
409                         Assert.AreEqual (2, path.PathData.Points.Length, "PathData");
410
411                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
412                         RectangleF rect = path.GetBounds ();
413                         Assert.AreEqual (1f, rect.X, "Bounds.X");
414                         Assert.AreEqual (1f, rect.Y, "Bounds.Y");
415                         Assert.AreEqual (1f, rect.Width, "Bounds.Width");
416                         Assert.AreEqual (1f, rect.Height, "Bounds.Height");
417
418                         Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
419                         Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
420                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
421                         Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
422                         Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
423                         Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
424                 }
425
426                 [Test]
427                 public void AddLine_Point ()
428                 {
429                         GraphicsPath gp = new GraphicsPath ();
430                         gp.AddLine (new Point (1, 1), new Point (2, 2));
431                         CheckLine (gp);
432                 }
433
434                 [Test]
435                 public void AddLine_PointF ()
436                 {
437                         GraphicsPath gp = new GraphicsPath ();
438                         gp.AddLine (new PointF (1f, 1f), new PointF (2f, 2f));
439                         CheckLine (gp);
440                 }
441
442                 [Test]
443                 public void AddLine_Int ()
444                 {
445                         GraphicsPath gp = new GraphicsPath ();
446                         gp.AddLine (1, 1, 2, 2);
447                         CheckLine (gp);
448                 }
449
450                 [Test]
451                 public void AddLine_Float ()
452                 {
453                         GraphicsPath gp = new GraphicsPath ();
454                         gp.AddLine (1f, 1f, 2f, 2f);
455                         CheckLine (gp);
456                 }
457
458                 [Test]
459                 public void AddLine_SamePoint ()
460                 {
461                         GraphicsPath gp = new GraphicsPath ();
462                         gp.AddLine (new Point (1, 1), new Point (1, 1));
463                         Assert.AreEqual (2, gp.PointCount, "PointCount");
464                         Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
465                         Assert.AreEqual (1, gp.PathTypes[1], "PathTypes[1]");
466                 }
467
468                 [Test]
469                 [ExpectedException (typeof (ArgumentNullException))]
470                 public void AddLines_Point_Null ()
471                 {
472                         new GraphicsPath ().AddLines ((Point[])null);
473                 }
474
475                 [Test]
476                 [ExpectedException (typeof (ArgumentException))]
477                 public void AddLines_Point_0 ()
478                 {
479                         GraphicsPath gp = new GraphicsPath ();
480                         gp.AddLines (new Point[0]);
481                         CheckLine (gp);
482                 }
483
484                 [Test]
485                 public void AddLines_Point_1 ()
486                 {
487                         GraphicsPath gp = new GraphicsPath ();
488                         gp.AddLines (new Point[1] { new Point (1, 1) });
489                         // Special case - a line with a single point is valid
490                         Assert.AreEqual (1, gp.PointCount, "PointCount");
491                         Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
492                 }
493
494                 [Test]
495                 public void AddLines_Point ()
496                 {
497                         GraphicsPath gp = new GraphicsPath ();
498                         gp.AddLines (new Point[2] { new Point (1, 1), new Point (2, 2) });
499                         CheckLine (gp);
500                 }
501
502                 [Test]
503                 [ExpectedException (typeof (ArgumentNullException))]
504                 public void AddLines_PointF_Null ()
505                 {
506                         new GraphicsPath ().AddLines ((PointF[]) null);
507                 }
508
509                 [Test]
510                 [ExpectedException (typeof (ArgumentException))]
511                 public void AddLines_PointF_0 ()
512                 {
513                         GraphicsPath gp = new GraphicsPath ();
514                         gp.AddLines (new PointF[0]);
515                         CheckLine (gp);
516                 }
517
518                 [Test]
519                 public void AddLines_PointF_1 ()
520                 {
521                         GraphicsPath gp = new GraphicsPath ();
522                         gp.AddLines (new PointF[1] { new PointF (1f, 1f) });
523                         // Special case - a line with a single point is valid
524                         Assert.AreEqual (1, gp.PointCount, "PointCount");
525                         Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
526                 }
527
528                 [Test]
529                 public void AddLines_PointF ()
530                 {
531                         GraphicsPath gp = new GraphicsPath ();
532                         gp.AddLines (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
533                         CheckLine (gp);
534                 }
535
536                 private void CheckPie (GraphicsPath path)
537                 {
538                         // the number of points generated for a Pie isn't the same between Mono and MS
539 #if false
540                         Assert.AreEqual (5, path.PathPoints.Length, "PathPoints");
541                         Assert.AreEqual (5, path.PathTypes.Length, "PathPoints");
542                         Assert.AreEqual (5, path.PathData.Points.Length, "PathData");
543
544                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
545                         RectangleF rect = path.GetBounds ();
546                         Assert.AreEqual (2f, rect.X, "Bounds.X");
547                         Assert.AreEqual (2f, rect.Y, "Bounds.Y");
548                         Assert.AreEqual (0.9999058f, rect.Width, "Bounds.Width");
549                         Assert.AreEqual (0.0274119377f, rect.Height, "Bounds.Height");
550
551                         Assert.AreEqual (2f, path.PathData.Points[0].X, "Points[0].X");
552                         Assert.AreEqual (2f, path.PathPoints[0].Y, "Points[0].Y");
553                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
554                         Assert.AreEqual (2.99990582f, path.PathData.Points[1].X, "Points[1].X");
555                         Assert.AreEqual (2.01370716f, path.PathPoints[1].Y, "Points[1].Y");
556                         Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
557                         Assert.AreEqual (2.99984312f, path.PathData.Points[2].X, "Points[2].X");
558                         Assert.AreEqual (2.018276f, path.PathPoints[2].Y, "Points[2].Y");
559                         Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
560                         Assert.AreEqual (2.99974918f, path.PathData.Points[3].X, "Points[2].X");
561                         Assert.AreEqual (2.02284455f, path.PathPoints[3].Y, "Points[2].Y");
562                         Assert.AreEqual (3, path.PathData.Types[3], "Types[2]");
563                         Assert.AreEqual (2.999624f, path.PathData.Points[4].X, "Points[3].X");
564                         Assert.AreEqual (2.027412f, path.PathPoints[4].Y, "Points[3].Y");
565                         Assert.AreEqual (131, path.PathTypes[4], "Types[3]");
566 #endif
567                 }
568
569                 [Test]
570                 public void AddPie_Rect ()
571                 {
572                         GraphicsPath gp = new GraphicsPath ();
573                         gp.AddPie (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
574                         CheckPie (gp);
575                 }
576
577                 [Test]
578                 public void AddPie_Int ()
579                 {
580                         GraphicsPath gp = new GraphicsPath ();
581                         gp.AddPie (1, 1, 2, 2, Pi4, Pi4);
582                         CheckPie (gp);
583                 }
584
585                 [Test]
586                 public void AddPie_Float ()
587                 {
588                         GraphicsPath gp = new GraphicsPath ();
589                         gp.AddPie (1f, 1f, 2f, 2f, Pi4, Pi4);
590                         CheckPie (gp);
591                 }
592
593                 private void CheckPolygon (GraphicsPath path)
594                 {
595                         // an extra point is generated by Mono (libgdiplus)
596 #if false
597                         Assert.AreEqual (3, path.PathPoints.Length, "PathPoints");
598                         Assert.AreEqual (3, path.PathTypes.Length, "PathPoints");
599                         Assert.AreEqual (3, path.PathData.Points.Length, "PathData");
600 #endif
601                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
602                         RectangleF rect = path.GetBounds ();
603                         Assert.AreEqual (1f, rect.X, "Bounds.X");
604                         Assert.AreEqual (1f, rect.Y, "Bounds.Y");
605                         Assert.AreEqual (2f, rect.Width, "Bounds.Width");
606                         Assert.AreEqual (2f, rect.Height, "Bounds.Height");
607
608                         Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
609                         Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
610                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
611                         Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
612                         Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
613                         Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
614                         Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
615                         Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
616                         // the extra point change the type of the last point
617 #if false
618                         Assert.AreEqual (129, path.PathData.Types[2], "Types[2]");
619 #endif
620                 }
621
622                 [Test]
623                 [ExpectedException (typeof (ArgumentNullException))]
624                 public void AddPolygon_Point_Null ()
625                 {
626                         new GraphicsPath ().AddPolygon ((Point[]) null);
627                 }
628
629                 [Test]
630                 [ExpectedException (typeof (ArgumentException))]
631                 public void AddPolygon_Point_Empty ()
632                 {
633                         new GraphicsPath ().AddPolygon (new Point[0]);
634                 }
635
636                 [Test]
637                 [ExpectedException (typeof (ArgumentException))]
638                 public void AddPolygon_Point_1 ()
639                 {
640                         GraphicsPath gp = new GraphicsPath ();
641                         gp.AddPolygon (new Point[1] { new Point (1, 1) });
642                 }
643
644                 [Test]
645                 [ExpectedException (typeof (ArgumentException))]
646                 public void AddPolygon_Point_2 ()
647                 {
648                         GraphicsPath gp = new GraphicsPath ();
649                         gp.AddPolygon (new Point[2] { new Point (1, 1), new Point (2, 2) });
650                 }
651
652                 [Test]
653                 public void AddPolygon_Point_3 ()
654                 {
655                         GraphicsPath gp = new GraphicsPath ();
656                         gp.AddPolygon (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
657                         CheckPolygon (gp);
658                 }
659
660                 [Test]
661                 [ExpectedException (typeof (ArgumentNullException))]
662                 public void AddPolygon_PointF_Null ()
663                 {
664                         new GraphicsPath ().AddPolygon ((PointF[]) null);
665                 }
666
667                 [Test]
668                 [ExpectedException (typeof (ArgumentException))]
669                 public void AddPolygon_PointF_Empty ()
670                 {
671                         new GraphicsPath ().AddPolygon (new PointF[0]);
672                 }
673
674                 [Test]
675                 [ExpectedException (typeof (ArgumentException))]
676                 public void AddPolygon_PointF_1 ()
677                 {
678                         GraphicsPath gp = new GraphicsPath ();
679                         gp.AddPolygon (new PointF[1] { new PointF (1f, 1f) });
680                 }
681
682                 [Test]
683                 [ExpectedException (typeof (ArgumentException))]
684                 public void AddPolygon_PointF_2 ()
685                 {
686                         GraphicsPath gp = new GraphicsPath ();
687                         gp.AddPolygon (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
688                 }
689
690                 [Test]
691                 public void AddPolygon_PointF_3 ()
692                 {
693                         GraphicsPath gp = new GraphicsPath ();
694                         gp.AddPolygon (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
695                         CheckPolygon (gp);
696                 }
697
698                 private void CheckRectangle (GraphicsPath path, int count)
699                 {
700                         Assert.AreEqual (count, path.PathPoints.Length, "PathPoints");
701                         Assert.AreEqual (count, path.PathTypes.Length, "PathPoints");
702                         Assert.AreEqual (count, path.PathData.Points.Length, "PathData");
703
704                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
705                         RectangleF rect = path.GetBounds ();
706                         Assert.AreEqual (1f, rect.X, "Bounds.X");
707                         Assert.AreEqual (1f, rect.Y, "Bounds.Y");
708                         Assert.AreEqual (2f, rect.Width, "Bounds.Width");
709                         Assert.AreEqual (2f, rect.Height, "Bounds.Height");
710
711                         // check first four points (first rectangle)
712                         Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
713                         Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
714                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
715                         Assert.AreEqual (3f, path.PathData.Points[1].X, "Points[1].X");
716                         Assert.AreEqual (1f, path.PathPoints[1].Y, "Points[1].Y");
717                         Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
718                         Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
719                         Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
720                         Assert.AreEqual (1, path.PathData.Types[2], "Types[2]");
721                         Assert.AreEqual (1f, path.PathData.Points[3].X, "Points[3].X");
722                         Assert.AreEqual (3f, path.PathPoints[3].Y, "Points[3].Y");
723                         Assert.AreEqual (129, path.PathTypes[3], "Types[3]");
724                 }
725
726                 [Test]
727                 public void AddRectangle_Int ()
728                 {
729                         GraphicsPath gp = new GraphicsPath ();
730                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
731                         CheckRectangle (gp, 4);
732                 }
733
734                 [Test]
735                 public void AddRectangle_Float ()
736                 {
737                         GraphicsPath gp = new GraphicsPath ();
738                         gp.AddRectangle (new RectangleF (1f, 1f, 2f, 2f));
739                         CheckRectangle (gp, 4);
740                 }
741
742                 [Test]
743                 [ExpectedException (typeof (ArgumentNullException))]
744                 public void AddRectangles_Int_Null ()
745                 {
746                         GraphicsPath gp = new GraphicsPath ();
747                         gp.AddRectangles ((Rectangle[]) null);
748                 }
749
750                 [Test]
751                 [ExpectedException (typeof (ArgumentException))]
752                 public void AddRectangles_Int_Empty ()
753                 {
754                         GraphicsPath gp = new GraphicsPath ();
755                         gp.AddRectangles (new Rectangle[0]);
756                         CheckRectangle (gp, 4);
757                 }
758
759                 [Test]
760                 public void AddRectangles_Int ()
761                 {
762                         GraphicsPath gp = new GraphicsPath ();
763                         gp.AddRectangles (new Rectangle[1] { new Rectangle (1, 1, 2, 2) });
764                         CheckRectangle (gp, 4);
765                 }
766
767                 [Test]
768                 [ExpectedException (typeof (ArgumentNullException))]
769                 public void AddRectangles_Float_Null ()
770                 {
771                         GraphicsPath gp = new GraphicsPath ();
772                         gp.AddRectangles ((RectangleF[]) null);
773                 }
774
775                 [Test]
776                 [ExpectedException (typeof (ArgumentException))]
777                 public void AddRectangles_Float_Empty ()
778                 {
779                         GraphicsPath gp = new GraphicsPath ();
780                         gp.AddRectangles ( new RectangleF[0]);
781                         CheckRectangle (gp, 4);
782                 }
783
784                 [Test]
785                 public void AddRectangles_Float ()
786                 {
787                         GraphicsPath gp = new GraphicsPath ();
788                         gp.AddRectangles (new RectangleF [1] { new RectangleF (1f, 1f, 2f, 2f) });
789                         CheckRectangle (gp, 4);
790                 }
791
792                 [Test]
793                 public void AddRectangles_Two ()
794                 {
795                         GraphicsPath gp = new GraphicsPath ();
796                         gp.AddRectangles (new RectangleF[2] {
797                                 new RectangleF (1f, 1f, 2f, 2f),
798                                 new RectangleF (2f, 2f, 1f, 1f) } );
799                         RectangleF rect = gp.GetBounds ();
800                         Assert.AreEqual (1f, rect.X, "Bounds.X");
801                         Assert.AreEqual (1f, rect.Y, "Bounds.Y");
802                         Assert.AreEqual (2f, rect.Width, "Bounds.Width");
803                         Assert.AreEqual (2f, rect.Height, "Bounds.Height");
804                         // second rectangle is completely within the first one
805                         CheckRectangle (gp, 8);
806                 }
807
808                 [Test]
809                 [ExpectedException (typeof (ArgumentNullException))]
810                 public void AddPath_Null ()
811                 {
812                         new GraphicsPath ().AddPath (null, false);
813                 }
814
815                 [Test]
816                 public void AddPath ()
817                 {
818                         GraphicsPath gpr = new GraphicsPath ();
819                         gpr.AddRectangle (new Rectangle (1, 1, 2, 2));
820                         GraphicsPath gp = new GraphicsPath ();
821                         gp.AddPath (gpr, true);
822                         CheckRectangle (gp, 4);
823                 }
824
825                 private void CheckClosedCurve (GraphicsPath path)
826                 {
827                         Assert.AreEqual (10, path.PathPoints.Length, "PathPoints");
828                         Assert.AreEqual (10, path.PathTypes.Length, "PathPoints");
829                         Assert.AreEqual (10, path.PathData.Points.Length, "PathData");
830
831                         // GetBounds (well GdipGetPathWorldBounds) isn't very precise with curves
832                         RectangleF rect = path.GetBounds ();
833                         Assert.AreEqual (0.8333333f, rect.X, 0.2f, "Bounds.X");
834                         Assert.AreEqual (0.8333333f, rect.Y, 0.2f, "Bounds.Y");
835                         Assert.AreEqual (2.33333278f, rect.Width, 0.4f, "Bounds.Width");
836                         Assert.AreEqual (2.33333278f, rect.Height, 0.4f, "Bounds.Height");
837
838                         Assert.AreEqual (0, path.PathData.Types[0], "PathData.Types[0]");
839                         for (int i = 1; i < 9; i++)
840                                 Assert.AreEqual (3, path.PathTypes[i], "PathTypes" + i.ToString ());
841                         Assert.AreEqual (131, path.PathData.Types[9], "PathData.Types[9]");
842                 }
843
844                 [Test]
845                 [ExpectedException (typeof (ArgumentNullException))]
846                 public void AddClosedCurve_Point_Null ()
847                 {
848                         new GraphicsPath ().AddClosedCurve ((Point[])null);
849                 }
850
851                 [Test]
852                 [ExpectedException (typeof (ArgumentException))]
853                 public void AddClosedCurve_Point_0 ()
854                 {
855                         GraphicsPath gp = new GraphicsPath ();
856                         gp.AddClosedCurve (new Point [0]);
857                 }
858
859                 [Test]
860                 [ExpectedException (typeof (ArgumentException))]
861                 public void AddClosedCurve_Point_1 ()
862                 {
863                         GraphicsPath gp = new GraphicsPath ();
864                         gp.AddClosedCurve (new Point[1] { new Point (1, 1) });
865                 }
866
867                 [Test]
868                 [ExpectedException (typeof (ArgumentException))]
869                 public void AddClosedCurve_Point_2 ()
870                 {
871                         GraphicsPath gp = new GraphicsPath ();
872                         gp.AddClosedCurve (new Point[2] { new Point (1, 1), new Point (2, 2) });
873                 }
874
875                 [Test]
876                 public void AddClosedCurve_Point_3 ()
877                 {
878                         GraphicsPath gp = new GraphicsPath ();
879                         gp.AddClosedCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
880                         CheckClosedCurve (gp);
881                 }
882
883                 [Test]
884                 [ExpectedException (typeof (ArgumentNullException))]
885                 public void AddClosedCurve_PointF_Null ()
886                 {
887                         new GraphicsPath ().AddClosedCurve ((PointF[]) null);
888                 }
889
890                 [Test]
891                 [ExpectedException (typeof (ArgumentException))]
892                 public void AddClosedCurve_PointF_0 ()
893                 {
894                         GraphicsPath gp = new GraphicsPath ();
895                         gp.AddClosedCurve (new PointF[0]);
896                 }
897
898                 [Test]
899                 [ExpectedException (typeof (ArgumentException))]
900                 public void AddClosedCurve_PointF_1 ()
901                 {
902                         GraphicsPath gp = new GraphicsPath ();
903                         gp.AddClosedCurve (new PointF[1] { new PointF (1f, 1f) });
904                 }
905
906                 [Test]
907                 [ExpectedException (typeof (ArgumentException))]
908                 public void AddClosedCurve_PointF_2 ()
909                 {
910                         GraphicsPath gp = new GraphicsPath ();
911                         gp.AddClosedCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
912                 }
913
914                 [Test]
915                 public void AddClosedCurve_PointF_3 ()
916                 {
917                         GraphicsPath gp = new GraphicsPath ();
918                         gp.AddClosedCurve (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
919                         CheckClosedCurve (gp);
920                 }
921
922                 private void CheckCurve (GraphicsPath path)
923                 {
924                         Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
925                         Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
926                         Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
927
928                         // GetBounds (well GdipGetPathWorldBounds) isn't implemented
929                         RectangleF rect = path.GetBounds ();
930                         Assert.AreEqual (1.0f, rect.X, "Bounds.X");
931                         Assert.AreEqual (1.0f, rect.Y, "Bounds.Y");
932                         Assert.AreEqual (1.0f, rect.Width, "Bounds.Width");
933                         Assert.AreEqual (1.0f, rect.Height, "Bounds.Height");
934
935                         Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
936                         Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
937                         Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
938                         // Mono has wrong? results
939 #if false
940                         Assert.AreEqual (1.16666663f, path.PathData.Points[1].X, "Points[1].X");
941                         Assert.AreEqual (1.16666663f, path.PathPoints[1].Y, "Points[1].Y");
942 #endif
943                         Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
944                         // Mono has wrong? results
945 #if false
946                         Assert.AreEqual (1.83333325f, path.PathData.Points[2].X, "Points[2].X");
947                         Assert.AreEqual (1.83333325f, path.PathPoints[2].Y, "Points[2].Y");
948 #endif
949                         Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
950                         Assert.AreEqual (2f, path.PathData.Points[3].X, "Points[3].X");
951                         Assert.AreEqual (2f, path.PathPoints[3].Y, "Points[3].Y");
952                         Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
953                 }
954
955                 [Test]
956                 [ExpectedException (typeof (ArgumentNullException))]
957                 public void AddCurve_Point_Null ()
958                 {
959                         new GraphicsPath ().AddCurve ((Point[]) null);
960                 }
961
962                 [Test]
963                 [ExpectedException (typeof (ArgumentException))]
964                 public void AddCurve_Point_0 ()
965                 {
966                         GraphicsPath gp = new GraphicsPath ();
967                         gp.AddCurve (new Point[0]);
968                 }
969
970                 [Test]
971                 [ExpectedException (typeof (ArgumentException))]
972                 public void AddCurve_Point_1 ()
973                 {
974                         GraphicsPath gp = new GraphicsPath ();
975                         gp.AddCurve (new Point[1] { new Point (1, 1) });
976                 }
977
978                 [Test]
979                 public void AddCurve_Point_2 ()
980                 {
981                         GraphicsPath gp = new GraphicsPath ();
982                         gp.AddCurve (new Point[2] { new Point (1, 1), new Point (2, 2) });
983                         CheckCurve (gp);
984                         // note: GdipAddPathCurveI allows adding a "curve" with only 2 points (a.k.a. a line ;-)
985                         gp.Dispose ();
986                 }
987
988                 [Test]
989                 public void AddCurve_Point_2_Tension ()
990                 {
991                         GraphicsPath gp = new GraphicsPath ();
992                         gp.AddCurve (new Point[2] { new Point (1, 1), new Point (2, 2) }, 1.0f);
993                         CheckCurve (gp);
994                         // note: GdipAddPathCurve2I allows adding a "curve" with only 2 points (a.k.a. a line ;-)
995                         gp.Dispose ();
996                 }
997
998                 [Test]
999                 [ExpectedException (typeof (ArgumentException))]
1000                 public void AddCurve3_Point_2 ()
1001                 {
1002                         GraphicsPath gp = new GraphicsPath ();
1003                         gp.AddCurve (new Point[2] { new Point (1, 1), new Point (2, 2) }, 0, 2, 0.5f);
1004                         // adding only two points isn't supported by GdipAddCurve3I
1005                 }
1006
1007                 [Test]
1008                 [ExpectedException (typeof (ArgumentNullException))]
1009                 public void AddCurve_PointF_Null ()
1010                 {
1011                         new GraphicsPath ().AddCurve ((PointF[]) null);
1012                 }
1013
1014                 [Test]
1015                 [ExpectedException (typeof (ArgumentException))]
1016                 public void AddCurve_PointF_0 ()
1017                 {
1018                         GraphicsPath gp = new GraphicsPath ();
1019                         gp.AddCurve (new PointF[0]);
1020                 }
1021
1022                 [Test]
1023                 [ExpectedException (typeof (ArgumentException))]
1024                 public void AddCurve_PointF_1 ()
1025                 {
1026                         GraphicsPath gp = new GraphicsPath ();
1027                         gp.AddCurve (new PointF[1] { new PointF (1f, 1f) });
1028                 }
1029
1030                 [Test]
1031                 public void AddCurve_PointF_2 ()
1032                 {
1033                         GraphicsPath gp = new GraphicsPath ();
1034                         gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
1035                         CheckCurve (gp);
1036                         // note: GdipAddPathCurve allows adding a "curve" with only 2 points (a.k.a. a line ;-)
1037                         gp.Dispose ();
1038                 }
1039
1040                 [Test]
1041                 public void AddCurve_PoinFt_2_Tension ()
1042                 {
1043                         GraphicsPath gp = new GraphicsPath ();
1044                         gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) }, 1.0f);
1045                         CheckCurve (gp);
1046                         // note: GdipAddPathCurve2 allows adding a "curve" with only 2 points (a.k.a. a line ;-)
1047                         gp.Dispose ();
1048                 }
1049
1050                 [Test]
1051                 [ExpectedException (typeof (ArgumentException))]
1052                 public void AddCurve3_PointF_2 ()
1053                 {
1054                         GraphicsPath gp = new GraphicsPath ();
1055                         gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) }, 0, 2, 0.5f);
1056                         // adding only two points isn't supported by GdipAddCurve3
1057                 }
1058
1059                 [Test]
1060                 public void AddCurve_LargeTension ()
1061                 {
1062                         GraphicsPath gp = new GraphicsPath ();
1063                         gp.AddCurve (new PointF[3] { new PointF (1f, 1f), new PointF (0f, 20f), new PointF (20f, 0f) }, 0, 2, Single.MaxValue);
1064                         Assert.AreEqual (7, gp.PointCount, "PointCount");
1065                         gp.Dispose ();
1066                 }
1067
1068                 [Test]
1069                 [ExpectedException (typeof (ArgumentException))]
1070                 public void AddCurve_ZeroSegments ()
1071                 {
1072                         GraphicsPath gp = new GraphicsPath ();
1073                         gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) }, 0, 0, 0.5f);
1074                 }
1075
1076                 [Test]
1077                 [ExpectedException (typeof (ArgumentException))]
1078                 public void AddCurve_NegativeSegments ()
1079                 {
1080                         GraphicsPath gp = new GraphicsPath ();
1081                         gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) }, 0, -1, 0.5f);
1082                 }
1083
1084                 [Test]
1085                 [ExpectedException (typeof (ArgumentException))]
1086                 public void AddCurve_OffsetTooLarge ()
1087                 {
1088                         GraphicsPath gp = new GraphicsPath ();
1089                         gp.AddCurve (new PointF[3] { new PointF (1f, 1f), new PointF (0f, 20f), new PointF (20f, 0f) }, 1, 2, 0.5f);
1090                 }
1091
1092                 [Test]
1093                 public void AddCurve_Offset ()
1094                 {
1095                         GraphicsPath gp = new GraphicsPath ();
1096                         gp.AddCurve (new PointF[4] { new PointF (1f, 1f), new PointF (0f, 20f), new PointF (20f, 0f), new PointF (0f, 10f) }, 1, 2, 0.5f);
1097                         Assert.AreEqual (7, gp.PointCount, "PointCount");
1098                         gp.Dispose ();
1099                 }
1100
1101                 private FontFamily GetFontFamily ()
1102                 {
1103                         try {
1104                                 return FontFamily.GenericMonospace;
1105                         }
1106                         catch (ArgumentException) {
1107                                 Assert.Ignore ("GenericMonospace FontFamily couldn't be found");
1108                                 return null;
1109                         }
1110                 }
1111
1112                 [Test]
1113                 [ExpectedException (typeof (NullReferenceException))]
1114                 public void AddString_NullString ()
1115                 {
1116                         GraphicsPath gp = new GraphicsPath ();
1117                         FontFamily ff = GetFontFamily ();
1118                         gp.AddString (null, ff, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
1119                 }
1120
1121                 [Test]
1122                 public void AddString_EmptyString ()
1123                 {
1124                         GraphicsPath gp = new GraphicsPath ();
1125                         FontFamily ff = GetFontFamily ();
1126                         gp.AddString (String.Empty, ff, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
1127                         Assert.AreEqual (0, gp.PointCount, "PointCount");
1128                 }
1129
1130                 [Test]
1131                 [ExpectedException (typeof (ArgumentException))]
1132                 public void AddString_NullFontFamily ()
1133                 {
1134                         GraphicsPath gp = new GraphicsPath ();
1135                         gp.AddString ("mono", null, 0, 10, new Point (10, 10), StringFormat.GenericDefault);
1136                 }
1137
1138                 [Test]
1139                 public void AddString_NegativeSize ()
1140                 {
1141                         GraphicsPath gp = new GraphicsPath ();
1142                         FontFamily ff = GetFontFamily ();
1143                         gp.AddString ("mono", ff, 0, -10, new Point (10, 10), StringFormat.GenericDefault);
1144                         Assert.IsTrue (gp.PointCount > 0, "PointCount");
1145                 }
1146
1147                 [Test]
1148                 [Category ("NotWorking")] // StringFormat not yet supported in libgdiplus
1149                 public void AddString_StringFormat ()
1150                 {
1151                         FontFamily ff = GetFontFamily ();
1152                         // null maps to ?
1153                         GraphicsPath gp1 = new GraphicsPath ();
1154                         gp1.AddString ("mono", ff, 0, 10, new RectangleF (10, 10, 10, 10), null);
1155
1156                         // StringFormat.GenericDefault
1157                         GraphicsPath gp2 = new GraphicsPath ();
1158                         gp2.AddString ("mono", ff, 0, 10, new RectangleF (10, 10, 10, 10), StringFormat.GenericDefault);
1159                         Assert.AreEqual (gp1.PointCount, gp2.PointCount, "GenericDefault");
1160
1161                         // StringFormat.GenericTypographic
1162                         GraphicsPath gp3 = new GraphicsPath ();
1163                         gp3.AddString ("mono", ff, 0, 10, new RectangleF (10, 10, 10, 10), StringFormat.GenericTypographic);
1164                         Assert.IsFalse (gp1.PointCount == gp3.PointCount, "GenericTypographic");
1165                 }
1166
1167                 [Test]
1168                 public void GetBounds_Empty_Empty ()
1169                 {
1170                         GraphicsPath gp = new GraphicsPath ();
1171                         RectangleF rect = gp.GetBounds ();
1172                         Assert.AreEqual (0.0f, rect.X, "Bounds.X");
1173                         Assert.AreEqual (0.0f, rect.Y, "Bounds.Y");
1174                         Assert.AreEqual (0.0f, rect.Width, "Bounds.Width");
1175                         Assert.AreEqual (0.0f, rect.Height, "Bounds.Height");
1176                 }
1177
1178                 private void CheckRectangleBounds (RectangleF rect)
1179                 {
1180                         Assert.AreEqual (1.0f, rect.X, "Bounds.X");
1181                         Assert.AreEqual (1.0f, rect.Y, "Bounds.Y");
1182                         Assert.AreEqual (2.0f, rect.Width, "Bounds.Width");
1183                         Assert.AreEqual (2.0f, rect.Height, "Bounds.Height");
1184                 }
1185
1186                 [Test]
1187                 public void GetBounds_Empty_Rectangle ()
1188                 {
1189                         GraphicsPath gp = new GraphicsPath ();
1190                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1191                         CheckRectangleBounds (gp.GetBounds ());
1192                 }
1193
1194                 [Test]
1195                 public void GetBounds_Null_Rectangle ()
1196                 {
1197                         GraphicsPath gp = new GraphicsPath ();
1198                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1199                         CheckRectangleBounds (gp.GetBounds (null));
1200                 }
1201
1202                 [Test]
1203                 public void GetBounds_MatrixEmpty_Rectangle ()
1204                 {
1205                         GraphicsPath gp = new GraphicsPath ();
1206                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1207                         CheckRectangleBounds (gp.GetBounds (new Matrix ()));
1208                 }
1209
1210                 [Test]
1211                 public void GetBounds_NullNull_Rectangle ()
1212                 {
1213                         GraphicsPath gp = new GraphicsPath ();
1214                         gp.AddRectangle (new Rectangle (1, 1, 2, 2));
1215                         CheckRectangleBounds (gp.GetBounds (null, null));
1216                 }
1217
1218                 [Test]
1219                 [Category ("NotWorking")] // can't/wont duplicate the lack of precision
1220                 public void GetBounds_WithPen ()
1221                 {
1222                         Rectangle rect = new Rectangle (1, 1, 2, 2);
1223                         Pen p = new Pen (Color.Aqua, 0);
1224                         GraphicsPath gp = new GraphicsPath ();
1225                         gp.AddRectangle (rect);
1226
1227                         RectangleF bounds = gp.GetBounds (null, p);
1228                         // those bounds doesn't make any sense (even visually)
1229                         // probably null gets mis-interpreted ???
1230                         Assert.AreEqual (-6.09999943f, bounds.X, "NullMatrix.Bounds.X");
1231                         Assert.AreEqual (-6.09999943f, bounds.Y, "NullMatrix.Bounds.Y");
1232                         Assert.AreEqual (16.1999989f, bounds.Width, "NullMatrix.Bounds.Width");
1233                         Assert.AreEqual (16.1999989f, bounds.Height, "NullMatrix.Bounds.Height");
1234
1235                         Matrix m = new Matrix ();
1236                         bounds = gp.GetBounds (m, p);
1237                         Assert.AreEqual (-0.419999957f, bounds.X, "EmptyMatrix.Bounds.X");
1238                         Assert.AreEqual (-0.419999957f, bounds.Y, "EmptyMatrix.Bounds.Y");
1239                         Assert.AreEqual (4.83999968f, bounds.Width, "EmptyMatrix.Bounds.Width");
1240                         Assert.AreEqual (4.83999968f, bounds.Height, "EmptyMatrix.Bounds.Height");
1241                         // visually we can see the bounds just a pixel bigger than the rectangle
1242
1243                         gp = new GraphicsPath ();
1244                         gp.AddRectangle (rect);
1245                         gp.Widen (p);
1246                         bounds = gp.GetBounds (null);
1247                         Assert.AreEqual (0.499999523f, bounds.X, "WidenNullMatrix.Bounds.X");
1248                         Assert.AreEqual (0.499999523f, bounds.Y, "WidenNullMatrix.Bounds.Y");
1249                         Assert.AreEqual (3.000001f, bounds.Width, "WidenNullMatrix.Bounds.Width");
1250                         Assert.AreEqual (3.000001f, bounds.Height, "WidenNullMatrix.Bounds.Height");
1251
1252                         bounds = gp.GetBounds (m);
1253                         Assert.AreEqual (0.499999523f, bounds.X, "WidenEmptyMatrix.Bounds.X");
1254                         Assert.AreEqual (0.499999523f, bounds.Y, "WidenEmptyMatrix.Bounds.Y");
1255                         Assert.AreEqual (3.000001f, bounds.Width, "WidenEmptyMatrix.Bounds.Width");
1256                         Assert.AreEqual (3.000001f, bounds.Height, "WidenEmptyMatrix.Bounds.Height");
1257                 }
1258
1259                 private void CheckPieBounds (RectangleF rect)
1260                 {
1261                         Assert.AreEqual (60.0f, rect.X, 1, "Bounds.X");
1262                         Assert.AreEqual (60.0f, rect.Y, 1, "Bounds.Y");
1263                         Assert.AreEqual (43.3f, rect.Width, 1, "Bounds.Width");
1264                         Assert.AreEqual (48.3f, rect.Height, 1, "Bounds.Height");
1265                 }
1266
1267                 [Test]
1268                 public void GetBounds_Empty_Pie ()
1269                 {
1270                         GraphicsPath gp = new GraphicsPath ();
1271                         gp.AddPie (10, 10, 100, 100, 30, 45);
1272                         CheckPieBounds (gp.GetBounds ());
1273                         gp.Dispose ();
1274                 }
1275
1276                 [Test]
1277                 public void GetBounds_Null_Pie ()
1278                 {
1279                         GraphicsPath gp = new GraphicsPath ();
1280                         gp.AddPie (10, 10, 100, 100, 30, 45);
1281                         CheckPieBounds (gp.GetBounds (null));
1282                         gp.Dispose ();
1283                 }
1284
1285                 [Test]
1286                 public void GetBounds_MatrixEmpty_Pie ()
1287                 {
1288                         GraphicsPath gp = new GraphicsPath ();
1289                         gp.AddPie (10, 10, 100, 100, 30, 45);
1290                         CheckPieBounds (gp.GetBounds (new Matrix ()));
1291                         gp.Dispose ();
1292                 }
1293
1294                 [Test]
1295                 public void GetBounds_NullNull_Pie ()
1296                 {
1297                         GraphicsPath gp = new GraphicsPath ();
1298                         gp.AddPie (10, 10, 100, 100, 30, 45);
1299                         CheckPieBounds (gp.GetBounds (null, null));
1300                         gp.Dispose ();
1301                 }
1302
1303                 [Test]
1304                 public void GetBounds_Empty_ClosedCurve ()
1305                 {
1306                         GraphicsPath gp = new GraphicsPath ();
1307                         gp.AddClosedCurve (new Point[4] { new Point (20, 100), new Point (70, 10),
1308                                 new Point (130, 200), new Point (180, 100) });
1309 #if false
1310                         // so far from reality that it's totally useless
1311                         Assert.AreEqual (1.666666f, rect.X, 0.00001, "Bounds.X");
1312                         Assert.AreEqual (-6.66666f, rect.Y, 1, "Bounds.Y");
1313                         Assert.AreEqual (196.6666f, rect.Width, 1, "Bounds.Width");
1314                         Assert.AreEqual (221.6666f, rect.Height, 1, "Bounds.Height");
1315 #endif
1316                         gp.Dispose ();
1317                 }
1318
1319                 [Test]
1320                 [ExpectedException (typeof (ArgumentNullException))]
1321                 public void Transform_Null ()
1322                 {
1323                         new GraphicsPath ().Transform (null);
1324                 }
1325
1326                 [Test]
1327                 public void Transform_Empty ()
1328                 {
1329                         // no points in path and no exception
1330                         new GraphicsPath ().Transform (new Matrix ());
1331                 }
1332
1333                 private void ComparePaths (GraphicsPath expected, GraphicsPath actual)
1334                 {
1335                         Assert.AreEqual (expected.PointCount, actual.PointCount, "PointCount");
1336                         for (int i = 0; i < expected.PointCount; i++) {
1337                                 Assert.AreEqual (expected.PathPoints[i], actual.PathPoints[i], "PathPoints-" + i.ToString ());
1338                                 Assert.AreEqual (expected.PathTypes[i], actual.PathTypes[i], "PathTypes-" + i.ToString ());
1339                         }
1340                 }
1341
1342                 private void CompareFlats (GraphicsPath flat, GraphicsPath original)
1343                 {
1344                         Assert.IsTrue (flat.PointCount >= original.PointCount, "PointCount");
1345                         for (int i = 0; i < flat.PointCount; i++) {
1346                                 Assert.IsTrue (flat.PathTypes[i] != 3, "PathTypes-" + i.ToString ());
1347                         }
1348                 }
1349
1350                 [Test]
1351                 public void Flatten_Empty ()
1352                 {
1353                         GraphicsPath path = new GraphicsPath ();
1354                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1355                         // this is a no-op as there's nothing in the path
1356                         path.Flatten ();
1357                         ComparePaths (path, clone);
1358                 }
1359
1360                 [Test]
1361                 public void Flatten_Null ()
1362                 {
1363                         GraphicsPath path = new GraphicsPath ();
1364                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1365                         // this is a no-op as there's nothing in the path
1366                         // an no matrix to apply
1367                         path.Flatten (null);
1368                         ComparePaths (path, clone);
1369                 }
1370
1371                 [Test]
1372                 public void Flatten_NullFloat ()
1373                 {
1374                         GraphicsPath path = new GraphicsPath ();
1375                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1376                         // this is a no-op as there's nothing in the path
1377                         // an no matrix to apply
1378                         path.Flatten (null, 1f);
1379                         ComparePaths (path, clone);
1380                 }
1381
1382                 [Test]
1383                 public void Flatten_Arc ()
1384                 {
1385                         GraphicsPath path = new GraphicsPath ();
1386                         path.AddArc (0f, 0f, 100f, 100f, 30, 30);
1387                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1388                         path.Flatten ();
1389                         CompareFlats (path, clone);
1390                 }
1391
1392                 [Test]
1393                 public void Flatten_Bezier ()
1394                 {
1395                         GraphicsPath path = new GraphicsPath ();
1396                         path.AddBezier (0, 0, 100, 100, 30, 30, 60, 60);
1397                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1398                         path.Flatten ();
1399                         CompareFlats (path, clone);
1400                 }
1401
1402                 [Test]
1403                 public void Flatten_ClosedCurve ()
1404                 {
1405                         GraphicsPath path = new GraphicsPath ();
1406                         path.AddClosedCurve (new Point[4] { 
1407                                 new Point (0, 0), new Point (40, 20),
1408                                 new Point (20, 40), new Point (40, 40)
1409                                 });
1410                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1411                         path.Flatten ();
1412                         CompareFlats (path, clone);
1413                 }
1414
1415                 [Test]
1416                 public void Flatten_Curve ()
1417                 {
1418                         GraphicsPath path = new GraphicsPath ();
1419                         path.AddCurve (new Point[4] { 
1420                                 new Point (0, 0), new Point (40, 20),
1421                                 new Point (20, 40), new Point (40, 40)
1422                                 });
1423                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1424                         path.Flatten ();
1425                         CompareFlats (path, clone);
1426                 }
1427
1428                 [Test]
1429                 public void Flatten_Ellipse ()
1430                 {
1431                         GraphicsPath path = new GraphicsPath ();
1432                         path.AddEllipse (10f, 10f, 100f, 100f);
1433                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1434                         path.Flatten ();
1435                         CompareFlats (path, clone);
1436                 }
1437
1438                 [Test]
1439                 public void Flatten_Line ()
1440                 {
1441                         GraphicsPath path = new GraphicsPath ();
1442                         path.AddLine (10f, 10f, 100f, 100f);
1443                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1444                         path.Flatten ();
1445                         ComparePaths (path, clone);
1446                 }
1447
1448                 [Test]
1449                 public void Flatten_Pie ()
1450                 {
1451                         GraphicsPath path = new GraphicsPath ();
1452                         path.AddPie (0, 0, 100, 100, 30, 30);
1453                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1454                         path.Flatten ();
1455                         CompareFlats (path, clone);
1456                 }
1457
1458                 [Test]
1459                 public void Flatten_Polygon ()
1460                 {
1461                         GraphicsPath path = new GraphicsPath ();
1462                         path.AddPolygon (new Point[4] { 
1463                                 new Point (0, 0), new Point (10, 10),
1464                                 new Point (20, 20), new Point (40, 40)
1465                                 });
1466                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1467                         path.Flatten ();
1468                         ComparePaths (path, clone);
1469                 }
1470
1471                 [Test]
1472                 public void Flatten_Rectangle ()
1473                 {
1474                         GraphicsPath path = new GraphicsPath ();
1475                         path.AddRectangle (new Rectangle (0, 0, 100, 100));
1476                         GraphicsPath clone = (GraphicsPath) path.Clone ();
1477                         path.Flatten ();
1478                         ComparePaths (path, clone);
1479                 }
1480
1481                 private void CheckWrap (GraphicsPath path)
1482                 {
1483                         Assert.AreEqual (3, path.PointCount, "Count");
1484
1485                         PointF[] pts = path.PathPoints;
1486                         Assert.AreEqual (0, pts[0].X, 1e-30, "0.X");
1487                         Assert.AreEqual (0, pts[0].Y, 1e-30, "0.Y");
1488                         Assert.AreEqual (0, pts[1].X, 1e-30, "1.X");
1489                         Assert.AreEqual (0, pts[1].Y, 1e-30, "1.Y");
1490                         Assert.AreEqual (0, pts[2].X, 1e-30, "2.X");
1491                         Assert.AreEqual (0, pts[2].Y, 1e-30, "2.Y");
1492
1493                         byte[] types = path.PathTypes;
1494                         Assert.AreEqual (0, types[0], "0");
1495                         Assert.AreEqual (1, types[1], "1");
1496                         Assert.AreEqual (129, types[2], "2");
1497                 }
1498
1499                 private void CheckWrapNaN (GraphicsPath path, bool closed)
1500                 {
1501                         Assert.AreEqual (3, path.PointCount, "Count");
1502
1503                         PointF[] pts = path.PathPoints;
1504                         Assert.AreEqual (Single.NaN, pts[0].X, "0.X");
1505                         Assert.AreEqual (Single.NaN, pts[0].Y, "0.Y");
1506                         Assert.AreEqual (Single.NaN, pts[1].X, "1.X");
1507                         Assert.AreEqual (Single.NaN, pts[1].Y, "1.Y");
1508                         Assert.AreEqual (Single.NaN, pts[2].X, "2.X");
1509                         Assert.AreEqual (Single.NaN, pts[2].Y, "2.Y");
1510
1511                         byte[] types = path.PathTypes;
1512                         Assert.AreEqual (0, types[0], "0");
1513                         Assert.AreEqual (1, types[1], "1");
1514                         Assert.AreEqual (closed ? 129 : 1, types[2], "2");
1515                 }
1516
1517                 [Test]
1518                 [ExpectedException (typeof (ArgumentNullException))]
1519                 public void Warp_Null ()
1520                 {
1521                         new GraphicsPath ().Warp (null, new RectangleF ());
1522                 }
1523
1524                 [Test]
1525                 [ExpectedException (typeof (ArgumentException))]
1526                 public void Warp_NoPoints ()
1527                 {
1528                         new GraphicsPath ().Warp (new PointF[0], new RectangleF ());
1529                 }
1530
1531                 [Test]
1532                 public void Wrap_NoPoint ()
1533                 {
1534                         using (GraphicsPath gp = new GraphicsPath ()) {
1535                                 Assert.AreEqual (0, gp.PointCount, "PointCount-1");
1536
1537                                 PointF[] pts = new PointF[1] { new PointF (0, 0) };
1538                                 RectangleF r = new RectangleF (10, 20, 30, 40);
1539                                 gp.Warp (pts, r, new Matrix ());
1540                                 Assert.AreEqual (0, gp.PointCount, "PointCount-2");
1541                         }
1542                 }
1543
1544                 [Test]
1545                 [Category ("NotWorking")]
1546                 public void Wrap_SinglePoint ()
1547                 {
1548                         using (GraphicsPath gp = new GraphicsPath ()) {
1549                                 gp.AddLines (new Point[1] { new Point (1, 1) });
1550                                 // Special case - a line with a single point is valid
1551                                 Assert.AreEqual (1, gp.PointCount, "PointCount-1");
1552
1553                                 PointF[] pts = new PointF[1] { new PointF (0, 0) };
1554                                 RectangleF r = new RectangleF (10, 20, 30, 40);
1555                                 gp.Warp (pts, r, new Matrix ());
1556                                 Assert.AreEqual (0, gp.PointCount, "PointCount-2");
1557                         }
1558                 }
1559
1560                 [Test]
1561                 [Category ("NotWorking")]
1562                 public void Wrap_Line ()
1563                 {
1564                         using (GraphicsPath gp = new GraphicsPath ()) {
1565                                 gp.AddLine (new Point (1, 1), new Point (20, 20));
1566                                 Assert.AreEqual (2, gp.PointCount, "PointCount-1");
1567
1568                                 PointF[] pts = new PointF[1] { new PointF (0, 0) };
1569                                 RectangleF r = new RectangleF (10, 20, 30, 40);
1570                                 gp.Warp (pts, r, new Matrix ());
1571                                 Assert.AreEqual (2, gp.PointCount, "PointCount-2");
1572                         }
1573                 }
1574
1575                 [Test]
1576                 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
1577                 public void Warp_NullMatrix ()
1578                 {
1579                         PointF[] pts = new PointF[1] { new PointF (0,0) };
1580                         GraphicsPath path = new GraphicsPath ();
1581                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1582                         RectangleF r = new RectangleF (10, 20, 30, 40);
1583                         path.Warp (pts, r, null);
1584                         CheckWrap (path);
1585                 }
1586
1587                 [Test]
1588                 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
1589                 public void Warp_EmptyMatrix ()
1590                 {
1591                         PointF[] pts = new PointF[1] { new PointF (0, 0) };
1592                         GraphicsPath path = new GraphicsPath ();
1593                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1594                         RectangleF r = new RectangleF (10, 20, 30, 40);
1595                         path.Warp (pts, r, new Matrix ());
1596                         CheckWrap (path);
1597                 }
1598
1599                 [Test]
1600                 [Category ("NotWorking")]
1601                 public void Warp_Rectangle_Empty ()
1602                 {
1603                         PointF[] pts = new PointF[1] { new PointF (0, 0) };
1604                         GraphicsPath path = new GraphicsPath ();
1605                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1606                         path.Warp (pts, new RectangleF (), null);
1607                         CheckWrapNaN (path, true);
1608                 }
1609
1610                 [Test]
1611                 [Category ("NotWorking")]
1612                 public void Warp_Rectangle_NegativeWidthHeight ()
1613                 {
1614                         PointF[] pts = new PointF[1] { new PointF (0, 0) };
1615                         GraphicsPath path = new GraphicsPath ();
1616                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1617                         RectangleF r = new RectangleF (10, 20, -30, -40);
1618                         path.Warp (pts, r, null);
1619                         Assert.AreEqual (3, path.PointCount, "Count");
1620
1621                         pts = path.PathPoints;
1622                         Assert.AreEqual (1.131355e-39, pts[0].X, 1e40, "0.X");
1623                         Assert.AreEqual (-2.0240637E-33, pts[0].Y, 1e40, "0.Y");
1624                         Assert.AreEqual (1.070131E-39, pts[1].X, 1e40, "1.X");
1625                         Assert.AreEqual (-2.02406389E-33, pts[1].Y, 1e40, "1.Y");
1626                         Assert.AreEqual (3.669146E-40, pts[2].X, 1e40, "2.X");
1627                         Assert.AreEqual (-6.746879E-34, pts[2].Y, 1e40, "2.Y");
1628                         byte[] types = path.PathTypes;
1629                         Assert.AreEqual (0, types[0], "0");
1630                         Assert.AreEqual (1, types[1], "1");
1631                         Assert.AreEqual (129, types[2], "2");
1632                 }
1633
1634                 [Test]
1635                 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
1636                 public void Warp_Matrix_NonInvertible ()
1637                 {
1638                         Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
1639                         Assert.IsFalse (matrix.IsInvertible, "!IsInvertible");
1640                         PointF[] pts = new PointF[1] { new PointF (0, 0) };
1641                         GraphicsPath path = new GraphicsPath ();
1642                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1643                         RectangleF r = new RectangleF (10, 20, 30, 40);
1644                         path.Warp (pts, r, matrix);
1645
1646                         Assert.AreEqual (3, path.PointCount, "Count");
1647                         pts = path.PathPoints;
1648                         Assert.AreEqual (47, pts[0].X, "0.X");
1649                         Assert.AreEqual (30, pts[0].Y, "0.Y");
1650                         Assert.AreEqual (47, pts[1].X, "1.X");
1651                         Assert.AreEqual (30, pts[1].Y, "1.Y");
1652                         Assert.AreEqual (47, pts[2].X, "2.X");
1653                         Assert.AreEqual (30, pts[2].Y, "2.Y");
1654                         byte[] types = path.PathTypes;
1655                         Assert.AreEqual (0, types[0], "0");
1656                         Assert.AreEqual (1, types[1], "1");
1657                         Assert.AreEqual (129, types[2], "2");
1658                 }
1659
1660                 [Test]
1661                 [Category ("NotWorking")]
1662                 public void Warp_Bilinear ()
1663                 {
1664                         PointF[] pts = new PointF[1] { new PointF (0, 0) };
1665                         GraphicsPath path = new GraphicsPath ();
1666                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1667                         RectangleF r = new RectangleF (10, 20, 30, 40);
1668                         path.Warp (pts, r, new Matrix (), WarpMode.Bilinear);
1669                         // note that the last point is no more closed
1670                         CheckWrapNaN (path, false);
1671                 }
1672
1673                 [Test]
1674                 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
1675                 public void Warp_Perspective ()
1676                 {
1677                         PointF[] pts = new PointF[1] { new PointF (0, 0) };
1678                         GraphicsPath path = new GraphicsPath ();
1679                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1680                         RectangleF r = new RectangleF (10, 20, 30, 40);
1681                         path.Warp (pts, r, new Matrix (), WarpMode.Perspective);
1682                         CheckWrap (path);
1683                 }
1684
1685                 [Test]
1686                 public void Warp_Invalid ()
1687                 {
1688                         PointF[] pts = new PointF[1] { new PointF (0, 0) };
1689                         GraphicsPath path = new GraphicsPath ();
1690                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1691                         RectangleF r = new RectangleF (10, 20, 30, 40);
1692                         path.Warp (pts, r, new Matrix (), (WarpMode) Int32.MinValue);
1693                         Assert.AreEqual (0, path.PointCount, "Count");
1694                 }
1695
1696                 [Test]
1697                 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
1698                 public void Warp_Flatness_Negative ()
1699                 {
1700                         PointF[] pts = new PointF[1] { new PointF (0, 0) };
1701                         GraphicsPath path = new GraphicsPath ();
1702                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1703                         RectangleF r = new RectangleF (10, 20, 30, 40);
1704                         path.Warp (pts, r, new Matrix (), WarpMode.Perspective, -1f);
1705                         CheckWrap (path);
1706                 }
1707
1708                 [Test]
1709                 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
1710                 public void Warp_Flatness_OverOne ()
1711                 {
1712                         PointF[] pts = new PointF[1] { new PointF (0, 0) };
1713                         GraphicsPath path = new GraphicsPath ();
1714                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
1715                         RectangleF r = new RectangleF (10, 20, 30, 40);
1716                         path.Warp (pts, r, new Matrix (), WarpMode.Perspective, 2.0f);
1717                         CheckWrap (path);
1718                 }
1719
1720                 [Test]
1721                 public void SetMarkers_EmptyPath ()
1722                 {
1723                         new GraphicsPath ().SetMarkers ();
1724                 }
1725
1726                 [Test]
1727                 public void ClearMarkers_EmptyPath ()
1728                 {
1729                         new GraphicsPath ().ClearMarkers ();
1730                 }
1731
1732                 [Test]
1733                 public void CloseFigure_EmptyPath ()
1734                 {
1735                         new GraphicsPath ().CloseFigure ();
1736                 }
1737
1738                 [Test]
1739                 public void CloseAllFigures_EmptyPath ()
1740                 {
1741                         new GraphicsPath ().CloseAllFigures ();
1742                 }
1743
1744                 [Test]
1745                 public void StartClose_AddArc ()
1746                 {
1747                         GraphicsPath path = new GraphicsPath ();
1748                         path.AddLine (1, 1, 2, 2);
1749                         path.AddArc (10, 10, 100, 100, 90, 180);
1750                         path.AddLine (10, 10, 20, 20);
1751                         byte[] types = path.PathTypes;
1752                         // check first types
1753                         Assert.AreEqual (0, types[0], "start/Line");
1754                         Assert.AreEqual (1, types[2], "start/Arc");
1755                         // check last types
1756                         Assert.AreEqual (3, types[path.PointCount - 3], "end/Arc");
1757                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1758                 }
1759
1760                 [Test]
1761                 public void StartClose_AddBezier ()
1762                 {
1763                         GraphicsPath path = new GraphicsPath ();
1764                         path.AddLine (1, 1, 2, 2);
1765                         path.AddBezier (10, 10, 100, 100, 20, 20, 200, 200);
1766                         path.AddLine (10, 10, 20, 20);
1767                         byte[] types = path.PathTypes;
1768                         // check first types
1769                         Assert.AreEqual (0, types[0], "start/Line");
1770                         Assert.AreEqual (1, types[2], "start/Bezier");
1771                         // check last types
1772                         Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier");
1773                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1774                 }
1775
1776                 [Test]
1777                 public void StartClose_AddBeziers ()
1778                 {
1779                         GraphicsPath path = new GraphicsPath ();
1780                         path.AddLine (1, 1, 2, 2);
1781                         path.AddBeziers (new Point[7] { new Point (10, 10), 
1782                                 new Point (20, 10), new Point (20, 20), new Point (30, 20),
1783                                 new Point (40, 40), new Point (50, 40), new Point (50, 50)
1784                         });
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 (1, types[2], "start/Bezier");
1790                         // check last types
1791                         Assert.AreEqual (3, types[path.PointCount - 3], "end/Bezier");
1792                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1793                 }
1794
1795                 [Test]
1796                 public void StartClose_AddClosedCurve ()
1797                 {
1798                         GraphicsPath path = new GraphicsPath ();
1799                         path.AddLine (1, 1, 2, 2);
1800                         path.AddClosedCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
1801                         path.AddLine (10, 10, 20, 20);
1802                         byte[] types = path.PathTypes;
1803                         // check first types
1804                         Assert.AreEqual (0, types[0], "start/Line");
1805                         Assert.AreEqual (0, types[2], "start/ClosedCurve");
1806                         // check last types
1807                         Assert.AreEqual (131, types[path.PointCount - 3], "end/ClosedCurve");
1808                         Assert.AreEqual (0, types[path.PointCount - 2], "start/Line3");
1809                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line3");
1810                 }
1811
1812                 [Test]
1813                 public void StartClose_AddCurve ()
1814                 {
1815                         GraphicsPath path = new GraphicsPath ();
1816                         path.AddLine (1, 1, 2, 2);
1817                         path.AddCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
1818                         path.AddLine (10, 10, 20, 20);
1819                         byte[] types = path.PathTypes;
1820                         // check first types
1821                         Assert.AreEqual (0, types[0], "start/Line");
1822                         Assert.AreEqual (1, types[2], "start/Curve");
1823                         // check last types
1824                         Assert.AreEqual (3, types[path.PointCount - 3], "end/Curve");
1825                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1826                 }
1827
1828                 [Test]
1829                 public void StartClose_AddEllipse ()
1830                 {
1831                         GraphicsPath path = new GraphicsPath ();
1832                         path.AddLine (1, 1, 2, 2);
1833                         path.AddEllipse (10, 10, 100, 100);
1834                         path.AddLine (10, 10, 20, 20);
1835                         byte[] types = path.PathTypes;
1836                         // check first types
1837                         Assert.AreEqual (0, types[0], "start/Line");
1838                         Assert.AreEqual (0, types[2], "start/Ellipse");
1839                         // check last types
1840                         Assert.AreEqual (131, types[path.PointCount - 3], "end/Ellipse");
1841                         Assert.AreEqual (0, types[path.PointCount - 2], "start/Line3");
1842                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line3");
1843                 }
1844
1845                 [Test]
1846                 public void StartClose_AddLine ()
1847                 {
1848                         GraphicsPath path = new GraphicsPath ();
1849                         path.AddLine (1, 1, 2, 2);
1850                         path.AddLine (5, 5, 10, 10);
1851                         path.AddLine (10, 10, 20, 20);
1852                         byte[] types = path.PathTypes;
1853                         // check first types
1854                         Assert.AreEqual (0, types[0], "start/Line");
1855                         Assert.AreEqual (1, types[2], "start/Line2");
1856                         // check last types
1857                         Assert.AreEqual (1, types[path.PointCount - 3], "end/Line2");
1858                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1859                 }
1860
1861                 [Test]
1862                 public void StartClose_AddLines ()
1863                 {
1864                         GraphicsPath path = new GraphicsPath ();
1865                         path.AddLine (1, 1, 2, 2);
1866                         path.AddLines (new Point[4] { new Point (10, 10), new Point (20, 10), new Point (20, 20), new Point (30, 20) });
1867                         path.AddLine (10, 10, 20, 20);
1868                         byte[] types = path.PathTypes;
1869                         // check first types
1870                         Assert.AreEqual (0, types[0], "start/Line");
1871                         Assert.AreEqual (1, types[2], "start/Lines");
1872                         // check last types
1873                         Assert.AreEqual (1, types[path.PointCount - 3], "end/Lines");
1874                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1875                 }
1876
1877                 [Test]
1878                 public void StartClose_AddPath_Connect ()
1879                 {
1880                         GraphicsPath inner = new GraphicsPath ();
1881                         inner.AddArc (10, 10, 100, 100, 90, 180);
1882                         GraphicsPath path = new GraphicsPath ();
1883                         path.AddLine (1, 1, 2, 2);
1884                         path.AddPath (inner, true);
1885                         path.AddLine (10, 10, 20, 20);
1886                         byte[] types = path.PathTypes;
1887                         // check first types
1888                         Assert.AreEqual (0, types[0], "start/Line");
1889                         Assert.AreEqual (1, types[2], "start/Path");
1890                         // check last types
1891                         Assert.AreEqual (3, types[path.PointCount - 3], "end/Path");
1892                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1893                 }
1894
1895                 [Test]
1896                 public void StartClose_AddPath_NoConnect ()
1897                 {
1898                         GraphicsPath inner = new GraphicsPath ();
1899                         inner.AddArc (10, 10, 100, 100, 90, 180);
1900                         GraphicsPath path = new GraphicsPath ();
1901                         path.AddLine (1, 1, 2, 2);
1902                         path.AddPath (inner, false);
1903                         path.AddLine (10, 10, 20, 20);
1904                         byte[] types = path.PathTypes;
1905                         // check first types
1906                         Assert.AreEqual (0, types[0], "start/Line");
1907                         Assert.AreEqual (0, types[2], "start/Path");
1908                         // check last types
1909                         Assert.AreEqual (3, types[path.PointCount - 3], "end/Path");
1910                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line");
1911                 }
1912
1913                 [Test]
1914                 public void StartClose_AddPie ()
1915                 {
1916                         GraphicsPath path = new GraphicsPath ();
1917                         path.AddLine (1, 1, 2, 2);
1918                         path.AddPie (10, 10, 10, 10, 90, 180);
1919                         path.AddLine (10, 10, 20, 20);
1920                         byte[] types = path.PathTypes;
1921                         // check first types
1922                         Assert.AreEqual (0, types[0], "start/Line");
1923                         Assert.AreEqual (0, types[2], "start/Pie");
1924                         // check last types
1925                         // libgdiplus draws pie by ending with a line (not a curve) section
1926                         Assert.IsTrue ((types[path.PointCount - 3] & 128) == 128, "end/Pie");
1927                         Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
1928                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
1929                 }
1930
1931                 [Test]
1932                 public void StartClose_AddPolygon ()
1933                 {
1934                         GraphicsPath path = new GraphicsPath ();
1935                         path.AddLine (1, 1, 2, 2);
1936                         path.AddPolygon (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
1937                         path.AddLine (10, 10, 20, 20);
1938                         byte[] types = path.PathTypes;
1939                         // check first types
1940                         Assert.AreEqual (0, types[0], "start/Line");
1941                         Assert.AreEqual (0, types[2], "start/Polygon");
1942                         // check last types
1943                         Assert.AreEqual (129, types[path.PointCount - 3], "end/Polygon");
1944                         Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
1945                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
1946                 }
1947
1948                 [Test]
1949                 public void StartClose_AddRectangle ()
1950                 {
1951                         GraphicsPath path = new GraphicsPath ();
1952                         path.AddLine (1, 1, 2, 2);
1953                         path.AddRectangle (new RectangleF (10, 10, 20, 20));
1954                         path.AddLine (10, 10, 20, 20);
1955                         byte[] types = path.PathTypes;
1956                         // check first types
1957                         Assert.AreEqual (0, types[0], "start/Line");
1958                         Assert.AreEqual (0, types[2], "start/Rectangle");
1959                         // check last types
1960                         Assert.AreEqual (129, types[path.PointCount - 3], "end/Rectangle");
1961                         Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
1962                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
1963                 }
1964
1965                 [Test]
1966                 public void StartClose_AddRectangles ()
1967                 {
1968                         GraphicsPath path = new GraphicsPath ();
1969                         path.AddLine (1, 1, 2, 2);
1970                         path.AddRectangles (new RectangleF[2] {
1971                                 new RectangleF (10, 10, 20, 20),
1972                                 new RectangleF (20, 20, 10, 10) });
1973                         path.AddLine (10, 10, 20, 20);
1974                         byte[] types = path.PathTypes;
1975                         // check first types
1976                         Assert.AreEqual (0, types[0], "start/Line");
1977                         Assert.AreEqual (0, types[2], "start/Rectangles");
1978                         // check last types
1979                         Assert.AreEqual (129, types[path.PointCount - 3], "end/Rectangles");
1980                         Assert.AreEqual (0, types[path.PointCount - 2], "start/Line2");
1981                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
1982                 }
1983
1984                 [Test]
1985                 [Category ("NotWorking")]
1986                 public void StartClose_AddString ()
1987                 {
1988                         GraphicsPath path = new GraphicsPath ();
1989                         path.AddLine (1, 1, 2, 2);
1990                         path.AddString ("mono", FontFamily.GenericMonospace, 0, 10, new Point (20,20), StringFormat.GenericDefault);
1991                         path.AddLine (10, 10, 20, 20);
1992                         byte[] types = path.PathTypes;
1993                         // check first types
1994                         Assert.AreEqual (0, types[0], "start/Line");
1995                         Assert.AreEqual (0, types[2], "start/String");
1996                         // check last types
1997                         Assert.AreEqual (163, types[path.PointCount - 3], "end/String");
1998                         Assert.AreEqual (1, types[path.PointCount - 2], "start/Line2");
1999                         Assert.AreEqual (1, types[path.PointCount - 1], "end/Line2");
2000                 }
2001
2002                 [Test]
2003                 [ExpectedException (typeof (ArgumentNullException))]
2004                 public void Widen_Pen_Null ()
2005                 {
2006                         new GraphicsPath ().Widen (null);
2007                 }
2008
2009                 [Test]
2010                 [Category ("NotWorking")]
2011                 public void Widen_Pen ()
2012                 {
2013                         Pen pen = new Pen (Color.Blue);
2014                         GraphicsPath path = new GraphicsPath ();
2015                         path.AddRectangle (new Rectangle (1, 1, 2, 2));
2016                         Assert.AreEqual (4, path.PointCount, "Count-1");
2017                         path.Widen (pen);
2018                         Assert.AreEqual (12, path.PointCount, "Count-2");
2019
2020                         PointF[] pts = path.PathPoints;
2021                         Assert.AreEqual (0.5, pts[0].X, 0.25, "0.X");
2022                         Assert.AreEqual (0.5, pts[0].Y, 0.25, "0.Y");
2023                         Assert.AreEqual (3.5, pts[1].X, 0.25, "1.X");
2024                         Assert.AreEqual (0.5, pts[1].Y, 0.25, "1.Y");
2025                         Assert.AreEqual (3.5, pts[2].X, 0.25, "2.X");
2026                         Assert.AreEqual (3.5, pts[2].Y, 0.25, "2.Y");
2027                         Assert.AreEqual (0.5, pts[3].X, 0.25, "3.X");
2028                         Assert.AreEqual (3.5, pts[3].Y, 0.25, "3.Y");
2029                         Assert.AreEqual (1.5, pts[4].X, 0.25, "4.X");
2030                         Assert.AreEqual (3.0, pts[4].Y, 0.25, "4.Y");
2031                         Assert.AreEqual (1.0, pts[5].X, 0.25, "5.X");
2032                         Assert.AreEqual (2.5, pts[5].Y, 0.25, "5.Y");
2033                         Assert.AreEqual (3.0, pts[6].X, 0.25, "6.X");
2034                         Assert.AreEqual (2.5, pts[6].Y, 0.25, "6.Y");
2035                         Assert.AreEqual (2.5, pts[7].X, 0.25, "7.X");
2036                         Assert.AreEqual (3.0, pts[7].Y, 0.25, "7.Y");
2037                         Assert.AreEqual (2.5, pts[8].X, 0.25, "8.X");
2038                         Assert.AreEqual (1.0, pts[8].Y, 0.25, "8.Y");
2039                         Assert.AreEqual (3.0, pts[9].X, 0.25, "9.X");
2040                         Assert.AreEqual (1.5, pts[9].Y, 0.25, "9.Y");
2041                         Assert.AreEqual (1.0, pts[10].X, 0.25, "10.X");
2042                         Assert.AreEqual (1.5, pts[10].Y, 0.25, "10.Y");
2043                         Assert.AreEqual (1.5, pts[11].X, 0.25, "11.X");
2044                         Assert.AreEqual (1.0, pts[11].Y, 0.25, "11.Y");
2045
2046                         byte[] types = path.PathTypes;
2047                         Assert.AreEqual (0, types[0], "0");
2048                         Assert.AreEqual (1, types[1], "1");
2049                         Assert.AreEqual (1, types[2], "2");
2050                         Assert.AreEqual (129, types[3], "3");
2051                         Assert.AreEqual (0, types[4], "4");
2052                         Assert.AreEqual (1, types[5], "5");
2053                         Assert.AreEqual (1, types[6], "6");
2054                         Assert.AreEqual (1, types[7], "7");
2055                         Assert.AreEqual (1, types[8], "8");
2056                         Assert.AreEqual (1, types[9], "9");
2057                         Assert.AreEqual (1, types[10], "10");
2058                         Assert.AreEqual (129, types[11], "11");
2059                 }
2060
2061                 [Test]
2062                 [ExpectedException (typeof (ArgumentNullException))]
2063                 public void Widen_Pen_Null_Matrix ()
2064                 {
2065                         new GraphicsPath ().Widen (null, new Matrix ());
2066                 }
2067
2068                 [Test]
2069 #if ONLY_1_1
2070                 [ExpectedException (typeof (OutOfMemoryException))]
2071 #endif
2072                 public void Widen_NoPoint ()
2073                 {
2074                         using (GraphicsPath gp = new GraphicsPath ()) {
2075                                 Assert.AreEqual (0, gp.PointCount, "PointCount-1");
2076                                 Pen pen = new Pen (Color.Blue);
2077                                 gp.Widen (pen);
2078                                 Assert.AreEqual (0, gp.PointCount, "PointCount-2");
2079                         }
2080                 }
2081
2082                 [Test]
2083                 [ExpectedException (typeof (OutOfMemoryException))]
2084                 public void Widen_SinglePoint ()
2085                 {
2086                         using (GraphicsPath gp = new GraphicsPath ()) {
2087                                 gp.AddLines (new Point[1] { new Point (1, 1) });
2088                                 // Special case - a line with a single point is valid
2089                                 Assert.AreEqual (1, gp.PointCount, "PointCount");
2090                                 gp.Widen (Pens.Red);
2091                                 // oops ;-)
2092                         }
2093                 }
2094
2095                 private void CheckWiden3 (GraphicsPath path)
2096                 {
2097                         PointF[] pts = path.PathPoints;
2098                         Assert.AreEqual (4.2, pts[0].X, 0.25, "0.X");
2099                         Assert.AreEqual (4.5, pts[0].Y, 0.25, "0.Y");
2100                         Assert.AreEqual (15.8, pts[1].X, 0.25, "1.X");
2101                         Assert.AreEqual (4.5, pts[1].Y, 0.25, "1.Y");
2102                         Assert.AreEqual (10.0, pts[2].X, 0.25, "2.X");
2103                         Assert.AreEqual (16.1, pts[2].Y, 0.25, "2.Y");
2104                         Assert.AreEqual (10.4, pts[3].X, 0.25, "3.X");
2105                         Assert.AreEqual (14.8, pts[3].Y, 0.25, "3.Y");
2106                         Assert.AreEqual (9.6, pts[4].X, 0.25, "4.X");
2107                         Assert.AreEqual (14.8, pts[4].Y, 0.25, "4.Y");
2108                         Assert.AreEqual (14.6, pts[5].X, 0.25, "7.X");
2109                         Assert.AreEqual (4.8, pts[5].Y, 0.25, "7.Y");
2110                         Assert.AreEqual (15.0, pts[6].X, 0.25, "5.X");
2111                         Assert.AreEqual (5.5, pts[6].Y, 0.25, "5.Y");
2112                         Assert.AreEqual (5.0, pts[7].X, 0.25, "6.X");
2113                         Assert.AreEqual (5.5, pts[7].Y, 0.25, "6.Y");
2114                         Assert.AreEqual (5.4, pts[8].X, 0.25, "8.X");
2115                         Assert.AreEqual (4.8, pts[8].Y, 0.25, "8.Y");
2116
2117                         byte[] types = path.PathTypes;
2118                         Assert.AreEqual (0, types[0], "0");
2119                         Assert.AreEqual (1, types[1], "1");
2120                         Assert.AreEqual (129, types[2], "2");
2121                         Assert.AreEqual (0, types[3], "3");
2122                         Assert.AreEqual (1, types[4], "4");
2123                         Assert.AreEqual (1, types[5], "5");
2124                         Assert.AreEqual (1, types[6], "6");
2125                         Assert.AreEqual (1, types[7], "7");
2126                         Assert.AreEqual (129, types[8], "8");
2127                 }
2128
2129                 [Test]
2130                 [Category ("NotWorking")]
2131                 public void Widen_Pen_Matrix_Null ()
2132                 {
2133                         Pen pen = new Pen (Color.Blue);
2134                         GraphicsPath path = new GraphicsPath ();
2135                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
2136                         path.Widen (pen, null);
2137                         Assert.AreEqual (9, path.PointCount, "Count");
2138                         CheckWiden3 (path);
2139                 }
2140
2141                 [Test]
2142                 [Category ("NotWorking")]
2143                 public void Widen_Pen_Matrix_Empty ()
2144                 {
2145                         Pen pen = new Pen (Color.Blue);
2146                         GraphicsPath path = new GraphicsPath ();
2147                         path.AddPolygon (new Point[3] { new Point (5, 5), new Point (15, 5), new Point (10, 15) });
2148                         path.Widen (pen, new Matrix ());
2149                         Assert.AreEqual (9, path.PointCount, "Count");
2150                         CheckWiden3 (path);
2151                 }
2152
2153                 [Test]
2154                 [Ignore ("results aren't always constant and differs from 1.x and 2.0")]
2155                 public void Widen_Pen_Matrix_NonInvertible ()
2156                 {
2157                         Matrix matrix = new Matrix (123, 24, 82, 16, 47, 30);
2158                         Assert.IsFalse (matrix.IsInvertible, "!IsInvertible");
2159                         GraphicsPath path = new GraphicsPath ();
2160                         path.Widen (new Pen (Color.Blue), matrix);
2161                         Assert.AreEqual (0, path.PointCount, "Points");
2162                 }
2163
2164                 private void CheckWidenedBounds (string message, GraphicsPath gp, Matrix m)
2165                 {
2166                         RectangleF bounds = gp.GetBounds (m);
2167                         Assert.AreEqual (0.5f, bounds.X, 0.00001f, message + ".Bounds.X");
2168                         Assert.AreEqual (0.5f, bounds.Y, 0.00001f, message + ".Bounds.Y");
2169                         Assert.AreEqual (3.0f, bounds.Width, 0.00001f, message + ".Bounds.Width");
2170                         Assert.AreEqual (3.0f, bounds.Height, 0.00001f, message + ".Bounds.Height");
2171                 }
2172
2173                 [Test]
2174                 [Category ("NotWorking")]
2175                 public void Widen_Pen_SmallWidth ()
2176                 {
2177                         Matrix m = new Matrix ();
2178                         Rectangle rect = new Rectangle (1, 1, 2, 2);
2179
2180                         // pen's smaller than 1.0 (width) are "promoted" to 1
2181                         Pen p = new Pen (Color.Aqua, 0);
2182                         GraphicsPath gp = new GraphicsPath ();
2183                         gp.AddRectangle (rect);
2184                         gp.Widen (p);
2185                         CheckWidenedBounds ("Width == 0, Null matrix", gp, null);
2186                         CheckWidenedBounds ("Width == 0, Empty matrix", gp, m);
2187
2188                         p.Width = 0.5f;
2189                         gp = new GraphicsPath ();
2190                         gp.AddRectangle (rect);
2191                         gp.Widen (p);
2192                         CheckWidenedBounds ("Width == 0.5, Null matrix", gp, null);
2193                         CheckWidenedBounds ("Width == 0.5, Empty matrix", gp, m);
2194
2195                         p.Width = 1.0f;
2196                         gp = new GraphicsPath ();
2197                         gp.AddRectangle (rect);
2198                         gp.Widen (p);
2199                         CheckWidenedBounds ("Width == 1.0, Null matrix", gp, null);
2200                         CheckWidenedBounds ("Width == 1.0, Empty matrix", gp, m);
2201
2202                         p.Width = 1.1f;
2203                         gp = new GraphicsPath ();
2204                         gp.AddRectangle (rect);
2205                         gp.Widen (p);
2206                         RectangleF bounds = gp.GetBounds (m);
2207                         Assert.AreEqual (0.45f, bounds.X, 0.00001f, "1.1.Bounds.X");
2208                         Assert.AreEqual (0.45f, bounds.Y, 0.00001f, "1.1.Bounds.Y");
2209                         Assert.AreEqual (3.10f, bounds.Width, 0.00001f, "1.1.Bounds.Width");
2210                         Assert.AreEqual (3.10f, bounds.Height, 0.00001f, "1.1.Bounds.Height");
2211                 }
2212
2213                 [Test]
2214                 [ExpectedException (typeof (ArgumentNullException))]
2215                 public void IsOutlineVisible_IntNull ()
2216                 {
2217                         new GraphicsPath ().IsOutlineVisible (1, 1, null);
2218                 }
2219
2220                 [Test]
2221                 [ExpectedException (typeof (ArgumentNullException))]
2222                 public void IsOutlineVisible_FloatNull ()
2223                 {
2224                         new GraphicsPath ().IsOutlineVisible (1.0f, 1.0f, null);
2225                 }
2226
2227                 [Test]
2228                 [ExpectedException (typeof (ArgumentNullException))]
2229                 public void IsOutlineVisible_PointNull ()
2230                 {
2231                         new GraphicsPath ().IsOutlineVisible (new Point (), null);
2232                 }
2233
2234                 [Test]
2235                 [ExpectedException (typeof (ArgumentNullException))]
2236                 public void IsOutlineVisible_PointFNull ()
2237                 {
2238                         new GraphicsPath ().IsOutlineVisible (new PointF (), null);
2239                 }
2240
2241                 private void IsOutlineVisible_Line (Graphics graphics)
2242                 {
2243                         Pen p2 = new Pen (Color.Red, 3.0f);
2244                         using (GraphicsPath gp = new GraphicsPath ()) {
2245                                 gp.AddLine (10, 1, 14, 1);
2246                                 Assert.IsTrue (gp.IsOutlineVisible (10, 1, Pens.Red, graphics), "Int1");
2247                                 Assert.IsTrue (gp.IsOutlineVisible (10, 2, p2, graphics), "Int2");
2248                                 Assert.IsFalse (gp.IsOutlineVisible (10, 2, Pens.Red, graphics), "Int3");
2249
2250                                 Assert.IsTrue (gp.IsOutlineVisible (11.0f, 1.0f, Pens.Red, graphics), "Float1");
2251                                 Assert.IsTrue (gp.IsOutlineVisible (11.0f, 1.0f, p2, graphics), "Float2");
2252                                 Assert.IsFalse (gp.IsOutlineVisible (11.0f, 2.0f, Pens.Red, graphics), "Float3");
2253
2254                                 Point pt = new Point (12, 2);
2255                                 Assert.IsFalse (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point1");
2256                                 Assert.IsTrue (gp.IsOutlineVisible (pt, p2, graphics), "Point2");
2257                                 pt.Y = 1;
2258                                 Assert.IsTrue (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point3");
2259
2260                                 PointF pf = new PointF (13.0f, 2.0f);
2261                                 Assert.IsFalse (gp.IsOutlineVisible (pf, Pens.Red, graphics), "PointF1");
2262                                 Assert.IsTrue (gp.IsOutlineVisible (pf, p2, graphics), "PointF2");
2263                                 pf.Y = 1;
2264                                 Assert.IsTrue (gp.IsOutlineVisible (pf, Pens.Red, graphics), "PointF3");
2265                         }
2266                         p2.Dispose ();
2267                 }
2268
2269                 [Test]
2270                 public void IsOutlineVisible_Line_WithoutGraphics ()
2271                 {
2272                         IsOutlineVisible_Line (null);
2273                 }
2274
2275                 [Test]
2276                 public void IsOutlineVisible_Line_WithGraphics_Inside ()
2277                 {
2278                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2279                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2280                                         IsOutlineVisible_Line (g);
2281                                 }
2282                         }
2283                 }
2284
2285                 [Test]
2286                 public void IsOutlineVisible_Line_WithGraphics_Outside ()
2287                 {
2288                         using (Bitmap bitmap = new Bitmap (5, 5)) {
2289                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2290                                         IsOutlineVisible_Line (g);
2291                                 }
2292                                 // graphics "seems" ignored as the line is outside the bitmap!
2293                         }
2294                 }
2295
2296                 // docs ways the point is in world coordinates and that the graphics transform 
2297                 // should be applied
2298
2299                 [Test]
2300                 public void IsOutlineVisible_Line_WithGraphics_Transform ()
2301                 {
2302                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2303                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2304                                         g.Transform = new Matrix (2, 0, 0, 2, 50, -50);
2305                                         IsOutlineVisible_Line (g);
2306                                 }
2307                                 // graphics still "seems" ignored (Transform)
2308                         }
2309                 }
2310
2311                 [Test]
2312                 public void IsOutlineVisible_Line_WithGraphics_PageUnit ()
2313                 {
2314                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2315                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2316                                         g.PageUnit = GraphicsUnit.Millimeter;
2317                                         IsOutlineVisible_Line (g);
2318                                 }
2319                                 // graphics still "seems" ignored (PageUnit)
2320                         }
2321                 }
2322
2323                 [Test]
2324                 public void IsOutlineVisible_Line_WithGraphics_PageScale ()
2325                 {
2326                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2327                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2328                                         g.PageScale = 2.0f;
2329                                         IsOutlineVisible_Line (g);
2330                                 }
2331                                 // graphics still "seems" ignored (PageScale)
2332                         }
2333                 }
2334
2335                 [Test]
2336                 [Category ("NotWorking")]
2337                 public void IsOutlineVisible_Line_WithGraphics ()
2338                 {
2339                         using (Bitmap bitmap = new Bitmap (20, 20)) {
2340                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2341                                         g.Transform = new Matrix (2, 0, 0, 2, 50, -50);
2342                                         g.PageUnit = GraphicsUnit.Millimeter;
2343                                         g.PageScale = 2.0f;
2344                                         using (GraphicsPath gp = new GraphicsPath ()) {
2345                                                 gp.AddLine (10, 1, 14, 1);
2346                                                 Assert.IsFalse (gp.IsOutlineVisible (10, 1, Pens.Red, g), "Int1");
2347                                         }
2348                                 }
2349                                 // graphics ISN'T ignored (Transform+PageUnit+PageScale)
2350                         }
2351                 }
2352
2353                 [Test]
2354                 [Category ("NotWorking")] // looks buggy - reported to MS as FDBK50868
2355                 public void IsOutlineVisible_Line_End ()
2356                 {
2357                         // horizontal line
2358                         using (GraphicsPath gp = new GraphicsPath ()) {
2359                                 gp.AddLine (10, 1, 14, 1);
2360                                 Assert.IsFalse (gp.IsOutlineVisible (14, 1, Pens.Red, null), "Int1h");
2361                                 Assert.IsFalse (gp.IsOutlineVisible (13.5f, 1.0f, Pens.Red, null), "Float1h");
2362                                 Assert.IsTrue (gp.IsOutlineVisible (13.4f, 1.0f, Pens.Red, null), "Float2h");
2363                                 Assert.IsFalse (gp.IsOutlineVisible (new Point (14, 1), Pens.Red, null), "Point1h");
2364                                 Assert.IsFalse (gp.IsOutlineVisible (new PointF (13.5f, 1.0f), Pens.Red, null), "PointF1h");
2365                                 Assert.IsTrue (gp.IsOutlineVisible (new PointF (13.49f, 1.0f), Pens.Red, null), "PointF2h");
2366                         }
2367                         // vertical line
2368                         using (GraphicsPath gp = new GraphicsPath ()) {
2369                                 gp.AddLine (1, 10, 1, 14);
2370                                 Assert.IsFalse (gp.IsOutlineVisible (1, 14, Pens.Red, null), "Int1v");
2371                                 Assert.IsFalse (gp.IsOutlineVisible (1.0f, 13.5f, Pens.Red, null), "Float1v");
2372                                 Assert.IsTrue (gp.IsOutlineVisible (1.0f, 13.4f, Pens.Red, null), "Float2v");
2373                                 Assert.IsFalse (gp.IsOutlineVisible (new Point (1, 14), Pens.Red, null), "Point1v");
2374                                 Assert.IsFalse (gp.IsOutlineVisible (new PointF (1.0f, 13.5f), Pens.Red, null), "PointF1v");
2375                                 Assert.IsTrue (gp.IsOutlineVisible (new PointF (1.0f, 13.49f), Pens.Red, null), "PointF2v");
2376                         }
2377                 }
2378
2379                 private void IsOutlineVisible_Rectangle (Graphics graphics)
2380                 {
2381                         Pen p2 = new Pen (Color.Red, 3.0f);
2382                         using (GraphicsPath gp = new GraphicsPath ()) {
2383                                 gp.AddRectangle (new Rectangle (10, 10, 20, 20));
2384                                 Assert.IsTrue (gp.IsOutlineVisible (10, 10, Pens.Red, graphics), "Int1");
2385                                 Assert.IsTrue (gp.IsOutlineVisible (10, 11, p2, graphics), "Int2");
2386                                 Assert.IsFalse (gp.IsOutlineVisible (11, 11, Pens.Red, graphics), "Int3");
2387
2388                                 Assert.IsTrue (gp.IsOutlineVisible (11.0f, 10.0f, Pens.Red, graphics), "Float1");
2389                                 Assert.IsTrue (gp.IsOutlineVisible (11.0f, 11.0f, p2, graphics), "Float2");
2390                                 Assert.IsFalse (gp.IsOutlineVisible (11.0f, 11.0f, Pens.Red, graphics), "Float3");
2391
2392                                 Point pt = new Point (15, 10);
2393                                 Assert.IsTrue (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point1");
2394                                 Assert.IsTrue (gp.IsOutlineVisible (pt, p2, graphics), "Point2");
2395                                 pt.Y = 15;
2396                                 Assert.IsFalse (gp.IsOutlineVisible (pt, Pens.Red, graphics), "Point3");
2397
2398                                 PointF pf = new PointF (29.0f, 29.0f);
2399                                 Assert.IsFalse (gp.IsOutlineVisible (pf, Pens.Red, graphics), "PointF1");
2400                                 Assert.IsTrue (gp.IsOutlineVisible (pf, p2, graphics), "PointF2");
2401                                 pf.Y = 31.0f;
2402                                 Assert.IsTrue (gp.IsOutlineVisible (pf, p2, graphics), "PointF3");
2403                         }
2404                         p2.Dispose ();
2405                 }
2406
2407                 [Test]
2408                 public void IsOutlineVisible_Rectangle_WithoutGraphics ()
2409                 {
2410                         IsOutlineVisible_Rectangle (null);
2411                 }
2412
2413                 private void IsVisible_Rectangle (Graphics graphics)
2414                 {
2415                         using (GraphicsPath gp = new GraphicsPath ()) {
2416                                 gp.AddRectangle (new Rectangle (10, 10, 20, 20));
2417                                 Assert.IsFalse (gp.IsVisible (9, 9, graphics), "Int0");
2418                                 Assert.IsTrue (gp.IsVisible (10, 10, graphics), "Int1");
2419                                 Assert.IsTrue (gp.IsVisible (20, 20, graphics), "Int2");
2420                                 Assert.IsTrue (gp.IsVisible (29, 29, graphics), "Int3");
2421                                 Assert.IsFalse (gp.IsVisible (30, 29, graphics), "Int4");
2422                                 Assert.IsFalse (gp.IsVisible (29, 30, graphics), "Int5");
2423                                 Assert.IsFalse (gp.IsVisible (30, 30, graphics), "Int6");
2424
2425                                 Assert.IsFalse (gp.IsVisible (9.4f, 9.4f, graphics), "Float0");
2426                                 Assert.IsTrue (gp.IsVisible (9.5f, 9.5f, graphics), "Float1");
2427                                 Assert.IsTrue (gp.IsVisible (10f, 10f, graphics), "Float2");
2428                                 Assert.IsTrue (gp.IsVisible (20f, 20f, graphics), "Float3");
2429                                 Assert.IsTrue (gp.IsVisible (29.4f, 29.4f, graphics), "Float4");
2430                                 Assert.IsFalse (gp.IsVisible (29.5f, 29.5f, graphics), "Float5");
2431                                 Assert.IsFalse (gp.IsVisible (29.5f, 29.4f, graphics), "Float6");
2432                                 Assert.IsFalse (gp.IsVisible (29.4f, 29.5f, graphics), "Float7");
2433                         }
2434                 }
2435
2436                 [Test]
2437                 public void IsVisible_Rectangle_WithoutGraphics ()
2438                 {
2439                         IsVisible_Rectangle (null);
2440                 }
2441
2442                 [Test]
2443                 public void IsVisible_Rectangle_WithGraphics ()
2444                 {
2445                         using (Bitmap bitmap = new Bitmap (40, 40)) {
2446                                 using (Graphics g = Graphics.FromImage (bitmap)) {
2447                                         IsVisible_Rectangle (g);
2448                                 }
2449                         }
2450                 }
2451
2452                 [Test]
2453                 public void Reverse_Arc ()
2454                 {
2455                         using (GraphicsPath gp = new GraphicsPath ()) {
2456                                 gp.AddArc (1f, 1f, 2f, 2f, Pi4, Pi4);
2457                                 PointF[] bp = gp.PathPoints;
2458                                 byte[] bt = gp.PathTypes;
2459
2460                                 gp.Reverse ();
2461                                 PointF[] ap = gp.PathPoints;
2462                                 byte[] at = gp.PathTypes;
2463
2464                                 int count = gp.PointCount;
2465                                 Assert.AreEqual (bp.Length, count, "PointCount");
2466                                 for (int i = 0; i < count; i++) {
2467                                         Assert.AreEqual (bp[i], ap[count - i - 1], "Point" + i.ToString ());
2468                                         // PathTypes are NOT reversed
2469                                         Assert.AreEqual (bt[i], at[i], "Type" + i.ToString ());
2470                                 }
2471                         }
2472                 }
2473         }
2474 }