4 // Tests for COM Interop related features
8 using System
.Runtime
.CompilerServices
;
9 using System
.Runtime
.InteropServices
;
15 [DllImport("libtest")]
16 public static extern int mono_test_marshal_bstr_in([MarshalAs(UnmanagedType
.BStr
)]string str
);
18 [DllImport("libtest")]
19 public static extern int mono_test_marshal_bstr_out([MarshalAs(UnmanagedType
.BStr
)] out string str
);
21 [DllImport("libtest")]
22 public static extern int mono_test_marshal_bstr_in_null([MarshalAs(UnmanagedType
.BStr
)]string str
);
24 [DllImport("libtest")]
25 public static extern int mono_test_marshal_bstr_out_null([MarshalAs(UnmanagedType
.BStr
)] out string str
);
27 [DllImport("libtest")]
28 public static extern int mono_test_marshal_variant_in_sbyte([MarshalAs(UnmanagedType
.Struct
)]object obj
);
30 [DllImport("libtest")]
31 public static extern int mono_test_marshal_variant_in_byte([MarshalAs(UnmanagedType
.Struct
)]object obj
);
33 [DllImport("libtest")]
34 public static extern int mono_test_marshal_variant_in_short([MarshalAs(UnmanagedType
.Struct
)]object obj
);
36 [DllImport("libtest")]
37 public static extern int mono_test_marshal_variant_in_ushort([MarshalAs(UnmanagedType
.Struct
)]object obj
);
39 [DllImport("libtest")]
40 public static extern int mono_test_marshal_variant_in_int([MarshalAs(UnmanagedType
.Struct
)]object obj
);
42 [DllImport("libtest")]
43 public static extern int mono_test_marshal_variant_in_uint([MarshalAs(UnmanagedType
.Struct
)]object obj
);
45 [DllImport("libtest")]
46 public static extern int mono_test_marshal_variant_in_long([MarshalAs(UnmanagedType
.Struct
)]object obj
);
48 [DllImport("libtest")]
49 public static extern int mono_test_marshal_variant_in_ulong([MarshalAs(UnmanagedType
.Struct
)]object obj
);
51 [DllImport("libtest")]
52 public static extern int mono_test_marshal_variant_in_float([MarshalAs(UnmanagedType
.Struct
)]object obj
);
54 [DllImport("libtest")]
55 public static extern int mono_test_marshal_variant_in_double([MarshalAs(UnmanagedType
.Struct
)]object obj
);
57 [DllImport("libtest")]
58 public static extern int mono_test_marshal_variant_in_bstr ([MarshalAs (UnmanagedType
.Struct
)]object obj
);
60 [DllImport ("libtest")]
61 public static extern int mono_test_marshal_variant_in_bool_true ([MarshalAs (UnmanagedType
.Struct
)]object obj
);
63 [DllImport ("libtest")]
64 public static extern int mono_test_marshal_variant_in_bool_false ([MarshalAs (UnmanagedType
.Struct
)]object obj
);
66 [DllImport("libtest")]
67 public static extern int mono_test_marshal_variant_out_sbyte([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
69 [DllImport("libtest")]
70 public static extern int mono_test_marshal_variant_out_sbyte_byref([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
72 [DllImport("libtest")]
73 public static extern int mono_test_marshal_variant_out_byte([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
75 [DllImport("libtest")]
76 public static extern int mono_test_marshal_variant_out_byte_byref([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
78 [DllImport("libtest")]
79 public static extern int mono_test_marshal_variant_out_short([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
81 [DllImport("libtest")]
82 public static extern int mono_test_marshal_variant_out_short_byref([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
84 [DllImport("libtest")]
85 public static extern int mono_test_marshal_variant_out_ushort([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
87 [DllImport("libtest")]
88 public static extern int mono_test_marshal_variant_out_ushort_byref([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
90 [DllImport("libtest")]
91 public static extern int mono_test_marshal_variant_out_int([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
93 [DllImport("libtest")]
94 public static extern int mono_test_marshal_variant_out_int_byref([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
96 [DllImport("libtest")]
97 public static extern int mono_test_marshal_variant_out_uint([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
99 [DllImport("libtest")]
100 public static extern int mono_test_marshal_variant_out_uint_byref([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
102 [DllImport("libtest")]
103 public static extern int mono_test_marshal_variant_out_long([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
105 [DllImport("libtest")]
106 public static extern int mono_test_marshal_variant_out_long_byref([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
108 [DllImport("libtest")]
109 public static extern int mono_test_marshal_variant_out_ulong([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
111 [DllImport("libtest")]
112 public static extern int mono_test_marshal_variant_out_ulong_byref([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
114 [DllImport("libtest")]
115 public static extern int mono_test_marshal_variant_out_float([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
117 [DllImport("libtest")]
118 public static extern int mono_test_marshal_variant_out_float_byref([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
120 [DllImport("libtest")]
121 public static extern int mono_test_marshal_variant_out_double([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
123 [DllImport("libtest")]
124 public static extern int mono_test_marshal_variant_out_double_byref([MarshalAs(UnmanagedType
.Struct
)]out object obj
);
126 [DllImport("libtest")]
127 public static extern int mono_test_marshal_variant_out_bstr ([MarshalAs (UnmanagedType
.Struct
)]out object obj
);
129 [DllImport("libtest")]
130 public static extern int mono_test_marshal_variant_out_bstr_byref ([MarshalAs (UnmanagedType
.Struct
)]out object obj
);
132 [DllImport("libtest")]
133 public static extern int mono_test_marshal_variant_out_bool_true ([MarshalAs (UnmanagedType
.Struct
)]out object obj
);
135 [DllImport("libtest")]
136 public static extern int mono_test_marshal_variant_out_bool_true_byref ([MarshalAs (UnmanagedType
.Struct
)]out object obj
);
138 [DllImport ("libtest")]
139 public static extern int mono_test_marshal_variant_out_bool_false ([MarshalAs (UnmanagedType
.Struct
)]out object obj
);
141 [DllImport ("libtest")]
142 public static extern int mono_test_marshal_variant_out_bool_false_byref ([MarshalAs (UnmanagedType
.Struct
)]out object obj
);
145 public delegate int VarFunc (VarEnum vt
, [MarshalAs (UnmanagedType
.Struct
)] object obj
);
147 public delegate int VarRefFunc (VarEnum vt
, [MarshalAs (UnmanagedType
.Struct
)] ref object obj
);
149 [DllImport ("libtest")]
150 public static extern int mono_test_marshal_variant_in_sbyte_unmanaged (VarFunc func
);
152 [DllImport ("libtest")]
153 public static extern int mono_test_marshal_variant_in_byte_unmanaged (VarFunc func
);
155 [DllImport ("libtest")]
156 public static extern int mono_test_marshal_variant_in_short_unmanaged (VarFunc func
);
158 [DllImport ("libtest")]
159 public static extern int mono_test_marshal_variant_in_ushort_unmanaged (VarFunc func
);
161 [DllImport ("libtest")]
162 public static extern int mono_test_marshal_variant_in_int_unmanaged (VarFunc func
);
164 [DllImport ("libtest")]
165 public static extern int mono_test_marshal_variant_in_uint_unmanaged (VarFunc func
);
167 [DllImport ("libtest")]
168 public static extern int mono_test_marshal_variant_in_long_unmanaged (VarFunc func
);
170 [DllImport ("libtest")]
171 public static extern int mono_test_marshal_variant_in_ulong_unmanaged (VarFunc func
);
173 [DllImport ("libtest")]
174 public static extern int mono_test_marshal_variant_in_float_unmanaged (VarFunc func
);
176 [DllImport ("libtest")]
177 public static extern int mono_test_marshal_variant_in_double_unmanaged (VarFunc func
);
179 [DllImport ("libtest")]
180 public static extern int mono_test_marshal_variant_in_bstr_unmanaged (VarFunc func
);
182 [DllImport ("libtest")]
183 public static extern int mono_test_marshal_variant_in_bool_true_unmanaged (VarFunc func
);
185 [DllImport ("libtest")]
186 public static extern int mono_test_marshal_variant_in_bool_false_unmanaged (VarFunc func
);
188 [DllImport ("libtest")]
189 public static extern int mono_test_marshal_variant_out_sbyte_unmanaged (VarRefFunc func
);
191 [DllImport ("libtest")]
192 public static extern int mono_test_marshal_variant_out_byte_unmanaged (VarRefFunc func
);
194 [DllImport ("libtest")]
195 public static extern int mono_test_marshal_variant_out_short_unmanaged (VarRefFunc func
);
197 [DllImport ("libtest")]
198 public static extern int mono_test_marshal_variant_out_ushort_unmanaged (VarRefFunc func
);
200 [DllImport ("libtest")]
201 public static extern int mono_test_marshal_variant_out_int_unmanaged (VarRefFunc func
);
203 [DllImport ("libtest")]
204 public static extern int mono_test_marshal_variant_out_uint_unmanaged (VarRefFunc func
);
206 [DllImport ("libtest")]
207 public static extern int mono_test_marshal_variant_out_long_unmanaged (VarRefFunc func
);
209 [DllImport ("libtest")]
210 public static extern int mono_test_marshal_variant_out_ulong_unmanaged (VarRefFunc func
);
212 [DllImport ("libtest")]
213 public static extern int mono_test_marshal_variant_out_float_unmanaged (VarRefFunc func
);
215 [DllImport ("libtest")]
216 public static extern int mono_test_marshal_variant_out_double_unmanaged (VarRefFunc func
);
218 [DllImport ("libtest")]
219 public static extern int mono_test_marshal_variant_out_bstr_unmanaged (VarRefFunc func
);
221 [DllImport ("libtest")]
222 public static extern int mono_test_marshal_variant_out_bool_true_unmanaged (VarRefFunc func
);
224 [DllImport ("libtest")]
225 public static extern int mono_test_marshal_variant_out_bool_false_unmanaged (VarRefFunc func
);
227 [DllImport ("libtest")]
228 public static extern int mono_test_marshal_com_object_create (out IntPtr pUnk
);
230 [DllImport ("libtest")]
231 public static extern int mono_test_marshal_com_object_same (out IntPtr pUnk
);
233 [DllImport ("libtest")]
234 public static extern int mono_test_marshal_com_object_destroy (IntPtr pUnk
);
236 [DllImport ("libtest")]
237 public static extern int mono_test_marshal_com_object_ref_count (IntPtr pUnk
);
239 [DllImport ("libtest")]
240 public static extern int mono_test_marshal_ccw_identity ([MarshalAs (UnmanagedType
.Interface
)]ITest itest
);
242 [DllImport ("libtest")]
243 public static extern int mono_test_marshal_ccw_reflexive ([MarshalAs (UnmanagedType
.Interface
)]ITest itest
);
245 [DllImport ("libtest")]
246 public static extern int mono_test_marshal_ccw_transitive ([MarshalAs (UnmanagedType
.Interface
)]ITest itest
);
248 [DllImport ("libtest")]
249 public static extern int mono_test_marshal_ccw_itest ([MarshalAs (UnmanagedType
.Interface
)]ITest itest
);
251 [DllImport ("libtest")]
252 public static extern int mono_test_marshal_ccw_itest ([MarshalAs (UnmanagedType
.Interface
)]ITestPresSig itest
);
254 [DllImport("libtest")]
255 public static extern int mono_test_marshal_safearray_out_1dim_vt_bstr_empty ([MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)]out Array array
);
257 [DllImport("libtest")]
258 public static extern int mono_test_marshal_safearray_out_1dim_vt_bstr ([MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)]out Array array
);
260 [DllImport("libtest")]
261 public static extern int mono_test_marshal_safearray_out_2dim_vt_i4 ([MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)]out Array array
);
263 [DllImport("libtest")]
264 public static extern int mono_test_marshal_safearray_out_4dim_vt_i4 ([MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)]out Array array
);
266 [DllImport("libtest")]
267 public static extern int mono_test_marshal_safearray_in_byval_1dim_empty ([In
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] Array array
);
269 [DllImport("libtest")]
270 public static extern int mono_test_marshal_safearray_in_byval_1dim_vt_i4 ([In
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] Array array
);
272 [DllImport("libtest")]
273 public static extern int mono_test_marshal_safearray_in_byval_1dim_vt_mixed ([In
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] Array array
);
275 [DllImport("libtest")]
276 public static extern int mono_test_marshal_safearray_in_byval_2dim_vt_i4 ([In
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] Array array
);
278 [DllImport("libtest")]
279 public static extern int mono_test_marshal_safearray_in_byval_3dim_vt_bstr ([In
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] Array array
);
281 [DllImport("libtest")]
282 public static extern int mono_test_marshal_safearray_in_byref_3dim_vt_bstr ([In
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] ref Array array
);
284 [DllImport("libtest")]
285 public static extern int mono_test_marshal_safearray_in_out_byref_1dim_empty ([In
, Out
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] ref Array array
);
287 [DllImport("libtest")]
288 public static extern int mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr ([In
, Out
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] ref Array array
);
290 [DllImport("libtest")]
291 public static extern int mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 ([In
, Out
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] ref Array array
);
293 [DllImport("libtest")]
294 public static extern int mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 ([In
, Out
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] Array array
);
296 [DllImport("libtest")]
297 public static extern int mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr ([In
, Out
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] Array array
);
299 [DllImport("libtest")]
300 public static extern int mono_test_marshal_safearray_mixed (
301 [In
, Out
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] Array array1
,
302 [MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] out Array array2
,
303 [In
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] Array array3
,
304 [In
, Out
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] ref Array array4
);
306 [DllImport("libtest")]
307 public static extern bool mono_cominterop_is_supported ();
309 public static int Main ()
312 bool isWindows
= !(((int)Environment
.OSVersion
.Platform
== 4) ||
313 ((int)Environment
.OSVersion
.Platform
== 128));
315 if (mono_cominterop_is_supported () || isWindows
)
320 if (mono_test_marshal_bstr_in ("mono_test_marshal_bstr_in") != 0)
322 if (mono_test_marshal_bstr_out (out str
) != 0 || str
!= "mono_test_marshal_bstr_out")
324 if (mono_test_marshal_bstr_in_null (null) != 0)
326 if (mono_test_marshal_bstr_out_null (out str
) != 0 || str
!= null)
329 #endregion // BSTR Tests
331 #region VARIANT Tests
334 if (mono_test_marshal_variant_in_sbyte ((sbyte)100) != 0)
336 if (mono_test_marshal_variant_in_byte ((byte)100) != 0)
338 if (mono_test_marshal_variant_in_short ((short)314) != 0)
340 if (mono_test_marshal_variant_in_ushort ((ushort)314) != 0)
342 if (mono_test_marshal_variant_in_int ((int)314) != 0)
344 if (mono_test_marshal_variant_in_uint ((uint)314) != 0)
346 if (mono_test_marshal_variant_in_long ((long)314) != 0)
348 if (mono_test_marshal_variant_in_ulong ((ulong)314) != 0)
350 if (mono_test_marshal_variant_in_float ((float)3.14) != 0)
352 if (mono_test_marshal_variant_in_double ((double)3.14) != 0)
354 if (mono_test_marshal_variant_in_bstr ("PI") != 0)
356 if (mono_test_marshal_variant_out_sbyte (out obj
) != 0 || (sbyte)obj
!= 100)
358 if (mono_test_marshal_variant_out_byte (out obj
) != 0 || (byte)obj
!= 100)
360 if (mono_test_marshal_variant_out_short (out obj
) != 0 || (short)obj
!= 314)
362 if (mono_test_marshal_variant_out_ushort (out obj
) != 0 || (ushort)obj
!= 314)
364 if (mono_test_marshal_variant_out_int (out obj
) != 0 || (int)obj
!= 314)
366 if (mono_test_marshal_variant_out_uint (out obj
) != 0 || (uint)obj
!= 314)
368 if (mono_test_marshal_variant_out_long (out obj
) != 0 || (long)obj
!= 314)
370 if (mono_test_marshal_variant_out_ulong (out obj
) != 0 || (ulong)obj
!= 314)
372 if (mono_test_marshal_variant_out_float (out obj
) != 0 || ((float)obj
- 3.14) / 3.14 > .001)
374 if (mono_test_marshal_variant_out_double (out obj
) != 0 || ((double)obj
- 3.14) / 3.14 > .001)
376 if (mono_test_marshal_variant_out_bstr (out obj
) != 0 || (string)obj
!= "PI")
379 VarFunc func
= new VarFunc (mono_test_marshal_variant_in_callback
);
380 if (mono_test_marshal_variant_in_sbyte_unmanaged (func
) != 0)
382 if (mono_test_marshal_variant_in_byte_unmanaged (func
) != 0)
384 if (mono_test_marshal_variant_in_short_unmanaged (func
) != 0)
386 if (mono_test_marshal_variant_in_ushort_unmanaged (func
) != 0)
388 if (mono_test_marshal_variant_in_int_unmanaged (func
) != 0)
390 if (mono_test_marshal_variant_in_uint_unmanaged (func
) != 0)
392 if (mono_test_marshal_variant_in_long_unmanaged (func
) != 0)
394 if (mono_test_marshal_variant_in_ulong_unmanaged (func
) != 0)
396 if (mono_test_marshal_variant_in_float_unmanaged (func
) != 0)
398 if (mono_test_marshal_variant_in_double_unmanaged (func
) != 0)
400 if (mono_test_marshal_variant_in_bstr_unmanaged (func
) != 0)
402 if (mono_test_marshal_variant_in_bool_true_unmanaged (func
) != 0)
405 VarRefFunc reffunc
= new VarRefFunc (mono_test_marshal_variant_out_callback
);
406 if (mono_test_marshal_variant_out_sbyte_unmanaged (reffunc
) != 0)
408 if (mono_test_marshal_variant_out_byte_unmanaged (reffunc
) != 0)
410 if (mono_test_marshal_variant_out_short_unmanaged (reffunc
) != 0)
412 if (mono_test_marshal_variant_out_ushort_unmanaged (reffunc
) != 0)
414 if (mono_test_marshal_variant_out_int_unmanaged (reffunc
) != 0)
416 if (mono_test_marshal_variant_out_uint_unmanaged (reffunc
) != 0)
418 if (mono_test_marshal_variant_out_long_unmanaged (reffunc
) != 0)
420 if (mono_test_marshal_variant_out_ulong_unmanaged (reffunc
) != 0)
422 if (mono_test_marshal_variant_out_float_unmanaged (reffunc
) != 0)
424 if (mono_test_marshal_variant_out_double_unmanaged (reffunc
) != 0)
426 if (mono_test_marshal_variant_out_bstr_unmanaged (reffunc
) != 0)
428 if (mono_test_marshal_variant_out_bool_true_unmanaged (reffunc
) != 0)
431 if (mono_test_marshal_variant_out_sbyte_byref (out obj
) != 0 || (sbyte)obj
!= 100)
433 if (mono_test_marshal_variant_out_byte_byref (out obj
) != 0 || (byte)obj
!= 100)
435 if (mono_test_marshal_variant_out_short_byref (out obj
) != 0 || (short)obj
!= 314)
437 if (mono_test_marshal_variant_out_ushort_byref (out obj
) != 0 || (ushort)obj
!= 314)
439 if (mono_test_marshal_variant_out_int_byref (out obj
) != 0 || (int)obj
!= 314)
441 if (mono_test_marshal_variant_out_uint_byref (out obj
) != 0 || (uint)obj
!= 314)
443 if (mono_test_marshal_variant_out_long_byref (out obj
) != 0 || (long)obj
!= 314)
445 if (mono_test_marshal_variant_out_ulong_byref (out obj
) != 0 || (ulong)obj
!= 314)
447 if (mono_test_marshal_variant_out_float_byref (out obj
) != 0 || ((float)obj
- 3.14) / 3.14 > .001)
449 if (mono_test_marshal_variant_out_double_byref (out obj
) != 0 || ((double)obj
- 3.14) / 3.14 > .001)
451 if (mono_test_marshal_variant_out_bstr_byref (out obj
) != 0 || (string)obj
!= "PI")
454 #endregion // VARIANT Tests
456 #region Runtime Callable Wrapper Tests
459 if (mono_test_marshal_com_object_create (out pUnk
) != 0)
462 if (mono_test_marshal_com_object_ref_count (pUnk
) != 1)
465 if (Marshal
.AddRef (pUnk
) != 2)
468 if (mono_test_marshal_com_object_ref_count (pUnk
) != 2)
471 if (Marshal
.Release (pUnk
) != 1)
474 if (mono_test_marshal_com_object_ref_count (pUnk
) != 1)
477 object com_obj
= Marshal
.GetObjectForIUnknown (pUnk
);
482 ITest itest
= com_obj
as ITest
;
488 if (mono_test_marshal_com_object_same (out pUnk2
) != 0)
491 object com_obj2
= Marshal
.GetObjectForIUnknown (pUnk2
);
493 if (com_obj
!= com_obj2
)
496 if (!com_obj
.Equals (com_obj2
))
500 if (mono_test_marshal_com_object_create (out pUnk3
) != 0)
503 object com_obj3
= Marshal
.GetObjectForIUnknown (pUnk3
);
504 if (com_obj
== com_obj3
)
507 if (com_obj
.Equals (com_obj3
))
510 // com_obj & com_obj2 share a RCW
511 if (Marshal
.ReleaseComObject (com_obj2
) != 1)
514 // com_obj3 should only have one RCW
515 if (Marshal
.ReleaseComObject (com_obj3
) != 0)
518 IntPtr iunknown
= Marshal
.GetIUnknownForObject (com_obj
);
519 if (iunknown
== IntPtr
.Zero
)
522 if (pUnk
!= iunknown
)
525 if (TestITest (itest
) != 0)
528 if (TestITestPresSig (itest
as ITestPresSig
) != 0)
531 if (TestITestDelegate (itest
) != 0)
534 itest
= new TestClass ();
536 if (TestITest (itest
) != 0)
539 itest
= (ITest
)System
.Activator
.CreateInstance (typeof(TestActivatorClass
));
541 if (TestITest (itest
) != 0)
544 #endregion // Runtime Callable Wrapper Tests
546 #region COM Callable Wrapper Tests
548 ManagedTest test
= new ManagedTest ();
550 mono_test_marshal_ccw_itest (test
);
552 if (test
.Status
!= 0)
555 ManagedTestPresSig test_pres_sig
= new ManagedTestPresSig ();
557 mono_test_marshal_ccw_itest (test_pres_sig
);
559 #endregion // COM Callable Wrapper Tests
561 #region SAFEARRAY tests
568 if ((mono_test_marshal_safearray_out_1dim_vt_bstr_empty (out array
) != 0) || (array
.Rank
!= 1) || (array
.Length
!= 0))
571 if ((mono_test_marshal_safearray_out_1dim_vt_bstr (out array
) != 0) || (array
.Rank
!= 1) || (array
.Length
!= 10))
573 for (int i
= 0; i
< 10; ++i
) {
574 if (i
!= Convert
.ToInt32 (array
.GetValue (i
)))
578 if ((mono_test_marshal_safearray_out_2dim_vt_i4 (out array
) != 0) || (array
.Rank
!= 2))
580 if ( (array
.GetLowerBound (0) != 0) || (array
.GetUpperBound (0) != 3)
581 || (array
.GetLowerBound (1) != 0) || (array
.GetUpperBound (1) != 2))
583 for (int i
= array
.GetLowerBound (0); i
<= array
.GetUpperBound (0); ++i
)
585 for (int j
= array
.GetLowerBound (1); j
<= array
.GetUpperBound (1); ++j
) {
586 if ((i
+ 1) * 10 + (j
+ 1) != (int)array
.GetValue (new long[] { i, j }
))
591 if ((mono_test_marshal_safearray_out_4dim_vt_i4 (out array
) != 0) || (array
.Rank
!= 4))
593 if ( (array
.GetLowerBound (0) != 15) || (array
.GetUpperBound (0) != 24)
594 || (array
.GetLowerBound (1) != 20) || (array
.GetUpperBound (1) != 22)
595 || (array
.GetLowerBound (2) != 5) || (array
.GetUpperBound (2) != 10)
596 || (array
.GetLowerBound (3) != 12) || (array
.GetUpperBound (3) != 18) )
600 for (int i
= array
.GetLowerBound (3); i
<= array
.GetUpperBound (3); ++i
) {
601 for (int j
= array
.GetLowerBound (2); j
<= array
.GetUpperBound (2); ++j
) {
602 for (int k
= array
.GetLowerBound (1); k
<= array
.GetUpperBound (1); ++k
) {
603 for (int l
= array
.GetLowerBound (0); l
<= array
.GetUpperBound (0); ++l
) {
604 if (index
!= (int)array
.GetValue (new long[] { l, k, j, i }
))
614 array
= new object[] { }
;
615 if (mono_test_marshal_safearray_in_byval_1dim_empty (array
) != 0)
618 array
= new object[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
;
619 if (mono_test_marshal_safearray_in_byval_1dim_vt_i4 (array
) != 0)
622 array
= new object[] { 0, "1", 2, "3", 4, "5", 6, "7", 8, "9", 10, "11", 12 }
;
623 if (mono_test_marshal_safearray_in_byval_1dim_vt_mixed (array
) != 0)
625 if ((int)array
.GetValue (0) != 0)
628 array
= new object[,] { { 11, 12, 13, 14 }
, { 21, 22, 23, 24 }
};
629 if (mono_test_marshal_safearray_in_byval_2dim_vt_i4 (array
) != 0)
631 if ((int)array
.GetValue (new int[] { 0, 0 }
) != 11)
634 array
= new object[,,] { { { "111", "112", "113" }
, { "121", "122", "123" }
}, { { "211", "212", "213" }
, { "221", "222", "223" }
} };
635 if (mono_test_marshal_safearray_in_byval_3dim_vt_bstr (array
) != 0)
637 if ((string)array
.GetValue (new int[] { 0, 0, 0 }
) != "111")
640 array
= new object[,,] { { { "111", "112", "113" }
, { "121", "122", "123" }
}, { { "211", "212", "213" }
, { "221", "222", "223" }
} };
641 if ((mono_test_marshal_safearray_in_byref_3dim_vt_bstr (ref array
) != 0) || (array
.Rank
!= 3) || (array
.Length
!= 12))
643 if ((string)array
.GetValue (new int[] { 0, 0, 0 }
) != "111")
648 array
= new object[] { }
;
649 if ((mono_test_marshal_safearray_in_out_byref_1dim_empty (ref array
) != 0) || (array
.Rank
!= 1) || (array
.Length
!= 8))
651 for (int i
= 0; i
< 8; ++i
)
653 if (i
!= Convert
.ToInt32 (array
.GetValue (i
)))
657 array
= new object[,,] { { { "111", "112", "113" }
, { "121", "122", "123" }
}, { { "211", "212", "213" }
, { "221", "222", "223" }
} };
658 if ((mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr (ref array
) != 0) || (array
.Rank
!= 1) || (array
.Length
!= 8))
660 for (int i
= 0; i
< 8; ++i
)
662 if (i
!= Convert
.ToInt32 (array
.GetValue (i
)))
666 array
= new object[] { 1 }
;
667 if ((mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 (ref array
) != 0) || (array
.Rank
!= 1) || (array
.Length
!= 1))
671 if (Convert
.ToInt32 (array
.GetValue (0)) != -1)
676 array
= new object[] { 1 }
;
677 if ((mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (array
) != 0) || (array
.Rank
!= 1) || (array
.Length
!= 1))
681 if (Convert
.ToInt32 (array
.GetValue (0)) != 12345)
684 array
= new object[,,] { { { "111", "112", "113" }
, { "121", "122", "123" }
}, { { "211", "212", "213" }
, { "221", "222", "223" }
} };
685 if ((mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr (array
) != 0) || (array
.Rank
!= 3) || (array
.Length
!= 12))
689 if (Convert
.ToInt32 (array
.GetValue (new int[] { 1, 1, 1 }
)) != 111)
691 if (Convert
.ToInt32 (array
.GetValue (new int[] { 1, 1, 2 }
)) != 333)
693 if (Convert
.ToString(array
.GetValue (new int[] { 0, 1, 0 }
)) != "ABCDEFG")
696 /* Multiple safearray parameters with various types and options */
698 Array array1
= new object[] { 1 }
;
699 Array array2
= new object[,] { { 11, 12, 13, 14 }
, { 21, 22, 23, 24 }
};
700 Array array3
= new object[] { 0, "1", 2, "3", 4, "5", 6, "7", 8, "9", 10, "11", 12 }
;
701 Array array4
= new object[,,] { { { "111", "112", "113" }
, { "121", "122", "123" }
}, { { "211", "212", "213" }
, { "221", "222", "223" }
} };
702 if ( (mono_test_marshal_safearray_mixed (array1
, out array2
, array3
, ref array4
) != 0)
703 || (array1
.Rank
!= 1) || (array1
.Length
!= 1) || (Convert
.ToInt32 (array1
.GetValue (0)) != 12345)
704 || (array2
.Rank
!= 1) || (array2
.Length
!= 10)
705 || (array4
.Rank
!= 1) || (array4
.Length
!= 8)
710 for (int i
= 0; i
< 10; ++i
)
712 if (i
!= Convert
.ToInt32 (array2
.GetValue (i
)))
715 if ((int)array3
.GetValue (0) != 0)
717 for (int i
= 0; i
< 8; ++i
)
719 if (i
!= Convert
.ToInt32 (array4
.GetValue (i
)))
723 #endregion // SafeArray Tests
725 #region COM Visible Test
726 TestVisible test_vis
= new TestVisible();
727 IntPtr pDisp
= Marshal
.GetIDispatchForObject(test_vis
);
728 if (pDisp
== IntPtr
.Zero
)
738 [Guid ("00000000-0000-0000-0000-000000000001")]
739 [InterfaceType (ComInterfaceType
.InterfaceIsIUnknown
)]
740 public interface ITest
742 // properties need to go first since mcs puts them there
745 [return: MarshalAs (UnmanagedType
.Interface
)]
746 [MethodImpl (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
), DispId (5242884)]
750 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
751 void SByteIn (sbyte val
);
752 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
753 void ByteIn (byte val
);
754 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
755 void ShortIn (short val
);
756 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
757 void UShortIn (ushort val
);
758 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
759 void IntIn (int val
);
760 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
761 void UIntIn (uint val
);
762 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
763 void LongIn (long val
);
764 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
765 void ULongIn (ulong val
);
766 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
767 void FloatIn (float val
);
768 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
769 void DoubleIn (double val
);
770 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
771 void ITestIn ([MarshalAs (UnmanagedType
.Interface
)]ITest val
);
772 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
773 void ITestOut ([MarshalAs (UnmanagedType
.Interface
)]out ITest val
);
777 [Guid ("00000000-0000-0000-0000-000000000001")]
778 [InterfaceType (ComInterfaceType
.InterfaceIsIUnknown
)]
779 public interface ITestPresSig
781 // properties need to go first since mcs puts them there
784 [return: MarshalAs (UnmanagedType
.Interface
)]
785 [MethodImpl (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
), DispId (5242884)]
789 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
791 int SByteIn (sbyte val
);
792 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
794 int ByteIn (byte val
);
795 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
797 int ShortIn (short val
);
798 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
800 int UShortIn (ushort val
);
801 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
804 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
806 int UIntIn (uint val
);
807 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
809 int LongIn (long val
);
810 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
812 int ULongIn (ulong val
);
813 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
815 int FloatIn (float val
);
816 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
818 int DoubleIn (double val
);
819 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
821 int ITestIn ([MarshalAs (UnmanagedType
.Interface
)]ITestPresSig val
);
822 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
824 int ITestOut ([MarshalAs (UnmanagedType
.Interface
)]out ITestPresSig val
);
827 [System
.Runtime
.InteropServices
.GuidAttribute ("00000000-0000-0000-0000-000000000002")]
828 [System
.Runtime
.InteropServices
.ComImportAttribute ()]
829 [System
.Runtime
.InteropServices
.ClassInterfaceAttribute (ClassInterfaceType
.None
)]
830 public class _TestClass
: ITest
832 // properties need to go first since mcs puts them there
833 public virtual extern ITest Test
835 [return: MarshalAs (UnmanagedType
.Interface
)]
836 [MethodImpl (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
), DispId (5242884)]
840 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
841 public virtual extern void SByteIn (sbyte val
);
842 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
843 public virtual extern void ByteIn (byte val
);
844 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
845 public virtual extern void ShortIn (short val
);
846 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
847 public virtual extern void UShortIn (ushort val
);
848 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
849 public virtual extern void IntIn (int val
);
850 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
851 public virtual extern void UIntIn (uint val
);
852 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
853 public virtual extern void LongIn (long val
);
854 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
855 public virtual extern void ULongIn (ulong val
);
856 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
857 public virtual extern void FloatIn (float val
);
858 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
859 public virtual extern void DoubleIn (double val
);
860 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
861 public virtual extern void ITestIn ([MarshalAs (UnmanagedType
.Interface
)]ITest val
);
862 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
863 public virtual extern void ITestOut ([MarshalAs (UnmanagedType
.Interface
)]out ITest val
);
866 [System
.Runtime
.InteropServices
.GuidAttribute ("00000000-0000-0000-0000-000000000002")]
867 public class TestClass
: _TestClass
871 ExtensibleClassFactory
.RegisterObjectCreationCallback (new ObjectCreationDelegate (CreateObject
)); ;
873 private static System
.IntPtr
CreateObject (System
.IntPtr aggr
)
876 mono_test_marshal_com_object_create (out pUnk3
);
881 [System
.Runtime
.InteropServices
.GuidAttribute ("00000000-0000-0000-0000-000000000003")]
882 public class TestActivatorClass
: _TestClass
884 static TestActivatorClass ()
886 ExtensibleClassFactory
.RegisterObjectCreationCallback (new ObjectCreationDelegate (CreateObject
)); ;
888 private static System
.IntPtr
CreateObject (System
.IntPtr aggr
)
891 mono_test_marshal_com_object_create (out pUnk3
);
896 delegate void SByteInDelegate (sbyte val
);
897 delegate void ByteInDelegate (byte val
);
898 delegate void ShortInDelegate (short val
);
899 delegate void UShortInDelegate (ushort val
);
900 delegate void IntInDelegate (int val
);
901 delegate void UIntInDelegate (uint val
);
902 delegate void LongInDelegate (long val
);
903 delegate void ULongInDelegate (ulong val
);
904 delegate void FloatInDelegate (float val
);
905 delegate void DoubleInDelegate (double val
);
906 delegate void ITestInDelegate (ITest val
);
907 delegate void ITestOutDelegate (out ITest val
);
909 public class ManagedTestPresSig
: ITestPresSig
910 { // properties need to go first since mcs puts them there
911 public ITestPresSig Test
915 return new ManagedTestPresSig ();
919 public int SByteIn (sbyte val
)
926 public int ByteIn (byte val
)
933 public int ShortIn (short val
)
940 public int UShortIn (ushort val
)
947 public int IntIn (int val
)
954 public int UIntIn (uint val
)
961 public int LongIn (long val
)
968 public int ULongIn (ulong val
)
975 public int FloatIn (float val
)
977 if (Math
.Abs (val
- 3.14f
) > .000001)
982 public int DoubleIn (double val
)
984 if (Math
.Abs (val
- 3.14f
) > .000001)
989 public int ITestIn ([MarshalAs (UnmanagedType
.Interface
)]ITestPresSig val
)
993 if (null == val
as ManagedTestPresSig
)
998 public int ITestOut ([MarshalAs (UnmanagedType
.Interface
)]out ITestPresSig val
)
1000 val
= new ManagedTestPresSig ();
1005 public class ManagedTest
: ITest
1007 private int status
= 0;
1010 get { return status; }
1012 public void SByteIn (sbyte val
)
1018 public void ByteIn (byte val
)
1024 public void ShortIn (short val
)
1030 public void UShortIn (ushort val
)
1036 public void IntIn (int val
)
1042 public void UIntIn (uint val
)
1048 public void LongIn (long val
)
1054 public void ULongIn (ulong val
)
1060 public void FloatIn (float val
)
1062 if (Math
.Abs (val
- 3.14f
) > .000001)
1066 public void DoubleIn (double val
)
1068 if (Math
.Abs (val
- 3.14) > .000001)
1072 public void ITestIn (ITest val
)
1076 if (null == val
as ManagedTest
)
1080 public void ITestOut (out ITest val
)
1082 val
= new ManagedTest ();
1089 return new ManagedTest ();
1094 public static int mono_test_marshal_variant_in_callback (VarEnum vt
, object obj
)
1099 if (obj
.GetType () != typeof (sbyte))
1101 if ((sbyte)obj
!= -100)
1104 case VarEnum
.VT_UI1
:
1105 if (obj
.GetType () != typeof (byte))
1107 if ((byte)obj
!= 100)
1111 if (obj
.GetType () != typeof (short))
1113 if ((short)obj
!= -100)
1116 case VarEnum
.VT_UI2
:
1117 if (obj
.GetType () != typeof (ushort))
1119 if ((ushort)obj
!= 100)
1123 if (obj
.GetType () != typeof (int))
1125 if ((int)obj
!= -100)
1128 case VarEnum
.VT_UI4
:
1129 if (obj
.GetType () != typeof (uint))
1131 if ((uint)obj
!= 100)
1135 if (obj
.GetType () != typeof (long))
1137 if ((long)obj
!= -100)
1140 case VarEnum
.VT_UI8
:
1141 if (obj
.GetType () != typeof (ulong))
1143 if ((ulong)obj
!= 100)
1147 if (obj
.GetType () != typeof (float))
1149 if (Math
.Abs ((float)obj
- 3.14f
) > 1e-10)
1153 if (obj
.GetType () != typeof (double))
1155 if (Math
.Abs ((double)obj
- 3.14) > 1e-10)
1158 case VarEnum
.VT_BSTR
:
1159 if (obj
.GetType () != typeof (string))
1161 if ((string)obj
!= "PI")
1164 case VarEnum
.VT_BOOL
:
1165 if (obj
.GetType () != typeof (bool))
1167 if ((bool)obj
!= true)
1174 public static int mono_test_marshal_variant_out_callback (VarEnum vt
, ref object obj
)
1180 case VarEnum
.VT_UI1
:
1186 case VarEnum
.VT_UI2
:
1192 case VarEnum
.VT_UI4
:
1198 case VarEnum
.VT_UI8
:
1207 case VarEnum
.VT_BSTR
:
1210 case VarEnum
.VT_BOOL
:
1217 public static int TestITest (ITest itest
)
1221 itest
.SByteIn (-100);
1223 itest
.ShortIn (-100);
1224 itest
.UShortIn (100);
1227 itest
.LongIn (-100);
1228 itest
.ULongIn (100);
1229 itest
.FloatIn (3.14f
);
1230 itest
.DoubleIn (3.14);
1231 itest
.ITestIn (itest
);
1232 itest
.ITestOut (out itest2
);
1234 catch (Exception ex
) {
1240 public static int TestITestPresSig (ITestPresSig itest
)
1242 ITestPresSig itest2
;
1243 if (itest
.SByteIn (-100) != 0)
1245 if (itest
.ByteIn (100) != 0)
1247 if (itest
.ShortIn (-100) != 0)
1249 if (itest
.UShortIn (100) != 0)
1251 if (itest
.IntIn (-100) != 0)
1253 if (itest
.UIntIn (100) != 0)
1255 if (itest
.LongIn (-100) != 0)
1257 if (itest
.ULongIn (100) != 0)
1259 if (itest
.FloatIn (3.14f
) != 0)
1261 if (itest
.DoubleIn (3.14) != 0)
1263 if (itest
.ITestIn (itest
) != 0)
1265 if (itest
.ITestOut (out itest2
) != 0)
1270 public static int TestITestDelegate (ITest itest
)
1275 SByteInDelegate SByteInFcn
= itest
.SByteIn
;
1276 ByteInDelegate ByteInFcn
= itest
.ByteIn
;
1277 UShortInDelegate UShortInFcn
= itest
.UShortIn
;
1278 IntInDelegate IntInFcn
= itest
.IntIn
;
1279 UIntInDelegate UIntInFcn
= itest
.UIntIn
;
1280 LongInDelegate LongInFcn
= itest
.LongIn
;
1282 ULongInDelegate ULongInFcn
= itest
.ULongIn
;
1283 FloatInDelegate FloatInFcn
= itest
.FloatIn
;
1284 DoubleInDelegate DoubleInFcn
= itest
.DoubleIn
;
1285 ITestInDelegate ITestInFcn
= itest
.ITestIn
;
1286 ITestOutDelegate ITestOutFcn
= itest
.ITestOut
;
1298 ITestOutFcn (out itest2
);
1307 public class TestVisible