Merge pull request #5210 from alexrp/profiler-runtime-settings
[mono.git] / mono / tests / cominterop.cs
1 //
2 // cominterop.cs:
3 //
4 //  Tests for COM Interop related features
5 //
6
7 using System;
8 using System.Runtime.CompilerServices;
9 using System.Runtime.InteropServices;
10
11
12 public class Tests
13 {
14
15         [DllImport("libtest")]
16         public static extern int mono_test_marshal_bstr_in([MarshalAs(UnmanagedType.BStr)]string str);
17
18         [DllImport("libtest")]
19     public static extern int mono_test_marshal_bstr_out([MarshalAs(UnmanagedType.BStr)] out string str);
20
21     [DllImport("libtest")]
22     public static extern int mono_test_marshal_bstr_in_null([MarshalAs(UnmanagedType.BStr)]string str);
23
24     [DllImport("libtest")]
25     public static extern int mono_test_marshal_bstr_out_null([MarshalAs(UnmanagedType.BStr)] out string str);
26
27         [DllImport("libtest")]
28         public static extern int mono_test_marshal_variant_in_sbyte([MarshalAs(UnmanagedType.Struct)]object obj);
29
30         [DllImport("libtest")]
31         public static extern int mono_test_marshal_variant_in_byte([MarshalAs(UnmanagedType.Struct)]object obj);
32
33         [DllImport("libtest")]
34         public static extern int mono_test_marshal_variant_in_short([MarshalAs(UnmanagedType.Struct)]object obj);
35
36         [DllImport("libtest")]
37         public static extern int mono_test_marshal_variant_in_ushort([MarshalAs(UnmanagedType.Struct)]object obj);
38
39         [DllImport("libtest")]
40         public static extern int mono_test_marshal_variant_in_int([MarshalAs(UnmanagedType.Struct)]object obj);
41
42         [DllImport("libtest")]
43         public static extern int mono_test_marshal_variant_in_uint([MarshalAs(UnmanagedType.Struct)]object obj);
44
45         [DllImport("libtest")]
46         public static extern int mono_test_marshal_variant_in_long([MarshalAs(UnmanagedType.Struct)]object obj);
47
48         [DllImport("libtest")]
49         public static extern int mono_test_marshal_variant_in_ulong([MarshalAs(UnmanagedType.Struct)]object obj);
50
51         [DllImport("libtest")]
52         public static extern int mono_test_marshal_variant_in_float([MarshalAs(UnmanagedType.Struct)]object obj);
53
54         [DllImport("libtest")]
55         public static extern int mono_test_marshal_variant_in_double([MarshalAs(UnmanagedType.Struct)]object obj);
56
57         [DllImport("libtest")]
58         public static extern int mono_test_marshal_variant_in_bstr ([MarshalAs (UnmanagedType.Struct)]object obj);
59
60         [DllImport ("libtest")]
61         public static extern int mono_test_marshal_variant_in_bool_true ([MarshalAs (UnmanagedType.Struct)]object obj);
62
63         [DllImport ("libtest")]
64         public static extern int mono_test_marshal_variant_in_bool_false ([MarshalAs (UnmanagedType.Struct)]object obj);
65
66         [DllImport("libtest")]
67         public static extern int mono_test_marshal_variant_out_sbyte([MarshalAs(UnmanagedType.Struct)]out object obj);
68
69         [DllImport("libtest")]
70         public static extern int mono_test_marshal_variant_out_sbyte_byref([MarshalAs(UnmanagedType.Struct)]out object obj);
71
72         [DllImport("libtest")]
73         public static extern int mono_test_marshal_variant_out_byte([MarshalAs(UnmanagedType.Struct)]out object obj);
74
75         [DllImport("libtest")]
76         public static extern int mono_test_marshal_variant_out_byte_byref([MarshalAs(UnmanagedType.Struct)]out object obj);
77
78         [DllImport("libtest")]
79         public static extern int mono_test_marshal_variant_out_short([MarshalAs(UnmanagedType.Struct)]out object obj);
80
81         [DllImport("libtest")]
82         public static extern int mono_test_marshal_variant_out_short_byref([MarshalAs(UnmanagedType.Struct)]out object obj);
83
84         [DllImport("libtest")]
85         public static extern int mono_test_marshal_variant_out_ushort([MarshalAs(UnmanagedType.Struct)]out object obj);
86
87         [DllImport("libtest")]
88         public static extern int mono_test_marshal_variant_out_ushort_byref([MarshalAs(UnmanagedType.Struct)]out object obj);
89
90         [DllImport("libtest")]
91         public static extern int mono_test_marshal_variant_out_int([MarshalAs(UnmanagedType.Struct)]out object obj);
92
93         [DllImport("libtest")]
94         public static extern int mono_test_marshal_variant_out_int_byref([MarshalAs(UnmanagedType.Struct)]out object obj);
95
96         [DllImport("libtest")]
97         public static extern int mono_test_marshal_variant_out_uint([MarshalAs(UnmanagedType.Struct)]out object obj);
98
99         [DllImport("libtest")]
100         public static extern int mono_test_marshal_variant_out_uint_byref([MarshalAs(UnmanagedType.Struct)]out object obj);
101
102         [DllImport("libtest")]
103         public static extern int mono_test_marshal_variant_out_long([MarshalAs(UnmanagedType.Struct)]out object obj);
104
105         [DllImport("libtest")]
106         public static extern int mono_test_marshal_variant_out_long_byref([MarshalAs(UnmanagedType.Struct)]out object obj);
107
108         [DllImport("libtest")]
109         public static extern int mono_test_marshal_variant_out_ulong([MarshalAs(UnmanagedType.Struct)]out object obj);
110
111         [DllImport("libtest")]
112         public static extern int mono_test_marshal_variant_out_ulong_byref([MarshalAs(UnmanagedType.Struct)]out object obj);
113
114         [DllImport("libtest")]
115         public static extern int mono_test_marshal_variant_out_float([MarshalAs(UnmanagedType.Struct)]out object obj);
116
117         [DllImport("libtest")]
118         public static extern int mono_test_marshal_variant_out_float_byref([MarshalAs(UnmanagedType.Struct)]out object obj);
119
120         [DllImport("libtest")]
121         public static extern int mono_test_marshal_variant_out_double([MarshalAs(UnmanagedType.Struct)]out object obj);
122
123         [DllImport("libtest")]
124         public static extern int mono_test_marshal_variant_out_double_byref([MarshalAs(UnmanagedType.Struct)]out object obj);
125
126         [DllImport("libtest")]
127         public static extern int mono_test_marshal_variant_out_bstr ([MarshalAs (UnmanagedType.Struct)]out object obj);
128
129         [DllImport("libtest")]
130         public static extern int mono_test_marshal_variant_out_bstr_byref ([MarshalAs (UnmanagedType.Struct)]out object obj);
131
132         [DllImport("libtest")]
133         public static extern int mono_test_marshal_variant_out_bool_true ([MarshalAs (UnmanagedType.Struct)]out object obj);
134
135         [DllImport("libtest")]
136         public static extern int mono_test_marshal_variant_out_bool_true_byref ([MarshalAs (UnmanagedType.Struct)]out object obj);
137
138         [DllImport ("libtest")]
139         public static extern int mono_test_marshal_variant_out_bool_false ([MarshalAs (UnmanagedType.Struct)]out object obj);
140
141         [DllImport ("libtest")]
142         public static extern int mono_test_marshal_variant_out_bool_false_byref ([MarshalAs (UnmanagedType.Struct)]out object obj);
143
144
145         public delegate int VarFunc (VarEnum vt, [MarshalAs (UnmanagedType.Struct)] object obj);
146
147         public delegate int VarRefFunc (VarEnum vt, [MarshalAs (UnmanagedType.Struct)] ref object obj);
148
149         [DllImport ("libtest")]
150         public static extern int mono_test_marshal_variant_in_sbyte_unmanaged (VarFunc func);
151
152         [DllImport ("libtest")]
153         public static extern int mono_test_marshal_variant_in_byte_unmanaged (VarFunc func);
154
155         [DllImport ("libtest")]
156         public static extern int mono_test_marshal_variant_in_short_unmanaged (VarFunc func);
157
158         [DllImport ("libtest")]
159         public static extern int mono_test_marshal_variant_in_ushort_unmanaged (VarFunc func);
160
161         [DllImport ("libtest")]
162         public static extern int mono_test_marshal_variant_in_int_unmanaged (VarFunc func);
163
164         [DllImport ("libtest")]
165         public static extern int mono_test_marshal_variant_in_uint_unmanaged (VarFunc func);
166
167         [DllImport ("libtest")]
168         public static extern int mono_test_marshal_variant_in_long_unmanaged (VarFunc func);
169
170         [DllImport ("libtest")]
171         public static extern int mono_test_marshal_variant_in_ulong_unmanaged (VarFunc func);
172
173         [DllImport ("libtest")]
174         public static extern int mono_test_marshal_variant_in_float_unmanaged (VarFunc func);
175
176         [DllImport ("libtest")]
177         public static extern int mono_test_marshal_variant_in_double_unmanaged (VarFunc func);
178
179         [DllImport ("libtest")]
180         public static extern int mono_test_marshal_variant_in_bstr_unmanaged (VarFunc func);
181
182         [DllImport ("libtest")]
183         public static extern int mono_test_marshal_variant_in_bool_true_unmanaged (VarFunc func);
184
185         [DllImport ("libtest")]
186         public static extern int mono_test_marshal_variant_in_bool_false_unmanaged (VarFunc func);
187
188         [DllImport ("libtest")]
189         public static extern int mono_test_marshal_variant_out_sbyte_unmanaged (VarRefFunc func);
190
191         [DllImport ("libtest")]
192         public static extern int mono_test_marshal_variant_out_byte_unmanaged (VarRefFunc func);
193
194         [DllImport ("libtest")]
195         public static extern int mono_test_marshal_variant_out_short_unmanaged (VarRefFunc func);
196
197         [DllImport ("libtest")]
198         public static extern int mono_test_marshal_variant_out_ushort_unmanaged (VarRefFunc func);
199
200         [DllImport ("libtest")]
201         public static extern int mono_test_marshal_variant_out_int_unmanaged (VarRefFunc func);
202
203         [DllImport ("libtest")]
204         public static extern int mono_test_marshal_variant_out_uint_unmanaged (VarRefFunc func);
205
206         [DllImport ("libtest")]
207         public static extern int mono_test_marshal_variant_out_long_unmanaged (VarRefFunc func);
208
209         [DllImport ("libtest")]
210         public static extern int mono_test_marshal_variant_out_ulong_unmanaged (VarRefFunc func);
211
212         [DllImport ("libtest")]
213         public static extern int mono_test_marshal_variant_out_float_unmanaged (VarRefFunc func);
214
215         [DllImport ("libtest")]
216         public static extern int mono_test_marshal_variant_out_double_unmanaged (VarRefFunc func);
217
218         [DllImport ("libtest")]
219         public static extern int mono_test_marshal_variant_out_bstr_unmanaged (VarRefFunc func);
220
221         [DllImport ("libtest")]
222         public static extern int mono_test_marshal_variant_out_bool_true_unmanaged (VarRefFunc func);
223
224         [DllImport ("libtest")]
225         public static extern int mono_test_marshal_variant_out_bool_false_unmanaged (VarRefFunc func);
226
227     [DllImport ("libtest")]
228         public static extern int mono_test_marshal_com_object_create (out IntPtr pUnk);
229
230         [DllImport ("libtest")]
231         public static extern int mono_test_marshal_com_object_same (out IntPtr pUnk);
232
233     [DllImport ("libtest")]
234     public static extern int mono_test_marshal_com_object_destroy (IntPtr pUnk);
235
236         [DllImport ("libtest")]
237         public static extern int mono_test_marshal_com_object_ref_count (IntPtr pUnk);
238
239         [DllImport ("libtest")]
240         public static extern int mono_test_marshal_ccw_identity ([MarshalAs (UnmanagedType.Interface)]ITest itest);
241
242         [DllImport ("libtest")]
243         public static extern int mono_test_marshal_ccw_reflexive ([MarshalAs (UnmanagedType.Interface)]ITest itest);
244
245         [DllImport ("libtest")]
246         public static extern int mono_test_marshal_ccw_transitive ([MarshalAs (UnmanagedType.Interface)]ITest itest);
247
248         [DllImport ("libtest")]
249         public static extern int mono_test_marshal_ccw_itest ([MarshalAs (UnmanagedType.Interface)]ITest itest);
250
251         [DllImport ("libtest")]
252         public static extern int mono_test_marshal_ccw_itest ([MarshalAs (UnmanagedType.Interface)]ITestPresSig itest);
253
254         [DllImport("libtest")]
255         public static extern int mono_test_marshal_safearray_out_1dim_vt_bstr_empty ([MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)]out Array array);
256
257         [DllImport("libtest")]
258         public static extern int mono_test_marshal_safearray_out_1dim_vt_bstr ([MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)]out Array array);
259
260         [DllImport("libtest")]
261         public static extern int mono_test_marshal_safearray_out_2dim_vt_i4 ([MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)]out Array array);
262
263         [DllImport("libtest")]
264         public static extern int mono_test_marshal_safearray_out_4dim_vt_i4 ([MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)]out Array array);
265
266         [DllImport("libtest")]
267         public static extern int mono_test_marshal_safearray_in_byval_1dim_empty ([In, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] Array array);
268
269         [DllImport("libtest")]
270         public static extern int mono_test_marshal_safearray_in_byval_1dim_vt_i4 ([In, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] Array array);
271
272         [DllImport("libtest")]
273         public static extern int mono_test_marshal_safearray_in_byval_1dim_vt_mixed ([In, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] Array array);
274
275         [DllImport("libtest")]
276         public static extern int mono_test_marshal_safearray_in_byval_2dim_vt_i4 ([In, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] Array array);
277
278         [DllImport("libtest")]
279         public static extern int mono_test_marshal_safearray_in_byval_3dim_vt_bstr ([In, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] Array array);
280
281         [DllImport("libtest")]
282         public static extern int mono_test_marshal_safearray_in_byref_3dim_vt_bstr ([In, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] ref Array array);
283
284         [DllImport("libtest")]
285         public static extern int mono_test_marshal_safearray_in_out_byref_1dim_empty ([In, Out, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] ref Array array);
286
287         [DllImport("libtest")]
288         public static extern int mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr ([In, Out, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] ref Array array);
289
290         [DllImport("libtest")]
291         public static extern int mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 ([In, Out, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] ref Array array);
292
293         [DllImport("libtest")]
294         public static extern int mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 ([In, Out, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] Array array);
295
296         [DllImport("libtest")]
297         public static extern int mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr ([In, Out, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] Array array);
298
299         [DllImport("libtest")]
300         public static extern int mono_test_marshal_safearray_mixed (
301                 [In, Out, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] Array array1,
302                 [MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] out Array array2,
303                 [In, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] Array array3,
304                 [In, Out, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] ref Array array4);
305
306         [DllImport("libtest")]
307         public static extern bool mono_cominterop_is_supported ();
308
309         public static int Main ()
310         {
311
312                 bool isWindows = !(((int)Environment.OSVersion.Platform == 4) ||
313                         ((int)Environment.OSVersion.Platform == 128));
314
315                 if (mono_cominterop_is_supported () || isWindows)
316                 {
317                         #region BSTR Tests
318
319                         string str;
320                         if (mono_test_marshal_bstr_in ("mono_test_marshal_bstr_in") != 0)
321                                 return 1;
322                         if (mono_test_marshal_bstr_out (out str) != 0 || str != "mono_test_marshal_bstr_out")
323                                 return 2;
324                         if (mono_test_marshal_bstr_in_null (null) != 0)
325                                 return 1;
326                         if (mono_test_marshal_bstr_out_null (out str) != 0 || str != null)
327                                 return 2;
328
329                         #endregion // BSTR Tests
330
331                         #region VARIANT Tests
332
333                         object obj;
334                         if (mono_test_marshal_variant_in_sbyte ((sbyte)100) != 0)
335                                 return 13;
336                         if (mono_test_marshal_variant_in_byte ((byte)100) != 0)
337                                 return 14;
338                         if (mono_test_marshal_variant_in_short ((short)314) != 0)
339                                 return 15;
340                         if (mono_test_marshal_variant_in_ushort ((ushort)314) != 0)
341                                 return 16;
342                         if (mono_test_marshal_variant_in_int ((int)314) != 0)
343                                 return 17;
344                         if (mono_test_marshal_variant_in_uint ((uint)314) != 0)
345                                 return 18;
346                         if (mono_test_marshal_variant_in_long ((long)314) != 0)
347                                 return 19;
348                         if (mono_test_marshal_variant_in_ulong ((ulong)314) != 0)
349                                 return 20;
350                         if (mono_test_marshal_variant_in_float ((float)3.14) != 0)
351                                 return 21;
352                         if (mono_test_marshal_variant_in_double ((double)3.14) != 0)
353                                 return 22;
354                         if (mono_test_marshal_variant_in_bstr ("PI") != 0)
355                                 return 23;
356                         if (mono_test_marshal_variant_out_sbyte (out obj) != 0 || (sbyte)obj != 100)
357                                 return 24;
358                         if (mono_test_marshal_variant_out_byte (out obj) != 0 || (byte)obj != 100)
359                                 return 25;
360                         if (mono_test_marshal_variant_out_short (out obj) != 0 || (short)obj != 314)
361                                 return 26;
362                         if (mono_test_marshal_variant_out_ushort (out obj) != 0 || (ushort)obj != 314)
363                                 return 27;
364                         if (mono_test_marshal_variant_out_int (out obj) != 0 || (int)obj != 314)
365                                 return 28;
366                         if (mono_test_marshal_variant_out_uint (out obj) != 0 || (uint)obj != 314)
367                                 return 29;
368                         if (mono_test_marshal_variant_out_long (out obj) != 0 || (long)obj != 314)
369                                 return 30;
370                         if (mono_test_marshal_variant_out_ulong (out obj) != 0 || (ulong)obj != 314)
371                                 return 31;
372                         if (mono_test_marshal_variant_out_float (out obj) != 0 || ((float)obj - 3.14) / 3.14 > .001)
373                                 return 32;
374                         if (mono_test_marshal_variant_out_double (out obj) != 0 || ((double)obj - 3.14) / 3.14 > .001)
375                                 return 33;
376                         if (mono_test_marshal_variant_out_bstr (out obj) != 0 || (string)obj != "PI")
377                                 return 34;
378
379                         VarFunc func = new VarFunc (mono_test_marshal_variant_in_callback);
380                         if (mono_test_marshal_variant_in_sbyte_unmanaged (func) != 0)
381                                 return 35;
382                         if (mono_test_marshal_variant_in_byte_unmanaged (func) != 0)
383                                 return 36;
384                         if (mono_test_marshal_variant_in_short_unmanaged (func) != 0)
385                                 return 37;
386                         if (mono_test_marshal_variant_in_ushort_unmanaged (func) != 0)
387                                 return 38;
388                         if (mono_test_marshal_variant_in_int_unmanaged (func) != 0)
389                                 return 39;
390                         if (mono_test_marshal_variant_in_uint_unmanaged (func) != 0)
391                                 return 40;
392                         if (mono_test_marshal_variant_in_long_unmanaged (func) != 0)
393                                 return 41;
394                         if (mono_test_marshal_variant_in_ulong_unmanaged (func) != 0)
395                                 return 42;
396                         if (mono_test_marshal_variant_in_float_unmanaged (func) != 0)
397                                 return 43;
398                         if (mono_test_marshal_variant_in_double_unmanaged (func) != 0)
399                                 return 44;
400                         if (mono_test_marshal_variant_in_bstr_unmanaged (func) != 0)
401                                 return 45;
402                         if (mono_test_marshal_variant_in_bool_true_unmanaged (func) != 0)
403                                 return 46;
404
405                         VarRefFunc reffunc = new VarRefFunc (mono_test_marshal_variant_out_callback);
406                         if (mono_test_marshal_variant_out_sbyte_unmanaged (reffunc) != 0)
407                                 return 50;
408                         if (mono_test_marshal_variant_out_byte_unmanaged (reffunc) != 0)
409                                 return 51;
410                         if (mono_test_marshal_variant_out_short_unmanaged (reffunc) != 0)
411                                 return 52;
412                         if (mono_test_marshal_variant_out_ushort_unmanaged (reffunc) != 0)
413                                 return 53;
414                         if (mono_test_marshal_variant_out_int_unmanaged (reffunc) != 0)
415                                 return 54;
416                         if (mono_test_marshal_variant_out_uint_unmanaged (reffunc) != 0)
417                                 return 55;
418                         if (mono_test_marshal_variant_out_long_unmanaged (reffunc) != 0)
419                                 return 56;
420                         if (mono_test_marshal_variant_out_ulong_unmanaged (reffunc) != 0)
421                                 return 57;
422                         if (mono_test_marshal_variant_out_float_unmanaged (reffunc) != 0)
423                                 return 58;
424                         if (mono_test_marshal_variant_out_double_unmanaged (reffunc) != 0)
425                                 return 59;
426                         if (mono_test_marshal_variant_out_bstr_unmanaged (reffunc) != 0)
427                                 return 60;
428                         if (mono_test_marshal_variant_out_bool_true_unmanaged (reffunc) != 0)
429                                 return 61;
430
431                         if (mono_test_marshal_variant_out_sbyte_byref (out obj) != 0 || (sbyte)obj != 100)
432                                 return 97;
433                         if (mono_test_marshal_variant_out_byte_byref (out obj) != 0 || (byte)obj != 100)
434                                 return 98;
435                         if (mono_test_marshal_variant_out_short_byref (out obj) != 0 || (short)obj != 314)
436                                 return 99;
437                         if (mono_test_marshal_variant_out_ushort_byref (out obj) != 0 || (ushort)obj != 314)
438                                 return 100;
439                         if (mono_test_marshal_variant_out_int_byref (out obj) != 0 || (int)obj != 314)
440                                 return 101;
441                         if (mono_test_marshal_variant_out_uint_byref (out obj) != 0 || (uint)obj != 314)
442                                 return 102;
443                         if (mono_test_marshal_variant_out_long_byref (out obj) != 0 || (long)obj != 314)
444                                 return 103;
445                         if (mono_test_marshal_variant_out_ulong_byref (out obj) != 0 || (ulong)obj != 314)
446                                 return 104;
447                         if (mono_test_marshal_variant_out_float_byref (out obj) != 0 || ((float)obj - 3.14) / 3.14 > .001)
448                                 return 105;
449                         if (mono_test_marshal_variant_out_double_byref (out obj) != 0 || ((double)obj - 3.14) / 3.14 > .001)
450                                 return 106;
451                         if (mono_test_marshal_variant_out_bstr_byref (out obj) != 0 || (string)obj != "PI")
452                                 return 107;
453
454                         #endregion // VARIANT Tests
455
456                         #region Runtime Callable Wrapper Tests
457
458 #if !MOBILE
459
460                         IntPtr pUnk;
461                         if (mono_test_marshal_com_object_create (out pUnk) != 0)
462                                 return 145;
463
464                         if (mono_test_marshal_com_object_ref_count (pUnk) != 1)
465                                 return 146;
466
467                         if (Marshal.AddRef (pUnk) != 2)
468                                 return 147;
469
470                         if (mono_test_marshal_com_object_ref_count (pUnk) != 2)
471                                 return 148;
472
473                         if (Marshal.Release (pUnk) != 1)
474                                 return 149;
475
476                         if (mono_test_marshal_com_object_ref_count (pUnk) != 1)
477                                 return 150;
478
479                         object com_obj = Marshal.GetObjectForIUnknown (pUnk);
480
481                         if (com_obj == null)
482                                 return 151;
483
484                         ITest itest = com_obj as ITest;
485
486                         if (itest == null)
487                                 return 152;
488
489                         IntPtr pUnk2;
490                         if (mono_test_marshal_com_object_same (out pUnk2) != 0)
491                                 return 153;
492
493                         object com_obj2 = Marshal.GetObjectForIUnknown (pUnk2);
494                         
495                         if (com_obj != com_obj2)
496                                 return 154;
497
498                         if (!com_obj.Equals (com_obj2))
499                                 return 155;
500
501                         IntPtr pUnk3;
502                         if (mono_test_marshal_com_object_create (out pUnk3) != 0)
503                                 return 156;
504
505                         object com_obj3 = Marshal.GetObjectForIUnknown (pUnk3);
506                         if (com_obj == com_obj3)
507                                 return 157;
508
509                         if (com_obj.Equals (com_obj3))
510                                 return 158;
511
512                         // com_obj & com_obj2 share a RCW
513                         if (Marshal.ReleaseComObject (com_obj2) != 1)
514                                 return 159;
515
516                         // com_obj3 should only have one RCW
517                         if (Marshal.ReleaseComObject (com_obj3) != 0)
518                                 return 160;
519
520                         IntPtr iunknown = Marshal.GetIUnknownForObject (com_obj);
521                         if (iunknown == IntPtr.Zero)
522                                 return 170;
523
524                         if (pUnk != iunknown)
525                                 return 171;
526
527                         if (TestITest (itest) != 0)
528                                 return 172;
529
530                         if (TestITestPresSig (itest as ITestPresSig) != 0)
531                                 return 173;
532
533                         if (TestITestDelegate (itest) != 0)
534                                 return 174;
535
536                         if (TestIfaceNoIcall (itest as ITestPresSig) != 0)
537                                 return 201;
538
539                         itest = new TestClass ();
540
541                         if (TestITest (itest) != 0)
542                                 return 175;
543
544                         itest = (ITest)System.Activator.CreateInstance (typeof(TestActivatorClass));
545
546                         if (TestITest (itest) != 0)
547                                 return 176;
548
549
550 #endif
551
552                         #endregion // Runtime Callable Wrapper Tests
553
554                         #region COM Callable Wrapper Tests
555
556                         ManagedTest test = new ManagedTest ();
557
558                         mono_test_marshal_ccw_itest (test);
559
560                         if (test.Status != 0)
561                                 return 200;
562
563                         ManagedTestPresSig test_pres_sig = new ManagedTestPresSig ();
564
565                         mono_test_marshal_ccw_itest (test_pres_sig);
566
567                         #endregion // COM Callable Wrapper Tests
568
569                         #region SAFEARRAY tests
570                         
571                         if (isWindows) {
572
573                                 /* out */
574
575                                 Array array;
576                                 if ((mono_test_marshal_safearray_out_1dim_vt_bstr_empty (out array) != 0) || (array.Rank != 1) || (array.Length != 0))
577                                         return 62;
578
579                                 if ((mono_test_marshal_safearray_out_1dim_vt_bstr (out array) != 0) || (array.Rank != 1) || (array.Length != 10))
580                                         return 63;
581                                 for (int i = 0; i < 10; ++i) {
582                                         if (i != Convert.ToInt32 (array.GetValue (i)))
583                                                 return 64;
584                                 }
585
586                                 if ((mono_test_marshal_safearray_out_2dim_vt_i4 (out array) != 0) || (array.Rank != 2))
587                                         return 65;
588                                 if (   (array.GetLowerBound (0) != 0) || (array.GetUpperBound (0) != 3)
589                                         || (array.GetLowerBound (1) != 0) || (array.GetUpperBound (1) != 2))
590                                         return 66;
591                                 for (int i = array.GetLowerBound (0); i <= array.GetUpperBound (0); ++i)
592                                 {
593                                         for (int j = array.GetLowerBound (1); j <= array.GetUpperBound (1); ++j) {
594                                                 if ((i + 1) * 10 + (j + 1) != (int)array.GetValue (new long[] { i, j }))
595                                                         return 67;
596                                         }
597                                 }
598
599                                 if ((mono_test_marshal_safearray_out_4dim_vt_i4 (out array) != 0) || (array.Rank != 4))
600                                         return 68;
601                                 if (   (array.GetLowerBound (0) != 15) || (array.GetUpperBound (0) != 24)
602                                         || (array.GetLowerBound (1) != 20) || (array.GetUpperBound (1) != 22)
603                                         || (array.GetLowerBound (2) !=  5) || (array.GetUpperBound (2) != 10)
604                                         || (array.GetLowerBound (3) != 12) || (array.GetUpperBound (3) != 18) )
605                                         return 69;
606
607                                 int index = 0;
608                                 for (int i = array.GetLowerBound (3); i <= array.GetUpperBound (3); ++i) {
609                                         for (int j = array.GetLowerBound (2); j <= array.GetUpperBound (2); ++j) {
610                                                 for (int k = array.GetLowerBound (1); k <= array.GetUpperBound (1); ++k) {
611                                                         for (int l = array.GetLowerBound (0); l <= array.GetUpperBound (0); ++l) {
612                                                                 if (index != (int)array.GetValue (new long[] { l, k, j, i }))
613                                                                         return 70;
614                                                                 ++index;
615                                                         }
616                                                 }
617                                         }
618                                 }
619
620                                 /* in */
621
622                                 array = new object[] { };
623                                 if (mono_test_marshal_safearray_in_byval_1dim_empty (array) != 0)
624                                         return 71;
625
626                                 array = new object[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
627                                 if (mono_test_marshal_safearray_in_byval_1dim_vt_i4 (array) != 0)
628                                         return 72;
629
630                                 array = new object[] { 0, "1", 2, "3", 4, "5", 6, "7", 8, "9", 10, "11", 12 };
631                                 if (mono_test_marshal_safearray_in_byval_1dim_vt_mixed (array) != 0)
632                                         return 73;
633                                 if ((int)array.GetValue (0) != 0)
634                                         return 74;
635
636                                 array = new object[,] { { 11, 12, 13, 14 }, { 21, 22, 23, 24 } };
637                                 if (mono_test_marshal_safearray_in_byval_2dim_vt_i4 (array) != 0)
638                                         return 75;
639                                 if ((int)array.GetValue (new int[] { 0, 0 }) != 11)
640                                         return 76;
641
642                                 array = new object[,,] { { { "111", "112", "113" }, { "121", "122", "123" } }, { { "211", "212", "213" }, { "221", "222", "223" } } };
643                                 if (mono_test_marshal_safearray_in_byval_3dim_vt_bstr (array) != 0)
644                                         return 77;
645                                 if ((string)array.GetValue (new int[] { 0, 0, 0 }) != "111")
646                                         return 78;
647
648                                 array = new object[,,] { { { "111", "112", "113" }, { "121", "122", "123" } }, { { "211", "212", "213" }, { "221", "222", "223" } } };
649                                 if ((mono_test_marshal_safearray_in_byref_3dim_vt_bstr (ref array) != 0) || (array.Rank != 3) || (array.Length != 12))
650                                         return 79;
651                                 if ((string)array.GetValue (new int[] { 0, 0, 0 }) != "111")
652                                         return 80;
653
654                                 /* in, out, byref */
655
656                                 array = new object[] { };
657                                 if ((mono_test_marshal_safearray_in_out_byref_1dim_empty (ref array) != 0) || (array.Rank != 1) || (array.Length != 8))
658                                         return 81;
659                                 for (int i = 0; i < 8; ++i)
660                                 {
661                                         if (i != Convert.ToInt32 (array.GetValue (i)))
662                                                 return 82;
663                                 }
664
665                                 array = new object[,,] { { { "111", "112", "113" }, { "121", "122", "123" } }, { { "211", "212", "213" }, { "221", "222", "223" } } };
666                                 if ((mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr (ref array) != 0) || (array.Rank != 1) || (array.Length != 8))
667                                         return 83;
668                                 for (int i = 0; i < 8; ++i)
669                                 {
670                                         if (i != Convert.ToInt32 (array.GetValue (i)))
671                                                 return 84;
672                                 }
673
674                                 array = new object[] { 1 };
675                                 if ((mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 (ref array) != 0) || (array.Rank != 1) || (array.Length != 1))
676                                 {
677                                     return 85;
678                                 }
679                                 if (Convert.ToInt32 (array.GetValue (0)) != -1)
680                                     return 86;
681
682                                 /* in, out, byval */
683
684                                 array = new object[] { 1 };
685                                 if ((mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (array) != 0) || (array.Rank != 1) || (array.Length != 1))
686                                 {
687                                         return 87;
688                                 }
689                                 if (Convert.ToInt32 (array.GetValue (0)) != 12345)
690                                         return 88;
691
692                                 array = new object[,,] { { { "111", "112", "113" }, { "121", "122", "123" } }, { { "211", "212", "213" }, { "221", "222", "223" } } };
693                                 if ((mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr (array) != 0) || (array.Rank != 3) || (array.Length != 12))
694                                 {
695                                     return 89;
696                                 }
697                                 if (Convert.ToInt32 (array.GetValue (new int[] { 1, 1, 1 })) != 111)
698                                         return 90;
699                                 if (Convert.ToInt32 (array.GetValue (new int[] { 1, 1, 2 })) != 333)
700                                         return 91;
701                                 if (Convert.ToString(array.GetValue (new int[] { 0, 1, 0 })) != "ABCDEFG")
702                                         return 92;
703
704                                 /* Multiple safearray parameters with various types and options */
705
706                                 Array array1 = new object[] { 1 };
707                                 Array array2 = new object[,] { { 11, 12, 13, 14 }, { 21, 22, 23, 24 } };
708                                 Array array3 = new object[] { 0, "1", 2, "3", 4, "5", 6, "7", 8, "9", 10, "11", 12 };
709                                 Array array4 = new object[,,] { { { "111", "112", "113" }, { "121", "122", "123" } }, { { "211", "212", "213" }, { "221", "222", "223" } } };
710                                 if (    (mono_test_marshal_safearray_mixed (array1, out array2, array3, ref array4) != 0)
711                                          || (array1.Rank != 1) || (array1.Length != 1) || (Convert.ToInt32 (array1.GetValue (0)) != 12345)
712                                          || (array2.Rank != 1) || (array2.Length != 10)
713                                          || (array4.Rank != 1) || (array4.Length != 8)
714                                         )
715                                 {
716                                         return 93;
717                                 }
718                                 for (int i = 0; i < 10; ++i)
719                                 {
720                                         if (i != Convert.ToInt32 (array2.GetValue (i)))
721                                                 return 94;
722                                 }
723                                 if ((int)array3.GetValue (0) != 0)
724                                         return 95;
725                                 for (int i = 0; i < 8; ++i)
726                                 {
727                                         if (i != Convert.ToInt32 (array4.GetValue (i)))
728                                                 return 96;
729                                 }
730                         }
731                         #endregion // SafeArray Tests
732
733                         #region COM Visible Test
734                         TestVisible test_vis = new TestVisible();
735                         IntPtr pDisp = Marshal.GetIDispatchForObject(test_vis);
736                         if (pDisp == IntPtr.Zero)
737                                 return 200;
738                         #endregion 
739                 }
740
741         return 0;
742         }
743
744
745         [ComImport ()]
746         [Guid ("00000000-0000-0000-0000-000000000001")]
747         [InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
748         public interface ITest
749         {
750                 // properties need to go first since mcs puts them there
751                 ITest Test
752                 {
753                         [return: MarshalAs (UnmanagedType.Interface)]
754                         [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId (5242884)]
755                         get;
756                 }
757
758                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
759                 void SByteIn (sbyte val);
760                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
761                 void ByteIn (byte val);
762                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
763                 void ShortIn (short val);
764                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
765                 void UShortIn (ushort val);
766                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
767                 void IntIn (int val);
768                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
769                 void UIntIn (uint val);
770                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
771                 void LongIn (long val);
772                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
773                 void ULongIn (ulong val);
774                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
775                 void FloatIn (float val);
776                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
777                 void DoubleIn (double val);
778                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
779                 void ITestIn ([MarshalAs (UnmanagedType.Interface)]ITest val);
780                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
781                 void ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITest val);
782                 int Return22NoICall();
783         }
784
785         [ComImport ()]
786         [Guid ("00000000-0000-0000-0000-000000000001")]
787         [InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
788         public interface ITestPresSig
789         {
790                 // properties need to go first since mcs puts them there
791                 ITestPresSig Test
792                 {
793                         [return: MarshalAs (UnmanagedType.Interface)]
794                         [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId (5242884)]
795                         get;
796                 }
797
798                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
799                 [PreserveSig ()]
800                 int SByteIn (sbyte val);
801                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
802                 [PreserveSig ()]
803                 int ByteIn (byte val);
804                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
805                 [PreserveSig ()]
806                 int ShortIn (short val);
807                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
808                 [PreserveSig ()]
809                 int UShortIn (ushort val);
810                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
811                 [PreserveSig ()]
812                 int IntIn (int val);
813                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
814                 [PreserveSig ()]
815                 int UIntIn (uint val);
816                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
817                 [PreserveSig ()]
818                 int LongIn (long val);
819                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
820                 [PreserveSig ()]
821                 int ULongIn (ulong val);
822                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
823                 [PreserveSig ()]
824                 int FloatIn (float val);
825                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
826                 [PreserveSig ()]
827                 int DoubleIn (double val);
828                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
829                 [PreserveSig ()]
830                 int ITestIn ([MarshalAs (UnmanagedType.Interface)]ITestPresSig val);
831                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
832                 [PreserveSig ()]
833                 int ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITestPresSig val);
834                 [PreserveSig ()]
835                 int Return22NoICall();
836         }
837
838         [System.Runtime.InteropServices.GuidAttribute ("00000000-0000-0000-0000-000000000002")]
839         [System.Runtime.InteropServices.ComImportAttribute ()]
840         [System.Runtime.InteropServices.ClassInterfaceAttribute (ClassInterfaceType.None)]
841         public class _TestClass : ITest
842         {
843                 // properties need to go first since mcs puts them there
844                 public virtual extern ITest Test
845                 {
846                         [return: MarshalAs (UnmanagedType.Interface)]
847                         [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId (5242884)]
848                         get;
849                 }
850
851                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
852                 public virtual extern void SByteIn (sbyte val);
853                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
854                 public virtual extern void ByteIn (byte val);
855                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
856                 public virtual extern void ShortIn (short val);
857                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
858                 public virtual extern void UShortIn (ushort val);
859                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
860                 public virtual extern void IntIn (int val);
861                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
862                 public virtual extern void UIntIn (uint val);
863                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
864                 public virtual extern void LongIn (long val);
865                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
866                 public virtual extern void ULongIn (ulong val);
867                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
868                 public virtual extern void FloatIn (float val);
869                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
870                 public virtual extern void DoubleIn (double val);
871                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
872                 public virtual extern void ITestIn ([MarshalAs (UnmanagedType.Interface)]ITest val);
873                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
874                 public virtual extern void ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITest val);
875
876                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
877                 public virtual extern int Return22NoICall();
878         }
879
880         [System.Runtime.InteropServices.GuidAttribute ("00000000-0000-0000-0000-000000000002")]
881         public class TestClass : _TestClass
882         {
883                 static TestClass ()
884                 {
885                         ExtensibleClassFactory.RegisterObjectCreationCallback (new ObjectCreationDelegate (CreateObject)); ;
886                 }
887                 private static System.IntPtr CreateObject (System.IntPtr aggr)
888                 {
889                         IntPtr pUnk3;
890                         mono_test_marshal_com_object_create (out pUnk3);
891                         return pUnk3;
892                 }
893         }
894
895         [System.Runtime.InteropServices.GuidAttribute ("00000000-0000-0000-0000-000000000003")]
896         public class TestActivatorClass : _TestClass
897         {
898                 static TestActivatorClass ()
899                 {
900                         ExtensibleClassFactory.RegisterObjectCreationCallback (new ObjectCreationDelegate (CreateObject)); ;
901                 }
902                 private static System.IntPtr CreateObject (System.IntPtr aggr)
903                 {
904                         IntPtr pUnk3;
905                         mono_test_marshal_com_object_create (out pUnk3);
906                         return pUnk3;
907                 }
908         }
909
910         delegate void SByteInDelegate (sbyte val);
911         delegate void ByteInDelegate (byte val);
912         delegate void ShortInDelegate (short val);
913         delegate void UShortInDelegate (ushort val);
914         delegate void IntInDelegate (int val);
915         delegate void UIntInDelegate (uint val);
916         delegate void LongInDelegate (long val);
917         delegate void ULongInDelegate (ulong val);
918         delegate void FloatInDelegate (float val);
919         delegate void DoubleInDelegate (double val);
920         delegate void ITestInDelegate (ITest val);
921         delegate void ITestOutDelegate (out ITest val);
922
923         public class ManagedTestPresSig : ITestPresSig
924         {               // properties need to go first since mcs puts them there
925                 public ITestPresSig Test
926                 {
927                         get
928                         {
929                                 return new ManagedTestPresSig ();
930                         }
931                 }
932
933                 public int SByteIn (sbyte val)
934                 {
935                         if (val != -100)
936                                 return 1;
937                         return 0;
938                 }
939
940                 public int ByteIn (byte val)
941                 {
942                         if (val != 100)
943                                 return 2;
944                         return 0;
945                 }
946
947                 public int ShortIn (short val)
948                 {
949                         if (val != -100)
950                                 return 3;
951                         return 0;
952                 }
953
954                 public int UShortIn (ushort val)
955                 {
956                         if (val != 100)
957                                 return 4;
958                         return 0;
959                 }
960
961                 public int IntIn (int val)
962                 {
963                         if (val != -100)
964                                 return 5;
965                         return 0;
966                 }
967
968                 public int UIntIn (uint val)
969                 {
970                         if (val != 100)
971                                 return 6;
972                         return 0;
973                 }
974
975                 public int LongIn (long val)
976                 {
977                         if (val != -100)
978                                 return 7;
979                         return 0;
980                 }
981
982                 public int ULongIn (ulong val)
983                 {
984                         if (val != 100)
985                                 return 8;
986                         return 0;
987                 }
988
989                 public int FloatIn (float val)
990                 {
991                         if (Math.Abs (val - 3.14f) > .000001)
992                                 return 9;
993                         return 0;
994                 }
995
996                 public int DoubleIn (double val)
997                 {
998                         if (Math.Abs (val - 3.14f) > .000001)
999                                 return 10;
1000                         return 0;
1001                 }
1002
1003                 public int ITestIn ([MarshalAs (UnmanagedType.Interface)]ITestPresSig val)
1004                 {
1005                         if (val == null)
1006                                 return 11;
1007                         if (null == val as ManagedTestPresSig)
1008                                 return 12;
1009                         return 0;
1010                 }
1011
1012                 public int ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITestPresSig val)
1013                 {
1014                         val = new ManagedTestPresSig ();
1015                         return 0;
1016                 }
1017
1018                 public int Return22NoICall()
1019                 {
1020                         return 88;
1021                 }
1022         }
1023
1024         public class ManagedTest : ITest
1025         {
1026                 private int status = 0;
1027                 public int Status
1028                 {
1029                         get { return status; }
1030                 }
1031                 public void SByteIn (sbyte val)
1032                 {
1033                         if (val != -100)
1034                                 status = 1;
1035                 }
1036
1037                 public void ByteIn (byte val)
1038                 {
1039                         if (val != 100)
1040                                 status = 2;
1041                 }
1042
1043                 public void ShortIn (short val)
1044                 {
1045                         if (val != -100)
1046                                 status = 3;
1047                 }
1048
1049                 public void UShortIn (ushort val)
1050                 {
1051                         if (val != 100)
1052                                 status = 4;
1053                 }
1054
1055                 public void IntIn (int val)
1056                 {
1057                         if (val != -100)
1058                                 status = 5;
1059                 }
1060
1061                 public void UIntIn (uint val)
1062                 {
1063                         if (val != 100)
1064                                 status = 6;
1065                 }
1066
1067                 public void LongIn (long val)
1068                 {
1069                         if (val != -100)
1070                                 status = 7;
1071                 }
1072
1073                 public void ULongIn (ulong val)
1074                 {
1075                         if (val != 100)
1076                                 status = 8;
1077                 }
1078
1079                 public void FloatIn (float val)
1080                 {
1081                         if (Math.Abs (val - 3.14f) > .000001)
1082                                 status = 9;
1083                 }
1084
1085                 public void DoubleIn (double val)
1086                 {
1087                         if (Math.Abs (val - 3.14) > .000001)
1088                                 status = 10;
1089                 }
1090
1091                 public void ITestIn (ITest val)
1092                 {
1093                         if (val == null)
1094                                 status = 11;
1095                         if (null == val as ManagedTest)
1096                                 status = 12;
1097                 }
1098
1099                 public void ITestOut (out ITest val)
1100                 {
1101                         val = new ManagedTest ();
1102                 }
1103
1104                 public ITest Test
1105                 {
1106                         get
1107                         {
1108                                 return new ManagedTest ();
1109                         }
1110                 }
1111
1112                 public int Return22NoICall()
1113                 {
1114                         return 99;
1115                 }
1116         }
1117
1118         public static int mono_test_marshal_variant_in_callback (VarEnum vt, object obj)
1119         {
1120                 switch (vt)
1121                 {
1122                 case VarEnum.VT_I1:
1123                         if (obj.GetType () != typeof (sbyte))
1124                                 return 1;
1125                         if ((sbyte)obj != -100)
1126                                 return 2;
1127                         break;
1128                 case VarEnum.VT_UI1:
1129                         if (obj.GetType () != typeof (byte))
1130                                 return 1;
1131                         if ((byte)obj != 100)
1132                                 return 2;
1133                         break;
1134                 case VarEnum.VT_I2:
1135                         if (obj.GetType () != typeof (short))
1136                                 return 1;
1137                         if ((short)obj != -100)
1138                                 return 2;
1139                         break;
1140                 case VarEnum.VT_UI2:
1141                         if (obj.GetType () != typeof (ushort))
1142                                 return 1;
1143                         if ((ushort)obj != 100)
1144                                 return 2;
1145                         break;
1146                 case VarEnum.VT_I4:
1147                         if (obj.GetType () != typeof (int))
1148                                 return 1;
1149                         if ((int)obj != -100)
1150                                 return 2;
1151                         break;
1152                 case VarEnum.VT_UI4:
1153                         if (obj.GetType () != typeof (uint))
1154                                 return 1;
1155                         if ((uint)obj != 100)
1156                                 return 2;
1157                         break;
1158                 case VarEnum.VT_I8:
1159                         if (obj.GetType () != typeof (long))
1160                                 return 1;
1161                         if ((long)obj != -100)
1162                                 return 2;
1163                         break;
1164                 case VarEnum.VT_UI8:
1165                         if (obj.GetType () != typeof (ulong))
1166                                 return 1;
1167                         if ((ulong)obj != 100)
1168                                 return 2;
1169                         break;
1170                 case VarEnum.VT_R4:
1171                         if (obj.GetType () != typeof (float))
1172                                 return 1;
1173                         if (Math.Abs ((float)obj - 3.14f) > 1e-10)
1174                                 return 2;
1175                         break;
1176                 case VarEnum.VT_R8:
1177                         if (obj.GetType () != typeof (double))
1178                                 return 1;
1179                         if (Math.Abs ((double)obj - 3.14) > 1e-10)
1180                                 return 2;
1181                         break;
1182                 case VarEnum.VT_BSTR:
1183                         if (obj.GetType () != typeof (string))
1184                                 return 1;
1185                         if ((string)obj != "PI")
1186                                 return 2;
1187                         break;
1188                 case VarEnum.VT_BOOL:
1189                         if (obj.GetType () != typeof (bool))
1190                                 return 1;
1191                         if ((bool)obj != true)
1192                                 return 2;
1193                         break;
1194                 }
1195                 return 0;
1196         }
1197
1198         public static int mono_test_marshal_variant_out_callback (VarEnum vt, ref object obj)
1199         {
1200                 switch (vt) {
1201                 case VarEnum.VT_I1:
1202                         obj = (sbyte)-100;
1203                         break;
1204                 case VarEnum.VT_UI1:
1205                         obj = (byte)100;
1206                         break;
1207                 case VarEnum.VT_I2:
1208                         obj = (short)-100;
1209                         break;
1210                 case VarEnum.VT_UI2:
1211                         obj = (ushort)100;
1212                         break;
1213                 case VarEnum.VT_I4:
1214                         obj = (int)-100;
1215                         break;
1216                 case VarEnum.VT_UI4:
1217                         obj = (uint)100;
1218                         break;
1219                 case VarEnum.VT_I8:
1220                         obj = (long)-100;
1221                         break;
1222                 case VarEnum.VT_UI8:
1223                         obj = (ulong)100;
1224                         break;
1225                 case VarEnum.VT_R4:
1226                         obj = (float)3.14f;
1227                         break;
1228                 case VarEnum.VT_R8:
1229                         obj = (double)3.14;
1230                         break;
1231                 case VarEnum.VT_BSTR:
1232                         obj = "PI";
1233                         break;
1234                 case VarEnum.VT_BOOL:
1235                         obj = true;
1236                         break;
1237                 }
1238                 return 0;
1239         }
1240
1241         public static int TestITest (ITest itest)
1242         {
1243                 try {
1244                         ITest itest2;
1245                         itest.SByteIn (-100);
1246                         itest.ByteIn (100);
1247                         itest.ShortIn (-100);
1248                         itest.UShortIn (100);
1249                         itest.IntIn (-100);
1250                         itest.UIntIn (100);
1251                         itest.LongIn (-100);
1252                         itest.ULongIn (100);
1253                         itest.FloatIn (3.14f);
1254                         itest.DoubleIn (3.14);
1255                         itest.ITestIn (itest);
1256                         itest.ITestOut (out itest2);
1257                 }
1258                 catch (Exception ex) {
1259                         return 1;
1260                 }
1261                 return 0;
1262         }
1263
1264         public static int TestITestPresSig (ITestPresSig itest)
1265         {
1266                 ITestPresSig itest2;
1267                 if (itest.SByteIn (-100) != 0)
1268                         return 1000;
1269                 if (itest.ByteIn (100) != 0)
1270                         return 1001;
1271                 if (itest.ShortIn (-100) != 0)
1272                         return 1002;
1273                 if (itest.UShortIn (100) != 0)
1274                         return 1003;
1275                 if (itest.IntIn (-100) != 0)
1276                         return 1004;
1277                 if (itest.UIntIn (100) != 0)
1278                         return 1005;
1279                 if (itest.LongIn (-100) != 0)
1280                         return 1006;
1281                 if (itest.ULongIn (100) != 0)
1282                         return 1007;
1283                 if (itest.FloatIn (3.14f) != 0)
1284                         return 1008;
1285                 if (itest.DoubleIn (3.14) != 0)
1286                         return 1009;
1287                 if (itest.ITestIn (itest) != 0)
1288                         return 1010;
1289                 if (itest.ITestOut (out itest2) != 0)
1290                         return 1011;
1291                 return 0;
1292         }
1293
1294         public static int TestITestDelegate (ITest itest)
1295         {
1296                 try {
1297                         ITest itest2;
1298
1299                         SByteInDelegate SByteInFcn= itest.SByteIn;
1300                         ByteInDelegate ByteInFcn = itest.ByteIn;
1301                         UShortInDelegate UShortInFcn = itest.UShortIn;
1302                         IntInDelegate IntInFcn = itest.IntIn;
1303                         UIntInDelegate UIntInFcn = itest.UIntIn;
1304                         LongInDelegate LongInFcn = itest.LongIn;
1305
1306                         ULongInDelegate ULongInFcn = itest.ULongIn;
1307                         FloatInDelegate FloatInFcn = itest.FloatIn;
1308                         DoubleInDelegate DoubleInFcn = itest.DoubleIn;
1309                         ITestInDelegate ITestInFcn = itest.ITestIn;
1310                         ITestOutDelegate ITestOutFcn = itest.ITestOut;
1311
1312                         SByteInFcn (-100);
1313                         ByteInFcn (100);
1314                         UShortInFcn (100);
1315                         IntInFcn (-100);
1316                         UIntInFcn (100);
1317                         LongInFcn (-100);
1318                         ULongInFcn (100);
1319                         FloatInFcn (3.14f);
1320                         DoubleInFcn (3.14);
1321                         ITestInFcn (itest);
1322                         ITestOutFcn (out itest2);
1323                 }
1324                 catch (Exception) {
1325                         return 1;
1326                 }
1327                 return 0;
1328         }
1329
1330         public static int TestIfaceNoIcall (ITestPresSig itest) {
1331                 return itest.Return22NoICall () == 22 ? 0 : 1;
1332         }
1333 }
1334
1335 public class TestVisible
1336 {
1337 }