2 // System.Drawing.GraphicsPath unit tests
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
30 using SC = System.ComponentModel;
32 using System.Drawing.Drawing2D;
33 using System.Security.Permissions;
34 using NUnit.Framework;
36 namespace MonoTests.System.Drawing.Drawing2D {
39 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
40 public class GraphicsPathTest {
42 private const float Pi4 = (float) (Math.PI / 4);
44 private void CheckEmpty (string prefix, GraphicsPath gp)
46 Assert.AreEqual (0, gp.PathData.Points.Length, "PathData.Points");
47 Assert.AreEqual (0, gp.PathData.Types.Length, "PathData.Types");
48 Assert.AreEqual (0, gp.PointCount, prefix + "PointCount");
52 public void Constructor_InvalidFillMode ()
54 GraphicsPath gp = new GraphicsPath ((FillMode) Int32.MinValue);
55 Assert.AreEqual (Int32.MinValue, (int) gp.FillMode, "FillMode");
56 CheckEmpty ("InvalidFillMode.", gp);
60 [ExpectedException (typeof (ArgumentNullException))]
61 public void Constructor_Point_Null_Byte ()
63 new GraphicsPath ((Point[]) null, new byte[1]);
67 [ExpectedException (typeof (NullReferenceException))]
68 public void Constructor_Point_Byte_Null ()
70 new GraphicsPath (new Point[1], null);
74 [ExpectedException (typeof (ArgumentException))]
75 public void Constructor_Point_Byte_LengthMismatch ()
77 new GraphicsPath (new Point[1], new byte [2]);
81 [ExpectedException (typeof (ArgumentNullException))]
82 public void Constructor_PointF_Null_Byte ()
84 new GraphicsPath ((PointF[])null, new byte [1]);
88 [ExpectedException (typeof (NullReferenceException))]
89 public void Constructor_PointF_Byte_Null ()
91 new GraphicsPath ( new PointF[1], null);
95 [ExpectedException (typeof (ArgumentException))]
96 public void Constructor_PointF_Byte_LengthMismatch ()
98 new GraphicsPath (new PointF[2], new byte [1]);
102 public void GraphicsPath_Empty ()
104 GraphicsPath gp = new GraphicsPath ();
105 Assert.AreEqual (FillMode.Alternate, gp.FillMode, "Empty.FillMode");
106 CheckEmpty ("Empty.", gp);
108 GraphicsPath clone = (GraphicsPath) gp.Clone ();
109 Assert.AreEqual (FillMode.Alternate, gp.FillMode, "Clone.FillMode");
110 CheckEmpty ("Clone.", gp);
114 [ExpectedException (typeof (ArgumentException))]
115 public void GraphicsPath_Empty_PathPoints ()
117 Assert.IsNull (new GraphicsPath ().PathPoints);
121 [ExpectedException (typeof (ArgumentException))]
122 public void GraphicsPath_Empty_PathTypes ()
124 Assert.IsNull (new GraphicsPath ().PathTypes);
128 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
129 public void FillMode_Invalid ()
131 // constructor accept an invalid FillMode
132 GraphicsPath gp = new GraphicsPath ((FillMode) Int32.MaxValue);
133 Assert.AreEqual (Int32.MaxValue, (int) gp.FillMode, "MaxValue");
134 // but you can't set the FillMode property to an invalid value ;-)
135 gp.FillMode = (FillMode) Int32.MaxValue;
139 public void PathData_CannotChange ()
141 GraphicsPath gp = new GraphicsPath ();
142 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
144 Assert.AreEqual (1f, gp.PathData.Points[0].X, "Points[0].X");
145 Assert.AreEqual (1f, gp.PathData.Points[0].Y, "Points[0].Y");
147 // now try to change the first point
148 gp.PathData.Points[0] = new Point (0, 0);
149 // the changes isn't reflected in the property
150 Assert.AreEqual (1f, gp.PathData.Points[0].X, "Points[0].X-1");
151 Assert.AreEqual (1f, gp.PathData.Points[0].Y, "Points[0].Y-1");
155 public void PathPoints_CannotChange ()
157 GraphicsPath gp = new GraphicsPath ();
158 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
160 Assert.AreEqual (1f, gp.PathPoints[0].X, "PathPoints[0].X");
161 Assert.AreEqual (1f, gp.PathPoints[0].Y, "PathPoints[0].Y");
163 // now try to change the first point
164 gp.PathPoints[0] = new Point (0, 0);
165 // the changes isn't reflected in the property
166 Assert.AreEqual (1f, gp.PathPoints[0].X, "PathPoints[0].X-1");
167 Assert.AreEqual (1f, gp.PathPoints[0].Y, "PathPoints[0].Y-1");
171 public void PathTypes_CannotChange ()
173 GraphicsPath gp = new GraphicsPath ();
174 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
176 Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
178 // now try to change the first type
180 // the changes isn't reflected in the property
181 Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]-1");
184 private void CheckArc (GraphicsPath path)
186 Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
187 Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
188 Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
190 Assert.AreEqual (2.999906f, path.PathData.Points[0].X, "Points[0].X");
191 Assert.AreEqual (2.013707f, path.PathPoints[0].Y, "Points[0].Y");
192 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
193 Assert.AreEqual (2.999843f, path.PathData.Points[1].X, "Points[1].X");
194 Assert.AreEqual (2.018276f, path.PathPoints[1].Y, "Points[1].Y");
195 Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
196 Assert.AreEqual (2.99974918f, path.PathData.Points[2].X, "Points[2].X");
197 Assert.AreEqual (2.02284455f, path.PathPoints[2].Y, "Points[2].Y");
198 Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
199 Assert.AreEqual (2.999624f, path.PathData.Points[3].X, "Points[3].X");
200 Assert.AreEqual (2.027412f, path.PathPoints[3].Y, "Points[3].Y");
201 Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
205 public void AddArc_Rectangle ()
207 GraphicsPath gp = new GraphicsPath ();
208 gp.AddArc (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
213 public void AddArc_RectangleF ()
215 GraphicsPath gp = new GraphicsPath ();
216 gp.AddArc (new RectangleF (1f, 1f, 2f, 2f), Pi4, Pi4);
221 public void AddArc_Int ()
223 GraphicsPath gp = new GraphicsPath ();
224 gp.AddArc (1, 1, 2, 2, Pi4, Pi4);
229 public void AddArc_Float ()
231 GraphicsPath gp = new GraphicsPath ();
232 gp.AddArc (1f, 1f, 2f, 2f, Pi4, Pi4);
236 private void CheckBezier (GraphicsPath path)
238 Assert.AreEqual (4, path.PointCount, "PointCount");
239 Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
240 Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
241 Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
243 Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
244 Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
245 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
246 Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
247 Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
248 Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
249 Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
250 Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
251 Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
252 Assert.AreEqual (4f, path.PathData.Points[3].X, "Points[3].X");
253 Assert.AreEqual (4f, path.PathPoints[3].Y, "Points[3].Y");
254 Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
258 public void AddBezier_Point ()
260 GraphicsPath gp = new GraphicsPath ();
261 gp.AddBezier (new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4));
266 public void AddBezier_PointF ()
268 GraphicsPath gp = new GraphicsPath ();
269 gp.AddBezier (new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f));
274 public void AddBezier_Int ()
276 GraphicsPath gp = new GraphicsPath ();
277 gp.AddBezier (1, 1, 2, 2, 3, 3, 4, 4);
282 public void AddBezier_Float ()
284 GraphicsPath gp = new GraphicsPath ();
285 gp.AddBezier (1f, 1f, 2f, 2f, 3f, 3f, 4f, 4f);
290 [ExpectedException (typeof (ArgumentNullException))]
291 public void AddBeziers_Point_Null ()
293 new GraphicsPath ().AddBeziers ((Point[]) null);
297 [ExpectedException (typeof (ArgumentException))]
298 public void AddBeziers_3_Points ()
300 GraphicsPath gp = new GraphicsPath ();
301 gp.AddBeziers (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
305 public void AddBeziers_Point ()
307 GraphicsPath gp = new GraphicsPath ();
308 gp.AddBeziers (new Point[4] { new Point (1, 1), new Point (2, 2), new Point (3, 3), new Point (4, 4) });
313 [ExpectedException (typeof (ArgumentNullException))]
314 public void AddBeziers_PointF_Null ()
316 new GraphicsPath ().AddBeziers ((PointF[]) null);
320 [ExpectedException (typeof (ArgumentException))]
321 public void AddBeziers_3_PointFs ()
323 GraphicsPath gp = new GraphicsPath ();
324 gp.AddBeziers (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
328 public void AddBeziers_PointF ()
330 GraphicsPath gp = new GraphicsPath ();
331 gp.AddBeziers (new PointF[4] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f), new PointF (4f, 4f) });
335 private void CheckEllipse (GraphicsPath path)
337 Assert.AreEqual (13, path.PathPoints.Length, "PathPoints");
338 Assert.AreEqual (13, path.PathTypes.Length, "PathPoints");
339 Assert.AreEqual (13, path.PathData.Points.Length, "PathData");
341 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
342 RectangleF rect = path.GetBounds ();
343 Assert.AreEqual (1f, rect.X, "Bounds.X");
344 Assert.AreEqual (1f, rect.Y, "Bounds.Y");
345 Assert.AreEqual (2f, rect.Width, "Bounds.Width");
346 Assert.AreEqual (2f, rect.Height, "Bounds.Height");
348 Assert.AreEqual (0, path.PathData.Types[0], "PathData.Types[0]");
349 for (int i = 1; i < 12; i++)
350 Assert.AreEqual (3, path.PathTypes[i], "PathTypes" + i.ToString ());
351 Assert.AreEqual (131, path.PathData.Types[12], "PathData.Types[12]");
355 public void AddEllipse_Rectangle ()
357 GraphicsPath gp = new GraphicsPath ();
358 gp.AddEllipse (new Rectangle (1, 1, 2, 2));
363 public void AddEllipse_RectangleF ()
365 GraphicsPath gp = new GraphicsPath ();
366 gp.AddEllipse (new RectangleF (1f, 1f, 2f, 2f));
371 public void AddEllipse_Int ()
373 GraphicsPath gp = new GraphicsPath ();
374 gp.AddEllipse (1, 1, 2, 2);
379 public void AddEllipse_Float ()
381 GraphicsPath gp = new GraphicsPath ();
382 gp.AddEllipse (1f, 1f, 2f, 2f);
386 private void CheckLine (GraphicsPath path)
388 Assert.AreEqual (2, path.PathPoints.Length, "PathPoints");
389 Assert.AreEqual (2, path.PathTypes.Length, "PathPoints");
390 Assert.AreEqual (2, path.PathData.Points.Length, "PathData");
392 Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
393 Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
394 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
395 Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
396 Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
397 Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
401 public void AddLine_Point ()
403 GraphicsPath gp = new GraphicsPath ();
404 gp.AddLine (new Point (1, 1), new Point (2, 2));
409 public void AddLine_PointF ()
411 GraphicsPath gp = new GraphicsPath ();
412 gp.AddLine (new PointF (1f, 1f), new PointF (2f, 2f));
417 public void AddLine_Int ()
419 GraphicsPath gp = new GraphicsPath ();
420 gp.AddLine (1, 1, 2, 2);
425 public void AddLine_Float ()
427 GraphicsPath gp = new GraphicsPath ();
428 gp.AddLine (1f, 1f, 2f, 2f);
433 public void AddLine_SamePoint ()
435 GraphicsPath gp = new GraphicsPath ();
436 gp.AddLine (new Point (1, 1), new Point (1, 1));
437 Assert.AreEqual (2, gp.PointCount, "PointCount");
438 Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
439 Assert.AreEqual (1, gp.PathTypes[1], "PathTypes[1]");
443 [ExpectedException (typeof (ArgumentNullException))]
444 public void AddLines_Point_Null ()
446 new GraphicsPath ().AddLines ((Point[])null);
450 [ExpectedException (typeof (ArgumentException))]
451 public void AddLines_Point_0 ()
453 GraphicsPath gp = new GraphicsPath ();
454 gp.AddLines (new Point[0]);
459 [Category ("NotWorking")]
460 public void AddLines_Point_1 ()
462 GraphicsPath gp = new GraphicsPath ();
463 gp.AddLines (new Point[1] { new Point (1, 1) });
464 // Special case - a line with a single point is valid
465 Assert.AreEqual (1, gp.PointCount, "PointCount");
466 Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
470 public void AddLines_Point ()
472 GraphicsPath gp = new GraphicsPath ();
473 gp.AddLines (new Point[2] { new Point (1, 1), new Point (2, 2) });
478 [ExpectedException (typeof (ArgumentNullException))]
479 public void AddLines_PointF_Null ()
481 new GraphicsPath ().AddLines ((PointF[]) null);
485 [ExpectedException (typeof (ArgumentException))]
486 public void AddLines_PointF_0 ()
488 GraphicsPath gp = new GraphicsPath ();
489 gp.AddLines (new PointF[0]);
494 [Category ("NotWorking")]
495 public void AddLines_PointF_1 ()
497 GraphicsPath gp = new GraphicsPath ();
498 gp.AddLines (new PointF[1] { new PointF (1f, 1f) });
499 // Special case - a line with a single point is valid
500 Assert.AreEqual (1, gp.PointCount, "PointCount");
501 Assert.AreEqual (0, gp.PathTypes[0], "PathTypes[0]");
505 public void AddLines_PointF ()
507 GraphicsPath gp = new GraphicsPath ();
508 gp.AddLines (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
512 private void CheckPie (GraphicsPath path)
514 // the number of points generated for a Pie isn't the same between Mono and MS
516 Assert.AreEqual (5, path.PathPoints.Length, "PathPoints");
517 Assert.AreEqual (5, path.PathTypes.Length, "PathPoints");
518 Assert.AreEqual (5, path.PathData.Points.Length, "PathData");
520 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
521 RectangleF rect = path.GetBounds ();
522 Assert.AreEqual (2f, rect.X, "Bounds.X");
523 Assert.AreEqual (2f, rect.Y, "Bounds.Y");
524 Assert.AreEqual (0.9999058f, rect.Width, "Bounds.Width");
525 Assert.AreEqual (0.0274119377f, rect.Height, "Bounds.Height");
527 Assert.AreEqual (2f, path.PathData.Points[0].X, "Points[0].X");
528 Assert.AreEqual (2f, path.PathPoints[0].Y, "Points[0].Y");
529 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
530 Assert.AreEqual (2.99990582f, path.PathData.Points[1].X, "Points[1].X");
531 Assert.AreEqual (2.01370716f, path.PathPoints[1].Y, "Points[1].Y");
532 Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
533 Assert.AreEqual (2.99984312f, path.PathData.Points[2].X, "Points[2].X");
534 Assert.AreEqual (2.018276f, path.PathPoints[2].Y, "Points[2].Y");
535 Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
536 Assert.AreEqual (2.99974918f, path.PathData.Points[3].X, "Points[2].X");
537 Assert.AreEqual (2.02284455f, path.PathPoints[3].Y, "Points[2].Y");
538 Assert.AreEqual (3, path.PathData.Types[3], "Types[2]");
539 Assert.AreEqual (2.999624f, path.PathData.Points[4].X, "Points[3].X");
540 Assert.AreEqual (2.027412f, path.PathPoints[4].Y, "Points[3].Y");
541 Assert.AreEqual (131, path.PathTypes[4], "Types[3]");
546 public void AddPie_Rect ()
548 GraphicsPath gp = new GraphicsPath ();
549 gp.AddPie (new Rectangle (1, 1, 2, 2), Pi4, Pi4);
554 public void AddPie_Int ()
556 GraphicsPath gp = new GraphicsPath ();
557 gp.AddPie (1, 1, 2, 2, Pi4, Pi4);
562 public void AddPie_Float ()
564 GraphicsPath gp = new GraphicsPath ();
565 gp.AddPie (1f, 1f, 2f, 2f, Pi4, Pi4);
569 private void CheckPolygon (GraphicsPath path)
571 // an extra point is generated by Mono (libgdiplus)
573 Assert.AreEqual (3, path.PathPoints.Length, "PathPoints");
574 Assert.AreEqual (3, path.PathTypes.Length, "PathPoints");
575 Assert.AreEqual (3, path.PathData.Points.Length, "PathData");
577 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
578 RectangleF rect = path.GetBounds ();
579 Assert.AreEqual (1f, rect.X, "Bounds.X");
580 Assert.AreEqual (1f, rect.Y, "Bounds.Y");
581 Assert.AreEqual (2f, rect.Width, "Bounds.Width");
582 Assert.AreEqual (2f, rect.Height, "Bounds.Height");
584 Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
585 Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
586 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
587 Assert.AreEqual (2f, path.PathData.Points[1].X, "Points[1].X");
588 Assert.AreEqual (2f, path.PathPoints[1].Y, "Points[1].Y");
589 Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
590 Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
591 Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
592 // the extra point change the type of the last point
594 Assert.AreEqual (129, path.PathData.Types[2], "Types[2]");
599 [ExpectedException (typeof (ArgumentNullException))]
600 public void AddPolygon_Point_Null ()
602 new GraphicsPath ().AddPolygon ((Point[]) null);
606 [ExpectedException (typeof (ArgumentException))]
607 public void AddPolygon_Point_Empty ()
609 new GraphicsPath ().AddPolygon (new Point[0]);
613 [ExpectedException (typeof (ArgumentException))]
614 public void AddPolygon_Point_1 ()
616 GraphicsPath gp = new GraphicsPath ();
617 gp.AddPolygon (new Point[1] { new Point (1, 1) });
621 [ExpectedException (typeof (ArgumentException))]
622 public void AddPolygon_Point_2 ()
624 GraphicsPath gp = new GraphicsPath ();
625 gp.AddPolygon (new Point[2] { new Point (1, 1), new Point (2, 2) });
629 public void AddPolygon_Point_3 ()
631 GraphicsPath gp = new GraphicsPath ();
632 gp.AddPolygon (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
637 [ExpectedException (typeof (ArgumentNullException))]
638 public void AddPolygon_PointF_Null ()
640 new GraphicsPath ().AddPolygon ((PointF[]) null);
644 [ExpectedException (typeof (ArgumentException))]
645 public void AddPolygon_PointF_Empty ()
647 new GraphicsPath ().AddPolygon (new PointF[0]);
651 [ExpectedException (typeof (ArgumentException))]
652 public void AddPolygon_PointF_1 ()
654 GraphicsPath gp = new GraphicsPath ();
655 gp.AddPolygon (new PointF[1] { new PointF (1f, 1f) });
659 [ExpectedException (typeof (ArgumentException))]
660 public void AddPolygon_PointF_2 ()
662 GraphicsPath gp = new GraphicsPath ();
663 gp.AddPolygon (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
667 public void AddPolygon_PointF_3 ()
669 GraphicsPath gp = new GraphicsPath ();
670 gp.AddPolygon (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
674 private void CheckRectangle (GraphicsPath path)
676 Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
677 Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
678 Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
680 Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
681 Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
682 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
683 Assert.AreEqual (3f, path.PathData.Points[1].X, "Points[1].X");
684 Assert.AreEqual (1f, path.PathPoints[1].Y, "Points[1].Y");
685 Assert.AreEqual (1, path.PathTypes[1], "Types[1]");
686 Assert.AreEqual (3f, path.PathData.Points[2].X, "Points[2].X");
687 Assert.AreEqual (3f, path.PathPoints[2].Y, "Points[2].Y");
688 Assert.AreEqual (1, path.PathData.Types[2], "Types[2]");
689 Assert.AreEqual (1f, path.PathData.Points[3].X, "Points[3].X");
690 Assert.AreEqual (3f, path.PathPoints[3].Y, "Points[3].Y");
691 Assert.AreEqual (129, path.PathTypes[3], "Types[3]");
695 public void AddRectangle_Int ()
697 GraphicsPath gp = new GraphicsPath ();
698 gp.AddRectangle (new Rectangle (1, 1, 2, 2));
703 public void AddRectangle_Float ()
705 GraphicsPath gp = new GraphicsPath ();
706 gp.AddRectangle (new RectangleF (1f, 1f, 2f, 2f));
711 [ExpectedException (typeof (ArgumentNullException))]
712 public void AddRectangles_Int_Null ()
714 GraphicsPath gp = new GraphicsPath ();
715 gp.AddRectangles ((Rectangle[]) null);
719 [ExpectedException (typeof (ArgumentException))]
720 public void AddRectangles_Int_Empty ()
722 GraphicsPath gp = new GraphicsPath ();
723 gp.AddRectangles (new Rectangle[0]);
728 public void AddRectangles_Int ()
730 GraphicsPath gp = new GraphicsPath ();
731 gp.AddRectangles (new Rectangle[1] { new Rectangle (1, 1, 2, 2) });
736 [ExpectedException (typeof (ArgumentNullException))]
737 public void AddRectangles_Float_Null ()
739 GraphicsPath gp = new GraphicsPath ();
740 gp.AddRectangles ((RectangleF[]) null);
744 [ExpectedException (typeof (ArgumentException))]
745 public void AddRectangles_Float_Empty ()
747 GraphicsPath gp = new GraphicsPath ();
748 gp.AddRectangles ( new RectangleF[0]);
753 public void AddRectangles_Float ()
755 GraphicsPath gp = new GraphicsPath ();
756 gp.AddRectangles (new RectangleF [1] { new RectangleF (1f, 1f, 2f, 2f) });
761 [ExpectedException (typeof (ArgumentNullException))]
762 public void AddPath_Null ()
764 new GraphicsPath ().AddPath (null, false);
768 public void AddPath ()
770 GraphicsPath gpr = new GraphicsPath ();
771 gpr.AddRectangle (new Rectangle (1, 1, 2, 2));
772 GraphicsPath gp = new GraphicsPath ();
773 gp.AddPath (gpr, true);
777 private void CheckClosedCurve (GraphicsPath path)
779 Assert.AreEqual (10, path.PathPoints.Length, "PathPoints");
780 Assert.AreEqual (10, path.PathTypes.Length, "PathPoints");
781 Assert.AreEqual (10, path.PathData.Points.Length, "PathData");
783 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
784 RectangleF rect = path.GetBounds ();
785 Assert.AreEqual (0.8333333f, rect.X, "Bounds.X");
786 Assert.AreEqual (0.8333333f, rect.Y, "Bounds.Y");
787 Assert.AreEqual (2.33333278f, rect.Width, "Bounds.Width");
788 Assert.AreEqual (2.33333278f, rect.Height, "Bounds.Height");
790 Assert.AreEqual (0, path.PathData.Types[0], "PathData.Types[0]");
791 for (int i = 1; i < 9; i++)
792 Assert.AreEqual (3, path.PathTypes[i], "PathTypes" + i.ToString ());
793 Assert.AreEqual (131, path.PathData.Types[9], "PathData.Types[9]");
797 [ExpectedException (typeof (ArgumentNullException))]
798 public void AddClosedCurve_Point_Null ()
800 new GraphicsPath ().AddClosedCurve ((Point[])null);
804 [ExpectedException (typeof (ArgumentException))]
805 public void AddClosedCurve_Point_0 ()
807 GraphicsPath gp = new GraphicsPath ();
808 gp.AddClosedCurve (new Point [0]);
812 [ExpectedException (typeof (ArgumentException))]
813 public void AddClosedCurve_Point_1 ()
815 GraphicsPath gp = new GraphicsPath ();
816 gp.AddClosedCurve (new Point[1] { new Point (1, 1) });
820 [ExpectedException (typeof (ArgumentException))]
821 public void AddClosedCurve_Point_2 ()
823 GraphicsPath gp = new GraphicsPath ();
824 gp.AddClosedCurve (new Point[2] { new Point (1, 1), new Point (2, 2) });
828 public void AddClosedCurve_Point_3 ()
830 GraphicsPath gp = new GraphicsPath ();
831 gp.AddClosedCurve (new Point[3] { new Point (1, 1), new Point (2, 2), new Point (3, 3) });
832 CheckClosedCurve (gp);
836 [ExpectedException (typeof (ArgumentNullException))]
837 public void AddClosedCurve_PointF_Null ()
839 new GraphicsPath ().AddClosedCurve ((PointF[]) null);
843 [ExpectedException (typeof (ArgumentException))]
844 public void AddClosedCurve_PointF_0 ()
846 GraphicsPath gp = new GraphicsPath ();
847 gp.AddClosedCurve (new PointF[0]);
851 [ExpectedException (typeof (ArgumentException))]
852 public void AddClosedCurve_PointF_1 ()
854 GraphicsPath gp = new GraphicsPath ();
855 gp.AddClosedCurve (new PointF[1] { new PointF (1f, 1f) });
859 [ExpectedException (typeof (ArgumentException))]
860 public void AddClosedCurve_PointF_2 ()
862 GraphicsPath gp = new GraphicsPath ();
863 gp.AddClosedCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
867 public void AddClosedCurve_PointF_3 ()
869 GraphicsPath gp = new GraphicsPath ();
870 gp.AddClosedCurve (new PointF[3] { new PointF (1f, 1f), new PointF (2f, 2f), new PointF (3f, 3f) });
871 CheckClosedCurve (gp);
874 private void CheckCurve (GraphicsPath path)
876 Assert.AreEqual (4, path.PathPoints.Length, "PathPoints");
877 Assert.AreEqual (4, path.PathTypes.Length, "PathPoints");
878 Assert.AreEqual (4, path.PathData.Points.Length, "PathData");
880 // GetBounds (well GdipGetPathWorldBounds) isn't implemented
881 RectangleF rect = path.GetBounds ();
882 Assert.AreEqual (1.0f, rect.X, "Bounds.X");
883 Assert.AreEqual (1.0f, rect.Y, "Bounds.Y");
884 Assert.AreEqual (1.0f, rect.Width, "Bounds.Width");
885 Assert.AreEqual (1.0f, rect.Height, "Bounds.Height");
887 Assert.AreEqual (1f, path.PathData.Points[0].X, "Points[0].X");
888 Assert.AreEqual (1f, path.PathPoints[0].Y, "Points[0].Y");
889 Assert.AreEqual (0, path.PathData.Types[0], "Types[0]");
890 // Mono has wrong? results
892 Assert.AreEqual (1.16666663f, path.PathData.Points[1].X, "Points[1].X");
893 Assert.AreEqual (1.16666663f, path.PathPoints[1].Y, "Points[1].Y");
895 Assert.AreEqual (3, path.PathTypes[1], "Types[1]");
896 // Mono has wrong? results
898 Assert.AreEqual (1.83333325f, path.PathData.Points[2].X, "Points[2].X");
899 Assert.AreEqual (1.83333325f, path.PathPoints[2].Y, "Points[2].Y");
901 Assert.AreEqual (3, path.PathData.Types[2], "Types[2]");
902 Assert.AreEqual (2f, path.PathData.Points[3].X, "Points[3].X");
903 Assert.AreEqual (2f, path.PathPoints[3].Y, "Points[3].Y");
904 Assert.AreEqual (3, path.PathTypes[3], "Types[3]");
908 [ExpectedException (typeof (ArgumentNullException))]
909 public void AddCurve_Point_Null ()
911 new GraphicsPath ().AddCurve ((Point[]) null);
915 [ExpectedException (typeof (ArgumentException))]
916 public void AddCurve_Point_0 ()
918 GraphicsPath gp = new GraphicsPath ();
919 gp.AddCurve (new Point[0]);
923 [ExpectedException (typeof (ArgumentException))]
924 public void AddCurve_Point_1 ()
926 GraphicsPath gp = new GraphicsPath ();
927 gp.AddCurve (new Point[1] { new Point (1, 1) });
931 public void AddCurve_Point_2 ()
933 GraphicsPath gp = new GraphicsPath ();
934 gp.AddCurve (new Point[2] { new Point (1, 1), new Point (2, 2) });
939 [ExpectedException (typeof (ArgumentNullException))]
940 public void AddCurve_PointF_Null ()
942 new GraphicsPath ().AddCurve ((PointF[]) null);
946 [ExpectedException (typeof (ArgumentException))]
947 public void AddCurve_PointF_0 ()
949 GraphicsPath gp = new GraphicsPath ();
950 gp.AddCurve (new PointF[0]);
954 [ExpectedException (typeof (ArgumentException))]
955 public void AddCurve_PointF_1 ()
957 GraphicsPath gp = new GraphicsPath ();
958 gp.AddCurve (new PointF[1] { new PointF (1f, 1f) });
962 public void AddCurve_PointF_2 ()
964 GraphicsPath gp = new GraphicsPath ();
965 gp.AddCurve (new PointF[2] { new PointF (1f, 1f), new PointF (2f, 2f) });
970 [ExpectedException (typeof (ArgumentNullException))]
971 public void Transform_Null ()
973 new GraphicsPath ().Transform (null);
977 [Category ("NotWorking")]
978 public void Flatten_Null ()
980 new GraphicsPath ().Flatten (null);
981 // no ArgumentNullException or NullReferenceException
985 [Category ("NotWorking")]
986 public void Flatten_NullFloat ()
988 new GraphicsPath ().Flatten (null, 1f);
989 // no ArgumentNullException or NullReferenceException
993 [ExpectedException (typeof (ArgumentNullException))]
994 public void Warp_Null ()
996 new GraphicsPath ().Warp (null, new RectangleF ());