Merge pull request #1949 from lewurm/fixtype
[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
33                 [TestFixtureSetUp]
34                 public void FixtureSetUp ()
35                 {
36                         reset = new ManualResetEvent (false);
37                 }
38
39                 [TestFixtureTearDown]
40                 public void FixtureTearDown ()
41                 {
42                         reset.Close ();
43                 }
44
45                 [SetUp]
46                 public void SetUp ()
47                 {
48                         if (!SecurityManager.SecurityEnabled)
49                                 Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
50                 }
51
52                 // async tests (for stack propagation)
53 /* Oops - not yet implemented in Mono
54                 private void ConnectCallback (IAsyncResult ar)
55                 {
56                         TcpClient c = (TcpClient)ar.AsyncState;
57                         c.EndConnect (ar);
58                         try {
59                                 // can we do something bad here ?
60                                 Assert.IsNotNull (Environment.GetEnvironmentVariable ("USERNAME"));
61                                 message = "Expected a SecurityException";
62                         }
63                         catch (SecurityException) {
64                                 message = null;
65                                 reset.Set ();
66                         }
67                         catch (Exception e) {
68                                 message = e.ToString ();
69                         }
70                 }
71
72                 [Test]
73                 [EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
74                 [Category ("InetAccess")]
75                 public void AsyncConnect_StringIntAsyncCallbackObject ()
76                 {
77                         TcpClient s = new TcpClient ();
78                         message = "AsyncConnect";
79                         reset.Reset ();
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);
85                 }
86
87                 [Test]
88                 [EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
89                 [Category ("InetAccess")]
90                 public void AsyncConnect_IPAddressIntAsyncCallbackObject ()
91                 {
92                         IPHostEntry host = Dns.Resolve ("www.google.com");
93                         TcpClient s = new TcpClient ();
94                         message = "AsyncConnect";
95                         reset.Reset ();
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);
101                 }
102
103                 [Test]
104                 [EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
105                 [Category ("InetAccess")]
106                 public void AsyncConnect_IPAddressArrayIntAsyncCallbackObject ()
107                 {
108                         IPHostEntry host = Dns.Resolve ("www.google.com");
109                         TcpClient s = new TcpClient ();
110                         message = "AsyncConnect";
111                         reset.Reset ();
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);
117                 }
118 */
119         }
120 }