// // ColorTranslator class testing unit // // Copyright (C) 2006-2007 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; using System.Drawing; using System.Security.Permissions; using NUnit.Framework; namespace MonoTests.System.Drawing { [TestFixture] [SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)] public class ColorTranslatorTest { [Test] public void FromHtml_Null () { Assert.AreEqual (0, ColorTranslator.FromHtml (null).ToArgb ()); } [Test] public void FromHtml_Empty () { Assert.AreEqual (0, ColorTranslator.FromHtml (String.Empty).ToArgb ()); } [Test] public void FromHtml_KnownValues () { Assert.AreEqual (SystemColors.Control, ColorTranslator.FromHtml ("buttonface"), "buttonface"); Assert.AreEqual (SystemColors.ActiveCaptionText, ColorTranslator.FromHtml ("CAPTIONTEXT"), "captiontext"); Assert.AreEqual (SystemColors.ControlDarkDark, ColorTranslator.FromHtml ("threedDARKshadow"), "threeddarkshadow"); Assert.AreEqual (SystemColors.Desktop, ColorTranslator.FromHtml ("background"), "background"); Assert.AreEqual (SystemColors.ControlText, ColorTranslator.FromHtml ("ButtonText"), "buttontext"); Assert.AreEqual (SystemColors.Info, ColorTranslator.FromHtml ("infobackground"), "infobackground"); } [Test] public void FromHtml_Int () { Assert.AreEqual (-1, ColorTranslator.FromHtml ("-1").ToArgb (), "-1"); Assert.AreEqual (0, ColorTranslator.FromHtml ("0").ToArgb (), "0"); Assert.AreEqual (1, ColorTranslator.FromHtml ("1").ToArgb (), "1"); } [Test] public void FromHtml_PoundInt () { Assert.AreEqual (0, ColorTranslator.FromHtml ("#0").ToArgb (), "#0"); Assert.AreEqual (1, ColorTranslator.FromHtml ("#1").ToArgb (), "#1"); Assert.AreEqual (255, ColorTranslator.FromHtml ("#FF").ToArgb (), "#FF"); Assert.AreEqual (65535, ColorTranslator.FromHtml ("#FFFF").ToArgb (), "#FFFF"); Assert.AreEqual (-15584170, ColorTranslator.FromHtml ("#123456").ToArgb (), "#123456"); Assert.AreEqual (-1, ColorTranslator.FromHtml ("#FFFFFF").ToArgb (), "#FFFFFF"); Assert.AreEqual (305419896, ColorTranslator.FromHtml ("#12345678").ToArgb (), "#12345678"); Assert.AreEqual (-1, ColorTranslator.FromHtml ("#FFFFFFFF").ToArgb (), "#FFFFFFFF"); Assert.AreEqual (Color.White, ColorTranslator.FromHtml ("#FFFFFF"), "used to resolve to some KnownColor"); Assert.AreEqual (Color.White, ColorTranslator.FromHtml ("0xFFFFFF"), "used to resolve to some KnownColor"); } [Test] [ExpectedException (typeof (Exception))] public void FromHtml_PoundNegative () { ColorTranslator.FromHtml ("#-1"); } [Test] [ExpectedException (typeof (Exception))] public void FromHtml_PoundTooLarge () { ColorTranslator.FromHtml ("#100000000"); } [Test] [ExpectedException (typeof (Exception))] public void FromHtml_Unknown () { ColorTranslator.FromHtml ("unknown-color-test"); } [Test] public void FromHtml () { Color [] colors = new Color [] { Color.Aqua, Color.Black, Color.Blue, Color.Fuchsia, Color.Gray, Color.Green, Color.Lime, Color.Maroon, Color.Navy, Color.Olive, Color.Purple, Color.Red, Color.Silver, Color.Teal, Color.White, Color.Yellow, SystemColors.ActiveBorder, SystemColors.ActiveCaption, SystemColors.Control, //SystemColors.ControlLightLight, SystemColors.ActiveCaptionText, SystemColors.GrayText, //SystemColors.InactiveBorder, SystemColors.InactiveCaption, SystemColors.InfoText, SystemColors.Menu, SystemColors.ControlDarkDark, //SystemColors.ControlText, SystemColors.ControlDark, SystemColors.Window, SystemColors.AppWorkspace, SystemColors.Desktop, //SystemColors.ControlDark, SystemColors.ControlText, SystemColors.Highlight, SystemColors.HighlightText, //SystemColors.InactiveCaptionText, SystemColors.Info, SystemColors.MenuText, SystemColors.ScrollBar, //SystemColors.ControlLight, SystemColors.ControlLightLight }; string [] htmlColors = new string [] { "Aqua", "Black", "Blue", "Fuchsia", "Gray", "Green", "Lime", "Maroon", "Navy", "Olive", "Purple", "Red", "Silver", "Teal", "White", "Yellow", "activeborder", "activecaption", "buttonface", //"buhighlight", "captiontext", "graytext", //"iborder", "Icaption", "infotext", "menu", "threeddarkshadow", //"thrface", "Threedshadow", "window", "appworkspace", "background", //"bshadow", "buttontext", "highlight", "highlighttext", //"icaptiontext", "infobackground", "menutext", "scrollbar", //"thhighlight", "thlightshadow" }; for (int i=0; i