New test.
[mono.git] / mono / tests / cas / linkdemand / aptc2.cs
1 using System;
2 using System.Reflection;
3 using System.Security;
4 using System.Security.Permissions;
5
6 using Mono.Test;
7
8 #if RESTRICT
9 // this ensure we don't have FullTrust
10 [assembly: SecurityPermission (SecurityAction.RequestRefuse, SkipVerification = true)]
11 #endif
12
13 public class Program {
14
15         static bool IsRestricted ()
16         {
17 #if RESTRICT
18                 return true;
19 #else
20                 return false;
21 #endif
22         }
23
24         static int Main ()
25         {
26                 try {
27                         // aptclib.dll is strongnamed and DOESN'T have [AllowPartiallyTrustedCallers]
28                         // so this call will work ONLY IF this assembly IS strongnamed
29                         string s = AptcLibrary.Hello ("World");
30                         int ec = IsRestricted () ? 1 : 0;
31                         Console.WriteLine ("*{0}* AptcLibrary: {1}", ec, s);
32                         return ec;
33                 }
34                 catch (SecurityException se) {
35                         int ec = IsRestricted () ? 0 : 1;
36                         Console.WriteLine ("*{0}* Expected SecurityException\n{1}", ec, se);
37                         return ec;
38                 }
39                 catch (Exception e) {
40                         Console.WriteLine ("*2* Unexpected exception\n{0}", e);
41                         return 2;
42                 }
43         }
44 }