merged Sys.Web.Services 2.0 support in my branch:
[mono.git] / mono / tests / cas / linkdemand / pinvoke4.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                 uint u = (RunningOnMono ()) ? getuid () : GetTickCount ();
28                 Console.WriteLine ("*1* Unexpected P/Invoke success: {0}", u);
29                 return 1;
30         }
31
32         static int Main ()
33         {
34                 try {
35                         return Test ();
36                 }
37                 catch (SecurityException se) {
38                         Console.WriteLine ("*0* SecurityException\n{0}", se);
39                         return 0;
40                 }
41                 catch (Exception e) {
42                         Console.WriteLine ("*2* Unexpected exception\n{0}", e);
43                         return 2;
44                 }
45         }
46 }