* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Drawing / Test / DrawingTest / Test / Colors.cs
1 using System;\r
2 using System.Drawing;\r
3 using System.Drawing.Drawing2D;\r
4 using NUnit.Framework;\r
5 using System.Reflection;\r
6 \r
7 namespace Test.Sys.Drawing\r
8 {\r
9         /// <summary>\r
10         /// Summary description for Pens.\r
11         /// </summary>\r
12         \r
13         [TestFixture]\r
14         public class ColorsFixture\r
15         {\r
16 \r
17                 [SetUp]\r
18                 public void SetUp () \r
19                 {\r
20                 }\r
21 \r
22                 #region names array\r
23                 private string [] ar_colors = {\r
24                                                                                   "Transparent,0,255,255,255,1,0,0",\r
25                                                                                   "AliceBlue,255,240,248,255,0.9705882,208,1",\r
26                                                                                   "AntiqueWhite,255,250,235,215,0.9117647,34.28571,0.7777778",\r
27                                                                                   "Aqua,255,0,255,255,0.5,180,1",\r
28                                                                                   "Aquamarine,255,127,255,212,0.7490196,159.8438,1",\r
29                                                                                   "Azure,255,240,255,255,0.9705882,180,1",\r
30                                                                                   "Beige,255,245,245,220,0.9117647,60,0.5555556",\r
31                                                                                   "Bisque,255,255,228,196,0.8843137,32.54237,1",\r
32                                                                                   "Black,255,0,0,0,0,0,0",\r
33                                                                                   "BlanchedAlmond,255,255,235,205,0.9019608,36,1",\r
34                                                                                   "Blue,255,0,0,255,0.5,240,1",\r
35                                                                                   "BlueViolet,255,138,43,226,0.527451,271.1476,0.7593361",\r
36                                                                                   "Brown,255,165,42,42,0.4058824,0,0.5942029",\r
37                                                                                   "BurlyWood,255,222,184,135,0.7,33.7931,0.5686275",\r
38                                                                                   "CadetBlue,255,95,158,160,0.5,181.8462,0.254902",\r
39                                                                                   "Chartreuse,255,127,255,0,0.5,90.11765,1",\r
40                                                                                   "Chocolate,255,210,105,30,0.4705882,25,0.75",\r
41                                                                                   "Coral,255,255,127,80,0.6568627,16.11428,1",\r
42                                                                                   "CornflowerBlue,255,100,149,237,0.6607843,218.5401,0.7919075",\r
43                                                                                   "Cornsilk,255,255,248,220,0.9313725,48,1",\r
44                                                                                   "Crimson,255,220,20,60,0.4705882,348,0.8333333",\r
45                                                                                   "Cyan,255,0,255,255,0.5,180,1",\r
46                                                                                   "DarkBlue,255,0,0,139,0.272549,240,1",\r
47                                                                                   "DarkCyan,255,0,139,139,0.272549,180,1",\r
48                                                                                   "DarkGoldenrod,255,184,134,11,0.3823529,42.65896,0.8871795",\r
49                                                                                   "DarkGray,255,169,169,169,0.6627451,0,0",\r
50                                                                                   "DarkGreen,255,0,100,0,0.1960784,120,1",\r
51                                                                                   "DarkKhaki,255,189,183,107,0.5803922,55.60976,0.3831776",\r
52                                                                                   "DarkMagenta,255,139,0,139,0.272549,300,1",\r
53                                                                                   "DarkOliveGreen,255,85,107,47,0.3019608,82,0.3896104",\r
54                                                                                   "DarkOrange,255,255,140,0,0.5,32.94118,1",\r
55                                                                                   "DarkOrchid,255,153,50,204,0.4980392,280.1299,0.6062992",\r
56                                                                                   "DarkRed,255,139,0,0,0.272549,0,1",\r
57                                                                                   "DarkSalmon,255,233,150,122,0.6960784,15.13514,0.7161291",\r
58                                                                                   "DarkSeaGreen,255,143,188,139,0.6411765,115.102,0.2677596",\r
59                                                                                   "DarkSlateBlue,255,72,61,139,0.3921569,248.4615,0.39",\r
60                                                                                   "DarkSlateGray,255,47,79,79,0.2470588,180,0.2539683",\r
61                                                                                   "DarkTurquoise,255,0,206,209,0.4098039,180.8612,1",\r
62                                                                                   "DarkViolet,255,148,0,211,0.4137255,282.0853,1",\r
63                                                                                   "DeepPink,255,255,20,147,0.5392157,327.5745,1",\r
64                                                                                   "DeepSkyBlue,255,0,191,255,0.5,195.0588,1",\r
65                                                                                   "DimGray,255,105,105,105,0.4117647,0,0",\r
66                                                                                   "DodgerBlue,255,30,144,255,0.5588235,209.6,1",\r
67                                                                                   "Firebrick,255,178,34,34,0.4156863,0,0.6792453",\r
68                                                                                   "FloralWhite,255,255,250,240,0.9705882,40,1",\r
69                                                                                   "ForestGreen,255,34,139,34,0.3392157,120,0.6069364",\r
70                                                                                   "Fuchsia,255,255,0,255,0.5,300,1",\r
71                                                                                   "Gainsboro,255,220,220,220,0.8627451,0,0",\r
72                                                                                   "GhostWhite,255,248,248,255,0.9862745,240,1",\r
73                                                                                   "Gold,255,255,215,0,0.5,50.58823,1",\r
74                                                                                   "Goldenrod,255,218,165,32,0.4901961,42.90322,0.744",\r
75                                                                                   "Gray,255,128,128,128,0.5019608,0,0",\r
76                                                                                   "Green,255,0,128,0,0.2509804,120,1",\r
77                                                                                   "GreenYellow,255,173,255,47,0.5921569,83.65385,1",\r
78                                                                                   "Honeydew,255,240,255,240,0.9705882,120,1",\r
79                                                                                   "HotPink,255,255,105,180,0.7058824,330,1",\r
80                                                                                   "IndianRed,255,205,92,92,0.5823529,0,0.5305164",\r
81                                                                                   "Indigo,255,75,0,130,0.254902,274.6154,1",\r
82                                                                                   "Ivory,255,255,255,240,0.9705882,60,1",\r
83                                                                                   "Khaki,255,240,230,140,0.7450981,54,0.7692308",\r
84                                                                                   "Lavender,255,230,230,250,0.9411765,240,0.6666667",\r
85                                                                                   "LavenderBlush,255,255,240,245,0.9705882,340,1",\r
86                                                                                   "LawnGreen,255,124,252,0,0.4941176,90.47619,1",\r
87                                                                                   "LemonChiffon,255,255,250,205,0.9019608,54,1",\r
88                                                                                   "LightBlue,255,173,216,230,0.7901961,194.7368,0.5327103",\r
89                                                                                   "LightCoral,255,240,128,128,0.7215686,0,0.7887324",\r
90                                                                                   "LightCyan,255,224,255,255,0.9392157,180,1",\r
91                                                                                   "LightGoldenrodYellow,255,250,250,210,0.9019608,60,0.8",\r
92                                                                                   "LightGreen,255,144,238,144,0.7490196,120,0.734375",\r
93                                                                                   "LightGray,255,211,211,211,0.827451,0,0",\r
94                                                                                   "LightPink,255,255,182,193,0.8568628,350.9589,1",\r
95                                                                                   "LightSalmon,255,255,160,122,0.7392157,17.14286,1",\r
96                                                                                   "LightSeaGreen,255,32,178,170,0.4117647,176.7123,0.6952381",\r
97                                                                                   "LightSkyBlue,255,135,206,250,0.754902,202.9565,0.92",\r
98                                                                                   "LightSlateGray,255,119,136,153,0.5333334,210,0.1428572",\r
99                                                                                   "LightSteelBlue,255,176,196,222,0.7803922,213.913,0.4107143",\r
100                                                                                   "LightYellow,255,255,255,224,0.9392157,60,1",\r
101                                                                                   "Lime,255,0,255,0,0.5,120,1",\r
102                                                                                   "LimeGreen,255,50,205,50,0.5,120,0.6078432",\r
103                                                                                   "Linen,255,250,240,230,0.9411765,30,0.6666667",\r
104                                                                                   "Magenta,255,255,0,255,0.5,300,1",\r
105                                                                                   "Maroon,255,128,0,0,0.2509804,0,1",\r
106                                                                                   "MediumAquamarine,255,102,205,170,0.6019608,159.6116,0.5073892",\r
107                                                                                   "MediumBlue,255,0,0,205,0.4019608,240,1",\r
108                                                                                   "MediumOrchid,255,186,85,211,0.5803922,288.0952,0.5887851",\r
109                                                                                   "MediumPurple,255,147,112,219,0.6490196,259.6262,0.5977654",\r
110                                                                                   "MediumSeaGreen,255,60,179,113,0.4686275,146.7227,0.497908",\r
111                                                                                   "MediumSlateBlue,255,123,104,238,0.6705883,248.5075,0.797619",\r
112                                                                                   "MediumSpringGreen,255,0,250,154,0.4901961,156.96,1",\r
113                                                                                   "MediumTurquoise,255,72,209,204,0.5509804,177.8102,0.5982533",\r
114                                                                                   "MediumVioletRed,255,199,21,133,0.4313726,322.2472,0.8090909",\r
115                                                                                   "MidnightBlue,255,25,25,112,0.2686275,240,0.6350365",\r
116                                                                                   "MintCream,255,245,255,250,0.9803922,150,1",\r
117                                                                                   "MistyRose,255,255,228,225,0.9411765,6,1",\r
118                                                                                   "Moccasin,255,255,228,181,0.854902,38.10811,1",\r
119                                                                                   "NavajoWhite,255,255,222,173,0.8392157,35.85366,1",\r
120                                                                                   "Navy,255,0,0,128,0.2509804,240,1",\r
121                                                                                   "OldLace,255,253,245,230,0.9470588,39.13044,0.8518519",\r
122                                                                                   "Olive,255,128,128,0,0.2509804,60,1",\r
123                                                                                   "OliveDrab,255,107,142,35,0.3470588,79.62617,0.6045198",\r
124                                                                                   "Orange,255,255,165,0,0.5,38.82353,1",\r
125                                                                                   "OrangeRed,255,255,69,0,0.5,16.23529,1",\r
126                                                                                   "Orchid,255,218,112,214,0.6470588,302.2642,0.5888889",\r
127                                                                                   "PaleGoldenrod,255,238,232,170,0.8,54.70588,0.6666667",\r
128                                                                                   "PaleGreen,255,152,251,152,0.7901961,120,0.9252337",\r
129                                                                                   "PaleTurquoise,255,175,238,238,0.809804,180,0.6494845",\r
130                                                                                   "PaleVioletRed,255,219,112,147,0.6490196,340.3738,0.5977654",\r
131                                                                                   "PapayaWhip,255,255,239,213,0.9176471,37.14286,1",\r
132                                                                                   "PeachPuff,255,255,218,185,0.8627451,28.28572,1",\r
133                                                                                   "Peru,255,205,133,63,0.5254902,29.57747,0.5867769",\r
134                                                                                   "Pink,255,255,192,203,0.8764706,349.5238,1",\r
135                                                                                   "Plum,255,221,160,221,0.7470589,300,0.4728682",\r
136                                                                                   "PowderBlue,255,176,224,230,0.7960784,186.6667,0.5192308",\r
137                                                                                   "Purple,255,128,0,128,0.2509804,300,1",\r
138                                                                                   "Red,255,255,0,0,0.5,0,1",\r
139                                                                                   "RosyBrown,255,188,143,143,0.6490196,0,0.2513967",\r
140                                                                                   "RoyalBlue,255,65,105,225,0.5686275,225,0.7272727",\r
141                                                                                   "SaddleBrown,255,139,69,19,0.3098039,25,0.7594936",\r
142                                                                                   "Salmon,255,250,128,114,0.7137255,6.176474,0.9315069",\r
143                                                                                   "SandyBrown,255,244,164,96,0.6666667,27.56757,0.8705882",\r
144                                                                                   "SeaGreen,255,46,139,87,0.3627451,146.4516,0.5027027",\r
145                                                                                   "SeaShell,255,255,245,238,0.9666667,24.70588,1",\r
146                                                                                   "Sienna,255,160,82,45,0.4019608,19.30435,0.5609756",\r
147                                                                                   "Silver,255,192,192,192,0.7529412,0,0",\r
148                                                                                   "SkyBlue,255,135,206,235,0.7254902,197.4,0.7142857",\r
149                                                                                   "SlateBlue,255,106,90,205,0.5784314,248.3478,0.5348837",\r
150                                                                                   "SlateGray,255,112,128,144,0.5019608,210,0.1259843",\r
151                                                                                   "Snow,255,255,250,250,0.9901961,0,1",\r
152                                                                                   "SpringGreen,255,0,255,127,0.5,149.8824,1",\r
153                                                                                   "SteelBlue,255,70,130,180,0.4901961,207.2727,0.44",\r
154                                                                                   "Tan,255,210,180,140,0.6862745,34.28571,0.4375",\r
155                                                                                   "Teal,255,0,128,128,0.2509804,180,1",\r
156                                                                                   "Thistle,255,216,191,216,0.7980392,300,0.2427184",\r
157                                                                                   "Tomato,255,255,99,71,0.6392157,9.130435,1",\r
158                                                                                   "Turquoise,255,64,224,208,0.5647059,174,0.7207207",\r
159                                                                                   "Violet,255,238,130,238,0.7215686,300,0.7605634",\r
160                                                                                   "Wheat,255,245,222,179,0.8313726,39.09091,0.7674419",\r
161                                                                                   "White,255,255,255,255,1,0,0",\r
162                                                                                   "WhiteSmoke,255,245,245,245,0.9607843,0,0",\r
163                                                                                   "Yellow,255,255,255,0,0.5,60,1",\r
164                                                                                   "YellowGreen,255,154,205,50,0.5,79.74194,0.6078432"};\r
165 \r
166                 string [] ar_system_colors = {\r
167                                                                                  "ActiveBorder,255,212,208,200,0.8078431,40,0.122449",\r
168                                                                                  "ActiveCaption,255,10,36,106,0.227451,223.75,0.8275862",\r
169                                                                                  "ActiveCaptionText,255,255,255,255,1,0,0",\r
170                                                                                  "AppWorkspace,255,128,128,128,0.5019608,0,0",\r
171                                                                                  "Control,255,212,208,200,0.8078431,40,0.122449",\r
172                                                                                  "ControlDark,255,128,128,128,0.5019608,0,0",\r
173                                                                                  "ControlDarkDark,255,64,64,64,0.2509804,0,0",\r
174                                                                                  "ControlLight,255,212,208,200,0.8078431,40,0.122449",\r
175                                                                                  "ControlLightLight,255,255,255,255,1,0,0",\r
176                                                                                  "ControlText,255,0,0,0,0,0,0",\r
177                                                                                  "Desktop,255,58,110,165,0.4372549,210.8411,0.4798206",\r
178                                                                                  "GrayText,255,128,128,128,0.5019608,0,0",\r
179                                                                                  "Highlight,255,10,36,106,0.227451,223.75,0.8275862",\r
180                                                                                  "HighlightText,255,255,255,255,1,0,0",\r
181                                                                                  "HotTrack,255,0,0,128,0.2509804,240,1",\r
182                                                                                  "InactiveBorder,255,212,208,200,0.8078431,40,0.122449",\r
183                                                                                  "InactiveCaption,255,128,128,128,0.5019608,0,0",\r
184                                                                                  "InactiveCaptionText,255,212,208,200,0.8078431,40,0.122449",\r
185                                                                                  "Info,255,255,255,225,0.9411765,60,1",\r
186                                                                                  "InfoText,255,0,0,0,0,0,0",\r
187                                                                                  "Menu,255,212,208,200,0.8078431,40,0.122449",\r
188                                                                                  "MenuText,255,0,0,0,0,0,0",\r
189                                                                                  "ScrollBar,255,212,208,200,0.8078431,40,0.122449",\r
190                                                                                  "Window,255,255,255,255,1,0,0",\r
191                                                                                  "WindowFrame,255,0,0,0,0,0,0",\r
192                                                                                  "WindowText,255,0,0,0,0,0,0"};\r
193 \r
194                 string [] ar_system_color_conversions = {\r
195                                                                                                         "ActiveBorder,activeborder",\r
196                                                                                                         "ActiveCaption,activecaption",\r
197                                                                                                         "ActiveCaptionText,captiontext",\r
198                                                                                                         "AppWorkspace,appworkspace",\r
199                                                                                                         "Control,buttonface",\r
200                                                                                                         "ControlDark,buttonshadow",\r
201                                                                                                         "ControlDarkDark,threeddarkshadow",\r
202                                                                                                         "ControlLight,buttonface",\r
203                                                                                                         "ControlLightLight,buttonhighlight",\r
204                                                                                                         "ControlText,buttontext",\r
205                                                                                                         "Desktop,background",\r
206                                                                                                         "GrayText,graytext",\r
207                                                                                                         "Highlight,highlight",\r
208                                                                                                         "HighlightText,highlighttext",\r
209                                                                                                         "HotTrack,highlight",\r
210                                                                                                         "InactiveBorder,inactiveborder",\r
211                                                                                                         "InactiveCaption,inactivecaption",\r
212                                                                                                         "InactiveCaptionText,inactivecaptiontext",\r
213                                                                                                         "Info,infobackground",\r
214                                                                                                         "InfoText,infotext",\r
215                                                                                                         "Menu,menu",\r
216                                                                                                         "MenuText,menutext",\r
217                                                                                                         "ScrollBar,scrollbar",\r
218                                                                                                         "Window,window",\r
219                                                                                                         "WindowFrame,windowframe",\r
220                                                                                                         "WindowText,windowtext"};\r
221                 #endregion\r
222 \r
223         \r
224                 [Test]\r
225                 public void ColorPropertyCount()\r
226                 {\r
227                         Type t = typeof(Color);\r
228                         PropertyInfo [] pi = t.GetProperties(BindingFlags.Static | BindingFlags.Public);\r
229 \r
230                         int i = 0;\r
231                         foreach (PropertyInfo p in pi)\r
232                         {\r
233                                 if (p.PropertyType == typeof(Color))\r
234                                 {\r
235                                         i++;\r
236                                 }\r
237                         }\r
238                         Assert.AreEqual(ar_colors.Length, i, "Number of Colors");\r
239                 }\r
240 \r
241                 [Test]\r
242                 public void ColorProperties () \r
243                 {\r
244                         Type t = typeof(Color);\r
245                         foreach (string s in ar_colors)\r
246                         {\r
247                                 string [] col = s.Split(',');\r
248                                 MemberInfo [] mi = t.GetMember(col[0]);\r
249 \r
250                                 if (mi.Length == 1)\r
251                                 {\r
252                                         if (mi[0].MemberType == MemberTypes.Property)\r
253                                         {\r
254                                                 PropertyInfo p = (PropertyInfo)mi[0];\r
255                                                 Color color = (Color)p.GetValue(null, null);\r
256                                                 Assert.AreEqual(col[0], color.Name, col[0] + " Color Name is wrong");\r
257                                                 Assert.AreEqual(Convert.ToByte( col[1] ), color.A, col[0] + " Color A is wrong");\r
258                                                 Assert.AreEqual(Convert.ToByte( col[2] ), color.R, col[0] + " Color R is wrong");\r
259                                                 Assert.AreEqual(Convert.ToByte( col[3] ), color.G, col[0] + " Color G is wrong");\r
260                                                 Assert.AreEqual(Convert.ToByte( col[4] ), color.B, col[0] + " Color B is wrong");\r
261 \r
262                                                 Assert.AreEqual(float.Parse(col[5]), color.GetBrightness(), 0.001F, col[0] + " Color.GetBrightness() is wrong");\r
263                                                 Assert.AreEqual(float.Parse(col[6]), color.GetHue(), 0.001F, col[0] + " Color.GetHue() is wrong");\r
264                                                 Assert.AreEqual(float.Parse(col[7]), color.GetSaturation(), 0.001F, col[0] + " Color.GetSaturation() is wrong");\r
265 \r
266                                                 Assert.AreEqual(true, color.IsNamedColor, col[0] + " IsNamedColor is wrong");\r
267                                                 Assert.AreEqual(false, color.IsSystemColor, col[0] + " IsSystemColor is wrong");\r
268                                                 Assert.AreEqual(true, color.IsKnownColor, col[0] + " IsKnownColor is wrong");\r
269                                         }\r
270                                         else\r
271                                         {\r
272                                                 Assert.Fail(s + " is not property of Color class");\r
273                                         }\r
274                                 }\r
275                                 else \r
276                                 {\r
277                                         Assert.Fail("Property " + s + " not found in Color class");\r
278                                 }\r
279                         }\r
280                 }\r
281 \r
282                 [Test]\r
283                 public void SystemColorPropertyCount()\r
284                 {\r
285                         Type t = typeof(SystemColors);\r
286                         PropertyInfo [] pi = t.GetProperties(BindingFlags.Static | BindingFlags.Public);\r
287 \r
288                         int i = 0;\r
289                         foreach (PropertyInfo p in pi)\r
290                         {\r
291                                 if (p.PropertyType == typeof(Color))\r
292                                 {\r
293                                         i++;\r
294                                 }\r
295                         }\r
296                         Assert.AreEqual(ar_system_colors.Length, i, "Number of SystemColors");\r
297                 }\r
298 \r
299                 [Test]\r
300                 public void SystemColorProperties () \r
301                 {\r
302                         Type t = typeof(SystemColors);\r
303                         foreach (string s in ar_system_colors)\r
304                         {\r
305                                 string [] col = s.Split(',');\r
306                                 MemberInfo [] mi = t.GetMember(col[0]);\r
307 \r
308                                 if (mi.Length == 1)\r
309                                 {\r
310                                         if (mi[0].MemberType == MemberTypes.Property)\r
311                                         {\r
312                                                 PropertyInfo p = (PropertyInfo)mi[0];\r
313                                                 Color color = (Color)p.GetValue(null, null);\r
314                                                 Assert.AreEqual(col[0], color.Name, col[0] + " Color Name is wrong");\r
315                                                 Assert.AreEqual(Convert.ToByte( col[1] ), color.A, col[0] + " Color A is wrong");\r
316                                                 Assert.AreEqual(Convert.ToByte( col[2] ), color.R, col[0] + " Color R is wrong");\r
317                                                 Assert.AreEqual(Convert.ToByte( col[3] ), color.G, col[0] + " Color G is wrong");\r
318                                                 Assert.AreEqual(Convert.ToByte( col[4] ), color.B, col[0] + " Color B is wrong");\r
319 \r
320                                                 Assert.AreEqual(float.Parse(col[5]), color.GetBrightness(), 0.001F, col[0] + " Color.GetBrightness() is wrong");\r
321                                                 Assert.AreEqual(float.Parse(col[6]), color.GetHue(), 0.001F, col[0] + " Color.GetHue() is wrong");\r
322                                                 Assert.AreEqual(float.Parse(col[7]), color.GetSaturation(), 0.001F, col[0] + " Color.GetSaturation() is wrong");\r
323 \r
324                                                 Assert.AreEqual(true, color.IsNamedColor, col[0] + " IsNamedColor is wrong");\r
325                                                 Assert.AreEqual(true, color.IsSystemColor, col[0] + " IsSystemColor is wrong");\r
326                                                 Assert.AreEqual(true, color.IsKnownColor, col[0] + " IsKnownColor is wrong");\r
327                                         }\r
328                                         else\r
329                                         {\r
330                                                 Assert.Fail(s + " is not property of SystemColors class");\r
331                                         }\r
332                                 }\r
333                                 else \r
334                                 {\r
335                                         Assert.Fail("Property " + s + " not found in SystemColors class");\r
336                                 }\r
337                         }\r
338                 }\r
339                 [Test]\r
340                 public void SystemColorTranslator()\r
341                 {\r
342                         Type t = typeof(SystemColors);\r
343 \r
344                         foreach (string s in ar_system_color_conversions)\r
345                         {\r
346                                 string [] col = s.Split(',');\r
347                                 try\r
348                                 {\r
349                                         PropertyInfo pi = t.GetProperty(col[0]);\r
350                                         Color c = (Color)pi.GetValue(null, null);\r
351 \r
352                                         Assert.AreEqual(col[1], ColorTranslator.ToHtml(c), col[0] + " is worng");\r
353                                 }\r
354                                 catch (Exception)\r
355                                 {\r
356                                         Assert.Fail(col[0] + " failed");\r
357                                 }\r
358                         }\r
359                 }\r
360         }\r
361 }