[System*] Throw a PlatformNotSupported exception when using the networking stack...
[mono-project.git] / mcs / class / System / Test / System.Net.Sockets / NetworkStreamTest.cs
blob0af239d238ccd494056a4fb8476cd8d1e356f1c4
1 // System.Net.Sockets.NetworkStreamTest.cs
2 //
3 // Author:
4 // Dick Porter (dick@ximian.com)
5 //
6 // Copyright (C) 2007 Novell, Inc (http://www.novell.com)
7 //
9 using System.Net.Sockets;
10 using System.Net;
11 using System;
12 using System.IO;
13 using NUnit.Framework;
16 namespace MonoTests.System.Net.Sockets
18 [TestFixture]
19 public class NetworkStreamTest
21 [Test]
22 // See bug #371923
24 #if FEATURE_NO_BSD_SOCKETS
25 [ExpectedException (typeof (PlatformNotSupportedException))]
26 #else
27 [ExpectedException(typeof(IOException))]
28 #endif
29 public void NetworkStreamConnection ()
31 IPEndPoint ipe = new IPEndPoint(Dns.GetHostEntry ("www.google.com").AddressList [0], 80);
32 Socket s = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
33 s.Close ();
34 NetworkStream ns = new NetworkStream (s);
37 [Test]
38 #if FEATURE_NO_BSD_SOCKETS
39 [ExpectedException (typeof (PlatformNotSupportedException))]
40 #endif
41 public void ReadTimeout ()
43 Socket sock = new Socket (AddressFamily.InterNetwork,
44 SocketType.Stream,
45 ProtocolType.Tcp);
46 Socket listen = new Socket (AddressFamily.InterNetwork,
47 SocketType.Stream,
48 ProtocolType.Tcp);
49 IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 0);
51 listen.Bind (ep);
52 listen.Listen (1);
54 sock.Connect (listen.LocalEndPoint);
56 NetworkStream stream = new NetworkStream (sock);
57 stream.ReadTimeout = 1000;
59 byte[] buf = new byte[1024];
61 try {
62 stream.Read (buf, 0, buf.Length);
63 Assert.Fail ("ReadTimeout #1");
64 } catch (IOException ex) {
65 Exception inner = ex.InnerException;
66 SocketException sockex = inner as SocketException;
68 Assert.IsNotNull (sockex, "ReadTimeout #2");
70 /* Linux gives error 10035 (EWOULDBLOCK) here, whereas windows has 10060 (ETIMEDOUT)
71 Assert.AreEqual (10060, sockex.ErrorCode, "ReadTimeout #3");
73 } catch {
74 Assert.Fail ("ReadTimeout #4");
75 } finally {
76 stream.Close ();
77 sock.Close ();
78 listen.Close ();