In System.Threading:
authorSebastien Pouliot <sebastien@ximian.com>
Thu, 22 Oct 2009 20:46:35 +0000 (20:46 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Thu, 22 Oct 2009 20:46:35 +0000 (20:46 -0000)
2009-10-22  Sebastien Pouliot  <sebastien@ximian.com>
* EventWaitHandle.cs: Add validation on the EventResetMode
parameter used in the constructors
In .:
2009-10-22  Sebastien Pouliot  <sebastien@ximian.com>

* corlib_test.dll.sources: Add System/WeakReferenceTest and
System.Threading/EventWaitHandleTest.cs

In Test/System.Threading:
2009-10-22  Sebastien Pouliot  <sebastien@ximian.com>
* EventWaitHandleTest.cs: New. Test case for EventResetMode
validation
In Test/System:
2009-10-22  Sebastien Pouliot  <sebastien@ximian.com>

* WeakReferenceTest.cs: New. Basic test cases

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

mcs/class/corlib/ChangeLog
mcs/class/corlib/System.Threading/ChangeLog
mcs/class/corlib/System.Threading/EventWaitHandle.cs
mcs/class/corlib/Test/System.Threading/ChangeLog
mcs/class/corlib/Test/System.Threading/EventWaitHandleTest.cs [new file with mode: 0644]
mcs/class/corlib/Test/System/ChangeLog
mcs/class/corlib/Test/System/WeakReferenceTest.cs [new file with mode: 0644]
mcs/class/corlib/corlib_test.dll.sources

index cb1b9ceae68530e80766245759ca8b8ea3ffb6d8..e7c6d13f788679a208f6db3e0bbab7b9e2bc1e22 100644 (file)
@@ -1,3 +1,8 @@
+2009-10-22  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * corlib_test.dll.sources: Add System/WeakReferenceTest and
+       System.Threading/EventWaitHandleTest.cs
+
 2009-10-21  Sebastien Pouliot  <sebastien@ximian.com>
 
        * corlib_test.dll.sources: Add System.Threading/WaitHandleTest.cs
index 48d9846b676b6fb00e742682c53201e77257f2a1..7f418c58b38ceea330075c9a720b7bcaf5d3433e 100644 (file)
@@ -1,5 +1,7 @@
-2009-10-22  Sebastien Pouliot  <sebastien@ximian.com> 
+2009-10-22  Sebastien Pouliot  <sebastien@ximian.com>
 
+       * EventWaitHandle.cs: Add validation on the EventResetMode 
+       parameter used in the constructors
        * Monitor.cs: Fix validations for TryEnter and Wait. Reduce 
        duplicated code between overloads.
 
index d812b3ddd89cadec3e42d28cd916502be7c8ab47..f5ae953ed981817ebc6f40f02525e70f4f6aa0fa 100644 (file)
@@ -44,26 +44,34 @@ namespace System.Threading
                {
                        Handle = handle;
                }
+
+               private bool IsManualReset (EventResetMode mode)
+               {
+                       if ((mode < EventResetMode.AutoReset) || (mode > EventResetMode.ManualReset))
+                               throw new ArgumentException ("mode");
+                       return (mode == EventResetMode.ManualReset);
+               }
                
                public EventWaitHandle (bool initialState, EventResetMode mode)
                {
                        bool created;
-                       
-                       Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, null, out created);
+                       bool manual = IsManualReset (mode);
+                       Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, null, out created);
                }
                
                public EventWaitHandle (bool initialState, EventResetMode mode,
                                        string name)
                {
                        bool created;
-                       
-                       Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, name, out created);
+                       bool manual = IsManualReset (mode);
+                       Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, name, out created);
                }
                
                public EventWaitHandle (bool initialState, EventResetMode mode,
                                        string name, out bool createdNew)
                {
-                       Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, name, out createdNew);
+                       bool manual = IsManualReset (mode);
+                       Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, name, out createdNew);
                }
 #if !NET_2_1
                [MonoTODO ("Implement access control")]
@@ -71,7 +79,8 @@ namespace System.Threading
                                        string name, out bool createdNew,
                                        EventWaitHandleSecurity eventSecurity)
                {
-                       Handle = NativeEventCalls.CreateEvent_internal ((mode == EventResetMode.ManualReset), initialState, name, out createdNew);
+                       bool manual = IsManualReset (mode);
+                       Handle = NativeEventCalls.CreateEvent_internal (manual, initialState, name, out createdNew);
                }
                
                [MonoTODO]
index 894703676f23939e434526283e68c0c972499625..ace9623cc5a4669df46149b937fd26ff17984aab 100644 (file)
@@ -1,5 +1,7 @@
-2009-10-22  Sebastien Pouliot  <sebastien@ximian.com> 
+2009-10-22  Sebastien Pouliot  <sebastien@ximian.com>
 
+       * EventWaitHandleTest.cs: New. Test case for EventResetMode 
+       validation
        * MonitorTest.cs: Mark existing tests as "NotWorking" since they
        fail in MS FX2 (maybe they worked in 1.x?). Add more test cases
        to validate the TryEnter and Wait overloaded methods.
