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