New test.
[mono.git] / mono / tests / cas / inheritance / cas2.cs
1 using System;
2 using System.Reflection;
3 using System.Security;
4 using System.Security.Permissions;
5
6 public abstract class AbstractProgram {
7
8         protected int rc;
9
10         internal static bool IsSigned ()
11         {
12                 AssemblyName an = Assembly.GetExecutingAssembly ().GetName ();
13                 byte[] pk = an.GetPublicKey ();
14                 return ((pk != null) && (pk.Length > 0));
15         }
16
17         public AbstractProgram ()
18         {
19                 rc = IsSigned () ? 0 : 1;
20                 Console.WriteLine ("*{0}* AbstractProgram", rc);
21         }
22
23         [StrongNameIdentityPermission (SecurityAction.InheritanceDemand, PublicKey="0024000004800000940000000602000000240000525341310004000011000000db294bcb78b7361ed6eb5656b612ce266fc81da8c8c6cb04116fc29b5e1d09a02f6c0f387f6d97a1ce9bdbbeb2d874832ae2d2971e70144ea039c710dccab5fb0a36cb14268a83c9b435c1e7318e7915518b68c8ed056b104e76166d6cabe9b77383f26bcf6a0a0b09d04f37b2a407b47d39421a34f2fbc6e6701a1d5c2e8cbb")]
24         public virtual int InstanceTest ()
25         {
26                 return rc;
27         }
28 }
29
30 public class Program : AbstractProgram {
31
32         public override int InstanceTest ()
33         {
34                 // exception even if base class isn't called
35                 return rc;
36         }
37
38         static int Main ()
39         {
40                 try {
41                         return new Program ().InstanceTest ();
42                 }
43                 catch (SecurityException se) {
44                         // if unsigned the SecurityException will be unhandled
45                         Console.WriteLine ("*1* Unexpected SecurityException\n{0}", se);
46                         return 1;
47                 }
48                 catch (Exception e) {
49                         Console.WriteLine ("*2* Unexpected Exception\n{0}", e);
50                         return 2;
51                 }
52         }
53 }