2005-10-04 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.Drawing / Test / System.Drawing / ColorTranslator.cs
1 using System;
2 using System.Drawing;
3 using System.Security.Permissions;
4 using NUnit.Framework;
5
6 namespace MonoTests.System.Drawing {
7
8         [TestFixture]
9         [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
10         public class ColorTranslatorFixture {
11                 [Test]
12                 public void FromHtml ()
13                 {
14                         Color [] colors = new Color [] {
15 Color.Aqua, Color.Black, Color.Blue, Color.Fuchsia, Color.Gray,
16 Color.Green, Color.Lime, Color.Maroon, Color.Navy, Color.Olive,
17 Color.Purple, Color.Red, Color.Silver, Color.Teal, Color.White,
18 Color.Yellow,
19
20 SystemColors.ActiveBorder, SystemColors.ActiveCaption,
21 SystemColors.Control, 
22 //SystemColors.ControlLightLight,
23 SystemColors.ActiveCaptionText, SystemColors.GrayText,
24 //SystemColors.InactiveBorder, SystemColors.InactiveCaption,
25 SystemColors.InfoText, SystemColors.Menu,
26 SystemColors.ControlDarkDark, 
27 //SystemColors.ControlText, SystemColors.ControlDark,
28 SystemColors.Window,
29 SystemColors.AppWorkspace, SystemColors.Desktop,
30 //SystemColors.ControlDark,
31 SystemColors.ControlText,
32 SystemColors.Highlight, SystemColors.HighlightText,
33 //SystemColors.InactiveCaptionText,
34 SystemColors.Info,
35 SystemColors.MenuText, SystemColors.ScrollBar,
36 //SystemColors.ControlLight, SystemColors.ControlLightLight
37                         };
38                         string [] htmlColors = new string [] {
39 "Aqua", "Black", "Blue", "Fuchsia", "Gray", "Green",
40 "Lime", "Maroon", "Navy", "Olive", "Purple", "Red",
41 "Silver", "Teal", "White", "Yellow",
42
43 "activeborder", "activecaption", "buttonface",
44 //"buhighlight",
45 "captiontext", "graytext",
46 //"iborder", "Icaption", 
47 "infotext", "menu", "threeddarkshadow",
48 //"thrface", "Threedshadow",
49 "window", "appworkspace",
50 "background", 
51 //"bshadow",
52 "buttontext", "highlight",
53 "highlighttext",
54 //"icaptiontext",
55 "infobackground",
56 "menutext", "scrollbar", 
57 //"thhighlight", "thlightshadow"
58                         };
59                 
60                         for (int i=0; i<colors.Length; i++)
61                                 Assert.AreEqual (colors[i], ColorTranslator.FromHtml (htmlColors [i]));
62                 }
63
64                 [Test]
65                 public void FromOle ()
66                 {
67                         Assert.AreEqual (Color.FromArgb (0x10, 0x20, 0x30), ColorTranslator.FromOle (0x302010));
68                         Assert.AreEqual (Color.FromArgb (0xbb, 0x20, 0x30), ColorTranslator.FromOle (unchecked ((int)0xee3020bb)));
69                 }
70
71                 [Test]
72                 public void FromWin32 ()
73                 {
74                         Assert.AreEqual (Color.FromArgb (0x10, 0x20, 0x30), ColorTranslator.FromWin32 (0x302010));
75                         Assert.AreEqual (Color.FromArgb (0xbb, 0x20, 0x30), ColorTranslator.FromWin32 (unchecked ((int)0xee3020bb)));
76                 }
77
78                 [Test]
79                 public void ToHtml ()
80                 {
81                         string [] htmlColors = new string [] {
82 "activeborder", "activecaption", "captiontext", "appworkspace", "buttonface",
83 "buttonshadow", "threeddarkshadow", "buttonface", "buttonhighlight", "buttontext",
84 "background", "graytext", "highlight", "highlighttext", "highlight", "inactiveborder",
85 "inactivecaption", "inactivecaptiontext", "infobackground", "infotext", "menu",
86 "menutext", "scrollbar", "window", "windowframe", "windowtext", 
87
88 "Transparent", "AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine", "Azure", "Beige",
89 "Bisque", "Black", "BlanchedAlmond", "Blue", "BlueViolet", "Brown", "BurlyWood",
90 "CadetBlue", "Chartreuse", "Chocolate", "Coral", "CornflowerBlue", "Cornsilk",
91 "Crimson", "Cyan", "DarkBlue", "DarkCyan", "DarkGoldenrod", "DarkGray", "DarkGreen",
92 "DarkKhaki", "DarkMagenta", "DarkOliveGreen", "DarkOrange", "DarkOrchid", "DarkRed",
93 "DarkSalmon", "DarkSeaGreen", "DarkSlateBlue", "DarkSlateGray", "DarkTurquoise", "DarkViolet",
94 "DeepPink", "DeepSkyBlue", "DimGray", "DodgerBlue", "Firebrick", "FloralWhite", "ForestGreen",
95 "Fuchsia", "Gainsboro", "GhostWhite", "Gold", "Goldenrod", "Gray", "Green", "GreenYellow",
96 "Honeydew", "HotPink", "IndianRed", "Indigo", "Ivory", "Khaki", "Lavender", "LavenderBlush",
97 "LawnGreen", "LemonChiffon", "LightBlue", "LightCoral", "LightCyan", "LightGoldenrodYellow",
98 "LightGrey", "LightGreen", "LightPink", "LightSalmon", "LightSeaGreen", "LightSkyBlue",
99 "LightSlateGray", "LightSteelBlue", "LightYellow", "Lime", "LimeGreen", "Linen", "Magenta",
100 "Maroon", "MediumAquamarine", "MediumBlue", "MediumOrchid", "MediumPurple", "MediumSeaGreen",
101 "MediumSlateBlue", "MediumSpringGreen", "MediumTurquoise", "MediumVioletRed", "MidnightBlue",
102 "MintCream", "MistyRose", "Moccasin", "NavajoWhite", "Navy", "OldLace", "Olive", "OliveDrab",
103 "Orange", "OrangeRed", "Orchid", "PaleGoldenrod", "PaleGreen", "PaleTurquoise", "PaleVioletRed",
104 "PapayaWhip", "PeachPuff", "Peru", "Pink", "Plum", "PowderBlue", "Purple", "Red", "RosyBrown",
105 "RoyalBlue", "SaddleBrown", "Salmon", "SandyBrown", "SeaGreen", "SeaShell", "Sienna", "Silver",
106 "SkyBlue", "SlateBlue", "SlateGray", "Snow", "SpringGreen", "SteelBlue", "Tan", "Teal",
107 "Thistle", "Tomato", "Turquoise", "Violet", "Wheat", "White", "WhiteSmoke", "Yellow", "YellowGreen",
108                                                                                         };
109
110                         for (KnownColor i=KnownColor.ActiveBorder; i<=KnownColor.YellowGreen; i++)
111                                 Assert.AreEqual (htmlColors[(int)i-1], ColorTranslator.ToHtml (Color.FromKnownColor (i)));
112                 }
113
114                 [Test]
115                 public void ToOle () {
116                         Assert.AreEqual (0x302010, ColorTranslator.ToOle (Color.FromArgb (0x10, 0x20, 0x30)));
117                         Assert.AreEqual (unchecked ((int)0x3020bb), ColorTranslator.ToOle (Color.FromArgb (0xee, 0xbb, 0x20, 0x30)));
118                 }
119
120                 [Test]
121                 public void ToWin32 () {
122                         Assert.AreEqual (0x302010, ColorTranslator.ToWin32 (Color.FromArgb (0x10, 0x20, 0x30)));
123                         Assert.AreEqual (unchecked ((int)0x3020bb), ColorTranslator.ToWin32 (Color.FromArgb (0xee, 0xbb, 0x20, 0x30)));
124                 }
125
126         }
127 }
128