New test.
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / PenTest.cs
1 //
2 // System.Drawing.Pen unit tests
3 //
4 // Authors:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28
29 using System;
30 using SC = System.ComponentModel;
31 using System.Drawing;
32 using System.Drawing.Drawing2D;
33 using System.Security.Permissions;
34 using NUnit.Framework;
35
36 namespace MonoTests.System.Drawing {
37
38         [TestFixture]
39         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
40         public class PenTest {
41
42                 private Pen default_pen;
43                 private CustomLineCap custom_line_cap;
44
45                 [TestFixtureSetUp]
46                 public void FixtureSetUp ()
47                 {
48                         default_pen = new Pen (Color.Empty);
49                         custom_line_cap = new CustomLineCap (new GraphicsPath (), new GraphicsPath ());
50                 }
51
52                 private void Check (Pen p)
53                 {
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");
68                 }
69
70                 [Test]
71                 public void Constructor_Color ()
72                 {
73                         using (Pen p = new Pen (Color.Red)) {
74                                 Assert.AreEqual (1, p.Width, "Width");
75                                 Check (p);
76                         }
77                 }
78
79                 [Test]
80                 public void Constructor_Color_Float ()
81                 {
82                         using (Pen p = new Pen (Color.Red, 2.5f)) {
83                                 Assert.AreEqual (2.5f, p.Width, "Width");
84                                 Check (p);
85                         }
86                 }
87
88                 [Test]
89                 public void Constructor_Color_Float_Zero ()
90                 {
91                         using (Pen p = new Pen (Color.Red, 0.0f)) {
92                                 Assert.AreEqual (0.0f, p.Width, "Width");
93                                 Check (p);
94                         }
95                 }
96
97                 [Test]
98                 public void Constructor_Color_Float_Negative ()
99                 {
100                         using (Pen p = new Pen (Color.Red, -2)) {
101                                 Assert.AreEqual (-2, p.Width, "Width");
102                                 Check (p);
103                         }
104                 }
105
106                 [Test]
107                 public void Constructor_Color_Float_MaxValue ()
108                 {
109                         using (Pen p = new Pen (Color.Red, Single.MaxValue)) {
110                                 Assert.AreEqual (Single.MaxValue, p.Width, "Width");
111                                 Check (p);
112                         }
113                 }
114
115                 [Test]
116                 public void Constructor_Brush ()
117                 {
118                         using (Pen p = new Pen (Brushes.Red)) {
119                                 Assert.AreEqual (1, p.Width, "Width");
120                                 Check (p);
121                         }
122                 }
123
124                 [Test]
125                 [ExpectedException (typeof (ArgumentNullException))]
126                 public void Constructor_Brush_Null ()
127                 {
128                         new Pen ((Brush) null);
129                 }
130
131                 [Test]
132                 public void Constructor_Brush_Float ()
133                 {
134                         using (Pen p = new Pen (Brushes.Red, 2.5f)) {
135                                 Assert.AreEqual (2.5f, p.Width, "Width");
136                                 Check (p);
137                         }
138                 }
139
140                 [Test]
141                 [ExpectedException (typeof (ArgumentNullException))]
142                 public void Constructor_Brush_Float_Null ()
143                 {
144                         new Pen ((Brush) null, Single.MaxValue);
145                 }
146
147                 [Test]
148                 public void Constructor_Brush_Float_Zero ()
149                 {
150                         using (Pen p = new Pen (Brushes.Red, 0.0f)) {
151                                 Assert.AreEqual (0.0f, p.Width, "Width");
152                                 Check (p);
153                         }
154                 }
155
156                 [Test]
157                 public void Constructor_Brush_Float_Negative ()
158                 {
159                         using (Pen p = new Pen (Brushes.Red, -2)) {
160                                 Assert.AreEqual (-2, p.Width, "Width");
161                                 Check (p);
162                         }
163                 }
164
165                 [Test]
166                 public void Constructor_Brush_Float_MaxValue ()
167                 {
168                         using (Pen p = new Pen (Brushes.Red, Single.MaxValue)) {
169                                 Assert.AreEqual (Single.MaxValue, p.Width, "Width");
170                                 Check (p);
171                         }
172                 }
173
174                 [Test]
175                 public void Constructor_Brush_DisposeBeforeUse ()
176                 {
177                         using (SolidBrush b = new SolidBrush (Color.Red)) {
178                                 using (Pen p = new Pen (b, 1)) {
179                                         b.Dispose ();
180                                         Check (p);
181                                         using (Bitmap bmp = new Bitmap (12, 12)) {
182                                                 using (Graphics g = Graphics.FromImage (bmp)) {
183                                                         g.DrawLine (p, 1, 1, 10, 10);
184                                                 }
185                                         }
186                                 }
187                         }
188                 }
189
190                 private void Check2 (Pen p)
191                 {
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");
201                 }
202
203                 [Test]
204                 public void Alignment ()
205                 {
206                         using (Pen p = new Pen (Brushes.Gold, Single.NegativeInfinity)) {
207                                 foreach (PenAlignment pa in Enum.GetValues (typeof (PenAlignment))) {
208                                         p.Alignment = pa;
209                                         Assert.AreEqual (pa, p.Alignment, pa.ToString ());
210                                 }
211                         }
212                 }
213
214                 [Test]
215                 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
216                 public void Alignment_Invalid ()
217                 {
218                         default_pen.Alignment = (PenAlignment) Int32.MinValue;
219                 }
220
221                 [Test]
222                 public void Brush_Dispose ()
223                 {
224                         using (Pen p = new Pen (Brushes.Red, 2.5f)) {
225                                 // are we getting the original brush ?
226                                 Brush b1 = p.Brush;
227                                 b1.Dispose ();
228                                 Check (p);
229                                 using (Pen clone = (Pen) p.Clone ()) {
230                                         Check (clone);
231                                 }
232                                 Assert.IsFalse (Object.ReferenceEquals (b1, p.Brush), "Brush");
233                                 // nope :)
234                         }
235                 }
236
237                 [Test]
238 #if NET_2_0
239                 [ExpectedException (typeof (ArgumentNullException))]
240 #else
241                 [ExpectedException (typeof (NullReferenceException))]
242 #endif
243                 public void Brush_Null ()
244                 {
245                         default_pen.Brush = null;
246                 }
247
248                 [Test]
249                 [Category ("NotWorking")] // not supported by libgdiplus
250                 public void CustomEndCap_Set ()
251                 {
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");
256                         }
257                 }
258
259                 [Test]
260                 [ExpectedException (typeof (ArgumentException))]
261                 [Category ("NotWorking")] // not supported by libgdiplus
262                 public void CustomEndCap_Default ()
263                 {
264                         CustomLineCap clc = default_pen.CustomEndCap;
265                 }
266
267                 [Test]
268                 [Category ("NotWorking")] // not supported by libgdiplus
269                 public void CustomStartCap_Set ()
270                 {
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");
275                         }
276                 }
277
278                 [Test]
279                 [ExpectedException (typeof (ArgumentException))]
280                 [Category ("NotWorking")] // not supported by libgdiplus
281                 public void CustomStartCap_Default ()
282                 {
283                         CustomLineCap clc = default_pen.CustomStartCap;
284                 }
285
286                 [Test]
287                 public void DashCap_Valid ()
288                 {
289                         using (Pen p = new Pen (Brushes.YellowGreen, 0)) {
290                                 foreach (DashCap dc in Enum.GetValues (typeof (DashCap))) {
291                                         p.DashCap = dc;
292                                         Assert.AreEqual (dc, p.DashCap, dc.ToString ());
293                                 }
294                         }
295                 }
296
297                 [Test]
298                 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
299                 public void DashCap_Invalid ()
300                 {
301                         default_pen.DashCap = (DashCap) Int32.MinValue;
302                 }
303
304                 [Test]
305                 public void DashOffset ()
306                 {
307                         using (Pen p = new Pen (Brushes.Transparent, 32)) {
308                                 p.DashOffset = 0;
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");
314                         }
315                 }
316
317                 [Test]
318                 public void DashPattern ()
319                 {
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");
325                         }
326                 }
327
328                 [Test]
329                 [ExpectedException (typeof (ArgumentException))]
330                 public void DashPattern_Empty ()
331                 {
332                         default_pen.DashPattern = new float[0];
333                 }
334
335                 [Test]
336                 public void DashStyle_Valid ()
337                 {
338                         using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
339                                 foreach (DashStyle ds in Enum.GetValues (typeof (DashStyle))) {
340                                         p.DashStyle = ds;
341                                         Assert.AreEqual (ds, p.DashStyle, ds.ToString ());
342                                 }
343                         }
344                 }
345
346                 [Test]
347                 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
348                 public void DashStyle_Invalid ()
349                 {
350                         default_pen.DashStyle = (DashStyle) Int32.MinValue;
351                 }
352
353                 [Test]
354                 public void DashStyle_Custom ()
355                 {
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]");
363
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]");
374
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]");
385
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]");
400
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]");
419
420                                 // resetting to DashStyle.Solid doesn't throw the OutOfMemoryException
421                                 // on MS runtime
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]");
429                         }
430                 }
431
432                 [Test]
433                 [ExpectedException (typeof (OutOfMemoryException))]
434                 [Category ("NotWorking")] // MS bug reported as FDBK50053
435                 public void DashPattern_Default ()
436                 {
437                         float[] pattern = default_pen.DashPattern;
438                 }
439
440                 [Test]
441                 public void EndCap_Valid ()
442                 {
443                         using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
444                                 foreach (LineCap lc in Enum.GetValues (typeof (LineCap))) {
445                                         p.EndCap = lc;
446                                         Assert.AreEqual (lc, p.EndCap, lc.ToString ());
447                                 }
448                         }
449                 }
450
451                 [Test]
452                 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
453                 public void EndCap_Invalid ()
454                 {
455                         default_pen.EndCap = (LineCap) Int32.MinValue;
456                 }
457
458                 [Test]
459                 public void LineJoin_Valid ()
460                 {
461                         using (Pen p = new Pen (Brushes.Chocolate, Single.NaN)) {
462                                 foreach (LineJoin lj in Enum.GetValues (typeof (LineJoin))) {
463                                         p.LineJoin = lj;
464                                         Assert.AreEqual (lj, p.LineJoin, lj.ToString ());
465                                 }
466                         }
467                 }
468
469                 [Test]
470                 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
471                 public void LineJoin_Invalid ()
472                 {
473                         default_pen.LineJoin = (LineJoin) Int32.MinValue;
474                 }
475
476                 [Test]
477                 public void MiterLimit ()
478                 {
479                         using (Pen p = new Pen (Brushes.Tan, 1)) {
480                                 p.MiterLimit = Single.MinValue;
481                                 Assert.AreEqual (1, p.MiterLimit, "MinValue/1");
482                                 p.MiterLimit = 0;
483                                 Assert.AreEqual (1, p.MiterLimit, "0/1");
484                                 p.MiterLimit = Single.MaxValue;
485                                 Assert.AreEqual (Single.MaxValue, p.MiterLimit, "MaxValue");
486                         }
487                 }
488
489                 [Test]
490                 public void StartCap_Valid ()
491                 {
492                         using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
493                                 foreach (LineCap lc in Enum.GetValues (typeof (LineCap))) {
494                                         p.StartCap = lc;
495                                         Assert.AreEqual (lc, p.StartCap, lc.ToString ());
496                                 }
497                         }
498                 }
499
500                 [Test]
501                 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
502                 public void StartCap_Invalid ()
503                 {
504                         default_pen.StartCap = (LineCap) Int32.MinValue;
505                 }
506
507                 [Test]
508                 [ExpectedException (typeof (ArgumentNullException))]
509                 public void Transform_Null ()
510                 {
511                         default_pen.Transform = null;
512                 }
513
514                 [Test]
515                 [ExpectedException (typeof (ArgumentException))]
516                 public void Transform_NonInvertible ()
517                 {
518                         using (Pen p = new Pen (Brushes.Snow, Single.MaxValue)) {
519                                 p.Transform = new Matrix (123, 24, 82, 16, 47, 30);
520                         }
521                 }
522
523                 [Test]
524                 public void Width ()
525                 {
526                         using (Pen p = new Pen (Brushes.Tan, Single.MinValue)) {
527                                 Assert.AreEqual (Single.MinValue, p.Width, "MinValue");
528                                 p.Width = 0;
529                                 Assert.AreEqual (0, p.Width, "0");
530                                 p.Width = Single.MaxValue;
531                                 Assert.AreEqual (Single.MaxValue, p.Width, "MaxValue");
532                         }
533                 }
534
535                 [Test]
536                 public void Clone ()
537                 {
538                         using (Pen p = new Pen (Brushes.Red)) {
539                                 using (Pen clone = (Pen) p.Clone ()) {
540                                         Check (clone);
541                                 }
542                         }
543                 }
544
545                 [Test]
546                 [ExpectedException (typeof (ArgumentException))]
547                 public void Dispose ()
548                 {
549                         Pen p = new Pen (Brushes.Red);
550                         p.Dispose ();
551                         p.Alignment = PenAlignment.Center;
552                         // exception but not an ObjectDisposedException
553                 }
554
555                 [Test]
556                 public void SetLineCap ()
557                 {
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");
567                                                 }
568                                         }
569                                 }
570                         }
571                 }
572
573                 [Test]
574                 public void SetLineCap_InvalidStartCap ()
575                 {
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");
582                         }
583                 }
584
585                 [Test]
586                 public void SetLineCap_InvalidEndCap ()
587                 {
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");
594                         }
595                 }
596
597                 [Test]
598                 public void SetLineCap_InvalidDashCap ()
599                 {
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");
606                         }
607                 }
608
609                 [Test]
610                 //[ExpectedException (typeof (ArgumentNullException))] // reported as FDBK50058
611                 [ExpectedException (typeof (NullReferenceException))]
612                 public void MultiplyTransform1_Null ()
613                 {
614                         default_pen.MultiplyTransform (null);
615                 }
616
617                 [Test]
618                 //[ExpectedException (typeof (ArgumentNullException))] // reported as FDBK50058
619                 [ExpectedException (typeof (NullReferenceException))]
620                 public void MultiplyTransform2_Null ()
621                 {
622                         default_pen.MultiplyTransform (null, MatrixOrder.Append);
623                 }
624
625                 [Test]
626                 public void MultiplyTransform2_InvalidMatrixOrder ()
627                 {
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);
631
632                                 p.Transform = m2;
633                                 p.MultiplyTransform (m1, (MatrixOrder) Int32.MinValue);
634                                 // no exception, but which order is it ?
635                                 Matrix invalid = p.Transform;
636
637                                 p.Transform = m2;
638                                 p.MultiplyTransform (m1, MatrixOrder.Append);
639                                 Assert.IsTrue (invalid.Equals (p.Transform), "Append");
640
641                                 p.Transform = m2;
642                                 p.MultiplyTransform (m1, MatrixOrder.Prepend);
643                                 Assert.IsFalse (invalid.Equals (p.Transform), "Prepend");
644                         }
645                 }
646
647                 [Test]
648                 [ExpectedException (typeof (ArgumentException))]
649                 public void MultiplyTransform_NonInvertible ()
650                 {
651                         using (Matrix noninvertible = new Matrix (123, 24, 82, 16, 47, 30)) {
652                                 using (Pen p = new Pen (Brushes.Red)) {
653                                         p.MultiplyTransform (noninvertible);
654                                 }
655                         }
656                 }
657
658                 [Test]
659                 public void ResetTransform ()
660                 {
661                         using (Matrix m = new Matrix (2, 0, 0, 2, 10, -10)) {
662                                 using (Pen p = new Pen (Brushes.Red)) {
663                                         p.Transform = m;
664                                         Assert.IsFalse (p.Transform.IsIdentity, "Transform.IsIdentity");
665                                         p.ResetTransform ();
666                                         Assert.IsTrue (p.Transform.IsIdentity, "Reset.IsIdentity");
667                                 }
668                         }
669                 }
670
671                 [Test]
672                 public void RotateTransform ()
673                 {
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");
683
684                                 p.RotateTransform (270);
685                                 Assert.IsTrue (p.Transform.IsIdentity, "Transform.IsIdentity");
686                         }
687                 }
688
689                 [Test]
690                 [ExpectedException (typeof (ArgumentException))]
691                 public void RotateTransform_InvalidOrder ()
692                 {
693                         default_pen.RotateTransform (720, (MatrixOrder) Int32.MinValue);
694                 }
695
696                 [Test]
697                 public void ScaleTransform ()
698                 {
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");
708
709                                 p.ScaleTransform (0.5f, 0.25f);
710                                 Assert.IsTrue (p.Transform.IsIdentity, "Transform.IsIdentity");
711                         }
712                 }
713
714                 [Test]
715                 public void ScaleTransform_MaxMin ()
716                 {
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");
726                         }
727                 }
728
729                 [Test]
730                 [ExpectedException (typeof (ArgumentException))]
731                 public void ScaleTransform_InvalidOrder ()
732                 {
733                         default_pen.ScaleTransform (1, 1, (MatrixOrder) Int32.MinValue);
734                 }
735
736                 [Test]
737                 public void TranslateTransform ()
738                 {
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");
748
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");
757                         }
758                 }
759
760                 [Test]
761                 [ExpectedException (typeof (ArgumentException))]
762                 public void TranslateTransform_InvalidOrder ()
763                 {
764                         default_pen.TranslateTransform (1, 1, (MatrixOrder) Int32.MinValue);
765                 }
766
767                 [Test]
768                 public void Transform_Operations ()
769                 {
770                         using (Pen p = new Pen (Brushes.Red)) {
771                                 Matrix clone = p.Transform.Clone ();
772                                 Matrix mul = clone.Clone ();
773
774                                 clone.Multiply (mul, MatrixOrder.Append);
775                                 p.MultiplyTransform (mul, MatrixOrder.Append);
776                                 Assert.AreEqual (p.Transform, clone, "Multiply/Append");
777
778                                 clone.Multiply (mul, MatrixOrder.Prepend);
779                                 p.MultiplyTransform (mul, MatrixOrder.Prepend);
780                                 Assert.AreEqual (p.Transform, clone, "Multiply/Prepend");
781
782                                 clone.Rotate (45, MatrixOrder.Append);
783                                 p.RotateTransform (45, MatrixOrder.Append);
784                                 Assert.AreEqual (p.Transform, clone, "Rotate/Append");
785
786                                 clone.Rotate (45, MatrixOrder.Prepend);
787                                 p.RotateTransform (45, MatrixOrder.Prepend);
788                                 Assert.AreEqual (p.Transform, clone, "Rotate/Prepend");
789
790                                 clone.Scale (0.25f, 2, MatrixOrder.Append);
791                                 p.ScaleTransform (0.25f, 2, MatrixOrder.Append);
792                                 Assert.AreEqual (p.Transform, clone, "Scale/Append");
793
794                                 clone.Scale (0.25f, 2, MatrixOrder.Prepend);
795                                 p.ScaleTransform (0.25f, 2, MatrixOrder.Prepend);
796                                 Assert.AreEqual (p.Transform, clone, "Scale/Prepend");
797
798                                 clone.Translate (10, 20, MatrixOrder.Append);
799                                 p.TranslateTransform (10, 20, MatrixOrder.Append);
800                                 Assert.AreEqual (p.Transform, clone, "Translate/Append");
801
802                                 clone.Translate (30, 40, MatrixOrder.Prepend);
803                                 p.TranslateTransform (30, 40, MatrixOrder.Prepend);
804                                 Assert.AreEqual (p.Transform, clone, "Translate/Prepend");
805
806                                 clone.Reset ();
807                                 p.ResetTransform ();
808                                 Assert.AreEqual (p.Transform, clone, "Reset");
809                         }
810                 }
811         }
812 }