// (C) Eduardo Garcia Cebollero\r
// \r
\r
-using NUnit.Framework;\r
using System;\r
using System.Threading;\r
\r
+using NUnit.Framework;\r
+\r
namespace MonoTests.System.Threading\r
{\r
-\r
- public class MutexTest : TestCase \r
+ [TestFixture]\r
+ public class MutexTest\r
{\r
- \r
//Auxiliary Classes (Future Threads)\r
private class ConcClass\r
{\r
this.id = id;\r
this.mut = mut;\r
}\r
- public void wait()\r
+ public void Wait()\r
{\r
mut.WaitOne();\r
}\r
- public void signal()\r
+ public void Signal()\r
{\r
mut.ReleaseMutex();\r
}\r
public void WithoutWait()\r
{\r
this.marker = this.id;\r
- this.signal();\r
+ this.Signal();\r
}\r
\r
\r
{\r
while (this.marker<100)\r
{\r
- this.wait();\r
+ this.Wait();\r
this.marker++;\r
- this.signal();\r
+ this.Signal();\r
}\r
}\r
\r
public void WaitAndForget()\r
{\r
- this.wait();\r
+ this.Wait();\r
this.marker = id;\r
}\r
public void WaitAndWait()\r
}\r
}\r
\r
- protected override void SetUp() {}\r
-\r
- protected override void TearDown() {}\r
-\r
+ [Test]\r
public void TestCtor1()\r
{\r
- try\r
- {\r
- Mutex Sem = new Mutex();\r
- }\r
- catch (Exception e)\r
- {\r
- Fail("#01 Error Creating The Simple Mutex:" + e.ToString());\r
- }\r
+ Mutex Sem = new Mutex();\r
}\r
\r
// These tests produce mutex release errors\r
-/*\r
+/**\r
+ [Test]\r
public void TestCtorDefaultValue()\r
{\r
Mutex Sem = new Mutex();\r
AssertEquals("#02 The default value of The mutex wrong set:",class1.id,class1.marker);\r
}\r
\r
+ [Test]\r
public void TestCtorCtor2()\r
{\r
Mutex Sem = new Mutex(false);\r
while(thread1.IsAlive);\r
AssertEquals("#03 The value of The mutex wrong set:",class1.id,class1.marker);\r
}\r
- \r
+ \r
+ [Test]\r
public void TestCtorCtor3()\r
{\r
Mutex Sem = new Mutex(true);\r
while(thread1.IsAlive);\r
AssertEquals("#04 The default value of The mutex wrong set:",class1.id,class1.marker);\r
}\r
-\r
*/\r
- \r
+\r
// Hangs #72534\r
+ [Test]\r
[Category("NotWorking")]\r
public void TestWaitAndSignal1()\r
{\r
- Mutex Sem = new Mutex(false);\r
- ConcClassLoop class1 = new ConcClassLoop(1,Sem);\r
- Thread thread1 = new Thread(new ThreadStart(class1.Loop));\r
+ Mutex Sem = new Mutex (false);\r
+ ConcClassLoop class1 = new ConcClassLoop (1, Sem);\r
+ Thread thread1 = new Thread (new ThreadStart (class1.Loop));\r
try {\r
- thread1.Start();\r
+ thread1.Start ();\r
TestUtil.WaitForNotAlive (thread1, "");\r
- AssertEquals("#41 Mutex Worked InCorrecly:",100,class1.marker);\r
- }\r
- finally {\r
+ Assert.AreEqual (100, class1.marker);\r
+ } finally {\r
thread1.Abort ();\r
}\r
}\r
\r
// Hangs\r
+ [Test]\r
[Category("NotWorking")]\r
+ [Ignore ("It hangs and breaks the domain which runs nunit-console itself")]\r
public void TestWaitAndFoget1()\r
{\r
Mutex Sem = new Mutex(false);\r
thread2.Start();\r
TestUtil.WaitForNotAlive (thread2, "t2");\r
\r
- AssertEquals("#51 The Mutex Has been Kept after end of the thread:", class2.id,class2.marker);\r
- }\r
- finally {\r
+ Assert.AreEqual (class2.id, class2.marker);\r
+ } finally {\r
thread1.Abort ();\r
thread2.Abort ();\r
}\r
}\r
\r
+ [Test]\r
+ [Category("TargetJvmNotSupported")] // IntPtr native handles are not supported for TARGET_JVM.\r
public void TestHandle()\r
{\r
Mutex Sem = new Mutex();\r
- try\r
- {\r
- IntPtr Handle = Sem.Handle;\r
- }\r
- catch (Exception e)\r
- {\r
- Fail("#61 Unexpected Exception accessing Sem.Handle:" + e.ToString());\r
+ IntPtr Handle = Sem.Handle;\r
+ }\r
+\r
+ [Test] // bug #79358\r
+ [Category ("NotWorking")]\r
+ public void DoubleRelease ()\r
+ {\r
+ Mutex mutex = new Mutex ();\r
+ mutex.WaitOne ();\r
+ mutex.ReleaseMutex ();\r
+\r
+ try {\r
+ mutex.ReleaseMutex ();\r
+ Assert.Fail ("#1");\r
+ } catch (ApplicationException ex) {\r
+ Assert.AreEqual (typeof (ApplicationException), ex.GetType (), "#2");\r
}\r
}\r
}\r