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