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");
239 [ExpectedException (typeof (ArgumentNullException))]
241 [ExpectedException (typeof (NullReferenceException))]
243 public void Brush_Null ()
245 default_pen.Brush = null;
249 [Category ("NotWorking")] // not supported by libgdiplus
250 public void CustomEndCap_Set ()
252 using (Pen p = new Pen (Brushes.DeepSkyBlue, -1)) {
253 p.CustomEndCap = custom_line_cap;
254 Assert.IsNotNull (p.CustomEndCap, "CustomEndCap");
255 Assert.IsFalse (Object.ReferenceEquals (custom_line_cap, p.CustomEndCap), "!same");
260 [ExpectedException (typeof (ArgumentException))]
261 [Category ("NotWorking")] // not supported by libgdiplus
262 public void CustomEndCap_Default ()
264 CustomLineCap clc = default_pen.CustomEndCap;
268 [Category ("NotWorking")] // not supported by libgdiplus
269 public void CustomStartCap_Set ()
271 using (Pen p = new Pen (Brushes.Ivory, 5)) {
272 p.CustomStartCap = custom_line_cap;
273 Assert.IsNotNull (p.CustomStartCap, "CustomStartCap");
274 Assert.IsFalse (Object.ReferenceEquals (custom_line_cap, p.CustomStartCap), "!same");
279 [ExpectedException (typeof (ArgumentException))]
280 [Category ("NotWorking")] // not supported by libgdiplus
281 public void CustomStartCap_Default ()
283 CustomLineCap clc = default_pen.CustomStartCap;
287 public void DashCap_Valid ()
289 using (Pen p = new Pen (Brushes.YellowGreen, 0)) {
290 foreach (DashCap dc in Enum.GetValues (typeof (DashCap))) {
292 Assert.AreEqual (dc, p.DashCap, dc.ToString ());
298 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
299 public void DashCap_Invalid ()
301 default_pen.DashCap = (DashCap) Int32.MinValue;
305 public void DashOffset ()
307 using (Pen p = new Pen (Brushes.Transparent, 32)) {
309 Assert.AreEqual (0, p.DashOffset, "0");
310 p.DashOffset = Single.MaxValue;
311 Assert.AreEqual (Single.MaxValue, p.DashOffset, "MaxValue");
312 p.DashOffset = Single.MinValue;
313 Assert.AreEqual (Single.MinValue, p.DashOffset, "MinValue");
318 public void DashPattern ()
320 using (Pen p = new Pen (Brushes.Tomato, 1.1f)) {
321 Assert.AreEqual (DashStyle.Solid, p.DashStyle, "Solid");
322 p.DashPattern = new float[1] { 1 };
323 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Custom");
324 Assert.AreEqual (1, p.DashPattern.Length, "DashPattern");
329 [ExpectedException (typeof (ArgumentException))]
330 public void DashPattern_Empty ()
332 default_pen.DashPattern = new float[0];
336 public void DashStyle_Valid ()
338 using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
339 foreach (DashStyle ds in Enum.GetValues (typeof (DashStyle))) {
341 Assert.AreEqual (ds, p.DashStyle, ds.ToString ());
347 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
348 public void DashStyle_Invalid ()
350 default_pen.DashStyle = (DashStyle) Int32.MinValue;
354 public void DashStyle_Custom ()
356 using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
357 Assert.AreEqual (DashStyle.Solid, p.DashStyle, "Solid");
358 // can't ask for Solid (default) -> OutOfMemoryException
359 p.DashStyle = DashStyle.Custom;
360 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Solid->Custom");
361 Assert.AreEqual (1, p.DashPattern.Length, "Solid->Custom.Length");
362 Assert.AreEqual (1, p.DashPattern[0], "Solid->Custom[0]");
364 p.DashStyle = DashStyle.Dot;
365 Assert.AreEqual (DashStyle.Dot, p.DashStyle, "Dot");
366 Assert.AreEqual (2, p.DashPattern.Length, "Dot.Length");
367 Assert.AreEqual (1, p.DashPattern[0], "Dot[0]");
368 Assert.AreEqual (1, p.DashPattern[1], "Dot[1]");
369 p.DashStyle = DashStyle.Custom;
370 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Dot->Custom");
371 Assert.AreEqual (2, p.DashPattern.Length, "Dot->Custom.Length");
372 Assert.AreEqual (1, p.DashPattern[0], "Dot->Custom[0]");
373 Assert.AreEqual (1, p.DashPattern[1], "Dot->Custom[1]");
375 p.DashStyle = DashStyle.Dash;
376 Assert.AreEqual (DashStyle.Dash, p.DashStyle, "Dash");
377 Assert.AreEqual (2, p.DashPattern.Length, "Dash.Length");
378 Assert.AreEqual (3, p.DashPattern[0], "Dash[0]");
379 Assert.AreEqual (1, p.DashPattern[1], "Dash[1]");
380 p.DashStyle = DashStyle.Custom;
381 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Dash->Custom");
382 Assert.AreEqual (2, p.DashPattern.Length, "Dash->Custom.Length");
383 Assert.AreEqual (3, p.DashPattern[0], "Dash->Custom[0]");
384 Assert.AreEqual (1, p.DashPattern[1], "Dash->Custom[1]");
386 p.DashStyle = DashStyle.DashDot;
387 Assert.AreEqual (DashStyle.DashDot, p.DashStyle, "DashDot");
388 Assert.AreEqual (4, p.DashPattern.Length, "DashDot.Length");
389 Assert.AreEqual (3, p.DashPattern[0], "DashDot[0]");
390 Assert.AreEqual (1, p.DashPattern[1], "DashDot[1]");
391 Assert.AreEqual (1, p.DashPattern[2], "DashDot[2]");
392 Assert.AreEqual (1, p.DashPattern[3], "DashDot[3]");
393 p.DashStyle = DashStyle.Custom;
394 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "DashDot->Custom");
395 Assert.AreEqual (4, p.DashPattern.Length, "DashDot->Custom.Length");
396 Assert.AreEqual (3, p.DashPattern[0], "DashDot->Custom[0]");
397 Assert.AreEqual (1, p.DashPattern[1], "DashDot->Custom[1]");
398 Assert.AreEqual (1, p.DashPattern[2], "DashDot->Custom[2]");
399 Assert.AreEqual (1, p.DashPattern[3], "DashDot->Custom[3]");
401 p.DashStyle = DashStyle.DashDotDot;
402 Assert.AreEqual (DashStyle.DashDotDot, p.DashStyle, "DashDotDot");
403 Assert.AreEqual (6, p.DashPattern.Length, "DashDotDot.Length");
404 Assert.AreEqual (3, p.DashPattern[0], "DashDotDot[0]");
405 Assert.AreEqual (1, p.DashPattern[1], "DashDotDot[1]");
406 Assert.AreEqual (1, p.DashPattern[2], "DashDotDot[2]");
407 Assert.AreEqual (1, p.DashPattern[3], "DashDotDot[3]");
408 Assert.AreEqual (1, p.DashPattern[2], "DashDotDot[2]");
409 Assert.AreEqual (1, p.DashPattern[3], "DashDotDot[3]");
410 p.DashStyle = DashStyle.Custom;
411 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "DashDotDot->Custom");
412 Assert.AreEqual (6, p.DashPattern.Length, "DashDotDot->Custom.Length");
413 Assert.AreEqual (3, p.DashPattern[0], "DashDotDot->Custom[0]");
414 Assert.AreEqual (1, p.DashPattern[1], "DashDotDot->Custom[1]");
415 Assert.AreEqual (1, p.DashPattern[2], "DashDotDot->Custom[2]");
416 Assert.AreEqual (1, p.DashPattern[3], "DashDotDot->Custom[3]");
417 Assert.AreEqual (1, p.DashPattern[2], "DashDotDot->Custom[2]");
418 Assert.AreEqual (1, p.DashPattern[3], "DashDotDot->Custom[3]");
420 // resetting to DashStyle.Solid doesn't throw the OutOfMemoryException
422 p.DashStyle = DashStyle.Solid;
423 Assert.AreEqual (DashStyle.Solid, p.DashStyle, "Solid-2");
424 Assert.AreEqual (0, p.DashPattern.Length, "Solid2.Length");
425 p.DashStyle = DashStyle.Custom;
426 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Solid2->Custom");
427 Assert.AreEqual (1, p.DashPattern.Length, "Solid2->Custom.Length");
428 Assert.AreEqual (1, p.DashPattern[0], "Solid2->Custom[0]");
433 [ExpectedException (typeof (OutOfMemoryException))]
434 [Category ("NotWorking")] // MS bug reported as FDBK50053
435 public void DashPattern_Default ()
437 float[] pattern = default_pen.DashPattern;
441 public void EndCap_Valid ()
443 using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
444 foreach (LineCap lc in Enum.GetValues (typeof (LineCap))) {
446 Assert.AreEqual (lc, p.EndCap, lc.ToString ());
452 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
453 public void EndCap_Invalid ()
455 default_pen.EndCap = (LineCap) Int32.MinValue;
459 public void LineJoin_Valid ()
461 using (Pen p = new Pen (Brushes.Chocolate, Single.NaN)) {
462 foreach (LineJoin lj in Enum.GetValues (typeof (LineJoin))) {
464 Assert.AreEqual (lj, p.LineJoin, lj.ToString ());
470 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
471 public void LineJoin_Invalid ()
473 default_pen.LineJoin = (LineJoin) Int32.MinValue;
477 public void MiterLimit ()
479 using (Pen p = new Pen (Brushes.Tan, 1)) {
480 p.MiterLimit = Single.MinValue;
481 Assert.AreEqual (1, p.MiterLimit, "MinValue/1");
483 Assert.AreEqual (1, p.MiterLimit, "0/1");
484 p.MiterLimit = Single.MaxValue;
485 Assert.AreEqual (Single.MaxValue, p.MiterLimit, "MaxValue");
490 public void StartCap_Valid ()
492 using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
493 foreach (LineCap lc in Enum.GetValues (typeof (LineCap))) {
495 Assert.AreEqual (lc, p.StartCap, lc.ToString ());
501 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
502 public void StartCap_Invalid ()
504 default_pen.StartCap = (LineCap) Int32.MinValue;
508 [ExpectedException (typeof (ArgumentNullException))]
509 public void Transform_Null ()
511 default_pen.Transform = null;
515 [ExpectedException (typeof (ArgumentException))]
516 public void Transform_NonInvertible ()
518 using (Pen p = new Pen (Brushes.Snow, Single.MaxValue)) {
519 p.Transform = new Matrix (123, 24, 82, 16, 47, 30);
526 using (Pen p = new Pen (Brushes.Tan, Single.MinValue)) {
527 Assert.AreEqual (Single.MinValue, p.Width, "MinValue");
529 Assert.AreEqual (0, p.Width, "0");
530 p.Width = Single.MaxValue;
531 Assert.AreEqual (Single.MaxValue, p.Width, "MaxValue");
538 using (Pen p = new Pen (Brushes.Red)) {
539 using (Pen clone = (Pen) p.Clone ()) {
546 [ExpectedException (typeof (ArgumentException))]
547 public void Dispose ()
549 Pen p = new Pen (Brushes.Red);
551 p.Alignment = PenAlignment.Center;
552 // exception but not an ObjectDisposedException
556 public void SetLineCap ()
558 using (Pen p = new Pen (Brushes.Red)) {
559 foreach (LineCap sc in Enum.GetValues (typeof (LineCap))) {
560 foreach (LineCap ec in Enum.GetValues (typeof (LineCap))) {
561 foreach (DashCap dc in Enum.GetValues (typeof (DashCap))) {
562 string s = String.Format ("{0}-{1}-{2}", sc, ec, dc);
563 p.SetLineCap (sc, ec, dc);
564 Assert.AreEqual (sc, p.StartCap, s + ".StartCap");
565 Assert.AreEqual (ec, p.EndCap, s + ".EndCap");
566 Assert.AreEqual (dc, p.DashCap, s + ".DashCap");
574 public void SetLineCap_InvalidStartCap ()
576 using (Pen p = new Pen (Brushes.Red)) {
577 p.SetLineCap ((LineCap)Int32.MinValue, LineCap.Flat, DashCap.Flat);
578 // no exception :( (reported as FDBK50057)
579 Assert.AreEqual (Int32.MinValue, (int) p.StartCap, "StartCap");
580 Assert.AreEqual (LineCap.Flat, p.EndCap, "EndCap");
581 Assert.AreEqual (DashCap.Flat, p.DashCap, "DashCap");
586 public void SetLineCap_InvalidEndCap ()
588 using (Pen p = new Pen (Brushes.Red)) {
589 p.SetLineCap (LineCap.Flat, (LineCap)Int32.MinValue, DashCap.Flat);
590 // no exception :( (reported as FDBK50057)
591 Assert.AreEqual (LineCap.Flat, p.StartCap, "StartCap");
592 Assert.AreEqual (Int32.MinValue, (int)p.EndCap, "EndCap");
593 Assert.AreEqual (DashCap.Flat, p.DashCap, "DashCap");
598 public void SetLineCap_InvalidDashCap ()
600 using (Pen p = new Pen (Brushes.Red)) {
601 p.SetLineCap (LineCap.Flat, LineCap.Flat, (DashCap)Int32.MinValue);
602 Assert.AreEqual (LineCap.Flat, p.StartCap, "StartCap");
603 Assert.AreEqual (LineCap.Flat, p.EndCap, "EndCap");
604 // invalid value was reseted to Flat (reported as FDBK50057)
605 Assert.AreEqual (DashCap.Flat, p.DashCap, "DashCap");
610 //[ExpectedException (typeof (ArgumentNullException))] // reported as FDBK50058
611 [ExpectedException (typeof (NullReferenceException))]
612 public void MultiplyTransform1_Null ()
614 default_pen.MultiplyTransform (null);
618 //[ExpectedException (typeof (ArgumentNullException))] // reported as FDBK50058
619 [ExpectedException (typeof (NullReferenceException))]
620 public void MultiplyTransform2_Null ()
622 default_pen.MultiplyTransform (null, MatrixOrder.Append);
626 public void MultiplyTransform2_InvalidMatrixOrder ()
628 using (Pen p = new Pen (Brushes.Red)) {
629 Matrix m1 = new Matrix (2, 0.5f, 0.5f, 4, 10, 20);
630 Matrix m2 = new Matrix (1, 0, 0, 1, -50, -30);
633 p.MultiplyTransform (m1, (MatrixOrder) Int32.MinValue);
634 // no exception, but which order is it ?
635 Matrix invalid = p.Transform;
638 p.MultiplyTransform (m1, MatrixOrder.Append);
639 Assert.IsTrue (invalid.Equals (p.Transform), "Append");
642 p.MultiplyTransform (m1, MatrixOrder.Prepend);
643 Assert.IsFalse (invalid.Equals (p.Transform), "Prepend");
648 [ExpectedException (typeof (ArgumentException))]
649 public void MultiplyTransform_NonInvertible ()
651 using (Matrix noninvertible = new Matrix (123, 24, 82, 16, 47, 30)) {
652 using (Pen p = new Pen (Brushes.Red)) {
653 p.MultiplyTransform (noninvertible);
659 public void ResetTransform ()
661 using (Matrix m = new Matrix (2, 0, 0, 2, 10, -10)) {
662 using (Pen p = new Pen (Brushes.Red)) {
664 Assert.IsFalse (p.Transform.IsIdentity, "Transform.IsIdentity");
666 Assert.IsTrue (p.Transform.IsIdentity, "Reset.IsIdentity");
672 public void RotateTransform ()
674 using (Pen p = new Pen (Brushes.Red)) {
675 p.RotateTransform (90);
676 float[] elements = p.Transform.Elements;
677 Assert.AreEqual (0, elements[0], 0.1, "matrix.0");
678 Assert.AreEqual (1, elements[1], 0.1, "matrix.1");
679 Assert.AreEqual (-1, elements[2], 0.1, "matrix.2");
680 Assert.AreEqual (0, elements[3], 0.1, "matrix.3");
681 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
682 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
684 p.RotateTransform (270);
685 Assert.IsTrue (p.Transform.IsIdentity, "Transform.IsIdentity");
690 [ExpectedException (typeof (ArgumentException))]
691 public void RotateTransform_InvalidOrder ()
693 default_pen.RotateTransform (720, (MatrixOrder) Int32.MinValue);
697 public void ScaleTransform ()
699 using (Pen p = new Pen (Brushes.Red)) {
700 p.ScaleTransform (2, 4);
701 float[] elements = p.Transform.Elements;
702 Assert.AreEqual (2, elements[0], 0.1, "matrix.0");
703 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
704 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
705 Assert.AreEqual (4, elements[3], 0.1, "matrix.3");
706 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
707 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
709 p.ScaleTransform (0.5f, 0.25f);
710 Assert.IsTrue (p.Transform.IsIdentity, "Transform.IsIdentity");
715 public void ScaleTransform_MaxMin ()
717 using (Pen p = new Pen (Brushes.Red)) {
718 p.ScaleTransform (Single.MaxValue, Single.MinValue);
719 float[] elements = p.Transform.Elements;
720 Assert.AreEqual (Single.MaxValue, elements[0], 1e33, "matrix.0");
721 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
722 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
723 Assert.AreEqual (Single.MinValue, elements[3], 1e33, "matrix.3");
724 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
725 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
730 [ExpectedException (typeof (ArgumentException))]
731 public void ScaleTransform_InvalidOrder ()
733 default_pen.ScaleTransform (1, 1, (MatrixOrder) Int32.MinValue);
737 public void TranslateTransform ()
739 using (Pen p = new Pen (Brushes.Red)) {
740 p.TranslateTransform (1, 1);
741 float[] elements = p.Transform.Elements;
742 Assert.AreEqual (1, elements[0], 0.1, "matrix.0");
743 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
744 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
745 Assert.AreEqual (1, elements[3], 0.1, "matrix.3");
746 Assert.AreEqual (1, elements[4], 0.1, "matrix.4");
747 Assert.AreEqual (1, elements[5], 0.1, "matrix.5");
749 p.TranslateTransform (-1, -1);
750 elements = p.Transform.Elements;
751 Assert.AreEqual (1, elements[0], 0.1, "revert.matrix.0");
752 Assert.AreEqual (0, elements[1], 0.1, "revert.matrix.1");
753 Assert.AreEqual (0, elements[2], 0.1, "revert.matrix.2");
754 Assert.AreEqual (1, elements[3], 0.1, "revert.matrix.3");
755 Assert.AreEqual (0, elements[4], 0.1, "revert.matrix.4");
756 Assert.AreEqual (0, elements[5], 0.1, "revert.matrix.5");
761 [ExpectedException (typeof (ArgumentException))]
762 public void TranslateTransform_InvalidOrder ()
764 default_pen.TranslateTransform (1, 1, (MatrixOrder) Int32.MinValue);
768 public void Transform_Operations ()
770 using (Pen p = new Pen (Brushes.Red)) {
771 Matrix clone = p.Transform.Clone ();
772 Matrix mul = clone.Clone ();
774 clone.Multiply (mul, MatrixOrder.Append);
775 p.MultiplyTransform (mul, MatrixOrder.Append);
776 Assert.AreEqual (p.Transform, clone, "Multiply/Append");
778 clone.Multiply (mul, MatrixOrder.Prepend);
779 p.MultiplyTransform (mul, MatrixOrder.Prepend);
780 Assert.AreEqual (p.Transform, clone, "Multiply/Prepend");
782 clone.Rotate (45, MatrixOrder.Append);
783 p.RotateTransform (45, MatrixOrder.Append);
784 Assert.AreEqual (p.Transform, clone, "Rotate/Append");
786 clone.Rotate (45, MatrixOrder.Prepend);
787 p.RotateTransform (45, MatrixOrder.Prepend);
788 Assert.AreEqual (p.Transform, clone, "Rotate/Prepend");
790 clone.Scale (0.25f, 2, MatrixOrder.Append);
791 p.ScaleTransform (0.25f, 2, MatrixOrder.Append);
792 Assert.AreEqual (p.Transform, clone, "Scale/Append");
794 clone.Scale (0.25f, 2, MatrixOrder.Prepend);
795 p.ScaleTransform (0.25f, 2, MatrixOrder.Prepend);
796 Assert.AreEqual (p.Transform, clone, "Scale/Prepend");
798 clone.Translate (10, 20, MatrixOrder.Append);
799 p.TranslateTransform (10, 20, MatrixOrder.Append);
800 Assert.AreEqual (p.Transform, clone, "Translate/Append");
802 clone.Translate (30, 40, MatrixOrder.Prepend);
803 p.TranslateTransform (30, 40, MatrixOrder.Prepend);
804 Assert.AreEqual (p.Transform, clone, "Translate/Prepend");
808 Assert.AreEqual (p.Transform, clone, "Reset");