Test case suite for Collection class
authorChris J. Breisch <cjbreisch@mono-cvs.ximian.com>
Sun, 12 May 2002 17:22:38 +0000 (17:22 -0000)
committerChris J. Breisch <cjbreisch@mono-cvs.ximian.com>
Sun, 12 May 2002 17:22:38 +0000 (17:22 -0000)
svn path=/trunk/mcs/; revision=4569

mcs/class/Microsoft.VisualBasic/Test/AllTests.cs [new file with mode: 0644]
mcs/class/Microsoft.VisualBasic/Test/CollectionTest.cs [new file with mode: 0644]
mcs/class/Microsoft.VisualBasic/Test/Microsoft.VisualBasic_test.build [new file with mode: 0644]

diff --git a/mcs/class/Microsoft.VisualBasic/Test/AllTests.cs b/mcs/class/Microsoft.VisualBasic/Test/AllTests.cs
new file mode 100644 (file)
index 0000000..d8243d5
--- /dev/null
@@ -0,0 +1,30 @@
+// MonoTests.AllTests, Microsoft.VisualBasic.dll\r
+//\r
+// Author:\r
+//   Mario Martinez (mariom925@home.com)\r
+//\r
+// (C) Ximian, Inc.  http://www.ximian.com\r
+//\r
+\r
+using NUnit.Framework;\r
+namespace MonoTests\r
+{\r
+       /// <summary>\r
+       ///   Combines all unit tests for the Microsoft.VisualBasic.dll assembly\r
+       ///   into one test suite.\r
+       /// </summary>\r
+       public class AllTests : TestCase\r
+       {\r
+               public AllTests(string name) : base(name) {}\r
+               public AllTests() : base("Microsoft.VisualBasic.AllTests") {}\r
+\r
+               public static ITest Suite {\r
+                       get {\r
+                               TestSuite suite = new TestSuite();\r
+                               suite.AddTest (Microsoft.VisualBasic.CollectionTest.Suite);\r
+                               \r
+                               return suite;\r
+                       }\r
+               }\r
+       }\r
+}\r
diff --git a/mcs/class/Microsoft.VisualBasic/Test/CollectionTest.cs b/mcs/class/Microsoft.VisualBasic/Test/CollectionTest.cs
new file mode 100644 (file)
index 0000000..4143148
--- /dev/null
@@ -0,0 +1,535 @@
+// Collection.cs - NUnit Test Cases for Microsoft.VisualBasic.Collection\r
+//\r
+// Author:\r
+//   Chris J. Breisch (cjbreisch@altavista.net)\r
+//\r
+// (C) Chris J. Breisch\r
+// \r
+\r
+using NUnit.Framework;\r
+using System;\r
+using Microsoft.VisualBasic;\r
+using System.Collections;\r
+\r
+namespace MonoTests.Microsoft.VisualBasic\r
+{\r
+\r
+       public class CollectionTest : TestCase \r
+       {\r
+       \r
+               public CollectionTest() : base ("Microsoft.VisualBasic.Collection") {}\r
+               public CollectionTest(string name) : base(name) {}\r
+\r
+               protected override void SetUp() {}\r
+               protected override void TearDown() {}\r
+\r
+               public static ITest Suite {\r
+                       get { \r
+                               return new TestSuite(typeof(CollectionTest)); \r
+                       }\r
+               }\r
+\r
+               // Test Constructor\r
+               public void TestNew ()\r
+               {\r
+                       Collection c;\r
+\r
+                       c = new Collection();\r
+\r
+                       AssertNotNull("#N01", c);\r
+                       AssertEquals("#N02", 0, c.Count);\r
+               }\r
+\r
+               // Test Add method with Key == null\r
+               public void TestAddNoKey ()\r
+               {\r
+                       Collection c;\r
+\r
+                       c = new Collection();\r
+\r
+                       c.Add(typeof(int), null, null, null);\r
+                       c.Add(typeof(double), null, null, null);\r
+                       c.Add(typeof(string), null, null, null);\r
+                       \r
+                       AssertEquals("#ANK01", 3, c.Count);\r
+\r
+                       // Collection class is 1-based\r
+                       AssertEquals("#ANK02", typeof(string), c[3]);\r
+\r
+               }\r
+\r
+               // Test Add method with Key specified\r
+               public void TestAddKey ()\r
+               {\r
+                       Collection c;\r
+\r
+                       c = new Collection();\r
+\r
+                       c.Add("Baseball", "Base", null, null);\r
+                       c.Add("Football", "Foot", null, null);\r
+                       c.Add("Basketball", "Basket", null, null);\r
+                       c.Add("Volleyball", "Volley", null, null);\r
+\r
+                       AssertEquals("#AK01", 4, c.Count);\r
+\r
+                       // Collection class is 1-based\r
+                       AssertEquals("#AK02", "Baseball", c[1]);\r
+                       AssertEquals("#AK03", "Volleyball", c["Volley"]);\r
+\r
+               }\r
+\r
+               // Test Add method with Before specified and Key == null\r
+               public void TestAddBeforeNoKey ()\r
+               {\r
+                       Collection c;\r
+\r
+                       c = new Collection();\r
+\r
+                       c.Add(typeof(int), null, null, null);\r
+                       c.Add(typeof(double), null, 1, null);\r
+                       c.Add(typeof(string), null, 2, null);\r
+                       c.Add(typeof(object), null, 2, null);\r
+\r
+                       AssertEquals("#ABNK01", 4, c.Count);\r
+\r
+                       // Collection class is 1-based\r
+                       AssertEquals("#ABNK02", typeof(int), c[4]);\r
+                       AssertEquals("#ABNK03", typeof(double), c[1]);\r
+                       AssertEquals("#ABNK04", typeof(object), c[2]);\r
+\r
+               }\r
+\r
+               // Test Add method with Before and Key\r
+               public void TestAddBeforeKey ()\r
+               {\r
+                       Collection c;\r
+\r
+                       c = new Collection();\r
+\r
+                       c.Add("Baseball", "Base", null, null);\r
+                       c.Add("Football", "Foot", 1, null);\r
+                       c.Add("Basketball", "Basket", 1, null);\r
+                       c.Add("Volleyball", "Volley", 3, null);\r
+\r
+                       AssertEquals("#ABK01", 4, c.Count);\r
+                       AssertEquals("#ABK02", "Basketball", c[1]);\r
+                       AssertEquals("#ABK03", "Baseball", c[4]);\r
+                       AssertEquals("#ABK04", "Volleyball", c["Volley"]);\r
+                       AssertEquals("#ABK05", "Football", c["Foot"]);\r
+\r
+               }\r
+\r
+               // Test Add method with After specified and Key == null\r
+               public void TestAddAfterNoKey ()\r
+               {\r
+                       Collection c;\r
+\r
+                       c = new Collection();\r
+\r
+                       c.Add(typeof(int), null, null, 0);\r
+                       c.Add(typeof(double), null, null, 1);\r
+                       c.Add(typeof(string), null, null, 1);\r
+                       c.Add(typeof(object), null, null, 3);\r
+\r
+                       AssertEquals("#AANK01", 4, c.Count);\r
+\r
+                       // Collection class is 1-based\r
+                       AssertEquals("#AANK02", typeof(object), c[4]);\r
+                       AssertEquals("#AANK03", typeof(int), c[1]);\r
+                       AssertEquals("#AANK04", typeof(string), c[2]);\r
+\r
+               }\r
+\r
+               // Test Add method with After and Key\r
+               public void TestAddAfterKey ()\r
+               {\r
+                       Collection c;\r
+\r
+                       c = new Collection();\r
+\r
+                       c.Add("Baseball", "Base", null, 0);\r
+                       c.Add("Football", "Foot", null, 1);\r
+                       c.Add("Basketball", "Basket", null, 1);\r
+                       c.Add("Volleyball", "Volley", null, 2);\r
+\r
+                       AssertEquals("#AAK01", 4, c.Count);\r
+\r
+                       // Collection class is 1-based\r
+                       AssertEquals("#AAK02", "Baseball", c[1]);\r
+                       AssertEquals("#AAK03", "Football", c[4]);\r
+                       AssertEquals("#AAK04", "Basketball", c["Basket"]);\r
+                       AssertEquals("#AAK05", "Volleyball", c["Volley"]);\r
+               }\r
+\r
+               // Test GetEnumerator method\r
+               public void TestGetEnumerator ()\r
+               {\r
+                       Collection c;\r
+                       IEnumerator e;\r
+                       object[] o = new object[4] {typeof(int), \r
+                               typeof(double), typeof(string), typeof(object)};\r
+                       int i = 0;\r
+\r
+                       c = new Collection();\r
+\r
+                       c.Add(typeof(int), null, null, null);\r
+                       c.Add(typeof(double), null, null, null);\r
+                       c.Add(typeof(string), null, null, null);\r
+                       c.Add(typeof(object), null, null, null);\r
+\r
+                       e = c.GetEnumerator();\r
+\r
+                       AssertNotNull("#GE01", e);\r
+\r
+                       while (e.MoveNext()) {\r
+                               AssertEquals("#GE02." + i.ToString(), o[i], e.Current);\r
+                               i++;\r
+                       }\r
+\r
+                       e.Reset();\r
+                       e.MoveNext();\r
+\r
+                       AssertEquals("#GE03", o[0], e.Current);\r
+\r
+               }\r
+\r
+               // Test GetEnumerator method again, this time using foreach\r
+               public void Testforeach ()\r
+               {\r
+                       Collection c;\r
+                       object[] o = new object[4] {typeof(int), \r
+                               typeof(double), typeof(string), typeof(object)};\r
+                       int i = 0;\r
+                       \r
+                       c = new Collection();\r
+\r
+                       c.Add(typeof(int), null, null, null);\r
+                       c.Add(typeof(double), null, null, null);\r
+                       c.Add(typeof(string), null, null, null);\r
+                       c.Add(typeof(object), null, null, null);\r
+\r
+                       \r
+                       foreach (object item in c) {\r
+                               AssertEquals("#fe01." + i.ToString(), o[i], item);\r
+                               i++;\r
+                       }\r
+                       \r
+               }\r
+\r
+               // Test Remove method with Index\r
+               public void TestRemoveNoKey ()\r
+               {\r
+                       Collection c;\r
+\r
+                       c = new Collection();\r
+\r
+                       c.Add(typeof(int), null, null, null);\r
+                       c.Add(typeof(double), null, null, null);\r
+                       c.Add(typeof(string), null, null, null);\r
+                       c.Add(typeof(object), null, null, null);\r
+\r
+                       AssertEquals("#RNK01", 4, c.Count);\r
+\r
+                       c.Remove(3);\r
+\r
+                       AssertEquals("#RNK02", 3, c.Count);\r
+\r
+                       // Collection class is 1-based\r
+                       AssertEquals("#RNK03", typeof(object), c[3]);\r
+\r
+                       c.Remove(1);\r
+\r
+                       AssertEquals("#RNK04", 2, c.Count);\r
+                       AssertEquals("#RNK05", typeof(double), c[1]);\r
+                       AssertEquals("#RNK06", typeof(object), c[2]);\r
+\r
+                       c.Remove(2);\r
+\r
+                       AssertEquals("#RNK07", 1, c.Count);\r
+                       AssertEquals("#RNK08", typeof(double), c[1]);\r
+\r
+                       c.Remove(1);\r
+\r
+                       AssertEquals("#RNK09", 0, c.Count);\r
+               \r
+               }\r
+\r
+               // Test Remove method with Key\r
+               public void TestRemoveKey ()\r
+               {\r
+                       Collection c;\r
+\r
+                       c = new Collection();\r
+\r
+                       c.Add("Baseball", "Base", null, null);\r
+                       c.Add("Football", "Foot", null, null);\r
+                       c.Add("Basketball", "Basket", null, null);\r
+                       c.Add("Volleyball", "Volley", null, null);\r
+\r
+                       AssertEquals("#RK01", 4, c.Count);\r
+\r
+                       c.Remove("Foot");\r
+\r
+                       AssertEquals("#RK02", 3, c.Count);\r
+                       AssertEquals("#RK03", "Basketball", c["Basket"]);\r
+\r
+                       // Collection class is 1-based\r
+                       AssertEquals("#RK04", "Volleyball", c[3]);\r
+\r
+                       c.Remove("Base");\r
+\r
+                       AssertEquals("#RK05", 2, c.Count);\r
+                       AssertEquals("#RK06", "Basketball", c[1]);\r
+                       AssertEquals("#RK07", "Volleyball", c["Volley"]);\r
+\r
+                       c.Remove(2);\r
+\r
+                       AssertEquals("#RK08", 1, c.Count);\r
+                       AssertEquals("#RK09", "Basketball", c[1]);\r
+                       AssertEquals("#RK10", "Basketball", c["Basket"]);\r
+\r
+                       c.Remove(1);\r
+\r
+                       AssertEquals("#RK11", 0, c.Count);\r
+               }\r
+\r
+               // Test all the Exceptions we're supposed to throw\r
+               public void TestException ()\r
+               {\r
+                       Collection c;\r
+                       bool CaughtException = false;\r
+\r
+                       c = new Collection();\r
+\r
+                       try {\r
+                               // nothing in Collection yet\r
+                               object o = c[0];\r
+                       }\r
+                       catch (Exception e) {\r
+                               AssertEquals("#E01", typeof(IndexOutOfRangeException), e.GetType());\r
+                               CaughtException = true;\r
+                       }\r
+\r
+                       AssertEquals("#E02", true, CaughtException);\r
+                \r
+                       c.Add("Baseball", "Base", null, null);\r
+                       c.Add("Football", "Foot", null, null);\r
+                       c.Add("Basketball", "Basket", null, null);\r
+                       c.Add("Volleyball", "Volley", null, null);\r
+\r
+                       CaughtException = false;\r
+\r
+                       try {\r
+                               // only 4 elements\r
+                               object o = c[5];\r
+                       }\r
+                       catch (Exception e) {\r
+                               AssertEquals("#E03", typeof(IndexOutOfRangeException), e.GetType());\r
+                               CaughtException = true;\r
+                       }\r
+\r
+                       AssertEquals("#E04", true, CaughtException);\r
+            \r
+                       CaughtException = false;\r
+                       \r
+                       try {\r
+                               // Collection class is 1-based\r
+                               object o = c[0];\r
+                       }\r
+                       catch (Exception e) {\r
+                               AssertEquals("#E05", typeof(IndexOutOfRangeException), e.GetType());\r
+                               CaughtException = true;\r
+                       }\r
+\r
+                       AssertEquals("#E06", true, CaughtException);\r
+            \r
+                       CaughtException = false;\r
+                       \r
+                       try {\r
+                               // no member with Key == "Kick"\r
+                               object o = c["Kick"];\r
+                       }\r
+                       catch (Exception e) {\r
+                               // FIXME\r
+                               // VB Language Reference says IndexOutOfRangeException \r
+                               // here, but MS throws ArgumentException\r
+                               // AssertEquals("#E07", typeof(IndexOutOfRangeException), e.GetType());\r
+                               AssertEquals("#E07", typeof(ArgumentException), e.GetType());\r
+                               CaughtException = true;\r
+                       }\r
+\r
+                       AssertEquals("#E08", true, CaughtException);\r
+         \r
+                       CaughtException = false;\r
+                       \r
+                       try {\r
+                               // Even though Indexer is an object, really it's a string\r
+                               object o = c[typeof(int)];\r
+                       }\r
+                       catch (Exception e) {\r
+                               AssertEquals("#E09", typeof(ArgumentException), e.GetType());\r
+                               CaughtException = true;\r
+                       }\r
+\r
+                       AssertEquals("#E10", true, CaughtException);\r
+         \r
+                       CaughtException = false;\r
+                       \r
+                       try {\r
+                               // can't specify both Before and After\r
+                               c.Add("Kickball", "Kick", "Volley", "Foot");\r
+                       }\r
+                       catch (Exception e) {\r
+                               AssertEquals("#E11", typeof(ArgumentException), e.GetType());\r
+                               CaughtException = true;\r
+                       }\r
+\r
+                       AssertEquals("#E12", true, CaughtException);\r
+         \r
+                       CaughtException = false;\r
+                       \r
+                       try {\r
+                               // Key "Foot" already exists\r
+                               c.Add("Kickball", "Foot", null, null);\r
+                       }\r
+                       catch (Exception e) {\r
+                               AssertEquals("#E13", typeof(ArgumentException), e.GetType());\r
+                               CaughtException = true;\r
+                       }\r
+\r
+                       AssertEquals("#E14", true, CaughtException);\r
+\r
+                       CaughtException = false;\r
+                       \r
+                       try {\r
+                               // Even though Before is object, it's really a string\r
+                               c.Add("Dodgeball", "Dodge", typeof(int), null);\r
+                       }\r
+                       catch (Exception e) {\r
+                               AssertEquals("#E15", typeof(InvalidCastException), e.GetType());\r
+                               CaughtException = true;\r
+                       }\r
+\r
+                       AssertEquals("#E16", true, CaughtException);\r
+        \r
+                       CaughtException = false;\r
+                       \r
+                       try {\r
+                               // Even though After is object, it's really a string\r
+                               c.Add("Wallyball", "Wally", null, typeof(int));\r
+                       }\r
+                       catch (Exception e) {\r
+                               AssertEquals("#E17", typeof(InvalidCastException), e.GetType());\r
+                               CaughtException = true;\r
+                       }\r
+\r
+                       AssertEquals("#E18", true, CaughtException);\r
+        \r
+                       CaughtException = false;\r
+                       \r
+                       try {\r
+                               // have to pass a legitimate value to remove\r
+                               c.Remove(null);\r
+                       }\r
+                       catch (Exception e) {\r
+                               AssertEquals("#E19", typeof(ArgumentException), e.GetType());\r
+                               CaughtException = true;\r
+                       }\r
+\r
+                       AssertEquals("#E20", true, CaughtException);\r
+        \r
+                       CaughtException = false;\r
+                       \r
+                       try {\r
+                               // no Key "Golf" exists\r
+                               c.Remove("Golf");\r
+                       }\r
+                       catch (Exception e) {\r
+                               AssertEquals("#E21", typeof(ArgumentException), e.GetType());\r
+                               CaughtException = true;\r
+                       }\r
+\r
+                       AssertEquals("#E22", true, CaughtException);\r
+        \r
+                       CaughtException = false;\r
+                       \r
+                       try {\r
+                               // no Index 10 exists\r
+                               c.Remove(10);\r
+                       }\r
+                       catch (Exception e) {\r
+                               AssertEquals("#E23", typeof(IndexOutOfRangeException), e.GetType());\r
+                               CaughtException = true;\r
+                       }\r
+\r
+                       AssertEquals("#E24", true, CaughtException);\r
+        \r
+                       CaughtException = false;\r
+                       \r
+                       try {\r
+                               IEnumerator e = c.GetEnumerator();\r
+                               \r
+                               // Must MoveNext before Current\r
+                               object item = e.Current;\r
+                       }\r
+                       catch (Exception e) {\r
+                               // FIXME\r
+                               // On-line help says InvalidOperationException here, \r
+                               // but MS throws IndexOutOfRangeException\r
+                               // AssertEquals("#E25", typeof(InvalidOperationException), e.GetType());\r
+                               AssertEquals("#E25", typeof(IndexOutOfRangeException), e.GetType());\r
+                               CaughtException = true;\r
+                       }\r
+\r
+                       AssertEquals("#E26", true, CaughtException);\r
+        \r
+                       CaughtException = false;\r
+                       \r
+                       try {\r
+                               IEnumerator e = c.GetEnumerator();\r
+                               e.MoveNext();\r
+\r
+                               c.Add("Paintball", "Paint", null, null);\r
+\r
+                               // Can't MoveNext if Collection has been modified\r
+                               e.MoveNext();\r
+                       }\r
+                       catch (Exception e) {\r
+                               // FIXME\r
+                               // On-line help says this should throw an error. MS doesn't.\r
+                               AssertEquals("#E27", typeof(InvalidOperationException), e.GetType());\r
+                               CaughtException = true;\r
+                       }\r
+\r
+                       // FIXME\r
+                       // What to do about this?  MS doesn't throw an error\r
+                       // AssertEquals("#E28", true, CaughtException);\r
+                       AssertEquals("#E28", false, CaughtException);\r
+        \r
+                       CaughtException = false;\r
+                       \r
+                       try {\r
+                               IEnumerator e = c.GetEnumerator();\r
+                               e.MoveNext();\r
+\r
+                               c.Add("Racketball", "Racket", null, null);\r
+\r
+                               // Can't Reset if Collection has been modified\r
+                               e.Reset();\r
+                       }\r
+                       catch (Exception e) {\r
+                               // FIXME\r
+                               // On-line help says this should throw an error.  MS doesn't.\r
+                               AssertEquals("#E29", typeof(InvalidOperationException), e.GetType());\r
+                               CaughtException = true;\r
+                       }\r
+\r
+                       // FIXME\r
+                       // What to do about this?  MS doesn't throw an error\r
+                       // AssertEquals("#E30", true, CaughtException);\r
+                       AssertEquals("#E30", false, CaughtException);\r
+\r
+                       CaughtException = false;\r
+               }\r
+       }\r
+}\r
diff --git a/mcs/class/Microsoft.VisualBasic/Test/Microsoft.VisualBasic_test.build b/mcs/class/Microsoft.VisualBasic/Test/Microsoft.VisualBasic_test.build
new file mode 100644 (file)
index 0000000..bddaad6
--- /dev/null
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="iso-8859-1"?>\r
+\r
+<!-- NAnt build file for System.Data_test.dll -->\r
+<!-- Target build (default) builds tests -->\r
+<!-- Target test runs tests -->\r
+\r
+<project name="System.Data_test" default="build">\r
+       <property name="debug" value="false"/>\r
+       <property name="nunit_home" value="..\..\..\nunit"/>\r
+\r
+       <target name="build">\r
+       </target>\r
+\r
+       <target name="assemblies">\r
+               <csc target="library" output="Microsoft.VisualBasic_test.dll" debug="${debug}">\r
+                       <arg value="/nowarn:1595"/>\r
+                       <sources>\r
+                               <includes name="**/*.cs"/>\r
+                               <excludes name="TheTests.cs"/>\r
+                       </sources>\r
+                       <references basedir="..\..\..\nunit">\r
+                               <includes name="NUnitCore.dll"/>\r
+                       </references>\r
+                       <arg value="/noconfig"/>        <!-- don't reference ms assemblies -->\r
+                       <arg value="/lib:../../lib/"/>\r
+                       \r
+                       <!-- cor compare dies with these currently -->\r
+                       <!--arg value="/nostdlib"/-->   <!-- don't reference mscorlib -->\r
+                       <!--arg value="/r:corlib.dll"/-->\r
+                       <arg value="/noconfig"/>        <!-- don't reference ms assemblies -->\r
+                       <arg value="/r:System.dll"/>\r
+                       <arg value="/r:.\Microsoft.VisualBasic.dll"/>\r
+               </csc>\r
+\r
+<!--\r
+               <csc target="exe" output="RunTests.Microsoft.VisualBasic.exe" debug="${debug}">\r
+                       <sources>\r
+                               <includes name="**/*.cs"/>\r
+                               <excludes name="AllTests.cs"/>\r
+                       </sources>\r
+                       <references basedir="..\..\..\nunit">\r
+                               <includes name="NUnitBase.dll"/>\r
+                       </references>\r
+                       <arg value="/nowarn:1595"/>\r
+                       <arg value="/noconfig"/>\r
+                       <arg value="/r:..\..\lib\corlib.dll"/>\r
+                       <arg value="/r:..\..\lib\System.dll"/>\r
+                       <arg value="/r:..\..\lib\Microsoft.VisualBasic.dll"/>\r
+               </csc>\r
+\r
+-->\r
+       </target>\r
+\r
+       <target name="test" depends="assemblies">\r
+               <exec program="..\..\..\nunit\NUnitConsole" commandline="MonoTests.AllTests,Microsoft.VisualBasic_test.dll" failonerror="false"/>\r
+       </target>\r
+\r
+       <target name="clean">\r
+               <delete file="Microsoft.VisualBasic.dll" failonerror="false"/>\r
+               <delete file="Microsoft.VisualBasic_test.dll" failonerror="false"/>\r
+               <delete file="corlib.dll" failonerror="false"/>\r
+               <delete file="System.dll" failonerror="false"/>\r
+       </target>\r
+</project>\r