[2019-12] [threads] Add back mono_threads_attach_tools_thread as a public API (#18074)
[mono-project.git] / mono / tests / cominterop.cs
blob604fe4fb3b4a44d254d773adf66fe042f1a95b1c
1 //
2 // cominterop.cs:
3 //
4 // Tests for COM Interop related features
5 //
7 using System;
8 using System.Runtime.CompilerServices;
9 using System.Runtime.InteropServices;
12 public class Tests
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)
341 #region BSTR Tests
343 string str;
344 if (mono_test_marshal_bstr_in ("mono_test_marshal_bstr_in") != 0)
345 return 1;
346 if (mono_test_marshal_bstr_out (out str) != 0 || str != "mono_test_marshal_bstr_out")
347 return 2;
348 if (mono_test_marshal_bstr_in_null (null) != 0)
349 return 1;
350 if (mono_test_marshal_bstr_out_null (out str) != 0 || str != null)
351 return 2;
353 #endregion // BSTR Tests
355 #region VARIANT Tests
357 object obj;
358 if (mono_test_marshal_variant_in_sbyte ((sbyte)100) != 0)
359 return 13;
360 if (mono_test_marshal_variant_in_byte ((byte)100) != 0)
361 return 14;
362 if (mono_test_marshal_variant_in_short ((short)314) != 0)
363 return 15;
364 if (mono_test_marshal_variant_in_ushort ((ushort)314) != 0)
365 return 16;
366 if (mono_test_marshal_variant_in_int ((int)314) != 0)
367 return 17;
368 if (mono_test_marshal_variant_in_uint ((uint)314) != 0)
369 return 18;
370 if (mono_test_marshal_variant_in_long ((long)314) != 0)
371 return 19;
372 if (mono_test_marshal_variant_in_ulong ((ulong)314) != 0)
373 return 20;
374 if (mono_test_marshal_variant_in_float ((float)3.14) != 0)
375 return 21;
376 if (mono_test_marshal_variant_in_double ((double)3.14) != 0)
377 return 22;
378 if (mono_test_marshal_variant_in_bstr ("PI") != 0)
379 return 23;
380 if (mono_test_marshal_variant_out_sbyte (out obj) != 0 || (sbyte)obj != 100)
381 return 24;
382 if (mono_test_marshal_variant_out_byte (out obj) != 0 || (byte)obj != 100)
383 return 25;
384 if (mono_test_marshal_variant_out_short (out obj) != 0 || (short)obj != 314)
385 return 26;
386 if (mono_test_marshal_variant_out_ushort (out obj) != 0 || (ushort)obj != 314)
387 return 27;
388 if (mono_test_marshal_variant_out_int (out obj) != 0 || (int)obj != 314)
389 return 28;
390 if (mono_test_marshal_variant_out_uint (out obj) != 0 || (uint)obj != 314)
391 return 29;
392 if (mono_test_marshal_variant_out_long (out obj) != 0 || (long)obj != 314)
393 return 30;
394 if (mono_test_marshal_variant_out_ulong (out obj) != 0 || (ulong)obj != 314)
395 return 31;
396 if (mono_test_marshal_variant_out_float (out obj) != 0 || ((float)obj - 3.14) / 3.14 > .001)
397 return 32;
398 if (mono_test_marshal_variant_out_double (out obj) != 0 || ((double)obj - 3.14) / 3.14 > .001)
399 return 33;
400 if (mono_test_marshal_variant_out_bstr (out obj) != 0 || (string)obj != "PI")
401 return 34;
403 VarFunc func = new VarFunc (mono_test_marshal_variant_in_callback);
404 if (mono_test_marshal_variant_in_sbyte_unmanaged (func) != 0)
405 return 35;
406 if (mono_test_marshal_variant_in_byte_unmanaged (func) != 0)
407 return 36;
408 if (mono_test_marshal_variant_in_short_unmanaged (func) != 0)
409 return 37;
410 if (mono_test_marshal_variant_in_ushort_unmanaged (func) != 0)
411 return 38;
412 if (mono_test_marshal_variant_in_int_unmanaged (func) != 0)
413 return 39;
414 if (mono_test_marshal_variant_in_uint_unmanaged (func) != 0)
415 return 40;
416 if (mono_test_marshal_variant_in_long_unmanaged (func) != 0)
417 return 41;
418 if (mono_test_marshal_variant_in_ulong_unmanaged (func) != 0)
419 return 42;
420 if (mono_test_marshal_variant_in_float_unmanaged (func) != 0)
421 return 43;
422 if (mono_test_marshal_variant_in_double_unmanaged (func) != 0)
423 return 44;
424 if (mono_test_marshal_variant_in_bstr_unmanaged (func) != 0)
425 return 45;
426 if (mono_test_marshal_variant_in_bool_true_unmanaged (func) != 0)
427 return 46;
429 VarRefFunc reffunc = new VarRefFunc (mono_test_marshal_variant_out_callback);
430 if (mono_test_marshal_variant_out_sbyte_unmanaged (reffunc) != 0)
431 return 50;
432 if (mono_test_marshal_variant_out_byte_unmanaged (reffunc) != 0)
433 return 51;
434 if (mono_test_marshal_variant_out_short_unmanaged (reffunc) != 0)
435 return 52;
436 if (mono_test_marshal_variant_out_ushort_unmanaged (reffunc) != 0)
437 return 53;
438 if (mono_test_marshal_variant_out_int_unmanaged (reffunc) != 0)
439 return 54;
440 if (mono_test_marshal_variant_out_uint_unmanaged (reffunc) != 0)
441 return 55;
442 if (mono_test_marshal_variant_out_long_unmanaged (reffunc) != 0)
443 return 56;
444 if (mono_test_marshal_variant_out_ulong_unmanaged (reffunc) != 0)
445 return 57;
446 if (mono_test_marshal_variant_out_float_unmanaged (reffunc) != 0)
447 return 58;
448 if (mono_test_marshal_variant_out_double_unmanaged (reffunc) != 0)
449 return 59;
450 if (mono_test_marshal_variant_out_bstr_unmanaged (reffunc) != 0)
451 return 60;
452 if (mono_test_marshal_variant_out_bool_true_unmanaged (reffunc) != 0)
453 return 61;
455 if (mono_test_marshal_variant_out_sbyte_byref (out obj) != 0 || (sbyte)obj != 100)
456 return 97;
457 if (mono_test_marshal_variant_out_byte_byref (out obj) != 0 || (byte)obj != 100)
458 return 98;
459 if (mono_test_marshal_variant_out_short_byref (out obj) != 0 || (short)obj != 314)
460 return 99;
461 if (mono_test_marshal_variant_out_ushort_byref (out obj) != 0 || (ushort)obj != 314)
462 return 100;
463 if (mono_test_marshal_variant_out_int_byref (out obj) != 0 || (int)obj != 314)
464 return 101;
465 if (mono_test_marshal_variant_out_uint_byref (out obj) != 0 || (uint)obj != 314)
466 return 102;
467 if (mono_test_marshal_variant_out_long_byref (out obj) != 0 || (long)obj != 314)
468 return 103;
469 if (mono_test_marshal_variant_out_ulong_byref (out obj) != 0 || (ulong)obj != 314)
470 return 104;
471 if (mono_test_marshal_variant_out_float_byref (out obj) != 0 || ((float)obj - 3.14) / 3.14 > .001)
472 return 105;
473 if (mono_test_marshal_variant_out_double_byref (out obj) != 0 || ((double)obj - 3.14) / 3.14 > .001)
474 return 106;
475 if (mono_test_marshal_variant_out_bstr_byref (out obj) != 0 || (string)obj != "PI")
476 return 107;
478 #endregion // VARIANT Tests
480 #region Runtime Callable Wrapper Tests
482 #if !MOBILE
484 IntPtr pUnk;
485 if (mono_test_marshal_com_object_create (out pUnk) != 0)
486 return 145;
488 if (mono_test_marshal_com_object_ref_count (pUnk) != 1)
489 return 146;
491 if (Marshal.AddRef (pUnk) != 2)
492 return 147;
494 if (mono_test_marshal_com_object_ref_count (pUnk) != 2)
495 return 148;
497 if (Marshal.Release (pUnk) != 1)
498 return 149;
500 if (mono_test_marshal_com_object_ref_count (pUnk) != 1)
501 return 150;
503 object com_obj = Marshal.GetObjectForIUnknown (pUnk);
505 if (com_obj == null)
506 return 151;
508 ITest itest = com_obj as ITest;
510 if (itest == null)
511 return 152;
513 IntPtr pUnk2;
514 if (mono_test_marshal_com_object_same (out pUnk2) != 0)
515 return 153;
517 object com_obj2 = Marshal.GetObjectForIUnknown (pUnk2);
519 if (com_obj != com_obj2)
520 return 154;
522 if (!com_obj.Equals (com_obj2))
523 return 155;
525 IntPtr pUnk3;
526 if (mono_test_marshal_com_object_create (out pUnk3) != 0)
527 return 156;
529 object com_obj3 = Marshal.GetObjectForIUnknown (pUnk3);
530 if (com_obj == com_obj3)
531 return 157;
533 if (com_obj.Equals (com_obj3))
534 return 158;
536 // com_obj & com_obj2 share a RCW
537 if (Marshal.ReleaseComObject (com_obj2) != 1)
538 return 159;
540 // com_obj3 should only have one RCW
541 if (Marshal.ReleaseComObject (com_obj3) != 0)
542 return 160;
544 IntPtr iunknown = Marshal.GetIUnknownForObject (com_obj);
545 if (iunknown == IntPtr.Zero)
546 return 170;
548 if (pUnk != iunknown)
549 return 171;
551 if (TestITest (itest) != 0)
552 return 172;
554 if (TestITestPresSig (itest as ITestPresSig) != 0)
555 return 173;
557 if (TestITestDelegate (itest) != 0)
558 return 174;
560 if (TestIfaceNoIcall (itest as ITestPresSig) != 0)
561 return 175;
563 itest = new TestClass ();
565 if (TestITest (itest) != 0)
566 return 176;
568 itest = (ITest)System.Activator.CreateInstance (typeof(TestActivatorClass));
570 if (TestITest (itest) != 0)
571 return 177;
573 #endif
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)
585 return 200;
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)
595 return 201;
597 var otherTest = new OtherTest ();
598 if (mono_test_cominterop_ccw_queryinterface (otherTest) != 0)
599 return 202;
601 if (mono_test_marshal_retval_ccw_itest(test, true) != 0)
602 return 203;
604 /* Passing NULL to an out parameter will crash. */
605 if (mono_test_marshal_retval_ccw_itest(test_pres_sig, false) != 0)
606 return 204;
608 if (mono_test_default_interface_ccw(test) != 0)
609 return 205;
611 #endregion // COM Callable Wrapper Tests
613 #region SAFEARRAY tests
615 if (isWindows) {
617 /* out */
618 Array array;
619 if ((mono_test_marshal_safearray_out_1dim_vt_bstr_empty (out array) != 0) || (array.Rank != 1) || (array.Length != 0))
620 return 62;
622 if ((mono_test_marshal_safearray_out_1dim_vt_bstr (out array) != 0) || (array.Rank != 1) || (array.Length != 10))
623 return 63;
624 for (int i = 0; i < 10; ++i) {
625 if (i != Convert.ToInt32 (array.GetValue (i)))
626 return 64;
629 if ((mono_test_marshal_safearray_out_2dim_vt_i4 (out array) != 0) || (array.Rank != 2))
630 return 65;
631 if ( (array.GetLowerBound (0) != 0) || (array.GetUpperBound (0) != 3)
632 || (array.GetLowerBound (1) != 0) || (array.GetUpperBound (1) != 2))
633 return 66;
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 }))
638 return 67;
642 if ((mono_test_marshal_safearray_out_4dim_vt_i4 (out array) != 0) || (array.Rank != 4))
643 return 68;
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) )
648 return 69;
650 int index = 0;
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 }))
656 return 70;
657 ++index;
663 /* in */
665 array = new object[] { };
666 if (mono_test_marshal_safearray_in_byval_1dim_empty (array) != 0)
667 return 71;
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)
671 return 72;
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)
675 return 73;
676 if ((int)array.GetValue (0) != 0)
677 return 74;
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)
681 return 75;
682 if ((int)array.GetValue (new int[] { 0, 0 }) != 11)
683 return 76;
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)
687 return 77;
688 if ((string)array.GetValue (new int[] { 0, 0, 0 }) != "111")
689 return 78;
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))
693 return 79;
694 if ((string)array.GetValue (new int[] { 0, 0, 0 }) != "111")
695 return 80;
697 /* in, out, byref */
699 array = new object[] { };
700 if ((mono_test_marshal_safearray_in_out_byref_1dim_empty (ref array) != 0) || (array.Rank != 1) || (array.Length != 8))
701 return 81;
702 for (int i = 0; i < 8; ++i)
704 if (i != Convert.ToInt32 (array.GetValue (i)))
705 return 82;
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))
710 return 83;
711 for (int i = 0; i < 8; ++i)
713 if (i != Convert.ToInt32 (array.GetValue (i)))
714 return 84;
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))
720 return 85;
722 if (Convert.ToInt32 (array.GetValue (0)) != -1)
723 return 86;
725 /* in, out, byval */
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))
730 return 87;
732 if (Convert.ToInt32 (array.GetValue (0)) != 12345)
733 return 88;
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))
738 return 89;
740 if (Convert.ToInt32 (array.GetValue (new int[] { 1, 1, 1 })) != 111)
741 return 90;
742 if (Convert.ToInt32 (array.GetValue (new int[] { 1, 1, 2 })) != 333)
743 return 91;
744 if (Convert.ToString(array.GetValue (new int[] { 0, 1, 0 })) != "ABCDEFG")
745 return 92;
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)
759 return 93;
761 for (int i = 0; i < 10; ++i)
763 if (i != Convert.ToInt32 (array2.GetValue (i)))
764 return 94;
766 if ((int)array3.GetValue (0) != 0)
767 return 95;
768 for (int i = 0; i < 8; ++i)
770 if (i != Convert.ToInt32 (array4.GetValue (i)))
771 return 96;
773 if (mono_test_marshal_safearray_in_ccw(test) != 0)
774 return 97;
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)
782 return 300;
783 #endregion
786 return 0;
789 [ComImport ()]
790 [Guid ("10000000-0000-0000-0000-000000000002")]
791 [InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
792 public interface IDefTest1
794 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
795 int Method1();
798 [ComImport ()]
799 [Guid ("10000000-0000-0000-0000-000000000003")]
800 [InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
801 public interface IDefTest2
803 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
804 int Method2();
807 public class TestDefaultInterfaceClass : IDefTest1, IDefTest2
809 public int Method3()
811 return 3;
814 public int Method1()
816 return 1;
819 public int Method4()
821 return 4;
824 public int Method2()
826 return 2;
830 [ComDefaultInterfaceAttribute (typeof (IDefTest1))]
831 public class TestDefaultInterfaceClass1 : TestDefaultInterfaceClass
835 [ComDefaultInterfaceAttribute (typeof (IDefTest2))]
836 public class TestDefaultInterfaceClass2 : TestDefaultInterfaceClass
840 [ComImport ()]
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
846 ITest Test
848 [return: MarshalAs (UnmanagedType.Interface)]
849 [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId (5242884)]
850 get;
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)]
879 int IntOut();
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();
894 [ComImport ()]
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
900 ITestPresSig Test
902 [return: MarshalAs (UnmanagedType.Interface)]
903 [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId (5242884)]
904 get;
907 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
908 [PreserveSig ()]
909 int SByteIn (sbyte val);
910 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
911 [PreserveSig ()]
912 int ByteIn (byte val);
913 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
914 [PreserveSig ()]
915 int ShortIn (short val);
916 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
917 [PreserveSig ()]
918 int UShortIn (ushort val);
919 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
920 [PreserveSig ()]
921 int IntIn (int val);
922 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
923 [PreserveSig ()]
924 int UIntIn (uint val);
925 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
926 [PreserveSig ()]
927 int LongIn (long val);
928 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
929 [PreserveSig ()]
930 int ULongIn (ulong val);
931 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
932 [PreserveSig ()]
933 int FloatIn (float val);
934 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
935 [PreserveSig ()]
936 int DoubleIn (double val);
937 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
938 [PreserveSig ()]
939 int ITestIn ([MarshalAs (UnmanagedType.Interface)]ITestPresSig val);
940 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
941 [PreserveSig ()]
942 int ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITestPresSig val);
943 [PreserveSig ()]
944 int Return22NoICall();
945 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
946 [PreserveSig ()]
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)]
966 get;
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
1012 static TestClass ()
1014 ExtensibleClassFactory.RegisterObjectCreationCallback (new ObjectCreationDelegate (CreateObject)); ;
1016 private static System.IntPtr CreateObject (System.IntPtr aggr)
1018 IntPtr pUnk3;
1019 mono_test_marshal_com_object_create (out pUnk3);
1020 return 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)
1033 IntPtr pUnk3;
1034 mono_test_marshal_com_object_create (out pUnk3);
1035 return 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)
1064 if (val != -100)
1065 return 1;
1066 return 0;
1069 public int ByteIn (byte val)
1071 if (val != 100)
1072 return 2;
1073 return 0;
1076 public int ShortIn (short val)
1078 if (val != -100)
1079 return 3;
1080 return 0;
1083 public int UShortIn (ushort val)
1085 if (val != 100)
1086 return 4;
1087 return 0;
1090 public int IntIn (int val)
1092 if (val != -100)
1093 return 5;
1094 return 0;
1097 public int UIntIn (uint val)
1099 if (val != 100)
1100 return 6;
1101 return 0;
1104 public int LongIn (long val)
1106 if (val != -100)
1107 return 7;
1108 return 0;
1111 public int ULongIn (ulong val)
1113 if (val != 100)
1114 return 8;
1115 return 0;
1118 public int FloatIn (float val)
1120 if (Math.Abs (val - 3.14f) > .000001)
1121 return 9;
1122 return 0;
1125 public int DoubleIn (double val)
1127 if (Math.Abs (val - 3.14f) > .000001)
1128 return 10;
1129 return 0;
1132 public int ITestIn ([MarshalAs (UnmanagedType.Interface)]ITestPresSig val)
1134 if (val == null)
1135 return 11;
1136 if (null == val as ManagedTestPresSig)
1137 return 12;
1138 return 0;
1141 public int ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITestPresSig val)
1143 val = new ManagedTestPresSig ();
1144 return 0;
1147 public int Return22NoICall()
1149 return 88;
1152 public int IntOut(out int val)
1154 val = 33;
1155 return 0;
1158 public int ArrayIn(object[] array)
1160 if (array.Length != 2)
1161 return 40;
1162 if (array.Rank != 1)
1163 return 41;
1164 if (array.GetLowerBound(0) != 0)
1165 return 42;
1166 if (array.GetUpperBound(0) != 1)
1167 return 43;
1168 if (array[0] is string)
1170 if ((array[0] as string) != "Test")
1171 return 44;
1173 else
1174 return 45;
1175 if (array[1] is int)
1177 if ((int)array[1] != 2345)
1178 return 46;
1180 else
1181 return 47;
1183 return 444;
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;
1200 public int Status
1202 get { return status; }
1204 public void SByteIn (sbyte val)
1206 if (val != -100)
1207 status = 1;
1210 public void ByteIn (byte val)
1212 if (val != 100)
1213 status = 2;
1216 public void ShortIn (short val)
1218 if (val != -100)
1219 status = 3;
1222 public void UShortIn (ushort val)
1224 if (val != 100)
1225 status = 4;
1228 public void IntIn (int val)
1230 if (val != -100)
1231 status = 5;
1234 public void UIntIn (uint val)
1236 if (val != 100)
1237 status = 6;
1240 public void LongIn (long val)
1242 if (val != -100)
1243 status = 7;
1246 public void ULongIn (ulong val)
1248 if (val != 100)
1249 status = 8;
1252 public void FloatIn (float val)
1254 if (Math.Abs (val - 3.14f) > .000001)
1255 status = 9;
1258 public void DoubleIn (double val)
1260 if (Math.Abs (val - 3.14) > .000001)
1261 status = 10;
1264 public void ITestIn (ITest val)
1266 if (val == null)
1267 status = 11;
1268 if (null == val as ManagedTest)
1269 status = 12;
1272 public void ITestOut (out ITest val)
1274 val = new ManagedTest ();
1277 public ITest Test
1281 return new ManagedTest ();
1285 public int Return22NoICall()
1287 return 99;
1290 public int IntOut()
1292 return 33;
1295 public void ArrayIn(object[] array)
1297 if (array.Length != 2)
1298 status = 40;
1299 else if (array.Rank != 1)
1300 status = 41;
1301 else if (array.GetLowerBound(0) != 0)
1302 status = 42;
1303 else if (array.GetUpperBound(0) != 1)
1304 status = 43;
1305 else if (array[0] is string)
1307 if ((array[0] as string) != "Test")
1308 status = 44;
1310 else if (array[1] is int)
1312 if ((int)array[1] != 2345)
1313 status = 45;
1316 status = 444;
1319 public void ArrayIn2(object[] array)
1321 ArrayIn(array);
1324 public void ArrayIn3(object[] array)
1326 ArrayIn(array);
1329 public TestDefaultInterfaceClass1 GetDefInterface1()
1331 return new TestDefaultInterfaceClass1();
1334 public TestDefaultInterfaceClass2 GetDefInterface2()
1336 return new TestDefaultInterfaceClass2();
1340 [ComVisible (true)]
1341 public interface IOtherTest
1345 public class OtherTest: IOtherTest
1349 public static int mono_test_marshal_variant_in_callback (VarEnum vt, object obj)
1351 switch (vt)
1353 case VarEnum.VT_I1:
1354 if (obj.GetType () != typeof (sbyte))
1355 return 1;
1356 if ((sbyte)obj != -100)
1357 return 2;
1358 break;
1359 case VarEnum.VT_UI1:
1360 if (obj.GetType () != typeof (byte))
1361 return 1;
1362 if ((byte)obj != 100)
1363 return 2;
1364 break;
1365 case VarEnum.VT_I2:
1366 if (obj.GetType () != typeof (short))
1367 return 1;
1368 if ((short)obj != -100)
1369 return 2;
1370 break;
1371 case VarEnum.VT_UI2:
1372 if (obj.GetType () != typeof (ushort))
1373 return 1;
1374 if ((ushort)obj != 100)
1375 return 2;
1376 break;
1377 case VarEnum.VT_I4:
1378 if (obj.GetType () != typeof (int))
1379 return 1;
1380 if ((int)obj != -100)
1381 return 2;
1382 break;
1383 case VarEnum.VT_UI4:
1384 if (obj.GetType () != typeof (uint))
1385 return 1;
1386 if ((uint)obj != 100)
1387 return 2;
1388 break;
1389 case VarEnum.VT_I8:
1390 if (obj.GetType () != typeof (long))
1391 return 1;
1392 if ((long)obj != -100)
1393 return 2;
1394 break;
1395 case VarEnum.VT_UI8:
1396 if (obj.GetType () != typeof (ulong))
1397 return 1;
1398 if ((ulong)obj != 100)
1399 return 2;
1400 break;
1401 case VarEnum.VT_R4:
1402 if (obj.GetType () != typeof (float))
1403 return 1;
1404 if (Math.Abs ((float)obj - 3.14f) > 1e-10)
1405 return 2;
1406 break;
1407 case VarEnum.VT_R8:
1408 if (obj.GetType () != typeof (double))
1409 return 1;
1410 if (Math.Abs ((double)obj - 3.14) > 1e-10)
1411 return 2;
1412 break;
1413 case VarEnum.VT_BSTR:
1414 if (obj.GetType () != typeof (string))
1415 return 1;
1416 if ((string)obj != "PI")
1417 return 2;
1418 break;
1419 case VarEnum.VT_BOOL:
1420 if (obj.GetType () != typeof (bool))
1421 return 1;
1422 if ((bool)obj != true)
1423 return 2;
1424 break;
1426 return 0;
1429 public static int mono_test_marshal_variant_out_callback (VarEnum vt, ref object obj)
1431 switch (vt) {
1432 case VarEnum.VT_I1:
1433 obj = (sbyte)-100;
1434 break;
1435 case VarEnum.VT_UI1:
1436 obj = (byte)100;
1437 break;
1438 case VarEnum.VT_I2:
1439 obj = (short)-100;
1440 break;
1441 case VarEnum.VT_UI2:
1442 obj = (ushort)100;
1443 break;
1444 case VarEnum.VT_I4:
1445 obj = (int)-100;
1446 break;
1447 case VarEnum.VT_UI4:
1448 obj = (uint)100;
1449 break;
1450 case VarEnum.VT_I8:
1451 obj = (long)-100;
1452 break;
1453 case VarEnum.VT_UI8:
1454 obj = (ulong)100;
1455 break;
1456 case VarEnum.VT_R4:
1457 obj = (float)3.14f;
1458 break;
1459 case VarEnum.VT_R8:
1460 obj = (double)3.14;
1461 break;
1462 case VarEnum.VT_BSTR:
1463 obj = "PI";
1464 break;
1465 case VarEnum.VT_BOOL:
1466 obj = true;
1467 break;
1469 return 0;
1472 public static int TestITest (ITest itest)
1474 try {
1475 ITest itest2;
1476 itest.SByteIn (-100);
1477 itest.ByteIn (100);
1478 itest.ShortIn (-100);
1479 itest.UShortIn (100);
1480 itest.IntIn (-100);
1481 itest.UIntIn (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) {
1490 return 1;
1492 return 0;
1495 public static int TestITestPresSig (ITestPresSig itest)
1497 ITestPresSig itest2;
1498 if (itest.SByteIn (-100) != 0)
1499 return 1000;
1500 if (itest.ByteIn (100) != 0)
1501 return 1001;
1502 if (itest.ShortIn (-100) != 0)
1503 return 1002;
1504 if (itest.UShortIn (100) != 0)
1505 return 1003;
1506 if (itest.IntIn (-100) != 0)
1507 return 1004;
1508 if (itest.UIntIn (100) != 0)
1509 return 1005;
1510 if (itest.LongIn (-100) != 0)
1511 return 1006;
1512 if (itest.ULongIn (100) != 0)
1513 return 1007;
1514 if (itest.FloatIn (3.14f) != 0)
1515 return 1008;
1516 if (itest.DoubleIn (3.14) != 0)
1517 return 1009;
1518 if (itest.ITestIn (itest) != 0)
1519 return 1010;
1520 if (itest.ITestOut (out itest2) != 0)
1521 return 1011;
1522 return 0;
1525 public static int TestITestDelegate (ITest itest)
1527 try {
1528 ITest itest2;
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;
1543 SByteInFcn (-100);
1544 ByteInFcn (100);
1545 UShortInFcn (100);
1546 IntInFcn (-100);
1547 UIntInFcn (100);
1548 LongInFcn (-100);
1549 ULongInFcn (100);
1550 FloatInFcn (3.14f);
1551 DoubleInFcn (3.14);
1552 ITestInFcn (itest);
1553 ITestOutFcn (out itest2);
1555 catch (Exception) {
1556 return 1;
1558 return 0;
1561 public static int TestIfaceNoIcall (ITestPresSig itest) {
1562 return itest.Return22NoICall () == 22 ? 0 : 1;
1566 public class TestVisible