2 // System.Drawing.Pen 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 {
39 [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
40 public class PenTest {
42 private Pen default_pen;
43 private CustomLineCap custom_line_cap;
46 public void FixtureSetUp ()
48 default_pen = new Pen (Color.Empty);
49 custom_line_cap = new CustomLineCap (new GraphicsPath (), new GraphicsPath ());
52 private void Check (Pen p)
54 Assert.AreEqual (PenAlignment.Center, p.Alignment, "MiterLimit");
55 Assert.AreEqual (typeof (SolidBrush), p.Brush.GetType (), "Brush.Type");
56 Assert.AreEqual (Color.Red.ToArgb (), (p.Brush as SolidBrush).Color.ToArgb (), "Brush.Color");
57 Assert.AreEqual (Color.Red.ToArgb (), p.Color.ToArgb (), "Color");
58 Assert.AreEqual (0, p.CompoundArray.Length, "CompoundArray");
59 Assert.AreEqual (DashCap.Flat, p.DashCap, "DashCap");
60 Assert.AreEqual (0, p.DashOffset, "DashOffset");
61 Assert.AreEqual (DashStyle.Solid, p.DashStyle, "DashStyle");
62 Assert.AreEqual (LineCap.Flat, p.EndCap, "EndCap");
63 Assert.AreEqual (LineJoin.Miter, p.LineJoin, "LineJoin");
64 Assert.AreEqual (10, p.MiterLimit, "MiterLimit");
65 Assert.AreEqual (PenType.SolidColor, p.PenType, "PenType");
66 Assert.AreEqual (LineCap.Flat, p.StartCap, "StartCap");
67 Assert.IsTrue (p.Transform.IsIdentity, "Transform");
71 public void Constructor_Color ()
73 using (Pen p = new Pen (Color.Red)) {
74 Assert.AreEqual (1, p.Width, "Width");
80 public void Constructor_Color_Float ()
82 using (Pen p = new Pen (Color.Red, 2.5f)) {
83 Assert.AreEqual (2.5f, p.Width, "Width");
89 public void Constructor_Color_Float_Zero ()
91 using (Pen p = new Pen (Color.Red, 0.0f)) {
92 Assert.AreEqual (0.0f, p.Width, "Width");
98 public void Constructor_Color_Float_Negative ()
100 using (Pen p = new Pen (Color.Red, -2)) {
101 Assert.AreEqual (-2, p.Width, "Width");
107 public void Constructor_Color_Float_MaxValue ()
109 using (Pen p = new Pen (Color.Red, Single.MaxValue)) {
110 Assert.AreEqual (Single.MaxValue, p.Width, "Width");
116 public void Constructor_Brush ()
118 using (Pen p = new Pen (Brushes.Red)) {
119 Assert.AreEqual (1, p.Width, "Width");
125 [ExpectedException (typeof (ArgumentNullException))]
126 public void Constructor_Brush_Null ()
128 new Pen ((Brush) null);
132 public void Constructor_Brush_Float ()
134 using (Pen p = new Pen (Brushes.Red, 2.5f)) {
135 Assert.AreEqual (2.5f, p.Width, "Width");
141 [ExpectedException (typeof (ArgumentNullException))]
142 public void Constructor_Brush_Float_Null ()
144 new Pen ((Brush) null, Single.MaxValue);
148 public void Constructor_Brush_Float_Zero ()
150 using (Pen p = new Pen (Brushes.Red, 0.0f)) {
151 Assert.AreEqual (0.0f, p.Width, "Width");
157 public void Constructor_Brush_Float_Negative ()
159 using (Pen p = new Pen (Brushes.Red, -2)) {
160 Assert.AreEqual (-2, p.Width, "Width");
166 public void Constructor_Brush_Float_MaxValue ()
168 using (Pen p = new Pen (Brushes.Red, Single.MaxValue)) {
169 Assert.AreEqual (Single.MaxValue, p.Width, "Width");
175 public void Constructor_Brush_DisposeBeforeUse ()
177 using (SolidBrush b = new SolidBrush (Color.Red)) {
178 using (Pen p = new Pen (b, 1)) {
181 using (Bitmap bmp = new Bitmap (12, 12)) {
182 using (Graphics g = Graphics.FromImage (bmp)) {
183 g.DrawLine (p, 1, 1, 10, 10);
190 private void Check2 (Pen p)
192 Assert.AreEqual (typeof (SolidBrush), p.Brush.GetType (), "Brush.Type");
193 Assert.AreEqual (Color.Red.ToArgb (), (p.Brush as SolidBrush).Color.ToArgb (), "Brush.Color");
194 Assert.AreEqual (Color.Red.ToArgb (), p.Color.ToArgb (), "Color");
195 Assert.AreEqual (0, p.CompoundArray.Length, "CompoundArray");
196 // Assert.AreEqual (DashCap.Flat, p.DashCap, "DashCap");
197 Assert.AreEqual (0, p.DashOffset, "DashOffset");
198 Assert.AreEqual (10, p.MiterLimit, "MiterLimit");
199 Assert.AreEqual (PenType.SolidColor, p.PenType, "PenType");
200 Assert.IsTrue (p.Transform.IsIdentity, "Transform");
204 public void Alignment ()
206 using (Pen p = new Pen (Brushes.Gold, Single.NegativeInfinity)) {
207 foreach (PenAlignment pa in Enum.GetValues (typeof (PenAlignment))) {
209 Assert.AreEqual (pa, p.Alignment, pa.ToString ());
215 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
216 public void Alignment_Invalid ()
218 default_pen.Alignment = (PenAlignment) Int32.MinValue;
222 public void Brush_Dispose ()
224 using (Pen p = new Pen (Brushes.Red, 2.5f)) {
225 // are we getting the original brush ?
229 using (Pen clone = (Pen) p.Clone ()) {
232 Assert.IsFalse (Object.ReferenceEquals (b1, p.Brush), "Brush");
238 [ExpectedException (typeof (ArgumentNullException))]
239 public void Brush_Null ()
241 default_pen.Brush = null;
245 [Category ("NotWorking")] // not supported by libgdiplus
246 public void CustomEndCap_Set ()
248 using (Pen p = new Pen (Brushes.DeepSkyBlue, -1)) {
249 p.CustomEndCap = custom_line_cap;
250 Assert.IsNotNull (p.CustomEndCap, "CustomEndCap");
251 Assert.IsFalse (Object.ReferenceEquals (custom_line_cap, p.CustomEndCap), "!same");
256 [ExpectedException (typeof (ArgumentException))]
257 [Category ("NotWorking")] // not supported by libgdiplus
258 public void CustomEndCap_Default ()
260 CustomLineCap clc = default_pen.CustomEndCap;
264 [Category ("NotWorking")] // not supported by libgdiplus
265 public void CustomStartCap_Set ()
267 using (Pen p = new Pen (Brushes.Ivory, 5)) {
268 p.CustomStartCap = custom_line_cap;
269 Assert.IsNotNull (p.CustomStartCap, "CustomStartCap");
270 Assert.IsFalse (Object.ReferenceEquals (custom_line_cap, p.CustomStartCap), "!same");
275 [ExpectedException (typeof (ArgumentException))]
276 [Category ("NotWorking")] // not supported by libgdiplus
277 public void CustomStartCap_Default ()
279 CustomLineCap clc = default_pen.CustomStartCap;
283 public void DashCap_Valid ()
285 // note: YellowGreen is broken by a destructive test so we can't use it afterward
286 // note: this worked with nunit 2.2 because this test was executed before the destructive one
287 using (Pen p = new Pen (Brushes.Yellow, 0)) {
288 foreach (DashCap dc in Enum.GetValues (typeof (DashCap))) {
290 Assert.AreEqual (dc, p.DashCap, dc.ToString ());
296 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
297 public void DashCap_Invalid ()
299 default_pen.DashCap = (DashCap) Int32.MinValue;
303 public void DashOffset ()
305 using (Pen p = new Pen (Brushes.Transparent, 32)) {
307 Assert.AreEqual (0, p.DashOffset, "0");
308 p.DashOffset = Single.MaxValue;
309 Assert.AreEqual (Single.MaxValue, p.DashOffset, "MaxValue");
310 p.DashOffset = Single.MinValue;
311 Assert.AreEqual (Single.MinValue, p.DashOffset, "MinValue");
316 public void DashPattern ()
318 using (Pen p = new Pen (Brushes.Tomato, 1.1f)) {
319 Assert.AreEqual (DashStyle.Solid, p.DashStyle, "Solid");
320 p.DashPattern = new float[1] { 1 };
321 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Custom");
322 Assert.AreEqual (1, p.DashPattern.Length, "DashPattern");
327 [ExpectedException (typeof (ArgumentException))]
328 public void DashPattern_Empty ()
330 default_pen.DashPattern = new float[0];
334 public void DashStyle_Valid ()
336 using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
337 foreach (DashStyle ds in Enum.GetValues (typeof (DashStyle))) {
339 Assert.AreEqual (ds, p.DashStyle, ds.ToString ());
345 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
346 public void DashStyle_Invalid ()
348 default_pen.DashStyle = (DashStyle) Int32.MinValue;
352 public void DashStyle_Custom ()
354 using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
355 Assert.AreEqual (DashStyle.Solid, p.DashStyle, "Solid");
356 // can't ask for Solid (default) -> OutOfMemoryException
357 p.DashStyle = DashStyle.Custom;
358 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Solid->Custom");
359 Assert.AreEqual (1, p.DashPattern.Length, "Solid->Custom.Length");
360 Assert.AreEqual (1, p.DashPattern[0], "Solid->Custom[0]");
362 p.DashStyle = DashStyle.Dot;
363 Assert.AreEqual (DashStyle.Dot, p.DashStyle, "Dot");
364 Assert.AreEqual (2, p.DashPattern.Length, "Dot.Length");
365 Assert.AreEqual (1, p.DashPattern[0], "Dot[0]");
366 Assert.AreEqual (1, p.DashPattern[1], "Dot[1]");
367 p.DashStyle = DashStyle.Custom;
368 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Dot->Custom");
369 Assert.AreEqual (2, p.DashPattern.Length, "Dot->Custom.Length");
370 Assert.AreEqual (1, p.DashPattern[0], "Dot->Custom[0]");
371 Assert.AreEqual (1, p.DashPattern[1], "Dot->Custom[1]");
373 p.DashStyle = DashStyle.Dash;
374 Assert.AreEqual (DashStyle.Dash, p.DashStyle, "Dash");
375 Assert.AreEqual (2, p.DashPattern.Length, "Dash.Length");
376 Assert.AreEqual (3, p.DashPattern[0], "Dash[0]");
377 Assert.AreEqual (1, p.DashPattern[1], "Dash[1]");
378 p.DashStyle = DashStyle.Custom;
379 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Dash->Custom");
380 Assert.AreEqual (2, p.DashPattern.Length, "Dash->Custom.Length");
381 Assert.AreEqual (3, p.DashPattern[0], "Dash->Custom[0]");
382 Assert.AreEqual (1, p.DashPattern[1], "Dash->Custom[1]");
384 p.DashStyle = DashStyle.DashDot;
385 Assert.AreEqual (DashStyle.DashDot, p.DashStyle, "DashDot");
386 Assert.AreEqual (4, p.DashPattern.Length, "DashDot.Length");
387 Assert.AreEqual (3, p.DashPattern[0], "DashDot[0]");
388 Assert.AreEqual (1, p.DashPattern[1], "DashDot[1]");
389 Assert.AreEqual (1, p.DashPattern[2], "DashDot[2]");
390 Assert.AreEqual (1, p.DashPattern[3], "DashDot[3]");
391 p.DashStyle = DashStyle.Custom;
392 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "DashDot->Custom");
393 Assert.AreEqual (4, p.DashPattern.Length, "DashDot->Custom.Length");
394 Assert.AreEqual (3, p.DashPattern[0], "DashDot->Custom[0]");
395 Assert.AreEqual (1, p.DashPattern[1], "DashDot->Custom[1]");
396 Assert.AreEqual (1, p.DashPattern[2], "DashDot->Custom[2]");
397 Assert.AreEqual (1, p.DashPattern[3], "DashDot->Custom[3]");
399 p.DashStyle = DashStyle.DashDotDot;
400 Assert.AreEqual (DashStyle.DashDotDot, p.DashStyle, "DashDotDot");
401 Assert.AreEqual (6, p.DashPattern.Length, "DashDotDot.Length");
402 Assert.AreEqual (3, p.DashPattern[0], "DashDotDot[0]");
403 Assert.AreEqual (1, p.DashPattern[1], "DashDotDot[1]");
404 Assert.AreEqual (1, p.DashPattern[2], "DashDotDot[2]");
405 Assert.AreEqual (1, p.DashPattern[3], "DashDotDot[3]");
406 Assert.AreEqual (1, p.DashPattern[2], "DashDotDot[2]");
407 Assert.AreEqual (1, p.DashPattern[3], "DashDotDot[3]");
408 p.DashStyle = DashStyle.Custom;
409 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "DashDotDot->Custom");
410 Assert.AreEqual (6, p.DashPattern.Length, "DashDotDot->Custom.Length");
411 Assert.AreEqual (3, p.DashPattern[0], "DashDotDot->Custom[0]");
412 Assert.AreEqual (1, p.DashPattern[1], "DashDotDot->Custom[1]");
413 Assert.AreEqual (1, p.DashPattern[2], "DashDotDot->Custom[2]");
414 Assert.AreEqual (1, p.DashPattern[3], "DashDotDot->Custom[3]");
415 Assert.AreEqual (1, p.DashPattern[2], "DashDotDot->Custom[2]");
416 Assert.AreEqual (1, p.DashPattern[3], "DashDotDot->Custom[3]");
418 // resetting to DashStyle.Solid doesn't throw the OutOfMemoryException
420 p.DashStyle = DashStyle.Solid;
421 Assert.AreEqual (DashStyle.Solid, p.DashStyle, "Solid-2");
422 Assert.AreEqual (0, p.DashPattern.Length, "Solid2.Length");
423 p.DashStyle = DashStyle.Custom;
424 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Solid2->Custom");
425 Assert.AreEqual (1, p.DashPattern.Length, "Solid2->Custom.Length");
426 Assert.AreEqual (1, p.DashPattern[0], "Solid2->Custom[0]");
431 [ExpectedException (typeof (OutOfMemoryException))]
432 [Category ("NotWorking")] // MS bug reported as FDBK50053
433 public void DashPattern_Default ()
435 float[] pattern = default_pen.DashPattern;
439 public void EndCap_Valid ()
441 using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
442 foreach (LineCap lc in Enum.GetValues (typeof (LineCap))) {
444 Assert.AreEqual (lc, p.EndCap, lc.ToString ());
450 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
451 public void EndCap_Invalid ()
453 default_pen.EndCap = (LineCap) Int32.MinValue;
457 public void LineJoin_Valid ()
459 using (Pen p = new Pen (Brushes.Chocolate, Single.NaN)) {
460 foreach (LineJoin lj in Enum.GetValues (typeof (LineJoin))) {
462 Assert.AreEqual (lj, p.LineJoin, lj.ToString ());
468 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
469 public void LineJoin_Invalid ()
471 default_pen.LineJoin = (LineJoin) Int32.MinValue;
475 public void MiterLimit ()
477 using (Pen p = new Pen (Brushes.Tan, 1)) {
478 p.MiterLimit = Single.MinValue;
479 Assert.AreEqual (1, p.MiterLimit, "MinValue/1");
481 Assert.AreEqual (1, p.MiterLimit, "0/1");
482 p.MiterLimit = Single.MaxValue;
483 Assert.AreEqual (Single.MaxValue, p.MiterLimit, "MaxValue");
488 public void StartCap_Valid ()
490 using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
491 foreach (LineCap lc in Enum.GetValues (typeof (LineCap))) {
493 Assert.AreEqual (lc, p.StartCap, lc.ToString ());
499 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
500 public void StartCap_Invalid ()
502 default_pen.StartCap = (LineCap) Int32.MinValue;
506 [ExpectedException (typeof (ArgumentNullException))]
507 public void Transform_Null ()
509 default_pen.Transform = null;
513 [ExpectedException (typeof (ArgumentException))]
514 public void Transform_NonInvertible ()
516 using (Pen p = new Pen (Brushes.Snow, Single.MaxValue)) {
517 p.Transform = new Matrix (123, 24, 82, 16, 47, 30);
524 using (Pen p = new Pen (Brushes.Tan, Single.MinValue)) {
525 Assert.AreEqual (Single.MinValue, p.Width, "MinValue");
527 Assert.AreEqual (0, p.Width, "0");
528 p.Width = Single.MaxValue;
529 Assert.AreEqual (Single.MaxValue, p.Width, "MaxValue");
536 using (Pen p = new Pen (Brushes.Red)) {
537 using (Pen clone = (Pen) p.Clone ()) {
544 [ExpectedException (typeof (ArgumentException))]
545 public void Dispose ()
547 Pen p = new Pen (Brushes.Red);
549 p.Alignment = PenAlignment.Center;
550 // exception but not an ObjectDisposedException
554 public void SetLineCap ()
556 using (Pen p = new Pen (Brushes.Red)) {
557 foreach (LineCap sc in Enum.GetValues (typeof (LineCap))) {
558 foreach (LineCap ec in Enum.GetValues (typeof (LineCap))) {
559 foreach (DashCap dc in Enum.GetValues (typeof (DashCap))) {
560 string s = String.Format ("{0}-{1}-{2}", sc, ec, dc);
561 p.SetLineCap (sc, ec, dc);
562 Assert.AreEqual (sc, p.StartCap, s + ".StartCap");
563 Assert.AreEqual (ec, p.EndCap, s + ".EndCap");
564 Assert.AreEqual (dc, p.DashCap, s + ".DashCap");
572 public void SetLineCap_InvalidStartCap ()
574 using (Pen p = new Pen (Brushes.Red)) {
575 p.SetLineCap ((LineCap)Int32.MinValue, LineCap.Flat, DashCap.Flat);
576 // no exception :( (reported as FDBK50057)
577 Assert.AreEqual (Int32.MinValue, (int) p.StartCap, "StartCap");
578 Assert.AreEqual (LineCap.Flat, p.EndCap, "EndCap");
579 Assert.AreEqual (DashCap.Flat, p.DashCap, "DashCap");
584 public void SetLineCap_InvalidEndCap ()
586 using (Pen p = new Pen (Brushes.Red)) {
587 p.SetLineCap (LineCap.Flat, (LineCap)Int32.MinValue, DashCap.Flat);
588 // no exception :( (reported as FDBK50057)
589 Assert.AreEqual (LineCap.Flat, p.StartCap, "StartCap");
590 Assert.AreEqual (Int32.MinValue, (int)p.EndCap, "EndCap");
591 Assert.AreEqual (DashCap.Flat, p.DashCap, "DashCap");
596 public void SetLineCap_InvalidDashCap ()
598 using (Pen p = new Pen (Brushes.Red)) {
599 p.SetLineCap (LineCap.Flat, LineCap.Flat, (DashCap)Int32.MinValue);
600 Assert.AreEqual (LineCap.Flat, p.StartCap, "StartCap");
601 Assert.AreEqual (LineCap.Flat, p.EndCap, "EndCap");
602 // invalid value was reseted to Flat (reported as FDBK50057)
603 Assert.AreEqual (DashCap.Flat, p.DashCap, "DashCap");
608 //[ExpectedException (typeof (ArgumentNullException))] // reported as FDBK50058
609 [ExpectedException (typeof (NullReferenceException))]
610 public void MultiplyTransform1_Null ()
612 default_pen.MultiplyTransform (null);
616 //[ExpectedException (typeof (ArgumentNullException))] // reported as FDBK50058
617 [ExpectedException (typeof (NullReferenceException))]
618 public void MultiplyTransform2_Null ()
620 default_pen.MultiplyTransform (null, MatrixOrder.Append);
624 public void MultiplyTransform2_InvalidMatrixOrder ()
626 using (Pen p = new Pen (Brushes.Red)) {
627 Matrix m1 = new Matrix (2, 0.5f, 0.5f, 4, 10, 20);
628 Matrix m2 = new Matrix (1, 0, 0, 1, -50, -30);
631 p.MultiplyTransform (m1, (MatrixOrder) Int32.MinValue);
632 // no exception, but which order is it ?
633 Matrix invalid = p.Transform;
636 p.MultiplyTransform (m1, MatrixOrder.Append);
637 Assert.IsTrue (invalid.Equals (p.Transform), "Append");
640 p.MultiplyTransform (m1, MatrixOrder.Prepend);
641 Assert.IsFalse (invalid.Equals (p.Transform), "Prepend");
646 [ExpectedException (typeof (ArgumentException))]
647 public void MultiplyTransform_NonInvertible ()
649 using (Matrix noninvertible = new Matrix (123, 24, 82, 16, 47, 30)) {
650 using (Pen p = new Pen (Brushes.Red)) {
651 p.MultiplyTransform (noninvertible);
657 public void ResetTransform ()
659 using (Matrix m = new Matrix (2, 0, 0, 2, 10, -10)) {
660 using (Pen p = new Pen (Brushes.Red)) {
662 Assert.IsFalse (p.Transform.IsIdentity, "Transform.IsIdentity");
664 Assert.IsTrue (p.Transform.IsIdentity, "Reset.IsIdentity");
670 public void RotateTransform ()
672 using (Pen p = new Pen (Brushes.Red)) {
673 p.RotateTransform (90);
674 float[] elements = p.Transform.Elements;
675 Assert.AreEqual (0, elements[0], 0.1, "matrix.0");
676 Assert.AreEqual (1, elements[1], 0.1, "matrix.1");
677 Assert.AreEqual (-1, elements[2], 0.1, "matrix.2");
678 Assert.AreEqual (0, elements[3], 0.1, "matrix.3");
679 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
680 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
682 p.RotateTransform (270);
683 Assert.IsTrue (p.Transform.IsIdentity, "Transform.IsIdentity");
688 [ExpectedException (typeof (ArgumentException))]
689 public void RotateTransform_InvalidOrder ()
691 default_pen.RotateTransform (720, (MatrixOrder) Int32.MinValue);
695 public void ScaleTransform ()
697 using (Pen p = new Pen (Brushes.Red)) {
698 p.ScaleTransform (2, 4);
699 float[] elements = p.Transform.Elements;
700 Assert.AreEqual (2, elements[0], 0.1, "matrix.0");
701 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
702 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
703 Assert.AreEqual (4, elements[3], 0.1, "matrix.3");
704 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
705 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
707 p.ScaleTransform (0.5f, 0.25f);
708 Assert.IsTrue (p.Transform.IsIdentity, "Transform.IsIdentity");
713 public void ScaleTransform_MaxMin ()
715 using (Pen p = new Pen (Brushes.Red)) {
716 p.ScaleTransform (Single.MaxValue, Single.MinValue);
717 float[] elements = p.Transform.Elements;
718 Assert.AreEqual (Single.MaxValue, elements[0], 1e33, "matrix.0");
719 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
720 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
721 Assert.AreEqual (Single.MinValue, elements[3], 1e33, "matrix.3");
722 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
723 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
728 [ExpectedException (typeof (ArgumentException))]
729 public void ScaleTransform_InvalidOrder ()
731 default_pen.ScaleTransform (1, 1, (MatrixOrder) Int32.MinValue);
735 public void TranslateTransform ()
737 using (Pen p = new Pen (Brushes.Red)) {
738 p.TranslateTransform (1, 1);
739 float[] elements = p.Transform.Elements;
740 Assert.AreEqual (1, elements[0], 0.1, "matrix.0");
741 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
742 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
743 Assert.AreEqual (1, elements[3], 0.1, "matrix.3");
744 Assert.AreEqual (1, elements[4], 0.1, "matrix.4");
745 Assert.AreEqual (1, elements[5], 0.1, "matrix.5");
747 p.TranslateTransform (-1, -1);
748 elements = p.Transform.Elements;
749 Assert.AreEqual (1, elements[0], 0.1, "revert.matrix.0");
750 Assert.AreEqual (0, elements[1], 0.1, "revert.matrix.1");
751 Assert.AreEqual (0, elements[2], 0.1, "revert.matrix.2");
752 Assert.AreEqual (1, elements[3], 0.1, "revert.matrix.3");
753 Assert.AreEqual (0, elements[4], 0.1, "revert.matrix.4");
754 Assert.AreEqual (0, elements[5], 0.1, "revert.matrix.5");
759 [ExpectedException (typeof (ArgumentException))]
760 public void TranslateTransform_InvalidOrder ()
762 default_pen.TranslateTransform (1, 1, (MatrixOrder) Int32.MinValue);
766 public void Transform_Operations ()
768 using (Pen p = new Pen (Brushes.Red)) {
769 Matrix clone = p.Transform.Clone ();
770 Matrix mul = clone.Clone ();
772 clone.Multiply (mul, MatrixOrder.Append);
773 p.MultiplyTransform (mul, MatrixOrder.Append);
774 Assert.AreEqual (p.Transform, clone, "Multiply/Append");
776 clone.Multiply (mul, MatrixOrder.Prepend);
777 p.MultiplyTransform (mul, MatrixOrder.Prepend);
778 Assert.AreEqual (p.Transform, clone, "Multiply/Prepend");
780 clone.Rotate (45, MatrixOrder.Append);
781 p.RotateTransform (45, MatrixOrder.Append);
782 Assert.AreEqual (p.Transform, clone, "Rotate/Append");
784 clone.Rotate (45, MatrixOrder.Prepend);
785 p.RotateTransform (45, MatrixOrder.Prepend);
786 Assert.AreEqual (p.Transform, clone, "Rotate/Prepend");
788 clone.Scale (0.25f, 2, MatrixOrder.Append);
789 p.ScaleTransform (0.25f, 2, MatrixOrder.Append);
790 Assert.AreEqual (p.Transform, clone, "Scale/Append");
792 clone.Scale (0.25f, 2, MatrixOrder.Prepend);
793 p.ScaleTransform (0.25f, 2, MatrixOrder.Prepend);
794 Assert.AreEqual (p.Transform, clone, "Scale/Prepend");
796 clone.Translate (10, 20, MatrixOrder.Append);
797 p.TranslateTransform (10, 20, MatrixOrder.Append);
798 Assert.AreEqual (p.Transform, clone, "Translate/Append");
800 clone.Translate (30, 40, MatrixOrder.Prepend);
801 p.TranslateTransform (30, 40, MatrixOrder.Prepend);
802 Assert.AreEqual (p.Transform, clone, "Translate/Prepend");
806 Assert.AreEqual (p.Transform, clone, "Reset");