Handle ENETDOWN error if defined.
[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                         itest = (ITest)System.Activator.CreateInstance (typeof(TestActivatorClass));
478
479                         if (TestITest (itest) != 0)
480                                 return 176;
481
482                         #endregion // Runtime Callable Wrapper Tests
483
484                         #region COM Callable Wrapper Tests
485
486                         ManagedTest test = new ManagedTest ();
487
488                         mono_test_marshal_ccw_itest (test);
489
490                         if (test.Status != 0)
491                                 return 200;
492
493                         ManagedTestPresSig test_pres_sig = new ManagedTestPresSig ();
494
495                         mono_test_marshal_ccw_itest (test_pres_sig);
496
497                         #endregion // COM Callable Wrapper Tests
498
499                         #region SAFEARRAY tests
500                         
501                         if (isWindows) {
502
503                                 /* out */
504
505                                 Array array;
506                                 if ((mono_test_marshal_safearray_out_1dim_vt_bstr_empty (out array) != 0) || (array.Rank != 1) || (array.Length != 0))
507                                         return 62;
508
509                                 if ((mono_test_marshal_safearray_out_1dim_vt_bstr (out array) != 0) || (array.Rank != 1) || (array.Length != 10))
510                                         return 63;
511                                 for (int i = 0; i < 10; ++i) {
512                                         if (i != Convert.ToInt32 (array.GetValue (i)))
513                                                 return 64;
514                                 }
515
516                                 if ((mono_test_marshal_safearray_out_2dim_vt_i4 (out array) != 0) || (array.Rank != 2))
517                                         return 65;
518                                 if (   (array.GetLowerBound (0) != 0) || (array.GetUpperBound (0) != 3)
519                                         || (array.GetLowerBound (1) != 0) || (array.GetUpperBound (1) != 2))
520                                         return 66;
521                                 for (int i = array.GetLowerBound (0); i <= array.GetUpperBound (0); ++i)
522                                 {
523                                         for (int j = array.GetLowerBound (1); j <= array.GetUpperBound (1); ++j) {
524                                                 if ((i + 1) * 10 + (j + 1) != (int)array.GetValue (new long[] { i, j }))
525                                                         return 67;
526                                         }
527                                 }
528
529                                 if ((mono_test_marshal_safearray_out_4dim_vt_i4 (out array) != 0) || (array.Rank != 4))
530                                         return 68;
531                                 if (   (array.GetLowerBound (0) != 15) || (array.GetUpperBound (0) != 24)
532                                         || (array.GetLowerBound (1) != 20) || (array.GetUpperBound (1) != 22)
533                                         || (array.GetLowerBound (2) !=  5) || (array.GetUpperBound (2) != 10)
534                                         || (array.GetLowerBound (3) != 12) || (array.GetUpperBound (3) != 18) )
535                                         return 69;
536
537                                 int index = 0;
538                                 for (int i = array.GetLowerBound (3); i <= array.GetUpperBound (3); ++i) {
539                                         for (int j = array.GetLowerBound (2); j <= array.GetUpperBound (2); ++j) {
540                                                 for (int k = array.GetLowerBound (1); k <= array.GetUpperBound (1); ++k) {
541                                                         for (int l = array.GetLowerBound (0); l <= array.GetUpperBound (0); ++l) {
542                                                                 if (index != (int)array.GetValue (new long[] { l, k, j, i }))
543                                                                         return 70;
544                                                                 ++index;
545                                                         }
546                                                 }
547                                         }
548                                 }
549
550                                 /* in */
551
552                                 array = new object[] { };
553                                 if (mono_test_marshal_safearray_in_byval_1dim_empty (array) != 0)
554                                         return 71;
555
556                                 array = new object[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
557                                 if (mono_test_marshal_safearray_in_byval_1dim_vt_i4 (array) != 0)
558                                         return 72;
559
560                                 array = new object[] { 0, "1", 2, "3", 4, "5", 6, "7", 8, "9", 10, "11", 12 };
561                                 if (mono_test_marshal_safearray_in_byval_1dim_vt_mixed (array) != 0)
562                                         return 73;
563                                 if ((int)array.GetValue (0) != 0)
564                                         return 74;
565
566                                 array = new object[,] { { 11, 12, 13, 14 }, { 21, 22, 23, 24 } };
567                                 if (mono_test_marshal_safearray_in_byval_2dim_vt_i4 (array) != 0)
568                                         return 75;
569                                 if ((int)array.GetValue (new int[] { 0, 0 }) != 11)
570                                         return 76;
571
572                                 array = new object[,,] { { { "111", "112", "113" }, { "121", "122", "123" } }, { { "211", "212", "213" }, { "221", "222", "223" } } };
573                                 if (mono_test_marshal_safearray_in_byval_3dim_vt_bstr (array) != 0)
574                                         return 77;
575                                 if ((string)array.GetValue (new int[] { 0, 0, 0 }) != "111")
576                                         return 78;
577
578                                 array = new object[,,] { { { "111", "112", "113" }, { "121", "122", "123" } }, { { "211", "212", "213" }, { "221", "222", "223" } } };
579                                 if ((mono_test_marshal_safearray_in_byref_3dim_vt_bstr (ref array) != 0) || (array.Rank != 3) || (array.Length != 12))
580                                         return 79;
581                                 if ((string)array.GetValue (new int[] { 0, 0, 0 }) != "111")
582                                         return 80;
583
584                                 /* in, out, byref */
585
586                                 array = new object[] { };
587                                 if ((mono_test_marshal_safearray_in_out_byref_1dim_empty (ref array) != 0) || (array.Rank != 1) || (array.Length != 8))
588                                         return 81;
589                                 for (int i = 0; i < 8; ++i)
590                                 {
591                                         if (i != Convert.ToInt32 (array.GetValue (i)))
592                                                 return 82;
593                                 }
594
595                                 array = new object[,,] { { { "111", "112", "113" }, { "121", "122", "123" } }, { { "211", "212", "213" }, { "221", "222", "223" } } };
596                                 if ((mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr (ref array) != 0) || (array.Rank != 1) || (array.Length != 8))
597                                         return 83;
598                                 for (int i = 0; i < 8; ++i)
599                                 {
600                                         if (i != Convert.ToInt32 (array.GetValue (i)))
601                                                 return 84;
602                                 }
603
604                                 array = new object[] { 1 };
605                                 if ((mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 (ref array) != 0) || (array.Rank != 1) || (array.Length != 1))
606                                 {
607                                     return 85;
608                                 }
609                                 if (Convert.ToInt32 (array.GetValue (0)) != -1)
610                                     return 86;
611
612                                 /* in, out, byval */
613
614                                 array = new object[] { 1 };
615                                 if ((mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (array) != 0) || (array.Rank != 1) || (array.Length != 1))
616                                 {
617                                         return 87;
618                                 }
619                                 if (Convert.ToInt32 (array.GetValue (0)) != 12345)
620                                         return 88;
621
622                                 array = new object[,,] { { { "111", "112", "113" }, { "121", "122", "123" } }, { { "211", "212", "213" }, { "221", "222", "223" } } };
623                                 if ((mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr (array) != 0) || (array.Rank != 3) || (array.Length != 12))
624                                 {
625                                     return 89;
626                                 }
627                                 if (Convert.ToInt32 (array.GetValue (new int[] { 1, 1, 1 })) != 111)
628                                         return 90;
629                                 if (Convert.ToInt32 (array.GetValue (new int[] { 1, 1, 2 })) != 333)
630                                         return 91;
631                                 if (Convert.ToString(array.GetValue (new int[] { 0, 1, 0 })) != "ABCDEFG")
632                                         return 92;
633
634                                 /* Multiple safearray parameters with various types and options */
635
636                                 Array array1 = new object[] { 1 };
637                                 Array array2 = new object[,] { { 11, 12, 13, 14 }, { 21, 22, 23, 24 } };
638                                 Array array3 = new object[] { 0, "1", 2, "3", 4, "5", 6, "7", 8, "9", 10, "11", 12 };
639                                 Array array4 = new object[,,] { { { "111", "112", "113" }, { "121", "122", "123" } }, { { "211", "212", "213" }, { "221", "222", "223" } } };
640                                 if (    (mono_test_marshal_safearray_mixed (array1, out array2, array3, ref array4) != 0)
641                                          || (array1.Rank != 1) || (array1.Length != 1) || (Convert.ToInt32 (array1.GetValue (0)) != 12345)
642                                          || (array2.Rank != 1) || (array2.Length != 10)
643                                          || (array4.Rank != 1) || (array4.Length != 8)
644                                         )
645                                 {
646                                         return 93;
647                                 }
648                                 for (int i = 0; i < 10; ++i)
649                                 {
650                                         if (i != Convert.ToInt32 (array2.GetValue (i)))
651                                                 return 94;
652                                 }
653                                 if ((int)array3.GetValue (0) != 0)
654                                         return 95;
655                                 for (int i = 0; i < 8; ++i)
656                                 {
657                                         if (i != Convert.ToInt32 (array4.GetValue (i)))
658                                                 return 96;
659                                 }
660                         }
661                         #endregion // SafeArray Tests
662
663                         #region COM Visible Test
664                         TestVisible test_vis = new TestVisible();
665                         IntPtr pDisp = Marshal.GetIDispatchForObject(test_vis);
666                         if (pDisp == IntPtr.Zero)
667                                 return 200;
668                         #endregion 
669                 }
670
671         return 0;
672         }
673
674
675         [ComImport ()]
676         [Guid ("00000000-0000-0000-0000-000000000001")]
677         [InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
678         public interface ITest
679         {
680                 // properties need to go first since mcs puts them there
681                 ITest Test
682                 {
683                         [return: MarshalAs (UnmanagedType.Interface)]
684                         [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId (5242884)]
685                         get;
686                 }
687
688                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
689                 void SByteIn (sbyte val);
690                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
691                 void ByteIn (byte val);
692                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
693                 void ShortIn (short val);
694                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
695                 void UShortIn (ushort val);
696                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
697                 void IntIn (int val);
698                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
699                 void UIntIn (uint val);
700                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
701                 void LongIn (long val);
702                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
703                 void ULongIn (ulong val);
704                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
705                 void FloatIn (float val);
706                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
707                 void DoubleIn (double val);
708                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
709                 void ITestIn ([MarshalAs (UnmanagedType.Interface)]ITest val);
710                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
711                 void ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITest val);
712         }
713
714         [ComImport ()]
715         [Guid ("00000000-0000-0000-0000-000000000001")]
716         [InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
717         public interface ITestPresSig
718         {
719                 // properties need to go first since mcs puts them there
720                 ITestPresSig Test
721                 {
722                         [return: MarshalAs (UnmanagedType.Interface)]
723                         [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId (5242884)]
724                         get;
725                 }
726
727                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
728                 [PreserveSig ()]
729                 int SByteIn (sbyte val);
730                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
731                 [PreserveSig ()]
732                 int ByteIn (byte val);
733                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
734                 [PreserveSig ()]
735                 int ShortIn (short val);
736                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
737                 [PreserveSig ()]
738                 int UShortIn (ushort val);
739                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
740                 [PreserveSig ()]
741                 int IntIn (int val);
742                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
743                 [PreserveSig ()]
744                 int UIntIn (uint val);
745                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
746                 [PreserveSig ()]
747                 int LongIn (long val);
748                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
749                 [PreserveSig ()]
750                 int ULongIn (ulong val);
751                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
752                 [PreserveSig ()]
753                 int FloatIn (float val);
754                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
755                 [PreserveSig ()]
756                 int DoubleIn (double val);
757                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
758                 [PreserveSig ()]
759                 int ITestIn ([MarshalAs (UnmanagedType.Interface)]ITestPresSig val);
760                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
761                 [PreserveSig ()]
762                 int ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITestPresSig val);
763         }
764
765         [System.Runtime.InteropServices.GuidAttribute ("00000000-0000-0000-0000-000000000002")]
766         [System.Runtime.InteropServices.ComImportAttribute ()]
767         [System.Runtime.InteropServices.ClassInterfaceAttribute (ClassInterfaceType.None)]
768         public class _TestClass : ITest
769         {
770                 // properties need to go first since mcs puts them there
771                 public virtual extern ITest Test
772                 {
773                         [return: MarshalAs (UnmanagedType.Interface)]
774                         [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId (5242884)]
775                         get;
776                 }
777
778                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
779                 public virtual extern void SByteIn (sbyte val);
780                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
781                 public virtual extern void ByteIn (byte val);
782                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
783                 public virtual extern void ShortIn (short val);
784                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
785                 public virtual extern void UShortIn (ushort val);
786                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
787                 public virtual extern void IntIn (int val);
788                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
789                 public virtual extern void UIntIn (uint val);
790                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
791                 public virtual extern void LongIn (long val);
792                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
793                 public virtual extern void ULongIn (ulong val);
794                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
795                 public virtual extern void FloatIn (float val);
796                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
797                 public virtual extern void DoubleIn (double val);
798                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
799                 public virtual extern void ITestIn ([MarshalAs (UnmanagedType.Interface)]ITest val);
800                 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
801                 public virtual extern void ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITest val);
802         }
803
804         [System.Runtime.InteropServices.GuidAttribute ("00000000-0000-0000-0000-000000000002")]
805         public class TestClass : _TestClass
806         {
807                 static TestClass ()
808                 {
809                         ExtensibleClassFactory.RegisterObjectCreationCallback (new ObjectCreationDelegate (CreateObject)); ;
810                 }
811                 private static System.IntPtr CreateObject (System.IntPtr aggr)
812                 {
813                         IntPtr pUnk3;
814                         mono_test_marshal_com_object_create (out pUnk3);
815                         return pUnk3;
816                 }
817         }
818
819         [System.Runtime.InteropServices.GuidAttribute ("00000000-0000-0000-0000-000000000003")]
820         public class TestActivatorClass : _TestClass
821         {
822                 static TestActivatorClass ()
823                 {
824                         ExtensibleClassFactory.RegisterObjectCreationCallback (new ObjectCreationDelegate (CreateObject)); ;
825                 }
826                 private static System.IntPtr CreateObject (System.IntPtr aggr)
827                 {
828                         IntPtr pUnk3;
829                         mono_test_marshal_com_object_create (out pUnk3);
830                         return pUnk3;
831                 }
832         }
833
834         delegate void SByteInDelegate (sbyte val);
835         delegate void ByteInDelegate (byte val);
836         delegate void ShortInDelegate (short val);
837         delegate void UShortInDelegate (ushort val);
838         delegate void IntInDelegate (int val);
839         delegate void UIntInDelegate (uint val);
840         delegate void LongInDelegate (long val);
841         delegate void ULongInDelegate (ulong val);
842         delegate void FloatInDelegate (float val);
843         delegate void DoubleInDelegate (double val);
844         delegate void ITestInDelegate (ITest val);
845         delegate void ITestOutDelegate (out ITest val);
846
847         public class ManagedTestPresSig : ITestPresSig
848         {               // properties need to go first since mcs puts them there
849                 public ITestPresSig Test
850                 {
851                         get
852                         {
853                                 return new ManagedTestPresSig ();
854                         }
855                 }
856
857                 public int SByteIn (sbyte val)
858                 {
859                         if (val != -100)
860                                 return 1;
861                         return 0;
862                 }
863
864                 public int ByteIn (byte val)
865                 {
866                         if (val != 100)
867                                 return 2;
868                         return 0;
869                 }
870
871                 public int ShortIn (short val)
872                 {
873                         if (val != -100)
874                                 return 3;
875                         return 0;
876                 }
877
878                 public int UShortIn (ushort val)
879                 {
880                         if (val != 100)
881                                 return 4;
882                         return 0;
883                 }
884
885                 public int IntIn (int val)
886                 {
887                         if (val != -100)
888                                 return 5;
889                         return 0;
890                 }
891
892                 public int UIntIn (uint val)
893                 {
894                         if (val != 100)
895                                 return 6;
896                         return 0;
897                 }
898
899                 public int LongIn (long val)
900                 {
901                         if (val != -100)
902                                 return 7;
903                         return 0;
904                 }
905
906                 public int ULongIn (ulong val)
907                 {
908                         if (val != 100)
909                                 return 8;
910                         return 0;
911                 }
912
913                 public int FloatIn (float val)
914                 {
915                         if (Math.Abs (val - 3.14f) > .000001)
916                                 return 9;
917                         return 0;
918                 }
919
920                 public int DoubleIn (double val)
921                 {
922                         if (Math.Abs (val - 3.14f) > .000001)
923                                 return 10;
924                         return 0;
925                 }
926
927                 public int ITestIn ([MarshalAs (UnmanagedType.Interface)]ITestPresSig val)
928                 {
929                         if (val == null)
930                                 return 11;
931                         if (null == val as ManagedTestPresSig)
932                                 return 12;
933                         return 0;
934                 }
935
936                 public int ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITestPresSig val)
937                 {
938                         val = new ManagedTestPresSig ();
939                         return 0;
940                 }
941         }
942
943         public class ManagedTest : ITest
944         {
945                 private int status = 0;
946                 public int Status
947                 {
948                         get { return status; }
949                 }
950                 public void SByteIn (sbyte val)
951                 {
952                         if (val != -100)
953                                 status = 1;
954                 }
955
956                 public void ByteIn (byte val)
957                 {
958                         if (val != 100)
959                                 status = 2;
960                 }
961
962                 public void ShortIn (short val)
963                 {
964                         if (val != -100)
965                                 status = 3;
966                 }
967
968                 public void UShortIn (ushort val)
969                 {
970                         if (val != 100)
971                                 status = 4;
972                 }
973
974                 public void IntIn (int val)
975                 {
976                         if (val != -100)
977                                 status = 5;
978                 }
979
980                 public void UIntIn (uint val)
981                 {
982                         if (val != 100)
983                                 status = 6;
984                 }
985
986                 public void LongIn (long val)
987                 {
988                         if (val != -100)
989                                 status = 7;
990                 }
991
992                 public void ULongIn (ulong val)
993                 {
994                         if (val != 100)
995                                 status = 8;
996                 }
997
998                 public void FloatIn (float val)
999                 {
1000                         if (Math.Abs (val - 3.14f) > .000001)
1001                                 status = 9;
1002                 }
1003
1004                 public void DoubleIn (double val)
1005                 {
1006                         if (Math.Abs (val - 3.14) > .000001)
1007                                 status = 10;
1008                 }
1009
1010                 public void ITestIn (ITest val)
1011                 {
1012                         if (val == null)
1013                                 status = 11;
1014                         if (null == val as ManagedTest)
1015                                 status = 12;
1016                 }
1017
1018                 public void ITestOut (out ITest val)
1019                 {
1020                         val = new ManagedTest ();
1021                 }
1022
1023                 public ITest Test
1024                 {
1025                         get
1026                         {
1027                                 return new ManagedTest ();
1028                         }
1029                 }
1030         }
1031
1032         public static int mono_test_marshal_variant_in_callback (VarEnum vt, object obj)
1033         {
1034                 switch (vt)
1035                 {
1036                 case VarEnum.VT_I1:
1037                         if (obj.GetType () != typeof (sbyte))
1038                                 return 1;
1039                         if ((sbyte)obj != -100)
1040                                 return 2;
1041                         break;
1042                 case VarEnum.VT_UI1:
1043                         if (obj.GetType () != typeof (byte))
1044                                 return 1;
1045                         if ((byte)obj != 100)
1046                                 return 2;
1047                         break;
1048                 case VarEnum.VT_I2:
1049                         if (obj.GetType () != typeof (short))
1050                                 return 1;
1051                         if ((short)obj != -100)
1052                                 return 2;
1053                         break;
1054                 case VarEnum.VT_UI2:
1055                         if (obj.GetType () != typeof (ushort))
1056                                 return 1;
1057                         if ((ushort)obj != 100)
1058                                 return 2;
1059                         break;
1060                 case VarEnum.VT_I4:
1061                         if (obj.GetType () != typeof (int))
1062                                 return 1;
1063                         if ((int)obj != -100)
1064                                 return 2;
1065                         break;
1066                 case VarEnum.VT_UI4:
1067                         if (obj.GetType () != typeof (uint))
1068                                 return 1;
1069                         if ((uint)obj != 100)
1070                                 return 2;
1071                         break;
1072                 case VarEnum.VT_I8:
1073                         if (obj.GetType () != typeof (long))
1074                                 return 1;
1075                         if ((long)obj != -100)
1076                                 return 2;
1077                         break;
1078                 case VarEnum.VT_UI8:
1079                         if (obj.GetType () != typeof (ulong))
1080                                 return 1;
1081                         if ((ulong)obj != 100)
1082                                 return 2;
1083                         break;
1084                 case VarEnum.VT_R4:
1085                         if (obj.GetType () != typeof (float))
1086                                 return 1;
1087                         if (Math.Abs ((float)obj - 3.14f) > 1e-10)
1088                                 return 2;
1089                         break;
1090                 case VarEnum.VT_R8:
1091                         if (obj.GetType () != typeof (double))
1092                                 return 1;
1093                         if (Math.Abs ((double)obj - 3.14) > 1e-10)
1094                                 return 2;
1095                         break;
1096                 case VarEnum.VT_BSTR:
1097                         if (obj.GetType () != typeof (string))
1098                                 return 1;
1099                         if ((string)obj != "PI")
1100                                 return 2;
1101                         break;
1102                 case VarEnum.VT_BOOL:
1103                         if (obj.GetType () != typeof (bool))
1104                                 return 1;
1105                         if ((bool)obj != true)
1106                                 return 2;
1107                         break;
1108                 }
1109                 return 0;
1110         }
1111
1112         public static int mono_test_marshal_variant_out_callback (VarEnum vt, ref object obj)
1113         {
1114                 switch (vt) {
1115                 case VarEnum.VT_I1:
1116                         obj = (sbyte)-100;
1117                         break;
1118                 case VarEnum.VT_UI1:
1119                         obj = (byte)100;
1120                         break;
1121                 case VarEnum.VT_I2:
1122                         obj = (short)-100;
1123                         break;
1124                 case VarEnum.VT_UI2:
1125                         obj = (ushort)100;
1126                         break;
1127                 case VarEnum.VT_I4:
1128                         obj = (int)-100;
1129                         break;
1130                 case VarEnum.VT_UI4:
1131                         obj = (uint)100;
1132                         break;
1133                 case VarEnum.VT_I8:
1134                         obj = (long)-100;
1135                         break;
1136                 case VarEnum.VT_UI8:
1137                         obj = (ulong)100;
1138                         break;
1139                 case VarEnum.VT_R4:
1140                         obj = (float)3.14f;
1141                         break;
1142                 case VarEnum.VT_R8:
1143                         obj = (double)3.14;
1144                         break;
1145                 case VarEnum.VT_BSTR:
1146                         obj = "PI";
1147                         break;
1148                 case VarEnum.VT_BOOL:
1149                         obj = true;
1150                         break;
1151                 }
1152                 return 0;
1153         }
1154
1155         public static int TestITest (ITest itest)
1156         {
1157                 try {
1158                         ITest itest2;
1159                         itest.SByteIn (-100);
1160                         itest.ByteIn (100);
1161                         itest.ShortIn (-100);
1162                         itest.UShortIn (100);
1163                         itest.IntIn (-100);
1164                         itest.UIntIn (100);
1165                         itest.LongIn (-100);
1166                         itest.ULongIn (100);
1167                         itest.FloatIn (3.14f);
1168                         itest.DoubleIn (3.14);
1169                         itest.ITestIn (itest);
1170                         itest.ITestOut (out itest2);
1171                 }
1172                 catch (Exception ex) {
1173                         return 1;
1174                 }
1175                 return 0;
1176         }
1177
1178         public static int TestITestPresSig (ITestPresSig itest)
1179         {
1180                 ITestPresSig itest2;
1181                 if (itest.SByteIn (-100) != 0)
1182                         return 1000;
1183                 if (itest.ByteIn (100) != 0)
1184                         return 1001;
1185                 if (itest.ShortIn (-100) != 0)
1186                         return 1002;
1187                 if (itest.UShortIn (100) != 0)
1188                         return 1003;
1189                 if (itest.IntIn (-100) != 0)
1190                         return 1004;
1191                 if (itest.UIntIn (100) != 0)
1192                         return 1005;
1193                 if (itest.LongIn (-100) != 0)
1194                         return 1006;
1195                 if (itest.ULongIn (100) != 0)
1196                         return 1007;
1197                 if (itest.FloatIn (3.14f) != 0)
1198                         return 1008;
1199                 if (itest.DoubleIn (3.14) != 0)
1200                         return 1009;
1201                 if (itest.ITestIn (itest) != 0)
1202                         return 1010;
1203                 if (itest.ITestOut (out itest2) != 0)
1204                         return 1011;
1205                 return 0;
1206         }
1207
1208         public static int TestITestDelegate (ITest itest)
1209         {
1210                 try {
1211                         ITest itest2;
1212
1213                         SByteInDelegate SByteInFcn= itest.SByteIn;
1214                         ByteInDelegate ByteInFcn = itest.ByteIn;
1215                         UShortInDelegate UShortInFcn = itest.UShortIn;
1216                         IntInDelegate IntInFcn = itest.IntIn;
1217                         UIntInDelegate UIntInFcn = itest.UIntIn;
1218                         LongInDelegate LongInFcn = itest.LongIn;
1219
1220                         ULongInDelegate ULongInFcn = itest.ULongIn;
1221                         FloatInDelegate FloatInFcn = itest.FloatIn;
1222                         DoubleInDelegate DoubleInFcn = itest.DoubleIn;
1223                         ITestInDelegate ITestInFcn = itest.ITestIn;
1224                         ITestOutDelegate ITestOutFcn = itest.ITestOut;
1225
1226                         SByteInFcn (-100);
1227                         ByteInFcn (100);
1228                         UShortInFcn (100);
1229                         IntInFcn (-100);
1230                         UIntInFcn (100);
1231                         LongInFcn (-100);
1232                         ULongInFcn (100);
1233                         FloatInFcn (3.14f);
1234                         DoubleInFcn (3.14);
1235                         ITestInFcn (itest);
1236                         ITestOutFcn (out itest2);
1237                 }
1238                 catch (Exception) {
1239                         return 1;
1240                 }
1241                 return 0;
1242         }
1243 }
1244
1245 public class TestVisible
1246 {
1247 }