X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem%2FTest%2FSystem.Net.Sockets%2FTcpClientTest.cs;h=cefe3bebc599a27a06a3892d3687a73a797be5bc;hb=cf3f3aa8d1b9528cd6f2778d5ecfd250d3e6d040;hp=d4769eb811bc6eeb297046a2b44df0c597c9d36a;hpb=687bbf2f71c14dd7c0740bcbd7c3b6f56ca39594;p=mono.git diff --git a/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs b/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs index d4769eb811b..cefe3bebc59 100644 --- a/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs +++ b/mcs/class/System/Test/System.Net.Sockets/TcpClientTest.cs @@ -29,18 +29,22 @@ namespace MonoTests.System.Net.Sockets /// (from System.Net.Sockets) /// [Test] +#if FEATURE_NO_BSD_SOCKETS + [ExpectedException (typeof (PlatformNotSupportedException))] +#endif public void TcpClient() { // set up a listening Socket Socket lSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); - lSock.Bind(new IPEndPoint(IPAddress.Any, 8765)); + var port = NetworkHelpers.FindFreePort (); + lSock.Bind(new IPEndPoint(IPAddress.Any, port)); lSock.Listen(-1); // connect to it with a TcpClient - TcpClient outClient = new TcpClient("localhost", 8765); + TcpClient outClient = new TcpClient("localhost", port); Socket inSock = lSock.Accept(); @@ -75,13 +79,15 @@ namespace MonoTests.System.Net.Sockets } [Test] // bug #81105 +#if FEATURE_NO_BSD_SOCKETS + [ExpectedException (typeof (PlatformNotSupportedException))] +#endif public void CloseTest () { - IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 8765); - using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (CloseRequestHandler))) { - sr.Start (); - - TcpClient tcpClient = new TcpClient (IPAddress.Loopback.ToString (), 8765); + var port = NetworkHelpers.FindFreePort (); + IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, port); + using (SocketResponder sr = new SocketResponder (localEP, s => CloseRequestHandler (s))) { + TcpClient tcpClient = new TcpClient (IPAddress.Loopback.ToString (), port); NetworkStream ns = tcpClient.GetStream (); Assert.IsNotNull (ns, "#A1"); Assert.AreEqual (0, tcpClient.Available, "#A2"); @@ -105,10 +111,8 @@ namespace MonoTests.System.Net.Sockets */ } - using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (CloseRequestHandler))) { - sr.Start (); - - TcpClient tcpClient = new TcpClient (IPAddress.Loopback.ToString (), 8765); + using (SocketResponder sr = new SocketResponder (localEP, s => CloseRequestHandler (s))) { + TcpClient tcpClient = new TcpClient (IPAddress.Loopback.ToString (), port); Assert.AreEqual (0, tcpClient.Available, "#B1"); Assert.IsTrue (tcpClient.Connected, "#B2"); // Assert.IsFalse (tcpClient.ExclusiveAddressUse, "#B3"); @@ -141,7 +145,11 @@ namespace MonoTests.System.Net.Sockets } [Test] +#if FEATURE_NO_BSD_SOCKETS + [ExpectedException (typeof (PlatformNotSupportedException))] +#else [ExpectedException (typeof(ArgumentNullException))] +#endif public void ConnectMultiNull () { TcpClient client = new TcpClient (); @@ -151,6 +159,9 @@ namespace MonoTests.System.Net.Sockets } [Test] +#if FEATURE_NO_BSD_SOCKETS + [ExpectedException (typeof (PlatformNotSupportedException))] +#endif public void ConnectMultiAny () { TcpClient client = new TcpClient (); @@ -169,6 +180,9 @@ namespace MonoTests.System.Net.Sockets } [Test] +#if FEATURE_NO_BSD_SOCKETS + [ExpectedException (typeof (PlatformNotSupportedException))] +#endif public void ConnectMultiRefused () { TcpClient client = new TcpClient (); @@ -185,5 +199,16 @@ namespace MonoTests.System.Net.Sockets Assert.Fail ("ConnectMultiRefused #3"); } } + + [Test] +#if FEATURE_NO_BSD_SOCKETS + [ExpectedException (typeof (PlatformNotSupportedException))] +#endif + public void ExclusiveAddressUse () + { + using (TcpClient client = new TcpClient ()) { + client.ExclusiveAddressUse = false; + } + } } }