Browse Source

2005-11-17 Sebastien Pouliot <[email protected]>

	* SemaphoreCas.cs: New. CAS tests for Semaphore (2.0).
	* SemaphoreFullExceptionCas.cs: New. CAS unit tests (2.0).
	* SemaphoreTest.cs: New. Unit tests for Semaphore (2.0).
	* ThreadExceptionEventArgsCas.cs: New. CAS unit tests.

svn path=/trunk/mcs/; revision=53177
Sebastien Pouliot 20 years ago
parent
commit
752ef1990e

+ 6 - 0
mcs/class/System/Test/System.Threading/ChangeLog

@@ -0,0 +1,6 @@
+2005-11-17  Sebastien Pouliot  <[email protected]>
+
+	* SemaphoreCas.cs: New. CAS tests for Semaphore (2.0).
+	* SemaphoreFullExceptionCas.cs: New. CAS unit tests (2.0).
+	* SemaphoreTest.cs: New. Unit tests for Semaphore (2.0).
+	* ThreadExceptionEventArgsCas.cs: New. CAS unit tests.

+ 111 - 0
mcs/class/System/Test/System.Threading/SemaphoreCas.cs

@@ -0,0 +1,111 @@
+//
+// SemaphoreCas.cs - CAS unit tests for System.Threading.Semaphore
+//
+// Author:
+//	Sebastien Pouliot  <[email protected]>
+//
+// Copyright (C) 2005 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 NUnit.Framework;
+
+using System;
+using System.Reflection;
+using System.Security;
+using System.Security.Permissions;
+using System.Threading;
+
+using MonoTests.System.Threading;
+
+namespace MonoCasTests.System.Threading {
+
+	[TestFixture]
+	[Category ("CAS")]
+	public class SemaphoreCas {
+
+		private SemaphoreTest unit;
+
+		[TestFixtureSetUp]
+		public void FixtureSetup ()
+		{
+			unit = new SemaphoreTest ();
+		}
+
+		[SetUp]
+		public void SetUp ()
+		{
+			if (!SecurityManager.SecurityEnabled)
+				Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
+		}
+
+		[Test]
+		[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
+		[Category ("NotWorking")] // not implemented in Mono
+		public void ReuseUnitTest_Deny_Unrestricted ()
+		{
+			unit.Constructor_IntInt ();
+			unit.Constructor_IntIntString_NullName ();
+			unit.Constructor_IntIntStringBool_NegativeInitialCount ();
+			unit.Constructor_IntIntStringBool_ZeroMaximumCount ();
+			unit.Constructor_IntIntStringBool_InitialBiggerThanMaximum ();
+			unit.Constructor_IntIntStringBool_NullName ();
+			unit.Constructor_IntIntStringBoolSecurity_NegativeInitialCount ();
+			unit.Constructor_IntIntStringBoolSecurity_ZeroMaximumCount ();
+			unit.Constructor_IntIntStringBoolSecurity_InitialBiggerThanMaximum ();
+			unit.Constructor_IntIntStringBoolSecurity_NullName ();
+			unit.Constructor_IntIntStringBoolSecurity ();
+			unit.OpenExisting_BadRights ();
+			unit.Release ();
+		}
+
+		[Test]
+		[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
+		[ExpectedException (typeof (SecurityException))]
+		[Category ("NotWorking")] // not implemented in Mono
+		public void ReuseUnitTest_Deny_UnmanagedCode ()
+		{
+			unit.AccessControl_Unnamed ();
+		}
+
+		[Test]
+		[SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
+		[Category ("NotWorking")] // not implemented in Mono
+		public void ReuseUnitTest_PermitOnly_UnmanagedCode ()
+		{
+			unit.AccessControl_Unnamed ();
+		}
+
+		[Test]
+		[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
+		public void LinkDemand_Deny_Unrestricted ()
+		{
+			Type[] types = new Type[2] { typeof (int), typeof (int) };
+			ConstructorInfo ci = typeof (Semaphore).GetConstructor (types);
+			Assert.IsNotNull (ci, ".ctor(int,int)");
+			Assert.IsNotNull (ci.Invoke (new object[2] { 0, 1 }), "invoke");
+		}
+	}
+}
+
+#endif

+ 73 - 0
mcs/class/System/Test/System.Threading/SemaphoreFullExceptionCas.cs

@@ -0,0 +1,73 @@
+//
+// SemaphoreFullExceptionCas.cs 
+//	- CAS unit tests for System.Threading.SemaphoreFullException
+//
+// Author:
+//	Sebastien Pouliot  <[email protected]>
+//
+// Copyright (C) 2005 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 NUnit.Framework;
+
+using System;
+using System.Reflection;
+using System.Security;
+using System.Security.Permissions;
+using System.Threading;
+
+namespace MonoCasTests.System.Threading {
+
+	[TestFixture]
+	[Category ("CAS")]
+	public class SemaphoreFullExceptionCas {
+
+		[SetUp]
+		public void SetUp ()
+		{
+			if (!SecurityManager.SecurityEnabled)
+				Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
+		}
+
+		[Test]
+		[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
+		public void Deny_Unrestricted ()
+		{
+			Assert.IsNotNull (new SemaphoreFullException (), "default ctor");
+			Assert.IsNotNull (new SemaphoreFullException ("msg"), "ctor(string)");
+			Assert.IsNotNull (new SemaphoreFullException ("msg", new Exception ()), "ctor(string.Exception)");
+		}
+
+		[Test]
+		[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
+		public void LinkDemand_Deny_Unrestricted ()
+		{
+			ConstructorInfo ci = typeof (SemaphoreFullException).GetConstructor (new Type [0]);
+			Assert.IsNotNull (ci, "default .ctor()");
+			Assert.IsNotNull (ci.Invoke (null), "invoke");
+		}
+	}
+}
+
+#endif

+ 277 - 0
mcs/class/System/Test/System.Threading/SemaphoreTest.cs

@@ -0,0 +1,277 @@
+//
+// SemaphoreTest.cs - Unit tests for System.Threading.Semaphore
+//
+// Author:
+//	Sebastien Pouliot  <[email protected]>
+//
+// Copyright (C) 2005 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 NUnit.Framework;
+
+using System;
+using System.Security.AccessControl;
+using System.Threading;
+
+namespace MonoTests.System.Threading {
+
+	[TestFixture]
+	public class SemaphoreTest {
+
+		[Test]
+		[ExpectedException (typeof (ArgumentOutOfRangeException))]
+		public void Constructor_IntInt_NegativeInitialCount ()
+		{
+			new Semaphore (-1, 1);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentOutOfRangeException))]
+		public void Constructor_IntInt_ZeroMaximumCount ()
+		{
+			new Semaphore (0, 0);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentException))]
+		public void Constructor_IntInt_InitialBiggerThanMaximum ()
+		{
+			new Semaphore (2, 1);
+		}
+
+		[Test]
+		[Category ("NotWorking")] // not implemented in Mono
+		public void Constructor_IntInt ()
+		{
+			new Semaphore (1, 2);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentOutOfRangeException))]
+		public void Constructor_IntIntString_NegativeInitialCount ()
+		{
+			new Semaphore (-1, 1, "mono");
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentOutOfRangeException))]
+		public void Constructor_IntIntString_ZeroMaximumCount ()
+		{
+			new Semaphore (0, 0, "mono");
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentException))]
+		public void Constructor_IntIntString_InitialBiggerThanMaximum ()
+		{
+			new Semaphore (2, 1, "mono");
+		}
+
+		[Test]
+		[Category ("NotWorking")] // not implemented in Mono
+		public void Constructor_IntIntString_NullName ()
+		{
+			new Semaphore (0, 1, null);
+		}
+
+		[Test]
+		public void Constructor_IntIntStringBool_NegativeInitialCount ()
+		{
+			bool created = true;
+			try {
+				new Semaphore (-1, 1, "mono", out created);
+			}
+			catch (ArgumentOutOfRangeException) {
+				Assert.IsTrue (created, "Created");
+			}
+		}
+
+		[Test]
+		public void Constructor_IntIntStringBool_ZeroMaximumCount ()
+		{
+			bool created = true;
+			try {
+				new Semaphore (0, 0, "mono", out created);
+			}
+			catch (ArgumentOutOfRangeException) {
+				Assert.IsTrue (created, "Created");
+			}
+		}
+
+		[Test]
+		public void Constructor_IntIntStringBool_InitialBiggerThanMaximum ()
+		{
+			bool created = true;
+			try {
+				new Semaphore (2, 1, "mono", out created);
+			}
+			catch (ArgumentException) {
+				Assert.IsTrue (created, "Created");
+			}
+		}
+
+		[Test]
+		[Category ("NotWorking")] // not implemented in Mono
+		public void Constructor_IntIntStringBool_NullName ()
+		{
+			bool created = false;
+			new Semaphore (0, 1, null, out created);
+			Assert.IsTrue (created, "Created");
+		}
+
+		[Test]
+		public void Constructor_IntIntStringBoolSecurity_NegativeInitialCount ()
+		{
+			bool created = true;
+			try {
+				new Semaphore (-1, 1, "mono", out created, null);
+			}
+			catch (ArgumentOutOfRangeException) {
+				Assert.IsTrue (created, "Created");
+			}
+		}
+
+		[Test]
+		public void Constructor_IntIntStringBoolSecurity_ZeroMaximumCount ()
+		{
+			bool created = true;
+			try {
+				new Semaphore (0, 0, "mono", out created, null);
+			}
+			catch (ArgumentOutOfRangeException) {
+				Assert.IsTrue (created, "Created");
+			}
+		}
+
+		[Test]
+		public void Constructor_IntIntStringBoolSecurity_InitialBiggerThanMaximum ()
+		{
+			bool created = true;
+			try {
+				new Semaphore (2, 1, "mono", out created, null);
+			}
+			catch (ArgumentException) {
+				Assert.IsTrue (created, "Created");
+			}
+		}
+
+		[Test]
+		[Category ("NotWorking")] // not implemented in Mono
+		public void Constructor_IntIntStringBoolSecurity_NullName ()
+		{
+			bool created = false;
+			new Semaphore (0, 1, null, out created, null);
+			Assert.IsTrue (created, "Created");
+		}
+
+		[Test]
+		[Category ("NotWorking")] // not implemented in Mono
+		public void Constructor_IntIntStringBoolSecurity ()
+		{
+			bool created = false;
+			SemaphoreSecurity ss = new SemaphoreSecurity ();
+			new Semaphore (0, 1, "secure", out created, ss);
+			Assert.IsTrue (created, "Created");
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		public void OpenExisting_NullName ()
+		{
+			Semaphore.OpenExisting (null);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentException))]
+		public void OpenExisting_EmptyName ()
+		{
+			Semaphore.OpenExisting (String.Empty);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentException))]
+		public void OpenExisting_TooLongName ()
+		{
+			Semaphore.OpenExisting (new String (' ', 261));
+		}
+
+		[Test]
+		[Category ("NotWorking")] // not implemented in Mono
+		[ExpectedException (typeof (WaitHandleCannotBeOpenedException))]
+		public void OpenExisting_Unexisting ()
+		{
+			Semaphore.OpenExisting (new String ('a', 260));
+		}
+
+		[Test]
+		[Category ("NotWorking")] // not implemented in Mono
+		public void OpenExisting_BadRights ()
+		{
+			Semaphore s = new Semaphore (0, 1, "bad-rights");
+			SemaphoreRights rights = (SemaphoreRights) Int32.MinValue;
+			Semaphore existing = Semaphore.OpenExisting ("bad-rights", rights);
+			// rights bits aren't validated
+			Assert.IsNotNull (existing, "OpenExisting");
+			Assert.IsFalse (Object.ReferenceEquals (s, existing), "!ref");
+		}
+
+		[Test]
+		[Category ("NotWorking")] // not implemented in Mono
+		public void AccessControl_Unnamed ()
+		{
+			Semaphore s = new Semaphore (0, 1, null);
+			SemaphoreSecurity ss = s.GetAccessControl ();
+			Assert.IsNotNull (ss, "GetAccessControl");
+			s.SetAccessControl (ss);
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentNullException))]
+		[Category ("NotWorking")] // not implemented in Mono
+		public void SetAccessControl_Null ()
+		{
+			Semaphore s = new Semaphore (0, 1, null);
+			s.SetAccessControl (null);
+		}
+
+		[Test]
+		[Category ("NotWorking")] // not implemented in Mono
+		public void Release ()
+		{
+			Semaphore s = new Semaphore (0, 1, null);
+			s.Release ();
+		}
+
+		[Test]
+		[ExpectedException (typeof (ArgumentOutOfRangeException))]
+		[Category ("NotWorking")] // not implemented in Mono
+		public void Release_Zero ()
+		{
+			Semaphore s = new Semaphore (0, 1, null);
+			s.Release (0);
+		}
+	}
+}
+
+#endif

