bc050f3daab24ba5ba19a1293c1d24e5e4a1922e
[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                 public void Constructor_Brush_Null ()
126                 {
127                         Assert.Throws<ArgumentNullException> (() => new Pen ((Brush) null));
128                 }
129
130                 [Test]
131                 public void Constructor_Brush_Float ()
132                 {
133                         using (Pen p = new Pen (Brushes.Red, 2.5f)) {
134                                 Assert.AreEqual (2.5f, p.Width, "Width");
135                                 Check (p);
136                         }
137                 }
138
139                 [Test]
140                 public void Constructor_Brush_Float_Null ()
141                 {
142                         Assert.Throws<ArgumentNullException> (() => new Pen ((Brush) null, Single.MaxValue));
143                 }
144
145                 [Test]
146                 public void Constructor_Brush_Float_Zero ()
147                 {
148                         using (Pen p = new Pen (Brushes.Red, 0.0f)) {
149                                 Assert.AreEqual (0.0f, p.Width, "Width");
150                                 Check (p);
151                         }
152                 }
153
154                 [Test]
155                 public void Constructor_Brush_Float_Negative ()
156                 {
157                         using (Pen p = new Pen (Brushes.Red, -2)) {
158                                 Assert.AreEqual (-2, p.Width, "Width");
159                                 Check (p);
160                         }
161                 }
162
163                 [Test]
164                 public void Constructor_Brush_Float_MaxValue ()
165                 {
166                         using (Pen p = new Pen (Brushes.Red, Single.MaxValue)) {
167                                 Assert.AreEqual (Single.MaxValue, p.Width, "Width");
168                                 Check (p);
169                         }
170                 }
171
172                 [Test]
173                 public void Constructor_Brush_DisposeBeforeUse ()
174                 {
175                         using (SolidBrush b = new SolidBrush (Color.Red)) {
176                                 using (Pen p = new Pen (b, 1)) {
177                                         b.Dispose ();
178                                         Check (p);
179                                         using (Bitmap bmp = new Bitmap (12, 12)) {
180                                                 using (Graphics g = Graphics.FromImage (bmp)) {
181                                                         g.DrawLine (p, 1, 1, 10, 10);
182                                                 }
183                                         }
184                                 }
185                         }
186                 }
187
188                 private void Check2 (Pen p)
189                 {
190                         Assert.AreEqual (typeof (SolidBrush), p.Brush.GetType (), "Brush.Type");
191                         Assert.AreEqual (Color.Red.ToArgb (), (p.Brush as SolidBrush).Color.ToArgb (), "Brush.Color");
192                         Assert.AreEqual (Color.Red.ToArgb (), p.Color.ToArgb (), "Color");
193                         Assert.AreEqual (0, p.CompoundArray.Length, "CompoundArray");
194                         //                      Assert.AreEqual (DashCap.Flat, p.DashCap, "DashCap");
195                         Assert.AreEqual (0, p.DashOffset, "DashOffset");
196                         Assert.AreEqual (10, p.MiterLimit, "MiterLimit");
197                         Assert.AreEqual (PenType.SolidColor, p.PenType, "PenType");
198                         Assert.IsTrue (p.Transform.IsIdentity, "Transform");
199                 }
200
201                 [Test]
202                 public void Alignment ()
203                 {
204                         using (Pen p = new Pen (Brushes.Gold, Single.NegativeInfinity)) {
205                                 foreach (PenAlignment pa in Enum.GetValues (typeof (PenAlignment))) {
206                                         p.Alignment = pa;
207                                         Assert.AreEqual (pa, p.Alignment, pa.ToString ());
208                                 }
209                         }
210                 }
211
212                 [Test]
213                 public void Alignment_Invalid ()
214                 {
215                         Assert.Throws<SC.InvalidEnumArgumentException> (() => default_pen.Alignment = (PenAlignment) Int32.MinValue);
216                 }
217
218                 [Test]
219                 public void Brush_Dispose ()
220                 {
221                         using (Pen p = new Pen (Brushes.Red, 2.5f)) {
222                                 // are we getting the original brush ?
223                                 Brush b1 = p.Brush;
224                                 b1.Dispose ();
225                                 Check (p);
226                                 using (Pen clone = (Pen) p.Clone ()) {
227                                         Check (clone);
228                                 }
229                                 Assert.IsFalse (Object.ReferenceEquals (b1, p.Brush), "Brush");
230                                 // nope :)
231                         }
232                 }
233
234                 [Test]
235                 public void Brush_Null ()
236                 {
237                         Assert.Throws<ArgumentNullException> (() => default_pen.Brush = null);
238                 }
239
240                 [Test]
241                 [Category ("NotWorking")] // not supported by libgdiplus
242                 public void CustomEndCap_Set ()
243                 {
244                         using (Pen p = new Pen (Brushes.DeepSkyBlue, -1)) {
245                                 p.CustomEndCap = custom_line_cap;
246                                 Assert.IsNotNull (p.CustomEndCap, "CustomEndCap");
247                                 Assert.IsFalse (Object.ReferenceEquals (custom_line_cap, p.CustomEndCap), "!same");
248                         }
249                 }
250
251                 [Test]
252                 [Category ("NotWorking")] // not supported by libgdiplus
253                 public void CustomEndCap_Default ()
254                 {
255                         Assert.Throws<ArgumentException> (() => { var x = default_pen.CustomEndCap; });
256                 }
257
258                 [Test]
259                 [Category ("NotWorking")] // not supported by libgdiplus
260                 public void CustomStartCap_Set ()
261                 {
262                         using (Pen p = new Pen (Brushes.Ivory, 5)) {
263                                 p.CustomStartCap = custom_line_cap;
264                                 Assert.IsNotNull (p.CustomStartCap, "CustomStartCap");
265                                 Assert.IsFalse (Object.ReferenceEquals (custom_line_cap, p.CustomStartCap), "!same");
266                         }
267                 }
268
269                 [Test]
270                 [Category ("NotWorking")] // not supported by libgdiplus
271                 public void CustomStartCap_Default ()
272                 {
273                         Assert.Throws<ArgumentException> (() => { var x = default_pen.CustomStartCap; });
274                 }
275
276                 [Test]
277                 public void DashCap_Valid ()
278                 {
279                         // note: YellowGreen is broken by a destructive test so we can't use it afterward
280                         // note: this worked with nunit 2.2 because this test was executed before the destructive one
281                         using (Pen p = new Pen (Brushes.Yellow, 0)) {
282                                 foreach (DashCap dc in Enum.GetValues (typeof (DashCap))) {
283                                         p.DashCap = dc;
284                                         Assert.AreEqual (dc, p.DashCap, dc.ToString ());
285                                 }
286                         }
287                 }
288
289                 [Test]
290                 public void DashCap_Invalid ()
291                 {
292                         Assert.Throws<SC.InvalidEnumArgumentException> (() => default_pen.DashCap = (DashCap) Int32.MinValue);
293                 }
294
295                 [Test]
296                 public void DashOffset ()
297                 {
298                         using (Pen p = new Pen (Brushes.Transparent, 32)) {
299                                 p.DashOffset = 0;
300                                 Assert.AreEqual (0, p.DashOffset, "0");
301                                 p.DashOffset = Single.MaxValue;
302                                 Assert.AreEqual (Single.MaxValue, p.DashOffset, "MaxValue");
303                                 p.DashOffset = Single.MinValue;
304                                 Assert.AreEqual (Single.MinValue, p.DashOffset, "MinValue");
305                         }
306                 }
307
308                 [Test]
309                 public void DashPattern ()
310                 {
311                         using (Pen p = new Pen (Brushes.Tomato, 1.1f)) {
312                                 Assert.AreEqual (DashStyle.Solid, p.DashStyle, "Solid");
313                                 p.DashPattern = new float[1] { 1 };
314                                 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Custom");
315                                 Assert.AreEqual (1, p.DashPattern.Length, "DashPattern");
316                         }
317                 }
318
319                 [Test]
320                 public void DashPattern_Empty ()
321                 {
322                         Assert.Throws<ArgumentException> (() => default_pen.DashPattern = new float[0]);
323                 }
324
325                 [Test]
326                 public void DashStyle_Valid ()
327                 {
328                         using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
329                                 foreach (DashStyle ds in Enum.GetValues (typeof (DashStyle))) {
330                                         p.DashStyle = ds;
331                                         Assert.AreEqual (ds, p.DashStyle, ds.ToString ());
332                                 }
333                         }
334                 }
335
336                 [Test]
337                 public void DashStyle_Invalid ()
338                 {
339                         Assert.Throws<SC.InvalidEnumArgumentException> (() => default_pen.DashStyle = (DashStyle) Int32.MinValue);
340                 }
341
342                 [Test]
343                 public void DashStyle_Custom ()
344                 {
345                         using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
346                                 Assert.AreEqual (DashStyle.Solid, p.DashStyle, "Solid");
347                                 // can't ask for Solid (default) -> OutOfMemoryException
348                                 p.DashStyle = DashStyle.Custom;
349                                 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Solid->Custom");
350                                 Assert.AreEqual (1, p.DashPattern.Length, "Solid->Custom.Length");
351                                 Assert.AreEqual (1, p.DashPattern[0], "Solid->Custom[0]");
352
353                                 p.DashStyle = DashStyle.Dot;
354                                 Assert.AreEqual (DashStyle.Dot, p.DashStyle, "Dot");
355                                 Assert.AreEqual (2, p.DashPattern.Length, "Dot.Length");
356                                 Assert.AreEqual (1, p.DashPattern[0], "Dot[0]");
357                                 Assert.AreEqual (1, p.DashPattern[1], "Dot[1]");
358                                 p.DashStyle = DashStyle.Custom;
359                                 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Dot->Custom");
360                                 Assert.AreEqual (2, p.DashPattern.Length, "Dot->Custom.Length");
361                                 Assert.AreEqual (1, p.DashPattern[0], "Dot->Custom[0]");
362                                 Assert.AreEqual (1, p.DashPattern[1], "Dot->Custom[1]");
363
364                                 p.DashStyle = DashStyle.Dash;
365                                 Assert.AreEqual (DashStyle.Dash, p.DashStyle, "Dash");
366                                 Assert.AreEqual (2, p.DashPattern.Length, "Dash.Length");
367                                 Assert.AreEqual (3, p.DashPattern[0], "Dash[0]");
368                                 Assert.AreEqual (1, p.DashPattern[1], "Dash[1]");
369                                 p.DashStyle = DashStyle.Custom;
370                                 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Dash->Custom");
371                                 Assert.AreEqual (2, p.DashPattern.Length, "Dash->Custom.Length");
372                                 Assert.AreEqual (3, p.DashPattern[0], "Dash->Custom[0]");
373                                 Assert.AreEqual (1, p.DashPattern[1], "Dash->Custom[1]");
374
375                                 p.DashStyle = DashStyle.DashDot;
376                                 Assert.AreEqual (DashStyle.DashDot, p.DashStyle, "DashDot");
377                                 Assert.AreEqual (4, p.DashPattern.Length, "DashDot.Length");
378                                 Assert.AreEqual (3, p.DashPattern[0], "DashDot[0]");
379                                 Assert.AreEqual (1, p.DashPattern[1], "DashDot[1]");
380                                 Assert.AreEqual (1, p.DashPattern[2], "DashDot[2]");
381                                 Assert.AreEqual (1, p.DashPattern[3], "DashDot[3]");
382                                 p.DashStyle = DashStyle.Custom;
383                                 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "DashDot->Custom");
384                                 Assert.AreEqual (4, p.DashPattern.Length, "DashDot->Custom.Length");
385                                 Assert.AreEqual (3, p.DashPattern[0], "DashDot->Custom[0]");
386                                 Assert.AreEqual (1, p.DashPattern[1], "DashDot->Custom[1]");
387                                 Assert.AreEqual (1, p.DashPattern[2], "DashDot->Custom[2]");
388                                 Assert.AreEqual (1, p.DashPattern[3], "DashDot->Custom[3]");
389
390                                 p.DashStyle = DashStyle.DashDotDot;
391                                 Assert.AreEqual (DashStyle.DashDotDot, p.DashStyle, "DashDotDot");
392                                 Assert.AreEqual (6, p.DashPattern.Length, "DashDotDot.Length");
393                                 Assert.AreEqual (3, p.DashPattern[0], "DashDotDot[0]");
394                                 Assert.AreEqual (1, p.DashPattern[1], "DashDotDot[1]");
395                                 Assert.AreEqual (1, p.DashPattern[2], "DashDotDot[2]");
396                                 Assert.AreEqual (1, p.DashPattern[3], "DashDotDot[3]");
397                                 Assert.AreEqual (1, p.DashPattern[2], "DashDotDot[2]");
398                                 Assert.AreEqual (1, p.DashPattern[3], "DashDotDot[3]");
399                                 p.DashStyle = DashStyle.Custom;
400                                 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "DashDotDot->Custom");
401                                 Assert.AreEqual (6, p.DashPattern.Length, "DashDotDot->Custom.Length");
402                                 Assert.AreEqual (3, p.DashPattern[0], "DashDotDot->Custom[0]");
403                                 Assert.AreEqual (1, p.DashPattern[1], "DashDotDot->Custom[1]");
404                                 Assert.AreEqual (1, p.DashPattern[2], "DashDotDot->Custom[2]");
405                                 Assert.AreEqual (1, p.DashPattern[3], "DashDotDot->Custom[3]");
406                                 Assert.AreEqual (1, p.DashPattern[2], "DashDotDot->Custom[2]");
407                                 Assert.AreEqual (1, p.DashPattern[3], "DashDotDot->Custom[3]");
408
409                                 // resetting to DashStyle.Solid doesn't throw the OutOfMemoryException
410                                 // on MS runtime
411                                 p.DashStyle = DashStyle.Solid;
412                                 Assert.AreEqual (DashStyle.Solid, p.DashStyle, "Solid-2");
413                                 Assert.AreEqual (0, p.DashPattern.Length, "Solid2.Length");
414                                 p.DashStyle = DashStyle.Custom;
415                                 Assert.AreEqual (DashStyle.Custom, p.DashStyle, "Solid2->Custom");
416                                 Assert.AreEqual (1, p.DashPattern.Length, "Solid2->Custom.Length");
417                                 Assert.AreEqual (1, p.DashPattern[0], "Solid2->Custom[0]");
418                         }
419                 }
420
421                 [Test]
422                 [Category ("NotWorking")] // MS bug reported as FDBK50053
423                 public void DashPattern_Default ()
424                 {
425                         Assert.Throws<OutOfMemoryException> (() => { var x = default_pen.DashPattern; });
426                 }
427
428                 [Test]
429                 public void EndCap_Valid ()
430                 {
431                         using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
432                                 foreach (LineCap lc in Enum.GetValues (typeof (LineCap))) {
433                                         p.EndCap = lc;
434                                         Assert.AreEqual (lc, p.EndCap, lc.ToString ());
435                                 }
436                         }
437                 }
438
439                 [Test]
440                 public void EndCap_Invalid ()
441                 {
442                         Assert.Throws<SC.InvalidEnumArgumentException> (() => default_pen.EndCap = (LineCap) Int32.MinValue);
443                 }
444
445                 [Test]
446                 public void LineJoin_Valid ()
447                 {
448                         using (Pen p = new Pen (Brushes.Chocolate, Single.NaN)) {
449                                 foreach (LineJoin lj in Enum.GetValues (typeof (LineJoin))) {
450                                         p.LineJoin = lj;
451                                         Assert.AreEqual (lj, p.LineJoin, lj.ToString ());
452                                 }
453                         }
454                 }
455
456                 [Test]
457                 public void LineJoin_Invalid ()
458                 {
459                         Assert.Throws<SC.InvalidEnumArgumentException> (() => default_pen.LineJoin = (LineJoin) Int32.MinValue);
460                 }
461
462                 [Test]
463                 public void MiterLimit ()
464                 {
465                         using (Pen p = new Pen (Brushes.Tan, 1)) {
466                                 p.MiterLimit = Single.MinValue;
467                                 Assert.AreEqual (1, p.MiterLimit, "MinValue/1");
468                                 p.MiterLimit = 0;
469                                 Assert.AreEqual (1, p.MiterLimit, "0/1");
470                                 p.MiterLimit = Single.MaxValue;
471                                 Assert.AreEqual (Single.MaxValue, p.MiterLimit, "MaxValue");
472                         }
473                 }
474
475                 [Test]
476                 public void StartCap_Valid ()
477                 {
478                         using (Pen p = new Pen (Brushes.Silver, Single.PositiveInfinity)) {
479                                 foreach (LineCap lc in Enum.GetValues (typeof (LineCap))) {
480                                         p.StartCap = lc;
481                                         Assert.AreEqual (lc, p.StartCap, lc.ToString ());
482                                 }
483                         }
484                 }
485
486                 [Test]
487                 public void StartCap_Invalid ()
488                 {
489                         Assert.Throws<SC.InvalidEnumArgumentException> (() => default_pen.StartCap = (LineCap) Int32.MinValue);
490                 }
491
492                 [Test]
493                 public void Transform_Null ()
494                 {
495                         Assert.Throws<ArgumentNullException> (() => default_pen.Transform = null);
496                 }
497
498                 [Test]
499                 public void Transform_NonInvertible ()
500                 {
501                         using (Pen p = new Pen (Brushes.Snow, Single.MaxValue)) {
502                                 Assert.Throws<ArgumentException> (() => p.Transform = new Matrix (123, 24, 82, 16, 47, 30));
503                         }
504                 }
505
506                 [Test]
507                 public void Width ()
508                 {
509                         using (Pen p = new Pen (Brushes.Tan, Single.MinValue)) {
510                                 Assert.AreEqual (Single.MinValue, p.Width, "MinValue");
511                                 p.Width = 0;
512                                 Assert.AreEqual (0, p.Width, "0");
513                                 p.Width = Single.MaxValue;
514                                 Assert.AreEqual (Single.MaxValue, p.Width, "MaxValue");
515                         }
516                 }
517
518                 [Test]
519                 public void Clone ()
520                 {
521                         using (Pen p = new Pen (Brushes.Red)) {
522                                 using (Pen clone = (Pen) p.Clone ()) {
523                                         Check (clone);
524                                 }
525                         }
526                 }
527
528                 [Test]
529                 public void Dispose ()
530                 {
531                         Pen p = new Pen (Brushes.Red);
532                         p.Dispose ();
533                         Assert.Throws<ArgumentException> (() => p.Alignment = PenAlignment.Center);
534                         // exception but not an ObjectDisposedException
535                 }
536
537                 [Test]
538                 public void SetLineCap ()
539                 {
540                         using (Pen p = new Pen (Brushes.Red)) {
541                                 foreach (LineCap sc in Enum.GetValues (typeof (LineCap))) {
542                                         foreach (LineCap ec in Enum.GetValues (typeof (LineCap))) {
543                                                 foreach (DashCap dc in Enum.GetValues (typeof (DashCap))) {
544                                                         string s = String.Format ("{0}-{1}-{2}", sc, ec, dc);
545                                                         p.SetLineCap (sc, ec, dc);
546                                                         Assert.AreEqual (sc, p.StartCap, s + ".StartCap");
547                                                         Assert.AreEqual (ec, p.EndCap, s + ".EndCap");
548                                                         Assert.AreEqual (dc, p.DashCap, s + ".DashCap");
549                                                 }
550                                         }
551                                 }
552                         }
553                 }
554
555                 [Test]
556                 public void SetLineCap_InvalidStartCap ()
557                 {
558                         using (Pen p = new Pen (Brushes.Red)) {
559                                 p.SetLineCap ((LineCap)Int32.MinValue, LineCap.Flat, DashCap.Flat);
560                                 // no exception :( (reported as FDBK50057)
561                                 Assert.AreEqual (Int32.MinValue, (int) p.StartCap, "StartCap");
562                                 Assert.AreEqual (LineCap.Flat, p.EndCap, "EndCap");
563                                 Assert.AreEqual (DashCap.Flat, p.DashCap, "DashCap");
564                         }
565                 }
566
567                 [Test]
568                 public void SetLineCap_InvalidEndCap ()
569                 {
570                         using (Pen p = new Pen (Brushes.Red)) {
571                                 p.SetLineCap (LineCap.Flat, (LineCap)Int32.MinValue, DashCap.Flat);
572                                 // no exception :( (reported as FDBK50057)
573                                 Assert.AreEqual (LineCap.Flat, p.StartCap, "StartCap");
574                                 Assert.AreEqual (Int32.MinValue, (int)p.EndCap, "EndCap");
575                                 Assert.AreEqual (DashCap.Flat, p.DashCap, "DashCap");
576                         }
577                 }
578
579                 [Test]
580                 public void SetLineCap_InvalidDashCap ()
581                 {
582                         using (Pen p = new Pen (Brushes.Red)) {
583                                 p.SetLineCap (LineCap.Flat, LineCap.Flat, (DashCap)Int32.MinValue);
584                                 Assert.AreEqual (LineCap.Flat, p.StartCap, "StartCap");
585                                 Assert.AreEqual (LineCap.Flat, p.EndCap, "EndCap");
586                                 // invalid value was reseted to Flat (reported as FDBK50057)
587                                 Assert.AreEqual (DashCap.Flat, p.DashCap, "DashCap");
588                         }
589                 }
590
591                 [Test]
592                 //[ExpectedException (typeof (ArgumentNullException))] // reported as FDBK50058
593                 public void MultiplyTransform1_Null ()
594                 {
595                         Assert.Throws<NullReferenceException> (() => default_pen.MultiplyTransform (null));
596                 }
597
598                 [Test]
599                 //[ExpectedException (typeof (ArgumentNullException))] // reported as FDBK50058
600                 public void MultiplyTransform2_Null ()
601                 {
602                         Assert.Throws<NullReferenceException> (() => default_pen.MultiplyTransform (null, MatrixOrder.Append));
603                 }
604
605                 [Test]
606                 public void MultiplyTransform2_InvalidMatrixOrder ()
607                 {
608                         using (Pen p = new Pen (Brushes.Red)) {
609                                 Matrix m1 = new Matrix (2, 0.5f, 0.5f, 4, 10, 20);
610                                 Matrix m2 = new Matrix (1, 0, 0, 1, -50, -30);
611
612                                 p.Transform = m2;
613                                 p.MultiplyTransform (m1, (MatrixOrder) Int32.MinValue);
614                                 // no exception, but which order is it ?
615                                 Matrix invalid = p.Transform;
616
617                                 p.Transform = m2;
618                                 p.MultiplyTransform (m1, MatrixOrder.Append);
619                                 Assert.IsTrue (invalid.Equals (p.Transform), "Append");
620
621                                 p.Transform = m2;
622                                 p.MultiplyTransform (m1, MatrixOrder.Prepend);
623                                 Assert.IsFalse (invalid.Equals (p.Transform), "Prepend");
624                         }
625                 }
626
627                 [Test]
628                 public void MultiplyTransform_NonInvertible ()
629                 {
630                         using (Matrix noninvertible = new Matrix (123, 24, 82, 16, 47, 30)) {
631                                 using (Pen p = new Pen (Brushes.Red)) {
632                                         Assert.Throws<ArgumentException> (() => p.MultiplyTransform (noninvertible));
633                                 }
634                         }
635                 }
636
637                 [Test]
638                 public void ResetTransform ()
639                 {
640                         using (Matrix m = new Matrix (2, 0, 0, 2, 10, -10)) {
641                                 using (Pen p = new Pen (Brushes.Red)) {
642                                         p.Transform = m;
643                                         Assert.IsFalse (p.Transform.IsIdentity, "Transform.IsIdentity");
644                                         p.ResetTransform ();
645                                         Assert.IsTrue (p.Transform.IsIdentity, "Reset.IsIdentity");
646                                 }
647                         }
648                 }
649
650                 [Test]
651                 public void RotateTransform ()
652                 {
653                         using (Pen p = new Pen (Brushes.Red)) {
654                                 p.RotateTransform (90);
655                                 float[] elements = p.Transform.Elements;
656                                 Assert.AreEqual (0, elements[0], 0.1, "matrix.0");
657                                 Assert.AreEqual (1, elements[1], 0.1, "matrix.1");
658                                 Assert.AreEqual (-1, elements[2], 0.1, "matrix.2");
659                                 Assert.AreEqual (0, elements[3], 0.1, "matrix.3");
660                                 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
661                                 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
662
663                                 p.RotateTransform (270);
664                                 Assert.IsTrue (p.Transform.IsIdentity, "Transform.IsIdentity");
665                         }
666                 }
667
668                 [Test]
669                 public void RotateTransform_InvalidOrder ()
670                 {
671                         Assert.Throws<ArgumentException> (() => default_pen.RotateTransform (720, (MatrixOrder) Int32.MinValue));
672                 }
673
674                 [Test]
675                 public void ScaleTransform ()
676                 {
677                         using (Pen p = new Pen (Brushes.Red)) {
678                                 p.ScaleTransform (2, 4);
679                                 float[] elements = p.Transform.Elements;
680                                 Assert.AreEqual (2, elements[0], 0.1, "matrix.0");
681                                 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
682                                 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
683                                 Assert.AreEqual (4, elements[3], 0.1, "matrix.3");
684                                 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
685                                 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
686
687                                 p.ScaleTransform (0.5f, 0.25f);
688                                 Assert.IsTrue (p.Transform.IsIdentity, "Transform.IsIdentity");
689                         }
690                 }
691
692                 [Test]
693                 public void ScaleTransform_MaxMin ()
694                 {
695                         using (Pen p = new Pen (Brushes.Red)) {
696                                 p.ScaleTransform (Single.MaxValue, Single.MinValue);
697                                 float[] elements = p.Transform.Elements;
698                                 Assert.AreEqual (Single.MaxValue, elements[0], 1e33, "matrix.0");
699                                 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
700                                 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
701                                 Assert.AreEqual (Single.MinValue, elements[3], 1e33, "matrix.3");
702                                 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
703                                 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
704                         }
705                 }
706
707                 [Test]
708                 public void ScaleTransform_InvalidOrder ()
709                 {
710                         Assert.Throws<ArgumentException> (() => default_pen.ScaleTransform (1, 1, (MatrixOrder) Int32.MinValue));
711                 }
712
713                 [Test]
714                 public void TranslateTransform ()
715                 {
716                         using (Pen p = new Pen (Brushes.Red)) {
717                                 p.TranslateTransform (1, 1);
718                                 float[] elements = p.Transform.Elements;
719                                 Assert.AreEqual (1, elements[0], 0.1, "matrix.0");
720                                 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
721                                 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
722                                 Assert.AreEqual (1, elements[3], 0.1, "matrix.3");
723                                 Assert.AreEqual (1, elements[4], 0.1, "matrix.4");
724                                 Assert.AreEqual (1, elements[5], 0.1, "matrix.5");
725
726                                 p.TranslateTransform (-1, -1);
727                                 elements = p.Transform.Elements;
728                                 Assert.AreEqual (1, elements[0], 0.1, "revert.matrix.0");
729                                 Assert.AreEqual (0, elements[1], 0.1, "revert.matrix.1");
730                                 Assert.AreEqual (0, elements[2], 0.1, "revert.matrix.2");
731                                 Assert.AreEqual (1, elements[3], 0.1, "revert.matrix.3");
732                                 Assert.AreEqual (0, elements[4], 0.1, "revert.matrix.4");
733                                 Assert.AreEqual (0, elements[5], 0.1, "revert.matrix.5");
734                         }
735                 }
736
737                 [Test]
738                 public void TranslateTransform_InvalidOrder ()
739                 {
740                         Assert.Throws<ArgumentException> (() => default_pen.TranslateTransform (1, 1, (MatrixOrder) Int32.MinValue));
741                 }
742
743                 [Test]
744                 public void Transform_Operations ()
745                 {
746                         using (Pen p = new Pen (Brushes.Red)) {
747                                 Matrix clone = p.Transform.Clone ();
748                                 Matrix mul = clone.Clone ();
749
750                                 clone.Multiply (mul, MatrixOrder.Append);
751                                 p.MultiplyTransform (mul, MatrixOrder.Append);
752                                 Assert.AreEqual (p.Transform, clone, "Multiply/Append");
753
754                                 clone.Multiply (mul, MatrixOrder.Prepend);
755                                 p.MultiplyTransform (mul, MatrixOrder.Prepend);
756                                 Assert.AreEqual (p.Transform, clone, "Multiply/Prepend");
757
758                                 clone.Rotate (45, MatrixOrder.Append);
759                                 p.RotateTransform (45, MatrixOrder.Append);
760                                 Assert.AreEqual (p.Transform, clone, "Rotate/Append");
761
762                                 clone.Rotate (45, MatrixOrder.Prepend);
763                                 p.RotateTransform (45, MatrixOrder.Prepend);
764                                 Assert.AreEqual (p.Transform, clone, "Rotate/Prepend");
765
766                                 clone.Scale (0.25f, 2, MatrixOrder.Append);
767                                 p.ScaleTransform (0.25f, 2, MatrixOrder.Append);
768                                 Assert.AreEqual (p.Transform, clone, "Scale/Append");
769
770                                 clone.Scale (0.25f, 2, MatrixOrder.Prepend);
771                                 p.ScaleTransform (0.25f, 2, MatrixOrder.Prepend);
772                                 Assert.AreEqual (p.Transform, clone, "Scale/Prepend");
773
774                                 clone.Translate (10, 20, MatrixOrder.Append);
775                                 p.TranslateTransform (10, 20, MatrixOrder.Append);
776                                 Assert.AreEqual (p.Transform, clone, "Translate/Append");
777
778                                 clone.Translate (30, 40, MatrixOrder.Prepend);
779                                 p.TranslateTransform (30, 40, MatrixOrder.Prepend);
780                                 Assert.AreEqual (p.Transform, clone, "Translate/Prepend");
781
782                                 clone.Reset ();
783                                 p.ResetTransform ();
784                                 Assert.AreEqual (p.Transform, clone, "Reset");
785                         }
786                 }
787         }
788 }