Fix problems with overlong directory names: phase #1
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / ColorTranslator.cs
1 //
2 // ColorTranslator class testing unit
3 //
4 // Copyright (C) 2006 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 ColorTranslatorFixture {
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_Int ()
51                 {
52                         Assert.AreEqual (-1, ColorTranslator.FromHtml ("-1").ToArgb (), "-1");
53                         Assert.AreEqual (0, ColorTranslator.FromHtml ("0").ToArgb (), "0");
54                         Assert.AreEqual (1, ColorTranslator.FromHtml ("1").ToArgb (), "1");
55                 }
56
57                 [Test]
58                 public void FromHtml_PoundInt ()
59                 {
60                         Assert.AreEqual (0, ColorTranslator.FromHtml ("#0").ToArgb (), "#0");
61                         Assert.AreEqual (1, ColorTranslator.FromHtml ("#1").ToArgb (), "#1");
62                         Assert.AreEqual (255, ColorTranslator.FromHtml ("#FF").ToArgb (), "#FF");
63                         Assert.AreEqual (65535, ColorTranslator.FromHtml ("#FFFF").ToArgb (), "#FFFF");
64                         Assert.AreEqual (-1, ColorTranslator.FromHtml ("#FFFFFF").ToArgb (), "#FFFFFF");
65                         Assert.AreEqual (-1, ColorTranslator.FromHtml ("#FFFFFFFF").ToArgb (), "#FFFFFFFF");
66                 }
67
68                 [Test]
69                 [ExpectedException (typeof (Exception))]
70 #if TARGET_JVM
71                 [Category ("NotWorking")]
72 #endif
73                 public void FromHtml_PoundNegative ()
74                 {
75                         ColorTranslator.FromHtml ("#-1");
76                 }
77
78                 [Test]
79                 [ExpectedException (typeof (Exception))]
80                 public void FromHtml_PoundTooLarge ()
81                 {
82                         ColorTranslator.FromHtml ("#100000000");
83                 }
84
85                 [Test]
86                 [ExpectedException (typeof (Exception))]
87 #if TARGET_JVM
88                 [Category ("NotWorking")]
89 #endif
90                 public void FromHtml_Unkown ()
91                 {
92                         ColorTranslator.FromHtml ("unknown-color-test");
93                 }
94
95                 [Test]
96                 public void FromHtml ()
97                 {
98                         Color [] colors = new Color [] {
99 Color.Aqua, Color.Black, Color.Blue, Color.Fuchsia, Color.Gray,
100 Color.Green, Color.Lime, Color.Maroon, Color.Navy, Color.Olive,
101 Color.Purple, Color.Red, Color.Silver, Color.Teal, Color.White,
102 Color.Yellow,
103
104 SystemColors.ActiveBorder, SystemColors.ActiveCaption,
105 SystemColors.Control, 
106 //SystemColors.ControlLightLight,
107 SystemColors.ActiveCaptionText, SystemColors.GrayText,
108 //SystemColors.InactiveBorder, SystemColors.InactiveCaption,
109 SystemColors.InfoText, SystemColors.Menu,
110 SystemColors.ControlDarkDark, 
111 //SystemColors.ControlText, SystemColors.ControlDark,
112 SystemColors.Window,
113 SystemColors.AppWorkspace, SystemColors.Desktop,
114 //SystemColors.ControlDark,
115 SystemColors.ControlText,
116 SystemColors.Highlight, SystemColors.HighlightText,
117 //SystemColors.InactiveCaptionText,
118 SystemColors.Info,
119 SystemColors.MenuText, SystemColors.ScrollBar,
120 //SystemColors.ControlLight, SystemColors.ControlLightLight
121                         };
122                         string [] htmlColors = new string [] {
123 "Aqua", "Black", "Blue", "Fuchsia", "Gray", "Green",
124 "Lime", "Maroon", "Navy", "Olive", "Purple", "Red",
125 "Silver", "Teal", "White", "Yellow",
126
127 "activeborder", "activecaption", "buttonface",
128 //"buhighlight",
129 "captiontext", "graytext",
130 //"iborder", "Icaption", 
131 "infotext", "menu", "threeddarkshadow",
132 //"thrface", "Threedshadow",
133 "window", "appworkspace",
134 "background", 
135 //"bshadow",
136 "buttontext", "highlight",
137 "highlighttext",
138 //"icaptiontext",
139 "infobackground",
140 "menutext", "scrollbar", 
141 //"thhighlight", "thlightshadow"
142                         };
143                 
144                         for (int i=0; i<colors.Length; i++)
145                                 Assert.AreEqual (colors[i], ColorTranslator.FromHtml (htmlColors [i]));
146                 }
147
148                 [Test]
149                 public void FromOle ()
150                 {
151                         Assert.AreEqual (Color.FromArgb (0x10, 0x20, 0x30), ColorTranslator.FromOle (0x302010));
152                         Assert.AreEqual (Color.FromArgb (0xbb, 0x20, 0x30), ColorTranslator.FromOle (unchecked ((int)0xee3020bb)));
153                 }
154
155                 [Test]
156                 public void FromWin32 ()
157                 {
158                         Assert.AreEqual (Color.FromArgb (0x10, 0x20, 0x30), ColorTranslator.FromWin32 (0x302010));
159                         Assert.AreEqual (Color.FromArgb (0xbb, 0x20, 0x30), ColorTranslator.FromWin32 (unchecked ((int)0xee3020bb)));
160                 }
161
162                 [Test]
163                 public void ToHtml ()
164                 {
165                         string [] htmlColors = new string [] {
166 "activeborder", "activecaption", "captiontext", "appworkspace", "buttonface",
167 "buttonshadow", "threeddarkshadow", "buttonface", "buttonhighlight", "buttontext",
168 "background", "graytext", "highlight", "highlighttext", "highlight", "inactiveborder",
169 "inactivecaption", "inactivecaptiontext", "infobackground", "infotext", "menu",
170 "menutext", "scrollbar", "window", "windowframe", "windowtext", 
171
172 "Transparent", "AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige",
173 "Bisque", "Black", "BlanchedAlmond", "Blue", "BlueViolet", "Brown", "BurlyWood",
174 "CadetBlue", "Chartreuse", "Chocolate", "Coral", "CornflowerBlue", "Cornsilk",
175 "Crimson", "Cyan", "DarkBlue", "DarkCyan", "DarkGoldenrod", "DarkGray", "DarkGreen",
176 "DarkKhaki", "DarkMagenta", "DarkOliveGreen", "DarkOrange", "DarkOrchid", "DarkRed",
177 "DarkSalmon", "DarkSeaGreen", "DarkSlateBlue", "DarkSlateGray", "DarkTurquoise", "DarkViolet",
178 "DeepPink", "DeepSkyBlue", "DimGray", "DodgerBlue", "Firebrick", "FloralWhite", "ForestGreen",
179 "Fuchsia", "Gainsboro", "GhostWhite", "Gold", "Goldenrod", "Gray", "Green", "GreenYellow",
180 "Honeydew", "HotPink", "IndianRed", "Indigo", "Ivory", "Khaki", "Lavender", "LavenderBlush",
181 "LawnGreen", "LemonChiffon", "LightBlue", "LightCoral", "LightCyan", "LightGoldenrodYellow",
182 "LightGrey", "LightGreen", "LightPink", "LightSalmon", "LightSeaGreen", "LightSkyBlue",
183 "LightSlateGray", "LightSteelBlue", "LightYellow", "Lime", "LimeGreen", "Linen", "Magenta",
184 "Maroon", "MediumAquamarine", "MediumBlue", "MediumOrchid", "MediumPurple", "MediumSeaGreen",
185 "MediumSlateBlue", "MediumSpringGreen", "MediumTurquoise", "MediumVioletRed", "MidnightBlue",
186 "MintCream", "MistyRose", "Moccasin", "NavajoWhite", "Navy", "OldLace", "Olive", "OliveDrab",
187 "Orange", "OrangeRed", "Orchid", "PaleGoldenrod", "PaleGreen", "PaleTurquoise", "PaleVioletRed",
188 "PapayaWhip", "PeachPuff", "Peru", "Pink", "Plum", "PowderBlue", "Purple", "Red", "RosyBrown",
189 "RoyalBlue", "SaddleBrown", "Salmon", "SandyBrown", "SeaGreen", "SeaShell", "Sienna", "Silver",
190 "SkyBlue", "SlateBlue", "SlateGray", "Snow", "SpringGreen", "SteelBlue", "Tan", "Teal",
191 "Thistle", "Tomato", "Turquoise", "Violet", "Wheat", "White", "WhiteSmoke", "Yellow", "YellowGreen",
192                                                                                         };
193
194                         for (KnownColor i=KnownColor.ActiveBorder; i<=KnownColor.YellowGreen; i++)
195                                 Assert.AreEqual (htmlColors[(int)i-1], ColorTranslator.ToHtml (Color.FromKnownColor (i)));
196                 }
197
198                 [Test]
199                 public void ToOle () {
200                         Assert.AreEqual (0x302010, ColorTranslator.ToOle (Color.FromArgb (0x10, 0x20, 0x30)));
201                         Assert.AreEqual (unchecked ((int)0x3020bb), ColorTranslator.ToOle (Color.FromArgb (0xee, 0xbb, 0x20, 0x30)));
202                 }
203
204                 [Test]
205                 public void ToWin32 () {
206                         Assert.AreEqual (0x302010, ColorTranslator.ToWin32 (Color.FromArgb (0x10, 0x20, 0x30)));
207                         Assert.AreEqual (unchecked ((int)0x3020bb), ColorTranslator.ToWin32 (Color.FromArgb (0xee, 0xbb, 0x20, 0x30)));
208                 }
209
210         }
211 }
212