From 2d0767d3b8e660ab257a76d1fd98743764e9b87c Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Thu, 22 Oct 2009 20:46:35 +0000 Subject: [PATCH] In System.Threading: 2009-10-22 Sebastien Pouliot * EventWaitHandle.cs: Add validation on the EventResetMode parameter used in the constructors In .: 2009-10-22 Sebastien Pouliot * corlib_test.dll.sources: Add System/WeakReferenceTest and System.Threading/EventWaitHandleTest.cs In Test/System.Threading: 2009-10-22 Sebastien Pouliot * EventWaitHandleTest.cs: New. Test case for EventResetMode validation In Test/System: 2009-10-22 Sebastien Pouliot * WeakReferenceTest.cs: New. Basic test cases svn path=/trunk/mcs/; revision=144681 --- mcs/class/corlib/ChangeLog | 5 ++ mcs/class/corlib/System.Threading/ChangeLog | 4 +- .../corlib/System.Threading/EventWaitHandle.cs | 21 +++-- mcs/class/corlib/Test/System.Threading/ChangeLog | 4 +- .../Test/System.Threading/EventWaitHandleTest.cs | 51 +++++++++++ mcs/class/corlib/Test/System/ChangeLog | 5 +- mcs/class/corlib/Test/System/WeakReferenceTest.cs | 100 +++++++++++++++++++++ mcs/class/corlib/corlib_test.dll.sources | 2 + 8 files changed, 183 insertions(+), 9 deletions(-) create mode 100644 mcs/class/corlib/Test/System.Threading/EventWaitHandleTest.cs create mode 100644 mcs/class/corlib/Test/System/WeakReferenceTest.cs diff --git a/mcs/class/corlib/ChangeLog b/mcs/class/corlib/ChangeLog index cb1b9ceae68..e7c6d13f788 100644 --- a/mcs/class/corlib/ChangeLog +++ b/mcs/class/corlib/ChangeLog @@ -1,3 +1,8 @@ +2009-10-22 Sebastien Pouliot + + * corlib_test.dll.sources: Add System/WeakReferenceTest and + System.Threading/EventWaitHandleTest.cs + 2009-10-21 Sebastien Pouliot * corlib_test.dll.sources: Add System.Threading/WaitHandleTest.cs diff --git a/mcs/class/corlib/System.Threading/ChangeLog b/mcs/class/corlib/System.Threading/ChangeLog index 48d9846b676..7f418c58b38 100644 --- a/mcs/class/corlib/System.Threading/ChangeLog +++ b/mcs/class/corlib/System.Threading/ChangeLog @@ -1,5 +1,7 @@ -2009-10-22 Sebastien Pouliot +2009-10-22 Sebastien Pouliot + * 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. diff --git a/mcs/class/corlib/System.Threading/EventWaitHandle.cs b/mcs/class/corlib/System.Threading/EventWaitHandle.cs index d812b3ddd89..f5ae953ed98 100644 --- a/mcs/class/corlib/System.Threading/EventWaitHandle.cs +++ b/mcs/class/corlib/System.Threading/EventWaitHandle.cs @@ -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] diff --git a/mcs/class/corlib/Test/System.Threading/ChangeLog b/mcs/class/corlib/Test/System.Threading/ChangeLog index 894703676f2..ace9623cc5a 100644 --- a/mcs/class/corlib/Test/System.Threading/ChangeLog +++ b/mcs/class/corlib/Test/System.Threading/ChangeLog @@ -1,5 +1,7 @@ -2009-10-22 Sebastien Pouliot +2009-10-22 Sebastien Pouliot + * 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 index 00000000000..c7f62c2b728 --- /dev/null +++ b/mcs/class/corlib/Test/System.Threading/EventWaitHandleTest.cs @@ -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 + diff --git a/mcs/class/corlib/Test/System/ChangeLog b/mcs/class/corlib/Test/System/ChangeLog index c29ad8ea2c3..4c81c34fe2a 100644 --- a/mcs/class/corlib/Test/System/ChangeLog +++ b/mcs/class/corlib/Test/System/ChangeLog @@ -1,9 +1,12 @@ +2009-10-22 Sebastien Pouliot + + * WeakReferenceTest.cs: New. Basic test cases + 2009-10-06 Jonathan Chambers * StringTest.cs (Contains): Add test for Contains using an Ordinal compare. Bug #535425. - 2009-09-24 Zoltan Varga * 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 index 00000000000..a9609e40d86 --- /dev/null +++ b/mcs/class/corlib/Test/System/WeakReferenceTest.cs @@ -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"); + } + } + } +} + diff --git a/mcs/class/corlib/corlib_test.dll.sources b/mcs/class/corlib/corlib_test.dll.sources index 2fd2c867dc5..5041e916c17 100644 --- a/mcs/class/corlib/corlib_test.dll.sources +++ b/mcs/class/corlib/corlib_test.dll.sources @@ -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 -- 2.11.4.GIT