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

2004-06-05 Sebastien Pouliot <[email protected]>

	* HybridDictionaryTest.cs: Added cases with an empty diectionary.
	* NameValueCollectionTest.cs: Added tests to add and replace (set)
	existing values in collection. Added tests for CopyTo.

svn path=/trunk/mcs/; revision=28890
Sebastien Pouliot пре 21 година
родитељ
комит
d497ff12cd

+ 6 - 0
mcs/class/System/Test/System.Collections.Specialized/ChangeLog

@@ -1,3 +1,9 @@
+2004-06-05  Sebastien Pouliot  <[email protected]>
+
+	* HybridDictionaryTest.cs: Added cases with an empty diectionary.
+	* NameValueCollectionTest.cs: Added tests to add and replace (set) 
+	existing values in collection. Added tests for CopyTo.
+
 2004-01-01  Nick Drochak  <[email protected]>
 
 	* BitVector32Test.cs: Test some more values less than 1.

+ 9 - 1
mcs/class/System/Test/System.Collections.Specialized/HybridDictionaryTest.cs

@@ -16,7 +16,7 @@ using System.Collections.Specialized;
 namespace MonoTests.System.Collections.Specialized
 {
 	[TestFixture]
-	public class HybridDictionaryTest
+	public class HybridDictionaryTest : Assertion
 	{
 		[Test]
 		public void All ()
@@ -42,5 +42,13 @@ namespace MonoTests.System.Collections.Specialized
 			Assertion.AssertEquals ("#3", 12, dict.Count);
 			Assertion.AssertEquals ("#4", "eee", dict ["eee"]);	
 		}
+
+		[Test]
+		public void Empty () 
+		{
+			HybridDictionary hd = new HybridDictionary (true);
+			Assert ("null", !hd.Contains (null));
+			Assert ("unexisting", !hd.Contains ("unexisting"));
+		}
 	}        
 }

+ 175 - 3
mcs/class/System/Test/System.Collections.Specialized/NameValueCollectionTest.cs

@@ -1,9 +1,11 @@
 // created on 7/21/2001 at 2:36 PM
 //
 // Authors:
-//   Martin Willemoes Hansen ([email protected])
+//	Martin Willemoes Hansen ([email protected])
+//	Sebastien Pouliot  <[email protected]>
 //
 // (C) 2003 Martin Willemoes Hansen
+// Copyright (C) 2004 Novell (http://www.novell.com)
 //
 
 using System;
