Merge pull request #3387 from xmcclure/test-suite-bump
[mono.git] / mono / tests / priority.cs
1 using System;
2 using System.Threading;
3 using System.Runtime;
4 using System.Text;
5
6 public class Tests
7 {
8         public static int Main ()
9         {
10                 return TestDriver.RunTests (typeof (Tests));
11         }
12
13         public static void TestMethod()
14         {
15                 Console.WriteLine("{0} with {1} priority",
16                         Thread.CurrentThread.Name, 
17                         Thread.CurrentThread.Priority.ToString());
18                 Thread.Sleep(6000);
19                 Console.WriteLine("{0} with {1} priority",
20                         Thread.CurrentThread.Name, 
21                         Thread.CurrentThread.Priority.ToString());
22         }
23         
24         public static int test_0_thread_priority () 
25         {
26                 int res = 0;
27
28                 Thread Me = Thread.CurrentThread;
29                 Thread TestThread = new Thread(new ThreadStart(TestMethod));
30
31                 Console.WriteLine("Starting test thread with priority to AboveNormal");  
32                 ThreadPriority before = TestThread.Priority;
33                 TestThread.Priority = ThreadPriority.AboveNormal;
34                 TestThread.Name = "TestMethod";
35                 TestThread.Start();
36                 ThreadPriority after = TestThread.Priority;
37                 Console.WriteLine("Priority: {0} {1}",before,after);
38                 if (before != ThreadPriority.Normal)
39                         res = 1;
40                 else if (after != ThreadPriority.AboveNormal)
41                         res = 2;
42                 else {
43                         TestThread.Priority = ThreadPriority.Normal;
44                         after = TestThread.Priority;
45                         Console.WriteLine("Setting test thread priority to Normal");     
46                         Thread.Sleep(1000);
47                         Console.WriteLine("Priority: {0} {1}",before,after);
48
49                         if (after != ThreadPriority.Normal) 
50                                 res = 3;
51                         else {
52                                 Console.WriteLine("Setting test thread priority to AboveNormal");        
53                                 before = after;
54                                 TestThread.Priority=ThreadPriority.AboveNormal;
55                                 after = TestThread.Priority;
56                                 Thread.Sleep(1000);
57                                 Console.WriteLine("Priority: {0} {1}",before,after);
58
59                                 if (after != ThreadPriority.AboveNormal) 
60                                         res = 4;
61                                 else {
62                                         before = after;
63                                         Console.WriteLine("Setting test thread priority to BelowNormal"); 
64                                         TestThread.Priority=ThreadPriority.BelowNormal;
65                                         after = TestThread.Priority;
66                                         Console.WriteLine("Priority: {0} {1}",before,after);
67                                         Thread.Sleep(1000);
68                                         
69                                         if (after != ThreadPriority.BelowNormal)
70                                                 res = 5;
71                                         else {
72                                                 before = after;
73                                                 Console.WriteLine("Setting test thread priority back to Normal");        
74                                                 TestThread.Priority=ThreadPriority.Normal;
75                                                 after = TestThread.Priority;
76                                                 Console.WriteLine("Priority: {0} {1}",before,after);
77                                                 Thread.Sleep(1000);
78
79                                                 if (after != ThreadPriority.Normal)
80                                                         res = 6;
81                                         }
82                                 }
83                         }
84                 }
85                 TestThread.Join();
86                 return(res);
87         }
88 }