19 #define STDCALL __stdcall
25 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
29 extern __declspec(dllimport) void __stdcall CoTaskMemFree(void *ptr);
32 typedef int (STDCALL *SimpleDelegate) (int a);
34 #if defined(WIN32) && defined (_MSC_VER)
35 #define LIBTEST_API __declspec(dllexport)
40 static void marshal_free (void *ptr)
49 static void* marshal_alloc (gsize size)
52 return CoTaskMemAlloc (size);
54 return g_malloc (size);
58 static void* marshal_alloc0 (gsize size)
61 void* ptr = CoTaskMemAlloc (size);
65 return g_malloc0 (size);
69 static char* marshal_strdup (const char *str)
79 buf = (char *) CoTaskMemAlloc (len + 1);
80 return strcpy (buf, str);
82 return g_strdup (str);
86 static gunichar2* marshal_bstr_alloc(const gchar* str)
89 gunichar2* ret = NULL;
90 gunichar2* temp = NULL;
91 temp = g_utf8_to_utf16 (str, -1, NULL, NULL, NULL);
92 ret = SysAllocString (temp);
97 int slen = strlen (str);
99 /* allocate len + 1 utf16 characters plus 4 byte integer for length*/
100 ret = g_malloc ((slen + 1) * sizeof(gunichar2) + sizeof(guint32));
103 temp = g_utf8_to_utf16 (str, -1, NULL, NULL, NULL);
104 memcpy (ret + sizeof(guint32), temp, slen * sizeof(gunichar2));
105 * ((guint32 *) ret) = slen * sizeof(gunichar2);
106 ret [4 + slen * sizeof(gunichar2)] = 0;
107 ret [5 + slen * sizeof(gunichar2)] = 0;
109 return (gunichar2*)(ret + 4);
113 #define marshal_new0(type,size) ((type *) marshal_alloc0 (sizeof (type)* (size)))
115 LIBTEST_API int STDCALL
116 mono_cominterop_is_supported (void)
118 #if defined(TARGET_X86) || defined(TARGET_AMD64)
124 LIBTEST_API unsigned short* STDCALL
125 test_lpwstr_marshal (unsigned short* chars, long length)
130 res = marshal_alloc (2 * (length + 1));
132 // printf("test_lpwstr_marshal()\n");
134 while ( i < length ) {
135 // printf("X|%u|\n", chars[i]);
146 LIBTEST_API void STDCALL
147 test_lpwstr_marshal_out (unsigned short** chars)
150 const char abc[] = "ABC";
151 glong len = strlen(abc);
153 *chars = marshal_alloc (2 * (len + 1));
156 (*chars) [i] = abc[i];
169 LIBTEST_API int STDCALL
170 mono_union_test_1 (union_test_1_type u1) {
171 // printf ("Got values %d %d %d\n", u1.b, u1.a, u1.c);
172 return u1.a + u1.b + u1.c;
175 LIBTEST_API int STDCALL
176 mono_return_int (int a) {
177 // printf ("Got value %d\n", a);
181 LIBTEST_API float STDCALL
182 mono_test_marshal_pass_return_float (float f) {
191 LIBTEST_API int STDCALL
192 mono_return_int_ss (struct ss a) {
193 // printf ("Got value %d\n", a.i);
197 LIBTEST_API struct ss STDCALL
198 mono_return_ss (struct ss a) {
199 // printf ("Got value %d\n", a.i);
209 LIBTEST_API struct sc1 STDCALL
210 mono_return_sc1 (struct sc1 a) {
211 // printf ("Got value %d\n", a.c[0]);
222 LIBTEST_API struct sc3 STDCALL
223 mono_return_sc3 (struct sc3 a) {
224 // printf ("Got values %d %d %d\n", a.c[0], a.c[1], a.c[2]);
236 LIBTEST_API struct sc5 STDCALL
237 mono_return_sc5 (struct sc5 a) {
238 // printf ("Got values %d %d %d %d %d\n", a.c[0], a.c[1], a.c[2], a.c[3], a.c[4]);
253 LIBTEST_API int STDCALL
254 mono_return_int_su (union su a) {
255 // printf ("Got value %d\n", a.i1);
259 LIBTEST_API int STDCALL
260 mono_test_many_int_arguments (int a, int b, int c, int d, int e,
261 int f, int g, int h, int i, int j);
262 LIBTEST_API short STDCALL
263 mono_test_many_short_arguments (short a, short b, short c, short d, short e,
264 short f, short g, short h, short i, short j);
265 LIBTEST_API char STDCALL
266 mono_test_many_char_arguments (char a, char b, char c, char d, char e,
267 char f, char g, char h, char i, char j);
269 LIBTEST_API int STDCALL
270 mono_test_many_int_arguments (int a, int b, int c, int d, int e, int f, int g, int h, int i, int j)
272 return a + b + c + d + e + f + g + h + i + j;
275 LIBTEST_API short STDCALL
276 mono_test_many_short_arguments (short a, short b, short c, short d, short e, short f, short g, short h, short i, short j)
278 return a + b + c + d + e + f + g + h + i + j;
281 LIBTEST_API char STDCALL
282 mono_test_many_byte_arguments (char a, char b, char c, char d, char e, char f, char g, char h, char i, char j)
284 return a + b + c + d + e + f + g + h + i + j;
287 LIBTEST_API float STDCALL
288 mono_test_many_float_arguments (float a, float b, float c, float d, float e, float f, float g, float h, float i, float j)
290 return a + b + c + d + e + f + g + h + i + j;
293 LIBTEST_API double STDCALL
294 mono_test_many_double_arguments (double a, double b, double c, double d, double e, double f, double g, double h, double i, double j)
296 return a + b + c + d + e + f + g + h + i + j;
299 LIBTEST_API double STDCALL
300 mono_test_split_double_arguments (double a, double b, float c, double d, double e)
302 return a + b + c + d + e;
305 LIBTEST_API int STDCALL
306 mono_test_puts_static (char *s)
308 // printf ("TEST %s\n", s);
312 typedef int (STDCALL *SimpleDelegate3) (int a, int b);
314 LIBTEST_API int STDCALL
315 mono_invoke_delegate (SimpleDelegate3 delegate)
319 // printf ("start invoke %p\n", delegate);
321 res = delegate (2, 3);
323 // printf ("end invoke\n");
328 LIBTEST_API int STDCALL
329 mono_invoke_simple_delegate (SimpleDelegate d)
334 LIBTEST_API int STDCALL
335 mono_test_marshal_char (short a1)
343 LIBTEST_API void STDCALL
344 mono_test_marshal_char_array (gunichar2 *s)
346 const char m[] = "abcdef";
350 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
358 LIBTEST_API int STDCALL
359 mono_test_marshal_ansi_char_array (char *s)
361 const char m[] = "abcdef";
363 if (strncmp ("qwer", s, 4))
366 memcpy (s, m, sizeof (m));
370 LIBTEST_API int STDCALL
371 mono_test_marshal_unicode_char_array (gunichar2 *s)
373 const char m[] = "abcdef";
374 const char expected[] = "qwer";
378 s1 = g_utf8_to_utf16 (m, -1, NULL, &len1, NULL);
379 s2 = g_utf8_to_utf16 (expected, -1, NULL, &len2, NULL);
383 if (memcmp (s, s2, len2))
386 memcpy (s, s1, len1);
391 LIBTEST_API int STDCALL
392 mono_test_empty_pinvoke (int i)
397 LIBTEST_API int STDCALL
398 mono_test_marshal_bool_byref (int a, int *b, int c)
407 LIBTEST_API int STDCALL
408 mono_test_marshal_bool_in_as_I1_U1 (char bTrue, char bFalse)
417 LIBTEST_API int STDCALL
418 mono_test_marshal_bool_out_as_I1_U1 (char* bTrue, char* bFalse)
420 if (!bTrue || !bFalse)
429 LIBTEST_API int STDCALL
430 mono_test_marshal_bool_ref_as_I1_U1 (char* bTrue, char* bFalse)
432 if (!bTrue || !bFalse)
446 LIBTEST_API int STDCALL
447 mono_test_marshal_array (int *a1)
451 for (i = 0; i < 50; i++)
457 LIBTEST_API int STDCALL
458 mono_test_marshal_inout_array (int *a1)
462 for (i = 0; i < 50; i++) {
464 a1 [i] = 50 - a1 [i];
470 LIBTEST_API int /* cdecl */
471 mono_test_marshal_inout_array_cdecl (int *a1)
473 return mono_test_marshal_inout_array (a1);
476 LIBTEST_API int STDCALL
477 mono_test_marshal_out_array (int *a1)
481 for (i = 0; i < 50; i++) {
488 LIBTEST_API int STDCALL
489 mono_test_marshal_inout_nonblittable_array (gunichar2 *a1)
493 for (i = 0; i < 10; i++) {
513 LIBTEST_API simplestruct STDCALL
514 mono_test_return_vtype (int i)
517 static gunichar2 test2 [] = { 'T', 'E', 'S', 'T', '2', 0 };
528 LIBTEST_API void STDCALL
529 mono_test_delegate_struct (void)
531 // printf ("TEST\n");
534 typedef char* (STDCALL *ReturnStringDelegate) (const char *s);
536 LIBTEST_API char * STDCALL
537 mono_test_return_string (ReturnStringDelegate func)
541 // printf ("mono_test_return_string\n");
546 // printf ("got string: %s\n", res);
547 return marshal_strdup ("12345");
550 typedef int (STDCALL *RefVTypeDelegate) (int a, simplestruct *ss, int b);
552 LIBTEST_API int STDCALL
553 mono_test_ref_vtype (int a, simplestruct *ss, int b, RefVTypeDelegate func)
555 if (a == 1 && b == 2 && ss->a == 0 && ss->b == 1 && ss->c == 0 &&
556 !strcmp (ss->d, "TEST1")) {
562 return func (a, ss, b);
568 typedef int (STDCALL *OutVTypeDelegate) (int a, simplestruct *ss, int b);
570 LIBTEST_API int STDCALL
571 mono_test_marshal_out_struct (int a, simplestruct *ss, int b, OutVTypeDelegate func)
573 /* Check that the input pointer is ignored */
574 ss->d = (gpointer)0x12345678;
578 if (ss->a && ss->b && ss->c && !strcmp (ss->d, "TEST3"))
586 SimpleDelegate func, func2, func3;
589 LIBTEST_API DelegateStruct STDCALL
590 mono_test_marshal_delegate_struct (DelegateStruct ds)
594 res.a = ds.func (ds.a) + ds.func2 (ds.a) + (ds.func3 == NULL ? 0 : 1);
596 res.func2 = ds.func2;
602 LIBTEST_API int STDCALL
603 mono_test_marshal_struct (simplestruct ss)
605 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
606 !strcmp (ss.d, "TEST"))
612 LIBTEST_API int STDCALL
613 mono_test_marshal_byref_struct (simplestruct *ss, int a, int b, int c, char *d)
615 gboolean res = (ss->a == a && ss->b == b && ss->c == c && strcmp (ss->d, d) == 0);
617 marshal_free ((char*)ss->d);
622 ss->d = marshal_strdup ("DEF");
638 LIBTEST_API int STDCALL
639 mono_test_marshal_struct2 (simplestruct2 ss)
641 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
642 !strcmp (ss.d, "TEST") &&
643 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
649 /* on HP some of the struct should be on the stack and not in registers */
650 LIBTEST_API int STDCALL
651 mono_test_marshal_struct2_2 (int i, int j, int k, simplestruct2 ss)
653 if (i != 10 || j != 11 || k != 12)
655 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
656 !strcmp (ss.d, "TEST") &&
657 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
663 LIBTEST_API int STDCALL
664 mono_test_marshal_lpstruct (simplestruct *ss)
666 if (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
667 !strcmp (ss->d, "TEST"))
673 LIBTEST_API int STDCALL
674 mono_test_marshal_lpstruct_blittable (point *p)
676 if (p->x == 1.0 && p->y == 2.0)
682 LIBTEST_API int STDCALL
683 mono_test_marshal_struct_array (simplestruct2 *ss)
685 if (! (ss[0].a == 0 && ss[0].b == 1 && ss[0].c == 0 &&
686 !strcmp (ss[0].d, "TEST") &&
687 ss[0].e == 99 && ss[0].f == 1.5 && ss[0].g == 42 && ss[0].h == (guint64)123))
690 if (! (ss[1].a == 0 && ss[1].b == 0 && ss[1].c == 0 &&
691 !strcmp (ss[1].d, "TEST2") &&
692 ss[1].e == 100 && ss[1].f == 2.5 && ss[1].g == 43 && ss[1].h == (guint64)124))
698 typedef struct long_align_struct {
704 LIBTEST_API int STDCALL
705 mono_test_marshal_long_align_struct_array (long_align_struct *ss)
707 return ss[0].a + ss[0].b + ss[0].c + ss[1].a + ss[1].b + ss[1].c;
710 LIBTEST_API simplestruct2 * STDCALL
711 mono_test_marshal_class (int i, int j, int k, simplestruct2 *ss, int l)
718 if (i != 10 || j != 11 || k != 12 || l != 14)
720 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
721 !strcmp (ss->d, "TEST") &&
722 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
725 res = marshal_new0 (simplestruct2, 1);
726 memcpy (res, ss, sizeof (simplestruct2));
727 res->d = marshal_strdup ("TEST");
731 LIBTEST_API int STDCALL
732 mono_test_marshal_byref_class (simplestruct2 **ssp)
734 simplestruct2 *ss = *ssp;
737 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
738 !strcmp (ss->d, "TEST") &&
739 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
742 res = marshal_new0 (simplestruct2, 1);
743 memcpy (res, ss, sizeof (simplestruct2));
744 res->d = marshal_strdup ("TEST-RES");
756 /* Yes, this is correct, we are only trying to determine the value of the stack here */
761 LIBTEST_API int STDCALL
762 reliable_delegate (int a)
768 * Checks whether get_sp() works as expected. It doesn't work with gcc-2.95.3 on linux.
771 is_get_sp_reliable (void)
775 reliable_delegate(1);
777 reliable_delegate(1);
782 LIBTEST_API int STDCALL
783 mono_test_marshal_delegate (SimpleDelegate delegate)
787 /* Check that the delegate wrapper is stdcall */
792 if (is_get_sp_reliable())
793 g_assert (sp1 == sp2);
798 static int STDCALL inc_cb (int i)
803 LIBTEST_API int STDCALL
804 mono_test_marshal_out_delegate (SimpleDelegate *delegate)
811 LIBTEST_API SimpleDelegate STDCALL
812 mono_test_marshal_return_delegate (SimpleDelegate delegate)
818 return_plus_one (int i)
823 LIBTEST_API SimpleDelegate STDCALL
824 mono_test_marshal_return_delegate_2 (void)
826 return return_plus_one;
829 typedef simplestruct (STDCALL *SimpleDelegate2) (simplestruct ss);
832 is_utf16_equals (gunichar2 *s1, const char *s2)
837 s = g_utf16_to_utf8 (s1, -1, NULL, NULL, NULL);
838 res = strcmp (s, s2);
844 LIBTEST_API int STDCALL
845 mono_test_marshal_delegate2 (SimpleDelegate2 delegate)
847 simplestruct ss, res;
853 ss.d2 = g_utf8_to_utf16 ("TEST2", -1, NULL, NULL, NULL);
856 if (! (res.a && !res.b && res.c && !strcmp (res.d, "TEST-RES") && is_utf16_equals (res.d2, "TEST2-RES")))
862 typedef simplestruct* (STDCALL *SimpleDelegate4) (simplestruct *ss);
864 LIBTEST_API int STDCALL
865 mono_test_marshal_delegate4 (SimpleDelegate4 delegate)
876 res = delegate (&ss);
880 /* Check return value */
881 if (! (!res->a && res->b && !res->c && !strcmp (res->d, "TEST")))
884 /* Check NULL argument and NULL result */
885 res = delegate (NULL);
892 typedef int (STDCALL *SimpleDelegate5) (simplestruct **ss);
894 LIBTEST_API int STDCALL
895 mono_test_marshal_delegate5 (SimpleDelegate5 delegate)
908 res = delegate (&ptr);
912 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
918 LIBTEST_API int STDCALL
919 mono_test_marshal_delegate6 (SimpleDelegate5 delegate)
923 res = delegate (NULL);
928 typedef int (STDCALL *SimpleDelegate7) (simplestruct **ss);
930 LIBTEST_API int STDCALL
931 mono_test_marshal_delegate7 (SimpleDelegate7 delegate)
936 /* Check that the input pointer is ignored */
937 ptr = (gpointer)0x12345678;
939 res = delegate (&ptr);
943 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
949 typedef int (STDCALL *InOutByvalClassDelegate) (simplestruct *ss);
951 LIBTEST_API int STDCALL
952 mono_test_marshal_inout_byval_class_delegate (InOutByvalClassDelegate delegate)
960 ss.d = g_strdup_printf ("%s", "FOO");
962 res = delegate (&ss);
966 if (!(ss.a && !ss.b && ss.c && !strcmp (ss.d, "RES")))
972 typedef int (STDCALL *SimpleDelegate8) (gunichar2 *s);
974 LIBTEST_API int STDCALL
975 mono_test_marshal_delegate8 (SimpleDelegate8 delegate, gunichar2 *s)
980 typedef int (STDCALL *return_int_fnt) (int i);
981 typedef int (STDCALL *SimpleDelegate9) (return_int_fnt d);
983 LIBTEST_API int STDCALL
984 mono_test_marshal_delegate9 (SimpleDelegate9 delegate, gpointer ftn)
986 return delegate (ftn);
995 LIBTEST_API int STDCALL
996 mono_test_marshal_delegate10 (SimpleDelegate9 delegate)
998 return delegate (return_self);
1001 typedef int (STDCALL *PrimitiveByrefDelegate) (int *i);
1003 LIBTEST_API int STDCALL
1004 mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate delegate)
1008 int res = delegate (&i);
1018 typedef int (STDCALL *return_int_delegate) (int i);
1020 typedef return_int_delegate (STDCALL *ReturnDelegateDelegate) (void);
1022 LIBTEST_API int STDCALL
1023 mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d)
1028 LIBTEST_API int STDCALL
1029 mono_test_marshal_stringbuilder (char *s, int n)
1031 const char m[] = "This is my message. Isn't it nice?";
1033 if (strcmp (s, "ABCD") != 0)
1040 LIBTEST_API int STDCALL
1041 mono_test_marshal_stringbuilder_default (char *s, int n)
1043 const char m[] = "This is my message. Isn't it nice?";
1050 LIBTEST_API int STDCALL
1051 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
1053 const char m[] = "This is my message. Isn't it nice?";
1057 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1059 len = (len * 2) + 2;
1062 memcpy (s, s2, len);
1069 LIBTEST_API void STDCALL
1070 mono_test_marshal_stringbuilder_out (char **s)
1072 const char m[] = "This is my message. Isn't it nice?";
1075 str = marshal_alloc (strlen (m) + 1);
1076 memcpy (str, m, strlen (m) + 1);
1081 LIBTEST_API int STDCALL
1082 mono_test_marshal_stringbuilder_out_unicode (gunichar2 **s)
1084 const char m[] = "This is my message. Isn't it nice?";
1088 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1090 len = (len * 2) + 2;
1091 *s = marshal_alloc (len);
1092 memcpy (*s, s2, len);
1105 LIBTEST_API int STDCALL
1106 mono_test_marshal_empty_string_array (char **array)
1108 return (array == NULL) ? 0 : 1;
1111 LIBTEST_API int STDCALL
1112 mono_test_marshal_string_array (char **array)
1114 if (strcmp (array [0], "ABC"))
1116 if (strcmp (array [1], "DEF"))
1119 if (array [2] != NULL)
1125 LIBTEST_API int STDCALL
1126 mono_test_marshal_byref_string_array (char ***array)
1131 if (strcmp ((*array) [0], "Alpha"))
1133 if (strcmp ((*array) [1], "Beta"))
1135 if (strcmp ((*array) [2], "Gamma"))
1141 LIBTEST_API int STDCALL
1142 mono_test_marshal_stringbuilder_array (char **array)
1144 if (strcmp (array [0], "ABC"))
1146 if (strcmp (array [1], "DEF"))
1149 strcpy (array [0], "DEF");
1150 strcpy (array [1], "ABC");
1155 LIBTEST_API int STDCALL
1156 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
1158 GError *error = NULL;
1161 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
1162 if (strcmp (s, "ABC")) {
1169 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
1170 if (strcmp (s, "DEF")) {
1177 if (strcmp (array2 [0], "ABC"))
1180 if (strcmp (array2 [1], "DEF"))
1186 /* this does not work on Redhat gcc 2.96 */
1187 LIBTEST_API int STDCALL
1188 mono_test_empty_struct (int a, EmptyStruct es, int b)
1190 // printf ("mono_test_empty_struct %d %d\n", a, b);
1192 // Intel icc on ia64 passes 'es' in 2 registers
1193 #if defined(__ia64) && defined(__INTEL_COMPILER)
1196 if (a == 1 && b == 2)
1206 LIBTEST_API ByValStrStruct * STDCALL
1207 mono_test_byvalstr_gen (void)
1209 ByValStrStruct *ret;
1211 ret = malloc(sizeof(ByValStrStruct));
1212 memset(ret, 'a', sizeof(ByValStrStruct)-1);
1213 ret->a[sizeof(ByValStrStruct)-1] = 0;
1218 LIBTEST_API int STDCALL
1219 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
1223 ret = strcmp(data->a, correctString);
1224 // printf ("T1: %s\n", data->a);
1225 // printf ("T2: %s\n", correctString);
1227 /* we need g_free because the allocation was performed by mono_test_byvalstr_gen */
1235 } ByValStrStruct_Unicode;
1237 LIBTEST_API int STDCALL
1238 mono_test_byvalstr_check_unicode (ByValStrStruct_Unicode *ref, int test)
1240 if (ref->flag != 0x1234abcd){
1241 printf ("overwritten data");
1245 if (test == 1 || test == 3){
1246 if (ref->a [0] != '1' ||
1247 ref->a [1] != '2' ||
1253 if (ref->a [0] != '1' ||
1261 LIBTEST_API int STDCALL
1262 NameManglingAnsi (char *data)
1264 return data [0] + data [1] + data [2];
1267 LIBTEST_API int STDCALL
1268 NameManglingAnsiA (char *data)
1270 g_assert_not_reached ();
1273 LIBTEST_API int STDCALL
1274 NameManglingAnsiW (char *data)
1276 g_assert_not_reached ();
1279 LIBTEST_API int STDCALL
1280 NameManglingAnsi2A (char *data)
1282 return data [0] + data [1] + data [2];
1285 LIBTEST_API int STDCALL
1286 NameManglingAnsi2W (char *data)
1288 g_assert_not_reached ();
1291 LIBTEST_API int STDCALL
1292 NameManglingUnicode (char *data)
1294 g_assert_not_reached ();
1297 LIBTEST_API int STDCALL
1298 NameManglingUnicodeW (gunichar2 *data)
1300 return data [0] + data [1] + data [2];
1303 LIBTEST_API int STDCALL
1304 NameManglingUnicode2 (gunichar2 *data)
1306 return data [0] + data [1] + data [2];
1309 LIBTEST_API int STDCALL
1310 NameManglingAutoW (char *data)
1313 return (data [0] + data [1] + data [2]) == 131 ? 0 : 1;
1315 g_assert_not_reached ();
1319 LIBTEST_API int STDCALL
1320 NameManglingAuto (char *data)
1323 return (data [0] + data [1] + data [2]) == 198 ? 0 : 1;
1325 g_assert_not_reached ();
1329 typedef int (STDCALL *intcharFunc)(const char*);
1331 LIBTEST_API void STDCALL
1332 callFunction (intcharFunc f)
1342 LIBTEST_API int STDCALL
1343 class_marshal_test0 (SimpleObj *obj1)
1345 // printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
1347 if (strcmp(obj1->str, "T1"))
1355 LIBTEST_API int STDCALL
1356 class_marshal_test4 (SimpleObj *obj1)
1364 LIBTEST_API void STDCALL
1365 class_marshal_test1 (SimpleObj **obj1)
1367 SimpleObj *res = malloc (sizeof (SimpleObj));
1369 res->str = marshal_strdup ("ABC");
1375 LIBTEST_API int STDCALL
1376 class_marshal_test2 (SimpleObj **obj1)
1378 // printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
1380 if (strcmp((*obj1)->str, "ABC"))
1382 if ((*obj1)->i != 5)
1388 LIBTEST_API int STDCALL
1389 string_marshal_test0 (char *str)
1391 if (strcmp (str, "TEST0"))
1397 LIBTEST_API void STDCALL
1398 string_marshal_test1 (const char **str)
1400 *str = marshal_strdup ("TEST1");
1403 LIBTEST_API int STDCALL
1404 string_marshal_test2 (char **str)
1406 // printf ("string_marshal_test2 %s\n", *str);
1408 if (strcmp (*str, "TEST1"))
1414 LIBTEST_API int STDCALL
1415 string_marshal_test3 (char *str)
1428 LIBTEST_API BlittableClass* STDCALL
1429 TestBlittableClass (BlittableClass *vl)
1431 BlittableClass *res;
1433 // printf ("TestBlittableClass %d %d\n", vl->a, vl->b);
1439 res = marshal_new0 (BlittableClass, 1);
1440 memcpy (res, vl, sizeof (BlittableClass));
1442 res = marshal_new0 (BlittableClass, 1);
1450 typedef struct OSVERSIONINFO_STRUCT
1454 } OSVERSIONINFO_STRUCT;
1456 LIBTEST_API int STDCALL
1457 MyGetVersionEx (OSVERSIONINFO_STRUCT *osvi)
1460 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1465 return osvi->a + osvi->b;
1468 LIBTEST_API int STDCALL
1469 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO_STRUCT *osvi)
1472 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1477 return osvi->a + osvi->b;
1480 LIBTEST_API int STDCALL
1481 mono_test_marshal_point (point pt)
1483 // printf("point %g %g\n", pt.x, pt.y);
1484 if (pt.x == 1.25 && pt.y == 3.5)
1495 LIBTEST_API int STDCALL
1496 mono_test_marshal_mixed_point (mixed_point pt)
1498 // printf("mixed point %d %g\n", pt.x, pt.y);
1499 if (pt.x == 5 && pt.y == 6.75)
1505 LIBTEST_API int STDCALL
1506 mono_test_marshal_mixed_point_2 (mixed_point *pt)
1508 if (pt->x != 5 || pt->y != 6.75)
1517 LIBTEST_API int STDCALL
1518 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
1521 if (*b1 != 0 && *b1 != 1)
1523 if (*b2 != 0 && *b2 != -1) /* variant_bool */
1525 if (*b3 != 0 && *b3 != 1)
1527 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
1539 short b2; /* variant_bool */
1543 LIBTEST_API int STDCALL
1544 marshal_test_bool_struct(struct BoolStruct *s)
1547 if (s->b1 != 0 && s->b1 != 1)
1549 if (s->b2 != 0 && s->b2 != -1)
1551 if (s->b3 != 0 && s->b3 != 1)
1553 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1570 LIBTEST_API int STDCALL
1571 mono_test_marshal_long_struct (LongStruct *s)
1573 return s->i + s->l.l;
1576 LIBTEST_API void STDCALL
1577 mono_test_last_error (int err)
1586 LIBTEST_API int STDCALL
1587 mono_test_asany (void *ptr, int what)
1591 return (*(int*)ptr == 5) ? 0 : 1;
1593 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1595 simplestruct2 ss = *(simplestruct2*)ptr;
1597 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1598 !strcmp (ss.d, "TEST") &&
1599 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1605 GError *error = NULL;
1608 s = g_utf16_to_utf8 (ptr, -1, NULL, NULL, &error);
1613 if (!strcmp (s, "ABC")) {
1623 g_assert_not_reached ();
1637 LIBTEST_API int STDCALL
1638 mono_test_marshal_asany_in (void* ptr)
1640 AsAnyStruct* asAny = ptr;
1641 int res = asAny->i + asAny->j + asAny->k;
1646 LIBTEST_API int STDCALL
1647 mono_test_marshal_asany_inout (void* ptr)
1649 AsAnyStruct* asAny = ptr;
1650 int res = asAny->i + asAny->j + asAny->k;
1652 marshal_free (asAny->s);
1662 LIBTEST_API int STDCALL
1663 mono_test_marshal_asany_out (void* ptr)
1665 AsAnyStruct* asAny = ptr;
1666 int res = asAny->i + asAny->j + asAny->k;
1677 * AMD64 marshalling tests.
1680 typedef struct amd64_struct1 {
1687 LIBTEST_API amd64_struct1 STDCALL
1688 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
1698 LIBTEST_API amd64_struct1 STDCALL
1699 mono_test_marshal_amd64_pass_return_struct1_many_args (amd64_struct1 s, int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8)
1704 s.l += 1 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8;
1709 typedef struct amd64_struct2 {
1714 LIBTEST_API amd64_struct2 STDCALL
1715 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
1723 typedef struct amd64_struct3 {
1727 LIBTEST_API amd64_struct3 STDCALL
1728 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s)
1735 typedef struct amd64_struct4 {
1739 LIBTEST_API amd64_struct4 STDCALL
1740 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s)
1749 * IA64 marshalling tests.
1751 typedef struct test_struct5 {
1755 LIBTEST_API test_struct5 STDCALL
1756 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, test_struct5 s, int i, double d3, double d4)
1758 s.d1 += d1 + d2 + i;
1759 s.d2 += d3 + d4 + i;
1764 typedef struct test_struct6 {
1768 LIBTEST_API test_struct6 STDCALL
1769 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, test_struct6 s, int i, double d3, double d4)
1771 s.d1 += d1 + d2 + i;
1777 static guint32 custom_res [2];
1779 LIBTEST_API void* STDCALL
1780 mono_test_marshal_pass_return_custom (int i, guint32 *ptr, int j)
1782 /* ptr will be freed by CleanupNative, so make a copy */
1783 custom_res [0] = 0; /* not allocated by AllocHGlobal */
1784 custom_res [1] = ptr [1];
1789 LIBTEST_API int STDCALL
1790 mono_test_marshal_pass_out_custom (int i, guint32 **ptr, int j)
1793 custom_res [1] = i + j + 10;
1800 LIBTEST_API int STDCALL
1801 mono_test_marshal_pass_inout_custom (int i, guint32 *ptr, int j)
1804 ptr [1] = i + ptr [1] + j;
1809 LIBTEST_API int STDCALL
1810 mono_test_marshal_pass_out_byval_custom (int i, guint32 *ptr, int j)
1812 return ptr == NULL ? 0 : 1;
1815 LIBTEST_API int STDCALL
1816 mono_test_marshal_pass_byref_custom (int i, guint32 **ptr, int j)
1823 LIBTEST_API void* STDCALL
1824 mono_test_marshal_pass_return_custom2 (int i, guint32 *ptr, int j)
1826 g_assert_not_reached ();
1831 LIBTEST_API void* STDCALL
1832 mono_test_marshal_pass_return_custom_null (int i, guint32 *ptr, int j)
1834 g_assert (ptr == NULL);
1839 typedef void *(STDCALL *PassReturnPtrDelegate) (void *ptr);
1841 LIBTEST_API int STDCALL
1842 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del)
1856 /* FIXME: Freed with FreeHGlobal */
1864 LIBTEST_API int STDCALL
1865 mono_test_marshal_pass_return_custom_null_in_delegate (PassReturnPtrDelegate del)
1867 void *ptr = del (NULL);
1869 return (ptr == NULL) ? 15 : 0;
1872 typedef void (STDCALL *CustomOutParamDelegate) (void **pptr);
1874 LIBTEST_API int STDCALL
1875 mono_test_marshal_custom_out_param_delegate (CustomOutParamDelegate del)
1887 typedef int (STDCALL *ReturnEnumDelegate) (int e);
1889 LIBTEST_API int STDCALL
1890 mono_test_marshal_return_enum_delegate (ReturnEnumDelegate func)
1900 typedef BlittableStruct (STDCALL *SimpleDelegate10) (BlittableStruct ss);
1902 LIBTEST_API int STDCALL
1903 mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 delegate)
1905 BlittableStruct ss, res;
1912 res = delegate (ss);
1913 if (! ((res.a == -1) && (res.b == -2) && (res.c == -3) && (res.d == -55)))
1919 LIBTEST_API int STDCALL
1920 mono_test_stdcall_name_mangling (int a, int b, int c)
1926 * PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
1933 typedef SmallStruct1 (STDCALL *SmallStructDelegate1) (SmallStruct1 ss);
1935 LIBTEST_API int STDCALL
1936 mono_test_marshal_small_struct_delegate1 (SmallStructDelegate1 delegate)
1938 SmallStruct1 ss, res;
1942 res = delegate (ss);
1943 if (! (res.i == -1))
1953 typedef SmallStruct2 (STDCALL *SmallStructDelegate2) (SmallStruct2 ss);
1955 LIBTEST_API int STDCALL
1956 mono_test_marshal_small_struct_delegate2 (SmallStructDelegate2 delegate)
1958 SmallStruct2 ss, res;
1963 res = delegate (ss);
1964 if (! ((res.i == -2) && (res.j == -3)))
1975 typedef SmallStruct3 (STDCALL *SmallStructDelegate3) (SmallStruct3 ss);
1977 LIBTEST_API int STDCALL
1978 mono_test_marshal_small_struct_delegate3 (SmallStructDelegate3 delegate)
1980 SmallStruct3 ss, res;
1985 res = delegate (ss);
1986 if (! ((res.i == -1) && (res.j == -2)))
1996 typedef SmallStruct4 (STDCALL *SmallStructDelegate4) (SmallStruct4 ss);
1998 LIBTEST_API int STDCALL
1999 mono_test_marshal_small_struct_delegate4 (SmallStructDelegate4 delegate)
2001 SmallStruct4 ss, res;
2005 res = delegate (ss);
2006 if (! (res.i == -1))
2016 typedef SmallStruct5 (STDCALL *SmallStructDelegate5) (SmallStruct5 ss);
2018 LIBTEST_API int STDCALL
2019 mono_test_marshal_small_struct_delegate5 (SmallStructDelegate5 delegate)
2021 SmallStruct5 ss, res;
2025 res = delegate (ss);
2026 if (! (res.i == -5))
2036 typedef SmallStruct6 (STDCALL *SmallStructDelegate6) (SmallStruct6 ss);
2038 LIBTEST_API int STDCALL
2039 mono_test_marshal_small_struct_delegate6 (SmallStructDelegate6 delegate)
2041 SmallStruct6 ss, res;
2046 res = delegate (ss);
2047 if (! ((res.i == -1) && (res.j == -2)))
2058 typedef SmallStruct7 (STDCALL *SmallStructDelegate7) (SmallStruct7 ss);
2060 LIBTEST_API int STDCALL
2061 mono_test_marshal_small_struct_delegate7 (SmallStructDelegate7 delegate)
2063 SmallStruct7 ss, res;
2068 res = delegate (ss);
2069 if (! ((res.i == -1) && (res.j == -2)))
2079 typedef SmallStruct8 (STDCALL *SmallStructDelegate8) (SmallStruct8 ss);
2081 LIBTEST_API int STDCALL
2082 mono_test_marshal_small_struct_delegate8 (SmallStructDelegate8 delegate)
2084 SmallStruct8 ss, res;
2088 res = delegate (ss);
2089 if (! ((res.i == -1.0)))
2099 typedef SmallStruct9 (STDCALL *SmallStructDelegate9) (SmallStruct9 ss);
2101 LIBTEST_API int STDCALL
2102 mono_test_marshal_small_struct_delegate9 (SmallStructDelegate9 delegate)
2104 SmallStruct9 ss, res;
2108 res = delegate (ss);
2109 if (! ((res.i == -1.0)))
2119 typedef SmallStruct10 (STDCALL *SmallStructDelegate10) (SmallStruct10 ss);
2121 LIBTEST_API int STDCALL
2122 mono_test_marshal_small_struct_delegate10 (SmallStructDelegate10 delegate)
2124 SmallStruct10 ss, res;
2129 res = delegate (ss);
2130 if (! ((res.i == -1.0) && (res.j == -2.0)))
2141 typedef SmallStruct11 (STDCALL *SmallStructDelegate11) (SmallStruct11 ss);
2143 LIBTEST_API int STDCALL
2144 mono_test_marshal_small_struct_delegate11 (SmallStructDelegate11 delegate)
2146 SmallStruct11 ss, res;
2151 res = delegate (ss);
2152 if (! ((res.i == -1.0) && (res.j == -2)))
2158 typedef int (STDCALL *ArrayDelegate) (int i, char *j, void *arr);
2160 LIBTEST_API int STDCALL
2161 mono_test_marshal_array_delegate (void *arr, int len, ArrayDelegate del)
2163 return del (len, NULL, arr);
2166 typedef int (STDCALL *ArrayDelegateLong) (gint64 i, char *j, void *arr);
2168 LIBTEST_API int STDCALL
2169 mono_test_marshal_array_delegate_long (void *arr, gint64 len, ArrayDelegateLong del)
2171 return del (len, NULL, arr);
2174 LIBTEST_API int STDCALL
2175 mono_test_marshal_out_array_delegate (int *arr, int len, ArrayDelegate del)
2177 del (len, NULL, arr);
2179 if ((arr [0] != 1) || (arr [1] != 2))
2185 typedef gunichar2* (STDCALL *UnicodeStringDelegate) (gunichar2 *message);
2187 LIBTEST_API int STDCALL
2188 mono_test_marshal_return_unicode_string_delegate (UnicodeStringDelegate del)
2190 const char m[] = "abcdef";
2191 gunichar2 *s2, *res;
2194 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
2203 LIBTEST_API int STDCALL
2204 mono_test_marshal_out_string_array_delegate (char **arr, int len, ArrayDelegate del)
2206 del (len, NULL, arr);
2208 if (!strcmp (arr [0], "ABC") && !strcmp (arr [1], "DEF"))
2214 typedef int (*CdeclDelegate) (int i, int j);
2216 LIBTEST_API int STDCALL
2217 mono_test_marshal_cdecl_delegate (CdeclDelegate del)
2221 for (i = 0; i < 1000; ++i)
2227 typedef char** (STDCALL *ReturnStringArrayDelegate) (int i);
2229 LIBTEST_API int STDCALL
2230 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d)
2238 if (strcmp (arr [0], "ABC") || strcmp (arr [1], "DEF"))
2248 typedef int (STDCALL *ByrefStringDelegate) (char **s);
2250 LIBTEST_API int STDCALL
2251 mono_test_marshal_byref_string_delegate (ByrefStringDelegate d)
2253 char *s = (char*)"ABC";
2260 if (!strcmp (s, "DEF"))
2270 LIBTEST_API int STDCALL
2271 add_delegate (int i, int j)
2276 LIBTEST_API gpointer STDCALL
2277 mono_test_marshal_return_fnptr (void)
2279 return &add_delegate;
2282 LIBTEST_API int STDCALL
2285 printf ("codigo %x\n", code);
2293 LIBTEST_API HandleRef STDCALL
2294 mono_xr_as_handle (int code)
2298 memset (&ref, 0, sizeof (ref));
2310 LIBTEST_API int STDCALL
2311 mono_safe_handle_struct_ref (HandleStructs *x)
2313 printf ("Dingus Ref! \n");
2314 printf ("Values: %d %d %p %p\n", x->a, x->b, x->handle1, x->handle2);
2320 if (x->handle1 != (void*) 0x7080feed)
2323 if (x->handle2 != (void*) 0x1234abcd)
2329 LIBTEST_API int STDCALL
2330 mono_safe_handle_struct (HandleStructs x)
2332 printf ("Dingus Standard! \n");
2333 printf ("Values: %d %d %p %p\n", x.a, x.b, x.handle1, x.handle2);
2339 if (x.handle1 != (void*) 0x7080feed)
2342 if (x.handle2 != (void*) 0x1234abcd)
2352 LIBTEST_API int STDCALL
2353 mono_safe_handle_struct_simple (TrivialHandle x)
2355 printf ("The value is %p\n", x.a);
2356 return ((int)(gsize)x.a) * 2;
2359 LIBTEST_API int STDCALL
2360 mono_safe_handle_return (void)
2365 LIBTEST_API void STDCALL
2366 mono_safe_handle_ref (void **handle)
2369 *handle = (void *) 0xbad;
2373 *handle = (void *) 0x800d;
2376 LIBTEST_API double STDCALL
2377 mono_test_marshal_date_time (double d, double *d2)
2448 VT_USERDEFINED = 29,
2456 VT_STREAMED_OBJECT = 68,
2457 VT_STORED_OBJECT = 69,
2458 VT_BLOB_OBJECT = 70,
2466 void VariantInit(VARIANT* vt)
2483 LIBTEST_API int STDCALL
2484 mono_test_marshal_bstr_in(gunichar2* bstr)
2487 gchar* bstr_utf8 = g_utf16_to_utf8 (bstr, -1, NULL, NULL, NULL);
2488 result = strcmp("mono_test_marshal_bstr_in", bstr_utf8);
2495 LIBTEST_API int STDCALL
2496 mono_test_marshal_bstr_out(gunichar2** bstr)
2498 *bstr = marshal_bstr_alloc ("mono_test_marshal_bstr_out");
2502 LIBTEST_API int STDCALL
2503 mono_test_marshal_bstr_in_null(gunichar2* bstr)
2510 LIBTEST_API int STDCALL
2511 mono_test_marshal_bstr_out_null(gunichar2** bstr)
2517 LIBTEST_API int STDCALL
2518 mono_test_marshal_variant_in_sbyte(VARIANT variant)
2520 if (variant.vt == VT_I1 && variant.cVal == 100)
2525 LIBTEST_API int STDCALL
2526 mono_test_marshal_variant_in_byte(VARIANT variant)
2528 if (variant.vt == VT_UI1 && variant.bVal == 100)
2533 LIBTEST_API int STDCALL
2534 mono_test_marshal_variant_in_short(VARIANT variant)
2536 if (variant.vt == VT_I2 && variant.iVal == 314)
2541 LIBTEST_API int STDCALL
2542 mono_test_marshal_variant_in_ushort(VARIANT variant)
2544 if (variant.vt == VT_UI2 && variant.uiVal == 314)
2549 LIBTEST_API int STDCALL
2550 mono_test_marshal_variant_in_int(VARIANT variant)
2552 if (variant.vt == VT_I4 && variant.lVal == 314)
2557 LIBTEST_API int STDCALL
2558 mono_test_marshal_variant_in_uint(VARIANT variant)
2560 if (variant.vt == VT_UI4 && variant.ulVal == 314)
2565 LIBTEST_API int STDCALL
2566 mono_test_marshal_variant_in_long(VARIANT variant)
2568 if (variant.vt == VT_I8 && variant.llVal == 314)
2573 LIBTEST_API int STDCALL
2574 mono_test_marshal_variant_in_ulong(VARIANT variant)
2576 if (variant.vt == VT_UI8 && variant.ullVal == 314)
2581 LIBTEST_API int STDCALL
2582 mono_test_marshal_variant_in_float(VARIANT variant)
2584 if (variant.vt == VT_R4 && (variant.fltVal - 3.14)/3.14 < .001)
2589 LIBTEST_API int STDCALL
2590 mono_test_marshal_variant_in_double(VARIANT variant)
2592 if (variant.vt == VT_R8 && (variant.dblVal - 3.14)/3.14 < .001)
2597 LIBTEST_API int STDCALL
2598 mono_test_marshal_variant_in_bstr(VARIANT variant)
2601 gchar* bstr_utf8 = g_utf16_to_utf8 (variant.bstrVal, -1, NULL, NULL, NULL);
2602 result = strcmp("PI", bstr_utf8);
2605 if (variant.vt == VT_BSTR && !result)
2610 LIBTEST_API int STDCALL
2611 mono_test_marshal_variant_in_bool_true (VARIANT variant)
2613 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_TRUE)
2618 LIBTEST_API int STDCALL
2619 mono_test_marshal_variant_in_bool_false (VARIANT variant)
2621 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_FALSE)
2626 LIBTEST_API int STDCALL
2627 mono_test_marshal_variant_out_sbyte(VARIANT* variant)
2629 variant->vt = VT_I1;
2630 variant->cVal = 100;
2635 LIBTEST_API int STDCALL
2636 mono_test_marshal_variant_out_byte(VARIANT* variant)
2638 variant->vt = VT_UI1;
2639 variant->bVal = 100;
2644 LIBTEST_API int STDCALL
2645 mono_test_marshal_variant_out_short(VARIANT* variant)
2647 variant->vt = VT_I2;
2648 variant->iVal = 314;
2653 LIBTEST_API int STDCALL
2654 mono_test_marshal_variant_out_ushort(VARIANT* variant)
2656 variant->vt = VT_UI2;
2657 variant->uiVal = 314;
2662 LIBTEST_API int STDCALL
2663 mono_test_marshal_variant_out_int(VARIANT* variant)
2665 variant->vt = VT_I4;
2666 variant->lVal = 314;
2671 LIBTEST_API int STDCALL
2672 mono_test_marshal_variant_out_uint(VARIANT* variant)
2674 variant->vt = VT_UI4;
2675 variant->ulVal = 314;
2680 LIBTEST_API int STDCALL
2681 mono_test_marshal_variant_out_long(VARIANT* variant)
2683 variant->vt = VT_I8;
2684 variant->llVal = 314;
2689 LIBTEST_API int STDCALL
2690 mono_test_marshal_variant_out_ulong(VARIANT* variant)
2692 variant->vt = VT_UI8;
2693 variant->ullVal = 314;
2698 LIBTEST_API int STDCALL
2699 mono_test_marshal_variant_out_float(VARIANT* variant)
2701 variant->vt = VT_R4;
2702 variant->fltVal = 3.14;
2707 LIBTEST_API int STDCALL
2708 mono_test_marshal_variant_out_double(VARIANT* variant)
2710 variant->vt = VT_R8;
2711 variant->dblVal = 3.14;
2716 LIBTEST_API int STDCALL
2717 mono_test_marshal_variant_out_bstr(VARIANT* variant)
2719 variant->vt = VT_BSTR;
2720 variant->bstrVal = marshal_bstr_alloc("PI");
2725 LIBTEST_API int STDCALL
2726 mono_test_marshal_variant_out_bool_true (VARIANT* variant)
2728 variant->vt = VT_BOOL;
2729 variant->boolVal = VARIANT_TRUE;
2734 LIBTEST_API int STDCALL
2735 mono_test_marshal_variant_out_bool_false (VARIANT* variant)
2737 variant->vt = VT_BOOL;
2738 variant->boolVal = VARIANT_FALSE;
2743 typedef int (STDCALL *VarFunc) (int vt, VARIANT variant);
2744 typedef int (STDCALL *VarRefFunc) (int vt, VARIANT* variant);
2746 LIBTEST_API int STDCALL
2747 mono_test_marshal_variant_in_sbyte_unmanaged(VarFunc func)
2752 return func (VT_I1, vt);
2755 LIBTEST_API int STDCALL
2756 mono_test_marshal_variant_in_byte_unmanaged(VarFunc func)
2761 return func (VT_UI1, vt);
2764 LIBTEST_API int STDCALL
2765 mono_test_marshal_variant_in_short_unmanaged(VarFunc func)
2770 return func (VT_I2, vt);
2773 LIBTEST_API int STDCALL
2774 mono_test_marshal_variant_in_ushort_unmanaged(VarFunc func)
2779 return func (VT_UI2, vt);
2782 LIBTEST_API int STDCALL
2783 mono_test_marshal_variant_in_int_unmanaged(VarFunc func)
2788 return func (VT_I4, vt);
2791 LIBTEST_API int STDCALL
2792 mono_test_marshal_variant_in_uint_unmanaged(VarFunc func)
2797 return func (VT_UI4, vt);
2800 LIBTEST_API int STDCALL
2801 mono_test_marshal_variant_in_long_unmanaged(VarFunc func)
2806 return func (VT_I8, vt);
2809 LIBTEST_API int STDCALL
2810 mono_test_marshal_variant_in_ulong_unmanaged(VarFunc func)
2815 return func (VT_UI8, vt);
2818 LIBTEST_API int STDCALL
2819 mono_test_marshal_variant_in_float_unmanaged(VarFunc func)
2824 return func (VT_R4, vt);
2827 LIBTEST_API int STDCALL
2828 mono_test_marshal_variant_in_double_unmanaged(VarFunc func)
2833 return func (VT_R8, vt);
2836 LIBTEST_API int STDCALL
2837 mono_test_marshal_variant_in_bstr_unmanaged(VarFunc func)
2841 vt.bstrVal = marshal_bstr_alloc("PI");
2842 return func (VT_BSTR, vt);
2845 LIBTEST_API int STDCALL
2846 mono_test_marshal_variant_in_bool_true_unmanaged(VarFunc func)
2850 vt.boolVal = VARIANT_TRUE;
2851 return func (VT_BOOL, vt);
2854 LIBTEST_API int STDCALL
2855 mono_test_marshal_variant_in_bool_false_unmanaged(VarFunc func)
2859 vt.boolVal = VARIANT_FALSE;
2860 return func (VT_BOOL, vt);
2863 LIBTEST_API int STDCALL
2864 mono_test_marshal_variant_out_sbyte_unmanaged(VarRefFunc func)
2869 if (vt.vt == VT_I1 && vt.cVal == -100)
2874 LIBTEST_API int STDCALL
2875 mono_test_marshal_variant_out_byte_unmanaged(VarRefFunc func)
2880 if (vt.vt == VT_UI1 && vt.bVal == 100)
2885 LIBTEST_API int STDCALL
2886 mono_test_marshal_variant_out_short_unmanaged(VarRefFunc func)
2891 if (vt.vt == VT_I2 && vt.iVal == -100)
2896 LIBTEST_API int STDCALL
2897 mono_test_marshal_variant_out_ushort_unmanaged(VarRefFunc func)
2902 if (vt.vt == VT_UI2 && vt.uiVal == 100)
2907 LIBTEST_API int STDCALL
2908 mono_test_marshal_variant_out_int_unmanaged(VarRefFunc func)
2913 if (vt.vt == VT_I4 && vt.lVal == -100)
2918 LIBTEST_API int STDCALL
2919 mono_test_marshal_variant_out_uint_unmanaged(VarRefFunc func)
2924 if (vt.vt == VT_UI4 && vt.ulVal == 100)
2929 LIBTEST_API int STDCALL
2930 mono_test_marshal_variant_out_long_unmanaged(VarRefFunc func)
2935 if (vt.vt == VT_I8 && vt.llVal == -100)
2940 LIBTEST_API int STDCALL
2941 mono_test_marshal_variant_out_ulong_unmanaged(VarRefFunc func)
2946 if (vt.vt == VT_UI8 && vt.ullVal == 100)
2951 LIBTEST_API int STDCALL
2952 mono_test_marshal_variant_out_float_unmanaged(VarRefFunc func)
2957 if (vt.vt == VT_R4 && fabs (vt.fltVal - 3.14f) < 1e-10)
2962 LIBTEST_API int STDCALL
2963 mono_test_marshal_variant_out_double_unmanaged(VarRefFunc func)
2968 if (vt.vt == VT_R8 && fabs (vt.dblVal - 3.14) < 1e-10)
2973 LIBTEST_API int STDCALL
2974 mono_test_marshal_variant_out_bstr_unmanaged(VarRefFunc func)
2982 func (VT_BSTR, &vt);
2983 bstr_utf8 = g_utf16_to_utf8 (vt.bstrVal, -1, NULL, NULL, NULL);
2984 result = strcmp("PI", bstr_utf8);
2986 if (vt.vt == VT_BSTR && !result)
2991 LIBTEST_API int STDCALL
2992 mono_test_marshal_variant_out_bool_true_unmanaged(VarRefFunc func)
2996 func (VT_BOOL, &vt);
2997 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3002 LIBTEST_API int STDCALL
3003 mono_test_marshal_variant_out_bool_false_unmanaged(VarRefFunc func)
3007 func (VT_BOOL, &vt);
3008 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3013 typedef struct MonoComObject MonoComObject;
3017 int (STDCALL *QueryInterface)(MonoComObject* pUnk, gpointer riid, gpointer* ppv);
3018 int (STDCALL *AddRef)(MonoComObject* pUnk);
3019 int (STDCALL *Release)(MonoComObject* pUnk);
3020 int (STDCALL *get_ITest)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3021 int (STDCALL *SByteIn)(MonoComObject* pUnk, char a);
3022 int (STDCALL *ByteIn)(MonoComObject* pUnk, unsigned char a);
3023 int (STDCALL *ShortIn)(MonoComObject* pUnk, short a);
3024 int (STDCALL *UShortIn)(MonoComObject* pUnk, unsigned short a);
3025 int (STDCALL *IntIn)(MonoComObject* pUnk, int a);
3026 int (STDCALL *UIntIn)(MonoComObject* pUnk, unsigned int a);
3027 int (STDCALL *LongIn)(MonoComObject* pUnk, gint64 a);
3028 int (STDCALL *ULongIn)(MonoComObject* pUnk, guint64 a);
3029 int (STDCALL *FloatIn)(MonoComObject* pUnk, float a);
3030 int (STDCALL *DoubleIn)(MonoComObject* pUnk, double a);
3031 int (STDCALL *ITestIn)(MonoComObject* pUnk, MonoComObject* pUnk2);
3032 int (STDCALL *ITestOut)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3035 struct MonoComObject
3041 static GUID IID_ITest = {0, 0, 0, {0,0,0,0,0,0,0,1}};
3042 static GUID IID_IMonoUnknown = {0, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3043 static GUID IID_IMonoDispatch = {0x00020400, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3045 LIBTEST_API int STDCALL
3046 MonoQueryInterface(MonoComObject* pUnk, gpointer riid, gpointer* ppv)
3050 if (!memcmp(riid, &IID_IMonoUnknown, sizeof(GUID))) {
3054 else if (!memcmp(riid, &IID_ITest, sizeof(GUID))) {
3058 else if (!memcmp(riid, &IID_IMonoDispatch, sizeof(GUID))) {
3062 return 0x80004002; //E_NOINTERFACE;
3065 LIBTEST_API int STDCALL
3066 MonoAddRef(MonoComObject* pUnk)
3068 return ++(pUnk->m_ref);
3071 LIBTEST_API int STDCALL
3072 MonoRelease(MonoComObject* pUnk)
3074 return --(pUnk->m_ref);
3077 LIBTEST_API int STDCALL
3078 SByteIn(MonoComObject* pUnk, char a)
3083 LIBTEST_API int STDCALL
3084 ByteIn(MonoComObject* pUnk, unsigned char a)
3089 LIBTEST_API int STDCALL
3090 ShortIn(MonoComObject* pUnk, short a)
3095 LIBTEST_API int STDCALL
3096 UShortIn(MonoComObject* pUnk, unsigned short a)
3101 LIBTEST_API int STDCALL
3102 IntIn(MonoComObject* pUnk, int a)
3107 LIBTEST_API int STDCALL
3108 UIntIn(MonoComObject* pUnk, unsigned int a)
3113 LIBTEST_API int STDCALL
3114 LongIn(MonoComObject* pUnk, gint64 a)
3119 LIBTEST_API int STDCALL
3120 ULongIn(MonoComObject* pUnk, guint64 a)
3125 LIBTEST_API int STDCALL
3126 FloatIn(MonoComObject* pUnk, float a)
3131 LIBTEST_API int STDCALL
3132 DoubleIn(MonoComObject* pUnk, double a)
3137 LIBTEST_API int STDCALL
3138 ITestIn(MonoComObject* pUnk, MonoComObject *pUnk2)
3143 LIBTEST_API int STDCALL
3144 ITestOut(MonoComObject* pUnk, MonoComObject* *ppUnk)
3149 LIBTEST_API int STDCALL
3150 get_ITest(MonoComObject* pUnk, MonoComObject* *ppUnk)
3155 static void create_com_object (MonoComObject** pOut)
3157 *pOut = marshal_new0 (MonoComObject, 1);
3158 (*pOut)->vtbl = marshal_new0 (MonoIUnknown, 1);
3161 (*pOut)->vtbl->QueryInterface = MonoQueryInterface;
3162 (*pOut)->vtbl->AddRef = MonoAddRef;
3163 (*pOut)->vtbl->Release = MonoRelease;
3164 (*pOut)->vtbl->SByteIn = SByteIn;
3165 (*pOut)->vtbl->ByteIn = ByteIn;
3166 (*pOut)->vtbl->ShortIn = ShortIn;
3167 (*pOut)->vtbl->UShortIn = UShortIn;
3168 (*pOut)->vtbl->IntIn = IntIn;
3169 (*pOut)->vtbl->UIntIn = UIntIn;
3170 (*pOut)->vtbl->LongIn = LongIn;
3171 (*pOut)->vtbl->ULongIn = ULongIn;
3172 (*pOut)->vtbl->FloatIn = FloatIn;
3173 (*pOut)->vtbl->DoubleIn = DoubleIn;
3174 (*pOut)->vtbl->ITestIn = ITestIn;
3175 (*pOut)->vtbl->ITestOut = ITestOut;
3176 (*pOut)->vtbl->get_ITest = get_ITest;
3179 static MonoComObject* same_object = NULL;
3181 LIBTEST_API int STDCALL
3182 mono_test_marshal_com_object_create(MonoComObject* *pUnk)
3184 create_com_object (pUnk);
3187 same_object = *pUnk;
3192 LIBTEST_API int STDCALL
3193 mono_test_marshal_com_object_same(MonoComObject* *pUnk)
3195 *pUnk = same_object;
3200 LIBTEST_API int STDCALL
3201 mono_test_marshal_com_object_destroy(MonoComObject *pUnk)
3203 int ref = --(pUnk->m_ref);
3210 LIBTEST_API int STDCALL
3211 mono_test_marshal_com_object_ref_count(MonoComObject *pUnk)
3216 LIBTEST_API int STDCALL
3217 mono_test_marshal_ccw_itest (MonoComObject *pUnk)
3220 MonoComObject* pTest;
3225 hr = pUnk->vtbl->SByteIn (pUnk, -100);
3228 hr = pUnk->vtbl->ByteIn (pUnk, 100);
3231 hr = pUnk->vtbl->ShortIn (pUnk, -100);
3234 hr = pUnk->vtbl->UShortIn (pUnk, 100);
3237 hr = pUnk->vtbl->IntIn (pUnk, -100);
3240 hr = pUnk->vtbl->UIntIn (pUnk, 100);
3243 hr = pUnk->vtbl->LongIn (pUnk, -100);
3246 hr = pUnk->vtbl->ULongIn (pUnk, 100);
3249 hr = pUnk->vtbl->FloatIn (pUnk, 3.14f);
3252 hr = pUnk->vtbl->DoubleIn (pUnk, 3.14);
3255 hr = pUnk->vtbl->ITestIn (pUnk, pUnk);
3258 hr = pUnk->vtbl->ITestOut (pUnk, &pTest);
3266 * mono_method_get_unmanaged_thunk tests
3269 #if defined(__GNUC__) && ((defined(__i386__) && (defined(__linux__) || defined (__APPLE__)) || defined (__FreeBSD__) || defined(__OpenBSD__)) || (defined(__ppc__) && defined(__APPLE__)))
3270 #define ALIGN(size) __attribute__ ((aligned(size)))
3276 /* thunks.cs:TestStruct */
3277 typedef struct _TestStruct {
3279 double B ALIGN(8); /* align according to mono's struct layout */
3282 /* Searches for mono symbols in all loaded modules */
3284 lookup_mono_symbol (const char *symbol_name)
3287 if (g_module_symbol (g_module_open (NULL, G_MODULE_BIND_LAZY), symbol_name, &symbol))
3293 LIBTEST_API gpointer STDCALL
3294 mono_test_marshal_lookup_symbol (const char *symbol_name)
3296 return lookup_mono_symbol (symbol_name);
3300 * test_method_thunk:
3302 * @test_id: the test number
3303 * @test_method_handle: MonoMethod* of the C# test method
3304 * @create_object_method_handle: MonoMethod* of thunks.cs:Test.CreateObject
3306 LIBTEST_API int STDCALL
3307 test_method_thunk (int test_id, gpointer test_method_handle, gpointer create_object_method_handle)
3309 gpointer (*mono_method_get_unmanaged_thunk)(gpointer)
3310 = lookup_mono_symbol ("mono_method_get_unmanaged_thunk");
3312 gpointer (*mono_string_new_wrapper)(const char *)
3313 = lookup_mono_symbol ("mono_string_new_wrapper");
3315 char* (*mono_string_to_utf8)(gpointer)
3316 = lookup_mono_symbol ("mono_string_to_utf8");
3318 gpointer (*mono_object_unbox)(gpointer)
3319 = lookup_mono_symbol ("mono_object_unbox");
3321 gpointer test_method, ex = NULL;
3322 gpointer (STDCALL *CreateObject)(gpointer*);
3325 if (!mono_method_get_unmanaged_thunk)
3328 test_method = mono_method_get_unmanaged_thunk (test_method_handle);
3332 CreateObject = mono_method_get_unmanaged_thunk (create_object_method_handle);
3340 /* thunks.cs:Test.Test0 */
3341 void (STDCALL *F)(gpointer*) = test_method;
3347 /* thunks.cs:Test.Test1 */
3348 int (STDCALL *F)(gpointer*) = test_method;
3355 /* thunks.cs:Test.Test2 */
3356 gpointer (STDCALL *F)(gpointer, gpointer*) = test_method;
3357 gpointer str = mono_string_new_wrapper ("foo");
3358 if (str != F (str, &ex))
3364 /* thunks.cs:Test.Test3 */
3365 gpointer (STDCALL *F)(gpointer, gpointer, gpointer*);
3370 obj = CreateObject (&ex);
3371 str = mono_string_new_wrapper ("bar");
3373 if (str != F (obj, str, &ex))
3379 /* thunks.cs:Test.Test4 */
3380 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3385 obj = CreateObject (&ex);
3386 str = mono_string_new_wrapper ("bar");
3388 if (42 != F (obj, str, 42, &ex))
3395 /* thunks.cs:Test.Test5 */
3396 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3401 obj = CreateObject (&ex);
3402 str = mono_string_new_wrapper ("bar");
3404 F (obj, str, 42, &ex);
3412 /* thunks.cs:Test.Test6 */
3413 int (STDCALL *F)(gpointer, guint8, gint16, gint32, gint64, float, double,
3414 gpointer, gpointer*);
3416 gpointer str = mono_string_new_wrapper ("Test6");
3420 obj = CreateObject (&ex);
3422 res = F (obj, 254, 32700, -245378, 6789600, 3.1415, 3.1415, str, &ex);
3433 /* thunks.cs:Test.Test7 */
3434 gint64 (STDCALL *F)(gpointer*) = test_method;
3435 if (F (&ex) != G_MAXINT64)
3441 /* thunks.cs:Test.Test8 */
3442 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3443 gpointer*, gpointer*);
3455 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3463 (fabs (a5 - 3.1415) < 0.001) &&
3464 (fabs (a6 - 3.1415) < 0.001) &&
3465 strcmp (mono_string_to_utf8 (a7), "Test8") == 0))
3472 /* thunks.cs:Test.Test9 */
3473 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3474 gpointer*, gpointer*);
3486 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3494 /* thunks.cs:Test.Test10 */
3495 void (STDCALL *F)(gpointer*, gpointer*);
3497 gpointer obj1, obj2;
3499 obj1 = obj2 = CreateObject (&ex);
3516 /* thunks.cs:TestStruct.Test0 */
3517 int (STDCALL *F)(gpointer*, gpointer*);
3523 obj = CreateObject (&ex);
3530 a1 = mono_object_unbox (obj);
3546 /* check whether the call was really by value */
3547 if (a1->A != 42 || a1->B != 3.1415)
3554 /* thunks.cs:TestStruct.Test1 */
3555 void (STDCALL *F)(gpointer, gpointer*);
3560 obj = CreateObject (&ex);
3567 a1 = mono_object_unbox (obj);
3580 if (!fabs (a1->B - 3.1415) < 0.001)
3587 /* thunks.cs:TestStruct.Test2 */
3588 gpointer (STDCALL *F)(gpointer*);
3602 a1 = mono_object_unbox (obj);
3607 if (!fabs (a1->B - 3.1415) < 0.001)
3614 /* thunks.cs:TestStruct.Test3 */
3615 void (STDCALL *F)(gpointer, gpointer*);
3620 obj = CreateObject (&ex);
3627 a1 = mono_object_unbox (obj);
3663 LIBTEST_API int STDCALL
3664 mono_test_Winx64_struct1_in (winx64_struct1 var)
3677 LIBTEST_API int STDCALL
3678 mono_test_Winx64_struct2_in (winx64_struct2 var)
3695 LIBTEST_API int STDCALL
3696 mono_test_Winx64_struct3_in (winx64_struct3 var)
3702 if (var.c != 0x1234)
3715 LIBTEST_API int STDCALL
3716 mono_test_Winx64_struct4_in (winx64_struct4 var)
3722 if (var.c != 0x1234)
3724 if (var.d != 0x87654321)
3736 LIBTEST_API int STDCALL
3737 mono_test_Winx64_struct5_in (winx64_struct5 var)
3755 LIBTEST_API int STDCALL
3756 mono_test_Winx64_struct6_in (winx64_struct6 var)
3767 LIBTEST_API int STDCALL
3768 mono_test_Winx64_structs_in1 (winx64_struct1 var1,
3769 winx64_struct2 var2,
3770 winx64_struct3 var3,
3771 winx64_struct4 var4)
3785 if (var3.c != 0x1234)
3792 if (var4.c != 0x1234)
3794 if (var4.d != 0x87654321)
3799 LIBTEST_API int STDCALL
3800 mono_test_Winx64_structs_in2 (winx64_struct1 var1,
3801 winx64_struct1 var2,
3802 winx64_struct1 var3,
3803 winx64_struct1 var4,
3804 winx64_struct1 var5)
3820 LIBTEST_API int STDCALL
3821 mono_test_Winx64_structs_in3 (winx64_struct1 var1,
3822 winx64_struct5 var2,
3823 winx64_struct1 var3,
3824 winx64_struct5 var4,
3825 winx64_struct1 var5,
3826 winx64_struct5 var6)
3861 LIBTEST_API winx64_struct1 STDCALL
3862 mono_test_Winx64_struct1_ret (void)
3869 LIBTEST_API winx64_struct2 STDCALL
3870 mono_test_Winx64_struct2_ret (void)
3878 LIBTEST_API winx64_struct3 STDCALL
3879 mono_test_Winx64_struct3_ret (void)
3888 LIBTEST_API winx64_struct4 STDCALL
3889 mono_test_Winx64_struct4_ret (void)
3899 LIBTEST_API winx64_struct5 STDCALL
3900 mono_test_Winx64_struct5_ret (void)
3909 LIBTEST_API winx64_struct1 STDCALL
3910 mono_test_Winx64_struct1_ret_5_args (char a, char b, char c, char d, char e)
3913 ret.a = a + b + c + d + e;
3917 LIBTEST_API winx64_struct5 STDCALL
3918 mono_test_Winx64_struct5_ret6_args (char a, char b, char c, char d, char e)
3931 } winx64_floatStruct;
3933 LIBTEST_API int STDCALL
3934 mono_test_Winx64_floatStruct (winx64_floatStruct a)
3936 if (a.a > 5.6 || a.a < 5.4)
3939 if (a.b > 9.6 || a.b < 9.4)
3948 } winx64_doubleStruct;
3950 LIBTEST_API int STDCALL
3951 mono_test_Winx64_doubleStruct (winx64_doubleStruct a)
3953 if (a.a > 5.6 || a.a < 5.4)
3959 typedef int (STDCALL *managed_struct1_delegate) (winx64_struct1 a);
3961 LIBTEST_API int STDCALL
3962 mono_test_managed_Winx64_struct1_in(managed_struct1_delegate func)
3969 typedef int (STDCALL *managed_struct5_delegate) (winx64_struct5 a);
3971 LIBTEST_API int STDCALL
3972 mono_test_managed_Winx64_struct5_in(managed_struct5_delegate func)
3981 typedef int (STDCALL *managed_struct1_struct5_delegate) (winx64_struct1 a, winx64_struct5 b,
3982 winx64_struct1 c, winx64_struct5 d,
3983 winx64_struct1 e, winx64_struct5 f);
3985 LIBTEST_API int STDCALL
3986 mono_test_managed_Winx64_struct1_struct5_in(managed_struct1_struct5_delegate func)
3988 winx64_struct1 a, c, e;
3989 winx64_struct5 b, d, f;
3991 b.a = 2; b.b = 3; b.c = 4;
3993 d.a = 6; d.b = 7; d.c = 8;
3995 f.a = 10; f.b = 11; f.c = 12;
3997 return func (a, b, c, d, e, f);
4000 typedef winx64_struct1 (STDCALL *managed_struct1_ret_delegate) (void);
4002 LIBTEST_API int STDCALL
4003 mono_test_Winx64_struct1_ret_managed (managed_struct1_ret_delegate func)
4015 typedef winx64_struct5 (STDCALL *managed_struct5_ret_delegate) (void);
4017 LIBTEST_API int STDCALL
4018 mono_test_Winx64_struct5_ret_managed (managed_struct5_ret_delegate func)
4034 LIBTEST_API int STDCALL
4035 mono_test_marshal_bool_in (int arg, unsigned int expected, unsigned int bDefaultMarsh, unsigned int bBoolCustMarsh,
4036 char bI1CustMarsh, unsigned char bU1CustMarsh, short bVBCustMarsh)
4040 if (bDefaultMarsh != expected)
4044 if (bBoolCustMarsh != expected)
4048 if (bI1CustMarsh != expected)
4052 if (bU1CustMarsh != expected)
4056 if (bVBCustMarsh != expected)
4065 LIBTEST_API int STDCALL
4066 mono_test_marshal_bool_out (int arg, unsigned int testVal, unsigned int* bDefaultMarsh, unsigned int* bBoolCustMarsh,
4067 char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh)
4073 *bDefaultMarsh = testVal;
4076 if (!bBoolCustMarsh)
4078 *bBoolCustMarsh = testVal;
4083 *bI1CustMarsh = (char)testVal;
4088 *bU1CustMarsh = (unsigned char)testVal;
4093 *bVBCustMarsh = (unsigned short)testVal;
4101 LIBTEST_API int STDCALL
4102 mono_test_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4103 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh,
4104 unsigned short* bVBCustMarsh)
4110 if (*bDefaultMarsh != expected)
4112 *bDefaultMarsh = testVal;
4115 if (!bBoolCustMarsh)
4117 if (*bBoolCustMarsh != expected)
4119 *bBoolCustMarsh = testVal;
4124 if (*bI1CustMarsh != expected)
4126 *bI1CustMarsh = (char)testVal;
4131 if (*bU1CustMarsh != expected)
4133 *bU1CustMarsh = (unsigned char)testVal;
4138 if (*bVBCustMarsh != expected)
4140 *bVBCustMarsh = (unsigned short)testVal;
4149 typedef int (STDCALL *MarshalBoolInDelegate) (int arg, unsigned int expected, unsigned int bDefaultMarsh,
4150 unsigned int bBoolCustMarsh, char bI1CustMarsh, unsigned char bU1CustMarsh, unsigned short bVBCustMarsh);
4152 LIBTEST_API int STDCALL
4153 mono_test_managed_marshal_bool_in (int arg, unsigned int expected, unsigned int testVal, MarshalBoolInDelegate pfcn)
4160 return pfcn (arg, expected, testVal, 0, 0, 0, 0);
4162 return pfcn (arg, expected, 0, testVal, 0, 0, 0);
4164 return pfcn (arg, expected, 0, 0, testVal, 0, 0);
4166 return pfcn (arg, expected, 0, 0, 0, testVal, 0);
4168 return pfcn (arg, expected, 0, 0, 0, 0, testVal);
4176 typedef int (STDCALL *MarshalBoolOutDelegate) (int arg, unsigned int expected, unsigned int* bDefaultMarsh,
4177 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4179 LIBTEST_API int STDCALL
4180 mono_test_managed_marshal_bool_out (int arg, unsigned int expected, unsigned int testVal, MarshalBoolOutDelegate pfcn)
4183 unsigned int lDefaultMarsh, lBoolCustMarsh;
4184 char lI1CustMarsh = 0;
4185 unsigned char lU1CustMarsh = 0;
4186 unsigned short lVBCustMarsh = 0;
4187 lDefaultMarsh = lBoolCustMarsh = 0;
4194 unsigned int ltVal = 0;
4195 ret = pfcn (arg, testVal, <Val, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4197 return 0x0100 + ret;
4198 if (expected != ltVal)
4203 unsigned int ltVal = 0;
4204 ret = pfcn (arg, testVal, &lDefaultMarsh, <Val, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4206 return 0x0300 + ret;
4207 if (expected != ltVal)
4213 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, <Val, &lU1CustMarsh, &lVBCustMarsh);
4215 return 0x0500 + ret;
4216 if (expected != ltVal)
4221 unsigned char ltVal = 0;
4222 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <Val, &lVBCustMarsh);
4224 return 0x0700 + ret;
4225 if (expected != ltVal)
4230 unsigned short ltVal = 0;
4231 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <Val);
4233 return 0x0900 + ret;
4234 if (expected != ltVal)
4245 typedef int (STDCALL *MarshalBoolRefDelegate) (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4246 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4248 LIBTEST_API int STDCALL
4249 mono_test_managed_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int outExpected,
4250 unsigned int outTestVal, MarshalBoolRefDelegate pfcn)
4253 unsigned int lDefaultMarsh, lBoolCustMarsh;
4254 char lI1CustMarsh = 0;
4255 unsigned char lU1CustMarsh = 0;
4256 unsigned short lVBCustMarsh = 0;
4257 lDefaultMarsh = lBoolCustMarsh = 0;
4265 unsigned int ltestVal = testVal;
4266 ret = pfcn (arg, expected, outTestVal, <estVal, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4268 return 0x0100 + ret;
4269 if (outExpected != ltestVal)
4275 unsigned int ltestVal = testVal;
4276 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, <estVal, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4278 return 0x0300 + ret;
4279 if (outExpected != ltestVal)
4285 char ltestVal = testVal;
4286 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, <estVal, &lU1CustMarsh, &lVBCustMarsh);
4288 return 0x0500 + ret;
4289 if (outExpected != ltestVal)
4295 unsigned char ltestVal = testVal;
4296 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <estVal, &lVBCustMarsh);
4298 return 0x0700 + ret;
4299 if (outExpected != ltestVal)
4305 unsigned short ltestVal = testVal;
4306 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <estVal);
4308 return 0x0900 + ret;
4309 if (outExpected != ltestVal)
4322 LIBTEST_API int STDCALL
4323 mono_test_marshal_safearray_out_1dim_vt_bstr_empty (SAFEARRAY** safearray)
4325 /* Create an empty one-dimensional array of variants */
4327 SAFEARRAYBOUND dimensions [1];
4329 dimensions [0].lLbound = 0;
4330 dimensions [0].cElements = 0;
4332 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4337 LIBTEST_API int STDCALL
4338 mono_test_marshal_safearray_out_1dim_vt_bstr (SAFEARRAY** safearray)
4340 /* Create a one-dimensional array of 10 variants filled with "0" to "9" */
4342 SAFEARRAYBOUND dimensions [1];
4348 dimensions [0].lLbound = 0;
4349 dimensions [0].cElements = 10;
4351 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4352 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4354 VariantInit (&vOut);
4356 _ltoa (i,buffer,10);
4357 vOut.bstrVal= marshal_bstr_alloc (buffer);
4359 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4360 VariantClear (&vOut);
4361 SafeArrayDestroy (pSA);
4364 VariantClear (&vOut);
4370 LIBTEST_API int STDCALL
4371 mono_test_marshal_safearray_out_2dim_vt_i4 (SAFEARRAY** safearray)
4373 /* Create a two-dimensional array of 4x3 variants filled with 11, 12, 13, etc. */
4375 SAFEARRAYBOUND dimensions [2];
4380 dimensions [0].lLbound = 0;
4381 dimensions [0].cElements = 4;
4382 dimensions [1].lLbound = 0;
4383 dimensions [1].cElements = 3;
4385 pSA= SafeArrayCreate(VT_VARIANT, 2, dimensions);
4386 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4387 for (j= dimensions [1].lLbound; j< (dimensions [1].cElements + dimensions [1].lLbound); j++) {
4389 VariantInit (&vOut);
4391 vOut.lVal = (i+1)*10+(j+1);
4394 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4395 VariantClear (&vOut);
4396 SafeArrayDestroy (pSA);
4399 VariantClear (&vOut); // does a deep destroy of source VARIANT
4406 LIBTEST_API int STDCALL
4407 mono_test_marshal_safearray_out_4dim_vt_i4 (SAFEARRAY** safearray)
4409 /* Create a four-dimensional array of 10x3x6x7 variants filled with their indices */
4410 /* Also use non zero lower bounds */
4412 SAFEARRAYBOUND dimensions [4];
4417 dimensions [0].lLbound = 15;
4418 dimensions [0].cElements = 10;
4419 dimensions [1].lLbound = 20;
4420 dimensions [1].cElements = 3;
4421 dimensions [2].lLbound = 5;
4422 dimensions [2].cElements = 6;
4423 dimensions [3].lLbound = 12;
4424 dimensions [3].cElements = 7;
4426 pSA= SafeArrayCreate (VT_VARIANT, 4, dimensions);
4428 SafeArrayAccessData (pSA, (void **)&pData);
4430 for (i= 0; i< 10*3*6*7; i++) {
4431 VariantInit(&pData [i]);
4432 pData [i].vt = VT_I4;
4435 SafeArrayUnaccessData (pSA);
4440 LIBTEST_API int STDCALL
4441 mono_test_marshal_safearray_in_byval_1dim_empty (SAFEARRAY* safearray)
4443 /* Check that array is one dimensional and empty */
4446 long lbound, ubound;
4448 dim = SafeArrayGetDim (safearray);
4452 SafeArrayGetLBound (safearray, 1, &lbound);
4453 SafeArrayGetUBound (safearray, 1, &ubound);
4455 if ((lbound > 0) || (ubound > 0))
4461 LIBTEST_API int STDCALL
4462 mono_test_marshal_safearray_in_byval_1dim_vt_i4 (SAFEARRAY* safearray)
4464 /* Check that array is one dimensional containing integers from 1 to 10 */
4467 long lbound, ubound;
4472 dim = SafeArrayGetDim (safearray);
4476 SafeArrayGetLBound (safearray, 1, &lbound);
4477 SafeArrayGetUBound (safearray, 1, &ubound);
4479 if ((lbound != 0) || (ubound != 9))
4482 SafeArrayAccessData (safearray, (void **)&pData);
4483 for (i= lbound; i <= ubound; i++) {
4484 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i + 1))
4487 SafeArrayUnaccessData (safearray);
4492 LIBTEST_API int STDCALL
4493 mono_test_marshal_safearray_in_byval_1dim_vt_mixed (SAFEARRAY* safearray)
4495 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4498 long lbound, ubound;
4505 VariantInit (&element);
4507 dim = SafeArrayGetDim (safearray);
4511 SafeArrayGetLBound (safearray, 1, &lbound);
4512 SafeArrayGetUBound (safearray, 1, &ubound);
4514 if ((lbound != 0) || (ubound != 12))
4517 SafeArrayAccessData (safearray, (void **)&pData);
4518 for (i= lbound; i <= ubound; i++) {
4519 if ((i%2 == 0) && (pData [i].vt != VT_I4))
4521 if ((i%2 == 1) && (pData [i].vt != VT_BSTR))
4523 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i))
4526 SafeArrayUnaccessData (safearray);
4528 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4533 SafeArrayPutElement (safearray, indices, &element);
4534 VariantClear (&element);
4539 LIBTEST_API int STDCALL
4540 mono_test_marshal_safearray_in_byval_2dim_vt_i4 (SAFEARRAY* safearray)
4542 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4545 long lbound1, ubound1, lbound2, ubound2;
4550 VariantInit (&element);
4552 dim = SafeArrayGetDim (safearray);
4556 SafeArrayGetLBound (safearray, 1, &lbound1);
4557 SafeArrayGetUBound (safearray, 1, &ubound1);
4559 if ((lbound1 != 0) || (ubound1 != 1))
4562 SafeArrayGetLBound (safearray, 2, &lbound2);
4563 SafeArrayGetUBound (safearray, 2, &ubound2);
4565 if ((lbound2 != 0) || (ubound2 != 3)) {
4569 for (i= lbound1; i <= ubound1; i++) {
4571 for (j= lbound2; j <= ubound2; j++) {
4573 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4575 failed = ((element.vt != VT_I4) || (element.lVal != 10*(i+1)+(j+1)));
4576 VariantClear (&element);
4582 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4588 SafeArrayPutElement (safearray, indices, &element);
4589 VariantClear (&element);
4594 LIBTEST_API int STDCALL
4595 mono_test_marshal_safearray_in_byval_3dim_vt_bstr (SAFEARRAY* safearray)
4597 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4600 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4601 long i, j, k, failed;
4605 VariantInit (&element);
4607 dim = SafeArrayGetDim (safearray);
4611 SafeArrayGetLBound (safearray, 1, &lbound1);
4612 SafeArrayGetUBound (safearray, 1, &ubound1);
4614 if ((lbound1 != 0) || (ubound1 != 1))
4617 SafeArrayGetLBound (safearray, 2, &lbound2);
4618 SafeArrayGetUBound (safearray, 2, &ubound2);
4620 if ((lbound2 != 0) || (ubound2 != 1))
4623 SafeArrayGetLBound (safearray, 3, &lbound3);
4624 SafeArrayGetUBound (safearray, 3, &ubound3);
4626 if ((lbound3 != 0) || (ubound3 != 2))
4629 for (i= lbound1; i <= ubound1; i++) {
4631 for (j= lbound2; j <= ubound2; j++) {
4633 for (k= lbound3; k <= ubound3; k++) {
4635 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4637 failed = ((element.vt != VT_BSTR)
4638 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4639 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4640 VariantClear (&element);
4647 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4652 element.vt = VT_BSTR;
4653 element.bstrVal = SysAllocString(L"Should not be copied");
4654 SafeArrayPutElement (safearray, indices, &element);
4655 VariantClear (&element);
4660 LIBTEST_API int STDCALL
4661 mono_test_marshal_safearray_in_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4663 return mono_test_marshal_safearray_in_byval_3dim_vt_bstr (*safearray);
4666 LIBTEST_API int STDCALL
4667 mono_test_marshal_safearray_in_out_byref_1dim_empty (SAFEARRAY** safearray)
4669 /* Check that the input array is what is expected and change it so the caller can check */
4670 /* correct marshalling back to managed code */
4673 long lbound, ubound;
4674 SAFEARRAYBOUND dimensions [1];
4676 wchar_t buffer [20];
4680 /* Check that in array is one dimensional and empty */
4682 dim = SafeArrayGetDim (*safearray);
4687 SafeArrayGetLBound (*safearray, 1, &lbound);
4688 SafeArrayGetUBound (*safearray, 1, &ubound);
4690 if ((lbound > 0) || (ubound > 0)) {
4694 /* Re-dimension the array and return a one-dimensional array of 8 variants filled with "0" to "7" */
4696 dimensions [0].lLbound = 0;
4697 dimensions [0].cElements = 8;
4699 hr = SafeArrayRedim (*safearray, dimensions);
4703 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
4705 VariantInit (&vOut);
4707 _ltow (i,buffer,10);
4708 vOut.bstrVal = SysAllocString (buffer);
4710 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
4711 VariantClear (&vOut);
4712 SafeArrayDestroy (*safearray);
4715 VariantClear (&vOut);
4720 LIBTEST_API int STDCALL
4721 mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4723 /* Check that the input array is what is expected and change it so the caller can check */
4724 /* correct marshalling back to managed code */
4727 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4728 SAFEARRAYBOUND dimensions [1];
4729 long i, j, k, failed;
4730 wchar_t buffer [20];
4735 VariantInit (&element);
4737 /* Check that in array is three dimensional and contains the expected values */
4739 dim = SafeArrayGetDim (*safearray);
4743 SafeArrayGetLBound (*safearray, 1, &lbound1);
4744 SafeArrayGetUBound (*safearray, 1, &ubound1);
4746 if ((lbound1 != 0) || (ubound1 != 1))
4749 SafeArrayGetLBound (*safearray, 2, &lbound2);
4750 SafeArrayGetUBound (*safearray, 2, &ubound2);
4752 if ((lbound2 != 0) || (ubound2 != 1))
4755 SafeArrayGetLBound (*safearray, 3, &lbound3);
4756 SafeArrayGetUBound (*safearray, 3, &ubound3);
4758 if ((lbound3 != 0) || (ubound3 != 2))
4761 for (i= lbound1; i <= ubound1; i++) {
4763 for (j= lbound2; j <= ubound2; j++) {
4765 for (k= lbound3; k <= ubound3; k++) {
4767 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
4769 failed = ((element.vt != VT_BSTR)
4770 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4771 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4772 VariantClear (&element);
4779 hr = SafeArrayDestroy (*safearray);
4783 /* Return a new one-dimensional array of 8 variants filled with "0" to "7" */
4785 dimensions [0].lLbound = 0;
4786 dimensions [0].cElements = 8;
4788 *safearray = SafeArrayCreate (VT_VARIANT, 1, dimensions);
4790 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
4792 VariantInit (&vOut);
4794 _ltow (i,buffer,10);
4795 vOut.bstrVal = SysAllocString (buffer);
4797 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
4798 VariantClear (&vOut);
4799 SafeArrayDestroy (*safearray);
4802 VariantClear (&vOut);
4807 LIBTEST_API int STDCALL
4808 mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 (SAFEARRAY** safearray)
4810 /* Check that the input array is what is expected and change it so the caller can check */
4811 /* correct marshalling back to managed code */
4814 long lbound1, ubound1;
4820 VariantInit (&element);
4822 /* Check that in array is one dimensional and contains the expected value */
4824 dim = SafeArrayGetDim (*safearray);
4828 SafeArrayGetLBound (*safearray, 1, &lbound1);
4829 SafeArrayGetUBound (*safearray, 1, &ubound1);
4832 if ((lbound1 != 0) || (ubound1 != 1))
4836 for (i= lbound1; i <= ubound1; i++) {
4838 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
4840 failed = (element.vt != VT_I4) || (element.lVal != i+1);
4841 VariantClear (&element);
4846 /* Change one of the elements of the array to verify that [out] parameter is marshalled back to the managed side */
4851 SafeArrayPutElement (*safearray, indices, &element);
4852 VariantClear (&element);
4857 LIBTEST_API int STDCALL
4858 mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (SAFEARRAY* safearray)
4860 /* Check that the input array is what is expected and change it so the caller can check */
4861 /* correct marshalling back to managed code */
4864 long lbound1, ubound1;
4865 SAFEARRAYBOUND dimensions [1];
4871 VariantInit (&element);
4873 /* Check that in array is one dimensional and contains the expected value */
4875 dim = SafeArrayGetDim (safearray);
4879 SafeArrayGetLBound (safearray, 1, &lbound1);
4880 SafeArrayGetUBound (safearray, 1, &ubound1);
4882 if ((lbound1 != 0) || (ubound1 != 0))
4885 for (i= lbound1; i <= ubound1; i++) {
4887 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4889 failed = (element.vt != VT_I4) || (element.lVal != i+1);
4890 VariantClear (&element);
4895 /* Change the array to verify how [out] parameter is marshalled back to the managed side */
4897 /* Redimension the array */
4898 dimensions [0].lLbound = lbound1;
4899 dimensions [0].cElements = 2;
4900 hr = SafeArrayRedim(safearray, dimensions);
4904 element.lVal = 12345;
4905 SafeArrayPutElement (safearray, indices, &element);
4906 VariantClear (&element);
4910 element.lVal = -12345;
4911 SafeArrayPutElement (safearray, indices, &element);
4912 VariantClear (&element);
4917 LIBTEST_API int STDCALL
4918 mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr (SAFEARRAY* safearray)
4920 /* Check that the input array is what is expected and change it so the caller can check */
4921 /* correct marshalling back to managed code */
4924 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4925 long i, j, k, failed;
4930 VariantInit (&element);
4932 /* Check that in array is three dimensional and contains the expected values */
4934 dim = SafeArrayGetDim (safearray);
4938 SafeArrayGetLBound (safearray, 1, &lbound1);
4939 SafeArrayGetUBound (safearray, 1, &ubound1);
4941 if ((lbound1 != 0) || (ubound1 != 1))
4944 SafeArrayGetLBound (safearray, 2, &lbound2);
4945 SafeArrayGetUBound (safearray, 2, &ubound2);
4947 if ((lbound2 != 0) || (ubound2 != 1))
4950 SafeArrayGetLBound (safearray, 3, &lbound3);
4951 SafeArrayGetUBound (safearray, 3, &ubound3);
4953 if ((lbound3 != 0) || (ubound3 != 2))
4956 for (i= lbound1; i <= ubound1; i++) {
4958 for (j= lbound2; j <= ubound2; j++) {
4960 for (k= lbound3; k <= ubound3; k++) {
4962 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4964 failed = ((element.vt != VT_BSTR)
4965 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4966 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4967 VariantClear (&element);
4974 /* Change the elements of the array to verify that [out] parameter is marshalled back to the managed side */
4981 SafeArrayPutElement (safearray, indices, &element);
4982 VariantClear (&element);
4989 SafeArrayPutElement (safearray, indices, &element);
4990 VariantClear (&element);
4995 element.vt = VT_BSTR;
4996 element.bstrVal = marshal_bstr_alloc("ABCDEFG");
4997 SafeArrayPutElement (safearray, indices, &element);
4998 VariantClear (&element);
5003 LIBTEST_API int STDCALL
5004 mono_test_marshal_safearray_mixed(
5005 SAFEARRAY *safearray1,
5006 SAFEARRAY **safearray2,
5007 SAFEARRAY *safearray3,
5008 SAFEARRAY **safearray4
5013 /* Initialize out parameters */
5016 /* array1: Check that in array is one dimensional and contains the expected value */
5017 hr = mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (safearray1);
5019 /* array2: Fill in with some values to check on the managed side */
5021 hr = mono_test_marshal_safearray_out_1dim_vt_bstr (safearray2);
5023 /* array3: Check that in array is one dimensional and contains the expected value */
5025 hr = mono_test_marshal_safearray_in_byval_1dim_vt_mixed(safearray3);
5027 /* array4: Check input values and fill in with some values to check on the managed side */
5029 hr = mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr(safearray4);
5036 static int call_managed_res;
5039 call_managed (gpointer arg)
5041 SimpleDelegate del = arg;
5043 call_managed_res = del (42);
5046 LIBTEST_API int STDCALL
5047 mono_test_marshal_thread_attach (SimpleDelegate del)
5055 res = pthread_create (&t, NULL, (gpointer)call_managed, del);
5056 g_assert (res == 0);
5057 pthread_join (t, NULL);
5059 return call_managed_res;