2010-06-17 Geoff Norton <gnorton@novell.com>
[mono.git] / mono / tests / load-exceptions.cs
blob13b75de6da12fc5ea6fd760803c2425744671e9e
1 //
2 // load-exceptions.cs: Tests for loading missing types/methods/fields from IL
3 //
5 using System;
6 using System.IO;
7 using System.Reflection;
9 class Miss1 : Missing.Foo1 {
12 public class Tests : LoadMissing {
14 public delegate void TestDel ();
16 internal static int check_type_load (TestDel d) {
17 try {
18 d ();
20 catch (TypeLoadException ex) {
21 //Console.WriteLine (ex.TypeName);
22 //Console.WriteLine (ex);
23 return 0;
26 return 1;
29 internal static int check_missing_method (TestDel d) {
30 try {
31 d ();
33 catch (MissingMethodException ex) {
34 //Console.WriteLine (ex);
35 return 0;
38 return 1;
41 internal static int check_file_not_found (TestDel d){
42 try {
43 d ();
44 } catch (FileNotFoundException ex){
45 return 0;
47 return 1;
50 internal static int check_missing_field (TestDel d) {
51 try {
52 d ();
54 catch (MissingFieldException ex) {
55 //Console.WriteLine (ex);
56 return 0;
59 return 1;
64 // Base instructions
67 public static int test_0_call () {
68 return check_missing_method (new TestDel (missing_call));
71 public static int test_0_jmp () {
72 return check_missing_method (new TestDel (missing_jmp));
75 public static int test_0_ldftn () {
76 return check_missing_method (new TestDel (missing_ldftn));
80 // Object model instructions
83 public static int test_0_box () {
84 // Thrown earlier
85 return 0;
88 public static int test_0_callvirt () {
89 return check_missing_method (new TestDel (missing_callvirt));
92 public static int test_0_castclass () {
93 return check_type_load (new TestDel (missing_castclass));
96 public static int test_0_cpobj () {
97 return check_type_load (new TestDel (missing_cpobj));
100 public static int test_0_missing_type_on_parameter () {
101 return check_type_load (new TestDel (missing_external_type_reference_on_parameter));
103 public static int test_0_initobj () {
104 return check_type_load (new TestDel (missing_initobj));
107 public static int test_0_isinst () {
108 return check_type_load (new TestDel (missing_isinst));
111 public static int test_0_ldelem () {
112 // Thrown earlier
113 return 0;
116 public static int test_0_ldelema () {
117 // Thrown earlier
118 return 0;
121 public static int test_0_ldfld () {
122 return check_missing_field (new TestDel (missing_ldfld));
125 public static int test_0_ldflda () {
126 return check_missing_field (new TestDel (missing_ldflda));
129 public static int test_0_ldobj () {
130 // Thrown earlier
131 return 0;
134 public static int test_0_ldsfld () {
135 return check_missing_field (new TestDel (missing_ldsfld));
138 public static int test_0_ldsflda () {
139 return check_missing_field (new TestDel (missing_ldsflda));
142 public static int test_0_ldtoken_type () {
143 return check_type_load (new TestDel (missing_ldtoken_type));
146 public static int test_0_ldtoken_method () {
147 return check_missing_method (new TestDel (missing_ldtoken_method));
150 public static int test_0_ldtoken_field () {
151 return check_missing_field (new TestDel (missing_ldtoken_field));
154 public static int test_0_ldvirtftn () {
155 return check_missing_method (new TestDel (missing_ldvirtftn));
158 public static int test_0_mkrefany () {
159 // Thrown earlier
160 return 0;
163 public static int test_0_newarr () {
164 return check_type_load (new TestDel (missing_newarr));
167 public static int test_0_newobj () {
168 return check_missing_method (new TestDel (missing_newobj));
171 public static int test_0_refanyval () {
172 return check_type_load (new TestDel (missing_refanyval));
175 public static int test_0_sizeof () {
176 return check_type_load (new TestDel (missing_sizeof));
179 public static int test_0_stelem () {
180 // Thrown earlier
181 return 0;
184 public static int test_0_stfld () {
185 return check_missing_field (new TestDel (missing_stfld));
188 public static int test_0_stobj () {
189 // Thrown earlier
190 return 0;
193 public static int test_0_stsfld () {
194 return check_missing_field (new TestDel (missing_stsfld));
197 public static int test_0_unbox () {
198 return check_type_load (new TestDel (missing_unbox));
201 public static int test_0_unbox_any () {
202 return check_type_load (new TestDel (missing_unbox_any));
205 #if false
206 // Bummer: we regressed! I should have put this before
207 public static int test_0_missing_assembly_in_fieldref () {
208 return check_file_not_found (new TestDel (missing_assembly_in_fieldref));
210 #endif
212 // FIXME: the corrent exception here is FileNotFoundException
213 public static int test_0_missing_assembly_in_call () {
214 return check_type_load (new TestDel (missing_assembly_in_call));
217 public static int test_0_missing_assembly_in_newobj () {
218 return check_type_load (new TestDel (missing_assembly_in_newobj));
221 public static int test_0_missing_delegate_ctor_argument () {
222 return check_type_load (new TestDel (missing_delegate_ctor_argument));
226 // Missing classes referenced from metadata
229 public static int test_0_missing_local () {
230 try {
231 missing_local ();
233 catch (TypeLoadException ex) {
236 /* MS.NET doesn't throw an exception if a local is not found */
237 return 0;
240 //Regression test for #508532
241 public static int test_0_assembly_throws_on_loader_error ()
243 try {
244 Assembly asm = Assembly.Load ("load-missing");
245 asm.GetType ("BrokenClass", false);
246 return 1;
247 } catch (TypeLoadException) {}
248 return 0;
251 public static int test_0_bad_method_override1 ()
253 try {
254 BadOverridesDriver.bad_override1 ();
255 return 1;
256 } catch (TypeLoadException) {}
257 return 0;
260 public static int test_0_bad_method_override2 ()
262 try {
263 BadOverridesDriver.bad_override2 ();
264 return 1;
265 } catch (TypeLoadException) {}
266 return 0;
269 public static int test_0_bad_method_override3 ()
271 try {
272 BadOverridesDriver.bad_override3 ();
273 return 1;
274 } catch (TypeLoadException) {}
275 return 0;
278 public static int test_0_bad_method_override4 ()
280 try {
281 BadOverridesDriver.bad_override4 ();
282 return 1;
283 } catch (TypeLoadException) {}
284 return 0;
287 public static void missing_outer () {
288 new Missing.Foo1.InnerFoo ();
291 //Regression test for #508487
292 public static int test_0_missing_outer_type_in_typeref () {
293 return check_type_load (new TestDel (missing_outer));
296 // #524498
297 public static int test_0_exception_while_jitting_cctor () {
298 try {
299 CCtorClass.foo ();
300 } catch (TypeInitializationException) {
301 return 0;
304 return 1;
307 #if FALSE
308 public static void missing_parent () {
309 new Miss1 ();
312 public static int test_0_missing_parent () {
313 return check_type_load (new TestDel (missing_parent));
315 #endif
317 public static int Main () {
318 return TestDriver.RunTests (typeof (Tests));