Cookie test units
authorLawrence Pit <lawrence@mono-cvs.ximian.com>
Fri, 26 Apr 2002 20:40:08 +0000 (20:40 -0000)
committerLawrence Pit <lawrence@mono-cvs.ximian.com>
Fri, 26 Apr 2002 20:40:08 +0000 (20:40 -0000)
svn path=/trunk/mcs/; revision=4074

mcs/class/System/Test/System.Net/AllTests.cs
mcs/class/System/Test/System.Net/ChangeLog
mcs/class/System/Test/System.Net/CookieCollectionTest.cs [new file with mode: 0644]
mcs/class/System/Test/System.Net/CookieTest.cs [new file with mode: 0644]
mcs/class/corlib/Test/System.Net/AllTests.cs
mcs/class/corlib/Test/System.Net/ChangeLog
mcs/class/corlib/Test/System.Net/CookieCollectionTest.cs [new file with mode: 0644]
mcs/class/corlib/Test/System.Net/CookieTest.cs [new file with mode: 0644]

index 9b997e8a220ceb961bb32c0fb0d44b40e81d2288..2414ae34fe7e4a6b16005fd255195987de80cd4a 100644 (file)
@@ -22,6 +22,9 @@ namespace MonoTests.System.Net {
                                 TestSuite suite = new TestSuite();
                                 suite.AddTest (IPAddressTest.Suite);
                                 suite.AddTest (IPEndPointTest.Suite);
+                                suite.AddTest (CookieTest.Suite);
+                                suite.AddTest (CookieCollectionTest.Suite);
+                                // suite.AddTest (CookieContainerTest.Suite);
                                return suite;
                         }
                 }
index 48de8c30fc0dc5e8ecddf1278e2ffd53a5130b08..fad7d34ed8e1880b22c4927bf859e760229830a4 100644 (file)
@@ -1,3 +1,8 @@
+2002-04-27  Lawrence Pit <loz@cable.a2000.nl>
+       * CookieTest.cs
+       * CookieCollectionTest.cs
+       * AllTests.cs
+
 2002-04-24  Nick Drochak  <ndrochak@gol.com>
 
        * IPAddressTest.cs: Make test conform to MS behavior. Also, if wrong 
