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