New test.
[mono.git] / mono / tests / load-exceptions.cs
1 //
2 // load-exceptions.cs: Tests for loading missing types/methods/fields from IL
3 //
4
5 using System;
6
7 class Miss1 : Missing.Foo1 {
8 }
9
10 public class Tests : LoadMissing {
11
12         public delegate void TestDel ();
13
14         internal static int check_type_load (TestDel d) {
15                 try {
16                         d ();
17                 }
18                 catch (TypeLoadException ex) {
19                         //Console.WriteLine (ex.TypeName);
20                         //Console.WriteLine (ex);
21                         return 0;
22                 }
23
24                 return 1;
25         }
26
27         internal static int check_missing_method (TestDel d) {
28                 try {
29                         d ();
30                 }
31                 catch (MissingMethodException ex) {
32                         //Console.WriteLine (ex);
33                         return 0;
34                 }
35
36                 return 1;
37         }
38
39         internal static int check_missing_field (TestDel d) {
40                 try {
41                         d ();
42                 }
43                 catch (MissingFieldException ex) {
44                         //Console.WriteLine (ex);
45                         return 0;
46                 }
47
48                 return 1;
49         }
50
51         //
52         // Base instructions
53         //
54
55         public static int test_0_call () {
56                 return check_missing_method (new TestDel (missing_call));
57         }
58
59         public static int test_0_jmp () {
60                 return check_missing_method (new TestDel (missing_jmp));
61         }
62
63         public static int test_0_ldftn () {
64                 return check_missing_method (new TestDel (missing_ldftn));
65         }
66
67         //
68         // Object model instructions
69         //
70
71         public static int test_0_box () {
72                 // Thrown earlier
73                 return 0;
74         }
75
76         public static int test_0_callvirt () {
77                 return check_missing_method (new TestDel (missing_callvirt));
78         }
79
80         public static int test_0_castclass () {
81                 return check_type_load (new TestDel (missing_castclass));
82         }
83
84         public static int test_0_cpobj () {
85                 return check_type_load (new TestDel (missing_cpobj));
86         }
87
88         public static int test_0_initobj () {
89                 return check_type_load (new TestDel (missing_initobj));
90         }
91
92         public static int test_0_isinst () {
93                 return check_type_load (new TestDel (missing_isinst));
94         }
95
96         public static int test_0_ldelem () {
97                 // Thrown earlier
98                 return 0;
99         }
100
101         public static int test_0_ldelema () {
102                 // Thrown earlier
103                 return 0;
104         }
105
106         public static int test_0_ldfld () {
107                 return check_missing_field (new TestDel (missing_ldfld));
108         }               
109
110         public static int test_0_ldflda () {
111                 return check_missing_field (new TestDel (missing_ldflda));
112         }               
113
114         public static int test_0_ldobj () {
115                 // Thrown earlier
116                 return 0;
117         }
118
119         public static int test_0_ldsfld () {
120                 return check_missing_field (new TestDel (missing_ldsfld));
121         }               
122
123         public static int test_0_ldsflda () {
124                 return check_missing_field (new TestDel (missing_ldsflda));
125         }               
126
127         public static int test_0_ldtoken_type () {
128                 return check_type_load (new TestDel (missing_ldtoken_type));
129         }
130
131         public static int test_0_ldtoken_method () {
132                 return check_missing_method (new TestDel (missing_ldtoken_method));
133         }
134
135         public static int test_0_ldtoken_field () {
136                 return check_missing_field (new TestDel (missing_ldtoken_field));
137         }
138
139         public static int test_0_ldvirtftn () {
140                 return check_missing_method (new TestDel (missing_ldvirtftn));
141         }
142
143         public static int test_0_mkrefany () {
144                 // Thrown earlier
145                 return 0;
146         }
147
148         public static int test_0_newarr () {
149                 return check_type_load (new TestDel (missing_newarr));
150         }               
151
152         public static int test_0_newobj () {
153                 return check_missing_method (new TestDel (missing_newobj));
154         }               
155
156         public static int test_0_refanyval () {
157                 return check_type_load (new TestDel (missing_refanyval));
158         }
159
160         public static int test_0_sizeof () {
161                 return check_type_load (new TestDel (missing_sizeof));
162         }
163
164         public static int test_0_stelem () {
165                 // Thrown earlier
166                 return 0;
167         }
168
169         public static int test_0_stfld () {
170                 return check_missing_field (new TestDel (missing_stfld));
171         }
172
173         public static int test_0_stobj () {
174                 // Thrown earlier
175                 return 0;
176         }
177
178         public static int test_0_stsfld () {
179                 return check_missing_field (new TestDel (missing_stsfld));
180         }
181
182         public static int test_0_unbox () {
183                 return check_type_load (new TestDel (missing_unbox));
184         }
185
186         public static int test_0_unbox_any () {
187                 return check_type_load (new TestDel (missing_unbox_any));
188         }
189
190         //
191         // Missing classes referenced from metadata
192         //
193
194         // FIXME: These do not work yet
195 #if FALSE
196         public static int test_0_missing_local () {
197                 try {
198                         missing_local ();
199                 }
200                 catch (TypeLoadException ex) {
201                 }
202
203                 /* MS.NET doesn't throw an exception if a local is not found */
204                 return 0;
205         }
206
207         public static void missing_parent () {
208                 new Miss1 ();
209         }
210
211         public static int test_0_missing_parent () {
212                 return check_type_load (new TestDel (missing_parent));
213         }
214 #endif
215
216         public static int Main () {
217                 return TestDriver.RunTests (typeof (Tests));
218         }
219 }