@@ -16,7 +18,7 @@ using NUnit.Framework;
 namespace MonoTests.System.Collections.Specialized {
 
 	[TestFixture]
-        public class NameValueCollectionTest {
+        public class NameValueCollectionTest : Assertion {
 
 		[Test]
 		public void GetValues ()
@@ -27,6 +29,176 @@ namespace MonoTests.System.Collections.Specialized {
 			Assertion.AssertEquals ("#2", null, col.GetValues (""));
 			Assertion.AssertEquals ("#3", null, col.GetValues ("NotExistent"));
 		}
+
+		[Test]
+		public void Add ()
+		{
+			NameValueCollection c = new NameValueCollection ();
+			c.Add ("mono", "mono");
+			c.Add ("!mono", null);
+			c.Add (null, "mono!");
+			AssertEquals ("Count", 3, c.Count);
+			AssertEquals ("mono", "mono", c ["mono"]);
+			AssertNull ("!mono", c ["!mono"]);
+			AssertEquals ("mono!", "mono!", c [null]);
+		}
+
+		[Test]
+		public void Add_Multiples ()
+		{
+			NameValueCollection c = new NameValueCollection ();
+			c.Add ("mono", "mono");
+			c.Add ("mono", "mono");
+			c.Add ("mono", "mono");
+			AssertEquals ("Count", 1, c.Count);
+			AssertEquals ("mono", "mono,mono,mono", c ["mono"]);
+		}
+
+		[Test]
+		public void Add_Multiples_Null ()
+		{
+			NameValueCollection c = new NameValueCollection ();
+			c.Add ("mono", "mono");
+			c.Add ("mono", null);
+			c.Add ("mono", "mono");
+			AssertEquals ("Count", 1, c.Count);
+			AssertEquals ("mono", "mono,mono", c ["mono"]);
+		}
+
+		[Test]
+		public void Add_NVC ()
+		{
+			NameValueCollection c1 = new NameValueCollection ();
+			NameValueCollection c2 = new NameValueCollection ();
+
+			c2.Add (c1);
+			AssertEquals ("c1.Count", 0, c1.Count);
+			AssertEquals ("c2.Count", 0, c2.Count);
+
+			c1.Add ("foo", "bar");
+			c2.Add ("bar", "foo");
+
+			AssertEquals ("c1.Count", 1, c1.Count);
+			AssertEquals ("c2.Count", 1, c2.Count);
+
+			c2.Add (c1);
+			AssertEquals ("c1.Count", 1, c1.Count);
+			AssertEquals ("c2.Count", 2, c2.Count);
+		}
+
+		[Test]
+//		[ExpectedException (typeof (ArgumentNullException))]
+		[ExpectedException (typeof (NullReferenceException))]
+		public void Add_NVC_Null ()
+		{
+			new NameValueCollection ().Add (null);
+		}
+
+		[Test]
+		public void Set_New ()
+		{
+			NameValueCollection c = new NameValueCollection ();
+			c.Set ("mono", "mono");
+			c.Set ("!mono", null);
+			c.Set (null, "mono!");
+			AssertEquals ("Count", 3, c.Count);
+			AssertEquals ("mono", "mono", c ["mono"]);
+			AssertNull ("!mono", c ["!mono"]);
+			AssertEquals ("mono!", "mono!", c [null]);
+		}
+
+		[Test]
+		public void Set_Replace ()
+		{
+			NameValueCollection c = new NameValueCollection ();
+			c.Add ("mono", "mono");
+			c.Add ("!mono", "!mono");
+			c.Add ("mono!", "mono!");
+			AssertEquals ("Count", 3, c.Count);
+			AssertEquals ("mono", "mono", c ["mono"]);
+			AssertEquals ("!mono", "!mono", c ["!mono"]);
+			AssertEquals ("mono!", "mono!", c ["mono!"]);
+
+			c.Set ("mono", "nomo");
+			c.Set ("!mono", null);
+			c.Set (null, "mono!");
+			AssertEquals ("Count", 4, c.Count); // mono! isn't removed
+			AssertEquals ("mono", "nomo", c ["mono"]);
+			AssertNull ("!mono", c ["!mono"]);
+			AssertEquals ("mono!1", "mono!", c ["mono!"]);
+			AssertEquals ("mono!2", "mono!", c [null]);
+		}
+
+		[Test]
+		public void CaseInsensitive () 
+		{
+			// default constructor is case insensitive
+			NameValueCollection c = new NameValueCollection ();
+			c.Add ("mono", "mono");
+			c.Add ("MoNo", "MoNo");
+			c.Add ("mOnO", "mOnO");
+			c.Add ("MONO", "MONO");
+			AssertEquals ("Count", 1, c.Count);
+		}
+
+		[Test]
+		public void CopyTo () 
+		{
+			string [] array = new string [4];
+			NameValueCollection c = new NameValueCollection ();
+			c.Add ("1", "mono");
+			c.Add ("2", "MoNo");
+			c.Add ("3", "mOnO");
+			c.Add ("4", "MONO");
+			c.CopyTo (array, 0);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void CopyTo_Null () 
+		{
+			NameValueCollection c = new NameValueCollection ();
+			c.CopyTo (null, 0);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentOutOfRangeException))]
+		public void CopyTo_NegativeIndex () 
+		{
+			string [] array = new string [4];
+			NameValueCollection c = new NameValueCollection ();
+			c.Add ("1", "mono");
+			c.Add ("2", "MoNo");
+			c.Add ("3", "mOnO");
+			c.Add ("4", "MONO");
+			c.CopyTo (array, -1);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentException))]
+		public void CopyTo_NotEnoughSpace () 
+		{
+			string [] array = new string [4];
+			NameValueCollection c = new NameValueCollection ();
+			c.Add ("1", "mono");
+			c.Add ("2", "MoNo");
+			c.Add ("3", "mOnO");
+			c.Add ("4", "MONO");
+			c.CopyTo (array, 2);
+		}
+
+		[Test]
+		// Note: not a RankException
+		[ExpectedException (typeof (ArgumentException))]
+		public void CopyTo_MultipleDimensionArray () 
+		{
+			string [,,] matrix = new string [2,3,4];
+			NameValueCollection c = new NameValueCollection ();
+			c.Add ("1", "mono");
+			c.Add ("2", "MoNo");
+			c.Add ("3", "mOnO");
+			c.Add ("4", "MONO");
+			c.CopyTo (matrix, 0);
+		}
 	}
 }
-