[System.Net] Add support for .pac proxy config scripts on mac
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / ColorTranslator.cs
1 //
2 // ColorTranslator class testing unit
3 //
4 // Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com)
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining
7 // a copy of this software and associated documentation files (the
8 // "Software"), to deal in the Software without restriction, including
9 // without limitation the rights to use, copy, modify, merge, publish,
10 // distribute, sublicense, and/or sell copies of the Software, and to
11 // permit persons to whom the Software is furnished to do so, subject to
12 // the following conditions:
13 // 
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
16 // 
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 //
25
26 using System;
27 using System.Drawing;
28 using System.Security.Permissions;
29 using NUnit.Framework;
30
31 namespace MonoTests.System.Drawing {
32
33         [TestFixture]
34         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
35         public class ColorTranslatorTest {
36
37                 [Test]
38                 public void FromHtml_Null ()
39                 {
40                         Assert.AreEqual (0, ColorTranslator.FromHtml (null).ToArgb ());
41                 }
42
43                 [Test]
44                 public void FromHtml_Empty ()
45                 {
46                         Assert.AreEqual (0, ColorTranslator.FromHtml (String.Empty).ToArgb ());
47                 }
48
49                 [Test]
50                 public void FromHtml_KnownValues ()
51                 {
52                         Assert.AreEqual (SystemColors.Control, ColorTranslator.FromHtml ("buttonface"), "buttonface");
53                         Assert.AreEqual (SystemColors.ActiveCaptionText, ColorTranslator.FromHtml ("CAPTIONTEXT"), "captiontext");
54                         Assert.AreEqual (SystemColors.ControlDarkDark, ColorTranslator.FromHtml ("threedDARKshadow"), "threeddarkshadow");
55                         Assert.AreEqual (SystemColors.Desktop, ColorTranslator.FromHtml ("background"), "background");
56                         Assert.AreEqual (SystemColors.ControlText, ColorTranslator.FromHtml ("ButtonText"), "buttontext");
57                         Assert.AreEqual (SystemColors.Info, ColorTranslator.FromHtml ("infobackground"), "infobackground");
58                 }
59
60                 [Test]
61                 public void FromHtml_Int ()
62                 {
63                         Assert.AreEqual (-1, ColorTranslator.FromHtml ("-1").ToArgb (), "-1");
64                         Assert.AreEqual (0, ColorTranslator.FromHtml ("0").ToArgb (), "0");
65                         Assert.AreEqual (1, ColorTranslator.FromHtml ("1").ToArgb (), "1");
66                 }
67
68                 [Test]
69                 public void FromHtml_PoundInt ()
70                 {
71                         Assert.AreEqual (0, ColorTranslator.FromHtml ("#0").ToArgb (), "#0");
72                         Assert.AreEqual (1, ColorTranslator.FromHtml ("#1").ToArgb (), "#1");
73                         Assert.AreEqual (255, ColorTranslator.FromHtml ("#FF").ToArgb (), "#FF");
74                         Assert.AreEqual (65535, ColorTranslator.FromHtml ("#FFFF").ToArgb (), "#FFFF");
75                         Assert.AreEqual (-15584170, ColorTranslator.FromHtml ("#123456").ToArgb (), "#123456");
76                         Assert.AreEqual (-1, ColorTranslator.FromHtml ("#FFFFFF").ToArgb (), "#FFFFFF");
77                         Assert.AreEqual (305419896, ColorTranslator.FromHtml ("#12345678").ToArgb (), "#12345678");
78                         Assert.AreEqual (-1, ColorTranslator.FromHtml ("#FFFFFFFF").ToArgb (), "#FFFFFFFF");
79                         
80                         Assert.AreEqual (Color.White, ColorTranslator.FromHtml ("#FFFFFF"), "used to resolve to some KnownColor");
81                         Assert.AreEqual (Color.White, ColorTranslator.FromHtml ("0xFFFFFF"), "used to resolve to some KnownColor");
82                 }
83
84                 [Test]
85                 [ExpectedException (typeof (Exception))]
86 #if TARGET_JVM
87                 [Category ("NotWorking")]
88 #endif
89                 public void FromHtml_PoundNegative ()
90                 {
91                         ColorTranslator.FromHtml ("#-1");
92                 }
93
94                 [Test]
95                 [ExpectedException (typeof (Exception))]
96                 public void FromHtml_PoundTooLarge ()
97                 {
98                         ColorTranslator.FromHtml ("#100000000");
99                 }
100
101                 [Test]
102                 [ExpectedException (typeof (Exception))]
103 #if TARGET_JVM
104                 [Category ("NotWorking")]
105 #endif
106                 public void FromHtml_Unknown ()
107                 {
108                         ColorTranslator.FromHtml ("unknown-color-test");
109                 }
110
111                 [Test]
112                 public void FromHtml ()
113                 {
114                         Color [] colors = new Color [] {
115 Color.Aqua, Color.Black, Color.Blue, Color.Fuchsia, Color.Gray,
116 Color.Green, Color.Lime, Color.Maroon, Color.Navy, Color.Olive,
117 Color.Purple, Color.Red, Color.Silver, Color.Teal, Color.White,
118 Color.Yellow,
119
120 SystemColors.ActiveBorder, SystemColors.ActiveCaption,
121 SystemColors.Control, 
122 //SystemColors.ControlLightLight,
123 SystemColors.ActiveCaptionText, SystemColors.GrayText,
124 //SystemColors.InactiveBorder, SystemColors.InactiveCaption,
125 SystemColors.InfoText, SystemColors.Menu,
126 SystemColors.ControlDarkDark, 
127 //SystemColors.ControlText, SystemColors.ControlDark,
128 SystemColors.Window,
129 SystemColors.AppWorkspace, SystemColors.Desktop,
130 //SystemColors.ControlDark,
131 SystemColors.ControlText,
132 SystemColors.Highlight, SystemColors.HighlightText,
133 //SystemColors.InactiveCaptionText,
134 SystemColors.Info,
135 SystemColors.MenuText, SystemColors.ScrollBar,
136 //SystemColors.ControlLight, SystemColors.ControlLightLight
137                         };
138                         string [] htmlColors = new string [] {
139 "Aqua", "Black", "Blue", "Fuchsia", "Gray", "Green",
140 "Lime", "Maroon", "Navy", "Olive", "Purple", "Red",
141 "Silver", "Teal", "White", "Yellow",
142
143 "activeborder", "activecaption", "buttonface",
144 //"buhighlight",
145 "captiontext", "graytext",
146 //"iborder", "Icaption", 
147 "infotext", "menu", "threeddarkshadow",
148 //"thrface", "Threedshadow",
149 "window", "appworkspace",
150 "background", 
151 //"bshadow",
152 "buttontext", "highlight",
153 "highlighttext",
154 //"icaptiontext",
155 "infobackground",
156 "menutext", "scrollbar", 
157 //"thhighlight", "thlightshadow"
158                         };
159                 
160                         for (int i=0; i<colors.Length; i++)
161                                 Assert.AreEqual (colors[i], ColorTranslator.FromHtml (htmlColors [i]));
162                 }
163
164                 [Test] // 340917
165                 public void FromHtml_LightGrey ()
166                 {
167                         Assert.AreEqual (Color.LightGray, ColorTranslator.FromHtml(ColorTranslator.ToHtml(Color.LightGray)));
168                 }
169
170                 [Test]
171                 public void FromOle ()
172                 {
173                         Assert.AreEqual (Color.FromArgb (0x10, 0x20, 0x30), ColorTranslator.FromOle (0x302010));
174                         Assert.AreEqual (Color.FromArgb (0xbb, 0x20, 0x30), ColorTranslator.FromOle (unchecked ((int)0xee3020bb)));
175                 }
176
177                 [Test]
178                 public void FromWin32 ()
179                 {
180                         Assert.AreEqual (Color.FromArgb (0x10, 0x20, 0x30), ColorTranslator.FromWin32 (0x302010));
181                         Assert.AreEqual (Color.FromArgb (0xbb, 0x20, 0x30), ColorTranslator.FromWin32 (unchecked ((int)0xee3020bb)));
182                 }
183
184                 [Test]
185                 public void ToHtml ()
186                 {
187                         string [] htmlColors = new string [] {
188 "activeborder", "activecaption", "captiontext", "appworkspace", "buttonface",
189 "buttonshadow", "threeddarkshadow", "buttonface", "buttonhighlight", "buttontext",
190 "background", "graytext", "highlight", "highlighttext", "highlight", "inactiveborder",
191 "inactivecaption", "inactivecaptiontext", "infobackground", "infotext", "menu",
192 "menutext", "scrollbar", "window", "windowframe", "windowtext", 
193
194 "Transparent", "AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige",
195 "Bisque", "Black", "BlanchedAlmond", "Blue", "BlueViolet", "Brown", "BurlyWood",
196 "CadetBlue", "Chartreuse", "Chocolate", "Coral", "CornflowerBlue", "Cornsilk",
197 "Crimson", "Cyan", "DarkBlue", "DarkCyan", "DarkGoldenrod", "DarkGray", "DarkGreen",
198 "DarkKhaki", "DarkMagenta", "DarkOliveGreen", "DarkOrange", "DarkOrchid", "DarkRed",
199 "DarkSalmon", "DarkSeaGreen", "DarkSlateBlue", "DarkSlateGray", "DarkTurquoise", "DarkViolet",
200 "DeepPink", "DeepSkyBlue", "DimGray", "DodgerBlue", "Firebrick", "FloralWhite", "ForestGreen",
201 "Fuchsia", "Gainsboro", "GhostWhite", "Gold", "Goldenrod", "Gray", "Green", "GreenYellow",
202 "Honeydew", "HotPink", "IndianRed", "Indigo", "Ivory", "Khaki", "Lavender", "LavenderBlush",
203 "LawnGreen", "LemonChiffon", "LightBlue", "LightCoral", "LightCyan", "LightGoldenrodYellow",
204 "LightGrey", "LightGreen", "LightPink", "LightSalmon", "LightSeaGreen", "LightSkyBlue",
205 "LightSlateGray", "LightSteelBlue", "LightYellow", "Lime", "LimeGreen", "Linen", "Magenta",
206 "Maroon", "MediumAquamarine", "MediumBlue", "MediumOrchid", "MediumPurple", "MediumSeaGreen",
207 "MediumSlateBlue", "MediumSpringGreen", "MediumTurquoise", "MediumVioletRed", "MidnightBlue",
208 "MintCream", "MistyRose", "Moccasin", "NavajoWhite", "Navy", "OldLace", "Olive", "OliveDrab",
209 "Orange", "OrangeRed", "Orchid", "PaleGoldenrod", "PaleGreen", "PaleTurquoise", "PaleVioletRed",
210 "PapayaWhip", "PeachPuff", "Peru", "Pink", "Plum", "PowderBlue", "Purple", "Red", "RosyBrown",
211 "RoyalBlue", "SaddleBrown", "Salmon", "SandyBrown", "SeaGreen", "SeaShell", "Sienna", "Silver",
212 "SkyBlue", "SlateBlue", "SlateGray", "Snow", "SpringGreen", "SteelBlue", "Tan", "Teal",
213 "Thistle", "Tomato", "Turquoise", "Violet", "Wheat", "White", "WhiteSmoke", "Yellow", "YellowGreen",
214                                                                                         };
215
216                         for (KnownColor i=KnownColor.ActiveBorder; i<=KnownColor.YellowGreen; i++)
217                                 Assert.AreEqual (htmlColors[(int)i-1], ColorTranslator.ToHtml (Color.FromKnownColor (i)));
218                 }
219
220                 [Test]
221                 public void ToOle () {
222                         Assert.AreEqual (0x302010, ColorTranslator.ToOle (Color.FromArgb (0x10, 0x20, 0x30)));
223                         Assert.AreEqual (unchecked ((int)0x3020bb), ColorTranslator.ToOle (Color.FromArgb (0xee, 0xbb, 0x20, 0x30)));
224                 }
225
226                 [Test]
227                 public void ToWin32 () {
228                         Assert.AreEqual (0x302010, ColorTranslator.ToWin32 (Color.FromArgb (0x10, 0x20, 0x30)));
229                         Assert.AreEqual (unchecked ((int)0x3020bb), ColorTranslator.ToWin32 (Color.FromArgb (0xee, 0xbb, 0x20, 0x30)));
230                 }
231
232         }
233 }
234