New test.
[mono.git] / mono / tests / cas / linkdemand / refcas4.cs
1 using System;
2 using System.Reflection;
3 using System.Security;
4 using System.Security.Permissions;
5
6 public class Program {
7
8         [SecurityPermission (SecurityAction.LinkDemand, ControlPrincipal=true)]
9         public static int Test ()
10         {
11                 return 1;
12         }
13
14         static MethodInfo GetReflectedCall ()
15         {
16                 return typeof (Program).GetMethod ("Test", BindingFlags.Static | BindingFlags.Public);
17         }
18
19         [SecurityPermission (SecurityAction.Deny, ControlPrincipal=true)]
20         static int CallReflectedCall (MethodInfo mi)
21         {
22                 return (int) mi.Invoke (null, null);
23         }
24
25         static int Main ()
26         {
27                 try {
28                         MethodInfo mi = GetReflectedCall ();
29                         if (mi == null) {
30                                 Console.WriteLine ("*2* Couldn't reflect on call Test (failure).");
31                                 return 2;
32                         } else {
33                                 int result = CallReflectedCall (mi);
34                                 if (result == 1)
35                                         Console.WriteLine ("*{0}* Unexpected calling thru reflection.", result);
36                                 else
37                                         Console.WriteLine ("*{0}* Unexpected return value from reflection.", result);
38
39                                 return result;
40                         }
41                 }
42                 catch (SecurityException) {
43                         Console.WriteLine ("*0* Expected SecurityException.");
44                         return 0;
45                 }
46         }
47 }