New test.
[mono.git] / mono / tests / cas / linkdemand / pinvoke3.cs
1 using System;
2 using System.Runtime.InteropServices;
3 using System.Security;
4 using System.Security.Permissions;
5
6 [assembly: SecurityPermission (SecurityAction.RequestRefuse, UnmanagedCode=true)]
7
8 public class Program {
9
10         // for Mono
11         [DllImport ("libc", SetLastError=true)]
12         public static extern uint getuid ();
13
14         // for Microsoft
15         [DllImport ("kernel32.dll", SetLastError=true)]
16         public static extern uint GetTickCount ();
17
18         static bool RunningOnMono ()
19         {
20                 bool mono = (Type.GetType ("Mono.Math.BigInteger") != null); 
21                 Console.WriteLine ("Running on {0} runtime...", mono ? "Mono" : "Microsoft");
22                 return mono;
23         }
24
25         static int Test ()
26         {
27                 try {
28                         uint u = (RunningOnMono ()) ? getuid () : GetTickCount ();
29                         Console.WriteLine ("*0* P/Invoke: {0}", u);
30                         return 0;
31                 }
32                 catch (SecurityException se) {
33                         Console.WriteLine ("*1* Unexpected SecurityException\n{0}", se);
34                         return 1;
35                 }
36                 catch (Exception e) {
37                         Console.WriteLine ("*2* Unexpected exception\n{0}", e);
38                         return 2;
39                 }
40         }
41
42         static int Main ()
43         {
44                 return Test ();
45         }
46 }