X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FTest%2FSystem.Threading%2FMutexTest.cs;h=a4669029b8882302d67cc2953ce2e7eee89677c3;hb=055495c537473805859a4db627918347be547ee3;hp=2fa5a2b3082a979756299d10639cdfcab80b9188;hpb=a8b22e0e864c03b8cfd2f2cb5a8075b6611c5553;p=mono.git diff --git a/mcs/class/corlib/Test/System.Threading/MutexTest.cs b/mcs/class/corlib/Test/System.Threading/MutexTest.cs index 2fa5a2b3082..a4669029b88 100644 --- a/mcs/class/corlib/Test/System.Threading/MutexTest.cs +++ b/mcs/class/corlib/Test/System.Threading/MutexTest.cs @@ -5,16 +5,16 @@ // (C) Eduardo Garcia Cebollero // -using NUnit.Framework; using System; using System.Threading; +using NUnit.Framework; + namespace MonoTests.System.Threading { - - public class MutexTest : TestCase + [TestFixture] + public class MutexTest { - //Auxiliary Classes (Future Threads) private class ConcClass { @@ -25,11 +25,11 @@ namespace MonoTests.System.Threading this.id = id; this.mut = mut; } - public void wait() + public void Wait() { mut.WaitOne(); } - public void signal() + public void Signal() { mut.ReleaseMutex(); } @@ -47,7 +47,7 @@ namespace MonoTests.System.Threading public void WithoutWait() { this.marker = this.id; - this.signal(); + this.Signal(); } @@ -55,15 +55,15 @@ namespace MonoTests.System.Threading { while (this.marker<100) { - this.wait(); + this.Wait(); this.marker++; - this.signal(); + this.Signal(); } } public void WaitAndForget() { - this.wait(); + this.Wait(); this.marker = id; } public void WaitAndWait() @@ -75,24 +75,15 @@ namespace MonoTests.System.Threading } } - protected override void SetUp() {} - - protected override void TearDown() {} - + [Test] public void TestCtor1() { - try - { - Mutex Sem = new Mutex(); - } - catch (Exception e) - { - Fail("#01 Error Creating The Simple Mutex:" + e.ToString()); - } + Mutex Sem = new Mutex(); } // These tests produce mutex release errors -/* +/** + [Test] public void TestCtorDefaultValue() { Mutex Sem = new Mutex(); @@ -100,9 +91,10 @@ namespace MonoTests.System.Threading Thread thread1 = new Thread(new ThreadStart(class1.WithoutWait)); thread1.Start(); while(thread1.IsAlive); - AssertEquals("#02 The default value of The mutex wrong set:",class1.id,class1.marker); + Assert.AreEqual(class1.id,class1.marker); } + [Test] public void TestCtorCtor2() { Mutex Sem = new Mutex(false); @@ -110,9 +102,10 @@ namespace MonoTests.System.Threading Thread thread1 = new Thread(new ThreadStart(class1.WithoutWait)); thread1.Start(); while(thread1.IsAlive); - AssertEquals("#03 The value of The mutex wrong set:",class1.id,class1.marker); + Assert.AreEqual(class1.id,class1.marker); } - + + [Test] public void TestCtorCtor3() { Mutex Sem = new Mutex(true); @@ -120,31 +113,26 @@ namespace MonoTests.System.Threading Thread thread1 = new Thread(new ThreadStart(class1.WithoutWait)); thread1.Start(); while(thread1.IsAlive); - AssertEquals("#04 The default value of The mutex wrong set:",class1.id,class1.marker); + Assert.AreEqual(class1.id,class1.marker); } - */ - - // Hangs #72534 - [Category("NotWorking")] + + [Test] public void TestWaitAndSignal1() { - Mutex Sem = new Mutex(false); - ConcClassLoop class1 = new ConcClassLoop(1,Sem); - Thread thread1 = new Thread(new ThreadStart(class1.Loop)); + Mutex Sem = new Mutex (false); + ConcClassLoop class1 = new ConcClassLoop (1, Sem); + Thread thread1 = new Thread (new ThreadStart (class1.Loop)); try { - thread1.Start(); + thread1.Start (); TestUtil.WaitForNotAlive (thread1, ""); - AssertEquals("#41 Mutex Worked InCorrecly:",100,class1.marker); - } - finally { + Assert.AreEqual (100, class1.marker); + } finally { thread1.Abort (); } } - // Hangs - [Category("NotWorking")] - [Ignore ("It hangs and breaks the domain which runs nunit-console itself")] + [Test] public void TestWaitAndFoget1() { Mutex Sem = new Mutex(false); @@ -160,24 +148,32 @@ namespace MonoTests.System.Threading thread2.Start(); TestUtil.WaitForNotAlive (thread2, "t2"); - AssertEquals("#51 The Mutex Has been Kept after end of the thread:", class2.id,class2.marker); - } - finally { + Assert.AreEqual (class2.id, class2.marker); + } finally { thread1.Abort (); thread2.Abort (); } } + [Test] public void TestHandle() { Mutex Sem = new Mutex(); - try - { - IntPtr Handle = Sem.Handle; - } - catch (Exception e) - { - Fail("#61 Unexpected Exception accessing Sem.Handle:" + e.ToString()); + IntPtr Handle = Sem.Handle; + } + + [Test] // bug #79358 + public void DoubleRelease () + { + Mutex mutex = new Mutex (); + mutex.WaitOne (); + mutex.ReleaseMutex (); + + try { + mutex.ReleaseMutex (); + Assert.Fail ("#1"); + } catch (ApplicationException ex) { + Assert.AreEqual (typeof (ApplicationException), ex.GetType (), "#2"); } } }