Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
// BarrierTest.cs
//
// Copyright (c) 2010 Jérémie "Garuma" Laval
//
// 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_4_0
using NUnit.Framework;
using System;
using System.Threading;
namespace MonoTests.System.Threading {
[TestFixture]
public class BarrierTests {
Barrier barrier;
const int participants = 10;
bool triggered;
[SetUp]
public void Setup ()
{
barrier = new Barrier (participants, PostPhaseAction);
triggered = false;
}
void PostPhaseAction (Barrier b)
{
Assert.AreEqual (barrier, b, "postphase");
triggered = true;
}
[Test]
public void AddParticipantTest ()
{
barrier.AddParticipant ();
Assert.AreEqual (participants + 1, barrier.ParticipantCount, "#1");
barrier.AddParticipants (3);
Assert.AreEqual (participants + 4, barrier.ParticipantCount, "#2");
}
[Test]
public void RemoveParticipantTest ()
{
barrier.RemoveParticipant ();
Assert.AreEqual (participants - 1, barrier.ParticipantCount, "#1");
barrier.RemoveParticipants (3);
Assert.AreEqual (participants - 4, barrier.ParticipantCount, "#2");
}
[Test]
public void SignalTest ()
{
barrier.RemoveParticipants (participants - 2);
Assert.IsFalse (barrier.SignalAndWait (1), "#1");
barrier.SignalAndWait ();
Assert.IsTrue (triggered, "#3");
Assert.AreEqual (1, barrier.CurrentPhaseNumber, "#4");
}
[Test]
public void RemoveTriggeringTest ()
{
barrier.RemoveParticipants (participants - 2);
barrier.RemoveParticipants (2);
Assert.IsTrue (triggered, "#1");
Assert.AreEqual (1, barrier.CurrentPhaseNumber, "#2");
}
}
}
#endif

View File

@@ -0,0 +1,18 @@
2010-03-02 Jérémie Laval <jeremie.laval@gmail.com>
* BarrierTest.cs: Add BarrierTest.
2005-12-23 Dick Porter <dick@ximian.com>
* SemaphoreTest.cs: Enable another test
2005-12-06 Dick Porter <dick@ximian.com>
* SemaphoreTest.cs: Enable the tests
2005-11-17 Sebastien Pouliot <sebastien@ximian.com>
* 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.

View File

@@ -0,0 +1,111 @@
//
// SemaphoreCas.cs - CAS unit tests for System.Threading.Semaphore
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// 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

View File

@@ -0,0 +1,73 @@
//
// SemaphoreFullExceptionCas.cs
// - CAS unit tests for System.Threading.SemaphoreFullException
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// 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

View File

@@ -0,0 +1,274 @@
//
// SemaphoreTest.cs - Unit tests for System.Threading.Semaphore
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// 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]
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]
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]
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]
public void Constructor_IntIntStringBoolSecurity_NullName ()
{
bool created = false;
new Semaphore (0, 1, null, out created, null);
Assert.IsTrue (created, "Created");
}
[Test]
[Category ("MobileNotWorking")]
public void Constructor_IntIntStringBoolSecurity ()
{
bool created = false;
SemaphoreSecurity ss = new SemaphoreSecurity ();
new Semaphore (0, 1, "secure", out created, ss);
Assert.IsTrue (created, "Created");
}
[Test]
[Category ("MobileNotWorking")]
[ExpectedException (typeof (ArgumentNullException))]
public void OpenExisting_NullName ()
{
Semaphore.OpenExisting (null);
}
[Test]
[Category ("MobileNotWorking")]
[ExpectedException (typeof (ArgumentException))]
public void OpenExisting_EmptyName ()
{
Semaphore.OpenExisting (String.Empty);
}
[Test]
[Category ("MobileNotWorking")]
[ExpectedException (typeof (ArgumentException))]
public void OpenExisting_TooLongName ()
{
Semaphore.OpenExisting (new String (' ', 261));
}
[Test]
[Category ("MobileNotWorking")]
[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]
public void Release ()
{
Semaphore s = new Semaphore (0, 1, null);
s.Release ();
}
[Test]
[ExpectedException (typeof (ArgumentOutOfRangeException))]
public void Release_Zero ()
{
Semaphore s = new Semaphore (0, 1, null);
s.Release (0);
}
}
}
#endif

View File

@@ -0,0 +1,69 @@
//
// ThreadExceptionEventArgsCas.cs
// - CAS unit tests for System.Threading.ThreadExceptionEventArgs
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// 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");
}
}
}