Imported Upstream version 3.8.0

Former-commit-id: 6a76a29bd07d86e57c6c8da45c65ed5447d38a61
This commit is contained in:
Jo Shields
2014-09-04 09:07:35 +01:00
parent a575963da9
commit fe777c5c82
1062 changed files with 12460 additions and 5983 deletions

View File

@ -28,8 +28,8 @@ namespace MonoTests.System.Net
[TestFixture]
public class DnsTest
{
private String site1Name = "mono-project.com",
site1Dot = "96.126.105.110",
private String site1Name = "xamarin.com",
site1Dot = "50.19.126.231",
site2Name = "info.diku.dk",
site2Dot = "130.225.96.4",
noneExistingSite = "unlikely.xamarin.com";
@ -44,7 +44,7 @@ namespace MonoTests.System.Net
IAsyncResult async = Dns.BeginGetHostByName (site1Name, null, null);
IPHostEntry entry = Dns.EndGetHostByName (async);
SubTestValidIPHostEntry (entry);
Assert.IsTrue (entry.HostName == "www.mono-project.com" || entry.HostName == "mono-project.com");
Assert.IsTrue (entry.HostName == "www.xamarin.com" || entry.HostName == "xamarin.com");
}
void GetHostByNameCallback (IAsyncResult ar)
@ -191,7 +191,7 @@ namespace MonoTests.System.Net
[Test]
public void GetHostByName ()
{
SubTestGetHostByName ("www.mono-project.com", site1Dot);
SubTestGetHostByName ("www.xamarin.com", site1Dot);
SubTestGetHostByName (site2Name, site2Dot);
try {
var entry = Dns.GetHostByName (noneExistingSite);

View File

@ -144,7 +144,7 @@ namespace MonoTests.System.Net {
Send (ns, "GET / HTTP/1.1\r\n\r\n"); // No host
string response = Receive (ns, 512);
ns.Close ();
Assert.IsTrue (response.StartsWith ("HTTP/1.1 400"));
StringAssert.StartsWith ("HTTP/1.1 400", response);
}
[Test]
@ -155,7 +155,7 @@ namespace MonoTests.System.Net {
Send (ns, "GET / HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n"); // no prefix
string response = Receive (ns, 512);
ns.Close ();
Assert.IsTrue (response.StartsWith ("HTTP/1.1 400"));
StringAssert.StartsWith ("HTTP/1.1 400", response);
}
[Test]
@ -192,7 +192,7 @@ namespace MonoTests.System.Net {
string response = Receive (ns, 512);
ns.Close ();
listener.Close ();
Assert.AreEqual (true, response.StartsWith ("HTTP/1.1 400"), String.Format ("Failed on {0}", (int) b));
StringAssert.StartsWith ("HTTP/1.1 400", response, String.Format ("Failed on {0}", (int) b));
}
}
@ -204,7 +204,7 @@ namespace MonoTests.System.Net {
Send (ns, "POST /test4/ HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n"); // length required
string response = Receive (ns, 512);
ns.Close ();
Assert.IsTrue (response.StartsWith ("HTTP/1.1 411"));
StringAssert.StartsWith ("HTTP/1.1 411", response);
}
[Test]
@ -215,7 +215,7 @@ namespace MonoTests.System.Net {
Send (ns, "POST / HTTP/1.1\r\nHost: 127.0.0.1\r\nTransfer-Encoding: pepe\r\n\r\n"); // not implemented
string response = Receive (ns, 512);
ns.Close ();
Assert.IsTrue (response.StartsWith ("HTTP/1.1 501"));
StringAssert.StartsWith ("HTTP/1.1 501", response);
}
[Test]
@ -227,7 +227,7 @@ namespace MonoTests.System.Net {
Send (ns, "POST /test6/ HTTP/1.1\r\nHost: 127.0.0.1\r\nTransfer-Encoding: identity\r\n\r\n");
string response = Receive (ns, 512);
ns.Close ();
Assert.IsTrue (response.StartsWith ("HTTP/1.1 501"));
StringAssert.StartsWith ("HTTP/1.1 501", response);
}
[Test]
@ -241,8 +241,8 @@ namespace MonoTests.System.Net {
ctx.Response.Close ();
string response = Receive (ns, 1024);
ns.Close ();
Assert.IsTrue (response.StartsWith ("HTTP/1.1 200"));
Assert.IsTrue (-1 != response.IndexOf ("Transfer-Encoding: chunked"));
StringAssert.StartsWith ("HTTP/1.1 200", response);
StringAssert.Contains ("Transfer-Encoding: chunked", response);
}
[Test]
@ -257,7 +257,7 @@ namespace MonoTests.System.Net {
ctx.Response.Close ();
string response = Receive (ns, 512);
ns.Close ();
Assert.IsTrue (response.StartsWith ("HTTP/1.1 200"));
StringAssert.StartsWith ("HTTP/1.1 200", response);
Assert.IsTrue (-1 == response.IndexOf ("Transfer-Encoding: chunked"));
}
@ -272,7 +272,7 @@ namespace MonoTests.System.Net {
string response = ReceiveWithTimeout (ns, 512, 1000, out timeout);
ns.Close ();
Assert.IsFalse (timeout);
Assert.IsTrue (response.StartsWith ("HTTP/1.1 411"));
StringAssert.StartsWith ("HTTP/1.1 411", response);
}
[Test]
@ -287,7 +287,7 @@ namespace MonoTests.System.Net {
string response = ReceiveWithTimeout (ns, 512, 1000, out timeout);
ns.Close ();
Assert.IsFalse (timeout);
Assert.IsTrue (response.StartsWith ("HTTP/1.1 411"));
StringAssert.StartsWith ("HTTP/1.1 411", response);
}
[Test]
@ -300,7 +300,7 @@ namespace MonoTests.System.Net {
ns.GetSocket ().Shutdown (SocketShutdown.Send);
string input = Receive (ns, 512);
ns.Close ();
Assert.IsTrue (input.StartsWith ("HTTP/1.1 400"));
StringAssert.StartsWith ("HTTP/1.1 400", input);
}
[Test]
@ -313,7 +313,7 @@ namespace MonoTests.System.Net {
ns.GetSocket ().Shutdown (SocketShutdown.Send);
string input = Receive (ns, 512);
ns.Close ();
Assert.IsTrue (input.StartsWith ("HTTP/1.1 400"));
StringAssert.StartsWith ("HTTP/1.1 400", input);
}
[Test]
@ -326,7 +326,7 @@ namespace MonoTests.System.Net {
ns.GetSocket ().Shutdown (SocketShutdown.Send);
string input = Receive (ns, 512);
ns.Close ();
Assert.IsTrue (input.StartsWith ("HTTP/1.1 400"));
StringAssert.StartsWith ("HTTP/1.1 400", input);
}
HttpListenerRequest test14_request;
@ -418,8 +418,8 @@ namespace MonoTests.System.Net {
ctx.Response.Close ();
string response = Receive (ns, 1024);
ns.Close ();
Assert.IsTrue (response.StartsWith ("HTTP/1.1 200"));
Assert.IsTrue (-1 != response.IndexOf ("Transfer-Encoding: chunked"));
StringAssert.StartsWith ("HTTP/1.1 200", response);
StringAssert.Contains ("Transfer-Encoding: chunked", response);
}
[Test]
@ -723,11 +723,11 @@ namespace MonoTests.System.Net {
public void ClosePort ()
{
var h = new HttpListener ();
h.Prefixes.Add ("http://127.0.0.1:8080/");
h.Prefixes.Add ("http://127.0.0.1:30158/");
h.Start ();
h.BeginGetContext (null, null);
h.Stop ();
TcpListener t = new TcpListener (IPAddress.Parse ("127.0.0.1"), 8080);
TcpListener t = new TcpListener (IPAddress.Parse ("127.0.0.1"), 30158);
t.Start ();
t.Stop ();
}

View File

@ -1 +1 @@
f0826d1c9902938fe975f2a12554f06926ef5876
ccf2484dfdddf2db7e554b5b4176c004fc9f9a94

View File

@ -2156,5 +2156,97 @@ namespace MonoTests.System.Net
// and return the same instance as WebRequest.DefaultWebProxy
Assert.AreSame (wc.Proxy, WebRequest.DefaultWebProxy);
}
#if NET_4_5
[Test]
public void UploadStringAsyncCancelEvent ()
{
UploadAsyncCancelEventTest ((webClient, uri, cancelEvent) =>
{
webClient.UploadStringCompleted += (sender, args) =>
{
if (args.Cancelled)
cancelEvent.Set ();
};
webClient.UploadStringAsync (uri, "PUT", "text");
});
}
[Test]
public void UploadDataAsyncCancelEvent ()
{
UploadAsyncCancelEventTest ((webClient, uri, cancelEvent) =>
{
webClient.UploadDataCompleted += (sender, args) =>
{
if (args.Cancelled)
cancelEvent.Set ();
};
webClient.UploadDataAsync (uri, "PUT", new byte[] { });
});
}
[Test]
public void UploadValuesAsyncCancelEvent ()
{
UploadAsyncCancelEventTest ((webClient, uri, cancelEvent) =>
{
webClient.UploadValuesCompleted += (sender, args) =>
{
if (args.Cancelled)
cancelEvent.Set ();
};
webClient.UploadValuesAsync (uri, "PUT", new NameValueCollection ());
});
}
[Test]
public void UploadFileAsyncCancelEvent ()
{
UploadAsyncCancelEventTest ((webClient, uri, cancelEvent) =>
{
string tempFile = Path.Combine (_tempFolder, "upload.tmp");
File.Create (tempFile).Close ();
webClient.UploadFileCompleted += (sender, args) =>
{
if (args.Cancelled)
cancelEvent.Set ();
};
webClient.UploadFileAsync (uri, "PUT", tempFile);
});
}
#endif
#if NET_4_0
public void UploadAsyncCancelEventTest (Action<WebClient, Uri, EventWaitHandle> uploadAction)
{
var ep = new IPEndPoint (IPAddress.Loopback, 8000);
string url = "http://" + IPAddress.Loopback + ":8000/test/";
using (var responder = new SocketResponder (ep, EchoRequestHandler))
{
responder.Start ();
var webClient = new WebClient ();
var cancellationTokenSource = new CancellationTokenSource ();
cancellationTokenSource.Token.Register (webClient.CancelAsync);
var cancelEvent = new ManualResetEvent (false);
uploadAction.Invoke (webClient, new Uri (url), cancelEvent);
cancellationTokenSource.Cancel ();
Assert.IsTrue (cancelEvent.WaitOne (1000));
}
}
#endif
}
}