diff --git a/mcs/class/System/Test/System.Net/CookieCollectionTest.cs b/mcs/class/System/Test/System.Net/CookieCollectionTest.cs
new file mode 100644 (file)
index 0000000..9d5e53e
--- /dev/null
@@ -0,0 +1,123 @@
+//\r
+// CookieCollectionTest.cs - NUnit Test Cases for System.Net.CookieCollection\r
+//\r
+// Author:\r
+//   Lawrence Pit (loz@cable.a2000.nl)\r
+//\r
+\r
+using NUnit.Framework;\r
+using System;\r
+using System.Net;\r
+using System.Collections;\r
+\r
+namespace MonoTests.System.Net\r
+{\r
+\r
+public class CookieCollectionTest : TestCase\r
+{\r
+       CookieCollection col;\r
+       \r
+        public CookieCollectionTest () :\r
+                base ("[MonoTests.System.Net.CookieCollectionTest]") {}\r
+\r
+        public CookieCollectionTest (string name) : base (name) {}\r
+\r
+        protected override void SetUp () \r
+        {\r
+               col = new CookieCollection ();  \r
+               col.Add (new Cookie ("name1", "value1"));\r
+               col.Add (new Cookie ("name2", "value2", "path2"));\r
+               col.Add (new Cookie ("name3", "value3", "path3", "domain3"));           \r
+       }\r
+\r
+        protected override void TearDown () {}\r
+\r
+        public static ITest Suite\r
+        {\r
+                get {\r
+                        return new TestSuite (typeof (CookieCollectionTest));\r
+                }\r
+        }\r
+        \r
+        public void TestCount ()\r
+        {\r
+               AssertEquals ("#1", col.Count, 3);\r
+       }\r
+\r
+        public void TestIndexer ()\r
+        {\r
+               Cookie c = null;\r
+               try {\r
+                       c = col [-1];\r
+                       Fail ("#1");\r
+               } catch (ArgumentOutOfRangeException) {\r
+               }\r
+               try {\r
+                       c = col [col.Count];\r
+                       Fail ("#2");\r
+               } catch (ArgumentOutOfRangeException) {\r
+               }\r
+               c = col ["name1"];\r
+               AssertEquals ("#3", c.Name, "name1");\r
+               c = col ["NAME2"];\r
+               AssertEquals ("#4", c.Name, "name2");\r
+       }\r
+       \r
+       public void TestAdd ()\r
+       {\r
+               try {\r
+                       Cookie c = null;\r
+                       col.Add (c);\r
+                       Fail ("#1");\r
+               } catch (ArgumentNullException) {\r
+               }\r
+               \r
+               // in the microsoft implementation this will fail,\r
+               // so we'll have to fail to.\r
+               try {\r
+                       col.Add (col);\r
+                       Fail ("#2");\r
+               } catch (Exception) {\r
+               }\r
+               AssertEquals ("#3", col.Count, 3);\r
+               \r
+               col.Add (new Cookie("name1", "value1"));                \r
+               AssertEquals ("#4", col.Count, 3);\r
+               \r
+               CookieCollection col2 = new CookieCollection();\r
+               Cookie c4 = new Cookie("name4", "value4");\r
+               Cookie c5 = new Cookie("name5", "value5");\r
+               col2.Add (c4);\r
+               col2.Add (c5);\r
+               col.Add (col2);\r
+               AssertEquals ("#5", col.Count, 5);\r
+               AssertEquals ("#6", col ["NAME4"], c4);\r
+               AssertEquals ("#7", col [4], c5);\r
+       }\r
+       \r
+       public void TestCopyTo ()\r
+       {\r
+               Array a = Array.CreateInstance (typeof (Cookie), 3);\r
+               col.CopyTo (a, 0);\r
+               AssertEquals ("#1", a.GetValue (0), col [0]);\r
+               AssertEquals ("#2", a.GetValue (1), col [1]);\r
+               AssertEquals ("#3", a.GetValue (2), col [2]);\r
+       }\r
+       \r
+       public void TestEnumerator ()\r
+       {\r
+               IEnumerator enumerator = col.GetEnumerator ();\r
+               enumerator.MoveNext ();\r
+               Cookie c = (Cookie) enumerator.Current;\r
+               AssertEquals ("#1", c, col [0]);\r
+               col.Add (new Cookie ("name6", "value6"));\r
+               try {\r
+                       enumerator.MoveNext ();\r
+                       Fail ("#2");\r
+               } catch (InvalidOperationException) {\r
+               }\r
+       }\r
+}\r
+\r
+}\r
+\r
diff --git a/mcs/class/System/Test/System.Net/CookieTest.cs b/mcs/class/System/Test/System.Net/CookieTest.cs
new file mode 100644 (file)
index 0000000..6f9110b
--- /dev/null
@@ -0,0 +1,163 @@
+//\r
+// CookieTest.cs - NUnit Test Cases for System.Net.Cookie\r
+//\r
+// Author:\r
+//   Lawrence Pit (loz@cable.a2000.nl)\r
+//\r
+\r
+using NUnit.Framework;\r
+using System;\r
+using System.Net;\r
+\r
+namespace MonoTests.System.Net\r
+{\r
+\r
+public class CookieTest : TestCase\r
+{\r
+        public CookieTest () :\r
+                base ("[MonoTests.System.Net.CookieTest]") {}\r
+\r
+        public CookieTest (string name) : base (name) {}\r
+\r
+        protected override void SetUp () {}\r
+\r
+        protected override void TearDown () {}\r
+\r
+        public static ITest Suite\r
+        {\r
+                get {\r
+                        return new TestSuite (typeof (CookieTest));\r
+                }\r
+        }\r
+\r
+        public void TestPublicFields ()\r
+        {\r
+        }\r
+\r
+        public void TestConstructors ()\r
+        {\r
+               Cookie c = new Cookie ("somename", null, null, null);\r
+               try {\r
+                       c = new Cookie (null, null, null, null);\r
+                       Fail ("#1: Name cannot be null");\r
+               } catch (CookieException) {\r
+               }\r
+        }\r
+        \r
+        public void TestName ()         \r
+        {\r
+               Cookie c = new Cookie ("SomeName", "SomeValue");\r
+               AssertEquals ("#1", c.Name, "SomeName");\r
+               try {\r
+                       c.Name = null;\r
+                       Fail ("#2a");\r
+               } catch (CookieException) {\r
+                       AssertEquals ("#2b", "SomeName", c.Name);\r
+               }\r
+               try {\r
+                       c.Name = "";\r
+                       Fail ("#2c");\r
+               } catch (CookieException) {\r
+                       AssertEquals ("#2d", "SomeName", c.Name);                       \r
+               }\r
+               try {\r
+                       c.Name = " ";\r
+                       Fail ("#2e");                   \r
+               } catch (CookieException) {\r
+                       // bah! this fails, yet the name is changed.. \r
+                       // inconsistent with previous test\r
+                       AssertEquals ("#2f", String.Empty, c.Name);                     \r
+               }\r
+               try {\r
+                       c.Name = "xxx\r\n";\r
+                       Fail ("#2g");                   \r
+               } catch (CookieException ttt) {\r
+                       AssertEquals ("#2h", String.Empty, c.Name);                     \r
+               }               \r
+               try {\r
+                       c.Name = "xxx" + (char) 0x80;\r
+               } catch (CookieException) {\r
+                       Fail ("#2i");                   \r
+               }                               \r
+               try {\r
+                       c.Name = "$omeName";\r
+                       Fail ("#3a: Name cannot start with '$' character");\r
+               } catch (CookieException) {\r
+                       AssertEquals ("#3b", String.Empty, c.Name);\r
+               }\r
+               c.Name = "SomeName$";\r
+               AssertEquals ("#4", c.Name, "SomeName$");\r
+               try {\r
+                       c.Name = "Some=Name";\r
+                       Fail ("#5a: Name cannot contain '=' character");\r
+               } catch (CookieException) {\r
+                       AssertEquals ("#5b", String.Empty, c.Name);\r
+               }               \r
+               c.Name = "domain";\r
+               AssertEquals ("#6", c.Name, "domain");\r
+       }\r
+       \r
+       public void TestValue ()\r
+       {\r
+               // LAMESPEC: According to .Net specs the Value property should not accept \r
+               // the semicolon and comma characters, yet it does\r
+               Cookie c = new Cookie("SomeName", "SomeValue");\r
+               try {\r
+                       c.Value = "Some;Value";\r
+                       Fail ("#1: semicolon should not be accepted");\r
+               } catch (CookieException) {\r
+               }\r
+               try {\r
+                       c.Value = "Some,Value";\r
+                       Fail ("#2: comma should not be accepted");\r
+               } catch (CookieException) {\r
+               }\r
+               c.Value = "Some\tValue";\r
+               AssertEquals ("#3", c.Value, "Some\tValue");\r
+       }\r
+       \r
+       public void TestPort ()\r
+       {\r
+               Cookie c = new Cookie ("SomeName", "SomeValue");\r
+               try {\r
+                       c.Port = "123";\r
+                       Fail ("#1: port must start and end with double quotes");\r
+               } catch (CookieException) {                     \r
+               }\r
+               try {\r
+                       c.Port = "\"123\"";\r
+               } catch (CookieException) {                     \r
+                       Fail ("#2");\r
+               }\r
+               try {\r
+                       c.Port = "\"123;124\"";\r
+                       Fail ("#3");\r
+               } catch (CookieException) {                                     \r
+               }\r
+               try {\r
+                       c.Port = "\"123,123,124\"";\r
+               } catch (CookieException) {                     \r
+                       Fail ("#4");\r
+               }\r
+               try {\r
+                       c.Port = "\"123,124\"";\r
+               } catch (CookieException) {                     \r
+                       Fail ("#5");\r
+               }\r
+       }\r
+\r
+        public void TestEquals ()\r
+        {\r
+               Cookie c1 = new Cookie ("NAME", "VALUE", "PATH", "DOMAIN");\r
+               Cookie c2 = new Cookie ("name", "value", "path", "domain");\r
+               Assert("#1", !c1.Equals (c2));\r
+               c2.Value = "VALUE";\r
+               c2.Path = "PATH";\r
+               Assert("#2", c1.Equals (c2));\r
+               c2.Version = 1;\r
+               Assert("#3", !c1.Equals (c2));\r
+        }\r
+}\r
+\r
+}\r
+\r
index 9b997e8a220ceb961bb32c0fb0d44b40e81d2288..2414ae34fe7e4a6b16005fd255195987de80cd4a 100644 (file)
@@ -22,6 +22,9 @@ namespace MonoTests.System.Net {
                                 TestSuite suite = new TestSuite();
                                 suite.AddTest (IPAddressTest.Suite);
                                 suite.AddTest (IPEndPointTest.Suite);
+                                suite.AddTest (CookieTest.Suite);
+                                suite.AddTest (CookieCollectionTest.Suite);
+                                // suite.AddTest (CookieContainerTest.Suite);
                                return suite;
                         }
                 }
