2 // TcpClientCas.cs - CAS unit tests for System.Net.Sockets.TcpClient class
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 using NUnit.Framework;
15 using System.Net.Sockets;
16 using System.Security;
17 using System.Security.Permissions;
18 using System.Threading;
20 using MonoTests.System.Net.Sockets;
22 namespace MonoCasTests.System.Net.Sockets {
26 public class TcpClientCas {
28 private const int timeout = 30000;
30 static ManualResetEvent reset;
31 private string message;
32 private string uri = "http://www.google.com";
35 public void FixtureSetUp ()
37 reset = new ManualResetEvent (false);
41 public void FixtureTearDown ()
49 if (!SecurityManager.SecurityEnabled)
50 Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
53 // async tests (for stack propagation)
55 /* Oops - not yet implemented in Mono
56 private void ConnectCallback (IAsyncResult ar)
58 TcpClient c = (TcpClient)ar.AsyncState;
61 // can we do something bad here ?
62 Assert.IsNotNull (Environment.GetEnvironmentVariable ("USERNAME"));
63 message = "Expected a SecurityException";
65 catch (SecurityException) {
70 message = e.ToString ();
75 [EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
76 [Category ("InetAccess")]
77 public void AsyncConnect_StringIntAsyncCallbackObject ()
79 TcpClient s = new TcpClient ();
80 message = "AsyncConnect";
82 IAsyncResult r = s.BeginConnect ("www.google.com", 80, new AsyncCallback (ConnectCallback), s);
83 Assert.IsNotNull (r, "IAsyncResult");
84 if (!reset.WaitOne (timeout, true))
85 Assert.Ignore ("Timeout");
86 Assert.IsNull (message, message);
90 [EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
91 [Category ("InetAccess")]
92 public void AsyncConnect_IPAddressIntAsyncCallbackObject ()
94 IPHostEntry host = Dns.Resolve ("www.google.com");
95 TcpClient s = new TcpClient ();
96 message = "AsyncConnect";
98 IAsyncResult r = s.BeginConnect (host.AddressList[0], 80, new AsyncCallback (ConnectCallback), s);
99 Assert.IsNotNull (r, "IAsyncResult");
100 if (!reset.WaitOne (timeout, true))
101 Assert.Ignore ("Timeout");
102 Assert.IsNull (message, message);
106 [EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
107 [Category ("InetAccess")]
108 public void AsyncConnect_IPAddressArrayIntAsyncCallbackObject ()
110 IPHostEntry host = Dns.Resolve ("www.google.com");
111 TcpClient s = new TcpClient ();
112 message = "AsyncConnect";
114 IAsyncResult r = s.BeginConnect (host.AddressList, 80, new AsyncCallback (ConnectCallback), s);
115 Assert.IsNotNull (r, "IAsyncResult");
116 if (!reset.WaitOne (timeout, true))
117 Assert.Ignore ("Timeout");
118 Assert.IsNull (message, message);