2 // load-exceptions.cs: Tests for loading missing types/methods/fields from IL
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
) {
20 catch (TypeLoadException ex
) {
21 //Console.WriteLine (ex.TypeName);
22 //Console.WriteLine (ex);
29 internal static int check_missing_method (TestDel d
) {
33 catch (MissingMethodException ex
) {
34 //Console.WriteLine (ex);
41 internal static int check_file_not_found (TestDel d
){
44 } catch (FileNotFoundException ex
){
50 internal static int check_missing_field (TestDel d
) {
54 catch (MissingFieldException ex
) {
55 //Console.WriteLine (ex);
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 () {
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 () {
116 public static int test_0_ldelema () {
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 () {
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 () {
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 () {
184 public static int test_0_stfld () {
185 return check_missing_field (new TestDel (missing_stfld
));
188 public static int test_0_stobj () {
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
));
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
));
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 () {
233 catch (TypeLoadException ex
) {
236 /* MS.NET doesn't throw an exception if a local is not found */
240 //Regression test for #508532
241 public static int test_0_assembly_throws_on_loader_error ()
244 Assembly asm
= Assembly
.Load ("load-missing");
245 asm
.GetType ("BrokenClass", false);
247 } catch (TypeLoadException
) {}
251 public static int test_0_bad_method_override1 ()
254 BadOverridesDriver
.bad_override1 ();
256 } catch (TypeLoadException
) {}
260 public static int test_0_bad_method_override2 ()
263 BadOverridesDriver
.bad_override2 ();
265 } catch (TypeLoadException
) {}
269 public static int test_0_bad_method_override3 ()
272 BadOverridesDriver
.bad_override3 ();
274 } catch (TypeLoadException
) {}
278 public static int test_0_bad_method_override4 ()
281 BadOverridesDriver
.bad_override4 ();
283 } catch (TypeLoadException
) {}
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
));
297 public static int test_0_exception_while_jitting_cctor () {
300 } catch (TypeInitializationException
) {
308 public static void missing_parent () {
312 public static int test_0_missing_parent () {
313 return check_type_load (new TestDel (missing_parent
));
317 public static int Main () {
318 return TestDriver
.RunTests (typeof (Tests
));