[sgen] Fix pointer access.
[mono.git] / mcs / class / System / Test / System.Net.Sockets / TcpClientCas.cs
1 //
2 // TcpClientCas.cs - CAS unit tests for System.Net.Sockets.TcpClient class
3 //
4 // Author:
5 //      Sebastien Pouliot  <sebastien@ximian.com>
6 //
7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
8 //
9
10 using NUnit.Framework;
11
12 using System;
13 using System.IO;
14 using System.Net;
15 using System.Net.Sockets;
16 using System.Security;
17 using System.Security.Permissions;
18 using System.Threading;
19
20 using MonoTests.System.Net.Sockets;
21
22 namespace MonoCasTests.System.Net.Sockets {
23
24         [TestFixture]
25         [Category ("CAS")]
26         public class TcpClientCas {
27
28                 private const int timeout = 30000;
29
30                 static ManualResetEvent reset;
31                 private string message;
32                 private string uri = "http://www.google.com";
33
34                 [TestFixtureSetUp]
35                 public void FixtureSetUp ()
36                 {
37                         reset = new ManualResetEvent (false);
38                 }
39
40                 [TestFixtureTearDown]
41                 public void FixtureTearDown ()
42                 {
43                         reset.Close ();
44                 }
45
46                 [SetUp]
47                 public void SetUp ()
48                 {
49                         if (!SecurityManager.SecurityEnabled)
50                                 Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
51                 }
52
53                 // async tests (for stack propagation)
54 #if NET_2_0
55 /* Oops - not yet implemented in Mono
56                 private void ConnectCallback (IAsyncResult ar)
57                 {
58                         TcpClient c = (TcpClient)ar.AsyncState;
59                         c.EndConnect (ar);
60                         try {
61                                 // can we do something bad here ?
62                                 Assert.IsNotNull (Environment.GetEnvironmentVariable ("USERNAME"));
63                                 message = "Expected a SecurityException";
64                         }
65                         catch (SecurityException) {
66                                 message = null;
67                                 reset.Set ();
68                         }
69                         catch (Exception e) {
70                                 message = e.ToString ();
71                         }
72                 }
73
74                 [Test]
75                 [EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
76                 [Category ("InetAccess")]
77                 public void AsyncConnect_StringIntAsyncCallbackObject ()
78                 {
79                         TcpClient s = new TcpClient ();
80                         message = "AsyncConnect";
81                         reset.Reset ();
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);
87                 }
88
89                 [Test]
90                 [EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
91                 [Category ("InetAccess")]
92                 public void AsyncConnect_IPAddressIntAsyncCallbackObject ()
93                 {
94                         IPHostEntry host = Dns.Resolve ("www.google.com");
95                         TcpClient s = new TcpClient ();
96                         message = "AsyncConnect";
97                         reset.Reset ();
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);
103                 }
104
105                 [Test]
106                 [EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
107                 [Category ("InetAccess")]
108                 public void AsyncConnect_IPAddressArrayIntAsyncCallbackObject ()
109                 {
110                         IPHostEntry host = Dns.Resolve ("www.google.com");
111                         TcpClient s = new TcpClient ();
112                         message = "AsyncConnect";
113                         reset.Reset ();
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);
119                 }
120 */
121 #endif
122         }
123 }