2006-03-30 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing.Drawing2D / LinearGradientBrushTest.cs
1 //
2 // System.Drawing.Drawing2D.LinearGradientBrush 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         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
40         public class LinearGradientBrushTest {
41
42                 private Point pt1;
43                 private Point pt2;
44                 private Color c1;
45                 private Color c2;
46                 private LinearGradientBrush default_brush;
47                 private Matrix empty_matrix;
48                 private RectangleF rect;
49
50                 [TestFixtureSetUp]
51                 public void FixtureSetUp ()
52                 {
53                         pt1 = new Point (0, 0);
54                         pt2 = new Point (32, 32);
55                         c1 = Color.Blue;
56                         c2 = Color.Red;
57                         default_brush = new LinearGradientBrush (pt1, pt2, c1, c2);
58                         empty_matrix = new Matrix ();
59                         rect = new RectangleF (0, 0, 32, 32);
60                 }
61
62                 private void CheckDefaultRectangle (string msg, RectangleF rect)
63                 {
64                         Assert.AreEqual (pt1.X, rect.X, msg + ".Rectangle.X");
65                         Assert.AreEqual (pt1.Y, rect.Y, msg + ".Rectangle.Y");
66                         Assert.AreEqual (pt2.X, rect.Width, msg + ".Rectangle.Width");
67                         Assert.AreEqual (pt2.Y, rect.Height, msg + ".Rectangle.Height");
68                 }
69
70                 private void CheckDefaultMatrix (Matrix matrix)
71                 {
72                         float[] elements = matrix.Elements;
73                         Assert.AreEqual (1, elements[0], 0.1, "matrix.0");
74                         Assert.AreEqual (1, elements[1], 0.1, "matrix.1");
75                         Assert.AreEqual (-1, elements[2], 0.1, "matrix.2");
76                         Assert.AreEqual (1, elements[3], 0.1, "matrix.3");
77                         Assert.AreEqual (16, elements[4], "matrix.4");
78                         Assert.AreEqual (-16, elements[5], "matrix.5");
79                 }
80
81                 private void CheckBrushAt45 (LinearGradientBrush lgb)
82                 {
83                         CheckDefaultRectangle ("4", lgb.Rectangle);
84                         Assert.AreEqual (1, lgb.Blend.Factors.Length, "Blend.Factors");
85                         Assert.AreEqual (1, lgb.Blend.Factors[0], "Blend.Factors [0]");
86                         Assert.AreEqual (1, lgb.Blend.Positions.Length, "Blend.Positions");
87                         // lgb.Blend.Positions [0] is always small (e-39) but never quite the same
88                         Assert.IsFalse (lgb.GammaCorrection, "GammaCorrection");
89                         Assert.AreEqual (2, lgb.LinearColors.Length, "LinearColors");
90                         Assert.IsNotNull (lgb.Transform, "Transform");
91                         CheckDefaultMatrix (lgb.Transform);
92                 }
93
94                 [Test]
95                 [NUnit.Framework.Category ("NotWorking")]
96                 public void Constructor_Point_Point_Color_Color ()
97                 {
98                         LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
99                         CheckBrushAt45 (lgb);
100
101                         Assert.AreEqual (WrapMode.Tile, lgb.WrapMode, "WrapMode.Tile");
102                         lgb.WrapMode = WrapMode.TileFlipX;
103                         Assert.AreEqual (WrapMode.TileFlipX, lgb.WrapMode, "WrapMode.TileFlipX");
104                         lgb.WrapMode = WrapMode.TileFlipY;
105                         Assert.AreEqual (WrapMode.TileFlipY, lgb.WrapMode, "WrapMode.TileFlipY");
106                         lgb.WrapMode = WrapMode.TileFlipXY;
107                         Assert.AreEqual (WrapMode.TileFlipXY, lgb.WrapMode, "WrapMode.TileFlipXY");
108                         // can't set WrapMode.Clamp
109                 }
110
111                 [Test]
112                 public void Constructor_RectangleF_Color_Color_Single_0 ()
113                 {
114                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
115                         Assert.AreEqual (1, lgb.Blend.Factors.Length, "Blend.Factors");
116                         Assert.AreEqual (1, lgb.Blend.Factors[0], "Blend.Factors[0]");
117                         Assert.AreEqual (1, lgb.Blend.Positions.Length, "Blend.Positions");
118                         // lgb.Blend.Positions [0] is always small (e-39) but never quite the same
119                         Assert.IsFalse (lgb.GammaCorrection, "GammaCorrection");
120                         Assert.AreEqual (c1.ToArgb (), lgb.LinearColors[0].ToArgb (), "LinearColors[0]");
121                         Assert.AreEqual (c2.ToArgb (), lgb.LinearColors[1].ToArgb (), "LinearColors[1]");
122                         Assert.AreEqual (rect, lgb.Rectangle, "Rectangle");
123                         Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity");
124                         Assert.AreEqual (WrapMode.Tile, lgb.WrapMode, "WrapMode");
125
126                         Matrix matrix = new Matrix (2, -1, 1, 2, 10, 10);
127                         lgb.Transform = matrix;
128                         Assert.AreEqual (matrix, lgb.Transform, "Transform");
129                 }
130
131                 [Test]
132                 [NUnit.Framework.Category ("NotWorking")]
133                 public void Constructor_RectangleF_Color_Color_Single_22_5 ()
134                 {
135                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 22.5f);
136                         float[] elements = lgb.Transform.Elements;
137                         Assert.AreEqual (1.207107, elements[0], 0.0001, "matrix.0");
138                         Assert.AreEqual (0.5, elements[1], 0.0001, "matrix.1");
139                         Assert.AreEqual (-0.5, elements[2], 0.0001, "matrix.2");
140                         Assert.AreEqual (1.207107, elements[3], 0.0001, "matrix.3");
141                         Assert.AreEqual (4.686291, elements[4], 0.0001, "matrix.4");
142                         Assert.AreEqual (-11.313709, elements[5], 0.0001, "matrix.5");
143                 }
144
145                 [Test]
146                 [NUnit.Framework.Category ("NotWorking")]
147                 public void Constructor_RectangleF_Color_Color_Single_45 ()
148                 {
149                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 45f);
150                         CheckBrushAt45 (lgb);
151                 }
152
153                 [Test]
154                 [NUnit.Framework.Category ("NotWorking")]
155                 public void Constructor_RectangleF_Color_Color_Single_90 ()
156                 {
157                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 90f);
158                         float[] elements = lgb.Transform.Elements;
159                         Assert.AreEqual (0, elements[0], 0.0001, "matrix.0");
160                         Assert.AreEqual (1, elements[1], 0.0001, "matrix.1");
161                         Assert.AreEqual (-1, elements[2], 0.0001, "matrix.2");
162                         Assert.AreEqual (0, elements[3], 0.0001, "matrix.3");
163                         Assert.AreEqual (32, elements[4], 0.0001, "matrix.4");
164                         Assert.AreEqual (0, elements[5], 0.0001, "matrix.5");
165                 }
166
167                 [Test]
168                 [NUnit.Framework.Category ("NotWorking")]
169                 public void Constructor_RectangleF_Color_Color_Single_135 ()
170                 {
171                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 135f);
172                         float[] elements = lgb.Transform.Elements;
173                         Assert.AreEqual (-1, elements[0], 0.0001, "matrix.0");
174                         Assert.AreEqual (1, elements[1], 0.0001, "matrix.1");
175                         Assert.AreEqual (-1, elements[2], 0.0001, "matrix.2");
176                         Assert.AreEqual (-1, elements[3], 0.0001, "matrix.3");
177                         Assert.AreEqual (48, elements[4], 0.0001, "matrix.4");
178                         Assert.AreEqual (16, elements[5], 0.0001, "matrix.5");
179                 }
180
181                 [Test]
182                 [NUnit.Framework.Category ("NotWorking")]
183                 public void Constructor_RectangleF_Color_Color_Single_180 ()
184                 {
185                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 180f);
186                         float[] elements = lgb.Transform.Elements;
187                         Assert.AreEqual (-1, elements[0], 0.0001, "matrix.0");
188                         Assert.AreEqual (0, elements[1], 0.0001, "matrix.1");
189                         Assert.AreEqual (0, elements[2], 0.0001, "matrix.2");
190                         Assert.AreEqual (-1, elements[3], 0.0001, "matrix.3");
191                         Assert.AreEqual (32, elements[4], 0.0001, "matrix.4");
192                         Assert.AreEqual (32, elements[5], 0.0001, "matrix.5");
193                 }
194
195                 [Test]
196                 [NUnit.Framework.Category ("NotWorking")]
197                 public void Constructor_RectangleF_Color_Color_Single_270 ()
198                 {
199                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 270f);
200                         float[] elements = lgb.Transform.Elements;
201                         Assert.AreEqual (0, elements[0], 0.0001, "matrix.0");
202                         Assert.AreEqual (-1, elements[1], 0.0001, "matrix.1");
203                         Assert.AreEqual (1, elements[2], 0.0001, "matrix.2");
204                         Assert.AreEqual (0, elements[3], 0.0001, "matrix.3");
205                         Assert.AreEqual (0, elements[4], 0.0001, "matrix.4");
206                         Assert.AreEqual (32, elements[5], 0.0001, "matrix.5");
207                 }
208
209                 [Test]
210                 [NUnit.Framework.Category ("NotWorking")]
211                 public void Constructor_RectangleF_Color_Color_Single_315 ()
212                 {
213                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 315f);
214                         float[] elements = lgb.Transform.Elements;
215                         Assert.AreEqual (1, elements[0], 0.0001, "matrix.0");
216                         Assert.AreEqual (-1, elements[1], 0.0001, "matrix.1");
217                         Assert.AreEqual (1, elements[2], 0.0001, "matrix.2");
218                         Assert.AreEqual (1, elements[3], 0.0001, "matrix.3");
219                         Assert.AreEqual (-16, elements[4], 0.0001, "matrix.4");
220                         Assert.AreEqual (16, elements[5], 0.0001, "matrix.5");
221                 }
222
223                 [Test]
224                 public void Constructor_RectangleF_Color_Color_Single_360()
225                 {
226                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 360f);
227                         float[] elements = lgb.Transform.Elements;
228                         // just like 0'
229                         Assert.AreEqual (1, elements[0], 0.0001, "matrix.0");
230                         Assert.AreEqual (0, elements[1], 0.0001, "matrix.1");
231                         Assert.AreEqual (0, elements[2], 0.0001, "matrix.2");
232                         Assert.AreEqual (1, elements[3], 0.0001, "matrix.3");
233                         Assert.AreEqual (0, elements[4], 0.0001, "matrix.4");
234                         Assert.AreEqual (0, elements[5], 0.0001, "matrix.5");
235                 }
236
237                 [Test]
238                 [NUnit.Framework.Category ("NotWorking")]
239                 public void Constructor_RectangleF_Color_Color_Single_540 ()
240                 {
241                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 540f);
242                         float[] elements = lgb.Transform.Elements;
243                         // just like 180'
244                         Assert.AreEqual (-1, elements[0], 0.0001, "matrix.0");
245                         Assert.AreEqual (0, elements[1], 0.0001, "matrix.1");
246                         Assert.AreEqual (0, elements[2], 0.0001, "matrix.2");
247                         Assert.AreEqual (-1, elements[3], 0.0001, "matrix.3");
248                         Assert.AreEqual (32, elements[4], 0.0001, "matrix.4");
249                         Assert.AreEqual (32, elements[5], 0.0001, "matrix.5");
250                 }
251
252                 [Test]
253                 [ExpectedException (typeof (ArgumentException))]
254                 public void InterpolationColors_Colors_InvalidBlend ()
255                 {
256                         // default Blend doesn't allow getting this property
257                         Assert.IsNotNull (default_brush.InterpolationColors.Colors);
258                 }
259
260                 [Test]
261                 [ExpectedException (typeof (ArgumentException))]
262                 public void InterpolationColors_Positions_InvalidBlend ()
263                 {
264                         // default Blend doesn't allow getting this property
265                         Assert.IsNotNull (default_brush.InterpolationColors.Positions);
266                 }
267
268                 [Test]
269                 [ExpectedException (typeof (IndexOutOfRangeException))]
270                 public void LinearColors_Empty ()
271                 {
272                         default_brush.LinearColors = new Color[0];
273                 }
274
275                 [Test]
276                 [ExpectedException (typeof (IndexOutOfRangeException))]
277                 public void LinearColors_One ()
278                 {
279                         default_brush.LinearColors = new Color[1];
280                 }
281
282                 [Test]
283                 public void LinearColors_Two ()
284                 {
285                         Assert.AreEqual (Color.FromArgb (255, 0, 0, 255), default_brush.LinearColors[0], "0");
286                         Assert.AreEqual (Color.FromArgb (255, 255, 0, 0), default_brush.LinearColors[1], "1");
287
288                         LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
289                         lgb.LinearColors = new Color[2] { Color.Black, Color.White };
290                         // not the same, the alpha is changed to 255 so they can't compare
291                         Assert.AreEqual (Color.FromArgb (255, 0, 0, 0), lgb.LinearColors[0], "0");
292                         Assert.AreEqual (Color.FromArgb (255, 255, 255, 255), lgb.LinearColors[1], "1");
293                 }
294
295                 [Test]
296                 public void LinearColors_Three ()
297                 {
298                         LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
299                         lgb.LinearColors = new Color[3] { Color.Red, Color.Green, Color.Blue };
300                         // not the same, the alpha is changed to 255 so they can't compare
301                         Assert.AreEqual (Color.FromArgb (255, 255, 0, 0), lgb.LinearColors[0], "0");
302                         Assert.AreEqual (Color.FromArgb (255, 0, 128, 0), lgb.LinearColors[1], "1");
303                 }
304
305                 [Test]
306                 [ExpectedException (typeof (ArgumentNullException))]
307                 public void Transform_Null ()
308                 {
309                         default_brush.Transform = null;
310                 }
311
312                 [Test]
313                 public void Transform_Empty ()
314                 {
315                         LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
316                         lgb.Transform = new Matrix ();
317                         Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity");
318                 }
319
320                 [Test]
321                 [ExpectedException (typeof (ArgumentException))]
322                 public void Transform_NonInvertible ()
323                 {
324                         default_brush.Transform = new Matrix (123, 24, 82, 16, 47, 30);
325                 }
326
327                 [Test]
328                 public void WrapMode_AllValid ()
329                 {
330                         LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
331                         lgb.WrapMode = WrapMode.Tile;
332                         Assert.AreEqual (WrapMode.Tile, lgb.WrapMode, "WrapMode.Tile");
333                         lgb.WrapMode = WrapMode.TileFlipX;
334                         Assert.AreEqual (WrapMode.TileFlipX, lgb.WrapMode, "WrapMode.TileFlipX");
335                         lgb.WrapMode = WrapMode.TileFlipY;
336                         Assert.AreEqual (WrapMode.TileFlipY, lgb.WrapMode, "WrapMode.TileFlipY");
337                         lgb.WrapMode = WrapMode.TileFlipXY;
338                         Assert.AreEqual (WrapMode.TileFlipXY, lgb.WrapMode, "WrapMode.TileFlipXY");
339                 }
340
341                 [Test]
342                 [ExpectedException (typeof (ArgumentException))]
343                 public void WrapMode_Clamp ()
344                 {
345                         default_brush.WrapMode = WrapMode.Clamp;
346                 }
347
348                 [Test]
349                 [ExpectedException (typeof (InvalidEnumArgumentException))]
350                 public void WrapMode_Invalid ()
351                 {
352                         default_brush.WrapMode = (WrapMode) Int32.MinValue;
353                 }
354
355
356                 [Test]
357                 public void Clone ()
358                 {
359                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
360                         LinearGradientBrush clone = (LinearGradientBrush) lgb.Clone ();
361                         Assert.AreEqual (lgb.Blend.Factors.Length, clone.Blend.Factors.Length, "Blend.Factors.Length");
362                         Assert.AreEqual (lgb.Blend.Positions.Length, clone.Blend.Positions.Length, "Blend.Positions.Length");
363                         Assert.AreEqual (lgb.GammaCorrection, clone.GammaCorrection, "GammaCorrection");
364                         Assert.AreEqual (lgb.LinearColors.Length, clone.LinearColors.Length, "LinearColors.Length");
365                         Assert.AreEqual (lgb.LinearColors.Length, clone.LinearColors.Length, "LinearColors.Length");
366                         Assert.AreEqual (lgb.Rectangle, clone.Rectangle, "Rectangle");
367                         Assert.AreEqual (lgb.Transform, clone.Transform, "Transform");
368                         Assert.AreEqual (lgb.WrapMode, clone.WrapMode, "WrapMode");
369                 }
370
371                 [Test]
372                 [ExpectedException (typeof (ArgumentNullException))]
373                 public void MultiplyTransform1_Null ()
374                 {
375                         default_brush.MultiplyTransform (null);
376                 }
377
378                 [Test]
379                 [ExpectedException (typeof (ArgumentNullException))]
380                 public void MultiplyTransform2_Null ()
381                 {
382                         default_brush.MultiplyTransform (null, MatrixOrder.Append);
383                 }
384
385                 [Test]
386                 public void MultiplyTransform2_Invalid ()
387                 {
388                         default_brush.MultiplyTransform (empty_matrix, (MatrixOrder) Int32.MinValue);
389                 }
390
391                 [Test]
392                 [NUnit.Framework.Category ("NotWorking")]
393                 public void ResetTransform ()
394                 {
395                         LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
396                         Assert.IsFalse (lgb.Transform.IsIdentity, "Transform.IsIdentity");
397                         lgb.ResetTransform ();
398                         Assert.IsTrue (lgb.Transform.IsIdentity, "Reset.IsIdentity");
399                 }
400
401                 [Test]
402                 [NUnit.Framework.Category ("NotWorking")]
403                 public void RotateTransform ()
404                 {
405                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
406                         lgb.RotateTransform (90);
407                         float[] elements = lgb.Transform.Elements;
408                         Assert.AreEqual (0, elements[0], 0.1, "matrix.0");
409                         Assert.AreEqual (1, elements[1], 0.1, "matrix.1");
410                         Assert.AreEqual (-1, elements[2], 0.1, "matrix.2");
411                         Assert.AreEqual (0, elements[3], 0.1, "matrix.3");
412                         Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
413                         Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
414
415                         lgb.RotateTransform (270);
416                         Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity");
417                 }
418
419                 [Test]
420                 [NUnit.Framework.Category ("NotWorking")]
421                 public void RotateTransform_Max ()
422                 {
423                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
424                         lgb.RotateTransform (Single.MaxValue);
425                         float[] elements = lgb.Transform.Elements;
426                         Assert.AreEqual (5.93904E+36, elements[0], 1e32, "matrix.0");
427                         Assert.AreEqual (5.93904E+36, elements[1], 1e32, "matrix.1");
428                         Assert.AreEqual (-5.93904E+36, elements[2], 1e32, "matrix.2");
429                         Assert.AreEqual (5.93904E+36, elements[3], 1e32, "matrix.3");
430                         Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
431                         Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
432                 }
433
434                 [Test]
435                 [NUnit.Framework.Category ("NotWorking")]
436                 public void RotateTransform_Min ()
437                 {
438                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
439                         lgb.RotateTransform (Single.MinValue);
440                         float[] elements = lgb.Transform.Elements;
441                         Assert.AreEqual (-5.93904E+36, elements[0], 1e32, "matrix.0");
442                         Assert.AreEqual (-5.93904E+36, elements[1], 1e32, "matrix.1");
443                         Assert.AreEqual (5.93904E+36, elements[2], 1e32, "matrix.2");
444                         Assert.AreEqual (-5.93904E+36, elements[3], 1e32, "matrix.3");
445                         Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
446                         Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
447                 }
448
449                 [Test]
450                 [ExpectedException (typeof (ArgumentException))]
451                 public void RotateTransform_InvalidOrder ()
452                 {
453                         LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
454                         lgb.RotateTransform (720, (MatrixOrder) Int32.MinValue);
455                 }
456
457                 [Test]
458                 public void ScaleTransform ()
459                 {
460                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
461                         lgb.ScaleTransform (2, 4);
462                         float[] elements = lgb.Transform.Elements;
463                         Assert.AreEqual (2, elements[0], 0.1, "matrix.0");
464                         Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
465                         Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
466                         Assert.AreEqual (4, elements[3], 0.1, "matrix.3");
467                         Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
468                         Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
469
470                         lgb.ScaleTransform (0.5f, 0.25f);
471                         Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity");
472                 }
473
474                 [Test]
475                 public void ScaleTransform_MaxMin ()
476                 {
477                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
478                         lgb.ScaleTransform (Single.MaxValue, Single.MinValue);
479                         float[] elements = lgb.Transform.Elements;
480                         Assert.AreEqual (Single.MaxValue, elements[0], 1e33, "matrix.0");
481                         Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
482                         Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
483                         Assert.AreEqual (Single.MinValue, elements[3], 1e33, "matrix.3");
484                         Assert.AreEqual (0, elements[4], 0.1, "matrix.4");
485                         Assert.AreEqual (0, elements[5], 0.1, "matrix.5");
486                 }
487
488                 [Test]
489                 [ExpectedException (typeof (ArgumentException))]
490                 public void ScaleTransform_InvalidOrder ()
491                 {
492                         LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
493                         lgb.ScaleTransform (1, 1, (MatrixOrder) Int32.MinValue);
494                 }
495
496                 [Test]
497                 public void SetBlendTriangularShape_Focus ()
498                 {
499                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
500                         // max valid
501                         lgb.SetBlendTriangularShape (1);
502                         Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
503                         // min valid
504                         lgb.SetBlendTriangularShape (0);
505                         Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
506                         // middle
507                         lgb.SetBlendTriangularShape (0.5f);
508                         Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
509                         // no impact on matrix
510                 }
511
512                 [Test]
513                 public void SetBlendTriangularShape_Scale ()
514                 {
515                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
516                         // max valid
517                         lgb.SetBlendTriangularShape (0, 1);
518                         Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
519                         // min valid
520                         lgb.SetBlendTriangularShape (1, 0);
521                         Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
522                         // middle
523                         lgb.SetBlendTriangularShape (0.5f, 0.5f);
524                         Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
525                         // no impact on matrix
526                 }
527
528                 [Test]
529                 [ExpectedException (typeof (ArgumentException))]
530                 public void SetBlendTriangularShape_FocusTooSmall ()
531                 {
532                         default_brush.SetBlendTriangularShape (-1);
533                 }
534
535                 [Test]
536                 [ExpectedException (typeof (ArgumentException))]
537                 public void SetBlendTriangularShape_FocusTooBig ()
538                 {
539                         default_brush.SetBlendTriangularShape (1.01f);
540                 }
541
542                 [Test]
543                 [ExpectedException (typeof (ArgumentException))]
544                 public void SetBlendTriangularShape_ScaleTooSmall ()
545                 {
546                         default_brush.SetBlendTriangularShape (1, -1);
547                 }
548
549                 [Test]
550                 [ExpectedException (typeof (ArgumentException))]
551                 public void SetBlendTriangularShape_ScaleTooBig ()
552                 {
553                         default_brush.SetBlendTriangularShape (1, 1.01f);
554                 }
555
556                 [Test]
557                 public void SetSigmaBellShape_Focus ()
558                 {
559                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
560                         // max valid
561                         lgb.SetSigmaBellShape (1);
562                         Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
563                         // min valid
564                         lgb.SetSigmaBellShape (0);
565                         Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
566                         // middle
567                         lgb.SetSigmaBellShape (0.5f);
568                         Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
569                         // no impact on matrix
570                 }
571
572                 [Test]
573                 public void SetSigmaBellShape_Scale ()
574                 {
575                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
576                         // max valid
577                         lgb.SetSigmaBellShape (0, 1);
578                         Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-1");
579                         // min valid
580                         lgb.SetSigmaBellShape (1, 0);
581                         Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-2");
582                         // middle
583                         lgb.SetSigmaBellShape (0.5f, 0.5f);
584                         Assert.IsTrue (lgb.Transform.IsIdentity, "Transform.IsIdentity-3");
585                         // no impact on matrix
586                 }
587
588                 [Test]
589                 [ExpectedException (typeof (ArgumentException))]
590                 public void SetSigmaBellShape_FocusTooSmall ()
591                 {
592                         default_brush.SetSigmaBellShape (-1);
593                 }
594
595                 [Test]
596                 [ExpectedException (typeof (ArgumentException))]
597                 public void SetSigmaBellShape_FocusTooBig ()
598                 {
599                         default_brush.SetSigmaBellShape (1.01f);
600                 }
601
602                 [Test]
603                 [ExpectedException (typeof (ArgumentException))]
604                 public void SetSigmaBellShape_ScaleTooSmall ()
605                 {
606                         default_brush.SetSigmaBellShape (1, -1);
607                 }
608
609                 [Test]
610                 [ExpectedException (typeof (ArgumentException))]
611                 public void SetSigmaBellShape_ScaleTooBig ()
612                 {
613                         default_brush.SetSigmaBellShape (1, 1.01f);
614                 }
615
616                 [Test]
617                 public void TranslateTransform ()
618                 {
619                         LinearGradientBrush lgb = new LinearGradientBrush (rect, c1, c2, 0f);
620                         lgb.TranslateTransform (1, 1);
621                         float[] elements = lgb.Transform.Elements;
622                         Assert.AreEqual (1, elements[0], 0.1, "matrix.0");
623                         Assert.AreEqual (0, elements[1], 0.1, "matrix.1");
624                         Assert.AreEqual (0, elements[2], 0.1, "matrix.2");
625                         Assert.AreEqual (1, elements[3], 0.1, "matrix.3");
626                         Assert.AreEqual (1, elements[4], 0.1, "matrix.4");
627                         Assert.AreEqual (1, elements[5], 0.1, "matrix.5");
628
629                         lgb.TranslateTransform (-1, -1);
630                         // strangely lgb.Transform.IsIdentity is false
631                         elements = lgb.Transform.Elements;
632                         Assert.AreEqual (1, elements[0], 0.1, "revert.matrix.0");
633                         Assert.AreEqual (0, elements[1], 0.1, "revert.matrix.1");
634                         Assert.AreEqual (0, elements[2], 0.1, "revert.matrix.2");
635                         Assert.AreEqual (1, elements[3], 0.1, "revert.matrix.3");
636                         Assert.AreEqual (0, elements[4], 0.1, "revert.matrix.4");
637                         Assert.AreEqual (0, elements[5], 0.1, "revert.matrix.5");
638                 }
639
640                 [Test]
641                 [ExpectedException (typeof (ArgumentException))]
642                 public void TranslateTransform_InvalidOrder ()
643                 {
644                         LinearGradientBrush lgb = new LinearGradientBrush (pt1, pt2, c1, c2);
645                         lgb.TranslateTransform (1, 1, (MatrixOrder) Int32.MinValue);
646                 }
647         }
648 }