Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing.Drawing2D / PathGradientBrushTest.cs
1 //
2 // System.Drawing.Drawing2D.PathGradientBrush 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 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.Drawing2D {
37
38         [TestFixture]
39         public class PathGradientBrushTest {
40
41                 private Point[] pts_2i;
42                 private PointF[] pts_2f;
43                 private Matrix empty_matrix;
44
45                 private void CheckDefaultRectangle (string message, RectangleF rect)
46                 {
47                         Assert.AreEqual (1f, rect.X, message + ".Rectangle.X");
48                         Assert.AreEqual (2f, rect.Y, message + ".Rectangle.Y");
49                         Assert.AreEqual (19f, rect.Width, message + ".Rectangle.Width");
50                         Assert.AreEqual (28f, rect.Height, message + ".Rectangle.Height");
51                 }
52
53                 private void CheckDefaults (PathGradientBrush pgb)
54                 {
55                         Assert.AreEqual (1, pgb.Blend.Factors.Length, "Blend.Factors.Length");
56                         Assert.AreEqual (1f, pgb.Blend.Factors[0], "Blend.Factors[0]");
57                         Assert.AreEqual (1, pgb.Blend.Positions.Length, "Blend.Positions.Length");
58                         Assert.AreEqual (0f, pgb.Blend.Positions[0], 1e-30, "Blend.Positions[0]");
59                         Assert.AreEqual (10.5f, pgb.CenterPoint.X, "CenterPoint.X");
60                         Assert.AreEqual (16f, pgb.CenterPoint.Y, "CenterPoint.Y");
61                         Assert.IsTrue (pgb.FocusScales.IsEmpty, "FocusScales");
62                         Assert.AreEqual (1, pgb.InterpolationColors.Colors.Length, "InterpolationColors.Colors.Length");
63                         Assert.AreEqual (0, pgb.InterpolationColors.Colors[0].ToArgb (), "InterpolationColors.Colors[0]");
64                         Assert.AreEqual (1, pgb.InterpolationColors.Positions.Length, "InterpolationColors.Positions.Length");
65                         Assert.AreEqual (0f, pgb.InterpolationColors.Positions[0], 1e-38, "InterpolationColors.Positions[0]");
66                         CheckDefaultRectangle (String.Empty, pgb.Rectangle);
67                         Assert.AreEqual (1, pgb.SurroundColors.Length, "SurroundColors.Length");
68                         Assert.AreEqual (-1, pgb.SurroundColors[0].ToArgb (), "SurroundColors[0]");
69                         Assert.IsTrue (pgb.Transform.IsIdentity, "Transform");
70                 }
71
72                 private void CheckPointsDefaults (PathGradientBrush pgb)
73                 {
74                         CheckDefaults (pgb);
75                         Assert.AreEqual (-16777216, pgb.CenterColor.ToArgb (), "CenterColor");
76                 }
77
78                 private void CheckPathDefaults (PathGradientBrush pgb)
79                 {
80                         CheckDefaults (pgb);
81                         Assert.AreEqual (-1, pgb.CenterColor.ToArgb (), "CenterColor");
82                 }
83
84                 [TestFixtureSetUp]
85                 public void FixtureSetUp ()
86                 {
87                         pts_2i = new Point[2] { new Point (1, 2), new Point (20, 30) };
88                         pts_2f = new PointF[2] { new PointF (1, 2), new PointF (20, 30) };
89                         empty_matrix = new Matrix ();
90                 }
91
92                 [Test]
93                 public void Constructor_GraphicsPath_Null ()
94                 {
95                         GraphicsPath gp = null;
96                         Assert.Throws<ArgumentNullException> (() => new PathGradientBrush (gp));
97                 }
98
99                 [Test]
100                 public void Constructor_GraphicsPath_Empty ()
101                 {
102                         using (GraphicsPath gp = new GraphicsPath ()) {
103                                 Assert.Throws<OutOfMemoryException> (() => new PathGradientBrush (gp));
104                         }
105                 }
106
107                 [Test]
108                 public void Constructor_GraphicsPath_SinglePoint ()
109                 {
110                         using (GraphicsPath gp = new GraphicsPath ()) {
111                                 gp.AddLines (new Point[1] { new Point (1, 1) });
112                                 // Special case - a line with a single point is valid
113                                 Assert.Throws<OutOfMemoryException> (() => new PathGradientBrush (gp));
114                         }
115                 }
116
117                 [Test]
118                 public void Constructor_GraphicsPath_Line ()
119                 {
120                         using (GraphicsPath gp = new GraphicsPath ()) {
121                                 gp.AddLines (pts_2f);
122                                 using (PathGradientBrush pgb = new PathGradientBrush (gp)) {
123                                         CheckPathDefaults (pgb);
124                                         Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
125                                 }
126                         }
127                 }
128
129                 [Test]
130                 public void Constructor_Point_Null ()
131                 {
132                         Point[] pts = null;
133                         Assert.Throws<ArgumentNullException> (() => new PathGradientBrush (pts));
134                 }
135
136                 [Test]
137                 public void Constructor_Point_Empty ()
138                 {
139                         Point[] pts = new Point [0];
140                         Assert.Throws<OutOfMemoryException> (() => new PathGradientBrush (pts));
141                 }
142
143                 [Test]
144                 public void Constructor_Point_One ()
145                 {
146                         Point[] pts = new Point[1] { new Point (1, 1) };
147                         Assert.Throws<OutOfMemoryException> (() => new PathGradientBrush (pts));
148                 }
149
150                 [Test]
151                 public void Constructor_Point_Two ()
152                 {
153                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2i)) {
154                                 CheckPointsDefaults (pgb);
155                                 Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
156                         }
157                 }
158
159                 [Test]
160                 public void Constructor_Point_WrapMode_Clamp ()
161                 {
162                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.Clamp)) {
163                                 CheckPointsDefaults (pgb);
164                                 Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
165                         }
166                 }
167
168                 [Test]
169                 public void Constructor_Point_WrapMode_Tile ()
170                 {
171                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.Tile)) {
172                                 CheckPointsDefaults (pgb);
173                                 Assert.AreEqual (WrapMode.Tile, pgb.WrapMode, "WrapMode");
174                         }
175                 }
176
177                 [Test]
178                 public void Constructor_Point_WrapMode_TileFlipX ()
179                 {
180                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.TileFlipX)) {
181                                 CheckPointsDefaults (pgb);
182                                 Assert.AreEqual (WrapMode.TileFlipX, pgb.WrapMode, "WrapMode");
183                         }
184                 }
185
186                 [Test]
187                 public void Constructor_Point_WrapMode_TileFlipY ()
188                 {
189                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.TileFlipY)) {
190                                 CheckPointsDefaults (pgb);
191                                 Assert.AreEqual (WrapMode.TileFlipY, pgb.WrapMode, "WrapMode");
192                         }
193                 }
194
195                 [Test]
196                 public void Constructor_Point_WrapMode_TileFlipXY ()
197                 {
198                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2i, WrapMode.TileFlipXY)) {
199                                 CheckPointsDefaults (pgb);
200                                 Assert.AreEqual (WrapMode.TileFlipXY, pgb.WrapMode, "WrapMode");
201                         }
202                 }
203
204                 [Test]
205                 public void Constructor_PointF_Null ()
206                 {
207                         PointF[] pts = null;
208                         Assert.Throws<ArgumentNullException> (() => new PathGradientBrush (pts));
209                 }
210
211                 [Test]
212                 public void Constructor_PointF_Empty ()
213                 {
214                         PointF[] pts = new PointF[0];
215                         Assert.Throws<OutOfMemoryException> (() => new PathGradientBrush (pts));
216                 }
217
218                 [Test]
219                 public void Constructor_PointF_One ()
220                 {
221                         PointF[] pts = new PointF[1] { new PointF (1, 1) };
222                         Assert.Throws<OutOfMemoryException> (() => new PathGradientBrush (pts));
223                 }
224
225                 [Test]
226                 public void Constructor_PointF_Two ()
227                 {
228                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f)) {
229                                 CheckPointsDefaults (pgb);
230                                 Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
231                         }
232                 }
233
234                 [Test]
235                 public void Constructor_PointF_WrapMode_Invalid ()
236                 {
237                         Assert.Throws<InvalidEnumArgumentException> (() => new PathGradientBrush (pts_2f, (WrapMode)Int32.MinValue));
238                 }
239
240                 [Test]
241                 public void Constructor_PointF_WrapMode_Clamp ()
242                 {
243                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
244                                 CheckPointsDefaults (pgb);
245                                 Assert.AreEqual (WrapMode.Clamp, pgb.WrapMode, "WrapMode");
246                         }
247                 }
248
249                 [Test]
250                 public void Constructor_PointF_WrapMode_Tile ()
251                 {
252                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Tile)) {
253                                 CheckPointsDefaults (pgb);
254                                 Assert.AreEqual (WrapMode.Tile, pgb.WrapMode, "WrapMode");
255                         }
256                 }
257
258                 [Test]
259                 public void Constructor_PointF_WrapMode_TileFlipX ()
260                 {
261                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipX)) {
262                                 CheckPointsDefaults (pgb);
263                                 Assert.AreEqual (WrapMode.TileFlipX, pgb.WrapMode, "WrapMode");
264                         }
265                 }
266
267                 [Test]
268                 public void Constructor_PointF_WrapMode_TileFlipY ()
269                 {
270                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipY)) {
271                                 CheckPointsDefaults (pgb);
272                                 Assert.AreEqual (WrapMode.TileFlipY, pgb.WrapMode, "WrapMode");
273                         }
274                 }
275
276                 [Test]
277                 public void Constructor_PointF_WrapMode_TileFlipXY ()
278                 {
279                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
280                                 CheckPointsDefaults (pgb);
281                                 Assert.AreEqual (WrapMode.TileFlipXY, pgb.WrapMode, "WrapMode");
282                         }
283                 }
284
285                 [Test]
286                 public void Blend ()
287                 {
288                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
289                                 // change not accepted - but no exception is thrown
290                                 pgb.Blend.Factors = new float[0];
291                                 Assert.AreEqual (1, pgb.Blend.Factors.Length, "Factors-0");
292                                 pgb.Blend.Factors = new float[2];
293                                 Assert.AreEqual (1, pgb.Blend.Factors.Length, "Factors-1");
294
295                                 // change not accepted - but no exception is thrown
296                                 pgb.Blend.Positions = new float[0];
297                                 Assert.AreEqual (1, pgb.Blend.Positions.Length, "Positions-0");
298                                 pgb.Blend.Positions = new float[2];
299                                 Assert.AreEqual (1, pgb.Blend.Positions.Length, "Positions-1");
300                         }
301                 }
302
303                 [Test]
304                 public void FocusScales ()
305                 {
306                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
307                                 PointF fs = new PointF (Single.MaxValue, Single.MinValue);
308                                 pgb.FocusScales = fs;
309                                 Assert.AreEqual (Single.MaxValue, pgb.FocusScales.X, "MaxValue");
310                                 Assert.AreEqual (Single.MinValue, pgb.FocusScales.Y, "MinValue");
311
312                                 fs.X = Single.NaN;
313                                 fs.Y = Single.NegativeInfinity;
314                                 pgb.FocusScales = fs;
315                                 Assert.AreEqual (Single.NaN, pgb.FocusScales.X, "NaN");
316                                 Assert.AreEqual (Single.NegativeInfinity, pgb.FocusScales.Y, "NegativeInfinity");
317                         }
318                 }
319
320                 [Test]
321                 public void CenterColor ()
322                 {
323                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
324                                 pgb.CenterColor = Color.Black;
325                                 Assert.AreEqual (Color.Black.ToArgb (), pgb.CenterColor.ToArgb (), "Black");
326                                 pgb.CenterColor = Color.Transparent;
327                                 Assert.AreEqual (Color.Transparent.ToArgb (), pgb.CenterColor.ToArgb (), "Transparent");
328                         }
329                 }
330
331                 [Test]
332                 public void CenterPoint ()
333                 {
334                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
335                                 PointF cp = new PointF (Single.MaxValue, Single.MinValue);
336                                 pgb.CenterPoint = cp;
337                                 Assert.AreEqual (Single.MaxValue, pgb.CenterPoint.X, "MaxValue");
338                                 Assert.AreEqual (Single.MinValue, pgb.CenterPoint.Y, "MinValue");
339
340                                 cp.X = Single.NaN;
341                                 cp.Y = Single.NegativeInfinity;
342                                 pgb.CenterPoint = cp;
343                                 Assert.AreEqual (Single.NaN, pgb.CenterPoint.X, "NaN");
344                                 Assert.AreEqual (Single.NegativeInfinity, pgb.CenterPoint.Y, "NegativeInfinity");
345                         }
346                 }
347
348                 [Test]
349                 public void InterpolationColors ()
350                 {
351                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
352                                 // change not accepted - but no exception is thrown
353                                 pgb.InterpolationColors.Colors = new Color[0];
354                                 Assert.AreEqual (1, pgb.InterpolationColors.Colors.Length, "Colors-0");
355                                 pgb.InterpolationColors.Colors = new Color[2];
356                                 Assert.AreEqual (1, pgb.InterpolationColors.Colors.Length, "Colors-1");
357
358                                 // change not accepted - but no exception is thrown
359                                 pgb.InterpolationColors.Positions = new float[0];
360                                 Assert.AreEqual (1, pgb.InterpolationColors.Positions.Length, "Positions-0");
361                                 pgb.InterpolationColors.Positions = new float[2];
362                                 Assert.AreEqual (1, pgb.InterpolationColors.Positions.Length, "Positions-1");
363                         }
364                 }
365
366                 [Test]
367                 public void Rectangle ()
368                 {
369                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
370                                 CheckDefaultRectangle ("Original", pgb.Rectangle);
371                                 pgb.MultiplyTransform (new Matrix (2, 0, 0, 2, 2, 2));
372                                 CheckDefaultRectangle ("Multiply", pgb.Rectangle);
373                                 pgb.ResetTransform ();
374                                 CheckDefaultRectangle ("Reset", pgb.Rectangle);
375                                 pgb.RotateTransform (90);
376                                 CheckDefaultRectangle ("Rotate", pgb.Rectangle);
377                                 pgb.ScaleTransform (4, 0.25f);
378                                 CheckDefaultRectangle ("Scale", pgb.Rectangle);
379                                 pgb.TranslateTransform (-10, -20);
380                                 CheckDefaultRectangle ("Translate", pgb.Rectangle);
381
382                                 pgb.SetBlendTriangularShape (0.5f);
383                                 CheckDefaultRectangle ("SetBlendTriangularShape", pgb.Rectangle);
384                                 pgb.SetSigmaBellShape (0.5f);
385                                 CheckDefaultRectangle ("SetSigmaBellShape", pgb.Rectangle);
386                         }
387                 }
388
389                 [Test]
390                 public void SurroundColors_Empty ()
391                 {
392                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
393                                 Assert.Throws<ArgumentException> (() => pgb.SurroundColors = new Color[0]);
394                         }
395                 }
396
397                 [Test]
398                 public void SurroundColors_2PointF ()
399                 {
400                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.TileFlipXY)) {
401                                 // default values
402                                 Assert.AreEqual (1, pgb.SurroundColors.Length, "Length-0");
403                                 Assert.AreEqual (-1, pgb.SurroundColors[0].ToArgb (), "SurroundColors-0");
404
405                                 // default can't be changed
406                                 pgb.SurroundColors[0] = Color.Gold;
407                                 Assert.AreEqual (-1, pgb.SurroundColors[0].ToArgb (), "SurroundColors-1");
408
409                                 // 2 empty color isn't valid, change isn't accepted
410                                 pgb.SurroundColors = new Color[2];
411                                 Assert.AreEqual (1, pgb.SurroundColors.Length, "Length-1");
412
413                                 pgb.SurroundColors = new Color[2] { Color.Black, Color.White };
414                                 Assert.AreEqual (2, pgb.SurroundColors.Length, "Length-2");
415                                 Assert.AreEqual (-16777216, pgb.SurroundColors[0].ToArgb (), "SurroundColors-2");
416                                 Assert.AreEqual (-1, pgb.SurroundColors[1].ToArgb (), "SurroundColors-3");
417                         }
418                 }
419
420                 [Test]
421                 public void SurroundColors_3PointsF ()
422                 {
423                         PointF[] points = new PointF[3] { new PointF (5, 50), new PointF (10, 100), new PointF (20, 75) };
424                         using (PathGradientBrush pgb = new PathGradientBrush (points)) {
425                                 // 3 empty color isn't valid, change isn't accepted
426                                 pgb.SurroundColors = new Color[3] { Color.Empty, Color.Empty, Color.Empty };
427                                 Assert.AreEqual (1, pgb.SurroundColors.Length, "Length-1");
428
429                                 pgb.SurroundColors = new Color[3] { Color.Red, Color.Green, Color.Blue };
430                                 // change not accepted - but no exception is thrown
431                                 Assert.AreEqual (3, pgb.SurroundColors.Length, "Length-1");
432                                 Assert.AreEqual (-65536, pgb.SurroundColors[0].ToArgb (), "SurroundColors-1");
433                                 Assert.AreEqual (-16744448, pgb.SurroundColors[1].ToArgb (), "SurroundColors-2");
434                                 Assert.AreEqual (-16776961, pgb.SurroundColors[2].ToArgb (), "SurroundColors-3");
435                         }
436                 }
437
438                 [Test]
439                 public void Transform_Null ()
440                 {
441                         Assert.Throws<ArgumentNullException> (() => new PathGradientBrush (pts_2f, WrapMode.Clamp).Transform = null);
442                 }
443
444                 [Test]
445                 public void Transform_Empty ()
446                 {
447                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
448                                 pgb.Transform = new Matrix ();
449                                 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity");
450                         }
451                 }
452
453                 [Test]
454                 public void Transform_NonInvertible ()
455                 {
456                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
457                                 Assert.Throws<ArgumentException> (() => pgb.Transform = new Matrix (123, 24, 82, 16, 47, 30));
458                         }
459                 }
460
461                 [Test]
462                 public void WrapMode_All ()
463                 {
464                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
465                                 foreach (WrapMode wm in Enum.GetValues (typeof (WrapMode))) {
466                                         pgb.WrapMode = wm;
467                                         Assert.AreEqual (wm, pgb.WrapMode, wm.ToString ());
468                                 }
469                         }
470                 }
471
472                 [Test]
473                 public void WrapMode_Invalid ()
474                 {
475                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
476                                 Assert.Throws<InvalidEnumArgumentException> (() => pgb.WrapMode = (WrapMode) Int32.MinValue);
477                         }
478                 }
479
480                 [Test]
481                 public void Clone ()
482                 {
483                         using (GraphicsPath gp = new GraphicsPath ()) {
484                                 gp.AddLines (pts_2f);
485                                 using (PathGradientBrush pgb = new PathGradientBrush (gp)) {
486                                         using (PathGradientBrush clone = (PathGradientBrush) pgb.Clone ()) {
487                                                 CheckPathDefaults (clone);
488                                                 Assert.AreEqual (WrapMode.Clamp, clone.WrapMode, "WrapMode");
489                                         }
490                                 }
491                         }
492                 }
493
494                 [Test]
495                 public void MultiplyTransform1_Null ()
496                 {
497                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
498                                 Assert.Throws<ArgumentNullException> (() => pgb.MultiplyTransform (null));
499                         }
500                 }
501
502                 [Test]
503                 public void MultiplyTransform2_Null ()
504                 {
505                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
506                                 Assert.Throws<ArgumentNullException> (() => pgb.MultiplyTransform (null, MatrixOrder.Append));
507                         }
508                 }
509
510                 [Test]
511                 public void MultiplyTransform2_Invalid ()
512                 {
513                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
514                                 pgb.MultiplyTransform (empty_matrix, (MatrixOrder) Int32.MinValue);
515                         }
516                 }
517
518                 [Test]
519                 public void MultiplyTransform_NonInvertible ()
520                 {
521                         using (Matrix noninvertible = new Matrix (123, 24, 82, 16, 47, 30)) {
522                                 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
523                                         Assert.Throws<ArgumentException> (() => pgb.MultiplyTransform (noninvertible));
524                                 }
525                         }
526                 }
527
528                 [Test]
529                 public void ResetTransform ()
530                 {
531                         using (Matrix m = new Matrix (2, 0, 0, 2, 10, -10)) {
532                                 using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
533                                         pgb.Transform = m;
534                                         Assert.IsFalse (pgb.Transform.IsIdentity, "Transform.IsIdentity");
535                                         pgb.ResetTransform ();
536                                         Assert.IsTrue (pgb.Transform.IsIdentity, "Reset.IsIdentity");
537                                 }
538                         }
539                 }
540
541                 [Test]
542                 public void RotateTransform ()
543                 {
544                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
545                                 pgb.RotateTransform (90);
546                                 float[] elements = pgb.Transform.Elements;
547                                 Assert.AreEqual (0, elements[0], 0.1, "matrix.0");
548                                 Assert.AreEqual (1, elements[1], 0.1, "matrix.1");
549                                 Assert.AreEqual (-1, elements[2], 0.1, "matrix.2");
550                                 Assert.AreEqual (0, elements[3], 0.1, "matrix.3");
551                                 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
552                                 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
553
554                                 pgb.RotateTransform (270);
555                                 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity");
556                         }
557                 }
558
559                 [Test]
560                 [NUnit.Framework.Category ("NotWorking")]
561                 public void RotateTransform_Max ()
562                 {
563                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
564                                 pgb.RotateTransform (Single.MaxValue);
565                                 float[] elements = pgb.Transform.Elements;
566                                 Assert.AreEqual (5.93904E+36, elements[0], 1e32, "matrix.0");
567                                 Assert.AreEqual (5.93904E+36, elements[1], 1e32, "matrix.1");
568                                 Assert.AreEqual (-5.93904E+36, elements[2], 1e32, "matrix.2");
569                                 Assert.AreEqual (5.93904E+36, elements[3], 1e32, "matrix.3");
570                                 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
571                                 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
572                         }
573                 }
574
575                 [Test]
576                 [NUnit.Framework.Category ("NotWorking")]
577                 public void RotateTransform_Min ()
578                 {
579                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
580                                 pgb.RotateTransform (Single.MinValue);
581                                 float[] elements = pgb.Transform.Elements;
582                                 Assert.AreEqual (-5.93904E+36, elements[0], 1e32, "matrix.0");
583                                 Assert.AreEqual (-5.93904E+36, elements[1], 1e32, "matrix.1");
584                                 Assert.AreEqual (5.93904E+36, elements[2], 1e32, "matrix.2");
585                                 Assert.AreEqual (-5.93904E+36, elements[3], 1e32, "matrix.3");
586                                 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
587                                 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
588                         }
589                 }
590
591                 [Test]
592                 public void RotateTransform_InvalidOrder ()
593                 {
594                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
595                                 Assert.Throws<ArgumentException> (() => pgb.RotateTransform (720, (MatrixOrder) Int32.MinValue));
596                         }
597                 }
598
599                 [Test]
600                 public void ScaleTransform ()
601                 {
602                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
603                                 pgb.ScaleTransform (2, 4);
604                                 float[] elements = pgb.Transform.Elements;
605                                 Assert.AreEqual (2, elements[0], 0.1, "matrix.0");
606                                 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
607                                 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
608                                 Assert.AreEqual (4, elements[3], 0.1, "matrix.3");
609                                 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
610                                 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
611
612                                 pgb.ScaleTransform (0.5f, 0.25f);
613                                 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity");
614                         }
615                 }
616
617                 [Test]
618                 public void ScaleTransform_MaxMin ()
619                 {
620                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
621                                 pgb.ScaleTransform (Single.MaxValue, Single.MinValue);
622                                 float[] elements = pgb.Transform.Elements;
623                                 Assert.AreEqual (Single.MaxValue, elements[0], 1e33, "matrix.0");
624                                 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
625                                 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
626                                 Assert.AreEqual (Single.MinValue, elements[3], 1e33, "matrix.3");
627                                 Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
628                                 Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
629                         }
630                 }
631
632                 [Test]
633                 public void ScaleTransform_InvalidOrder ()
634                 {
635                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
636                                 Assert.Throws<ArgumentException> (() => pgb.ScaleTransform (1, 1, (MatrixOrder) Int32.MinValue));
637                         }
638                 }
639
640                 [Test]
641                 public void SetBlendTriangularShape_Focus ()
642                 {
643                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
644                                 // max valid
645                                 pgb.SetBlendTriangularShape (1);
646                                 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
647                                 // min valid
648                                 pgb.SetBlendTriangularShape (0);
649                                 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
650                                 // middle
651                                 pgb.SetBlendTriangularShape (0.5f);
652                                 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
653                                 // no impact on matrix
654                         }
655                 }
656
657                 [Test]
658                 public void SetBlendTriangularShape_Scale ()
659                 {
660                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
661                                 // max valid
662                                 pgb.SetBlendTriangularShape (0, 1);
663                                 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
664                                 // min valid
665                                 pgb.SetBlendTriangularShape (1, 0);
666                                 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
667                                 // middle
668                                 pgb.SetBlendTriangularShape (0.5f, 0.5f);
669                                 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
670                                 // no impact on matrix
671                         }
672                 }
673
674                 [Test]
675                 public void SetBlendTriangularShape_FocusTooSmall ()
676                 {
677                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
678                                 Assert.Throws<ArgumentException> (() => pgb.SetBlendTriangularShape (-1));
679                         }
680                 }
681
682                 [Test]
683                 public void SetBlendTriangularShape_FocusTooBig ()
684                 {
685                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
686                                 Assert.Throws<ArgumentException> (() => pgb.SetBlendTriangularShape (1.01f));
687                         }
688                 }
689
690                 [Test]
691                 public void SetBlendTriangularShape_ScaleTooSmall ()
692                 {
693                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
694                                 Assert.Throws<ArgumentException> (() => pgb.SetBlendTriangularShape (1, -1));
695                         }
696                 }
697
698                 [Test]
699                 public void SetBlendTriangularShape_ScaleTooBig ()
700                 {
701                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
702                                 Assert.Throws<ArgumentException> (() => pgb.SetBlendTriangularShape (1, 1.01f));
703                         }
704                 }
705
706                 [Test]
707                 public void SetSigmaBellShape_Focus ()
708                 {
709                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
710                                 // max valid
711                                 pgb.SetSigmaBellShape (1);
712                                 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
713                                 // min valid
714                                 pgb.SetSigmaBellShape (0);
715                                 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
716                                 // middle
717                                 pgb.SetSigmaBellShape (0.5f);
718                                 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
719                                 // no impact on matrix
720                         }
721                 }
722
723                 [Test]
724                 public void SetSigmaBellShape_Scale ()
725                 {
726                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
727                                 // max valid
728                                 pgb.SetSigmaBellShape (0, 1);
729                                 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-1");
730                                 // min valid
731                                 pgb.SetSigmaBellShape (1, 0);
732                                 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-2");
733                                 // middle
734                                 pgb.SetSigmaBellShape (0.5f, 0.5f);
735                                 Assert.IsTrue (pgb.Transform.IsIdentity, "Transform.IsIdentity-3");
736                                 // no impact on matrix
737                         }
738                 }
739
740                 [Test]
741                 public void SetSigmaBellShape_FocusTooSmall ()
742                 {
743                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
744                                 Assert.Throws<ArgumentException> (() => pgb.SetSigmaBellShape (-1));
745                         }
746                 }
747
748                 [Test]
749                 public void SetSigmaBellShape_FocusTooBig ()
750                 {
751                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
752                                 Assert.Throws<ArgumentException> (() => pgb.SetSigmaBellShape (1.01f));
753                         }
754                 }
755
756                 [Test]
757                 public void SetSigmaBellShape_ScaleTooSmall ()
758                 {
759                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
760                                 Assert.Throws<ArgumentException> (() => pgb.SetSigmaBellShape (1, -1));
761                         }
762                 }
763
764                 [Test]
765                 public void SetSigmaBellShape_ScaleTooBig ()
766                 {
767                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
768                                 Assert.Throws<ArgumentException> (() => pgb.SetSigmaBellShape (1, 1.01f));
769                         }
770                 }
771
772                 [Test]
773                 public void TranslateTransform ()
774                 {
775                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
776                                 pgb.TranslateTransform (1, 1);
777                                 float[] elements = pgb.Transform.Elements;
778                                 Assert.AreEqual (1, elements[0], 0.1, "matrix.0");
779                                 Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
780                                 Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
781                                 Assert.AreEqual (1, elements[3], 0.1, "matrix.3");
782                                 Assert.AreEqual (1, elements[4], 0.1, "matrix.4");
783                                 Assert.AreEqual (1, elements[5], 0.1, "matrix.5");
784
785                                 pgb.TranslateTransform (-1, -1);
786                                 // strangely lgb.Transform.IsIdentity is false
787                                 elements = pgb.Transform.Elements;
788                                 Assert.AreEqual (1, elements[0], 0.1, "revert.matrix.0");
789                                 Assert.AreEqual (0, elements[1], 0.1, "revert.matrix.1");
790                                 Assert.AreEqual (0, elements[2], 0.1, "revert.matrix.2");
791                                 Assert.AreEqual (1, elements[3], 0.1, "revert.matrix.3");
792                                 Assert.AreEqual (0, elements[4], 0.1, "revert.matrix.4");
793                                 Assert.AreEqual (0, elements[5], 0.1, "revert.matrix.5");
794                         }
795                 }
796
797                 [Test]
798                 public void TranslateTransform_InvalidOrder ()
799                 {
800                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
801                                 Assert.Throws<ArgumentException> (() => pgb.TranslateTransform (1, 1, (MatrixOrder) Int32.MinValue));
802                         }
803                 }
804
805                 [Test]
806                 public void Transform_Operations ()
807                 {
808                         using (PathGradientBrush pgb = new PathGradientBrush (pts_2f, WrapMode.Clamp)) {
809                                 Matrix clone = pgb.Transform.Clone ();
810                                 Matrix mul = clone.Clone ();
811
812                                 clone.Multiply (mul, MatrixOrder.Append);
813                                 pgb.MultiplyTransform (mul, MatrixOrder.Append);
814                                 Assert.AreEqual (pgb.Transform, clone, "Multiply/Append");
815
816                                 clone.Multiply (mul, MatrixOrder.Prepend);
817                                 pgb.MultiplyTransform (mul, MatrixOrder.Prepend);
818                                 Assert.AreEqual (pgb.Transform, clone, "Multiply/Prepend");
819
820                                 clone.Rotate (45, MatrixOrder.Append);
821                                 pgb.RotateTransform (45, MatrixOrder.Append);
822                                 Assert.AreEqual (pgb.Transform, clone, "Rotate/Append");
823
824                                 clone.Rotate (45, MatrixOrder.Prepend);
825                                 pgb.RotateTransform (45, MatrixOrder.Prepend);
826                                 Assert.AreEqual (pgb.Transform, clone, "Rotate/Prepend");
827
828                                 clone.Scale (0.25f, 2, MatrixOrder.Append);
829                                 pgb.ScaleTransform (0.25f, 2, MatrixOrder.Append);
830                                 Assert.AreEqual (pgb.Transform, clone, "Scale/Append");
831
832                                 clone.Scale (0.25f, 2, MatrixOrder.Prepend);
833                                 pgb.ScaleTransform (0.25f, 2, MatrixOrder.Prepend);
834                                 Assert.AreEqual (pgb.Transform, clone, "Scale/Prepend");
835
836                                 clone.Translate (10, 20, MatrixOrder.Append);
837                                 pgb.TranslateTransform (10, 20, MatrixOrder.Append);
838                                 Assert.AreEqual (pgb.Transform, clone, "Translate/Append");
839
840                                 clone.Translate (30, 40, MatrixOrder.Prepend);
841                                 pgb.TranslateTransform (30, 40, MatrixOrder.Prepend);
842                                 Assert.AreEqual (pgb.Transform, clone, "Translate/Prepend");
843
844                                 clone.Reset ();
845                                 pgb.ResetTransform ();
846                                 Assert.AreEqual (pgb.Transform, clone, "Reset");
847                         }
848                 }
849
850                 [Test]
851                 public void Blend_Null ()
852                 {
853                         using (GraphicsPath gp = new GraphicsPath ()) {
854                                 gp.AddLines (pts_2f);
855                                 using (PathGradientBrush pgb = new PathGradientBrush (gp)) {
856                                         Assert.Throws<NullReferenceException> (() => pgb.Blend = null);
857                                 }
858                         }
859                 }
860
861                 [Test]
862                 public void InterpolationColors_Null ()
863                 {
864                         using (GraphicsPath gp = new GraphicsPath ()) {
865                                 gp.AddLines (pts_2f);
866                                 using (PathGradientBrush pgb = new PathGradientBrush (gp)) {
867                                         Assert.Throws<NullReferenceException> (() => pgb.InterpolationColors = null);
868                                 }
869                         }
870                 }
871
872                 [Test]
873                 public void SurroundColors_Null ()
874                 {
875                         using (GraphicsPath gp = new GraphicsPath ()) {
876                                 gp.AddLines (pts_2f);
877                                 using (PathGradientBrush pgb = new PathGradientBrush (gp)) {
878                                         Assert.Throws<NullReferenceException> (() => pgb.SurroundColors = null);
879                                 }
880                         }
881                 }
882         }
883 }