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