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", EntryPoint
="mono_test_marshal_ccw_itest")]
255 public static extern int mono_test_marshal_ccw_itest_nomarshal (ITest itest
);
257 [DllImport ("libtest", EntryPoint
="mono_test_marshal_ccw_itest")]
258 public static extern int mono_test_marshal_ccw_itest_nomarshal (ITestPresSig itest
);
260 [DllImport ("libtest")]
261 public static extern int mono_test_marshal_array_ccw_itest (int count
, [MarshalAs (UnmanagedType
.LPArray
, SizeParamIndex
=0)] ITest
[] ppUnk
);
263 [DllImport ("libtest")]
264 public static extern int mono_test_marshal_retval_ccw_itest ([MarshalAs (UnmanagedType
.Interface
)]ITest itest
, bool test_null
);
266 [DllImport ("libtest")]
267 public static extern int mono_test_marshal_retval_ccw_itest ([MarshalAs (UnmanagedType
.Interface
)]ITestPresSig itest
, bool test_null
);
269 [DllImport("libtest")]
270 public static extern int mono_test_cominterop_ccw_queryinterface ([MarshalAs (UnmanagedType
.Interface
)] IOtherTest itest
);
272 [DllImport("libtest")]
273 public static extern int mono_test_marshal_safearray_out_1dim_vt_bstr_empty ([MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)]out Array array
);
275 [DllImport("libtest")]
276 public static extern int mono_test_marshal_safearray_out_1dim_vt_bstr ([MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)]out Array array
);
278 [DllImport("libtest")]
279 public static extern int mono_test_marshal_safearray_out_2dim_vt_i4 ([MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)]out Array array
);
281 [DllImport("libtest")]
282 public static extern int mono_test_marshal_safearray_out_4dim_vt_i4 ([MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)]out Array array
);
284 [DllImport("libtest")]
285 public static extern int mono_test_marshal_safearray_in_byval_1dim_empty ([In
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] Array array
);
287 [DllImport("libtest")]
288 public static extern int mono_test_marshal_safearray_in_byval_1dim_vt_i4 ([In
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] Array array
);
290 [DllImport("libtest")]
291 public static extern int mono_test_marshal_safearray_in_byval_1dim_vt_mixed ([In
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] Array array
);
293 [DllImport("libtest")]
294 public static extern int mono_test_marshal_safearray_in_byval_2dim_vt_i4 ([In
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] Array array
);
296 [DllImport("libtest")]
297 public static extern int mono_test_marshal_safearray_in_byval_3dim_vt_bstr ([In
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] Array array
);
299 [DllImport("libtest")]
300 public static extern int mono_test_marshal_safearray_in_byref_3dim_vt_bstr ([In
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] ref Array array
);
302 [DllImport("libtest")]
303 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
);
305 [DllImport("libtest")]
306 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
);
308 [DllImport("libtest")]
309 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
);
311 [DllImport("libtest")]
312 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
);
314 [DllImport("libtest")]
315 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
);
317 [DllImport("libtest")]
318 public static extern int mono_test_marshal_safearray_mixed (
319 [In
, Out
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] Array array1
,
320 [MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] out Array array2
,
321 [In
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] Array array3
,
322 [In
, Out
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] ref Array array4
);
324 [DllImport("libtest")]
325 public static extern int mono_test_marshal_safearray_in_ccw([MarshalAs (UnmanagedType
.Interface
)] ITest itest
);
327 [DllImport("libtest")]
328 public static extern int mono_test_default_interface_ccw([MarshalAs (UnmanagedType
.Interface
)] ITest itest
);
330 [DllImport("libtest")]
331 public static extern bool mono_cominterop_is_supported ();
333 public static int Main ()
336 bool isWindows
= !(((int)Environment
.OSVersion
.Platform
== 4) ||
337 ((int)Environment
.OSVersion
.Platform
== 128));
339 if (mono_cominterop_is_supported () || isWindows
)
344 if (mono_test_marshal_bstr_in ("mono_test_marshal_bstr_in") != 0)
346 if (mono_test_marshal_bstr_out (out str
) != 0 || str
!= "mono_test_marshal_bstr_out")
348 if (mono_test_marshal_bstr_in_null (null) != 0)
350 if (mono_test_marshal_bstr_out_null (out str
) != 0 || str
!= null)
353 #endregion // BSTR Tests
355 #region VARIANT Tests
358 if (mono_test_marshal_variant_in_sbyte ((sbyte)100) != 0)
360 if (mono_test_marshal_variant_in_byte ((byte)100) != 0)
362 if (mono_test_marshal_variant_in_short ((short)314) != 0)
364 if (mono_test_marshal_variant_in_ushort ((ushort)314) != 0)
366 if (mono_test_marshal_variant_in_int ((int)314) != 0)
368 if (mono_test_marshal_variant_in_uint ((uint)314) != 0)
370 if (mono_test_marshal_variant_in_long ((long)314) != 0)
372 if (mono_test_marshal_variant_in_ulong ((ulong)314) != 0)
374 if (mono_test_marshal_variant_in_float ((float)3.14) != 0)
376 if (mono_test_marshal_variant_in_double ((double)3.14) != 0)
378 if (mono_test_marshal_variant_in_bstr ("PI") != 0)
380 if (mono_test_marshal_variant_out_sbyte (out obj
) != 0 || (sbyte)obj
!= 100)
382 if (mono_test_marshal_variant_out_byte (out obj
) != 0 || (byte)obj
!= 100)
384 if (mono_test_marshal_variant_out_short (out obj
) != 0 || (short)obj
!= 314)
386 if (mono_test_marshal_variant_out_ushort (out obj
) != 0 || (ushort)obj
!= 314)
388 if (mono_test_marshal_variant_out_int (out obj
) != 0 || (int)obj
!= 314)
390 if (mono_test_marshal_variant_out_uint (out obj
) != 0 || (uint)obj
!= 314)
392 if (mono_test_marshal_variant_out_long (out obj
) != 0 || (long)obj
!= 314)
394 if (mono_test_marshal_variant_out_ulong (out obj
) != 0 || (ulong)obj
!= 314)
396 if (mono_test_marshal_variant_out_float (out obj
) != 0 || ((float)obj
- 3.14) / 3.14 > .001)
398 if (mono_test_marshal_variant_out_double (out obj
) != 0 || ((double)obj
- 3.14) / 3.14 > .001)
400 if (mono_test_marshal_variant_out_bstr (out obj
) != 0 || (string)obj
!= "PI")
403 VarFunc func
= new VarFunc (mono_test_marshal_variant_in_callback
);
404 if (mono_test_marshal_variant_in_sbyte_unmanaged (func
) != 0)
406 if (mono_test_marshal_variant_in_byte_unmanaged (func
) != 0)
408 if (mono_test_marshal_variant_in_short_unmanaged (func
) != 0)
410 if (mono_test_marshal_variant_in_ushort_unmanaged (func
) != 0)
412 if (mono_test_marshal_variant_in_int_unmanaged (func
) != 0)
414 if (mono_test_marshal_variant_in_uint_unmanaged (func
) != 0)
416 if (mono_test_marshal_variant_in_long_unmanaged (func
) != 0)
418 if (mono_test_marshal_variant_in_ulong_unmanaged (func
) != 0)
420 if (mono_test_marshal_variant_in_float_unmanaged (func
) != 0)
422 if (mono_test_marshal_variant_in_double_unmanaged (func
) != 0)
424 if (mono_test_marshal_variant_in_bstr_unmanaged (func
) != 0)
426 if (mono_test_marshal_variant_in_bool_true_unmanaged (func
) != 0)
429 VarRefFunc reffunc
= new VarRefFunc (mono_test_marshal_variant_out_callback
);
430 if (mono_test_marshal_variant_out_sbyte_unmanaged (reffunc
) != 0)
432 if (mono_test_marshal_variant_out_byte_unmanaged (reffunc
) != 0)
434 if (mono_test_marshal_variant_out_short_unmanaged (reffunc
) != 0)
436 if (mono_test_marshal_variant_out_ushort_unmanaged (reffunc
) != 0)
438 if (mono_test_marshal_variant_out_int_unmanaged (reffunc
) != 0)
440 if (mono_test_marshal_variant_out_uint_unmanaged (reffunc
) != 0)
442 if (mono_test_marshal_variant_out_long_unmanaged (reffunc
) != 0)
444 if (mono_test_marshal_variant_out_ulong_unmanaged (reffunc
) != 0)
446 if (mono_test_marshal_variant_out_float_unmanaged (reffunc
) != 0)
448 if (mono_test_marshal_variant_out_double_unmanaged (reffunc
) != 0)
450 if (mono_test_marshal_variant_out_bstr_unmanaged (reffunc
) != 0)
452 if (mono_test_marshal_variant_out_bool_true_unmanaged (reffunc
) != 0)
455 if (mono_test_marshal_variant_out_sbyte_byref (out obj
) != 0 || (sbyte)obj
!= 100)
457 if (mono_test_marshal_variant_out_byte_byref (out obj
) != 0 || (byte)obj
!= 100)
459 if (mono_test_marshal_variant_out_short_byref (out obj
) != 0 || (short)obj
!= 314)
461 if (mono_test_marshal_variant_out_ushort_byref (out obj
) != 0 || (ushort)obj
!= 314)
463 if (mono_test_marshal_variant_out_int_byref (out obj
) != 0 || (int)obj
!= 314)
465 if (mono_test_marshal_variant_out_uint_byref (out obj
) != 0 || (uint)obj
!= 314)
467 if (mono_test_marshal_variant_out_long_byref (out obj
) != 0 || (long)obj
!= 314)
469 if (mono_test_marshal_variant_out_ulong_byref (out obj
) != 0 || (ulong)obj
!= 314)
471 if (mono_test_marshal_variant_out_float_byref (out obj
) != 0 || ((float)obj
- 3.14) / 3.14 > .001)
473 if (mono_test_marshal_variant_out_double_byref (out obj
) != 0 || ((double)obj
- 3.14) / 3.14 > .001)
475 if (mono_test_marshal_variant_out_bstr_byref (out obj
) != 0 || (string)obj
!= "PI")
478 #endregion // VARIANT Tests
480 #region Runtime Callable Wrapper Tests
485 if (mono_test_marshal_com_object_create (out pUnk
) != 0)
488 if (mono_test_marshal_com_object_ref_count (pUnk
) != 1)
491 if (Marshal
.AddRef (pUnk
) != 2)
494 if (mono_test_marshal_com_object_ref_count (pUnk
) != 2)
497 if (Marshal
.Release (pUnk
) != 1)
500 if (mono_test_marshal_com_object_ref_count (pUnk
) != 1)
503 object com_obj
= Marshal
.GetObjectForIUnknown (pUnk
);
508 ITest itest
= com_obj
as ITest
;
514 if (mono_test_marshal_com_object_same (out pUnk2
) != 0)
517 object com_obj2
= Marshal
.GetObjectForIUnknown (pUnk2
);
519 if (com_obj
!= com_obj2
)
522 if (!com_obj
.Equals (com_obj2
))
526 if (mono_test_marshal_com_object_create (out pUnk3
) != 0)
529 object com_obj3
= Marshal
.GetObjectForIUnknown (pUnk3
);
530 if (com_obj
== com_obj3
)
533 if (com_obj
.Equals (com_obj3
))
536 // com_obj & com_obj2 share a RCW
537 if (Marshal
.ReleaseComObject (com_obj2
) != 1)
540 // com_obj3 should only have one RCW
541 if (Marshal
.ReleaseComObject (com_obj3
) != 0)
544 IntPtr iunknown
= Marshal
.GetIUnknownForObject (com_obj
);
545 if (iunknown
== IntPtr
.Zero
)
548 if (pUnk
!= iunknown
)
551 if (TestITest (itest
) != 0)
554 if (TestITestPresSig (itest
as ITestPresSig
) != 0)
557 if (TestITestDelegate (itest
) != 0)
560 if (TestIfaceNoIcall (itest
as ITestPresSig
) != 0)
563 itest
= new TestClass ();
565 if (TestITest (itest
) != 0)
568 itest
= (ITest
)System
.Activator
.CreateInstance (typeof(TestActivatorClass
));
570 if (TestITest (itest
) != 0)
575 #endregion // Runtime Callable Wrapper Tests
577 #region COM Callable Wrapper Tests
579 ManagedTest test
= new ManagedTest ();
581 mono_test_marshal_ccw_itest (test
);
582 mono_test_marshal_ccw_itest_nomarshal (test
);
584 if (test
.Status
!= 0)
587 ManagedTestPresSig test_pres_sig
= new ManagedTestPresSig ();
589 mono_test_marshal_ccw_itest (test_pres_sig
);
590 mono_test_marshal_ccw_itest_nomarshal (test_pres_sig
);
592 // test for Xamarin-47560
593 var tests
= new[] { test.Test }
;
594 if (mono_test_marshal_array_ccw_itest (1, tests
) != 0)
597 var otherTest
= new OtherTest ();
598 if (mono_test_cominterop_ccw_queryinterface (otherTest
) != 0)
601 if (mono_test_marshal_retval_ccw_itest(test
, true) != 0)
604 /* Passing NULL to an out parameter will crash. */
605 if (mono_test_marshal_retval_ccw_itest(test_pres_sig
, false) != 0)
608 if (mono_test_default_interface_ccw(test
) != 0)
611 #endregion // COM Callable Wrapper Tests
613 #region SAFEARRAY tests
619 if ((mono_test_marshal_safearray_out_1dim_vt_bstr_empty (out array
) != 0) || (array
.Rank
!= 1) || (array
.Length
!= 0))
622 if ((mono_test_marshal_safearray_out_1dim_vt_bstr (out array
) != 0) || (array
.Rank
!= 1) || (array
.Length
!= 10))
624 for (int i
= 0; i
< 10; ++i
) {
625 if (i
!= Convert
.ToInt32 (array
.GetValue (i
)))
629 if ((mono_test_marshal_safearray_out_2dim_vt_i4 (out array
) != 0) || (array
.Rank
!= 2))
631 if ( (array
.GetLowerBound (0) != 0) || (array
.GetUpperBound (0) != 3)
632 || (array
.GetLowerBound (1) != 0) || (array
.GetUpperBound (1) != 2))
634 for (int i
= array
.GetLowerBound (0); i
<= array
.GetUpperBound (0); ++i
)
636 for (int j
= array
.GetLowerBound (1); j
<= array
.GetUpperBound (1); ++j
) {
637 if ((i
+ 1) * 10 + (j
+ 1) != (int)array
.GetValue (new long[] { i, j }
))
642 if ((mono_test_marshal_safearray_out_4dim_vt_i4 (out array
) != 0) || (array
.Rank
!= 4))
644 if ( (array
.GetLowerBound (0) != 15) || (array
.GetUpperBound (0) != 24)
645 || (array
.GetLowerBound (1) != 20) || (array
.GetUpperBound (1) != 22)
646 || (array
.GetLowerBound (2) != 5) || (array
.GetUpperBound (2) != 10)
647 || (array
.GetLowerBound (3) != 12) || (array
.GetUpperBound (3) != 18) )
651 for (int i
= array
.GetLowerBound (3); i
<= array
.GetUpperBound (3); ++i
) {
652 for (int j
= array
.GetLowerBound (2); j
<= array
.GetUpperBound (2); ++j
) {
653 for (int k
= array
.GetLowerBound (1); k
<= array
.GetUpperBound (1); ++k
) {
654 for (int l
= array
.GetLowerBound (0); l
<= array
.GetUpperBound (0); ++l
) {
655 if (index
!= (int)array
.GetValue (new long[] { l, k, j, i }
))
665 array
= new object[] { }
;
666 if (mono_test_marshal_safearray_in_byval_1dim_empty (array
) != 0)
669 array
= new object[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
;
670 if (mono_test_marshal_safearray_in_byval_1dim_vt_i4 (array
) != 0)
673 array
= new object[] { 0, "1", 2, "3", 4, "5", 6, "7", 8, "9", 10, "11", 12 }
;
674 if (mono_test_marshal_safearray_in_byval_1dim_vt_mixed (array
) != 0)
676 if ((int)array
.GetValue (0) != 0)
679 array
= new object[,] { { 11, 12, 13, 14 }
, { 21, 22, 23, 24 }
};
680 if (mono_test_marshal_safearray_in_byval_2dim_vt_i4 (array
) != 0)
682 if ((int)array
.GetValue (new int[] { 0, 0 }
) != 11)
685 array
= new object[,,] { { { "111", "112", "113" }
, { "121", "122", "123" }
}, { { "211", "212", "213" }
, { "221", "222", "223" }
} };
686 if (mono_test_marshal_safearray_in_byval_3dim_vt_bstr (array
) != 0)
688 if ((string)array
.GetValue (new int[] { 0, 0, 0 }
) != "111")
691 array
= new object[,,] { { { "111", "112", "113" }
, { "121", "122", "123" }
}, { { "211", "212", "213" }
, { "221", "222", "223" }
} };
692 if ((mono_test_marshal_safearray_in_byref_3dim_vt_bstr (ref array
) != 0) || (array
.Rank
!= 3) || (array
.Length
!= 12))
694 if ((string)array
.GetValue (new int[] { 0, 0, 0 }
) != "111")
699 array
= new object[] { }
;
700 if ((mono_test_marshal_safearray_in_out_byref_1dim_empty (ref array
) != 0) || (array
.Rank
!= 1) || (array
.Length
!= 8))
702 for (int i
= 0; i
< 8; ++i
)
704 if (i
!= Convert
.ToInt32 (array
.GetValue (i
)))
708 array
= new object[,,] { { { "111", "112", "113" }
, { "121", "122", "123" }
}, { { "211", "212", "213" }
, { "221", "222", "223" }
} };
709 if ((mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr (ref array
) != 0) || (array
.Rank
!= 1) || (array
.Length
!= 8))
711 for (int i
= 0; i
< 8; ++i
)
713 if (i
!= Convert
.ToInt32 (array
.GetValue (i
)))
717 array
= new object[] { 1 }
;
718 if ((mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 (ref array
) != 0) || (array
.Rank
!= 1) || (array
.Length
!= 1))
722 if (Convert
.ToInt32 (array
.GetValue (0)) != -1)
727 array
= new object[] { 1 }
;
728 if ((mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (array
) != 0) || (array
.Rank
!= 1) || (array
.Length
!= 1))
732 if (Convert
.ToInt32 (array
.GetValue (0)) != 12345)
735 array
= new object[,,] { { { "111", "112", "113" }
, { "121", "122", "123" }
}, { { "211", "212", "213" }
, { "221", "222", "223" }
} };
736 if ((mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr (array
) != 0) || (array
.Rank
!= 3) || (array
.Length
!= 12))
740 if (Convert
.ToInt32 (array
.GetValue (new int[] { 1, 1, 1 }
)) != 111)
742 if (Convert
.ToInt32 (array
.GetValue (new int[] { 1, 1, 2 }
)) != 333)
744 if (Convert
.ToString(array
.GetValue (new int[] { 0, 1, 0 }
)) != "ABCDEFG")
747 /* Multiple safearray parameters with various types and options */
749 Array array1
= new object[] { 1 }
;
750 Array array2
= new object[,] { { 11, 12, 13, 14 }
, { 21, 22, 23, 24 }
};
751 Array array3
= new object[] { 0, "1", 2, "3", 4, "5", 6, "7", 8, "9", 10, "11", 12 }
;
752 Array array4
= new object[,,] { { { "111", "112", "113" }
, { "121", "122", "123" }
}, { { "211", "212", "213" }
, { "221", "222", "223" }
} };
753 if ( (mono_test_marshal_safearray_mixed (array1
, out array2
, array3
, ref array4
) != 0)
754 || (array1
.Rank
!= 1) || (array1
.Length
!= 1) || (Convert
.ToInt32 (array1
.GetValue (0)) != 12345)
755 || (array2
.Rank
!= 1) || (array2
.Length
!= 10)
756 || (array4
.Rank
!= 1) || (array4
.Length
!= 8)
761 for (int i
= 0; i
< 10; ++i
)
763 if (i
!= Convert
.ToInt32 (array2
.GetValue (i
)))
766 if ((int)array3
.GetValue (0) != 0)
768 for (int i
= 0; i
< 8; ++i
)
770 if (i
!= Convert
.ToInt32 (array4
.GetValue (i
)))
773 if (mono_test_marshal_safearray_in_ccw(test
) != 0)
776 #endregion // SafeArray Tests
778 #region COM Visible Test
779 TestVisible test_vis
= new TestVisible();
780 IntPtr pDisp
= Marshal
.GetIDispatchForObject(test_vis
);
781 if (pDisp
== IntPtr
.Zero
)
790 [Guid ("10000000-0000-0000-0000-000000000002")]
791 [InterfaceType (ComInterfaceType
.InterfaceIsIUnknown
)]
792 public interface IDefTest1
794 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
799 [Guid ("10000000-0000-0000-0000-000000000003")]
800 [InterfaceType (ComInterfaceType
.InterfaceIsIUnknown
)]
801 public interface IDefTest2
803 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
807 public class TestDefaultInterfaceClass
: IDefTest1
, IDefTest2
830 [ComDefaultInterfaceAttribute (typeof (IDefTest1
))]
831 public class TestDefaultInterfaceClass1
: TestDefaultInterfaceClass
835 [ComDefaultInterfaceAttribute (typeof (IDefTest2
))]
836 public class TestDefaultInterfaceClass2
: TestDefaultInterfaceClass
841 [Guid ("00000000-0000-0000-0000-000000000001")]
842 [InterfaceType (ComInterfaceType
.InterfaceIsIUnknown
)]
843 public interface ITest
845 // properties need to go first since mcs puts them there
848 [return: MarshalAs (UnmanagedType
.Interface
)]
849 [MethodImpl (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
), DispId (5242884)]
853 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
854 void SByteIn (sbyte val
);
855 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
856 void ByteIn (byte val
);
857 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
858 void ShortIn (short val
);
859 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
860 void UShortIn (ushort val
);
861 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
862 void IntIn (int val
);
863 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
864 void UIntIn (uint val
);
865 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
866 void LongIn (long val
);
867 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
868 void ULongIn (ulong val
);
869 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
870 void FloatIn (float val
);
871 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
872 void DoubleIn (double val
);
873 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
874 void ITestIn ([MarshalAs (UnmanagedType
.Interface
)]ITest val
);
875 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
876 void ITestOut ([MarshalAs (UnmanagedType
.Interface
)]out ITest val
);
877 int Return22NoICall();
878 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
880 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
881 void ArrayIn ([In
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] object[] array
);
882 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
883 void ArrayIn2 ([In
] object[] array
);
884 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
885 void ArrayIn3 (object[] array
);
886 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
887 [return: MarshalAs (UnmanagedType
.Interface
)]
888 TestDefaultInterfaceClass1
GetDefInterface1();
889 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
890 [return: MarshalAs (UnmanagedType
.Interface
)]
891 TestDefaultInterfaceClass2
GetDefInterface2();
895 [Guid ("00000000-0000-0000-0000-000000000001")]
896 [InterfaceType (ComInterfaceType
.InterfaceIsIUnknown
)]
897 public interface ITestPresSig
899 // properties need to go first since mcs puts them there
902 [return: MarshalAs (UnmanagedType
.Interface
)]
903 [MethodImpl (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
), DispId (5242884)]
907 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
909 int SByteIn (sbyte val
);
910 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
912 int ByteIn (byte val
);
913 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
915 int ShortIn (short val
);
916 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
918 int UShortIn (ushort val
);
919 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
922 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
924 int UIntIn (uint val
);
925 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
927 int LongIn (long val
);
928 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
930 int ULongIn (ulong val
);
931 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
933 int FloatIn (float val
);
934 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
936 int DoubleIn (double val
);
937 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
939 int ITestIn ([MarshalAs (UnmanagedType
.Interface
)]ITestPresSig val
);
940 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
942 int ITestOut ([MarshalAs (UnmanagedType
.Interface
)]out ITestPresSig val
);
944 int Return22NoICall();
945 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
947 int IntOut (out int val
);
948 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
949 int ArrayIn ([In
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] object[] array
);
950 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
951 int ArrayIn2 ([In
] object[] array
);
952 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
953 int ArrayIn3 (object[] array
);
956 [System
.Runtime
.InteropServices
.GuidAttribute ("00000000-0000-0000-0000-000000000002")]
957 [System
.Runtime
.InteropServices
.ComImportAttribute ()]
958 [System
.Runtime
.InteropServices
.ClassInterfaceAttribute (ClassInterfaceType
.None
)]
959 public class _TestClass
: ITest
961 // properties need to go first since mcs puts them there
962 public virtual extern ITest Test
964 [return: MarshalAs (UnmanagedType
.Interface
)]
965 [MethodImpl (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
), DispId (5242884)]
969 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
970 public virtual extern void SByteIn (sbyte val
);
971 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
972 public virtual extern void ByteIn (byte val
);
973 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
974 public virtual extern void ShortIn (short val
);
975 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
976 public virtual extern void UShortIn (ushort val
);
977 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
978 public virtual extern void IntIn (int val
);
979 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
980 public virtual extern void UIntIn (uint val
);
981 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
982 public virtual extern void LongIn (long val
);
983 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
984 public virtual extern void ULongIn (ulong val
);
985 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
986 public virtual extern void FloatIn (float val
);
987 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
988 public virtual extern void DoubleIn (double val
);
989 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
990 public virtual extern void ITestIn ([MarshalAs (UnmanagedType
.Interface
)]ITest val
);
991 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
992 public virtual extern void ITestOut ([MarshalAs (UnmanagedType
.Interface
)]out ITest val
);
993 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
994 public virtual extern int Return22NoICall();
995 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
996 public virtual extern int IntOut();
997 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
998 public virtual extern void ArrayIn ([In
, MarshalAs (UnmanagedType
.SafeArray
, SafeArraySubType
= VarEnum
.VT_VARIANT
)] object[] array
);
999 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
1000 public virtual extern void ArrayIn2 ([In
] object[] array
);
1001 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
1002 public virtual extern void ArrayIn3 (object[] array
);
1003 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
1004 public virtual extern TestDefaultInterfaceClass1
GetDefInterface1();
1005 [MethodImplAttribute (MethodImplOptions
.InternalCall
, MethodCodeType
= MethodCodeType
.Runtime
)]
1006 public virtual extern TestDefaultInterfaceClass2
GetDefInterface2();
1009 [System
.Runtime
.InteropServices
.GuidAttribute ("00000000-0000-0000-0000-000000000002")]
1010 public class TestClass
: _TestClass
1014 ExtensibleClassFactory
.RegisterObjectCreationCallback (new ObjectCreationDelegate (CreateObject
)); ;
1016 private static System
.IntPtr
CreateObject (System
.IntPtr aggr
)
1019 mono_test_marshal_com_object_create (out pUnk3
);
1024 [System
.Runtime
.InteropServices
.GuidAttribute ("00000000-0000-0000-0000-000000000003")]
1025 public class TestActivatorClass
: _TestClass
1027 static TestActivatorClass ()
1029 ExtensibleClassFactory
.RegisterObjectCreationCallback (new ObjectCreationDelegate (CreateObject
)); ;
1031 private static System
.IntPtr
CreateObject (System
.IntPtr aggr
)
1034 mono_test_marshal_com_object_create (out pUnk3
);
1039 delegate void SByteInDelegate (sbyte val
);
1040 delegate void ByteInDelegate (byte val
);
1041 delegate void ShortInDelegate (short val
);
1042 delegate void UShortInDelegate (ushort val
);
1043 delegate void IntInDelegate (int val
);
1044 delegate void UIntInDelegate (uint val
);
1045 delegate void LongInDelegate (long val
);
1046 delegate void ULongInDelegate (ulong val
);
1047 delegate void FloatInDelegate (float val
);
1048 delegate void DoubleInDelegate (double val
);
1049 delegate void ITestInDelegate (ITest val
);
1050 delegate void ITestOutDelegate (out ITest val
);
1052 public class ManagedTestPresSig
: ITestPresSig
1053 { // properties need to go first since mcs puts them there
1054 public ITestPresSig Test
1058 return new ManagedTestPresSig ();
1062 public int SByteIn (sbyte val
)
1069 public int ByteIn (byte val
)
1076 public int ShortIn (short val
)
1083 public int UShortIn (ushort val
)
1090 public int IntIn (int val
)
1097 public int UIntIn (uint val
)
1104 public int LongIn (long val
)
1111 public int ULongIn (ulong val
)
1118 public int FloatIn (float val
)
1120 if (Math
.Abs (val
- 3.14f
) > .000001)
1125 public int DoubleIn (double val
)
1127 if (Math
.Abs (val
- 3.14f
) > .000001)
1132 public int ITestIn ([MarshalAs (UnmanagedType
.Interface
)]ITestPresSig val
)
1136 if (null == val
as ManagedTestPresSig
)
1141 public int ITestOut ([MarshalAs (UnmanagedType
.Interface
)]out ITestPresSig val
)
1143 val
= new ManagedTestPresSig ();
1147 public int Return22NoICall()
1152 public int IntOut(out int val
)
1158 public int ArrayIn(object[] array
)
1160 if (array
.Length
!= 2)
1162 if (array
.Rank
!= 1)
1164 if (array
.GetLowerBound(0) != 0)
1166 if (array
.GetUpperBound(0) != 1)
1168 if (array
[0] is string)
1170 if ((array
[0] as string) != "Test")
1175 if (array
[1] is int)
1177 if ((int)array
[1] != 2345)
1186 public int ArrayIn2(object[] array
)
1188 return ArrayIn(array
);
1191 public int ArrayIn3(object[] array
)
1193 return ArrayIn(array
);
1197 public class ManagedTest
: ITest
1199 private int status
= 0;
1202 get { return status; }
1204 public void SByteIn (sbyte val
)
1210 public void ByteIn (byte val
)
1216 public void ShortIn (short val
)
1222 public void UShortIn (ushort val
)
1228 public void IntIn (int val
)
1234 public void UIntIn (uint val
)
1240 public void LongIn (long val
)
1246 public void ULongIn (ulong val
)
1252 public void FloatIn (float val
)
1254 if (Math
.Abs (val
- 3.14f
) > .000001)
1258 public void DoubleIn (double val
)
1260 if (Math
.Abs (val
- 3.14) > .000001)
1264 public void ITestIn (ITest val
)
1268 if (null == val
as ManagedTest
)
1272 public void ITestOut (out ITest val
)
1274 val
= new ManagedTest ();
1281 return new ManagedTest ();
1285 public int Return22NoICall()
1295 public void ArrayIn(object[] array
)
1297 if (array
.Length
!= 2)
1299 else if (array
.Rank
!= 1)
1301 else if (array
.GetLowerBound(0) != 0)
1303 else if (array
.GetUpperBound(0) != 1)
1305 else if (array
[0] is string)
1307 if ((array
[0] as string) != "Test")
1310 else if (array
[1] is int)
1312 if ((int)array
[1] != 2345)
1319 public void ArrayIn2(object[] array
)
1324 public void ArrayIn3(object[] array
)
1329 public TestDefaultInterfaceClass1
GetDefInterface1()
1331 return new TestDefaultInterfaceClass1();
1334 public TestDefaultInterfaceClass2
GetDefInterface2()
1336 return new TestDefaultInterfaceClass2();
1341 public interface IOtherTest
1345 public class OtherTest
: IOtherTest
1349 public static int mono_test_marshal_variant_in_callback (VarEnum vt
, object obj
)
1354 if (obj
.GetType () != typeof (sbyte))
1356 if ((sbyte)obj
!= -100)
1359 case VarEnum
.VT_UI1
:
1360 if (obj
.GetType () != typeof (byte))
1362 if ((byte)obj
!= 100)
1366 if (obj
.GetType () != typeof (short))
1368 if ((short)obj
!= -100)
1371 case VarEnum
.VT_UI2
:
1372 if (obj
.GetType () != typeof (ushort))
1374 if ((ushort)obj
!= 100)
1378 if (obj
.GetType () != typeof (int))
1380 if ((int)obj
!= -100)
1383 case VarEnum
.VT_UI4
:
1384 if (obj
.GetType () != typeof (uint))
1386 if ((uint)obj
!= 100)
1390 if (obj
.GetType () != typeof (long))
1392 if ((long)obj
!= -100)
1395 case VarEnum
.VT_UI8
:
1396 if (obj
.GetType () != typeof (ulong))
1398 if ((ulong)obj
!= 100)
1402 if (obj
.GetType () != typeof (float))
1404 if (Math
.Abs ((float)obj
- 3.14f
) > 1e-10)
1408 if (obj
.GetType () != typeof (double))
1410 if (Math
.Abs ((double)obj
- 3.14) > 1e-10)
1413 case VarEnum
.VT_BSTR
:
1414 if (obj
.GetType () != typeof (string))
1416 if ((string)obj
!= "PI")
1419 case VarEnum
.VT_BOOL
:
1420 if (obj
.GetType () != typeof (bool))
1422 if ((bool)obj
!= true)
1429 public static int mono_test_marshal_variant_out_callback (VarEnum vt
, ref object obj
)
1435 case VarEnum
.VT_UI1
:
1441 case VarEnum
.VT_UI2
:
1447 case VarEnum
.VT_UI4
:
1453 case VarEnum
.VT_UI8
:
1462 case VarEnum
.VT_BSTR
:
1465 case VarEnum
.VT_BOOL
:
1472 public static int TestITest (ITest itest
)
1476 itest
.SByteIn (-100);
1478 itest
.ShortIn (-100);
1479 itest
.UShortIn (100);
1482 itest
.LongIn (-100);
1483 itest
.ULongIn (100);
1484 itest
.FloatIn (3.14f
);
1485 itest
.DoubleIn (3.14);
1486 itest
.ITestIn (itest
);
1487 itest
.ITestOut (out itest2
);
1489 catch (Exception ex
) {
1495 public static int TestITestPresSig (ITestPresSig itest
)
1497 ITestPresSig itest2
;
1498 if (itest
.SByteIn (-100) != 0)
1500 if (itest
.ByteIn (100) != 0)
1502 if (itest
.ShortIn (-100) != 0)
1504 if (itest
.UShortIn (100) != 0)
1506 if (itest
.IntIn (-100) != 0)
1508 if (itest
.UIntIn (100) != 0)
1510 if (itest
.LongIn (-100) != 0)
1512 if (itest
.ULongIn (100) != 0)
1514 if (itest
.FloatIn (3.14f
) != 0)
1516 if (itest
.DoubleIn (3.14) != 0)
1518 if (itest
.ITestIn (itest
) != 0)
1520 if (itest
.ITestOut (out itest2
) != 0)
1525 public static int TestITestDelegate (ITest itest
)
1530 SByteInDelegate SByteInFcn
= itest
.SByteIn
;
1531 ByteInDelegate ByteInFcn
= itest
.ByteIn
;
1532 UShortInDelegate UShortInFcn
= itest
.UShortIn
;
1533 IntInDelegate IntInFcn
= itest
.IntIn
;
1534 UIntInDelegate UIntInFcn
= itest
.UIntIn
;
1535 LongInDelegate LongInFcn
= itest
.LongIn
;
1537 ULongInDelegate ULongInFcn
= itest
.ULongIn
;
1538 FloatInDelegate FloatInFcn
= itest
.FloatIn
;
1539 DoubleInDelegate DoubleInFcn
= itest
.DoubleIn
;
1540 ITestInDelegate ITestInFcn
= itest
.ITestIn
;
1541 ITestOutDelegate ITestOutFcn
= itest
.ITestOut
;
1553 ITestOutFcn (out itest2
);
1561 public static int TestIfaceNoIcall (ITestPresSig itest
) {
1562 return itest
.Return22NoICall () == 22 ? 0 : 1;
1566 public class TestVisible