* roottypes.cs: Rename from tree.cs.
[mono.git] / mono / tests / cas / inheritance / reftype2.cs
1 using System;
2 using System.Reflection;
3 using System.Security;
4 using System.Security.Permissions;
5
6 public class Program {
7
8         private const string filename = "library1b";
9
10         static int GetTypeFalse (Assembly a)
11         {
12                 string typename = "InheritanceDemand";
13                 Type t = a.GetType (typename, false);
14                 if (t == null) {
15                         Console.WriteLine ("*1* Get null for type '{0}' with security.", typename);
16                         return 1;
17                 } else {
18                         Console.WriteLine ("*0* Can get type '{0}' with security.", typename);
19                         return 0;
20                 }
21         }
22
23         static int GetTypeTrue (Assembly a)
24         {
25                 string typename = "InheritanceDemand";
26                 Type t = a.GetType (typename, true);
27                 Console.WriteLine ("*0* Can get type '{0}' with security.", t);
28                 return 0;
29         }
30
31         static int GetTypes (Assembly a)
32         {
33                 Type[] ts = a.GetTypes ();
34                 Console.WriteLine ("*0* Can get all types from assembly '{0}' loaded. {1} types present.", filename, ts.Length);
35                 return 0;
36         }
37
38         static int Main ()
39         {
40                 try {
41                         Assembly a = Assembly.Load (filename);
42                         if (a == null) {
43                                 Console.WriteLine ("*2* Couldn't load assembly '{0}'.", filename);
44                                 return 2;
45                         }
46
47                         string typename = "NoSecurity";
48                         Type t = a.GetType (typename);
49                         if (t == null) {
50                                 Console.WriteLine ("*3* Cannot get type '{0}' without security.", typename);
51                                 return 3;
52                         }
53
54                         int err = GetTypeFalse (a);
55                         if (err != 0)
56                                 return err;
57
58                         err = GetTypeTrue (a);
59                         if (err != 0)
60                                 return err;
61
62                         err = GetTypes (a);
63                         return err;
64                 }
65                 catch (ReflectionTypeLoadException rtle) {
66                         Console.WriteLine ("*4* Expected ReflectionTypeLoadException\n{0}", rtle);
67                         return 4;
68                 }
69                 catch (SecurityException se) {
70                         Console.WriteLine ("*5* Unexpected SecurityException\n{0}", se);
71                         return 5;
72                 }
73                 catch (Exception e) {
74                         Console.WriteLine ("*6* Unexpected Exception\n{0}", e);
75                         return 6;
76                 }
77         }
78 }