New test.
[mono.git] / mono / tests / cas / threads / swf-timer4.cs
1 using System;
2 using System.Reflection;
3 using System.Security;
4 using System.Security.Permissions;
5 using System.Windows.Forms;
6
7 class Program {
8
9         static void ShowStackTrace (object o, EventArgs e)
10         {
11                 if (debug)
12                         Console.WriteLine ("{0}: {1}", counter, Environment.StackTrace);
13
14                 try {
15                         Console.WriteLine (Assembly.GetExecutingAssembly ().Evidence.Count);
16                         result = 1;
17                 }
18                 catch (SecurityException se) {
19                         if (debug)
20                                 Console.WriteLine ("EXPECTED SecurityException {0}", se);
21                 }
22                 catch (Exception ex) {
23                         Console.WriteLine ("UNEXPECTED {0}", ex);
24                         result = 1;
25                 }
26
27                 counter++;
28         }
29
30         static bool debug;
31         static int counter;
32         static int result = 0;
33
34         // this Deny will prevent the Assembly.Evidence property from working
35         [SecurityPermission (SecurityAction.Deny, ControlEvidence = true)]
36         static int Main (string[] args)
37         {
38                 debug = (args.Length > 0);
39                 if (debug) {
40                         SecurityManager.SecurityEnabled = (args [0] != "off");
41                 }
42
43                 if (SecurityManager.SecurityEnabled) {
44                         Console.WriteLine ("SecurityManager.SecurityEnabled: true");
45                         ShowStackTrace (null, null);
46                 } else {
47                         Console.WriteLine ("SecurityManager.SecurityEnabled: false");
48                 }
49
50                 Timer t = new Timer ();
51                 t.Tick += new EventHandler (ShowStackTrace);
52                 t.Interval = 1000;
53                 t.Start ();
54                 
55                 while (counter <= 5)
56                         Application.DoEvents ();
57
58                 return result;
59         }
60 }