* WebConnectionStream.cs: Move and improve argument checks to match MS.
authorGert Driesen <drieseng@users.sourceforge.net>
Mon, 6 Jul 2009 19:58:00 +0000 (19:58 -0000)
committerGert Driesen <drieseng@users.sourceforge.net>
Mon, 6 Jul 2009 19:58:00 +0000 (19:58 -0000)
Modified CanRead and CanWrite to return false when instance is disposed.
* HttpWebRequestTest.cs: Enabled tests, and removed test that is now
covered by two separate CanTimeout tests for request and response
stream.
* HttpWebResponseStreamTest.cs: Enabled tests.

svn path=/trunk/mcs/; revision=137450

mcs/class/System/System.Net/ChangeLog
mcs/class/System/System.Net/WebConnectionStream.cs
mcs/class/System/Test/System.Net/ChangeLog
mcs/class/System/Test/System.Net/HttpWebRequestTest.cs
mcs/class/System/Test/System.Net/HttpWebResponseTest.cs

index c17c79f7f5b567731b92a99bd993086fb3374828..472b2a27b4ce6948c337feb13b176e5b27f7a851 100644 (file)
@@ -1,3 +1,8 @@
+2009-07-06  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * WebConnectionStream.cs: Move and improve argument checks to match MS.
+       Modified CanRead and CanWrite to return false when instance is disposed.
+
 2009-07-02 Gonzalo Paniagua Javier <gonzalo@novell.com>
 
        * WebConnection.cs: provide better error message when there's an error
