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