Kaynağa Gözat

2002-04-19 Gonzalo Paniagua Javier <[email protected]>

	* AllTests.cs: added IPEndPointTest.
	* IPEndPointTest.cs: added file (author: Lawrence Pit).
	* IPAdressTest.cs: use Fail is expected exception are not raised.

svn path=/trunk/mcs/; revision=3903
Gonzalo Paniagua Javier 24 yıl önce
ebeveyn
işleme
c303807db2

+ 1 - 0
mcs/class/System/Test/System.Net/AllTests.cs

@@ -21,6 +21,7 @@ namespace MonoTests.System.Net {
                         {
                                 TestSuite suite = new TestSuite();
                                 suite.AddTest (IPAddressTest.Suite);
+                                suite.AddTest (IPEndPointTest.Suite);
 				return suite;
                         }
                 }

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

@@ -1,3 +1,9 @@
+2002-04-19  Gonzalo Paniagua Javier <[email protected]>
+
+	* AllTests.cs: added IPEndPointTest.
+	* IPEndPointTest.cs: added file (author: Lawrence Pit).
+	* IPAdressTest.cs: use Fail is expected exception are not raised.
+
 2002-04-15  Gonzalo Paniagua Javier <[email protected]>
 
 	* IPAddressTest.cs: use System.BitConverter.IsLittleEndian (suggested

+ 4 - 0
mcs/class/System/Test/System.Net/IPAddressTest.cs

@@ -94,6 +94,7 @@ public class IPAddressTest : TestCase
 		failure = false;
 		try {
 			ip = IPAddress.Parse ("12.+1.1.4");
+                        Fail("Should raise a FormatException #1");
 		} catch (FormatException) {
 			failure = true;
 		}
@@ -103,6 +104,7 @@ public class IPAddressTest : TestCase
 		failure = false;
 		try {
 			ip = IPAddress.Parse ("12.1.-1.5");
+                        Fail("Should raise a FormatException #2");
 		} catch (FormatException) {
 			failure = true;
 		}
@@ -112,6 +114,7 @@ public class IPAddressTest : TestCase
 		failure = false;
 		try {
 			ip = IPAddress.Parse ("257.1.1.9");
+                        Fail("Should raise a FormatException #3");
 		} catch (FormatException) {
 			failure = true;
 		}
@@ -121,6 +124,7 @@ public class IPAddressTest : TestCase
 		failure = false;
 		try {
 			ip = IPAddress.Parse (null);
+                        Fail("Should raise a ArgumentNullException #1");
 		} catch (ArgumentNullException) {
 			failure = true;
 		}

+ 134 - 0
mcs/class/System/Test/System.Net/IPEndPointTest.cs

@@ -0,0 +1,134 @@
+//
+// IPEndPointTest.cs - NUnit Test Cases for System.Net.IPEndPoint
+//
+// Author:
+//   Lawrence Pit ([email protected])
+//
+
+using NUnit.Framework;
+using System;
+using System.Net;
+using System.Runtime.InteropServices;
+
+namespace MonoTests.System.Net
+{
+
+public class IPEndPointTest : TestCase
+{
+        private const int MyPort = 42;
+        private const int MyMaxPort = 65535;
+        private const int MyMinPort = 0;
+        private const string MyIPAddressString = "192.168.1.1";
+
+        private IPAddress ipAddress;
+        private long ip;
+        private IPEndPoint endPoint1;
+        private IPEndPoint endPoint2;
+
+        public IPEndPointTest () :
+                base ("[MonoTests.System.Net.IPEndPointTest]") {}
+
+        public IPEndPointTest (string name) : base (name) {}
+
+        protected override void SetUp ()
+        {
+                ipAddress = IPAddress.Parse (MyIPAddressString);
+                ip = ipAddress.Address;
+                endPoint1 = new IPEndPoint(ipAddress, MyPort);
+                endPoint2 = new IPEndPoint(ip, MyPort);
+        }
+
+        protected override void TearDown () {}
+
+        public static ITest Suite
+        {
+                get {
+                        return new TestSuite(typeof(IPEndPointTest));
+                }
+        }
+
+        public void TestPublicFields ()
+        {
+                AssertEquals ("MinPort", IPEndPoint.MinPort, MyMinPort);
+                AssertEquals ("MaxPort", IPEndPoint.MaxPort, MyMaxPort);
+        }
+
+        public void TestConstructors ()
+        {
+                try {
+                        new IPEndPoint(null, 0);
+                        Fail("Should raise an ArgumentNullException");
+                } catch (ArgumentNullException) {
+                }
+                try {
+                        new IPEndPoint(ipAddress, MyMinPort - 1);
+                        Fail("Should raise an ArgumentOutOfRangeException #1");
+                } catch (ArgumentOutOfRangeException) {
+                }
+                try {
+                        new IPEndPoint(ipAddress, MyMaxPort + 1);
+                        Fail("Should raise an ArgumentOutOfRangeException #2");
+                } catch (ArgumentOutOfRangeException) {
+                }
+
+                try {
+                        new IPEndPoint(ip, MyMinPort -1);
+                        Fail("Should raise an ArgumentOutOfRangeException #3");
+                } catch (ArgumentOutOfRangeException) {
+                }
+                try {
+                        new IPEndPoint(ip, MyMaxPort + 1);
+                        Fail("Should raise an ArgumentOutOfRangeException #4");
+                } catch (ArgumentOutOfRangeException) {
+                }
+        }
+
+        public void TestPortProperty ()
+        {
+                try {
+                        endPoint1.Port = MyMinPort - 1;
+                        Fail("Should raise an ArgumentOutOfRangeException #1");
+                } catch (ArgumentOutOfRangeException) {
+                }
+                try {
+                        endPoint1.Port = MyMaxPort + 1;
+                        Fail("Should raise an ArgumentOutOfRangeException #2");
+                } catch (ArgumentOutOfRangeException) {
+                }
+        }
+
+        public void TestCreateAndSerialize()
+        {
+		SocketAddress addr = endPoint1.Serialize();
+		EndPoint endPoint3 = endPoint2.Create(addr);
+		Assert("#1", endPoint1.Equals(endPoint3));
+
+		IPAddress ipAddress = IPAddress.Parse ("255.255.255.255");
+                IPEndPoint endPoint4 = new IPEndPoint(ipAddress, MyMaxPort);
+		addr = endPoint4.Serialize();
+		EndPoint endPoint5 = endPoint2.Create(addr);
+		Assert("#2", endPoint4.Equals(endPoint5));
+		AssertEquals("#3", endPoint5.ToString(), "255.255.255.255:" + MyMaxPort);
+	}
+
+        public void TestEquals ()
+        {
+                Assert("Equals", endPoint1.Equals(endPoint2));
+                Assert("Not Equals", !endPoint1.Equals(new IPEndPoint(ip, MyPort + 1)));
+        }
+
+        public void TestGetHashCode ()
+        {
+                AssertEquals(endPoint1.GetHashCode(), endPoint2.GetHashCode());
+        }
+
+        public void TestToString ()
+        {
+                AssertEquals("ToString #1", endPoint1.ToString(), MyIPAddressString + ":" + MyPort);
+                AssertEquals("ToString #2", endPoint2.ToString(), MyIPAddressString + ":" + MyPort);
+        }
+
+}
+
+}
+

+ 1 - 0
mcs/class/corlib/Test/System.Net/AllTests.cs

@@ -21,6 +21,7 @@ namespace MonoTests.System.Net {
                         {
                                 TestSuite suite = new TestSuite();
                                 suite.AddTest (IPAddressTest.Suite);
+                                suite.AddTest (IPEndPointTest.Suite);
 				return suite;
                         }
                 }

+ 6 - 0
mcs/class/corlib/Test/System.Net/ChangeLog

@@ -1,3 +1,9 @@
+2002-04-19  Gonzalo Paniagua Javier <[email protected]>
+
+	* AllTests.cs: added IPEndPointTest.
+	* IPEndPointTest.cs: added file (author: Lawrence Pit).
+	* IPAdressTest.cs: use Fail is expected exception are not raised.
+
 2002-04-15  Gonzalo Paniagua Javier <[email protected]>
 
 	* IPAddressTest.cs: use System.BitConverter.IsLittleEndian (suggested

+ 4 - 0
mcs/class/corlib/Test/System.Net/IPAddressTest.cs

@@ -94,6 +94,7 @@ public class IPAddressTest : TestCase
 		failure = false;
 		try {
 			ip = IPAddress.Parse ("12.+1.1.4");
+                        Fail("Should raise a FormatException #1");
 		} catch (FormatException) {
 			failure = true;
 		}
@@ -103,6 +104,7 @@ public class IPAddressTest : TestCase
 		failure = false;
 		try {
 			ip = IPAddress.Parse ("12.1.-1.5");
+                        Fail("Should raise a FormatException #2");
 		} catch (FormatException) {
 			failure = true;
 		}
@@ -112,6 +114,7 @@ public class IPAddressTest : TestCase
 		failure = false;
 		try {
 			ip = IPAddress.Parse ("257.1.1.9");
+                        Fail("Should raise a FormatException #3");
 		} catch (FormatException) {
 			failure = true;
 		}
@@ -121,6 +124,7 @@ public class IPAddressTest : TestCase
 		failure = false;
 		try {
 			ip = IPAddress.Parse (null);
+                        Fail("Should raise a ArgumentNullException #1");
 		} catch (ArgumentNullException) {
 			failure = true;
 		}

+ 134 - 0
mcs/class/corlib/Test/System.Net/IPEndPointTest.cs

@@ -0,0 +1,134 @@
+//
+// IPEndPointTest.cs - NUnit Test Cases for System.Net.IPEndPoint
+//
+// Author:
+//   Lawrence Pit ([email protected])
+//
+
+using NUnit.Framework;
+using System;
+using System.Net;
+using System.Runtime.InteropServices;
+
+namespace MonoTests.System.Net
+{
+
+public class IPEndPointTest : TestCase
+{
+        private const int MyPort = 42;
+        private const int MyMaxPort = 65535;
+        private const int MyMinPort = 0;
+        private const string MyIPAddressString = "192.168.1.1";
+
+        private IPAddress ipAddress;
+        private long ip;
+        private IPEndPoint endPoint1;
+        private IPEndPoint endPoint2;
+
+        public IPEndPointTest () :
+                base ("[MonoTests.System.Net.IPEndPointTest]") {}
+
+        public IPEndPointTest (string name) : base (name) {}
+
+        protected override void SetUp ()
+        {
+                ipAddress = IPAddress.Parse (MyIPAddressString);
+                ip = ipAddress.Address;
+                endPoint1 = new IPEndPoint(ipAddress, MyPort);
+                endPoint2 = new IPEndPoint(ip, MyPort);
+        }
+
+        protected override void TearDown () {}
+
+        public static ITest Suite
+        {
+                get {
+                        return new TestSuite(typeof(IPEndPointTest));
+                }
+        }
+
+        public void TestPublicFields ()
+        {
+                AssertEquals ("MinPort", IPEndPoint.MinPort, MyMinPort);
+                AssertEquals ("MaxPort", IPEndPoint.MaxPort, MyMaxPort);
+        }
+
+        public void TestConstructors ()
+        {
+                try {
+                        new IPEndPoint(null, 0);
+                        Fail("Should raise an ArgumentNullException");
+                } catch (ArgumentNullException) {
+                }
+                try {
+                        new IPEndPoint(ipAddress, MyMinPort - 1);
+                        Fail("Should raise an ArgumentOutOfRangeException #1");
+                } catch (ArgumentOutOfRangeException) {
+                }
+                try {
+                        new IPEndPoint(ipAddress, MyMaxPort + 1);
+                        Fail("Should raise an ArgumentOutOfRangeException #2");
+                } catch (ArgumentOutOfRangeException) {
+                }
+
+                try {
+                        new IPEndPoint(ip, MyMinPort -1);
+                        Fail("Should raise an ArgumentOutOfRangeException #3");
+                } catch (ArgumentOutOfRangeException) {
+                }
+                try {
+                        new IPEndPoint(ip, MyMaxPort + 1);
+                        Fail("Should raise an ArgumentOutOfRangeException #4");
+                } catch (ArgumentOutOfRangeException) {
+                }
+        }
+
+        public void TestPortProperty ()
+        {
+                try {
+                        endPoint1.Port = MyMinPort - 1;
+                        Fail("Should raise an ArgumentOutOfRangeException #1");
+                } catch (ArgumentOutOfRangeException) {
+                }
+                try {
+                        endPoint1.Port = MyMaxPort + 1;
+                        Fail("Should raise an ArgumentOutOfRangeException #2");
+                } catch (ArgumentOutOfRangeException) {
+                }
+        }
+
+        public void TestCreateAndSerialize()
+        {
+		SocketAddress addr = endPoint1.Serialize();
+		EndPoint endPoint3 = endPoint2.Create(addr);
+		Assert("#1", endPoint1.Equals(endPoint3));
+
+		IPAddress ipAddress = IPAddress.Parse ("255.255.255.255");
+                IPEndPoint endPoint4 = new IPEndPoint(ipAddress, MyMaxPort);
+		addr = endPoint4.Serialize();
+		EndPoint endPoint5 = endPoint2.Create(addr);
+		Assert("#2", endPoint4.Equals(endPoint5));
+		AssertEquals("#3", endPoint5.ToString(), "255.255.255.255:" + MyMaxPort);
+	}
+
+        public void TestEquals ()
+        {
+                Assert("Equals", endPoint1.Equals(endPoint2));
+                Assert("Not Equals", !endPoint1.Equals(new IPEndPoint(ip, MyPort + 1)));
+        }
+
+        public void TestGetHashCode ()
+        {
+                AssertEquals(endPoint1.GetHashCode(), endPoint2.GetHashCode());
+        }
+
+        public void TestToString ()
+        {
+                AssertEquals("ToString #1", endPoint1.ToString(), MyIPAddressString + ":" + MyPort);
+                AssertEquals("ToString #2", endPoint2.ToString(), MyIPAddressString + ":" + MyPort);
+        }
+
+}
+
+}
+