4 // Tests for COM Interop related features
8 using System.Runtime.CompilerServices;
9 using System.Runtime.InteropServices;
14 [DllImport("libtest")]
15 public static extern int mono_test_marshal_bstr_in([MarshalAs(UnmanagedType.BStr)]string str);
17 [DllImport("libtest")]
18 public static extern int mono_test_marshal_bstr_out([MarshalAs(UnmanagedType.BStr)] out string str);
20 [DllImport("libtest")]
21 public static extern int mono_test_marshal_bstr_in_null([MarshalAs(UnmanagedType.BStr)]string str);
23 [DllImport("libtest")]
24 public static extern int mono_test_marshal_bstr_out_null([MarshalAs(UnmanagedType.BStr)] out string str);
26 [DllImport("libtest")]
27 public static extern int mono_test_marshal_variant_in_sbyte([MarshalAs(UnmanagedType.Struct)]object obj);
29 [DllImport("libtest")]
30 public static extern int mono_test_marshal_variant_in_byte([MarshalAs(UnmanagedType.Struct)]object obj);
32 [DllImport("libtest")]
33 public static extern int mono_test_marshal_variant_in_short([MarshalAs(UnmanagedType.Struct)]object obj);
35 [DllImport("libtest")]
36 public static extern int mono_test_marshal_variant_in_ushort([MarshalAs(UnmanagedType.Struct)]object obj);
38 [DllImport("libtest")]
39 public static extern int mono_test_marshal_variant_in_int([MarshalAs(UnmanagedType.Struct)]object obj);
41 [DllImport("libtest")]
42 public static extern int mono_test_marshal_variant_in_uint([MarshalAs(UnmanagedType.Struct)]object obj);
44 [DllImport("libtest")]
45 public static extern int mono_test_marshal_variant_in_long([MarshalAs(UnmanagedType.Struct)]object obj);
47 [DllImport("libtest")]
48 public static extern int mono_test_marshal_variant_in_ulong([MarshalAs(UnmanagedType.Struct)]object obj);
50 [DllImport("libtest")]
51 public static extern int mono_test_marshal_variant_in_float([MarshalAs(UnmanagedType.Struct)]object obj);
53 [DllImport("libtest")]
54 public static extern int mono_test_marshal_variant_in_double([MarshalAs(UnmanagedType.Struct)]object obj);
56 [DllImport("libtest")]
57 public static extern int mono_test_marshal_variant_in_bstr ([MarshalAs (UnmanagedType.Struct)]object obj);
59 [DllImport ("libtest")]
60 public static extern int mono_test_marshal_variant_in_bool_true ([MarshalAs (UnmanagedType.Struct)]object obj);
62 [DllImport ("libtest")]
63 public static extern int mono_test_marshal_variant_in_bool_false ([MarshalAs (UnmanagedType.Struct)]object obj);
65 [DllImport("libtest")]
66 public static extern int mono_test_marshal_variant_out_sbyte([MarshalAs(UnmanagedType.Struct)]out object obj);
68 [DllImport("libtest")]
69 public static extern int mono_test_marshal_variant_out_byte([MarshalAs(UnmanagedType.Struct)]out object obj);
71 [DllImport("libtest")]
72 public static extern int mono_test_marshal_variant_out_short([MarshalAs(UnmanagedType.Struct)]out object obj);
74 [DllImport("libtest")]
75 public static extern int mono_test_marshal_variant_out_ushort([MarshalAs(UnmanagedType.Struct)]out object obj);
77 [DllImport("libtest")]
78 public static extern int mono_test_marshal_variant_out_int([MarshalAs(UnmanagedType.Struct)]out object obj);
80 [DllImport("libtest")]
81 public static extern int mono_test_marshal_variant_out_uint([MarshalAs(UnmanagedType.Struct)]out object obj);
83 [DllImport("libtest")]
84 public static extern int mono_test_marshal_variant_out_long([MarshalAs(UnmanagedType.Struct)]out object obj);
86 [DllImport("libtest")]
87 public static extern int mono_test_marshal_variant_out_ulong([MarshalAs(UnmanagedType.Struct)]out object obj);
89 [DllImport("libtest")]
90 public static extern int mono_test_marshal_variant_out_float([MarshalAs(UnmanagedType.Struct)]out object obj);
92 [DllImport("libtest")]
93 public static extern int mono_test_marshal_variant_out_double([MarshalAs(UnmanagedType.Struct)]out object obj);
95 [DllImport("libtest")]
96 public static extern int mono_test_marshal_variant_out_bstr ([MarshalAs (UnmanagedType.Struct)]out object obj);
98 [DllImport("libtest")]
99 public static extern int mono_test_marshal_variant_out_bool_true ([MarshalAs (UnmanagedType.Struct)]out object obj);
101 [DllImport ("libtest")]
102 public static extern int mono_test_marshal_variant_out_bool_false ([MarshalAs (UnmanagedType.Struct)]out object obj);
105 public delegate int VarFunc (VarEnum vt, [MarshalAs (UnmanagedType.Struct)] object obj);
107 public delegate int VarRefFunc (VarEnum vt, [MarshalAs (UnmanagedType.Struct)] ref object obj);
109 [DllImport ("libtest")]
110 public static extern int mono_test_marshal_variant_in_sbyte_unmanaged (VarFunc func);
112 [DllImport ("libtest")]
113 public static extern int mono_test_marshal_variant_in_byte_unmanaged (VarFunc func);
115 [DllImport ("libtest")]
116 public static extern int mono_test_marshal_variant_in_short_unmanaged (VarFunc func);
118 [DllImport ("libtest")]
119 public static extern int mono_test_marshal_variant_in_ushort_unmanaged (VarFunc func);
121 [DllImport ("libtest")]
122 public static extern int mono_test_marshal_variant_in_int_unmanaged (VarFunc func);
124 [DllImport ("libtest")]
125 public static extern int mono_test_marshal_variant_in_uint_unmanaged (VarFunc func);
127 [DllImport ("libtest")]
128 public static extern int mono_test_marshal_variant_in_long_unmanaged (VarFunc func);
130 [DllImport ("libtest")]
131 public static extern int mono_test_marshal_variant_in_ulong_unmanaged (VarFunc func);
133 [DllImport ("libtest")]
134 public static extern int mono_test_marshal_variant_in_float_unmanaged (VarFunc func);
136 [DllImport ("libtest")]
137 public static extern int mono_test_marshal_variant_in_double_unmanaged (VarFunc func);
139 [DllImport ("libtest")]
140 public static extern int mono_test_marshal_variant_in_bstr_unmanaged (VarFunc func);
142 [DllImport ("libtest")]
143 public static extern int mono_test_marshal_variant_in_bool_true_unmanaged (VarFunc func);
145 [DllImport ("libtest")]
146 public static extern int mono_test_marshal_variant_in_bool_false_unmanaged (VarFunc func);
148 [DllImport ("libtest")]
149 public static extern int mono_test_marshal_variant_out_sbyte_unmanaged (VarRefFunc func);
151 [DllImport ("libtest")]
152 public static extern int mono_test_marshal_variant_out_byte_unmanaged (VarRefFunc func);
154 [DllImport ("libtest")]
155 public static extern int mono_test_marshal_variant_out_short_unmanaged (VarRefFunc func);
157 [DllImport ("libtest")]
158 public static extern int mono_test_marshal_variant_out_ushort_unmanaged (VarRefFunc func);
160 [DllImport ("libtest")]
161 public static extern int mono_test_marshal_variant_out_int_unmanaged (VarRefFunc func);
163 [DllImport ("libtest")]
164 public static extern int mono_test_marshal_variant_out_uint_unmanaged (VarRefFunc func);
166 [DllImport ("libtest")]
167 public static extern int mono_test_marshal_variant_out_long_unmanaged (VarRefFunc func);
169 [DllImport ("libtest")]
170 public static extern int mono_test_marshal_variant_out_ulong_unmanaged (VarRefFunc func);
172 [DllImport ("libtest")]
173 public static extern int mono_test_marshal_variant_out_float_unmanaged (VarRefFunc func);
175 [DllImport ("libtest")]
176 public static extern int mono_test_marshal_variant_out_double_unmanaged (VarRefFunc func);
178 [DllImport ("libtest")]
179 public static extern int mono_test_marshal_variant_out_bstr_unmanaged (VarRefFunc func);
181 [DllImport ("libtest")]
182 public static extern int mono_test_marshal_variant_out_bool_true_unmanaged (VarRefFunc func);
184 [DllImport ("libtest")]
185 public static extern int mono_test_marshal_variant_out_bool_false_unmanaged (VarRefFunc func);
187 [DllImport ("libtest")]
188 public static extern int mono_test_marshal_com_object_create (out IntPtr pUnk);
190 [DllImport ("libtest")]
191 public static extern int mono_test_marshal_com_object_same (out IntPtr pUnk);
193 [DllImport ("libtest")]
194 public static extern int mono_test_marshal_com_object_destroy (IntPtr pUnk);
196 [DllImport ("libtest")]
197 public static extern int mono_test_marshal_com_object_ref_count (IntPtr pUnk);
199 [DllImport ("libtest")]
200 public static extern int mono_test_marshal_ccw_identity ([MarshalAs (UnmanagedType.Interface)]ITest itest);
202 [DllImport ("libtest")]
203 public static extern int mono_test_marshal_ccw_reflexive ([MarshalAs (UnmanagedType.Interface)]ITest itest);
205 [DllImport ("libtest")]
206 public static extern int mono_test_marshal_ccw_transitive ([MarshalAs (UnmanagedType.Interface)]ITest itest);
208 [DllImport ("libtest")]
209 public static extern int mono_test_marshal_ccw_itest ([MarshalAs (UnmanagedType.Interface)]ITest itest);
211 [DllImport ("libtest")]
212 public static extern int mono_test_marshal_ccw_itest ([MarshalAs (UnmanagedType.Interface)]ITestPresSig itest);
214 [DllImport("libtest")]
215 public static extern int mono_test_marshal_safearray_out_1dim_vt_bstr_empty ([MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)]out Array array);
217 [DllImport("libtest")]
218 public static extern int mono_test_marshal_safearray_out_1dim_vt_bstr ([MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)]out Array array);
220 [DllImport("libtest")]
221 public static extern int mono_test_marshal_safearray_out_2dim_vt_i4 ([MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)]out Array array);
223 [DllImport("libtest")]
224 public static extern int mono_test_marshal_safearray_out_4dim_vt_i4 ([MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)]out Array array);
226 [DllImport("libtest")]
227 public static extern int mono_test_marshal_safearray_in_byval_1dim_empty ([In, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] Array array);
229 [DllImport("libtest")]
230 public static extern int mono_test_marshal_safearray_in_byval_1dim_vt_i4 ([In, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] Array array);
232 [DllImport("libtest")]
233 public static extern int mono_test_marshal_safearray_in_byval_1dim_vt_mixed ([In, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] Array array);
235 [DllImport("libtest")]
236 public static extern int mono_test_marshal_safearray_in_byval_2dim_vt_i4 ([In, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] Array array);
238 [DllImport("libtest")]
239 public static extern int mono_test_marshal_safearray_in_byval_3dim_vt_bstr ([In, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] Array array);
241 [DllImport("libtest")]
242 public static extern int mono_test_marshal_safearray_in_byref_3dim_vt_bstr ([In, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] ref Array array);
244 [DllImport("libtest")]
245 public static extern int mono_test_marshal_safearray_in_out_byref_1dim_empty ([In, Out, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] ref Array array);
247 [DllImport("libtest")]
248 public static extern int mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr ([In, Out, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] ref Array array);
250 [DllImport("libtest")]
251 public static extern int mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 ([In, Out, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] ref Array array);
253 [DllImport("libtest")]
254 public static extern int mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 ([In, Out, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] Array array);
256 [DllImport("libtest")]
257 public static extern int mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr ([In, Out, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] Array array);
259 [DllImport("libtest")]
260 public static extern int mono_test_marshal_safearray_mixed (
261 [In, Out, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] Array array1,
262 [MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] out Array array2,
263 [In, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] Array array3,
264 [In, Out, MarshalAs (UnmanagedType.SafeArray, SafeArraySubType = VarEnum.VT_VARIANT)] ref Array array4);
266 [DllImport("libtest")]
267 public static extern bool mono_cominterop_is_supported ();
269 public static int Main ()
272 bool isWindows = !(((int)Environment.OSVersion.Platform == 4) ||
273 ((int)Environment.OSVersion.Platform == 128));
275 if (mono_cominterop_is_supported () || isWindows)
280 if (mono_test_marshal_bstr_in ("mono_test_marshal_bstr_in") != 0)
282 if (mono_test_marshal_bstr_out (out str) != 0 || str != "mono_test_marshal_bstr_out")
284 if (mono_test_marshal_bstr_in_null (null) != 0)
286 if (mono_test_marshal_bstr_out_null (out str) != 0 || str != null)
289 #endregion // BSTR Tests
291 #region VARIANT Tests
294 if (mono_test_marshal_variant_in_sbyte ((sbyte)100) != 0)
296 if (mono_test_marshal_variant_in_byte ((byte)100) != 0)
298 if (mono_test_marshal_variant_in_short ((short)314) != 0)
300 if (mono_test_marshal_variant_in_ushort ((ushort)314) != 0)
302 if (mono_test_marshal_variant_in_int ((int)314) != 0)
304 if (mono_test_marshal_variant_in_uint ((uint)314) != 0)
306 if (mono_test_marshal_variant_in_long ((long)314) != 0)
308 if (mono_test_marshal_variant_in_ulong ((ulong)314) != 0)
310 if (mono_test_marshal_variant_in_float ((float)3.14) != 0)
312 if (mono_test_marshal_variant_in_double ((double)3.14) != 0)
314 if (mono_test_marshal_variant_in_bstr ("PI") != 0)
316 if (mono_test_marshal_variant_out_sbyte (out obj) != 0 || (sbyte)obj != 100)
318 if (mono_test_marshal_variant_out_byte (out obj) != 0 || (byte)obj != 100)
320 if (mono_test_marshal_variant_out_short (out obj) != 0 || (short)obj != 314)
322 if (mono_test_marshal_variant_out_ushort (out obj) != 0 || (ushort)obj != 314)
324 if (mono_test_marshal_variant_out_int (out obj) != 0 || (int)obj != 314)
326 if (mono_test_marshal_variant_out_uint (out obj) != 0 || (uint)obj != 314)
328 if (mono_test_marshal_variant_out_long (out obj) != 0 || (long)obj != 314)
330 if (mono_test_marshal_variant_out_ulong (out obj) != 0 || (ulong)obj != 314)
332 if (mono_test_marshal_variant_out_float (out obj) != 0 || ((float)obj - 3.14) / 3.14 > .001)
334 if (mono_test_marshal_variant_out_double (out obj) != 0 || ((double)obj - 3.14) / 3.14 > .001)
336 if (mono_test_marshal_variant_out_bstr (out obj) != 0 || (string)obj != "PI")
339 VarFunc func = new VarFunc (mono_test_marshal_variant_in_callback);
340 if (mono_test_marshal_variant_in_sbyte_unmanaged (func) != 0)
342 if (mono_test_marshal_variant_in_byte_unmanaged (func) != 0)
344 if (mono_test_marshal_variant_in_short_unmanaged (func) != 0)
346 if (mono_test_marshal_variant_in_ushort_unmanaged (func) != 0)
348 if (mono_test_marshal_variant_in_int_unmanaged (func) != 0)
350 if (mono_test_marshal_variant_in_uint_unmanaged (func) != 0)
352 if (mono_test_marshal_variant_in_long_unmanaged (func) != 0)
354 if (mono_test_marshal_variant_in_ulong_unmanaged (func) != 0)
356 if (mono_test_marshal_variant_in_float_unmanaged (func) != 0)
358 if (mono_test_marshal_variant_in_double_unmanaged (func) != 0)
360 if (mono_test_marshal_variant_in_bstr_unmanaged (func) != 0)
362 if (mono_test_marshal_variant_in_bool_true_unmanaged (func) != 0)
365 VarRefFunc reffunc = new VarRefFunc (mono_test_marshal_variant_out_callback);
366 if (mono_test_marshal_variant_out_sbyte_unmanaged (reffunc) != 0)
368 if (mono_test_marshal_variant_out_byte_unmanaged (reffunc) != 0)
370 if (mono_test_marshal_variant_out_short_unmanaged (reffunc) != 0)
372 if (mono_test_marshal_variant_out_ushort_unmanaged (reffunc) != 0)
374 if (mono_test_marshal_variant_out_int_unmanaged (reffunc) != 0)
376 if (mono_test_marshal_variant_out_uint_unmanaged (reffunc) != 0)
378 if (mono_test_marshal_variant_out_long_unmanaged (reffunc) != 0)
380 if (mono_test_marshal_variant_out_ulong_unmanaged (reffunc) != 0)
382 if (mono_test_marshal_variant_out_float_unmanaged (reffunc) != 0)
384 if (mono_test_marshal_variant_out_double_unmanaged (reffunc) != 0)
386 if (mono_test_marshal_variant_out_bstr_unmanaged (reffunc) != 0)
388 if (mono_test_marshal_variant_out_bool_true_unmanaged (reffunc) != 0)
391 #endregion // VARIANT Tests
393 #region Runtime Callable Wrapper Tests
396 if (mono_test_marshal_com_object_create (out pUnk) != 0)
399 if (mono_test_marshal_com_object_ref_count (pUnk) != 1)
402 if (Marshal.AddRef (pUnk) != 2)
405 if (mono_test_marshal_com_object_ref_count (pUnk) != 2)
408 if (Marshal.Release (pUnk) != 1)
411 if (mono_test_marshal_com_object_ref_count (pUnk) != 1)
414 object com_obj = Marshal.GetObjectForIUnknown (pUnk);
419 ITest itest = com_obj as ITest;
425 if (mono_test_marshal_com_object_same (out pUnk2) != 0)
428 object com_obj2 = Marshal.GetObjectForIUnknown (pUnk2);
430 if (com_obj != com_obj2)
433 if (!com_obj.Equals (com_obj2))
437 if (mono_test_marshal_com_object_create (out pUnk3) != 0)
440 object com_obj3 = Marshal.GetObjectForIUnknown (pUnk3);
441 if (com_obj == com_obj3)
444 if (com_obj.Equals (com_obj3))
447 // com_obj & com_obj2 share a RCW
448 if (Marshal.ReleaseComObject (com_obj2) != 1)
451 // com_obj3 should only have one RCW
452 if (Marshal.ReleaseComObject (com_obj3) != 0)
455 IntPtr iunknown = Marshal.GetIUnknownForObject (com_obj);
456 if (iunknown == IntPtr.Zero)
459 if (pUnk != iunknown)
462 if (TestITest (itest) != 0)
465 if (TestITestPresSig (itest as ITestPresSig) != 0)
468 if (TestITestDelegate (itest) != 0)
471 itest = new TestClass ();
473 if (TestITest (itest) != 0)
476 #endregion // Runtime Callable Wrapper Tests
478 #region COM Callable Wrapper Tests
480 ManagedTest test = new ManagedTest ();
482 mono_test_marshal_ccw_itest (test);
484 if (test.Status != 0)
487 ManagedTestPresSig test_pres_sig = new ManagedTestPresSig ();
489 mono_test_marshal_ccw_itest (test_pres_sig);
491 #endregion // COM Callable Wrapper Tests
493 #region SAFEARRAY tests
500 if ((mono_test_marshal_safearray_out_1dim_vt_bstr_empty (out array) != 0) || (array.Rank != 1) || (array.Length != 0))
503 if ((mono_test_marshal_safearray_out_1dim_vt_bstr (out array) != 0) || (array.Rank != 1) || (array.Length != 10))
505 for (int i = 0; i < 10; ++i) {
506 if (i != Convert.ToInt32 (array.GetValue (i)))
510 if ((mono_test_marshal_safearray_out_2dim_vt_i4 (out array) != 0) || (array.Rank != 2))
512 if ( (array.GetLowerBound (0) != 0) || (array.GetUpperBound (0) != 3)
513 || (array.GetLowerBound (1) != 0) || (array.GetUpperBound (1) != 2))
515 for (int i = array.GetLowerBound (0); i <= array.GetUpperBound (0); ++i)
517 for (int j = array.GetLowerBound (1); j <= array.GetUpperBound (1); ++j) {
518 if ((i + 1) * 10 + (j + 1) != (int)array.GetValue (new long[] { i, j }))
523 if ((mono_test_marshal_safearray_out_4dim_vt_i4 (out array) != 0) || (array.Rank != 4))
525 if ( (array.GetLowerBound (0) != 15) || (array.GetUpperBound (0) != 24)
526 || (array.GetLowerBound (1) != 20) || (array.GetUpperBound (1) != 22)
527 || (array.GetLowerBound (2) != 5) || (array.GetUpperBound (2) != 10)
528 || (array.GetLowerBound (3) != 12) || (array.GetUpperBound (3) != 18) )
532 for (int i = array.GetLowerBound (3); i <= array.GetUpperBound (3); ++i) {
533 for (int j = array.GetLowerBound (2); j <= array.GetUpperBound (2); ++j) {
534 for (int k = array.GetLowerBound (1); k <= array.GetUpperBound (1); ++k) {
535 for (int l = array.GetLowerBound (0); l <= array.GetUpperBound (0); ++l) {
536 if (index != (int)array.GetValue (new long[] { l, k, j, i }))
546 array = new object[] { };
547 if (mono_test_marshal_safearray_in_byval_1dim_empty (array) != 0)
550 array = new object[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
551 if (mono_test_marshal_safearray_in_byval_1dim_vt_i4 (array) != 0)
554 array = new object[] { 0, "1", 2, "3", 4, "5", 6, "7", 8, "9", 10, "11", 12 };
555 if (mono_test_marshal_safearray_in_byval_1dim_vt_mixed (array) != 0)
557 if ((int)array.GetValue (0) != 0)
560 array = new object[,] { { 11, 12, 13, 14 }, { 21, 22, 23, 24 } };
561 if (mono_test_marshal_safearray_in_byval_2dim_vt_i4 (array) != 0)
563 if ((int)array.GetValue (new int[] { 0, 0 }) != 11)
566 array = new object[,,] { { { "111", "112", "113" }, { "121", "122", "123" } }, { { "211", "212", "213" }, { "221", "222", "223" } } };
567 if (mono_test_marshal_safearray_in_byval_3dim_vt_bstr (array) != 0)
569 if ((string)array.GetValue (new int[] { 0, 0, 0 }) != "111")
572 array = new object[,,] { { { "111", "112", "113" }, { "121", "122", "123" } }, { { "211", "212", "213" }, { "221", "222", "223" } } };
573 if ((mono_test_marshal_safearray_in_byref_3dim_vt_bstr (ref array) != 0) || (array.Rank != 3) || (array.Length != 12))
575 if ((string)array.GetValue (new int[] { 0, 0, 0 }) != "111")
580 array = new object[] { };
581 if ((mono_test_marshal_safearray_in_out_byref_1dim_empty (ref array) != 0) || (array.Rank != 1) || (array.Length != 8))
583 for (int i = 0; i < 8; ++i)
585 if (i != Convert.ToInt32 (array.GetValue (i)))
589 array = new object[,,] { { { "111", "112", "113" }, { "121", "122", "123" } }, { { "211", "212", "213" }, { "221", "222", "223" } } };
590 if ((mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr (ref array) != 0) || (array.Rank != 1) || (array.Length != 8))
592 for (int i = 0; i < 8; ++i)
594 if (i != Convert.ToInt32 (array.GetValue (i)))
598 array = new object[] { 1 };
599 if ((mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 (ref array) != 0) || (array.Rank != 1) || (array.Length != 1))
603 if (Convert.ToInt32 (array.GetValue (0)) != -1)
608 array = new object[] { 1 };
609 if ((mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (array) != 0) || (array.Rank != 1) || (array.Length != 1))
613 if (Convert.ToInt32 (array.GetValue (0)) != 12345)
616 array = new object[,,] { { { "111", "112", "113" }, { "121", "122", "123" } }, { { "211", "212", "213" }, { "221", "222", "223" } } };
617 if ((mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr (array) != 0) || (array.Rank != 3) || (array.Length != 12))
621 if (Convert.ToInt32 (array.GetValue (new int[] { 1, 1, 1 })) != 111)
623 if (Convert.ToInt32 (array.GetValue (new int[] { 1, 1, 2 })) != 333)
625 if (Convert.ToString(array.GetValue (new int[] { 0, 1, 0 })) != "ABCDEFG")
628 /* Multiple safearray parameters with various types and options */
630 Array array1 = new object[] { 1 };
631 Array array2 = new object[,] { { 11, 12, 13, 14 }, { 21, 22, 23, 24 } };
632 Array array3 = new object[] { 0, "1", 2, "3", 4, "5", 6, "7", 8, "9", 10, "11", 12 };
633 Array array4 = new object[,,] { { { "111", "112", "113" }, { "121", "122", "123" } }, { { "211", "212", "213" }, { "221", "222", "223" } } };
634 if ( (mono_test_marshal_safearray_mixed (array1, out array2, array3, ref array4) != 0)
635 || (array1.Rank != 1) || (array1.Length != 1) || (Convert.ToInt32 (array1.GetValue (0)) != 12345)
636 || (array2.Rank != 1) || (array2.Length != 10)
637 || (array4.Rank != 1) || (array4.Length != 8)
642 for (int i = 0; i < 10; ++i)
644 if (i != Convert.ToInt32 (array2.GetValue (i)))
647 if ((int)array3.GetValue (0) != 0)
649 for (int i = 0; i < 8; ++i)
651 if (i != Convert.ToInt32 (array4.GetValue (i)))
655 #endregion // SafeArray Tests
663 [Guid ("00000000-0000-0000-0000-000000000001")]
664 [InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
665 public interface ITest
667 // properties need to go first since mcs puts them there
670 [return: MarshalAs (UnmanagedType.Interface)]
671 [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId (5242884)]
675 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
676 void SByteIn (sbyte val);
677 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
678 void ByteIn (byte val);
679 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
680 void ShortIn (short val);
681 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
682 void UShortIn (ushort val);
683 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
684 void IntIn (int val);
685 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
686 void UIntIn (uint val);
687 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
688 void LongIn (long val);
689 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
690 void ULongIn (ulong val);
691 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
692 void FloatIn (float val);
693 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
694 void DoubleIn (double val);
695 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
696 void ITestIn ([MarshalAs (UnmanagedType.Interface)]ITest val);
697 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
698 void ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITest val);
702 [Guid ("00000000-0000-0000-0000-000000000001")]
703 [InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
704 public interface ITestPresSig
706 // properties need to go first since mcs puts them there
709 [return: MarshalAs (UnmanagedType.Interface)]
710 [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId (5242884)]
714 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
716 int SByteIn (sbyte val);
717 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
719 int ByteIn (byte val);
720 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
722 int ShortIn (short val);
723 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
725 int UShortIn (ushort val);
726 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
729 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
731 int UIntIn (uint val);
732 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
734 int LongIn (long val);
735 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
737 int ULongIn (ulong val);
738 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
740 int FloatIn (float val);
741 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
743 int DoubleIn (double val);
744 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
746 int ITestIn ([MarshalAs (UnmanagedType.Interface)]ITestPresSig val);
747 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
749 int ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITestPresSig val);
752 [System.Runtime.InteropServices.GuidAttribute ("00000000-0000-0000-0000-000000000002")]
753 [System.Runtime.InteropServices.ComImportAttribute ()]
754 [System.Runtime.InteropServices.ClassInterfaceAttribute (ClassInterfaceType.None)]
755 public class _TestClass : ITest
757 // properties need to go first since mcs puts them there
758 public virtual extern ITest Test
760 [return: MarshalAs (UnmanagedType.Interface)]
761 [MethodImpl (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime), DispId (5242884)]
765 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
766 public virtual extern void SByteIn (sbyte val);
767 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
768 public virtual extern void ByteIn (byte val);
769 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
770 public virtual extern void ShortIn (short val);
771 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
772 public virtual extern void UShortIn (ushort val);
773 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
774 public virtual extern void IntIn (int val);
775 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
776 public virtual extern void UIntIn (uint val);
777 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
778 public virtual extern void LongIn (long val);
779 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
780 public virtual extern void ULongIn (ulong val);
781 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
782 public virtual extern void FloatIn (float val);
783 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
784 public virtual extern void DoubleIn (double val);
785 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
786 public virtual extern void ITestIn ([MarshalAs (UnmanagedType.Interface)]ITest val);
787 [MethodImplAttribute (MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
788 public virtual extern void ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITest val);
791 [System.Runtime.InteropServices.GuidAttribute ("00000000-0000-0000-0000-000000000002")]
792 public class TestClass : _TestClass
796 ExtensibleClassFactory.RegisterObjectCreationCallback (new ObjectCreationDelegate (CreateObject)); ;
798 private static System.IntPtr CreateObject (System.IntPtr aggr)
801 mono_test_marshal_com_object_create (out pUnk3);
807 delegate void SByteInDelegate (sbyte val);
808 delegate void ByteInDelegate (byte val);
809 delegate void ShortInDelegate (short val);
810 delegate void UShortInDelegate (ushort val);
811 delegate void IntInDelegate (int val);
812 delegate void UIntInDelegate (uint val);
813 delegate void LongInDelegate (long val);
814 delegate void ULongInDelegate (ulong val);
815 delegate void FloatInDelegate (float val);
816 delegate void DoubleInDelegate (double val);
817 delegate void ITestInDelegate (ITest val);
818 delegate void ITestOutDelegate (out ITest val);
820 public class ManagedTestPresSig : ITestPresSig
821 { // properties need to go first since mcs puts them there
822 public ITestPresSig Test
826 return new ManagedTestPresSig ();
830 public int SByteIn (sbyte val)
837 public int ByteIn (byte val)
844 public int ShortIn (short val)
851 public int UShortIn (ushort val)
858 public int IntIn (int val)
865 public int UIntIn (uint val)
872 public int LongIn (long val)
879 public int ULongIn (ulong val)
886 public int FloatIn (float val)
888 if (Math.Abs (val - 3.14f) > .000001)
893 public int DoubleIn (double val)
895 if (Math.Abs (val - 3.14f) > .000001)
900 public int ITestIn ([MarshalAs (UnmanagedType.Interface)]ITestPresSig val)
904 if (null == val as ManagedTestPresSig)
909 public int ITestOut ([MarshalAs (UnmanagedType.Interface)]out ITestPresSig val)
911 val = new ManagedTestPresSig ();
916 public class ManagedTest : ITest
918 private int status = 0;
921 get { return status; }
923 public void SByteIn (sbyte val)
929 public void ByteIn (byte val)
935 public void ShortIn (short val)
941 public void UShortIn (ushort val)
947 public void IntIn (int val)
953 public void UIntIn (uint val)
959 public void LongIn (long val)
965 public void ULongIn (ulong val)
971 public void FloatIn (float val)
973 if (Math.Abs (val - 3.14f) > .000001)
977 public void DoubleIn (double val)
979 if (Math.Abs (val - 3.14) > .000001)
983 public void ITestIn (ITest val)
987 if (null == val as ManagedTest)
991 public void ITestOut (out ITest val)
993 val = new ManagedTest ();
1000 return new ManagedTest ();
1005 public static int mono_test_marshal_variant_in_callback (VarEnum vt, object obj)
1010 if (obj.GetType () != typeof (sbyte))
1012 if ((sbyte)obj != -100)
1015 case VarEnum.VT_UI1:
1016 if (obj.GetType () != typeof (byte))
1018 if ((byte)obj != 100)
1022 if (obj.GetType () != typeof (short))
1024 if ((short)obj != -100)
1027 case VarEnum.VT_UI2:
1028 if (obj.GetType () != typeof (ushort))
1030 if ((ushort)obj != 100)
1034 if (obj.GetType () != typeof (int))
1036 if ((int)obj != -100)
1039 case VarEnum.VT_UI4:
1040 if (obj.GetType () != typeof (uint))
1042 if ((uint)obj != 100)
1046 if (obj.GetType () != typeof (long))
1048 if ((long)obj != -100)
1051 case VarEnum.VT_UI8:
1052 if (obj.GetType () != typeof (ulong))
1054 if ((ulong)obj != 100)
1058 if (obj.GetType () != typeof (float))
1060 if (Math.Abs ((float)obj - 3.14f) > 1e-10)
1064 if (obj.GetType () != typeof (double))
1066 if (Math.Abs ((double)obj - 3.14) > 1e-10)
1069 case VarEnum.VT_BSTR:
1070 if (obj.GetType () != typeof (string))
1072 if ((string)obj != "PI")
1075 case VarEnum.VT_BOOL:
1076 if (obj.GetType () != typeof (bool))
1078 if ((bool)obj != true)
1085 public static int mono_test_marshal_variant_out_callback (VarEnum vt, ref object obj)
1091 case VarEnum.VT_UI1:
1097 case VarEnum.VT_UI2:
1103 case VarEnum.VT_UI4:
1109 case VarEnum.VT_UI8:
1118 case VarEnum.VT_BSTR:
1121 case VarEnum.VT_BOOL:
1128 public static int TestITest (ITest itest)
1132 itest.SByteIn (-100);
1134 itest.ShortIn (-100);
1135 itest.UShortIn (100);
1138 itest.LongIn (-100);
1139 itest.ULongIn (100);
1140 itest.FloatIn (3.14f);
1141 itest.DoubleIn (3.14);
1142 itest.ITestIn (itest);
1143 itest.ITestOut (out itest2);
1145 catch (Exception ex) {
1151 public static int TestITestPresSig (ITestPresSig itest)
1153 ITestPresSig itest2;
1154 if (itest.SByteIn (-100) != 0)
1156 if (itest.ByteIn (100) != 0)
1158 if (itest.ShortIn (-100) != 0)
1160 if (itest.UShortIn (100) != 0)
1162 if (itest.IntIn (-100) != 0)
1164 if (itest.UIntIn (100) != 0)
1166 if (itest.LongIn (-100) != 0)
1168 if (itest.ULongIn (100) != 0)
1170 if (itest.FloatIn (3.14f) != 0)
1172 if (itest.DoubleIn (3.14) != 0)
1174 if (itest.ITestIn (itest) != 0)
1176 if (itest.ITestOut (out itest2) != 0)
1181 public static int TestITestDelegate (ITest itest)
1186 SByteInDelegate SByteInFcn= itest.SByteIn;
1187 ByteInDelegate ByteInFcn = itest.ByteIn;
1188 UShortInDelegate UShortInFcn = itest.UShortIn;
1189 IntInDelegate IntInFcn = itest.IntIn;
1190 UIntInDelegate UIntInFcn = itest.UIntIn;
1191 LongInDelegate LongInFcn = itest.LongIn;
1193 ULongInDelegate ULongInFcn = itest.ULongIn;
1194 FloatInDelegate FloatInFcn = itest.FloatIn;
1195 DoubleInDelegate DoubleInFcn = itest.DoubleIn;
1196 ITestInDelegate ITestInFcn = itest.ITestIn;
1197 ITestOutDelegate ITestOutFcn = itest.ITestOut;
1209 ITestOutFcn (out itest2);