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