ffe43baaf86bdf10cd476cccb24a0b04745e53b2
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing.Drawing2D / TestColorBlend.cs
1 //
2 // Tests for System.Drawing.Drawing2D.ColorBlend.cs
3 //
4 // Authors:
5 //      Ravindra (rkumar@novell.com)
6 //      Sebastien Pouliot  <sebastien@ximian.com>
7 //
8 // Copyright (C) 2004,2006 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 using NUnit.Framework;
31 using System;
32 using System.Drawing;
33 using System.Drawing.Drawing2D;
34 using System.Security.Permissions;
35
36 namespace MonoTests.System.Drawing.Drawing2D 
37 {
38         [TestFixture]   
39         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
40         public class ColorBlendTest {
41
42                 [Test]
43                 public void TestConstructors ()
44                 {
45                         ColorBlend cb1 = new ColorBlend (1);
46                         Assert.AreEqual (1, cb1.Colors.Length, "Colors");
47                         Assert.AreEqual (1, cb1.Positions.Length, "Positions");
48                 }
49
50                 [Test]
51                 public void TestProperties () 
52                 {
53                         ColorBlend cb1 = new ColorBlend (1);
54                         float[] positions = {0.0F, 0.5F, 1.0F};
55                         Color[] colors = {Color.Red, Color.White, Color.Black};
56                         cb1.Colors = colors;
57                         cb1.Positions = positions;
58
59                         // size match
60                         Assert.AreEqual (colors[0], cb1.Colors[0], "c0");
61                         Assert.AreEqual (colors[1], cb1.Colors[1], "c1");
62                         Assert.AreEqual (colors[2], cb1.Colors[2], "c2");
63                         Assert.AreEqual (positions[0], cb1.Positions[0], "p0");
64                         Assert.AreEqual (positions[1], cb1.Positions[1], "p1");
65                         Assert.AreEqual (positions[2], cb1.Positions[2], "p2");
66                 }
67
68                 [Test]
69                 public void ColorBlend_Empty ()
70                 {
71                         ColorBlend cb = new ColorBlend ();
72                         Assert.AreEqual (1, cb.Colors.Length, "Colors");
73                         Assert.IsTrue (cb.Colors[0].IsEmpty, "C0");
74                         Assert.AreEqual (1, cb.Positions.Length, "Positions");
75                         Assert.AreEqual (0f, cb.Positions[0], "P0");
76                 }
77
78                 [Test]
79                 public void ColorBlend_Zero ()
80                 {
81                         ColorBlend cb = new ColorBlend (0);
82                         Assert.AreEqual (0, cb.Colors.Length, "Colors");
83                         Assert.AreEqual (0, cb.Positions.Length, "Positions");
84                 }
85
86                 [Test]
87                 public void MismatchSizes ()
88                 {
89                         ColorBlend cb = new ColorBlend ();
90
91                         cb.Colors = new Color[16];
92                         Assert.AreEqual (16, cb.Colors.Length, "Colors");
93
94                         cb.Positions = new float[1];
95                         Assert.AreEqual (1, cb.Positions.Length, "Positions");
96                 }
97
98                 [Test]
99                 [ExpectedException (typeof (OverflowException))]
100                 public void ColorBlend_Negative ()
101                 {
102                         ColorBlend cb = new ColorBlend (-1);
103                 }
104
105                 [Test]
106                 public void ColorBlend_Lots ()
107                 {
108                         ColorBlend cb = new ColorBlend (1000);
109                         Assert.AreEqual (1000, cb.Colors.Length, "Colors");
110                         Assert.AreEqual (1000, cb.Positions.Length, "Positions");
111                 }
112         }
113 }