Merge pull request #757 from mlintner/master
[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                 [ExpectedException (typeof (ArgumentNullException))]
239                 public void Brush_Null ()
240                 {
241                         default_pen.Brush = null;
242                 }
243
244                 [Test]
245                 [Category ("NotWorking")] // not supported by libgdiplus
246                 public void CustomEndCap_Set ()
247                 {
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");
252                         }
253                 }
254
255                 [Test]
256                 [ExpectedException (typeof (ArgumentException))]
257                 [Category ("NotWorking")] // not supported by libgdiplus
258                 public void CustomEndCap_Default ()
259                 {
260                         CustomLineCap clc = default_pen.CustomEndCap;
261                 }
262
263                 [Test]
264                 [Category ("NotWorking")] // not supported by libgdiplus
265                 public void CustomStartCap_Set ()
266                 {
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");
271                         }
272                 }
273
274                 [Test]
275                 [ExpectedException (typeof (ArgumentException))]
276                 [Category ("NotWorking")] // not supported by libgdiplus
277                 public void CustomStartCap_Default ()
278                 {
279                         CustomLineCap clc = default_pen.CustomStartCap;
280                 }
281
282                 [Test]
283                 public void DashCap_Valid ()
284                 {
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))) {
289                                         p.DashCap = dc;
290                                         Assert.AreEqual (dc, p.DashCap, dc.ToString ());
291                                 }
292                         }
293                 }
294
295                 [Test]
296                 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
297                 public void DashCap_Invalid ()
298                 {
299                         default_pen.DashCap = (DashCap) Int32.MinValue;
300                 }
301
302                 [Test]
303                 public void DashOffset ()
304                 {
305                         using (Pen p = new Pen (Brushes.Transparent, 32)) {
306                                 p.DashOffset = 0;
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");
312                         }
313                 }
314
315                 [Test]
316                 public void DashPattern ()
317                 {
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");
323                         }
324                 }
325
326                 [Test]
327                 [ExpectedException (typeof (ArgumentException))]
328                 public void DashPattern_Empty ()
329                 {
330                         default_pen.DashPattern = new float[0];
331                 }
332
333                 [Test]
334                 public void DashStyle_Valid ()
335                 {
336                         using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
337                                 foreach (DashStyle ds in Enum.GetValues (typeof (DashStyle))) {
338                                         p.DashStyle = ds;
339                                         Assert.AreEqual (ds, p.DashStyle, ds.ToString ());
340                                 }
341                         }
342                 }
343
344                 [Test]
345                 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
346                 public void DashStyle_Invalid ()
347                 {
348                         default_pen.DashStyle = (DashStyle) Int32.MinValue;
349                 }
350
351                 [Test]
352                 public void DashStyle_Custom ()
353                 {
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]");
361
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]");
372
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]");
383
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]");
398
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]");
417
418                                 // resetting to DashStyle.Solid doesn't throw the OutOfMemoryException
419                                 // on MS runtime
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]");
427                         }
428                 }
429
430                 [Test]
431                 [ExpectedException (typeof (OutOfMemoryException))]
432                 [Category ("NotWorking")] // MS bug reported as FDBK50053
433                 public void DashPattern_Default ()
434                 {
435                         float[] pattern = default_pen.DashPattern;
436                 }
437
438                 [Test]
439                 public void EndCap_Valid ()
440                 {
441                         using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
442                                 foreach (LineCap lc in Enum.GetValues (typeof (LineCap))) {
443                                         p.EndCap = lc;
444                                         Assert.AreEqual (lc, p.EndCap, lc.ToString ());
445                                 }
446                         }
447                 }
448
449                 [Test]
450                 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
451                 public void EndCap_Invalid ()
452                 {
453                         default_pen.EndCap = (LineCap) Int32.MinValue;
454                 }
455
456                 [Test]
457                 public void LineJoin_Valid ()
458                 {
459                         using (Pen p = new Pen (Brushes.Chocolate, Single.NaN)) {
460                                 foreach (LineJoin lj in Enum.GetValues (typeof (LineJoin))) {
461                                         p.LineJoin = lj;
462                                         Assert.AreEqual (lj, p.LineJoin, lj.ToString ());
463                                 }
464                         }
465                 }
466
467                 [Test]
468                 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
469                 public void LineJoin_Invalid ()
470                 {
471                         default_pen.LineJoin = (LineJoin) Int32.MinValue;
472                 }
473
474                 [Test]
475                 public void MiterLimit ()
476                 {
477                         using (Pen p = new Pen (Brushes.Tan, 1)) {
478                                 p.MiterLimit = Single.MinValue;
479                                 Assert.AreEqual (1, p.MiterLimit, "MinValue/1");
480                                 p.MiterLimit = 0;
481                                 Assert.AreEqual (1, p.MiterLimit, "0/1");
482                                 p.MiterLimit = Single.MaxValue;
483                                 Assert.AreEqual (Single.MaxValue, p.MiterLimit, "MaxValue");
484                         }
485                 }
486
487                 [Test]
488                 public void StartCap_Valid ()
489                 {
490                         using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
491                                 foreach (LineCap lc in Enum.GetValues (typeof (LineCap))) {
492                                         p.StartCap = lc;
493                                         Assert.AreEqual (lc, p.StartCap, lc.ToString ());
494                                 }
495                         }
496                 }
497
498                 [Test]
499                 [ExpectedException (typeof (SC.InvalidEnumArgumentException))]
500                 public void StartCap_Invalid ()
501                 {
502                         default_pen.StartCap = (LineCap) Int32.MinValue;
503                 }
504
505                 [Test]
506                 [ExpectedException (typeof (ArgumentNullException))]
507                 public void Transform_Null ()
508                 {
509                         default_pen.Transform = null;
510                 }
511
512                 [Test]
513                 [ExpectedException (typeof (ArgumentException))]
514                 public void Transform_NonInvertible ()
515                 {
516                         using (Pen p = new Pen (Brushes.Snow, Single.MaxValue)) {
517                                 p.Transform = new Matrix (123, 24, 82, 16, 47, 30);
518                         }
519                 }
520
521                 [Test]
522                 public void Width ()
523                 {
524                         using (Pen p = new Pen (Brushes.Tan, Single.MinValue)) {
525                                 Assert.AreEqual (Single.MinValue, p.Width, "MinValue");
526                                 p.Width = 0;
527                                 Assert.AreEqual (0, p.Width, "0");
528                                 p.Width = Single.MaxValue;
529                                 Assert.AreEqual (Single.MaxValue, p.Width, "MaxValue");
530                         }
531                 }
532
533                 [Test]
534                 public void Clone ()
535                 {
536                         using (Pen p = new Pen (Brushes.Red)) {
537                                 using (Pen clone = (Pen) p.Clone ()) {
538                                         Check (clone);
539                                 }
540                         }
541                 }
542
543                 [Test]
544                 [ExpectedException (typeof (ArgumentException))]
545                 public void Dispose ()
546                 {
547                         Pen p = new Pen (Brushes.Red);
548                         p.Dispose ();
549                         p.Alignment = PenAlignment.Center;
550                         // exception but not an ObjectDisposedException
551                 }
552
553                 [Test]
554                 public void SetLineCap ()
555                 {
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");
565                                                 }
566                                         }
567                                 }
568                         }
569                 }
570
571                 [Test]
572                 public void SetLineCap_InvalidStartCap ()
573                 {
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");
580                         }
581                 }
582
583                 [Test]
584                 public void SetLineCap_InvalidEndCap ()
585                 {
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");
592                         }
593                 }
594
595                 [Test]
596                 public void SetLineCap_InvalidDashCap ()
597                 {
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");
604                         }
605                 }
606
607                 [Test]
608                 //[ExpectedException (typeof (ArgumentNullException))] // reported as FDBK50058
609                 [ExpectedException (typeof (NullReferenceException))]
610                 public void MultiplyTransform1_Null ()
611                 {
612                         default_pen.MultiplyTransform (null);
613                 }
614
615                 [Test]
616                 //[ExpectedException (typeof (ArgumentNullException))] // reported as FDBK50058
617                 [ExpectedException (typeof (NullReferenceException))]
618                 public void MultiplyTransform2_Null ()
619                 {
620                         default_pen.MultiplyTransform (null, MatrixOrder.Append);
621                 }
622
623                 [Test]
624                 public void MultiplyTransform2_InvalidMatrixOrder ()
625                 {
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);
629
630                                 p.Transform = m2;
631                                 p.MultiplyTransform (m1, (MatrixOrder) Int32.MinValue);
632                                 // no exception, but which order is it ?
633                                 Matrix invalid = p.Transform;
634
635                                 p.Transform = m2;
636                                 p.MultiplyTransform (m1, MatrixOrder.Append);
637                                 Assert.IsTrue (invalid.Equals (p.Transform), "Append");
638
639                                 p.Transform = m2;
640                                 p.MultiplyTransform (m1, MatrixOrder.Prepend);
641                                 Assert.IsFalse (invalid.Equals (p.Transform), "Prepend");
642                         }
643                 }
644
645                 [Test]
646                 [ExpectedException (typeof (ArgumentException))]
647                 public void MultiplyTransform_NonInvertible ()
648                 {
649                         using (Matrix noninvertible = new Matrix (123, 24, 82, 16, 47, 30)) {
650                                 using (Pen p = new Pen (Brushes.Red)) {
651                                         p.MultiplyTransform (noninvertible);
652                                 }
653                         }
654                 }
655
656                 [Test]
657                 public void ResetTransform ()
658                 {
659                         using (Matrix m = new Matrix (2, 0, 0, 2, 10, -10)) {
660                                 using (Pen p = new Pen (Brushes.Red)) {
661                                         p.Transform = m;
662                                         Assert.IsFalse (p.Transform.IsIdentity, "Transform.IsIdentity");
663                                         p.ResetTransform ();
664                                         Assert.IsTrue (p.Transform.IsIdentity, "Reset.IsIdentity");
665                                 }
666                         }
667                 }
668
669                 [Test]
670                 public void RotateTransform ()
671                 {
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");
681
682                                 p.RotateTransform (270);
683                                 Assert.IsTrue (p.Transform.IsIdentity, "Transform.IsIdentity");
684                         }
685                 }
686
687                 [Test]
688                 [ExpectedException (typeof (ArgumentException))]
689                 public void RotateTransform_InvalidOrder ()
690                 {
691                         default_pen.RotateTransform (720, (MatrixOrder) Int32.MinValue);
692                 }
693
694                 [Test]
695                 public void ScaleTransform ()
696                 {
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");
706
707                                 p.ScaleTransform (0.5f, 0.25f);
708                                 Assert.IsTrue (p.Transform.IsIdentity, "Transform.IsIdentity");
709                         }
710                 }
711
712                 [Test]
713                 public void ScaleTransform_MaxMin ()
714                 {
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");
724                         }
725                 }
726
727                 [Test]
728                 [ExpectedException (typeof (ArgumentException))]
729                 public void ScaleTransform_InvalidOrder ()
730                 {
731                         default_pen.ScaleTransform (1, 1, (MatrixOrder) Int32.MinValue);
732                 }
733
734                 [Test]
735                 public void TranslateTransform ()
736                 {
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");
746
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");
755                         }
756                 }
757
758                 [Test]
759                 [ExpectedException (typeof (ArgumentException))]
760                 public void TranslateTransform_InvalidOrder ()
761                 {
762                         default_pen.TranslateTransform (1, 1, (MatrixOrder) Int32.MinValue);
763                 }
764
765                 [Test]
766                 public void Transform_Operations ()
767                 {
768                         using (Pen p = new Pen (Brushes.Red)) {
769                                 Matrix clone = p.Transform.Clone ();
770                                 Matrix mul = clone.Clone ();
771
772                                 clone.Multiply (mul, MatrixOrder.Append);
773                                 p.MultiplyTransform (mul, MatrixOrder.Append);
774                                 Assert.AreEqual (p.Transform, clone, "Multiply/Append");
775
776                                 clone.Multiply (mul, MatrixOrder.Prepend);
777                                 p.MultiplyTransform (mul, MatrixOrder.Prepend);
778                                 Assert.AreEqual (p.Transform, clone, "Multiply/Prepend");
779
780                                 clone.Rotate (45, MatrixOrder.Append);
781                                 p.RotateTransform (45, MatrixOrder.Append);
782                                 Assert.AreEqual (p.Transform, clone, "Rotate/Append");
783
784                                 clone.Rotate (45, MatrixOrder.Prepend);
785                                 p.RotateTransform (45, MatrixOrder.Prepend);
786                                 Assert.AreEqual (p.Transform, clone, "Rotate/Prepend");
787
788                                 clone.Scale (0.25f, 2, MatrixOrder.Append);
789                                 p.ScaleTransform (0.25f, 2, MatrixOrder.Append);
790                                 Assert.AreEqual (p.Transform, clone, "Scale/Append");
791
792                                 clone.Scale (0.25f, 2, MatrixOrder.Prepend);
793                                 p.ScaleTransform (0.25f, 2, MatrixOrder.Prepend);
794                                 Assert.AreEqual (p.Transform, clone, "Scale/Prepend");
795
796                                 clone.Translate (10, 20, MatrixOrder.Append);
797                                 p.TranslateTransform (10, 20, MatrixOrder.Append);
798                                 Assert.AreEqual (p.Transform, clone, "Translate/Append");
799
800                                 clone.Translate (30, 40, MatrixOrder.Prepend);
801                                 p.TranslateTransform (30, 40, MatrixOrder.Prepend);
802                                 Assert.AreEqual (p.Transform, clone, "Translate/Prepend");
803
804                                 clone.Reset ();
805                                 p.ResetTransform ();
806                                 Assert.AreEqual (p.Transform, clone, "Reset");
807                         }
808                 }
809         }
810 }