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=929f63ebbb7844a63a2f756bd53a5b912517d735;hpb=0b31cdd230641a40652edd14a1f30f2b588ba86a;p=mono.git diff --git a/mcs/class/corlib/Test/System.Threading/MutexTest.cs b/mcs/class/corlib/Test/System.Threading/MutexTest.cs index 929f63ebbb7..a4669029b88 100644 --- a/mcs/class/corlib/Test/System.Threading/MutexTest.cs +++ b/mcs/class/corlib/Test/System.Threading/MutexTest.cs @@ -1,20 +1,20 @@ // MutexTest.cs - NUnit Test Cases for System.Threading.Mutex // -// Eduardo Garcia Cebollero +// Eduardo Garcia Cebollero // // (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,20 +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); } - */ + + [Test] public void TestWaitAndSignal1() { - Mutex Sem = new Mutex(false); - ConcClassLoop class1 = new ConcClassLoop(1,Sem); - Thread thread1 = new Thread(new ThreadStart(class1.Loop)); - thread1.Start(); - while(thread1.IsAlive); - AssertEquals("#41 Mutex Worked InCorrecly:",100,class1.marker); + Mutex Sem = new Mutex (false); + ConcClassLoop class1 = new ConcClassLoop (1, Sem); + Thread thread1 = new Thread (new ThreadStart (class1.Loop)); + try { + thread1.Start (); + TestUtil.WaitForNotAlive (thread1, ""); + Assert.AreEqual (100, class1.marker); + } finally { + thread1.Abort (); + } } - + + [Test] public void TestWaitAndFoget1() { Mutex Sem = new Mutex(false); @@ -141,25 +140,41 @@ namespace MonoTests.System.Threading ConcClassLoop class2 = new ConcClassLoop(2,Sem); Thread thread1 = new Thread(new ThreadStart(class1.WaitAndForget)); Thread thread2 = new Thread(new ThreadStart(class2.WaitAndForget)); - thread1.Start(); - while(thread1.IsAlive); - thread2.Start(); - while(thread2.IsAlive); - AssertEquals("#51 The Mutex Has been Kept after end of the thread:", - class2.id,class2.marker); + + try { + thread1.Start(); + TestUtil.WaitForNotAlive (thread1, "t1"); + + thread2.Start(); + TestUtil.WaitForNotAlive (thread2, "t2"); + + 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"); } } } -} +}