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