index 48de8c30fc0dc5e8ecddf1278e2ffd53a5130b08..fad7d34ed8e1880b22c4927bf859e760229830a4 100644 (file)
@@ -1,3 +1,8 @@
+2002-04-27  Lawrence Pit <loz@cable.a2000.nl>
+       * CookieTest.cs
+       * CookieCollectionTest.cs
+       * AllTests.cs
+
 2002-04-24  Nick Drochak  <ndrochak@gol.com>
 
        * IPAddressTest.cs: Make test conform to MS behavior. Also, if wrong 
diff --git a/mcs/class/corlib/Test/System.Net/CookieCollectionTest.cs b/mcs/class/corlib/Test/System.Net/CookieCollectionTest.cs
new file mode 100644 (file)
index 0000000..9d5e53e
--- /dev/null
@@ -0,0 +1,123 @@
+//\r
+// CookieCollectionTest.cs - NUnit Test Cases for System.Net.CookieCollection\r
+//\r
+// Author:\r
+//   Lawrence Pit (loz@cable.a2000.nl)\r
+//\r
+\r
+using NUnit.Framework;\r
+using System;\r
+using System.Net;\r
+using System.Collections;\r
+\r
+namespace MonoTests.System.Net\r
+{\r
+\r
+public class CookieCollectionTest : TestCase\r
+{\r
+       CookieCollection col;\r
+       \r
+        public CookieCollectionTest () :\r
+                base ("[MonoTests.System.Net.CookieCollectionTest]") {}\r
+\r
+        public CookieCollectionTest (string name) : base (name) {}\r
+\r
+        protected override void SetUp () \r
+        {\r
+               col = new CookieCollection ();  \r
+               col.Add (new Cookie ("name1", "value1"));\r
+               col.Add (new Cookie ("name2", "value2", "path2"));\r
+               col.Add (new Cookie ("name3", "value3", "path3", "domain3"));           \r
+       }\r
+\r
+        protected override void TearDown () {}\r
+\r
+        public static ITest Suite\r
+        {\r
+                get {\r
+                        return new TestSuite (typeof (CookieCollectionTest));\r
+                }\r
+        }\r
+        \r
+        public void TestCount ()\r
+        {\r
+               AssertEquals ("#1", col.Count, 3);\r
+       }\r
+\r
+        public void TestIndexer ()\r
+        {\r
+               Cookie c = null;\r
+               try {\r
+                       c = col [-1];\r
+                       Fail ("#1");\r
+               } catch (ArgumentOutOfRangeException) {\r
+               }\r
+               try {\r
+                       c = col [col.Count];\r
+                       Fail ("#2");\r
+               } catch (ArgumentOutOfRangeException) {\r
+               }\r
+               c = col ["name1"];\r
+               AssertEquals ("#3", c.Name, "name1");\r
+               c = col ["NAME2"];\r
+               AssertEquals ("#4", c.Name, "name2");\r
+       }\r
+       \r
+       public void TestAdd ()\r
+       {\r
+               try {\r
+                       Cookie c = null;\r
+                       col.Add (c);\r
+                       Fail ("#1");\r
+               } catch (ArgumentNullException) {\r
+               }\r
+               \r
+               // in the microsoft implementation this will fail,\r
+               // so we'll have to fail to.\r
+               try {\r
+                       col.Add (col);\r
+                       Fail ("#2");\r
+               } catch (Exception) {\r
+               }\r
+               AssertEquals ("#3", col.Count, 3);\r
+               \r
+               col.Add (new Cookie("name1", "value1"));                \r
+               AssertEquals ("#4", col.Count, 3);\r
+               \r
+               CookieCollection col2 = new CookieCollection();\r
+               Cookie c4 = new Cookie("name4", "value4");\r
+               Cookie c5 = new Cookie("name5", "value5");\r
+               col2.Add (c4);\r
+               col2.Add (c5);\r
+               col.Add (col2);\r
+               AssertEquals ("#5", col.Count, 5);\r
+               AssertEquals ("#6", col ["NAME4"], c4);\r
+               AssertEquals ("#7", col [4], c5);\r
+       }\r
+       \r
+       public void TestCopyTo ()\r
+       {\r
+               Array a = Array.CreateInstance (typeof (Cookie), 3);\r
+               col.CopyTo (a, 0);\r
+               AssertEquals ("#1", a.GetValue (0), col [0]);\r
+               AssertEquals ("#2", a.GetValue (1), col [1]);\r
+               AssertEquals ("#3", a.GetValue (2), col [2]);\r
+       }\r
+       \r
+       public void TestEnumerator ()\r
+       {\r
+               IEnumerator enumerator = col.GetEnumerator ();\r
+               enumerator.MoveNext ();\r
+               Cookie c = (Cookie) enumerator.Current;\r
+               AssertEquals ("#1", c, col [0]);\r
+               col.Add (new Cookie ("name6", "value6"));\r
+               try {\r
+                       enumerator.MoveNext ();\r
+                       Fail ("#2");\r
+               } catch (InvalidOperationException) {\r
+               }\r
+       }\r
+}\r
+\r
+}\r
+\r
diff --git a/mcs/class/corlib/Test/System.Net/CookieTest.cs b/mcs/class/corlib/Test/System.Net/CookieTest.cs
new file mode 100644 (file)
index 0000000..6f9110b
--- /dev/null
@@ -0,0 +1,163 @@
+//\r
+// CookieTest.cs - NUnit Test Cases for System.Net.Cookie\r
+//\r
+// Author:\r
+//   Lawrence Pit (loz@cable.a2000.nl)\r
+//\r
+\r
+using NUnit.Framework;\r
+using System;\r
+using System.Net;\r
+\r
+namespace MonoTests.System.Net\r
+{\r
+\r
+public class CookieTest : TestCase\r
+{\r
+        public CookieTest () :\r
+                base ("[MonoTests.System.Net.CookieTest]") {}\r
+\r
+        public CookieTest (string name) : base (name) {}\r
+\r
+        protected override void SetUp () {}\r
+\r
+        protected override void TearDown () {}\r
+\r
+        public static ITest Suite\r
+        {\r
+                get {\r
+                        return new TestSuite (typeof (CookieTest));\r
+                }\r
+        }\r
+\r
+        public void TestPublicFields ()\r
+        {\r
+        }\r
+\r
+        public void TestConstructors ()\r
+        {\r
+               Cookie c = new Cookie ("somename", null, null, null);\r
+               try {\r
+                       c = new Cookie (null, null, null, null);\r
+                       Fail ("#1: Name cannot be null");\r
+               } catch (CookieException) {\r
+               }\r
+        }\r
+        \r
+        public void TestName ()         \r
+        {\r
+               Cookie c = new Cookie ("SomeName", "SomeValue");\r
+               AssertEquals ("#1", c.Name, "SomeName");\r
+               try {\r
+                       c.Name = null;\r
+                       Fail ("#2a");\r
+               } catch (CookieException) {\r
+                       AssertEquals ("#2b", "SomeName", c.Name);\r
+               }\r
+               try {\r
+                       c.Name = "";\r
+                       Fail ("#2c");\r
+               } catch (CookieException) {\r
+                       AssertEquals ("#2d", "SomeName", c.Name);                       \r
+               }\r
+               try {\r
+                       c.Name = " ";\r
+                       Fail ("#2e");                   \r
+               } catch (CookieException) {\r
+                       // bah! this fails, yet the name is changed.. \r
+                       // inconsistent with previous test\r
+                       AssertEquals ("#2f", String.Empty, c.Name);                     \r
+               }\r
+               try {\r
+                       c.Name = "xxx\r\n";\r
+                       Fail ("#2g");                   \r
+               } catch (CookieException ttt) {\r
+                       AssertEquals ("#2h", String.Empty, c.Name);                     \r
+               }               \r
+               try {\r
+                       c.Name = "xxx" + (char) 0x80;\r
+               } catch (CookieException) {\r
+                       Fail ("#2i");                   \r
+               }                               \r
+               try {\r
+                       c.Name = "$omeName";\r
+                       Fail ("#3a: Name cannot start with '$' character");\r
+               } catch (CookieException) {\r
+                       AssertEquals ("#3b", String.Empty, c.Name);\r
+               }\r
+               c.Name = "SomeName$";\r
+               AssertEquals ("#4", c.Name, "SomeName$");\r
+               try {\r
+                       c.Name = "Some=Name";\r
+                       Fail ("#5a: Name cannot contain '=' character");\r
+               } catch (CookieException) {\r
+                       AssertEquals ("#5b", String.Empty, c.Name);\r
+               }               \r
+               c.Name = "domain";\r
+               AssertEquals ("#6", c.Name, "domain");\r
+       }\r
+       \r
+       public void TestValue ()\r
+       {\r
+               // LAMESPEC: According to .Net specs the Value property should not accept \r
+               // the semicolon and comma characters, yet it does\r
+               Cookie c = new Cookie("SomeName", "SomeValue");\r
+               try {\r
+                       c.Value = "Some;Value";\r
+                       Fail ("#1: semicolon should not be accepted");\r
+               } catch (CookieException) {\r
+               }\r
+               try {\r
+                       c.Value = "Some,Value";\r
+                       Fail ("#2: comma should not be accepted");\r
+               } catch (CookieException) {\r
+               }\r
+               c.Value = "Some\tValue";\r
+               AssertEquals ("#3", c.Value, "Some\tValue");\r
+       }\r
+       \r
+       public void TestPort ()\r
+       {\r
+               Cookie c = new Cookie ("SomeName", "SomeValue");\r
+               try {\r
+                       c.Port = "123";\r
+                       Fail ("#1: port must start and end with double quotes");\r
+               } catch (CookieException) {                     \r
+               }\r
+               try {\r
+                       c.Port = "\"123\"";\r
+               } catch (CookieException) {                     \r
+                       Fail ("#2");\r
+               }\r
+               try {\r
+                       c.Port = "\"123;124\"";\r
+                       Fail ("#3");\r
+               } catch (CookieException) {                                     \r
+               }\r
+               try {\r
+                       c.Port = "\"123,123,124\"";\r
+               } catch (CookieException) {                     \r
+                       Fail ("#4");\r
+               }\r
+               try {\r
+                       c.Port = "\"123,124\"";\r
+               } catch (CookieException) {                     \r
+                       Fail ("#5");\r
+               }\r
+       }\r
+\r
+        public void TestEquals ()\r
+        {\r
+               Cookie c1 = new Cookie ("NAME", "VALUE", "PATH", "DOMAIN");\r
+               Cookie c2 = new Cookie ("name", "value", "path", "domain");\r
+               Assert("#1", !c1.Equals (c2));\r
+               c2.Value = "VALUE";\r
+               c2.Path = "PATH";\r
+               Assert("#2", c1.Equals (c2));\r
+               c2.Version = 1;\r
+               Assert("#3", !c1.Equals (c2));\r
+        }\r
+}\r
+\r
+}\r
+\r