diff --git a/mcs/class/corlib/Test/System.Threading/EventWaitHandleTest.cs b/mcs/class/corlib/Test/System.Threading/EventWaitHandleTest.cs
new file mode 100644 (file)
index 0000000..c7f62c2
--- /dev/null
@@ -0,0 +1,51 @@
+//
+// EventWaitHandleTest.cs - NUnit Test Cases for EventWaitHandle
+//
+// Author:
+//     Sebastien Pouliot (sebastien@ximian.com)
+//
+// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if NET_2_0
+
+using System;
+using System.Threading;
+
+using NUnit.Framework;
+
+namespace MonoTests.System.Threading {
+
+       [TestFixture]
+       public class EventWaitHandleTest {
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void EventWaitHandle_InvalidEventResetMode ()
+               {
+                       new EventWaitHandle (true, (EventResetMode) Int32.MinValue);
+               }
+       }
+}
+
+#endif
+
index c29ad8ea2c3b9fcfafddbee3f1a329025085478c..4c81c34fe2a761a8f7ead1f31ad4bc73f078c641 100644 (file)
@@ -1,9 +1,12 @@
+2009-10-22  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * WeakReferenceTest.cs: New. Basic test cases
+
 2009-10-06  Jonathan Chambers  <joncham@gmail.com>
 
        * StringTest.cs (Contains): Add test for Contains using
        an Ordinal compare. Bug #535425.
 
-
 2009-09-24  Zoltan Varga  <vargaz@gmail.com>
 
        * TypeTest.cs: Add a test for missing.
diff --git a/mcs/class/corlib/Test/System/WeakReferenceTest.cs b/mcs/class/corlib/Test/System/WeakReferenceTest.cs
new file mode 100644 (file)
index 0000000..a9609e4
--- /dev/null
@@ -0,0 +1,100 @@
+//
+// WeakReferenceTest.cs - NUnit Test Cases for WeakReference
+//
+// Author:
+//     Sebastien Pouliot (sebastien@ximian.com)
+//
+// Copyright (C) 2009 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.IO;
+
+using NUnit.Framework;
+
+namespace MonoTests.System {
+
+       [TestFixture]
+       public class WeakReferenceTest {
+
+               [Test]
+               public void WeakReference_Object_Null ()
+               {
+                       WeakReference wr = new WeakReference (null);
+                       Assert.IsFalse (wr.IsAlive, "IsAlive");
+                       Assert.IsNull (wr.Target, "Target");
+                       Assert.IsFalse (wr.TrackResurrection, "TrackResurrection");
+               }
+
+               [Test]
+               public void WeakReference_Object_Null_TrackResurrection_True ()
+               {
+                       WeakReference wr = new WeakReference (null, true);
+                       Assert.IsFalse (wr.IsAlive, "IsAlive");
+                       Assert.IsNull (wr.Target, "Target");
+                       Assert.IsTrue (wr.TrackResurrection, "TrackResurrection");
+               }
+
+               [Test]
+               public void WeakReference_Object_Null_TrackResurrection_False ()
+               {
+                       WeakReference wr = new WeakReference (null, false);
+                       Assert.IsFalse (wr.IsAlive, "IsAlive");
+                       Assert.IsNull (wr.Target, "Target");
+                       Assert.IsFalse (wr.TrackResurrection, "TrackResurrection");
+               }
+
+               [Test]
+               public void WeakReference_Object ()
+               {
+                       using (Stream s = Stream.Null) {
+                               WeakReference wr = new WeakReference (s);
+                               Assert.IsTrue (wr.IsAlive, "IsAlive");
+                               Assert.AreSame (s, wr.Target, "Target");
+                               Assert.IsFalse (wr.TrackResurrection, "TrackResurrection");
+                       }
+               }
+
+               [Test]
+               public void WeakReference_Object_TrackResurrection_True ()
+               {
+                       using (Stream s = Stream.Null) {
+                               WeakReference wr = new WeakReference (s, true);
+                               Assert.IsTrue (wr.IsAlive, "IsAlive");
+                               Assert.AreSame (s, wr.Target, "Target");
+                               Assert.IsTrue (wr.TrackResurrection, "TrackResurrection");
+                       }
+               }
+
+               [Test]
+               public void WeakReference_Object_TrackResurrection_False ()
+               {
+                       using (Stream s = Stream.Null) {
+                               WeakReference wr = new WeakReference (s, false);
+                               Assert.IsTrue (wr.IsAlive, "IsAlive");
+                               Assert.AreSame (s, wr.Target, "Target");
+                               Assert.IsFalse (wr.TrackResurrection, "TrackResurrection");
+                       }
+               }
+       }
+}
+
index 2fd2c867dc51f5a30cc223747241ebee108cb5ff..5041e916c17f9f94abf6d366a9d0112149804b69 100644 (file)
@@ -349,6 +349,7 @@ System.Text/UTF8EncodingTest.cs
 System.Text/UTF32EncodingTest.cs
 System.Threading/AutoResetEventTest.cs
 System.Threading/CompressedStackTest.cs
+System.Threading/EventWaitHandleTest.cs
 System.Threading/ExecutionContextTest.cs
 System.Threading/MonitorTest.cs
 System.Threading/MutexTest.cs
@@ -366,6 +367,7 @@ System/UInt64Test.cs
 System/UIntPtrTest.cs
 System/VersionTest.cs
 System/ValueTypeTest.cs
+System/WeakReferenceTest.cs
 System/ActivatorCas.cs
 System/AppDomainCas.cs
 System/BadImageFormatExceptionCas.cs