New test.
[mono.git] / mono / tests / cas / demand / sucs1.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 RunningOnMono ()
17         {
18                 bool mono = (Type.GetType ("Mono.Math.BigInteger") != null); 
19                 Console.WriteLine ("Running on {0} runtime...", mono ? "Mono" : "Microsoft");
20                 return mono;
21         }
22
23         static int Test ()
24         {
25                 try {
26                         uint u = (RunningOnMono ()) ? getuid () : GetTickCount ();
27                         Console.WriteLine ("*1* P/Invoke: {0}", u);
28                         return 1;
29                 }
30                 catch (SecurityException se) {
31                         Console.WriteLine ("*0* Expected SecurityException\n{0}", se);
32                         return 0;
33                 }
34                 catch (Exception e) {
35                         Console.WriteLine ("*2* Unexpected exception\n{0}", e);
36                         return 2;
37                 }
38         }
39
40         [SecurityPermission (SecurityAction.Deny, UnmanagedCode=true)]
41         static int Main ()
42         {
43                 return Test ();
44         }
45 }