index 9cda6c424b9e713ca83e67f631048903d78bc73d..71de529cdadac8bfaa5b2ed9a570b4ef6a062040 100644 (file)
@@ -307,12 +307,6 @@ namespace System.Net
 
                public override int Read (byte [] buffer, int offset, int size)
                {
-                       if (!isRead)
-                               throw new NotSupportedException ("this stream does not allow reading");
-
-                       if (totalRead >= contentLength)
-                               return 0;
-
                        AsyncCallback cb = new AsyncCallback (ReadCallbackWrapper);
                        WebAsyncResult res = (WebAsyncResult) BeginRead (buffer, offset, size, cb, null);
                        if (!res.IsCompleted && !res.WaitUntilComplete (ReadTimeout, false)) {
@@ -334,8 +328,10 @@ namespace System.Net
                                throw new ArgumentNullException ("buffer");
 
                        int length = buffer.Length;
-                       if (size < 0 || offset < 0 || length < offset || length - offset < size)
-                               throw new ArgumentOutOfRangeException ();
+                       if (offset < 0 || length < offset)
+                               throw new ArgumentOutOfRangeException ("offset");
+                       if (size < 0 || (length - offset) < size)
+                               throw new ArgumentOutOfRangeException ("size");
 
                        lock (locker) {
                                pendingReads++;
@@ -467,8 +463,10 @@ namespace System.Net
                                throw new ArgumentNullException ("buffer");
 
                        int length = buffer.Length;
-                       if (size < 0 || offset < 0 || length < offset || length - offset < size)
-                               throw new ArgumentOutOfRangeException ();
+                       if (offset < 0 || length < offset)
+                               throw new ArgumentOutOfRangeException ("offset");
+                       if (size < 0 || (length - offset) < size)
+                               throw new ArgumentOutOfRangeException ("size");
 
                        if (sendChunked) {
                                lock (locker) {
@@ -591,9 +589,6 @@ namespace System.Net
                
                public override void Write (byte [] buffer, int offset, int size)
                {
-                       if (isRead)
-                               throw new NotSupportedException ("This stream does not allow writing");
-
                        AsyncCallback cb = new AsyncCallback (WriteCallbackWrapper);
                        WebAsyncResult res = (WebAsyncResult) BeginWrite (buffer, offset, size, cb, null);
                        if (!res.IsCompleted && !res.WaitUntilComplete (WriteTimeout, false)) {
@@ -778,11 +773,11 @@ namespace System.Net
                }
 
                public override bool CanRead {
-                       get { return isRead; }
+                       get { return !disposed && isRead; }
                }
 
                public override bool CanWrite {
-                       get { return !isRead; }
+                       get { return !disposed && !isRead; }
                }
 
                public override long Length {
index 0d0f4c01e6ce87f98e72324bad88dd3f9a9e2ad3..7017382e7202d63d76e93e169a51b1eb9b0a3881 100644 (file)
@@ -1,3 +1,10 @@
+2009-07-06  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * HttpWebRequestTest.cs: Enabled tests, and removed test that is now
+       covered by two separate CanTimeout tests for request and response
+       stream.
+       * HttpWebResponseStreamTest.cs: Enabled tests.
+
 2009-07-06  Gert Driesen  <drieseng@users.sourceforge.net>
 
        * HttpWebRequestTest.cs: Marked test notworking on 1.0 profile.
index b826df9b552323f2e97481cd5a5f78806d3a56a5..13bf8327b0ee833dd0ed1e8388e3e4ab2d92c3d8 100644 (file)
@@ -1502,38 +1502,6 @@ namespace MonoTests.System.Net
                        }
                }
 
-#if NET_2_0
-               [Test] // bug #324182
-#if TARGET_JVM
-               [Category ("NotWorking")]
-#endif
-               public void Stream_CanTimeout ()
-               {
-                       IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 8764);
-                       string url = "http://" + localEP.ToString () + "/original/";
-
-                       // allow autoredirect
-                       using (SocketResponder responder = new SocketResponder (localEP, new SocketRequestHandler (RedirectRequestHandler))) {
-                               responder.Start ();
-
-                               HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url);
-                               req.Method = "POST";
-                               req.Timeout = 2000;
-                               req.ReadWriteTimeout = 2000;
-                               req.KeepAlive = false;
-                               Stream rs = req.GetRequestStream ();
-                               Assert.IsTrue (rs.CanTimeout, "#1");
-                               rs.Close ();
-                               using (HttpWebResponse resp = (HttpWebResponse) req.GetResponse ()) {
-                                       Stream os = resp.GetResponseStream ();
-                                       Assert.IsTrue (os.CanTimeout, "#2");
-                                       os.Close ();
-                               }
-                               responder.Stop ();
-                       }
-               }
-#endif
-
                [Test] // bug #353495
                [Category ("NotWorking")]
                public void LastModifiedKind ()
@@ -2639,7 +2607,10 @@ namespace MonoTests.System.Net
                }
 
 #if NET_2_0
-               [Test]
+               [Test] // bug #324182
+#if TARGET_JVM
+               [Category ("NotWorking")]
+#endif
                public void CanTimeout ()
                {
                        IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8000);
@@ -2665,7 +2636,6 @@ namespace MonoTests.System.Net
 #endif
 
                [Test]
-               [Category ("NotWorking")]
                public void CanWrite ()
                {
                        IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8000);
@@ -2829,7 +2799,6 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void Write_Count_Negative ()
                {
                        IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8000);
@@ -2860,7 +2829,6 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void Write_Count_Overflow ()
                {
                        IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8000);
@@ -2891,7 +2859,6 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void Write_Offset_Negative ()
                {
                        IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8000);
@@ -2922,7 +2889,6 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void Write_Offset_Overflow ()
                {
                        IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8000);
index 775ced585bdde285109002a20bb9a6d744258f6c..dd9749175257522161bea694dcb0450a69abf99b 100644 (file)
@@ -665,7 +665,10 @@ namespace MonoTests.System.Net
                }
 
 #if NET_2_0
-               [Test]
+               [Test] // bug #324182
+#if TARGET_JVM
+               [Category ("NotWorking")]
+#endif
                public void CanTimeout ()
                {
                        IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8000);
@@ -764,7 +767,6 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void Read_Buffer_Null ()
                {
                        IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8000);
@@ -816,7 +818,6 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void Read_Count_Negative ()
                {
                        IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8000);
@@ -869,7 +870,6 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void Read_Count_Overflow ()
                {
                        IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8000);
@@ -922,7 +922,6 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void Read_Offset_Negative ()
                {
                        IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8000);
@@ -975,7 +974,6 @@ namespace MonoTests.System.Net
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void Read_Offset_Overflow ()
                {
                        IPEndPoint ep = new IPEndPoint (IPAddress.Loopback, 8000);