Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGert Driesen <drieseng@users.sourceforge.net>2009-06-20 17:22:17 +0400
committerGert Driesen <drieseng@users.sourceforge.net>2009-06-20 17:22:17 +0400
commit2fc81bb034cd9641544edf0758b63b29074b5213 (patch)
tree904080ab4ee99319c5b388a2ed9d27d25af0ff03 /mcs/class/System/Test
parent6f8bd0b8a81757b2555ca2ea9d68f4ffd1ed4a4b (diff)
* HttpListener2Test.cs: Added test for bug #513849.
* HttpWebRequestTest.cs: Enabled test for bug #508027. Added test for bug #513087. * WebClientTest.cs: Added test for bug #484795, for Encoding property. svn path=/trunk/mcs/; revision=136544
Diffstat (limited to 'mcs/class/System/Test')
-rw-r--r--mcs/class/System/Test/System.Net/ChangeLog7
-rw-r--r--mcs/class/System/Test/System.Net/HttpListener2Test.cs14
-rw-r--r--mcs/class/System/Test/System.Net/HttpWebRequestTest.cs75
-rw-r--r--mcs/class/System/Test/System.Net/WebClientTest.cs139
4 files changed, 230 insertions, 5 deletions
diff --git a/mcs/class/System/Test/System.Net/ChangeLog b/mcs/class/System/Test/System.Net/ChangeLog
index 18aeb3fcf2e..d5348f75f70 100644
--- a/mcs/class/System/Test/System.Net/ChangeLog
+++ b/mcs/class/System/Test/System.Net/ChangeLog
@@ -1,3 +1,10 @@
+2009-06-20 Gert Driesen <drieseng@users.sourceforge.net>
+
+ * HttpListener2Test.cs: Added test for bug #513849.
+ * HttpWebRequestTest.cs: Enabled test for bug #508027. Added test for
+ bug #513087.
+ * WebClientTest.cs: Added test for bug #484795, for Encoding property.
+
2009-06-16 Andrés G. Aragoneses <aaragoneses@novell.com>
* WebRequestTest.cs: Drop NotWorking attrib, more accurate tests.
diff --git a/mcs/class/System/Test/System.Net/HttpListener2Test.cs b/mcs/class/System/Test/System.Net/HttpListener2Test.cs
index fcd36d91bd6..f79f1593259 100644
--- a/mcs/class/System/Test/System.Net/HttpListener2Test.cs
+++ b/mcs/class/System/Test/System.Net/HttpListener2Test.cs
@@ -723,7 +723,19 @@ namespace MonoTests.System.Net {
listener.Close ();
}
-
+
+ [Test] // bug #513849
+ public void ClosePort ()
+ {
+ var h = new HttpListener ();
+ h.Prefixes.Add ("http://127.0.0.1:8080/");
+ h.Start ();
+ h.BeginGetContext (null, null);
+ h.Stop ();
+ TcpListener t = new TcpListener (IPAddress.Parse ("127.0.0.1"), 8080);
+ t.Start ();
+ t.Stop ();
+ }
}
}
#endif
diff --git a/mcs/class/System/Test/System.Net/HttpWebRequestTest.cs b/mcs/class/System/Test/System.Net/HttpWebRequestTest.cs
index cffc59b0e1e..dfab0a31e6f 100644
--- a/mcs/class/System/Test/System.Net/HttpWebRequestTest.cs
+++ b/mcs/class/System/Test/System.Net/HttpWebRequestTest.cs
@@ -381,7 +381,6 @@ namespace MonoTests.System.Net
}
[Test] // bug #508027
- [Category ("NotWorking")]
public void BeginGetResponse ()
{
IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8003);
@@ -544,7 +543,7 @@ namespace MonoTests.System.Net
}
}
- [Test] // bug #510661
+ [Test] // bug #510661 and #514996
[Category ("NotWorking")]
public void GetRequestStream_Close_NotAllBytesWritten ()
{
@@ -922,6 +921,40 @@ namespace MonoTests.System.Net
}
}
+ [Test] // bug #513087
+ public void NonStandardVerb ()
+ {
+ IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8000);
+ string url = "http://" + IPAddress.Loopback.ToString () + ":8000/moved/";
+
+ using (SocketResponder responder = new SocketResponder (ep, new SocketRequestHandler (VerbEchoHandler))) {
+ responder.Start ();
+
+ HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url);
+ req.Method = "WhatEver";
+ req.KeepAlive = false;
+ req.Timeout = 20000;
+ req.ReadWriteTimeout = 20000;
+
+ Stream rs = req.GetRequestStream ();
+ rs.Close ();
+
+ using (HttpWebResponse resp = (HttpWebResponse) req.GetResponse ()) {
+ StreamReader sr = new StreamReader (resp.GetResponseStream (),
+ Encoding.UTF8);
+ string body = sr.ReadToEnd ();
+
+ Assert.AreEqual (resp.StatusCode, HttpStatusCode.OK, "#1");
+ Assert.AreEqual (resp.ResponseUri.ToString (), "http://" +
+ ep.ToString () + "/moved/", "#2");
+ Assert.AreEqual ("WhatEver", resp.Method, "#3");
+ Assert.AreEqual ("WhatEver", body, "#4");
+ }
+
+ responder.Stop ();
+ }
+ }
+
[Test]
[Category ("NotWorking")] // Assert #2 fails
public void NotModiedSince ()
@@ -1133,6 +1166,44 @@ namespace MonoTests.System.Net
return Encoding.UTF8.GetBytes (sw.ToString ());
}
+ static byte [] VerbEchoHandler (Socket socket)
+ {
+ MemoryStream ms = new MemoryStream ();
+ byte [] buffer = new byte [4096];
+ int bytesReceived = socket.Receive (buffer);
+ while (bytesReceived > 0) {
+ ms.Write (buffer, 0, bytesReceived);
+ if (socket.Available > 0) {
+ bytesReceived = socket.Receive (buffer);
+ } else {
+ bytesReceived = 0;
+ }
+ }
+ ms.Flush ();
+ ms.Position = 0;
+ string statusLine = null;
+ using (StreamReader sr = new StreamReader (ms, Encoding.UTF8)) {
+ statusLine = sr.ReadLine ();
+ }
+
+ string verb = "DEFAULT";
+ if (statusLine != null) {
+ string [] parts = statusLine.Split (' ');
+ if (parts.Length > 0)
+ verb = parts [0];
+ }
+
+ StringWriter sw = new StringWriter ();
+ sw.WriteLine ("HTTP/1.1 200 OK");
+ sw.WriteLine ("Content-Type: text/plain");
+ sw.WriteLine ("Content-Length: " + verb.Length);
+ sw.WriteLine ();
+ sw.Write (verb);
+ sw.Flush ();
+
+ return Encoding.UTF8.GetBytes (sw.ToString ());
+ }
+
[Test]
public void NtlmAuthentication ()
{
diff --git a/mcs/class/System/Test/System.Net/WebClientTest.cs b/mcs/class/System/Test/System.Net/WebClientTest.cs
index fa57be61aec..9faf08cf5d7 100644
--- a/mcs/class/System/Test/System.Net/WebClientTest.cs
+++ b/mcs/class/System/Test/System.Net/WebClientTest.cs
@@ -5,12 +5,15 @@
//
using System;
+using System.Collections;
using System.Collections.Specialized;
+using System.Globalization;
using System.IO;
using System.Net;
-using System.Collections;
+using System.Net.Sockets;
using System.Runtime.Serialization;
-
+using System.Text;
+using System.Threading;
using NUnit.Framework;
namespace MonoTests.System.Net
@@ -382,6 +385,30 @@ namespace MonoTests.System.Net
Assert.IsNotNull (inner.Message, "#9");
}
}
+
+ [Test]
+ public void EncodingTest ()
+ {
+ WebClient wc = new WebClient ();
+ Assert.AreSame (Encoding.Default, wc.Encoding, "#1");
+ wc.Encoding = Encoding.ASCII;
+ Assert.AreSame (Encoding.ASCII, wc.Encoding, "#2");
+ }
+
+ [Test]
+ public void Encoding_Value_Null ()
+ {
+ WebClient wc = new WebClient ();
+ try {
+ wc.Encoding = null;
+ Assert.Fail ("#1");
+ } catch (ArgumentNullException ex) {
+ Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
+ Assert.IsNull (ex.InnerException, "#3");
+ Assert.IsNotNull (ex.Message, "#4");
+ Assert.AreEqual ("Encoding", ex.ParamName, "#6");
+ }
+ }
#endif
[Test] // OpenRead (string)
@@ -1667,6 +1694,30 @@ namespace MonoTests.System.Net
}
#endif
+ [Test]
+ public void UploadValues1 ()
+ {
+ IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8000);
+ string url = "http://" + IPAddress.Loopback.ToString () + ":8000/test/";
+
+ using (SocketResponder responder = new SocketResponder (ep, new SocketRequestHandler (EchoRequestHandler))) {
+ responder.Start ();
+
+ WebClient wc = new WebClient ();
+#if NET_2_0
+ wc.Encoding = Encoding.ASCII;
+#endif
+
+ NameValueCollection nvc = new NameValueCollection ();
+ nvc.Add ("Name", "\u0041\u2262\u0391\u002E");
+ nvc.Add ("Address", "\u002E\u2262\u0041\u0391");
+
+ byte [] buffer = wc.UploadValues (url, nvc);
+ string response = Encoding.UTF8.GetString (buffer);
+ Assert.AreEqual ("Name=A%e2%89%a2%ce%91.&Address=.%e2%89%a2A%ce%91\r\n", response);
+ }
+ }
+
[Test] // UploadValues (string, NameValueCollection)
public void UploadValues1_Address_Null ()
{
@@ -1982,5 +2033,89 @@ namespace MonoTests.System.Net
}
}
#endif
+
+ static byte [] EchoRequestHandler (Socket socket)
+ {
+ MemoryStream ms = new MemoryStream ();
+ byte [] buffer = new byte [4096];
+ int bytesReceived = socket.Receive (buffer);
+ while (bytesReceived > 0) {
+ ms.Write (buffer, 0, bytesReceived);
+ if (socket.Available > 0) {
+ bytesReceived = socket.Receive (buffer);
+ } else {
+ bytesReceived = 0;
+ }
+ }
+ ms.Flush ();
+ ms.Position = 0;
+
+ StringBuilder sb = new StringBuilder ();
+
+ string expect = null;
+
+ StreamReader sr = new StreamReader (ms, Encoding.UTF8);
+ string line = sr.ReadLine ();
+ byte state = 0;
+ while (line != null) {
+ if (state > 0) {
+ state = 2;
+ sb.Append (line);
+ sb.Append ("\r\n");
+ line = sr.ReadLine ();
+ } else {
+ if (line.StartsWith ("Expect:"))
+ expect = line.Substring (8);
+ line = sr.ReadLine ();
+ if (line.Length == 0) {
+ state = 1;
+ line = sr.ReadLine ();
+ }
+ }
+ }
+
+ StringWriter sw = new StringWriter ();
+
+ if (expect == "100-continue" && state != 2) {
+ sw.WriteLine ("HTTP/1.1 100 Continue");
+ sw.WriteLine ();
+ sw.Flush ();
+
+ socket.Send (Encoding.UTF8.GetBytes (sw.ToString ()));
+
+ // receive body
+ ms = new MemoryStream ();
+ buffer = new byte [4096];
+ bytesReceived = socket.Receive (buffer);
+ while (bytesReceived > 0) {
+ ms.Write (buffer, 0, bytesReceived);
+ if (socket.Available > 0) {
+ bytesReceived = socket.Receive (buffer);
+ } else {
+ bytesReceived = 0;
+ }
+ }
+ ms.Flush ();
+ ms.Position = 0;
+
+ sb = new StringBuilder ();
+ sr = new StreamReader (ms, Encoding.UTF8);
+ line = sr.ReadLine ();
+ while (line != null) {
+ sb.Append (line);
+ sb.Append ("\r\n");
+ line = sr.ReadLine ();
+ }
+ }
+
+ sw.WriteLine ("HTTP/1.1 200 OK");
+ sw.WriteLine ("Content-Type: text/xml");
+ sw.WriteLine ("Content-Length: " + sb.Length.ToString (CultureInfo.InvariantCulture));
+ sw.WriteLine ();
+ sw.Write (sb.ToString ());
+ sw.Flush ();
+
+ return Encoding.UTF8.GetBytes (sw.ToString ());
+ }
}
}