[mono-api-info] First filter, then order, and use ordinal comparison.
[mono-project.git] / mono / tests / load-exceptions.cs
blobcb2fc0983757332593bf06f99e62f07cbdb0ed50
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 Miss2 {
13 public class Foo : Missing.Foo1 {
17 public class Tests : LoadMissing {
19 public delegate void TestDel ();
21 internal static int check_type_load (TestDel d) {
22 try {
23 d ();
25 catch (TypeLoadException ex) {
26 //Console.WriteLine (ex.TypeName);
27 //Console.WriteLine (ex);
28 return 0;
31 return 1;
34 internal static int check_missing_method (TestDel d) {
35 try {
36 d ();
38 catch (MissingMethodException ex) {
39 //Console.WriteLine (ex);
40 return 0;
43 return 1;
46 internal static int check_file_not_found (TestDel d){
47 try {
48 d ();
49 } catch (FileNotFoundException ex){
50 return 0;
52 return 1;
55 internal static int check_missing_field (TestDel d) {
56 try {
57 d ();
59 catch (MissingFieldException ex) {
60 //Console.WriteLine (ex);
61 return 0;
64 return 1;
69 // Base instructions
72 public static int test_0_call () {
73 return check_missing_method (new TestDel (missing_call));
76 public static int test_0_jmp () {
77 return check_missing_method (new TestDel (missing_jmp));
80 public static int test_0_ldftn () {
81 return check_missing_method (new TestDel (missing_ldftn));
85 // Object model instructions
88 public static int test_0_box () {
89 // Thrown earlier
90 return 0;
93 public static int test_0_callvirt () {
94 return check_missing_method (new TestDel (missing_callvirt));
97 public static int test_0_castclass () {
98 return check_type_load (new TestDel (missing_castclass));
101 public static int test_0_cpobj () {
102 return check_type_load (new TestDel (missing_cpobj));
105 public static int test_0_missing_type_on_parameter () {
106 return check_type_load (new TestDel (missing_external_type_reference_on_parameter));
108 public static int test_0_initobj () {
109 return check_type_load (new TestDel (missing_initobj));
112 public static int test_0_isinst () {
113 return check_type_load (new TestDel (missing_isinst));
116 public static int test_0_ldelem () {
117 // Thrown earlier
118 return 0;
121 public static int test_0_ldelema () {
122 // Thrown earlier
123 return 0;
126 public static int test_0_ldfld () {
127 return check_missing_field (new TestDel (missing_ldfld));
130 public static int test_0_ldflda () {
131 return check_missing_field (new TestDel (missing_ldflda));
134 public static int test_0_ldobj () {
135 // Thrown earlier
136 return 0;
139 public static int test_0_ldsfld () {
140 return check_missing_field (new TestDel (missing_ldsfld));
143 public static int test_0_ldsflda () {
144 return check_missing_field (new TestDel (missing_ldsflda));
147 public static int test_0_ldtoken_type () {
148 return check_type_load (new TestDel (missing_ldtoken_type));
151 public static int test_0_ldtoken_method () {
152 return check_missing_method (new TestDel (missing_ldtoken_method));
155 public static int test_0_ldtoken_field () {
156 return check_missing_field (new TestDel (missing_ldtoken_field));
159 public static int test_0_ldvirtftn () {
160 return check_missing_method (new TestDel (missing_ldvirtftn));
163 public static int test_0_mkrefany () {
164 // Thrown earlier
165 return 0;
168 public static int test_0_newarr () {
169 return check_type_load (new TestDel (missing_newarr));
172 public static int test_0_newobj () {
173 return check_missing_method (new TestDel (missing_newobj));
176 public static int test_0_refanyval () {
177 return check_type_load (new TestDel (missing_refanyval));
180 public static int test_0_sizeof () {
181 return check_type_load (new TestDel (missing_sizeof));
184 public static int test_0_stelem () {
185 // Thrown earlier
186 return 0;
189 public static int test_0_stfld () {
190 return check_missing_field (new TestDel (missing_stfld));
193 public static int test_0_stobj () {
194 // Thrown earlier
195 return 0;
198 public static int test_0_stsfld () {
199 return check_missing_field (new TestDel (missing_stsfld));
202 public static int test_0_unbox () {
203 return check_type_load (new TestDel (missing_unbox));
206 public static int test_0_unbox_any () {
207 return check_type_load (new TestDel (missing_unbox_any));
210 #if false
211 // Bummer: we regressed! I should have put this before
212 public static int test_0_missing_assembly_in_fieldref () {
213 return check_file_not_found (new TestDel (missing_assembly_in_fieldref));
215 #endif
217 // FIXME: the corrent exception here is FileNotFoundException
218 public static int test_0_missing_assembly_in_call () {
219 return check_type_load (new TestDel (missing_assembly_in_call));
222 public static int test_0_missing_assembly_in_newobj () {
223 return check_type_load (new TestDel (missing_assembly_in_newobj));
226 public static int test_0_missing_delegate_ctor_argument () {
227 return check_type_load (new TestDel (missing_delegate_ctor_argument));
231 // Missing classes referenced from metadata
234 public static int test_0_missing_local () {
235 try {
236 missing_local ();
238 catch (TypeLoadException ex) {
241 /* MS.NET doesn't throw an exception if a local is not found */
242 return 0;
245 //Regression test for #508532
246 public static int test_0_assembly_throws_on_loader_error ()
248 try {
249 Assembly asm = Assembly.Load ("load-missing");
250 asm.GetType ("BrokenClass", false);
251 return 1;
252 } catch (TypeLoadException) {}
253 return 0;
256 public static int test_0_bad_method_override1 ()
258 try {
259 BadOverridesDriver.bad_override1 ();
260 return 1;
261 } catch (TypeLoadException) {}
262 return 0;
265 public static int test_0_bad_method_override2 ()
267 try {
268 BadOverridesDriver.bad_override2 ();
269 return 1;
270 } catch (TypeLoadException) {}
271 return 0;
274 public static int test_0_bad_method_override3 ()
276 try {
277 BadOverridesDriver.bad_override3 ();
278 return 1;
279 } catch (TypeLoadException) {}
280 return 0;
283 public static int test_0_bad_method_override4 ()
285 try {
286 BadOverridesDriver.bad_override4 ();
287 return 1;
288 } catch (TypeLoadException) {}
289 return 0;
292 public static void missing_outer () {
293 new Missing.Foo1.InnerFoo ();
296 //Regression test for #508487
297 public static int test_0_missing_outer_type_in_typeref () {
298 return check_type_load (new TestDel (missing_outer));
301 // #524498
302 public static int test_0_exception_while_jitting_cctor () {
303 try {
304 CCtorClass.foo ();
305 } catch (TypeInitializationException) {
306 return 0;
309 return 1;
312 #if FALSE
313 public static void missing_parent () {
314 new Miss1 ();
317 public static int test_0_missing_parent () {
318 return check_type_load (new TestDel (missing_parent));
320 #endif
322 public static int test_0_missing_nested () {
323 if (typeof (Miss2).GetNestedTypes ().Length != 0)
324 return 1;
325 return 0;
328 public static int test_0_reflection_on_field_with_missing_type () {
329 var t = typeof (BadOverridesDriver).Assembly.GetType ("FieldWithMissingType");
330 foreach (var f in t.GetFields (BindingFlags.Public | BindingFlags.Static)) {
331 try {
332 Console.WriteLine (f.Name);
333 f.GetValue (null);
334 return 1;
335 } catch (TypeLoadException) {
336 return 0;
339 return 2;
343 public static int Main () {
344 return TestDriver.RunTests (typeof (Tests));