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 public void Constructor_Brush_Null ()
127 Assert.Throws<ArgumentNullException> (() => new Pen ((Brush) null));
131 public void Constructor_Brush_Float ()
133 using (Pen p = new Pen (Brushes.Red, 2.5f)) {
134 Assert.AreEqual (2.5f, p.Width, "Width");
140 public void Constructor_Brush_Float_Null ()
142 Assert.Throws<ArgumentNullException> (() => new Pen ((Brush) null, Single.MaxValue));
146 public void Constructor_Brush_Float_Zero ()
148 using (Pen p = new Pen (Brushes.Red, 0.0f)) {
149 Assert.AreEqual (0.0f, p.Width, "Width");
155 public void Constructor_Brush_Float_Negative ()
157 using (Pen p = new Pen (Brushes.Red, -2)) {
158 Assert.AreEqual (-2, p.Width, "Width");
164 public void Constructor_Brush_Float_MaxValue ()
166 using (Pen p = new Pen (Brushes.Red, Single.MaxValue)) {
167 Assert.AreEqual (Single.MaxValue, p.Width, "Width");
173 public void Constructor_Brush_DisposeBeforeUse ()
175 using (SolidBrush b = new SolidBrush (Color.Red)) {
176 using (Pen p = new Pen (b, 1)) {
179 using (Bitmap bmp = new Bitmap (12, 12)) {
180 using (Graphics g = Graphics.FromImage (bmp)) {
181 g.DrawLine (p, 1, 1, 10, 10);
188 private void Check2 (Pen p)
190 Assert.AreEqual (typeof (SolidBrush), p.Brush.GetType (), "Brush.Type");
191 Assert.AreEqual (Color.Red.ToArgb (), (p.Brush as SolidBrush).Color.ToArgb (), "Brush.Color");
192 Assert.AreEqual (Color.Red.ToArgb (), p.Color.ToArgb (), "Color");
193 Assert.AreEqual (0, p.CompoundArray.Length, "CompoundArray");
194 // Assert.AreEqual (DashCap.Flat, p.DashCap, "DashCap");
195 Assert.AreEqual (0, p.DashOffset, "DashOffset");
196 Assert.AreEqual (10, p.MiterLimit, "MiterLimit");
197 Assert.AreEqual (PenType.SolidColor, p.PenType, "PenType");
198 Assert.IsTrue (p.Transform.IsIdentity, "Transform");
202 public void Alignment ()
204 using (Pen p = new Pen (Brushes.Gold, Single.NegativeInfinity)) {
205 foreach (PenAlignment pa in Enum.GetValues (typeof (PenAlignment))) {
207 Assert.AreEqual (pa, p.Alignment, pa.ToString ());
213 public void Alignment_Invalid ()
215 Assert.Throws<SC.InvalidEnumArgumentException> (() => default_pen.Alignment = (PenAlignment) Int32.MinValue);
219 public void Brush_Dispose ()
221 using (Pen p = new Pen (Brushes.Red, 2.5f)) {
222 // are we getting the original brush ?
226 using (Pen clone = (Pen) p.Clone ()) {
229 Assert.IsFalse (Object.ReferenceEquals (b1, p.Brush), "Brush");
235 public void Brush_Null ()
237 Assert.Throws<ArgumentNullException> (() => default_pen.Brush = null);
241 [Category ("NotWorking")] // not supported by libgdiplus
242 public void CustomEndCap_Set ()
244 using (Pen p = new Pen (Brushes.DeepSkyBlue, -1)) {
245 p.CustomEndCap = custom_line_cap;
246 Assert.IsNotNull (p.CustomEndCap, "CustomEndCap");
247 Assert.IsFalse (Object.ReferenceEquals (custom_line_cap, p.CustomEndCap), "!same");
252 [Category ("NotWorking")] // not supported by libgdiplus
253 public void CustomEndCap_Default ()
255 Assert.Throws<ArgumentException> (() => { var x = default_pen.CustomEndCap; });
259 [Category ("NotWorking")] // not supported by libgdiplus
260 public void CustomStartCap_Set ()
262 using (Pen p = new Pen (Brushes.Ivory, 5)) {
263 p.CustomStartCap = custom_line_cap;
264 Assert.IsNotNull (p.CustomStartCap, "CustomStartCap");
265 Assert.IsFalse (Object.ReferenceEquals (custom_line_cap, p.CustomStartCap), "!same");
270 [Category ("NotWorking")] // not supported by libgdiplus
271 public void CustomStartCap_Default ()
273 Assert.Throws<ArgumentException> (() => { var x = default_pen.CustomStartCap; });
277 public void DashCap_Valid ()
279 // note: YellowGreen is broken by a destructive test so we can't use it afterward
280 // note: this worked with nunit 2.2 because this test was executed before the destructive one
281 using (Pen p = new Pen (Brushes.Yellow, 0)) {
282 foreach (DashCap dc in Enum.GetValues (typeof (DashCap))) {
284 Assert.AreEqual (dc, p.DashCap, dc.ToString ());
290 public void DashCap_Invalid ()
292 Assert.Throws<SC.InvalidEnumArgumentException> (() => default_pen.DashCap = (DashCap) Int32.MinValue);
296 public void DashOffset ()
298 using (Pen p = new Pen (Brushes.Transparent, 32)) {
300 Assert.AreEqual (0, p.DashOffset, "0");
301 p.DashOffset = Single.MaxValue;
302 Assert.AreEqual (Single.MaxValue, p.DashOffset, "MaxValue");
303 p.DashOffset = Single.MinValue;
304 Assert.AreEqual (Single.MinValue, p.DashOffset, "MinValue");
309 public void DashPattern ()
311 using (Pen p = new Pen (Brushes.Tomato, 1.1f)) {
312 Assert.AreEqual (DashStyle.Solid, p.DashStyle, "Solid");
313 p.DashPattern = new float[1] { 1 };
314 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Custom");
315 Assert.AreEqual (1, p.DashPattern.Length, "DashPattern");
320 public void DashPattern_Empty ()
322 Assert.Throws<ArgumentException> (() => default_pen.DashPattern = new float[0]);
326 public void DashStyle_Valid ()
328 using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
329 foreach (DashStyle ds in Enum.GetValues (typeof (DashStyle))) {
331 Assert.AreEqual (ds, p.DashStyle, ds.ToString ());
337 public void DashStyle_Invalid ()
339 Assert.Throws<SC.InvalidEnumArgumentException> (() => default_pen.DashStyle = (DashStyle) Int32.MinValue);
343 public void DashStyle_Custom ()
345 using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
346 Assert.AreEqual (DashStyle.Solid, p.DashStyle, "Solid");
347 // can't ask for Solid (default) -> OutOfMemoryException
348 p.DashStyle = DashStyle.Custom;
349 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Solid->Custom");
350 Assert.AreEqual (1, p.DashPattern.Length, "Solid->Custom.Length");
351 Assert.AreEqual (1, p.DashPattern[0], "Solid->Custom[0]");
353 p.DashStyle = DashStyle.Dot;
354 Assert.AreEqual (DashStyle.Dot, p.DashStyle, "Dot");
355 Assert.AreEqual (2, p.DashPattern.Length, "Dot.Length");
356 Assert.AreEqual (1, p.DashPattern[0], "Dot[0]");
357 Assert.AreEqual (1, p.DashPattern[1], "Dot[1]");
358 p.DashStyle = DashStyle.Custom;
359 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Dot->Custom");
360 Assert.AreEqual (2, p.DashPattern.Length, "Dot->Custom.Length");
361 Assert.AreEqual (1, p.DashPattern[0], "Dot->Custom[0]");
362 Assert.AreEqual (1, p.DashPattern[1], "Dot->Custom[1]");
364 p.DashStyle = DashStyle.Dash;
365 Assert.AreEqual (DashStyle.Dash, p.DashStyle, "Dash");
366 Assert.AreEqual (2, p.DashPattern.Length, "Dash.Length");
367 Assert.AreEqual (3, p.DashPattern[0], "Dash[0]");
368 Assert.AreEqual (1, p.DashPattern[1], "Dash[1]");
369 p.DashStyle = DashStyle.Custom;
370 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Dash->Custom");
371 Assert.AreEqual (2, p.DashPattern.Length, "Dash->Custom.Length");
372 Assert.AreEqual (3, p.DashPattern[0], "Dash->Custom[0]");
373 Assert.AreEqual (1, p.DashPattern[1], "Dash->Custom[1]");
375 p.DashStyle = DashStyle.DashDot;
376 Assert.AreEqual (DashStyle.DashDot, p.DashStyle, "DashDot");
377 Assert.AreEqual (4, p.DashPattern.Length, "DashDot.Length");
378 Assert.AreEqual (3, p.DashPattern[0], "DashDot[0]");
379 Assert.AreEqual (1, p.DashPattern[1], "DashDot[1]");
380 Assert.AreEqual (1, p.DashPattern[2], "DashDot[2]");
381 Assert.AreEqual (1, p.DashPattern[3], "DashDot[3]");
382 p.DashStyle = DashStyle.Custom;
383 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "DashDot->Custom");
384 Assert.AreEqual (4, p.DashPattern.Length, "DashDot->Custom.Length");
385 Assert.AreEqual (3, p.DashPattern[0], "DashDot->Custom[0]");
386 Assert.AreEqual (1, p.DashPattern[1], "DashDot->Custom[1]");
387 Assert.AreEqual (1, p.DashPattern[2], "DashDot->Custom[2]");
388 Assert.AreEqual (1, p.DashPattern[3], "DashDot->Custom[3]");
390 p.DashStyle = DashStyle.DashDotDot;
391 Assert.AreEqual (DashStyle.DashDotDot, p.DashStyle, "DashDotDot");
392 Assert.AreEqual (6, p.DashPattern.Length, "DashDotDot.Length");
393 Assert.AreEqual (3, p.DashPattern[0], "DashDotDot[0]");
394 Assert.AreEqual (1, p.DashPattern[1], "DashDotDot[1]");
395 Assert.AreEqual (1, p.DashPattern[2], "DashDotDot[2]");
396 Assert.AreEqual (1, p.DashPattern[3], "DashDotDot[3]");
397 Assert.AreEqual (1, p.DashPattern[2], "DashDotDot[2]");
398 Assert.AreEqual (1, p.DashPattern[3], "DashDotDot[3]");
399 p.DashStyle = DashStyle.Custom;
400 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "DashDotDot->Custom");
401 Assert.AreEqual (6, p.DashPattern.Length, "DashDotDot->Custom.Length");
402 Assert.AreEqual (3, p.DashPattern[0], "DashDotDot->Custom[0]");
403 Assert.AreEqual (1, p.DashPattern[1], "DashDotDot->Custom[1]");
404 Assert.AreEqual (1, p.DashPattern[2], "DashDotDot->Custom[2]");
405 Assert.AreEqual (1, p.DashPattern[3], "DashDotDot->Custom[3]");
406 Assert.AreEqual (1, p.DashPattern[2], "DashDotDot->Custom[2]");
407 Assert.AreEqual (1, p.DashPattern[3], "DashDotDot->Custom[3]");
409 // resetting to DashStyle.Solid doesn't throw the OutOfMemoryException
411 p.DashStyle = DashStyle.Solid;
412 Assert.AreEqual (DashStyle.Solid, p.DashStyle, "Solid-2");
413 Assert.AreEqual (0, p.DashPattern.Length, "Solid2.Length");
414 p.DashStyle = DashStyle.Custom;
415 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Solid2->Custom");
416 Assert.AreEqual (1, p.DashPattern.Length, "Solid2->Custom.Length");
417 Assert.AreEqual (1, p.DashPattern[0], "Solid2->Custom[0]");
422 [Category ("NotWorking")] // MS bug reported as FDBK50053
423 public void DashPattern_Default ()
425 Assert.Throws<OutOfMemoryException> (() => { var x = default_pen.DashPattern; });
429 public void EndCap_Valid ()
431 using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
432 foreach (LineCap lc in Enum.GetValues (typeof (LineCap))) {
434 Assert.AreEqual (lc, p.EndCap, lc.ToString ());
440 public void EndCap_Invalid ()
442 Assert.Throws<SC.InvalidEnumArgumentException> (() => default_pen.EndCap = (LineCap) Int32.MinValue);
446 public void LineJoin_Valid ()
448 using (Pen p = new Pen (Brushes.Chocolate, Single.NaN)) {
449 foreach (LineJoin lj in Enum.GetValues (typeof (LineJoin))) {
451 Assert.AreEqual (lj, p.LineJoin, lj.ToString ());
457 public void LineJoin_Invalid ()
459 Assert.Throws<SC.InvalidEnumArgumentException> (() => default_pen.LineJoin = (LineJoin) Int32.MinValue);
463 public void MiterLimit ()
465 using (Pen p = new Pen (Brushes.Tan, 1)) {
466 p.MiterLimit = Single.MinValue;
467 Assert.AreEqual (1, p.MiterLimit, "MinValue/1");
469 Assert.AreEqual (1, p.MiterLimit, "0/1");
470 p.MiterLimit = Single.MaxValue;
471 Assert.AreEqual (Single.MaxValue, p.MiterLimit, "MaxValue");
476 public void StartCap_Valid ()
478 using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
479 foreach (LineCap lc in Enum.GetValues (typeof (LineCap))) {
481 Assert.AreEqual (lc, p.StartCap, lc.ToString ());
487 public void StartCap_Invalid ()
489 Assert.Throws<SC.InvalidEnumArgumentException> (() => default_pen.StartCap = (LineCap) Int32.MinValue);
493 public void Transform_Null ()
495 Assert.Throws<ArgumentNullException> (() => default_pen.Transform = null);
499 public void Transform_NonInvertible ()
501 using (Pen p = new Pen (Brushes.Snow, Single.MaxValue)) {
502 Assert.Throws<ArgumentException> (() => p.Transform = new Matrix (123, 24, 82, 16, 47, 30));
509 using (Pen p = new Pen (Brushes.Tan, Single.MinValue)) {
510 Assert.AreEqual (Single.MinValue, p.Width, "MinValue");
512 Assert.AreEqual (0, p.Width, "0");
513 p.Width = Single.MaxValue;
514 Assert.AreEqual (Single.MaxValue, p.Width, "MaxValue");
521 using (Pen p = new Pen (Brushes.Red)) {
522 using (Pen clone = (Pen) p.Clone ()) {
529 public void Dispose ()
531 Pen p = new Pen (Brushes.Red);
533 Assert.Throws<ArgumentException> (() => p.Alignment = PenAlignment.Center);
534 // exception but not an ObjectDisposedException
538 public void SetLineCap ()
540 using (Pen p = new Pen (Brushes.Red)) {
541 foreach (LineCap sc in Enum.GetValues (typeof (LineCap))) {
542 foreach (LineCap ec in Enum.GetValues (typeof (LineCap))) {
543 foreach (DashCap dc in Enum.GetValues (typeof (DashCap))) {
544 string s = String.Format ("{0}-{1}-{2}", sc, ec, dc);
545 p.SetLineCap (sc, ec, dc);
546 Assert.AreEqual (sc, p.StartCap, s + ".StartCap");
547 Assert.AreEqual (ec, p.EndCap, s + ".EndCap");
548 Assert.AreEqual (dc, p.DashCap, s + ".DashCap");
556 public void SetLineCap_InvalidStartCap ()
558 using (Pen p = new Pen (Brushes.Red)) {
559 p.SetLineCap ((LineCap)Int32.MinValue, LineCap.Flat, DashCap.Flat);
560 // no exception :( (reported as FDBK50057)
561 Assert.AreEqual (Int32.MinValue, (int) p.StartCap, "StartCap");
562 Assert.AreEqual (LineCap.Flat, p.EndCap, "EndCap");
563 Assert.AreEqual (DashCap.Flat, p.DashCap, "DashCap");
568 public void SetLineCap_InvalidEndCap ()
570 using (Pen p = new Pen (Brushes.Red)) {
571 p.SetLineCap (LineCap.Flat, (LineCap)Int32.MinValue, DashCap.Flat);
572 // no exception :( (reported as FDBK50057)
573 Assert.AreEqual (LineCap.Flat, p.StartCap, "StartCap");
574 Assert.AreEqual (Int32.MinValue, (int)p.EndCap, "EndCap");
575 Assert.AreEqual (DashCap.Flat, p.DashCap, "DashCap");
580 public void SetLineCap_InvalidDashCap ()
582 using (Pen p = new Pen (Brushes.Red)) {
583 p.SetLineCap (LineCap.Flat, LineCap.Flat, (DashCap)Int32.MinValue);
584 Assert.AreEqual (LineCap.Flat, p.StartCap, "StartCap");
585 Assert.AreEqual (LineCap.Flat, p.EndCap, "EndCap");
586 // invalid value was reseted to Flat (reported as FDBK50057)
587 Assert.AreEqual (DashCap.Flat, p.DashCap, "DashCap");
592 //[ExpectedException (typeof (ArgumentNullException))] // reported as FDBK50058
593 public void MultiplyTransform1_Null ()
595 Assert.Throws<NullReferenceException> (() => default_pen.MultiplyTransform (null));
599 //[ExpectedException (typeof (ArgumentNullException))] // reported as FDBK50058
600 public void MultiplyTransform2_Null ()
602 Assert.Throws<NullReferenceException> (() => default_pen.MultiplyTransform (null, MatrixOrder.Append));
606 public void MultiplyTransform2_InvalidMatrixOrder ()
608 using (Pen p = new Pen (Brushes.Red)) {
609 Matrix m1 = new Matrix (2, 0.5f, 0.5f, 4, 10, 20);
610 Matrix m2 = new Matrix (1, 0, 0, 1, -50, -30);
613 p.MultiplyTransform (m1, (MatrixOrder) Int32.MinValue);
614 // no exception, but which order is it ?
615 Matrix invalid = p.Transform;
618 p.MultiplyTransform (m1, MatrixOrder.Append);
619 Assert.IsTrue (invalid.Equals (p.Transform), "Append");
622 p.MultiplyTransform (m1, MatrixOrder.Prepend);
623 Assert.IsFalse (invalid.Equals (p.Transform), "Prepend");
628 public void MultiplyTransform_NonInvertible ()
630 using (Matrix noninvertible = new Matrix (123, 24, 82, 16, 47, 30)) {
631 using (Pen p = new Pen (Brushes.Red)) {
632 Assert.Throws<ArgumentException> (() => p.MultiplyTransform (noninvertible));
638 public void ResetTransform ()
640 using (Matrix m = new Matrix (2, 0, 0, 2, 10, -10)) {
641 using (Pen p = new Pen (Brushes.Red)) {
643 Assert.IsFalse (p.Transform.IsIdentity, "Transform.IsIdentity");
645 Assert.IsTrue (p.Transform.IsIdentity, "Reset.IsIdentity");
651 public void RotateTransform ()
653 using (Pen p = new Pen (Brushes.Red)) {
654 p.RotateTransform (90);
655 float[] elements = p.Transform.Elements;
656 Assert.AreEqual (0, elements[0], 0.1, "matrix.0");
657 Assert.AreEqual (1, elements[1], 0.1, "matrix.1");
658 Assert.AreEqual (-1, elements[2], 0.1, "matrix.2");
659 Assert.AreEqual (0, elements[3], 0.1, "matrix.3");
660 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
661 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
663 p.RotateTransform (270);
664 Assert.IsTrue (p.Transform.IsIdentity, "Transform.IsIdentity");
669 public void RotateTransform_InvalidOrder ()
671 Assert.Throws<ArgumentException> (() => default_pen.RotateTransform (720, (MatrixOrder) Int32.MinValue));
675 public void ScaleTransform ()
677 using (Pen p = new Pen (Brushes.Red)) {
678 p.ScaleTransform (2, 4);
679 float[] elements = p.Transform.Elements;
680 Assert.AreEqual (2, elements[0], 0.1, "matrix.0");
681 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
682 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
683 Assert.AreEqual (4, elements[3], 0.1, "matrix.3");
684 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
685 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
687 p.ScaleTransform (0.5f, 0.25f);
688 Assert.IsTrue (p.Transform.IsIdentity, "Transform.IsIdentity");
693 public void ScaleTransform_MaxMin ()
695 using (Pen p = new Pen (Brushes.Red)) {
696 p.ScaleTransform (Single.MaxValue, Single.MinValue);
697 float[] elements = p.Transform.Elements;
698 Assert.AreEqual (Single.MaxValue, elements[0], 1e33, "matrix.0");
699 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
700 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
701 Assert.AreEqual (Single.MinValue, elements[3], 1e33, "matrix.3");
702 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
703 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
708 public void ScaleTransform_InvalidOrder ()
710 Assert.Throws<ArgumentException> (() => default_pen.ScaleTransform (1, 1, (MatrixOrder) Int32.MinValue));
714 public void TranslateTransform ()
716 using (Pen p = new Pen (Brushes.Red)) {
717 p.TranslateTransform (1, 1);
718 float[] elements = p.Transform.Elements;
719 Assert.AreEqual (1, elements[0], 0.1, "matrix.0");
720 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
721 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
722 Assert.AreEqual (1, elements[3], 0.1, "matrix.3");
723 Assert.AreEqual (1, elements[4], 0.1, "matrix.4");
724 Assert.AreEqual (1, elements[5], 0.1, "matrix.5");
726 p.TranslateTransform (-1, -1);
727 elements = p.Transform.Elements;
728 Assert.AreEqual (1, elements[0], 0.1, "revert.matrix.0");
729 Assert.AreEqual (0, elements[1], 0.1, "revert.matrix.1");
730 Assert.AreEqual (0, elements[2], 0.1, "revert.matrix.2");
731 Assert.AreEqual (1, elements[3], 0.1, "revert.matrix.3");
732 Assert.AreEqual (0, elements[4], 0.1, "revert.matrix.4");
733 Assert.AreEqual (0, elements[5], 0.1, "revert.matrix.5");
738 public void TranslateTransform_InvalidOrder ()
740 Assert.Throws<ArgumentException> (() => default_pen.TranslateTransform (1, 1, (MatrixOrder) Int32.MinValue));
744 public void Transform_Operations ()
746 using (Pen p = new Pen (Brushes.Red)) {
747 Matrix clone = p.Transform.Clone ();
748 Matrix mul = clone.Clone ();
750 clone.Multiply (mul, MatrixOrder.Append);
751 p.MultiplyTransform (mul, MatrixOrder.Append);
752 Assert.AreEqual (p.Transform, clone, "Multiply/Append");
754 clone.Multiply (mul, MatrixOrder.Prepend);
755 p.MultiplyTransform (mul, MatrixOrder.Prepend);
756 Assert.AreEqual (p.Transform, clone, "Multiply/Prepend");
758 clone.Rotate (45, MatrixOrder.Append);
759 p.RotateTransform (45, MatrixOrder.Append);
760 Assert.AreEqual (p.Transform, clone, "Rotate/Append");
762 clone.Rotate (45, MatrixOrder.Prepend);
763 p.RotateTransform (45, MatrixOrder.Prepend);
764 Assert.AreEqual (p.Transform, clone, "Rotate/Prepend");
766 clone.Scale (0.25f, 2, MatrixOrder.Append);
767 p.ScaleTransform (0.25f, 2, MatrixOrder.Append);
768 Assert.AreEqual (p.Transform, clone, "Scale/Append");
770 clone.Scale (0.25f, 2, MatrixOrder.Prepend);
771 p.ScaleTransform (0.25f, 2, MatrixOrder.Prepend);
772 Assert.AreEqual (p.Transform, clone, "Scale/Prepend");
774 clone.Translate (10, 20, MatrixOrder.Append);
775 p.TranslateTransform (10, 20, MatrixOrder.Append);
776 Assert.AreEqual (p.Transform, clone, "Translate/Append");
778 clone.Translate (30, 40, MatrixOrder.Prepend);
779 p.TranslateTransform (30, 40, MatrixOrder.Prepend);
780 Assert.AreEqual (p.Transform, clone, "Translate/Prepend");
784 Assert.AreEqual (p.Transform, clone, "Reset");