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