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;
34 public void FixtureSetUp ()
36 reset = new ManualResetEvent (false);
40 public void FixtureTearDown ()
48 if (!SecurityManager.SecurityEnabled)
49 Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
52 // async tests (for stack propagation)
53 /* Oops - not yet implemented in Mono
54 private void ConnectCallback (IAsyncResult ar)
56 TcpClient c = (TcpClient)ar.AsyncState;
59 // can we do something bad here ?
60 Assert.IsNotNull (Environment.GetEnvironmentVariable ("USERNAME"));
61 message = "Expected a SecurityException";
63 catch (SecurityException) {
68 message = e.ToString ();
73 [EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
74 [Category ("InetAccess")]
75 public void AsyncConnect_StringIntAsyncCallbackObject ()
77 TcpClient s = new TcpClient ();
78 message = "AsyncConnect";
80 IAsyncResult r = s.BeginConnect ("www.google.com", 80, new AsyncCallback (ConnectCallback), s);
81 Assert.IsNotNull (r, "IAsyncResult");
82 if (!reset.WaitOne (timeout, true))
83 Assert.Ignore ("Timeout");
84 Assert.IsNull (message, message);
88 [EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
89 [Category ("InetAccess")]
90 public void AsyncConnect_IPAddressIntAsyncCallbackObject ()
92 IPHostEntry host = Dns.Resolve ("www.google.com");
93 TcpClient s = new TcpClient ();
94 message = "AsyncConnect";
96 IAsyncResult r = s.BeginConnect (host.AddressList[0], 80, new AsyncCallback (ConnectCallback), s);
97 Assert.IsNotNull (r, "IAsyncResult");
98 if (!reset.WaitOne (timeout, true))
99 Assert.Ignore ("Timeout");
100 Assert.IsNull (message, message);
104 [EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
105 [Category ("InetAccess")]
106 public void AsyncConnect_IPAddressArrayIntAsyncCallbackObject ()
108 IPHostEntry host = Dns.Resolve ("www.google.com");
109 TcpClient s = new TcpClient ();
110 message = "AsyncConnect";
112 IAsyncResult r = s.BeginConnect (host.AddressList, 80, new AsyncCallback (ConnectCallback), s);
113 Assert.IsNotNull (r, "IAsyncResult");
114 if (!reset.WaitOne (timeout, true))
115 Assert.Ignore ("Timeout");
116 Assert.IsNull (message, message);