* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System / Test / System.Net / IPEndPointTest.cs
1 //
2 // IPEndPointTest.cs - NUnit Test Cases for System.Net.IPEndPoint
3 //
4 // Authors:
5 //   Lawrence Pit (loz@cable.a2000.nl)
6 //   Martin Willemoes Hansen (mwh@sysrq.dk)
7 //
8 // (C) 2003 Martin Willemoes Hansen
9 //
10
11 using NUnit.Framework;
12 using System;
13 using System.Net;
14 using System.Runtime.InteropServices;
15
16 namespace MonoTests.System.Net
17 {
18
19 [TestFixture]
20 public class IPEndPointTest
21 {
22         private const int MyPort = 42;
23         private const int MyMaxPort = 65535;
24         private const int MyMinPort = 0;
25         private const string MyIPAddressString = "192.168.1.1";
26
27         private IPAddress ipAddress;
28         private long ip;
29         private IPEndPoint endPoint1;
30         private IPEndPoint endPoint2;
31
32         [SetUp]
33         public void GetReady()
34         {
35                 ipAddress = IPAddress.Parse (MyIPAddressString);
36                 ip = ipAddress.Address;
37                 endPoint1 = new IPEndPoint (ipAddress, MyPort);
38                 endPoint2 = new IPEndPoint (ip, MyPort);
39         }
40
41         [Test]
42         public void PublicFields ()
43         {
44                 Assertion.AssertEquals ("MinPort", IPEndPoint.MinPort, MyMinPort);
45                 Assertion.AssertEquals ("MaxPort", IPEndPoint.MaxPort, MyMaxPort);
46         }
47
48         [Test]
49         public void Constructors ()
50         {
51                 try {
52                         new IPEndPoint (null, 0);
53                         Assertion.Fail ("Should raise an ArgumentNullException");
54                 } catch (ArgumentNullException) {
55                 }
56                 try {
57                         new IPEndPoint (ipAddress, MyMinPort - 1);
58                         Assertion.Fail ("Should raise an ArgumentOutOfRangeException #1");
59                 } catch (ArgumentOutOfRangeException) {
60                 }
61                 try {
62                         new IPEndPoint (ipAddress, MyMaxPort + 1);
63                         Assertion.Fail ("Should raise an ArgumentOutOfRangeException #2");
64                 } catch (ArgumentOutOfRangeException) {
65                 }
66
67                 try {
68                         new IPEndPoint (ip, MyMinPort -1);
69                         Assertion.Fail ("Should raise an ArgumentOutOfRangeException #3");
70                 } catch (ArgumentOutOfRangeException) {
71                 }
72                 try {
73                         new IPEndPoint (ip, MyMaxPort + 1);
74                         Assertion.Fail ("Should raise an ArgumentOutOfRangeException #4");
75                 } catch (ArgumentOutOfRangeException) {
76                 }
77         }
78
79         [Test]
80         public void PortProperty ()
81         {
82                 try {
83                         endPoint1.Port = MyMinPort - 1;
84                         Assertion.Fail ("Should raise an ArgumentOutOfRangeException #1");
85                 } catch (ArgumentOutOfRangeException) {
86                 }
87                 try {
88                         endPoint1.Port = MyMaxPort + 1;
89                         Assertion.Fail ("Should raise an ArgumentOutOfRangeException #2");
90                 } catch (ArgumentOutOfRangeException) {
91                 }
92         }
93
94         [Test]
95         public void CreateAndSerialize()
96         {
97                 SocketAddress addr = endPoint1.Serialize ();
98                 EndPoint endPoint3 = endPoint2.Create (addr);
99                 Assertion.Assert ("#1", endPoint1.Equals (endPoint3));
100
101                 IPAddress ipAddress = IPAddress.Parse ("255.255.255.255");
102                 IPEndPoint endPoint4 = new IPEndPoint (ipAddress, MyMaxPort);
103                 addr = endPoint4.Serialize ();
104                 EndPoint endPoint5 = endPoint2.Create(addr);
105                 Assertion.Assert ("#2", endPoint4.Equals (endPoint5));
106                 Assertion.AssertEquals ("#3", endPoint5.ToString (), "255.255.255.255:" + MyMaxPort);
107         }
108
109         [Test]
110         public void Equals ()
111         {
112                 Assertion.Assert("Equals", endPoint1.Equals (endPoint2));
113                 Assertion.Assert("Not Equals", !endPoint1.Equals (new IPEndPoint (ip, MyPort + 1)));
114         }
115
116         [Test]
117         public void GetHashCodeTest ()
118         {
119                 Assertion.AssertEquals(endPoint1.GetHashCode(), endPoint2.GetHashCode());
120         }
121
122         [Test]
123         public void ToStringTest ()
124         {
125                 Assertion.AssertEquals("ToString #1", endPoint1.ToString (), MyIPAddressString + ":" + MyPort);
126                 Assertion.AssertEquals("ToString #2", endPoint2.ToString (), MyIPAddressString + ":" + MyPort);
127         }
128
129 }
130
131 }
132