[Fix] #635971 Fixed throwing exception in case of using zero timeout. Now it is legal.
authorKonrad M. Kruczynski <konrad.kruczynski@gmail.com>
Mon, 16 May 2011 20:21:35 +0000 (22:21 +0200)
committerKonrad M. Kruczynski <konrad.kruczynski@gmail.com>
Mon, 16 May 2011 20:21:35 +0000 (22:21 +0200)
For details, please see bug description and comments on bugzilla.

mcs/class/System/System.IO.Ports/SerialPort.cs
mcs/class/System/Test/System.IO.Ports/SerialPortTest.cs

index b5ac97e046eea1c8bbc656844f3ae557a0271a4e..657d4b187266431424e2e3b9517b9e3ddda17c60 100644 (file)
@@ -388,7 +388,7 @@ namespace System.IO.Ports
                                return read_timeout;
                        }
                        set {
-                               if (value <= 0 && value != InfiniteTimeout)
+                               if (value < 0 && value != InfiniteTimeout)
                                        throw new ArgumentOutOfRangeException ("value");
 
                                if (is_open)
@@ -476,7 +476,7 @@ namespace System.IO.Ports
                                return write_timeout;
                        }
                        set {
-                               if (value <= 0 && value != InfiniteTimeout)
+                               if (value < 0 && value != InfiniteTimeout)
                                        throw new ArgumentOutOfRangeException ("value");
 
                                if (is_open)
index 33e4191b0cb1d2eca4beec97ab2b35364185a3eb..a87f15feb82bb6f4bd2dec757dc40872516ef691 100644 (file)
@@ -70,6 +70,24 @@ namespace MonoTests.System.IO.Ports
                        Assert.IsTrue(exceptionCatched,
                                "Exception not thrown despite wrong baud rate");
                }
+
+               /// <summary>
+               /// This test is related to bug #635971
+               /// </summary>
+               [Test]
+               public void ZeroTimeout ()
+               {
+                       var sp = new SerialPort ();
+                       var exceptionThrown = false;
+                       try {
+                               sp.ReadTimeout = 0;
+                       } catch(ArgumentOutOfRangeException) {
+                               exceptionThrown = true;
+                       }
+                       Assert.IsFalse(exceptionThrown,
+                               "Exception thrown despite proper timeout (0)");
+               }
+
        }
 }