Add a more functional (i.e. fewer-stubs) implementation of System.Data.Linq.
[mono.git] / mono / tests / cas / demand / pinvoke2.cs
1 using System;
2 using System.Runtime.InteropServices;
3 using System.Security;
4 using System.Security.Permissions;
5
6 [SecurityPermission (SecurityAction.Deny, UnmanagedCode=true)]
7 public class Program {
8
9         // for Mono
10         [DllImport ("libc", SetLastError=true)]
11         public static extern uint getuid ();
12
13         // for Microsoft
14         [DllImport ("kernel32.dll", SetLastError=true)]
15         public static extern uint GetTickCount ();
16
17         static bool RunningOnWindows ()
18         {
19                 int p = (int) Environment.OSVersion.Platform;
20                 bool win = ((p != 4) && (p != 128));
21                 Console.WriteLine ("Running on {0}...", Environment.OSVersion);
22                 return win;
23         }
24
25         static int Test ()
26         {
27                 try {
28                         uint u = (RunningOnWindows () ? GetTickCount () : getuid ());
29                         Console.WriteLine ("*1* P/Invoke: {0}", u);
30                         return 1;
31                 }
32                 catch (SecurityException se) {
33                         Console.WriteLine ("*0* Expected SecurityException\n{0}", se);
34                         return 0;
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 }