2009-03-11 Zoltan Varga <vargaz@gmail.com>
[mono-debugger.git] / mono / tests / load-exceptions.cs
blob78c48548a9f50f36b5eb04167ab137b3ca02c989
1 //
2 // load-exceptions.cs: Tests for loading missing types/methods/fields from IL
3 //
5 using System;
6 using System.IO;
8 class Miss1 : Missing.Foo1 {
11 public class Tests : LoadMissing {
13 public delegate void TestDel ();
15 internal static int check_type_load (TestDel d) {
16 try {
17 d ();
19 catch (TypeLoadException ex) {
20 //Console.WriteLine (ex.TypeName);
21 //Console.WriteLine (ex);
22 return 0;
25 return 1;
28 internal static int check_missing_method (TestDel d) {
29 try {
30 d ();
32 catch (MissingMethodException ex) {
33 //Console.WriteLine (ex);
34 return 0;
37 return 1;
40 internal static int check_file_not_found (TestDel d){
41 try {
42 d ();
43 } catch (FileNotFoundException ex){
44 return 0;
46 return 1;
49 internal static int check_missing_field (TestDel d) {
50 try {
51 d ();
53 catch (MissingFieldException ex) {
54 //Console.WriteLine (ex);
55 return 0;
58 return 1;
63 // Base instructions
66 public static int test_0_call () {
67 return check_missing_method (new TestDel (missing_call));
70 public static int test_0_jmp () {
71 return check_missing_method (new TestDel (missing_jmp));
74 public static int test_0_ldftn () {
75 return check_missing_method (new TestDel (missing_ldftn));
79 // Object model instructions
82 public static int test_0_box () {
83 // Thrown earlier
84 return 0;
87 public static int test_0_callvirt () {
88 return check_missing_method (new TestDel (missing_callvirt));
91 public static int test_0_castclass () {
92 return check_type_load (new TestDel (missing_castclass));
95 public static int test_0_cpobj () {
96 return check_type_load (new TestDel (missing_cpobj));
99 public static int test_0_missing_type_on_parameter () {
100 return check_type_load (new TestDel (missing_external_type_reference_on_parameter));
102 public static int test_0_initobj () {
103 return check_type_load (new TestDel (missing_initobj));
106 public static int test_0_isinst () {
107 return check_type_load (new TestDel (missing_isinst));
110 public static int test_0_ldelem () {
111 // Thrown earlier
112 return 0;
115 public static int test_0_ldelema () {
116 // Thrown earlier
117 return 0;
120 public static int test_0_ldfld () {
121 return check_missing_field (new TestDel (missing_ldfld));
124 public static int test_0_ldflda () {
125 return check_missing_field (new TestDel (missing_ldflda));
128 public static int test_0_ldobj () {
129 // Thrown earlier
130 return 0;
133 public static int test_0_ldsfld () {
134 return check_missing_field (new TestDel (missing_ldsfld));
137 public static int test_0_ldsflda () {
138 return check_missing_field (new TestDel (missing_ldsflda));
141 public static int test_0_ldtoken_type () {
142 return check_type_load (new TestDel (missing_ldtoken_type));
145 public static int test_0_ldtoken_method () {
146 return check_missing_method (new TestDel (missing_ldtoken_method));
149 public static int test_0_ldtoken_field () {
150 return check_missing_field (new TestDel (missing_ldtoken_field));
153 public static int test_0_ldvirtftn () {
154 return check_missing_method (new TestDel (missing_ldvirtftn));
157 public static int test_0_mkrefany () {
158 // Thrown earlier
159 return 0;
162 public static int test_0_newarr () {
163 return check_type_load (new TestDel (missing_newarr));
166 public static int test_0_newobj () {
167 return check_missing_method (new TestDel (missing_newobj));
170 public static int test_0_refanyval () {
171 return check_type_load (new TestDel (missing_refanyval));
174 public static int test_0_sizeof () {
175 return check_type_load (new TestDel (missing_sizeof));
178 public static int test_0_stelem () {
179 // Thrown earlier
180 return 0;
183 public static int test_0_stfld () {
184 return check_missing_field (new TestDel (missing_stfld));
187 public static int test_0_stobj () {
188 // Thrown earlier
189 return 0;
192 public static int test_0_stsfld () {
193 return check_missing_field (new TestDel (missing_stsfld));
196 public static int test_0_unbox () {
197 return check_type_load (new TestDel (missing_unbox));
200 public static int test_0_unbox_any () {
201 return check_type_load (new TestDel (missing_unbox_any));
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));
209 #endif
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));
216 public static int test_0_missing_assembly_in_newobj () {
217 return check_type_load (new TestDel (missing_assembly_in_newobj));
220 public static int test_0_missing_delegate_ctor_argument () {
221 return check_type_load (new TestDel (missing_delegate_ctor_argument));
225 // Missing classes referenced from metadata
228 // FIXME: These do not work yet
229 #if FALSE
230 public static int test_0_missing_local () {
231 try {
232 missing_local ();
234 catch (TypeLoadException ex) {
237 /* MS.NET doesn't throw an exception if a local is not found */
238 return 0;
241 public static void missing_parent () {
242 new Miss1 ();
245 public static int test_0_missing_parent () {
246 return check_type_load (new TestDel (missing_parent));
248 #endif
250 public static int Main () {
251 return TestDriver.RunTests (typeof (Tests));