2009-11-20 Gonzalo Paniagua Javier <gonzalo@novell.com>
[mono.git] / mono / tests / thread6.cs
index 0db334e961a03481644e5716149ef25839b20b66..f8df7d22b16363b407448a04dcaf0d3f6750ff18 100644 (file)
@@ -1,7 +1,10 @@
+//
+// thread6.cs: Thread abort tests
+//
 using System;
 using System.Threading;
 
-public class MultiThreadExceptionTest {
+public class Tests {
 
        public static int result = 0;
        public static object started = new object ();
@@ -91,7 +94,10 @@ public class MultiThreadExceptionTest {
        }
        
        public static int Main() {
+               return TestDriver.RunTests (typeof (Tests));
+       }
 
+       public static int test_0_abort_current () {
                // Check aborting the current thread
                bool aborted = false;
                try {
@@ -104,27 +110,39 @@ public class MultiThreadExceptionTest {
                if (!aborted)
                        return 2;
 
-               Thread t1 = new Thread(new ThreadStart
-                       (MultiThreadExceptionTest.ThreadStart1));
-               t1.Name = "Thread 1";
+               return 0;
+       }
 
-               Thread.Sleep (100);
-               
-               t1.Start();
+       public static int test_0_test_1 () {
+               Thread t1 = null;
 
                lock (started) {
+                       t1 = new Thread(new ThreadStart
+                                                       (Tests.ThreadStart1));
+                       t1.Name = "Thread 1";
+
+                       Thread.Sleep (100);
+               
+                       t1.Start();
+
                        Monitor.Wait (started);
                }
-               
+
+               Thread.Sleep (100);
+
                t1.Abort ("STATETEST");
 
                t1.Join ();
-               Console.WriteLine ("Result: " + result);
 
-               if (result != 59)
+               if (result != 59) {
+                       Console.WriteLine ("Result: " + result);
                        return 1;
+               }
 
-               // Test from #68552
+               return 0;
+       }
+
+       public static int test_0_regress_68552 () {
                try {
                        try {
                                Run ();
@@ -137,7 +155,10 @@ public class MultiThreadExceptionTest {
                        Thread.ResetAbort ();
                }
 
-               // Test from #78024
+               return 0;
+       }
+
+       public static int test_0_regress_78024 () {
                try {
                        regress_78024 ();
                        return 3;
@@ -149,6 +170,34 @@ public class MultiThreadExceptionTest {
                return 0;
        }
 
+       public class CBO : ContextBoundObject {
+               public void Run () {
+                       Thread.CurrentThread.Abort ("FOO");
+               }
+       }
+
+       public static int test_0_regress_539394 () {
+               // Check that a ThreadAbortException thrown through remoting retains its
+               // abort state
+               AppDomain d = AppDomain.CreateDomain ("test");
+               CBO obj = (CBO)d.CreateInstanceFromAndUnwrap (typeof (Tests).Assembly.Location, "Tests/CBO");
+               bool success = false;
+
+               Thread t = new Thread (delegate () {
+                               try {
+                                       obj.Run ();
+                               } catch (ThreadAbortException ex) {
+                                       if ((string)ex.ExceptionState == "FOO")
+                                               success = true;
+                               }
+                       });
+
+               t.Start ();
+               t.Join ();
+
+               return success ? 0 : 1;
+       }
+
        public static void Run ()
        {
                try {