+ 69 - 0
mcs/class/System/Test/System.Threading/ThreadExceptionEventArgsCas.cs

@@ -0,0 +1,69 @@
+//
+// ThreadExceptionEventArgsCas.cs 
+//	- CAS unit tests for System.Threading.ThreadExceptionEventArgs
+//
+// Author:
+//	Sebastien Pouliot  <[email protected]>
+//
+// Copyright (C) 2005 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 NUnit.Framework;
+
+using System;
+using System.Reflection;
+using System.Security;
+using System.Security.Permissions;
+using System.Threading;
+
+namespace MonoCasTests.System.Threading {
+
+	[TestFixture]
+	[Category ("CAS")]
+	public class ThreadExceptionEventArgsCas {
+
+		[SetUp]
+		public void SetUp ()
+		{
+			if (!SecurityManager.SecurityEnabled)
+				Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
+		}
+
+		[Test]
+		[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
+		public void Constructor_Deny_Unrestricted ()
+		{
+			ThreadExceptionEventArgs teea = new ThreadExceptionEventArgs (null);
+			Assert.IsNull (teea.Exception, "Exception");
+		}
+
+		[Test]
+		[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
+		public void LinkDemand_Deny_Unrestricted ()
+		{
+			Type[] types = new Type[1] { typeof (Exception) };
+			ConstructorInfo ci = typeof (ThreadExceptionEventArgs).GetConstructor (types);
+			Assert.IsNotNull (ci, ".ctor(Exception)");
+			Assert.IsNotNull (ci.Invoke (new object[1] { null }), "invoke");
+		}
+	}
+}