Преглед изворни кода

2006-08-27 Sebastien Pouliot <[email protected]>

	* ColorConverter.cs: Add a new test case for a color with a integer 
	part that is too large to convert into an int.
	* ColorTranslator.cs: Add more test cases for FromHtml method.


svn path=/trunk/mcs/; revision=64455
Sebastien Pouliot пре 19 година
родитељ
комит
cf3756bc65

+ 6 - 0
mcs/class/System.Drawing/Test/System.Drawing/ChangeLog

@@ -1,3 +1,9 @@
+2006-08-27  Sebastien Pouliot  <[email protected]> 
+
+	* ColorConverter.cs: Add a new test case for a color with a integer 
+	part that is too large to convert into an int.
+	* ColorTranslator.cs: Add more test cases for FromHtml method.
+
 2006-08-25  Sebastien Pouliot  <[email protected]> 
 
 	* GDIPlusTest.cs: Fix ImageAttributes test case.

+ 7 - 0
mcs/class/System.Drawing/Test/System.Drawing/ColorConverter.cs

@@ -441,6 +441,13 @@ namespace MonoTests.System.Drawing {
 		public void GetStandardValuesExclusive () {
 			Assert.AreEqual (false, colconv.GetStandardValuesExclusive ());
 		}
+
+		[Test]
+		[ExpectedException (typeof (Exception))]
+		public void ConvertFromString_FromHtml_PoundTooLarge ()
+		{
+			colconv.ConvertFromString ("#100000000");
+		}
 	}
 }
 

+ 78 - 0
mcs/class/System.Drawing/Test/System.Drawing/ColorTranslator.cs

@@ -1,3 +1,28 @@
+//
+// ColorTranslator class testing unit
+//
+// Copyright (C) 2006 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;
@@ -8,6 +33,59 @@ namespace MonoTests.System.Drawing {
 	[TestFixture]
 	[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
 	public class ColorTranslatorFixture {
+
+		[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_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 (-1, ColorTranslator.FromHtml ("#FFFFFF").ToArgb (), "#FFFFFF");
+			Assert.AreEqual (-1, ColorTranslator.FromHtml ("#FFFFFFFF").ToArgb (), "#FFFFFFFF");
+		}
+
+		[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_Unkown ()
+		{
+			ColorTranslator.FromHtml ("unknown-color-test");
+		}
+
 		[Test]
 		public void FromHtml ()
 		{