2005-02-08 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mono / tests / cas / linkdemand / icall2.cs
1 using System;
2 using System.Reflection;
3 using System.Security;
4
5 namespace Test {
6
7         public class Program {
8
9                 private const string icall = "internalGetGacPath";
10
11                 static bool IsEcmaSigned ()
12                 {
13                         byte[] pk = Assembly.GetExecutingAssembly ().GetName ().GetPublicKey ();
14                         if ((pk != null) && (pk.Length == 16) && (pk [8] == 0x04)) {
15                                 int n = 0;
16                                 for (int i=0; i < pk.Length; i++)
17                                         n += pk [i];
18                                 if (n == 4)
19                                         return true;
20                         }
21                         return false;
22                 }
23
24                 static int Main ()
25                 {
26                         MethodInfo mi = typeof (System.Environment).GetMethod (icall, 
27                                 BindingFlags.Static | BindingFlags.NonPublic);
28                         if (mi == null) {
29                                 Console.WriteLine ("*3* Couldn't reflect on internalcall {0}", icall);
30                                 return 3;
31                         }
32
33                         try {
34                                 string gac = (string)mi.Invoke (null, null);
35                                 int ec = IsEcmaSigned () ? 0 : 1;
36                                 Console.WriteLine ("*{0}* internalGetGacPath: {1}", ec, gac);
37                                 return ec;
38                         }
39                         catch (SecurityException se) {
40                                 int ec = IsEcmaSigned () ? 1 : 0;
41                                 Console.WriteLine ("*{0}* Expected SecurityException\n{1}", ec, se);
42                                 return ec;
43                         }
44                         catch (Exception e) {
45                                 Console.WriteLine ("*2* Unexpected exception\n{0}", e);
46                                 return 2;
47                         }
48                 }
49         }
50 }