New test.
[mono.git] / mono / tests / cas / threads / tpool1.cs
1 using System;
2 using System.Security;
3 using System.Security.Permissions;
4 using System.Threading;
5
6 class Program {
7
8         static void ShowStackTrace (object o)
9         {
10                 if (debug)
11                         Console.WriteLine ((int)o);
12
13                 try {
14                         Console.WriteLine (Environment.UserName);
15                         result = 1;
16                 }
17                 catch (SecurityException se) {
18                         if (debug)
19                                 Console.WriteLine ("EXPECTED SecurityException {0}", se);
20                 }
21                 catch (Exception ex) {
22                         Console.WriteLine ("UNEXPECTED {0}", ex);
23                         result = 1;
24                 }
25         }
26
27         static bool debug;
28         static int result = 0;
29
30         // this Deny will prevent the Environment.UserName property from working
31         [EnvironmentPermission (SecurityAction.Deny, Read = "USERNAME")]
32         static int Main (string[] args)
33         {
34                 debug = (args.Length > 0);
35                 if (debug) {
36                         SecurityManager.SecurityEnabled = (args [0] != "off");
37                 }
38
39                 if (SecurityManager.SecurityEnabled) {
40                         Console.WriteLine ("SecurityManager.SecurityEnabled: true");
41                         ShowStackTrace ((object)-1);
42                 } else {
43                         Console.WriteLine ("SecurityManager.SecurityEnabled: false");
44                 }
45
46                 result = 0;
47                 for (int i=0; i < 5; i++)
48                         ThreadPool.QueueUserWorkItem (new WaitCallback (ShowStackTrace), i);
49                 
50                 System.Threading.Thread.Sleep (5000);
51                 return result;
52         }
53 }