In System.Threading:
authorSebastien Pouliot <sebastien@ximian.com>
Sun, 25 Oct 2009 16:41:18 +0000 (16:41 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Sun, 25 Oct 2009 16:41:18 +0000 (16:41 -0000)
2009-10-25  Sebastien Pouliot  <sebastien@ximian.com>

* Thread.cs: Fix validations for Join and Sleep overloads

In Test/System.Threading:
2009-10-25  Sebastien Pouliot  <sebastien@ximian.com>

* ThreadTest.cs: Add test cases for Current[UI]Culture (not
working), Name, Join, Sleep and SpinWait

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

mcs/class/corlib/System.Threading/ChangeLog
mcs/class/corlib/System.Threading/Thread.cs
mcs/class/corlib/Test/System.Threading/ChangeLog
mcs/class/corlib/Test/System.Threading/ThreadTest.cs

index 7f418c58b38ceea330075c9a720b7bcaf5d3433e..47dec815d4e47ceb75f62fe1873580a58a020ceb 100644 (file)
@@ -1,3 +1,7 @@
+2009-10-25  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * Thread.cs: Fix validations for Join and Sleep overloads
+
 2009-10-22  Sebastien Pouliot  <sebastien@ximian.com>
 
        * EventWaitHandle.cs: Add validation on the EventResetMode 
index 1c93a3d43c9f630b8dae97099228fbbb71327632..14435223fe851eca0c1448aebe49ee403883c6f5 100644 (file)
@@ -391,22 +391,21 @@ namespace System.Threading {
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
                private extern static void Sleep_internal(int ms);
 
-               public static void Sleep(int millisecondsTimeout) {
-                       if((millisecondsTimeout<0) && (millisecondsTimeout != Timeout.Infinite)) {
-                               throw new ArgumentException("Negative timeout");
-                       }
-                       Sleep_internal(millisecondsTimeout);
+               public static void Sleep (int millisecondsTimeout)
+               {
+                       if (millisecondsTimeout < Timeout.Infinite)
+                               throw new ArgumentOutOfRangeException ("millisecondsTimeout", "Negative timeout");
+
+                       Sleep_internal (millisecondsTimeout);
                }
 
-               public static void Sleep(TimeSpan timeout) {
-                       // LAMESPEC: says to throw ArgumentException too
-                       int ms=Convert.ToInt32(timeout.TotalMilliseconds);
-                       
-                       if(ms < 0 || ms > Int32.MaxValue) {
-                               throw new ArgumentOutOfRangeException("Timeout out of range");
-                       }
+               public static void Sleep (TimeSpan timeout)
+               {
+                       long ms = (long) timeout.TotalMilliseconds;
+                       if (ms < Timeout.Infinite || ms > Int32.MaxValue)
+                               throw new ArgumentOutOfRangeException ("timeout", "timeout out of range");
 
-                       Sleep_internal(ms);
+                       Sleep_internal ((int) ms);
                }
 
                // Returns the system thread handle
@@ -779,22 +778,20 @@ namespace System.Threading {
 
                public bool Join(int millisecondsTimeout)
                {
-                       if (millisecondsTimeout != Timeout.Infinite && millisecondsTimeout < 0)
-                               throw new ArgumentException ("Timeout less than zero", "millisecondsTimeout");
+                       if (millisecondsTimeout < Timeout.Infinite)
+                               throw new ArgumentOutOfRangeException ("millisecondsTimeout", "Timeout less than zero");
 
-                       return Join_internal(Internal, millisecondsTimeout, Internal.system_thread_handle);
+                       return Join_internal (Internal, millisecondsTimeout, Internal.system_thread_handle);
                }
 
 #if !NET_2_1 || MONOTOUCH
                public bool Join(TimeSpan timeout)
                {
-                       // LAMESPEC: says to throw ArgumentException too
-                       int ms=Convert.ToInt32(timeout.TotalMilliseconds);
-                       
-                       if(ms < 0 || ms > Int32.MaxValue) {
-                               throw new ArgumentOutOfRangeException("timeout out of range");
-                       }
-                       return Join_internal(Internal, ms, Internal.system_thread_handle);
+                       long ms = (long) timeout.TotalMilliseconds;
+                       if (ms < Timeout.Infinite || ms > Int32.MaxValue)
+                               throw new ArgumentOutOfRangeException ("timeout", "timeout out of range");
+
+                       return Join_internal (Internal, (int) ms, Internal.system_thread_handle);
                }
 #endif
 
index ace9623cc5a4669df46149b937fd26ff17984aab..f36f481c743a0e14486e3739e5ae075ac1c870e2 100644 (file)
@@ -1,3 +1,8 @@
+2009-10-25  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * ThreadTest.cs: Add test cases for Current[UI]Culture (not 
+       working), Name, Join, Sleep and SpinWait
+
 2009-10-22  Sebastien Pouliot  <sebastien@ximian.com>
 
        * EventWaitHandleTest.cs: New. Test case for EventResetMode 
index 945494e490a00b0636b398d9551568e3ffd7b31c..cf592f9dea50558ef72e5ea28b25e18a2561e05f 100644 (file)
@@ -88,6 +88,12 @@ namespace MonoTests.System.Threading
        [TestFixture]
        public class ThreadTest
        {
+               TimeSpan Infinite = new TimeSpan (-10000);      // -10000 ticks == -1 ms
+               TimeSpan SmallNegative = new TimeSpan (-2);     // between 0 and -1.0 (infinite) ms
+               TimeSpan Negative = new TimeSpan (-20000);      // really negative
+               TimeSpan MaxValue = TimeSpan.FromMilliseconds ((long) Int32.MaxValue);
+               TimeSpan TooLarge = TimeSpan.FromMilliseconds ((long) Int32.MaxValue + 1);
+
                static bool is_win32;
                static bool is_mono;
 
@@ -228,7 +234,27 @@ namespace MonoTests.System.Threading
                public void TestCtor1()
                {
                        C1Test test1 = new C1Test();
-                       Thread TestThread = new Thread(new ThreadStart(test1.TestMethod));
+                       Thread t = new Thread (new ThreadStart (test1.TestMethod));
+
+                       Assert.IsTrue (t.CurrentCulture.IsReadOnly, "CurrentCulture.IsReadOnly");
+                       Assert.IsFalse (t.IsAlive, "IsAlive");
+                       Assert.IsFalse (t.IsBackground, "IsBackground");
+                       Assert.IsNull (t.Name, "Name");
+                       Assert.AreEqual (ThreadState.Unstarted, t.ThreadState, "ThreadState");
+               }
+
+               [Test]
+               [Category ("NotWorking")] // we're not sharing (read-only) CultureInfo
+               public void CultureInfo_Shared_Across_Threads ()
+               {
+                       Thread t = new Thread (TestCtor1);
+                       Assert.AreSame (t.CurrentCulture, t.CurrentUICulture, "Culture");
+
+                       Assert.AreSame (t.CurrentCulture, CultureInfo.CurrentCulture, "CultureInfo.CurrentCulture");
+                       Assert.AreSame (t.CurrentUICulture, CultureInfo.CurrentUICulture, "CultureInfo.CurrentUICulture");
+
+                       Assert.AreSame (t.CurrentCulture, Thread.CurrentThread.CurrentCulture, "Thread.CurrentThread.CurrentCulture");
+                       Assert.AreSame (t.CurrentUICulture, Thread.CurrentThread.CurrentUICulture, "Thread.CurrentThread.CurrentUICulture");
                }
 
                [Test] // bug #325566
@@ -476,6 +502,24 @@ namespace MonoTests.System.Threading
                        }
                }
 
+               [Test]
+               public void Name ()
+               {
+                       Thread t = new Thread (new ThreadStart (Name));
+                       Assert.IsNull (t.Name, "Name-1");
+                       t.Name = null;
+                       Assert.IsNull (t.Name, "Name-2");
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void ReName ()
+               {
+                       Thread t = new Thread (new ThreadStart (ReName));
+                       t.Name = "a";
+                       t.Name = "b";
+               }
+
                [Test]
                public void TestNestedThreads1()
                {
@@ -518,6 +562,70 @@ namespace MonoTests.System.Threading
                        }
                }
 
+               [Test]
+               [ExpectedException (typeof (ArgumentOutOfRangeException))]
+               public void Join_Int32_Negative ()
+               {
+                       // -1 is Timeout.Infinite
+                       Thread.CurrentThread.Join (-2);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentOutOfRangeException))]
+               public void Join_TimeSpan_Negative ()
+               {
+                       Thread.CurrentThread.Join (Negative);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentOutOfRangeException))]
+               public void Join_TimeSpan_TooLarge ()
+               {
+                       Thread.CurrentThread.Join (TooLarge);
+               }
+
+               [Test]
+               public void Join_TimeSpan_SmallNegative ()
+               {
+                       Thread.CurrentThread.Join (SmallNegative);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentOutOfRangeException))]
+               public void Sleep_Int32_Negative ()
+               {
+                       // -1 is Timeout.Infinite
+                       Thread.Sleep (-2);
+               }
+
+               [Test]
+               public void Sleep_TimeSpan_SmallNegative ()
+               {
+                       Thread.Sleep (SmallNegative);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentOutOfRangeException))]
+               public void Sleep_TimeSpan_Negative ()
+               {
+                       Thread.Sleep (Negative);
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentOutOfRangeException))]
+               public void Sleep_TimeSpan_TooLarge ()
+               {
+                       Thread.Sleep (TooLarge);
+               }
+
+               [Test]
+               public void SpinWait ()
+               {
+                       // no exception for negative numbers
+                       Thread.SpinWait (Int32.MinValue);
+                       Thread.SpinWait (0);
+               }
+
                [Test]
                public void TestThreadState ()
                {