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_stringbuilder2 (char *s, int n)
1043 const char m[] = "EFGH";
1050 LIBTEST_API int STDCALL
1051 mono_test_marshal_stringbuilder_default (char *s, int n)
1053 const char m[] = "This is my message. Isn't it nice?";
1060 LIBTEST_API int STDCALL
1061 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
1063 const char m[] = "This is my message. Isn't it nice?";
1067 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1069 len = (len * 2) + 2;
1072 memcpy (s, s2, len);
1079 LIBTEST_API void STDCALL
1080 mono_test_marshal_stringbuilder_out (char **s)
1082 const char m[] = "This is my message. Isn't it nice?";
1085 str = marshal_alloc (strlen (m) + 1);
1086 memcpy (str, m, strlen (m) + 1);
1091 LIBTEST_API int STDCALL
1092 mono_test_marshal_stringbuilder_out_unicode (gunichar2 **s)
1094 const char m[] = "This is my message. Isn't it nice?";
1098 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1100 len = (len * 2) + 2;
1101 *s = marshal_alloc (len);
1102 memcpy (*s, s2, len);
1109 LIBTEST_API int STDCALL
1110 mono_test_marshal_stringbuilder_ref (char **s)
1112 const char m[] = "This is my message. Isn't it nice?";
1115 if (strcmp (*s, "ABC"))
1118 str = marshal_alloc (strlen (m) + 1);
1119 memcpy (str, m, strlen (m) + 1);
1131 LIBTEST_API int STDCALL
1132 mono_test_marshal_empty_string_array (char **array)
1134 return (array == NULL) ? 0 : 1;
1137 LIBTEST_API int STDCALL
1138 mono_test_marshal_string_array (char **array)
1140 if (strcmp (array [0], "ABC"))
1142 if (strcmp (array [1], "DEF"))
1145 if (array [2] != NULL)
1151 LIBTEST_API int STDCALL
1152 mono_test_marshal_byref_string_array (char ***array)
1157 if (strcmp ((*array) [0], "Alpha"))
1159 if (strcmp ((*array) [1], "Beta"))
1161 if (strcmp ((*array) [2], "Gamma"))
1167 LIBTEST_API int STDCALL
1168 mono_test_marshal_stringbuilder_array (char **array)
1170 if (strcmp (array [0], "ABC"))
1172 if (strcmp (array [1], "DEF"))
1175 strcpy (array [0], "DEF");
1176 strcpy (array [1], "ABC");
1181 LIBTEST_API int STDCALL
1182 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
1184 GError *error = NULL;
1187 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
1188 if (strcmp (s, "ABC")) {
1195 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
1196 if (strcmp (s, "DEF")) {
1203 if (strcmp (array2 [0], "ABC"))
1206 if (strcmp (array2 [1], "DEF"))
1212 /* this does not work on Redhat gcc 2.96 */
1213 LIBTEST_API int STDCALL
1214 mono_test_empty_struct (int a, EmptyStruct es, int b)
1216 // printf ("mono_test_empty_struct %d %d\n", a, b);
1218 // Intel icc on ia64 passes 'es' in 2 registers
1219 #if defined(__ia64) && defined(__INTEL_COMPILER)
1222 if (a == 1 && b == 2)
1232 LIBTEST_API ByValStrStruct * STDCALL
1233 mono_test_byvalstr_gen (void)
1235 ByValStrStruct *ret;
1237 ret = malloc(sizeof(ByValStrStruct));
1238 memset(ret, 'a', sizeof(ByValStrStruct)-1);
1239 ret->a[sizeof(ByValStrStruct)-1] = 0;
1244 LIBTEST_API int STDCALL
1245 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
1249 ret = strcmp(data->a, correctString);
1250 // printf ("T1: %s\n", data->a);
1251 // printf ("T2: %s\n", correctString);
1253 /* we need g_free because the allocation was performed by mono_test_byvalstr_gen */
1261 } ByValStrStruct_Unicode;
1263 LIBTEST_API int STDCALL
1264 mono_test_byvalstr_check_unicode (ByValStrStruct_Unicode *ref, int test)
1266 if (ref->flag != 0x1234abcd){
1267 printf ("overwritten data");
1271 if (test == 1 || test == 3){
1272 if (ref->a [0] != '1' ||
1273 ref->a [1] != '2' ||
1279 if (ref->a [0] != '1' ||
1287 LIBTEST_API int STDCALL
1288 NameManglingAnsi (char *data)
1290 return data [0] + data [1] + data [2];
1293 LIBTEST_API int STDCALL
1294 NameManglingAnsiA (char *data)
1296 g_assert_not_reached ();
1299 LIBTEST_API int STDCALL
1300 NameManglingAnsiW (char *data)
1302 g_assert_not_reached ();
1305 LIBTEST_API int STDCALL
1306 NameManglingAnsi2A (char *data)
1308 return data [0] + data [1] + data [2];
1311 LIBTEST_API int STDCALL
1312 NameManglingAnsi2W (char *data)
1314 g_assert_not_reached ();
1317 LIBTEST_API int STDCALL
1318 NameManglingUnicode (char *data)
1320 g_assert_not_reached ();
1323 LIBTEST_API int STDCALL
1324 NameManglingUnicodeW (gunichar2 *data)
1326 return data [0] + data [1] + data [2];
1329 LIBTEST_API int STDCALL
1330 NameManglingUnicode2 (gunichar2 *data)
1332 return data [0] + data [1] + data [2];
1335 LIBTEST_API int STDCALL
1336 NameManglingAutoW (char *data)
1339 return (data [0] + data [1] + data [2]) == 131 ? 0 : 1;
1341 g_assert_not_reached ();
1345 LIBTEST_API int STDCALL
1346 NameManglingAuto (char *data)
1349 return (data [0] + data [1] + data [2]) == 198 ? 0 : 1;
1351 g_assert_not_reached ();
1355 typedef int (STDCALL *intcharFunc)(const char*);
1357 LIBTEST_API void STDCALL
1358 callFunction (intcharFunc f)
1368 LIBTEST_API int STDCALL
1369 class_marshal_test0 (SimpleObj *obj1)
1371 // printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
1373 if (strcmp(obj1->str, "T1"))
1381 LIBTEST_API int STDCALL
1382 class_marshal_test4 (SimpleObj *obj1)
1390 LIBTEST_API void STDCALL
1391 class_marshal_test1 (SimpleObj **obj1)
1393 SimpleObj *res = malloc (sizeof (SimpleObj));
1395 res->str = marshal_strdup ("ABC");
1401 LIBTEST_API int STDCALL
1402 class_marshal_test2 (SimpleObj **obj1)
1404 // printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
1406 if (strcmp((*obj1)->str, "ABC"))
1408 if ((*obj1)->i != 5)
1414 LIBTEST_API int STDCALL
1415 string_marshal_test0 (char *str)
1417 if (strcmp (str, "TEST0"))
1423 LIBTEST_API void STDCALL
1424 string_marshal_test1 (const char **str)
1426 *str = marshal_strdup ("TEST1");
1429 LIBTEST_API int STDCALL
1430 string_marshal_test2 (char **str)
1432 // printf ("string_marshal_test2 %s\n", *str);
1434 if (strcmp (*str, "TEST1"))
1437 *str = marshal_strdup ("TEST2");
1442 LIBTEST_API int STDCALL
1443 string_marshal_test3 (char *str)
1456 LIBTEST_API BlittableClass* STDCALL
1457 TestBlittableClass (BlittableClass *vl)
1459 BlittableClass *res;
1461 // printf ("TestBlittableClass %d %d\n", vl->a, vl->b);
1467 res = marshal_new0 (BlittableClass, 1);
1468 memcpy (res, vl, sizeof (BlittableClass));
1470 res = marshal_new0 (BlittableClass, 1);
1478 typedef struct OSVERSIONINFO_STRUCT
1482 } OSVERSIONINFO_STRUCT;
1484 LIBTEST_API int STDCALL
1485 MyGetVersionEx (OSVERSIONINFO_STRUCT *osvi)
1488 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1493 return osvi->a + osvi->b;
1496 LIBTEST_API int STDCALL
1497 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO_STRUCT *osvi)
1500 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1505 return osvi->a + osvi->b;
1508 LIBTEST_API int STDCALL
1509 mono_test_marshal_point (point pt)
1511 // printf("point %g %g\n", pt.x, pt.y);
1512 if (pt.x == 1.25 && pt.y == 3.5)
1523 LIBTEST_API int STDCALL
1524 mono_test_marshal_mixed_point (mixed_point pt)
1526 // printf("mixed point %d %g\n", pt.x, pt.y);
1527 if (pt.x == 5 && pt.y == 6.75)
1533 LIBTEST_API int STDCALL
1534 mono_test_marshal_mixed_point_2 (mixed_point *pt)
1536 if (pt->x != 5 || pt->y != 6.75)
1545 LIBTEST_API int STDCALL
1546 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
1549 if (*b1 != 0 && *b1 != 1)
1551 if (*b2 != 0 && *b2 != -1) /* variant_bool */
1553 if (*b3 != 0 && *b3 != 1)
1555 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
1567 short b2; /* variant_bool */
1571 LIBTEST_API int STDCALL
1572 marshal_test_bool_struct(struct BoolStruct *s)
1575 if (s->b1 != 0 && s->b1 != 1)
1577 if (s->b2 != 0 && s->b2 != -1)
1579 if (s->b3 != 0 && s->b3 != 1)
1581 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1598 LIBTEST_API int STDCALL
1599 mono_test_marshal_long_struct (LongStruct *s)
1601 return s->i + s->l.l;
1604 LIBTEST_API void STDCALL
1605 mono_test_last_error (int err)
1614 LIBTEST_API int STDCALL
1615 mono_test_asany (void *ptr, int what)
1619 return (*(int*)ptr == 5) ? 0 : 1;
1621 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1623 simplestruct2 ss = *(simplestruct2*)ptr;
1625 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1626 !strcmp (ss.d, "TEST") &&
1627 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1633 GError *error = NULL;
1636 s = g_utf16_to_utf8 (ptr, -1, NULL, NULL, &error);
1641 if (!strcmp (s, "ABC")) {
1651 g_assert_not_reached ();
1665 LIBTEST_API int STDCALL
1666 mono_test_marshal_asany_in (void* ptr)
1668 AsAnyStruct* asAny = ptr;
1669 int res = asAny->i + asAny->j + asAny->k;
1674 LIBTEST_API int STDCALL
1675 mono_test_marshal_asany_inout (void* ptr)
1677 AsAnyStruct* asAny = ptr;
1678 int res = asAny->i + asAny->j + asAny->k;
1680 marshal_free (asAny->s);
1690 LIBTEST_API int STDCALL
1691 mono_test_marshal_asany_out (void* ptr)
1693 AsAnyStruct* asAny = ptr;
1694 int res = asAny->i + asAny->j + asAny->k;
1705 * AMD64 marshalling tests.
1708 typedef struct amd64_struct1 {
1715 LIBTEST_API amd64_struct1 STDCALL
1716 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
1726 LIBTEST_API amd64_struct1 STDCALL
1727 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)
1732 s.l += 1 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8;
1737 typedef struct amd64_struct2 {
1742 LIBTEST_API amd64_struct2 STDCALL
1743 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
1751 typedef struct amd64_struct3 {
1755 LIBTEST_API amd64_struct3 STDCALL
1756 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s)
1763 typedef struct amd64_struct4 {
1767 LIBTEST_API amd64_struct4 STDCALL
1768 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s)
1777 * IA64 marshalling tests.
1779 typedef struct test_struct5 {
1783 LIBTEST_API test_struct5 STDCALL
1784 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, test_struct5 s, int i, double d3, double d4)
1786 s.d1 += d1 + d2 + i;
1787 s.d2 += d3 + d4 + i;
1792 typedef struct test_struct6 {
1796 LIBTEST_API test_struct6 STDCALL
1797 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, test_struct6 s, int i, double d3, double d4)
1799 s.d1 += d1 + d2 + i;
1805 static guint32 custom_res [2];
1807 LIBTEST_API void* STDCALL
1808 mono_test_marshal_pass_return_custom (int i, guint32 *ptr, int j)
1810 /* ptr will be freed by CleanupNative, so make a copy */
1811 custom_res [0] = 0; /* not allocated by AllocHGlobal */
1812 custom_res [1] = ptr [1];
1817 LIBTEST_API int STDCALL
1818 mono_test_marshal_pass_out_custom (int i, guint32 **ptr, int j)
1821 custom_res [1] = i + j + 10;
1828 LIBTEST_API int STDCALL
1829 mono_test_marshal_pass_inout_custom (int i, guint32 *ptr, int j)
1832 ptr [1] = i + ptr [1] + j;
1837 LIBTEST_API int STDCALL
1838 mono_test_marshal_pass_out_byval_custom (int i, guint32 *ptr, int j)
1840 return ptr == NULL ? 0 : 1;
1843 LIBTEST_API int STDCALL
1844 mono_test_marshal_pass_byref_custom (int i, guint32 **ptr, int j)
1851 LIBTEST_API void* STDCALL
1852 mono_test_marshal_pass_return_custom2 (int i, guint32 *ptr, int j)
1854 g_assert_not_reached ();
1859 LIBTEST_API void* STDCALL
1860 mono_test_marshal_pass_return_custom_null (int i, guint32 *ptr, int j)
1862 g_assert (ptr == NULL);
1867 typedef void *(STDCALL *PassReturnPtrDelegate) (void *ptr);
1869 LIBTEST_API int STDCALL
1870 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del)
1884 /* FIXME: Freed with FreeHGlobal */
1892 LIBTEST_API int STDCALL
1893 mono_test_marshal_pass_return_custom_null_in_delegate (PassReturnPtrDelegate del)
1895 void *ptr = del (NULL);
1897 return (ptr == NULL) ? 15 : 0;
1900 typedef void (STDCALL *CustomOutParamDelegate) (void **pptr);
1902 LIBTEST_API int STDCALL
1903 mono_test_marshal_custom_out_param_delegate (CustomOutParamDelegate del)
1915 typedef int (STDCALL *ReturnEnumDelegate) (int e);
1917 LIBTEST_API int STDCALL
1918 mono_test_marshal_return_enum_delegate (ReturnEnumDelegate func)
1928 typedef BlittableStruct (STDCALL *SimpleDelegate10) (BlittableStruct ss);
1930 LIBTEST_API int STDCALL
1931 mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 delegate)
1933 BlittableStruct ss, res;
1940 res = delegate (ss);
1941 if (! ((res.a == -1) && (res.b == -2) && (res.c == -3) && (res.d == -55)))
1947 LIBTEST_API int STDCALL
1948 mono_test_stdcall_name_mangling (int a, int b, int c)
1954 * PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
1961 typedef SmallStruct1 (STDCALL *SmallStructDelegate1) (SmallStruct1 ss);
1963 LIBTEST_API int STDCALL
1964 mono_test_marshal_small_struct_delegate1 (SmallStructDelegate1 delegate)
1966 SmallStruct1 ss, res;
1970 res = delegate (ss);
1971 if (! (res.i == -1))
1981 typedef SmallStruct2 (STDCALL *SmallStructDelegate2) (SmallStruct2 ss);
1983 LIBTEST_API int STDCALL
1984 mono_test_marshal_small_struct_delegate2 (SmallStructDelegate2 delegate)
1986 SmallStruct2 ss, res;
1991 res = delegate (ss);
1992 if (! ((res.i == -2) && (res.j == -3)))
2003 typedef SmallStruct3 (STDCALL *SmallStructDelegate3) (SmallStruct3 ss);
2005 LIBTEST_API int STDCALL
2006 mono_test_marshal_small_struct_delegate3 (SmallStructDelegate3 delegate)
2008 SmallStruct3 ss, res;
2013 res = delegate (ss);
2014 if (! ((res.i == -1) && (res.j == -2)))
2024 typedef SmallStruct4 (STDCALL *SmallStructDelegate4) (SmallStruct4 ss);
2026 LIBTEST_API int STDCALL
2027 mono_test_marshal_small_struct_delegate4 (SmallStructDelegate4 delegate)
2029 SmallStruct4 ss, res;
2033 res = delegate (ss);
2034 if (! (res.i == -1))
2044 typedef SmallStruct5 (STDCALL *SmallStructDelegate5) (SmallStruct5 ss);
2046 LIBTEST_API int STDCALL
2047 mono_test_marshal_small_struct_delegate5 (SmallStructDelegate5 delegate)
2049 SmallStruct5 ss, res;
2053 res = delegate (ss);
2054 if (! (res.i == -5))
2064 typedef SmallStruct6 (STDCALL *SmallStructDelegate6) (SmallStruct6 ss);
2066 LIBTEST_API int STDCALL
2067 mono_test_marshal_small_struct_delegate6 (SmallStructDelegate6 delegate)
2069 SmallStruct6 ss, res;
2074 res = delegate (ss);
2075 if (! ((res.i == -1) && (res.j == -2)))
2086 typedef SmallStruct7 (STDCALL *SmallStructDelegate7) (SmallStruct7 ss);
2088 LIBTEST_API int STDCALL
2089 mono_test_marshal_small_struct_delegate7 (SmallStructDelegate7 delegate)
2091 SmallStruct7 ss, res;
2096 res = delegate (ss);
2097 if (! ((res.i == -1) && (res.j == -2)))
2107 typedef SmallStruct8 (STDCALL *SmallStructDelegate8) (SmallStruct8 ss);
2109 LIBTEST_API int STDCALL
2110 mono_test_marshal_small_struct_delegate8 (SmallStructDelegate8 delegate)
2112 SmallStruct8 ss, res;
2116 res = delegate (ss);
2117 if (! ((res.i == -1.0)))
2127 typedef SmallStruct9 (STDCALL *SmallStructDelegate9) (SmallStruct9 ss);
2129 LIBTEST_API int STDCALL
2130 mono_test_marshal_small_struct_delegate9 (SmallStructDelegate9 delegate)
2132 SmallStruct9 ss, res;
2136 res = delegate (ss);
2137 if (! ((res.i == -1.0)))
2147 typedef SmallStruct10 (STDCALL *SmallStructDelegate10) (SmallStruct10 ss);
2149 LIBTEST_API int STDCALL
2150 mono_test_marshal_small_struct_delegate10 (SmallStructDelegate10 delegate)
2152 SmallStruct10 ss, res;
2157 res = delegate (ss);
2158 if (! ((res.i == -1.0) && (res.j == -2.0)))
2169 typedef SmallStruct11 (STDCALL *SmallStructDelegate11) (SmallStruct11 ss);
2171 LIBTEST_API int STDCALL
2172 mono_test_marshal_small_struct_delegate11 (SmallStructDelegate11 delegate)
2174 SmallStruct11 ss, res;
2179 res = delegate (ss);
2180 if (! ((res.i == -1.0) && (res.j == -2)))
2186 typedef int (STDCALL *ArrayDelegate) (int i, char *j, void *arr);
2188 LIBTEST_API int STDCALL
2189 mono_test_marshal_array_delegate (void *arr, int len, ArrayDelegate del)
2191 return del (len, NULL, arr);
2194 typedef int (STDCALL *ArrayDelegateLong) (gint64 i, char *j, void *arr);
2196 LIBTEST_API int STDCALL
2197 mono_test_marshal_array_delegate_long (void *arr, gint64 len, ArrayDelegateLong del)
2199 return del (len, NULL, arr);
2202 LIBTEST_API int STDCALL
2203 mono_test_marshal_out_array_delegate (int *arr, int len, ArrayDelegate del)
2205 del (len, NULL, arr);
2207 if ((arr [0] != 1) || (arr [1] != 2))
2213 typedef gunichar2* (STDCALL *UnicodeStringDelegate) (gunichar2 *message);
2215 LIBTEST_API int STDCALL
2216 mono_test_marshal_return_unicode_string_delegate (UnicodeStringDelegate del)
2218 const char m[] = "abcdef";
2219 gunichar2 *s2, *res;
2222 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
2231 LIBTEST_API int STDCALL
2232 mono_test_marshal_out_string_array_delegate (char **arr, int len, ArrayDelegate del)
2234 del (len, NULL, arr);
2236 if (!strcmp (arr [0], "ABC") && !strcmp (arr [1], "DEF"))
2242 typedef int (*CdeclDelegate) (int i, int j);
2244 LIBTEST_API int STDCALL
2245 mono_test_marshal_cdecl_delegate (CdeclDelegate del)
2249 for (i = 0; i < 1000; ++i)
2255 typedef char** (STDCALL *ReturnStringArrayDelegate) (int i);
2257 LIBTEST_API int STDCALL
2258 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d)
2266 if (strcmp (arr [0], "ABC") || strcmp (arr [1], "DEF"))
2276 typedef int (STDCALL *ByrefStringDelegate) (char **s);
2278 LIBTEST_API int STDCALL
2279 mono_test_marshal_byref_string_delegate (ByrefStringDelegate d)
2281 char *s = (char*)"ABC";
2288 if (!strcmp (s, "DEF"))
2298 LIBTEST_API int STDCALL
2299 add_delegate (int i, int j)
2304 LIBTEST_API gpointer STDCALL
2305 mono_test_marshal_return_fnptr (void)
2307 return &add_delegate;
2310 LIBTEST_API int STDCALL
2313 printf ("codigo %x\n", code);
2321 LIBTEST_API HandleRef STDCALL
2322 mono_xr_as_handle (int code)
2326 memset (&ref, 0, sizeof (ref));
2338 LIBTEST_API int STDCALL
2339 mono_safe_handle_struct_ref (HandleStructs *x)
2341 printf ("Dingus Ref! \n");
2342 printf ("Values: %d %d %p %p\n", x->a, x->b, x->handle1, x->handle2);
2348 if (x->handle1 != (void*) 0x7080feed)
2351 if (x->handle2 != (void*) 0x1234abcd)
2357 LIBTEST_API int STDCALL
2358 mono_safe_handle_struct (HandleStructs x)
2360 printf ("Dingus Standard! \n");
2361 printf ("Values: %d %d %p %p\n", x.a, x.b, x.handle1, x.handle2);
2367 if (x.handle1 != (void*) 0x7080feed)
2370 if (x.handle2 != (void*) 0x1234abcd)
2380 LIBTEST_API int STDCALL
2381 mono_safe_handle_struct_simple (TrivialHandle x)
2383 printf ("The value is %p\n", x.a);
2384 return ((int)(gsize)x.a) * 2;
2387 LIBTEST_API int STDCALL
2388 mono_safe_handle_return (void)
2393 LIBTEST_API void STDCALL
2394 mono_safe_handle_ref (void **handle)
2397 *handle = (void *) 0xbad;
2401 *handle = (void *) 0x800d;
2404 LIBTEST_API double STDCALL
2405 mono_test_marshal_date_time (double d, double *d2)
2476 VT_USERDEFINED = 29,
2484 VT_STREAMED_OBJECT = 68,
2485 VT_STORED_OBJECT = 69,
2486 VT_BLOB_OBJECT = 70,
2494 void VariantInit(VARIANT* vt)
2511 LIBTEST_API int STDCALL
2512 mono_test_marshal_bstr_in(gunichar2* bstr)
2515 gchar* bstr_utf8 = g_utf16_to_utf8 (bstr, -1, NULL, NULL, NULL);
2516 result = strcmp("mono_test_marshal_bstr_in", bstr_utf8);
2523 LIBTEST_API int STDCALL
2524 mono_test_marshal_bstr_out(gunichar2** bstr)
2526 *bstr = marshal_bstr_alloc ("mono_test_marshal_bstr_out");
2530 LIBTEST_API int STDCALL
2531 mono_test_marshal_bstr_in_null(gunichar2* bstr)
2538 LIBTEST_API int STDCALL
2539 mono_test_marshal_bstr_out_null(gunichar2** bstr)
2545 LIBTEST_API int STDCALL
2546 mono_test_marshal_variant_in_sbyte(VARIANT variant)
2548 if (variant.vt == VT_I1 && variant.cVal == 100)
2553 LIBTEST_API int STDCALL
2554 mono_test_marshal_variant_in_byte(VARIANT variant)
2556 if (variant.vt == VT_UI1 && variant.bVal == 100)
2561 LIBTEST_API int STDCALL
2562 mono_test_marshal_variant_in_short(VARIANT variant)
2564 if (variant.vt == VT_I2 && variant.iVal == 314)
2569 LIBTEST_API int STDCALL
2570 mono_test_marshal_variant_in_ushort(VARIANT variant)
2572 if (variant.vt == VT_UI2 && variant.uiVal == 314)
2577 LIBTEST_API int STDCALL
2578 mono_test_marshal_variant_in_int(VARIANT variant)
2580 if (variant.vt == VT_I4 && variant.lVal == 314)
2585 LIBTEST_API int STDCALL
2586 mono_test_marshal_variant_in_uint(VARIANT variant)
2588 if (variant.vt == VT_UI4 && variant.ulVal == 314)
2593 LIBTEST_API int STDCALL
2594 mono_test_marshal_variant_in_long(VARIANT variant)
2596 if (variant.vt == VT_I8 && variant.llVal == 314)
2601 LIBTEST_API int STDCALL
2602 mono_test_marshal_variant_in_ulong(VARIANT variant)
2604 if (variant.vt == VT_UI8 && variant.ullVal == 314)
2609 LIBTEST_API int STDCALL
2610 mono_test_marshal_variant_in_float(VARIANT variant)
2612 if (variant.vt == VT_R4 && (variant.fltVal - 3.14)/3.14 < .001)
2617 LIBTEST_API int STDCALL
2618 mono_test_marshal_variant_in_double(VARIANT variant)
2620 if (variant.vt == VT_R8 && (variant.dblVal - 3.14)/3.14 < .001)
2625 LIBTEST_API int STDCALL
2626 mono_test_marshal_variant_in_bstr(VARIANT variant)
2629 gchar* bstr_utf8 = g_utf16_to_utf8 (variant.bstrVal, -1, NULL, NULL, NULL);
2630 result = strcmp("PI", bstr_utf8);
2633 if (variant.vt == VT_BSTR && !result)
2638 LIBTEST_API int STDCALL
2639 mono_test_marshal_variant_in_bool_true (VARIANT variant)
2641 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_TRUE)
2646 LIBTEST_API int STDCALL
2647 mono_test_marshal_variant_in_bool_false (VARIANT variant)
2649 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_FALSE)
2654 LIBTEST_API int STDCALL
2655 mono_test_marshal_variant_out_sbyte(VARIANT* variant)
2657 variant->vt = VT_I1;
2658 variant->cVal = 100;
2663 LIBTEST_API int STDCALL
2664 mono_test_marshal_variant_out_byte(VARIANT* variant)
2666 variant->vt = VT_UI1;
2667 variant->bVal = 100;
2672 LIBTEST_API int STDCALL
2673 mono_test_marshal_variant_out_short(VARIANT* variant)
2675 variant->vt = VT_I2;
2676 variant->iVal = 314;
2681 LIBTEST_API int STDCALL
2682 mono_test_marshal_variant_out_ushort(VARIANT* variant)
2684 variant->vt = VT_UI2;
2685 variant->uiVal = 314;
2690 LIBTEST_API int STDCALL
2691 mono_test_marshal_variant_out_int(VARIANT* variant)
2693 variant->vt = VT_I4;
2694 variant->lVal = 314;
2699 LIBTEST_API int STDCALL
2700 mono_test_marshal_variant_out_uint(VARIANT* variant)
2702 variant->vt = VT_UI4;
2703 variant->ulVal = 314;
2708 LIBTEST_API int STDCALL
2709 mono_test_marshal_variant_out_long(VARIANT* variant)
2711 variant->vt = VT_I8;
2712 variant->llVal = 314;
2717 LIBTEST_API int STDCALL
2718 mono_test_marshal_variant_out_ulong(VARIANT* variant)
2720 variant->vt = VT_UI8;
2721 variant->ullVal = 314;
2726 LIBTEST_API int STDCALL
2727 mono_test_marshal_variant_out_float(VARIANT* variant)
2729 variant->vt = VT_R4;
2730 variant->fltVal = 3.14;
2735 LIBTEST_API int STDCALL
2736 mono_test_marshal_variant_out_double(VARIANT* variant)
2738 variant->vt = VT_R8;
2739 variant->dblVal = 3.14;
2744 LIBTEST_API int STDCALL
2745 mono_test_marshal_variant_out_bstr(VARIANT* variant)
2747 variant->vt = VT_BSTR;
2748 variant->bstrVal = marshal_bstr_alloc("PI");
2753 LIBTEST_API int STDCALL
2754 mono_test_marshal_variant_out_bool_true (VARIANT* variant)
2756 variant->vt = VT_BOOL;
2757 variant->boolVal = VARIANT_TRUE;
2762 LIBTEST_API int STDCALL
2763 mono_test_marshal_variant_out_bool_false (VARIANT* variant)
2765 variant->vt = VT_BOOL;
2766 variant->boolVal = VARIANT_FALSE;
2771 typedef int (STDCALL *VarFunc) (int vt, VARIANT variant);
2772 typedef int (STDCALL *VarRefFunc) (int vt, VARIANT* variant);
2774 LIBTEST_API int STDCALL
2775 mono_test_marshal_variant_in_sbyte_unmanaged(VarFunc func)
2780 return func (VT_I1, vt);
2783 LIBTEST_API int STDCALL
2784 mono_test_marshal_variant_in_byte_unmanaged(VarFunc func)
2789 return func (VT_UI1, vt);
2792 LIBTEST_API int STDCALL
2793 mono_test_marshal_variant_in_short_unmanaged(VarFunc func)
2798 return func (VT_I2, vt);
2801 LIBTEST_API int STDCALL
2802 mono_test_marshal_variant_in_ushort_unmanaged(VarFunc func)
2807 return func (VT_UI2, vt);
2810 LIBTEST_API int STDCALL
2811 mono_test_marshal_variant_in_int_unmanaged(VarFunc func)
2816 return func (VT_I4, vt);
2819 LIBTEST_API int STDCALL
2820 mono_test_marshal_variant_in_uint_unmanaged(VarFunc func)
2825 return func (VT_UI4, vt);
2828 LIBTEST_API int STDCALL
2829 mono_test_marshal_variant_in_long_unmanaged(VarFunc func)
2834 return func (VT_I8, vt);
2837 LIBTEST_API int STDCALL
2838 mono_test_marshal_variant_in_ulong_unmanaged(VarFunc func)
2843 return func (VT_UI8, vt);
2846 LIBTEST_API int STDCALL
2847 mono_test_marshal_variant_in_float_unmanaged(VarFunc func)
2852 return func (VT_R4, vt);
2855 LIBTEST_API int STDCALL
2856 mono_test_marshal_variant_in_double_unmanaged(VarFunc func)
2861 return func (VT_R8, vt);
2864 LIBTEST_API int STDCALL
2865 mono_test_marshal_variant_in_bstr_unmanaged(VarFunc func)
2869 vt.bstrVal = marshal_bstr_alloc("PI");
2870 return func (VT_BSTR, vt);
2873 LIBTEST_API int STDCALL
2874 mono_test_marshal_variant_in_bool_true_unmanaged(VarFunc func)
2878 vt.boolVal = VARIANT_TRUE;
2879 return func (VT_BOOL, vt);
2882 LIBTEST_API int STDCALL
2883 mono_test_marshal_variant_in_bool_false_unmanaged(VarFunc func)
2887 vt.boolVal = VARIANT_FALSE;
2888 return func (VT_BOOL, vt);
2891 LIBTEST_API int STDCALL
2892 mono_test_marshal_variant_out_sbyte_unmanaged(VarRefFunc func)
2897 if (vt.vt == VT_I1 && vt.cVal == -100)
2902 LIBTEST_API int STDCALL
2903 mono_test_marshal_variant_out_byte_unmanaged(VarRefFunc func)
2908 if (vt.vt == VT_UI1 && vt.bVal == 100)
2913 LIBTEST_API int STDCALL
2914 mono_test_marshal_variant_out_short_unmanaged(VarRefFunc func)
2919 if (vt.vt == VT_I2 && vt.iVal == -100)
2924 LIBTEST_API int STDCALL
2925 mono_test_marshal_variant_out_ushort_unmanaged(VarRefFunc func)
2930 if (vt.vt == VT_UI2 && vt.uiVal == 100)
2935 LIBTEST_API int STDCALL
2936 mono_test_marshal_variant_out_int_unmanaged(VarRefFunc func)
2941 if (vt.vt == VT_I4 && vt.lVal == -100)
2946 LIBTEST_API int STDCALL
2947 mono_test_marshal_variant_out_uint_unmanaged(VarRefFunc func)
2952 if (vt.vt == VT_UI4 && vt.ulVal == 100)
2957 LIBTEST_API int STDCALL
2958 mono_test_marshal_variant_out_long_unmanaged(VarRefFunc func)
2963 if (vt.vt == VT_I8 && vt.llVal == -100)
2968 LIBTEST_API int STDCALL
2969 mono_test_marshal_variant_out_ulong_unmanaged(VarRefFunc func)
2974 if (vt.vt == VT_UI8 && vt.ullVal == 100)
2979 LIBTEST_API int STDCALL
2980 mono_test_marshal_variant_out_float_unmanaged(VarRefFunc func)
2985 if (vt.vt == VT_R4 && fabs (vt.fltVal - 3.14f) < 1e-10)
2990 LIBTEST_API int STDCALL
2991 mono_test_marshal_variant_out_double_unmanaged(VarRefFunc func)
2996 if (vt.vt == VT_R8 && fabs (vt.dblVal - 3.14) < 1e-10)
3001 LIBTEST_API int STDCALL
3002 mono_test_marshal_variant_out_bstr_unmanaged(VarRefFunc func)
3010 func (VT_BSTR, &vt);
3011 bstr_utf8 = g_utf16_to_utf8 (vt.bstrVal, -1, NULL, NULL, NULL);
3012 result = strcmp("PI", bstr_utf8);
3014 if (vt.vt == VT_BSTR && !result)
3019 LIBTEST_API int STDCALL
3020 mono_test_marshal_variant_out_bool_true_unmanaged(VarRefFunc func)
3024 func (VT_BOOL, &vt);
3025 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3030 LIBTEST_API int STDCALL
3031 mono_test_marshal_variant_out_bool_false_unmanaged(VarRefFunc func)
3035 func (VT_BOOL, &vt);
3036 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3041 typedef struct MonoComObject MonoComObject;
3045 int (STDCALL *QueryInterface)(MonoComObject* pUnk, gpointer riid, gpointer* ppv);
3046 int (STDCALL *AddRef)(MonoComObject* pUnk);
3047 int (STDCALL *Release)(MonoComObject* pUnk);
3048 int (STDCALL *get_ITest)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3049 int (STDCALL *SByteIn)(MonoComObject* pUnk, char a);
3050 int (STDCALL *ByteIn)(MonoComObject* pUnk, unsigned char a);
3051 int (STDCALL *ShortIn)(MonoComObject* pUnk, short a);
3052 int (STDCALL *UShortIn)(MonoComObject* pUnk, unsigned short a);
3053 int (STDCALL *IntIn)(MonoComObject* pUnk, int a);
3054 int (STDCALL *UIntIn)(MonoComObject* pUnk, unsigned int a);
3055 int (STDCALL *LongIn)(MonoComObject* pUnk, gint64 a);
3056 int (STDCALL *ULongIn)(MonoComObject* pUnk, guint64 a);
3057 int (STDCALL *FloatIn)(MonoComObject* pUnk, float a);
3058 int (STDCALL *DoubleIn)(MonoComObject* pUnk, double a);
3059 int (STDCALL *ITestIn)(MonoComObject* pUnk, MonoComObject* pUnk2);
3060 int (STDCALL *ITestOut)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3063 struct MonoComObject
3069 static GUID IID_ITest = {0, 0, 0, {0,0,0,0,0,0,0,1}};
3070 static GUID IID_IMonoUnknown = {0, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3071 static GUID IID_IMonoDispatch = {0x00020400, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3073 LIBTEST_API int STDCALL
3074 MonoQueryInterface(MonoComObject* pUnk, gpointer riid, gpointer* ppv)
3078 if (!memcmp(riid, &IID_IMonoUnknown, sizeof(GUID))) {
3082 else if (!memcmp(riid, &IID_ITest, sizeof(GUID))) {
3086 else if (!memcmp(riid, &IID_IMonoDispatch, sizeof(GUID))) {
3090 return 0x80004002; //E_NOINTERFACE;
3093 LIBTEST_API int STDCALL
3094 MonoAddRef(MonoComObject* pUnk)
3096 return ++(pUnk->m_ref);
3099 LIBTEST_API int STDCALL
3100 MonoRelease(MonoComObject* pUnk)
3102 return --(pUnk->m_ref);
3105 LIBTEST_API int STDCALL
3106 SByteIn(MonoComObject* pUnk, char a)
3111 LIBTEST_API int STDCALL
3112 ByteIn(MonoComObject* pUnk, unsigned char a)
3117 LIBTEST_API int STDCALL
3118 ShortIn(MonoComObject* pUnk, short a)
3123 LIBTEST_API int STDCALL
3124 UShortIn(MonoComObject* pUnk, unsigned short a)
3129 LIBTEST_API int STDCALL
3130 IntIn(MonoComObject* pUnk, int a)
3135 LIBTEST_API int STDCALL
3136 UIntIn(MonoComObject* pUnk, unsigned int a)
3141 LIBTEST_API int STDCALL
3142 LongIn(MonoComObject* pUnk, gint64 a)
3147 LIBTEST_API int STDCALL
3148 ULongIn(MonoComObject* pUnk, guint64 a)
3153 LIBTEST_API int STDCALL
3154 FloatIn(MonoComObject* pUnk, float a)
3159 LIBTEST_API int STDCALL
3160 DoubleIn(MonoComObject* pUnk, double a)
3165 LIBTEST_API int STDCALL
3166 ITestIn(MonoComObject* pUnk, MonoComObject *pUnk2)
3171 LIBTEST_API int STDCALL
3172 ITestOut(MonoComObject* pUnk, MonoComObject* *ppUnk)
3177 static void create_com_object (MonoComObject** pOut);
3179 LIBTEST_API int STDCALL
3180 get_ITest(MonoComObject* pUnk, MonoComObject* *ppUnk)
3182 create_com_object (ppUnk);
3186 static void create_com_object (MonoComObject** pOut)
3188 *pOut = marshal_new0 (MonoComObject, 1);
3189 (*pOut)->vtbl = marshal_new0 (MonoIUnknown, 1);
3192 (*pOut)->vtbl->QueryInterface = MonoQueryInterface;
3193 (*pOut)->vtbl->AddRef = MonoAddRef;
3194 (*pOut)->vtbl->Release = MonoRelease;
3195 (*pOut)->vtbl->SByteIn = SByteIn;
3196 (*pOut)->vtbl->ByteIn = ByteIn;
3197 (*pOut)->vtbl->ShortIn = ShortIn;
3198 (*pOut)->vtbl->UShortIn = UShortIn;
3199 (*pOut)->vtbl->IntIn = IntIn;
3200 (*pOut)->vtbl->UIntIn = UIntIn;
3201 (*pOut)->vtbl->LongIn = LongIn;
3202 (*pOut)->vtbl->ULongIn = ULongIn;
3203 (*pOut)->vtbl->FloatIn = FloatIn;
3204 (*pOut)->vtbl->DoubleIn = DoubleIn;
3205 (*pOut)->vtbl->ITestIn = ITestIn;
3206 (*pOut)->vtbl->ITestOut = ITestOut;
3207 (*pOut)->vtbl->get_ITest = get_ITest;
3210 static MonoComObject* same_object = NULL;
3212 LIBTEST_API int STDCALL
3213 mono_test_marshal_com_object_create(MonoComObject* *pUnk)
3215 create_com_object (pUnk);
3218 same_object = *pUnk;
3223 LIBTEST_API int STDCALL
3224 mono_test_marshal_com_object_same(MonoComObject* *pUnk)
3226 *pUnk = same_object;
3231 LIBTEST_API int STDCALL
3232 mono_test_marshal_com_object_destroy(MonoComObject *pUnk)
3234 int ref = --(pUnk->m_ref);
3241 LIBTEST_API int STDCALL
3242 mono_test_marshal_com_object_ref_count(MonoComObject *pUnk)
3247 LIBTEST_API int STDCALL
3248 mono_test_marshal_ccw_itest (MonoComObject *pUnk)
3251 MonoComObject* pTest;
3256 hr = pUnk->vtbl->SByteIn (pUnk, -100);
3259 hr = pUnk->vtbl->ByteIn (pUnk, 100);
3262 hr = pUnk->vtbl->ShortIn (pUnk, -100);
3265 hr = pUnk->vtbl->UShortIn (pUnk, 100);
3268 hr = pUnk->vtbl->IntIn (pUnk, -100);
3271 hr = pUnk->vtbl->UIntIn (pUnk, 100);
3274 hr = pUnk->vtbl->LongIn (pUnk, -100);
3277 hr = pUnk->vtbl->ULongIn (pUnk, 100);
3280 hr = pUnk->vtbl->FloatIn (pUnk, 3.14f);
3283 hr = pUnk->vtbl->DoubleIn (pUnk, 3.14);
3286 hr = pUnk->vtbl->ITestIn (pUnk, pUnk);
3289 hr = pUnk->vtbl->ITestOut (pUnk, &pTest);
3297 * mono_method_get_unmanaged_thunk tests
3300 #if defined(__GNUC__) && ((defined(__i386__) && (defined(__linux__) || defined (__APPLE__)) || defined (__FreeBSD__) || defined(__OpenBSD__)) || (defined(__ppc__) && defined(__APPLE__)))
3301 #define ALIGN(size) __attribute__ ((aligned(size)))
3307 /* thunks.cs:TestStruct */
3308 typedef struct _TestStruct {
3313 /* Searches for mono symbols in all loaded modules */
3315 lookup_mono_symbol (const char *symbol_name)
3318 if (g_module_symbol (g_module_open (NULL, G_MODULE_BIND_LAZY), symbol_name, &symbol))
3324 LIBTEST_API gpointer STDCALL
3325 mono_test_marshal_lookup_symbol (const char *symbol_name)
3327 return lookup_mono_symbol (symbol_name);
3331 * test_method_thunk:
3333 * @test_id: the test number
3334 * @test_method_handle: MonoMethod* of the C# test method
3335 * @create_object_method_handle: MonoMethod* of thunks.cs:Test.CreateObject
3337 LIBTEST_API int STDCALL
3338 test_method_thunk (int test_id, gpointer test_method_handle, gpointer create_object_method_handle)
3340 gpointer (*mono_method_get_unmanaged_thunk)(gpointer)
3341 = lookup_mono_symbol ("mono_method_get_unmanaged_thunk");
3343 gpointer (*mono_string_new_wrapper)(const char *)
3344 = lookup_mono_symbol ("mono_string_new_wrapper");
3346 char* (*mono_string_to_utf8)(gpointer)
3347 = lookup_mono_symbol ("mono_string_to_utf8");
3349 gpointer (*mono_object_unbox)(gpointer)
3350 = lookup_mono_symbol ("mono_object_unbox");
3352 gpointer test_method, ex = NULL;
3353 gpointer (STDCALL *CreateObject)(gpointer*);
3356 if (!mono_method_get_unmanaged_thunk)
3359 test_method = mono_method_get_unmanaged_thunk (test_method_handle);
3363 CreateObject = mono_method_get_unmanaged_thunk (create_object_method_handle);
3371 /* thunks.cs:Test.Test0 */
3372 void (STDCALL *F)(gpointer*) = test_method;
3378 /* thunks.cs:Test.Test1 */
3379 int (STDCALL *F)(gpointer*) = test_method;
3386 /* thunks.cs:Test.Test2 */
3387 gpointer (STDCALL *F)(gpointer, gpointer*) = test_method;
3388 gpointer str = mono_string_new_wrapper ("foo");
3389 if (str != F (str, &ex))
3395 /* thunks.cs:Test.Test3 */
3396 gpointer (STDCALL *F)(gpointer, gpointer, gpointer*);
3401 obj = CreateObject (&ex);
3402 str = mono_string_new_wrapper ("bar");
3404 if (str != F (obj, str, &ex))
3410 /* thunks.cs:Test.Test4 */
3411 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3416 obj = CreateObject (&ex);
3417 str = mono_string_new_wrapper ("bar");
3419 if (42 != F (obj, str, 42, &ex))
3426 /* thunks.cs:Test.Test5 */
3427 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3432 obj = CreateObject (&ex);
3433 str = mono_string_new_wrapper ("bar");
3435 F (obj, str, 42, &ex);
3443 /* thunks.cs:Test.Test6 */
3444 int (STDCALL *F)(gpointer, guint8, gint16, gint32, gint64, float, double,
3445 gpointer, gpointer*);
3447 gpointer str = mono_string_new_wrapper ("Test6");
3451 obj = CreateObject (&ex);
3453 res = F (obj, 254, 32700, -245378, 6789600, 3.1415, 3.1415, str, &ex);
3464 /* thunks.cs:Test.Test7 */
3465 gint64 (STDCALL *F)(gpointer*) = test_method;
3466 if (F (&ex) != G_MAXINT64)
3472 /* thunks.cs:Test.Test8 */
3473 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3474 gpointer*, gpointer*);
3486 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3494 (fabs (a5 - 3.1415) < 0.001) &&
3495 (fabs (a6 - 3.1415) < 0.001) &&
3496 strcmp (mono_string_to_utf8 (a7), "Test8") == 0))
3503 /* thunks.cs:Test.Test9 */
3504 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3505 gpointer*, gpointer*);
3517 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3525 /* thunks.cs:Test.Test10 */
3526 void (STDCALL *F)(gpointer*, gpointer*);
3528 gpointer obj1, obj2;
3530 obj1 = obj2 = CreateObject (&ex);
3547 /* thunks.cs:TestStruct.Test0 */
3548 int (STDCALL *F)(gpointer*, gpointer*);
3554 obj = CreateObject (&ex);
3561 a1 = mono_object_unbox (obj);
3577 /* check whether the call was really by value */
3578 if (a1->A != 42 || a1->B != 3.1415)
3585 /* thunks.cs:TestStruct.Test1 */
3586 void (STDCALL *F)(gpointer, gpointer*);
3591 obj = CreateObject (&ex);
3598 a1 = mono_object_unbox (obj);
3611 if (!fabs (a1->B - 3.1415) < 0.001)
3618 /* thunks.cs:TestStruct.Test2 */
3619 gpointer (STDCALL *F)(gpointer*);
3633 a1 = mono_object_unbox (obj);
3638 if (!fabs (a1->B - 3.1415) < 0.001)
3645 /* thunks.cs:TestStruct.Test3 */
3646 void (STDCALL *F)(gpointer, gpointer*);
3651 obj = CreateObject (&ex);
3658 a1 = mono_object_unbox (obj);
3694 LIBTEST_API int STDCALL
3695 mono_test_Winx64_struct1_in (winx64_struct1 var)
3708 LIBTEST_API int STDCALL
3709 mono_test_Winx64_struct2_in (winx64_struct2 var)
3726 LIBTEST_API int STDCALL
3727 mono_test_Winx64_struct3_in (winx64_struct3 var)
3733 if (var.c != 0x1234)
3746 LIBTEST_API int STDCALL
3747 mono_test_Winx64_struct4_in (winx64_struct4 var)
3753 if (var.c != 0x1234)
3755 if (var.d != 0x87654321)
3767 LIBTEST_API int STDCALL
3768 mono_test_Winx64_struct5_in (winx64_struct5 var)
3786 LIBTEST_API int STDCALL
3787 mono_test_Winx64_struct6_in (winx64_struct6 var)
3798 LIBTEST_API int STDCALL
3799 mono_test_Winx64_structs_in1 (winx64_struct1 var1,
3800 winx64_struct2 var2,
3801 winx64_struct3 var3,
3802 winx64_struct4 var4)
3816 if (var3.c != 0x1234)
3823 if (var4.c != 0x1234)
3825 if (var4.d != 0x87654321)
3830 LIBTEST_API int STDCALL
3831 mono_test_Winx64_structs_in2 (winx64_struct1 var1,
3832 winx64_struct1 var2,
3833 winx64_struct1 var3,
3834 winx64_struct1 var4,
3835 winx64_struct1 var5)
3851 LIBTEST_API int STDCALL
3852 mono_test_Winx64_structs_in3 (winx64_struct1 var1,
3853 winx64_struct5 var2,
3854 winx64_struct1 var3,
3855 winx64_struct5 var4,
3856 winx64_struct1 var5,
3857 winx64_struct5 var6)
3892 LIBTEST_API winx64_struct1 STDCALL
3893 mono_test_Winx64_struct1_ret (void)
3900 LIBTEST_API winx64_struct2 STDCALL
3901 mono_test_Winx64_struct2_ret (void)
3909 LIBTEST_API winx64_struct3 STDCALL
3910 mono_test_Winx64_struct3_ret (void)
3919 LIBTEST_API winx64_struct4 STDCALL
3920 mono_test_Winx64_struct4_ret (void)
3930 LIBTEST_API winx64_struct5 STDCALL
3931 mono_test_Winx64_struct5_ret (void)
3940 LIBTEST_API winx64_struct1 STDCALL
3941 mono_test_Winx64_struct1_ret_5_args (char a, char b, char c, char d, char e)
3944 ret.a = a + b + c + d + e;
3948 LIBTEST_API winx64_struct5 STDCALL
3949 mono_test_Winx64_struct5_ret6_args (char a, char b, char c, char d, char e)
3962 } winx64_floatStruct;
3964 LIBTEST_API int STDCALL
3965 mono_test_Winx64_floatStruct (winx64_floatStruct a)
3967 if (a.a > 5.6 || a.a < 5.4)
3970 if (a.b > 9.6 || a.b < 9.4)
3979 } winx64_doubleStruct;
3981 LIBTEST_API int STDCALL
3982 mono_test_Winx64_doubleStruct (winx64_doubleStruct a)
3984 if (a.a > 5.6 || a.a < 5.4)
3990 typedef int (STDCALL *managed_struct1_delegate) (winx64_struct1 a);
3992 LIBTEST_API int STDCALL
3993 mono_test_managed_Winx64_struct1_in(managed_struct1_delegate func)
4000 typedef int (STDCALL *managed_struct5_delegate) (winx64_struct5 a);
4002 LIBTEST_API int STDCALL
4003 mono_test_managed_Winx64_struct5_in(managed_struct5_delegate func)
4012 typedef int (STDCALL *managed_struct1_struct5_delegate) (winx64_struct1 a, winx64_struct5 b,
4013 winx64_struct1 c, winx64_struct5 d,
4014 winx64_struct1 e, winx64_struct5 f);
4016 LIBTEST_API int STDCALL
4017 mono_test_managed_Winx64_struct1_struct5_in(managed_struct1_struct5_delegate func)
4019 winx64_struct1 a, c, e;
4020 winx64_struct5 b, d, f;
4022 b.a = 2; b.b = 3; b.c = 4;
4024 d.a = 6; d.b = 7; d.c = 8;
4026 f.a = 10; f.b = 11; f.c = 12;
4028 return func (a, b, c, d, e, f);
4031 typedef winx64_struct1 (STDCALL *managed_struct1_ret_delegate) (void);
4033 LIBTEST_API int STDCALL
4034 mono_test_Winx64_struct1_ret_managed (managed_struct1_ret_delegate func)
4046 typedef winx64_struct5 (STDCALL *managed_struct5_ret_delegate) (void);
4048 LIBTEST_API int STDCALL
4049 mono_test_Winx64_struct5_ret_managed (managed_struct5_ret_delegate func)
4065 LIBTEST_API int STDCALL
4066 mono_test_marshal_bool_in (int arg, unsigned int expected, unsigned int bDefaultMarsh, unsigned int bBoolCustMarsh,
4067 char bI1CustMarsh, unsigned char bU1CustMarsh, short bVBCustMarsh)
4071 if (bDefaultMarsh != expected)
4075 if (bBoolCustMarsh != expected)
4079 if (bI1CustMarsh != expected)
4083 if (bU1CustMarsh != expected)
4087 if (bVBCustMarsh != expected)
4096 LIBTEST_API int STDCALL
4097 mono_test_marshal_bool_out (int arg, unsigned int testVal, unsigned int* bDefaultMarsh, unsigned int* bBoolCustMarsh,
4098 char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh)
4104 *bDefaultMarsh = testVal;
4107 if (!bBoolCustMarsh)
4109 *bBoolCustMarsh = testVal;
4114 *bI1CustMarsh = (char)testVal;
4119 *bU1CustMarsh = (unsigned char)testVal;
4124 *bVBCustMarsh = (unsigned short)testVal;
4132 LIBTEST_API int STDCALL
4133 mono_test_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4134 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh,
4135 unsigned short* bVBCustMarsh)
4141 if (*bDefaultMarsh != expected)
4143 *bDefaultMarsh = testVal;
4146 if (!bBoolCustMarsh)
4148 if (*bBoolCustMarsh != expected)
4150 *bBoolCustMarsh = testVal;
4155 if (*bI1CustMarsh != expected)
4157 *bI1CustMarsh = (char)testVal;
4162 if (*bU1CustMarsh != expected)
4164 *bU1CustMarsh = (unsigned char)testVal;
4169 if (*bVBCustMarsh != expected)
4171 *bVBCustMarsh = (unsigned short)testVal;
4180 typedef int (STDCALL *MarshalBoolInDelegate) (int arg, unsigned int expected, unsigned int bDefaultMarsh,
4181 unsigned int bBoolCustMarsh, char bI1CustMarsh, unsigned char bU1CustMarsh, unsigned short bVBCustMarsh);
4183 LIBTEST_API int STDCALL
4184 mono_test_managed_marshal_bool_in (int arg, unsigned int expected, unsigned int testVal, MarshalBoolInDelegate pfcn)
4191 return pfcn (arg, expected, testVal, 0, 0, 0, 0);
4193 return pfcn (arg, expected, 0, testVal, 0, 0, 0);
4195 return pfcn (arg, expected, 0, 0, testVal, 0, 0);
4197 return pfcn (arg, expected, 0, 0, 0, testVal, 0);
4199 return pfcn (arg, expected, 0, 0, 0, 0, testVal);
4207 typedef int (STDCALL *MarshalBoolOutDelegate) (int arg, unsigned int expected, unsigned int* bDefaultMarsh,
4208 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4210 LIBTEST_API int STDCALL
4211 mono_test_managed_marshal_bool_out (int arg, unsigned int expected, unsigned int testVal, MarshalBoolOutDelegate pfcn)
4214 unsigned int lDefaultMarsh, lBoolCustMarsh;
4215 char lI1CustMarsh = 0;
4216 unsigned char lU1CustMarsh = 0;
4217 unsigned short lVBCustMarsh = 0;
4218 lDefaultMarsh = lBoolCustMarsh = 0;
4225 unsigned int ltVal = 0;
4226 ret = pfcn (arg, testVal, <Val, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4228 return 0x0100 + ret;
4229 if (expected != ltVal)
4234 unsigned int ltVal = 0;
4235 ret = pfcn (arg, testVal, &lDefaultMarsh, <Val, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4237 return 0x0300 + ret;
4238 if (expected != ltVal)
4244 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, <Val, &lU1CustMarsh, &lVBCustMarsh);
4246 return 0x0500 + ret;
4247 if (expected != ltVal)
4252 unsigned char ltVal = 0;
4253 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <Val, &lVBCustMarsh);
4255 return 0x0700 + ret;
4256 if (expected != ltVal)
4261 unsigned short ltVal = 0;
4262 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <Val);
4264 return 0x0900 + ret;
4265 if (expected != ltVal)
4276 typedef int (STDCALL *MarshalBoolRefDelegate) (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4277 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4279 LIBTEST_API int STDCALL
4280 mono_test_managed_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int outExpected,
4281 unsigned int outTestVal, MarshalBoolRefDelegate pfcn)
4284 unsigned int lDefaultMarsh, lBoolCustMarsh;
4285 char lI1CustMarsh = 0;
4286 unsigned char lU1CustMarsh = 0;
4287 unsigned short lVBCustMarsh = 0;
4288 lDefaultMarsh = lBoolCustMarsh = 0;
4296 unsigned int ltestVal = testVal;
4297 ret = pfcn (arg, expected, outTestVal, <estVal, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4299 return 0x0100 + ret;
4300 if (outExpected != ltestVal)
4306 unsigned int ltestVal = testVal;
4307 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, <estVal, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4309 return 0x0300 + ret;
4310 if (outExpected != ltestVal)
4316 char ltestVal = testVal;
4317 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, <estVal, &lU1CustMarsh, &lVBCustMarsh);
4319 return 0x0500 + ret;
4320 if (outExpected != ltestVal)
4326 unsigned char ltestVal = testVal;
4327 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <estVal, &lVBCustMarsh);
4329 return 0x0700 + ret;
4330 if (outExpected != ltestVal)
4336 unsigned short ltestVal = testVal;
4337 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <estVal);
4339 return 0x0900 + ret;
4340 if (outExpected != ltestVal)
4353 LIBTEST_API int STDCALL
4354 mono_test_marshal_safearray_out_1dim_vt_bstr_empty (SAFEARRAY** safearray)
4356 /* Create an empty one-dimensional array of variants */
4358 SAFEARRAYBOUND dimensions [1];
4360 dimensions [0].lLbound = 0;
4361 dimensions [0].cElements = 0;
4363 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4368 LIBTEST_API int STDCALL
4369 mono_test_marshal_safearray_out_1dim_vt_bstr (SAFEARRAY** safearray)
4371 /* Create a one-dimensional array of 10 variants filled with "0" to "9" */
4373 SAFEARRAYBOUND dimensions [1];
4379 dimensions [0].lLbound = 0;
4380 dimensions [0].cElements = 10;
4382 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4383 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4385 VariantInit (&vOut);
4387 _ltoa (i,buffer,10);
4388 vOut.bstrVal= marshal_bstr_alloc (buffer);
4390 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4391 VariantClear (&vOut);
4392 SafeArrayDestroy (pSA);
4395 VariantClear (&vOut);
4401 LIBTEST_API int STDCALL
4402 mono_test_marshal_safearray_out_2dim_vt_i4 (SAFEARRAY** safearray)
4404 /* Create a two-dimensional array of 4x3 variants filled with 11, 12, 13, etc. */
4406 SAFEARRAYBOUND dimensions [2];
4411 dimensions [0].lLbound = 0;
4412 dimensions [0].cElements = 4;
4413 dimensions [1].lLbound = 0;
4414 dimensions [1].cElements = 3;
4416 pSA= SafeArrayCreate(VT_VARIANT, 2, dimensions);
4417 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4418 for (j= dimensions [1].lLbound; j< (dimensions [1].cElements + dimensions [1].lLbound); j++) {
4420 VariantInit (&vOut);
4422 vOut.lVal = (i+1)*10+(j+1);
4425 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4426 VariantClear (&vOut);
4427 SafeArrayDestroy (pSA);
4430 VariantClear (&vOut); // does a deep destroy of source VARIANT
4437 LIBTEST_API int STDCALL
4438 mono_test_marshal_safearray_out_4dim_vt_i4 (SAFEARRAY** safearray)
4440 /* Create a four-dimensional array of 10x3x6x7 variants filled with their indices */
4441 /* Also use non zero lower bounds */
4443 SAFEARRAYBOUND dimensions [4];
4448 dimensions [0].lLbound = 15;
4449 dimensions [0].cElements = 10;
4450 dimensions [1].lLbound = 20;
4451 dimensions [1].cElements = 3;
4452 dimensions [2].lLbound = 5;
4453 dimensions [2].cElements = 6;
4454 dimensions [3].lLbound = 12;
4455 dimensions [3].cElements = 7;
4457 pSA= SafeArrayCreate (VT_VARIANT, 4, dimensions);
4459 SafeArrayAccessData (pSA, (void **)&pData);
4461 for (i= 0; i< 10*3*6*7; i++) {
4462 VariantInit(&pData [i]);
4463 pData [i].vt = VT_I4;
4466 SafeArrayUnaccessData (pSA);
4471 LIBTEST_API int STDCALL
4472 mono_test_marshal_safearray_in_byval_1dim_empty (SAFEARRAY* safearray)
4474 /* Check that array is one dimensional and empty */
4477 long lbound, ubound;
4479 dim = SafeArrayGetDim (safearray);
4483 SafeArrayGetLBound (safearray, 1, &lbound);
4484 SafeArrayGetUBound (safearray, 1, &ubound);
4486 if ((lbound > 0) || (ubound > 0))
4492 LIBTEST_API int STDCALL
4493 mono_test_marshal_safearray_in_byval_1dim_vt_i4 (SAFEARRAY* safearray)
4495 /* Check that array is one dimensional containing integers from 1 to 10 */
4498 long lbound, ubound;
4503 dim = SafeArrayGetDim (safearray);
4507 SafeArrayGetLBound (safearray, 1, &lbound);
4508 SafeArrayGetUBound (safearray, 1, &ubound);
4510 if ((lbound != 0) || (ubound != 9))
4513 SafeArrayAccessData (safearray, (void **)&pData);
4514 for (i= lbound; i <= ubound; i++) {
4515 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i + 1))
4518 SafeArrayUnaccessData (safearray);
4523 LIBTEST_API int STDCALL
4524 mono_test_marshal_safearray_in_byval_1dim_vt_mixed (SAFEARRAY* safearray)
4526 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4529 long lbound, ubound;
4536 VariantInit (&element);
4538 dim = SafeArrayGetDim (safearray);
4542 SafeArrayGetLBound (safearray, 1, &lbound);
4543 SafeArrayGetUBound (safearray, 1, &ubound);
4545 if ((lbound != 0) || (ubound != 12))
4548 SafeArrayAccessData (safearray, (void **)&pData);
4549 for (i= lbound; i <= ubound; i++) {
4550 if ((i%2 == 0) && (pData [i].vt != VT_I4))
4552 if ((i%2 == 1) && (pData [i].vt != VT_BSTR))
4554 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i))
4557 SafeArrayUnaccessData (safearray);
4559 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4564 SafeArrayPutElement (safearray, indices, &element);
4565 VariantClear (&element);
4570 LIBTEST_API int STDCALL
4571 mono_test_marshal_safearray_in_byval_2dim_vt_i4 (SAFEARRAY* safearray)
4573 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4576 long lbound1, ubound1, lbound2, ubound2;
4581 VariantInit (&element);
4583 dim = SafeArrayGetDim (safearray);
4587 SafeArrayGetLBound (safearray, 1, &lbound1);
4588 SafeArrayGetUBound (safearray, 1, &ubound1);
4590 if ((lbound1 != 0) || (ubound1 != 1))
4593 SafeArrayGetLBound (safearray, 2, &lbound2);
4594 SafeArrayGetUBound (safearray, 2, &ubound2);
4596 if ((lbound2 != 0) || (ubound2 != 3)) {
4600 for (i= lbound1; i <= ubound1; i++) {
4602 for (j= lbound2; j <= ubound2; j++) {
4604 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4606 failed = ((element.vt != VT_I4) || (element.lVal != 10*(i+1)+(j+1)));
4607 VariantClear (&element);
4613 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4619 SafeArrayPutElement (safearray, indices, &element);
4620 VariantClear (&element);
4625 LIBTEST_API int STDCALL
4626 mono_test_marshal_safearray_in_byval_3dim_vt_bstr (SAFEARRAY* safearray)
4628 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4631 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4632 long i, j, k, failed;
4636 VariantInit (&element);
4638 dim = SafeArrayGetDim (safearray);
4642 SafeArrayGetLBound (safearray, 1, &lbound1);
4643 SafeArrayGetUBound (safearray, 1, &ubound1);
4645 if ((lbound1 != 0) || (ubound1 != 1))
4648 SafeArrayGetLBound (safearray, 2, &lbound2);
4649 SafeArrayGetUBound (safearray, 2, &ubound2);
4651 if ((lbound2 != 0) || (ubound2 != 1))
4654 SafeArrayGetLBound (safearray, 3, &lbound3);
4655 SafeArrayGetUBound (safearray, 3, &ubound3);
4657 if ((lbound3 != 0) || (ubound3 != 2))
4660 for (i= lbound1; i <= ubound1; i++) {
4662 for (j= lbound2; j <= ubound2; j++) {
4664 for (k= lbound3; k <= ubound3; k++) {
4666 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4668 failed = ((element.vt != VT_BSTR)
4669 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4670 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4671 VariantClear (&element);
4678 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4683 element.vt = VT_BSTR;
4684 element.bstrVal = SysAllocString(L"Should not be copied");
4685 SafeArrayPutElement (safearray, indices, &element);
4686 VariantClear (&element);
4691 LIBTEST_API int STDCALL
4692 mono_test_marshal_safearray_in_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4694 return mono_test_marshal_safearray_in_byval_3dim_vt_bstr (*safearray);
4697 LIBTEST_API int STDCALL
4698 mono_test_marshal_safearray_in_out_byref_1dim_empty (SAFEARRAY** safearray)
4700 /* Check that the input array is what is expected and change it so the caller can check */
4701 /* correct marshalling back to managed code */
4704 long lbound, ubound;
4705 SAFEARRAYBOUND dimensions [1];
4707 wchar_t buffer [20];
4711 /* Check that in array is one dimensional and empty */
4713 dim = SafeArrayGetDim (*safearray);
4718 SafeArrayGetLBound (*safearray, 1, &lbound);
4719 SafeArrayGetUBound (*safearray, 1, &ubound);
4721 if ((lbound > 0) || (ubound > 0)) {
4725 /* Re-dimension the array and return a one-dimensional array of 8 variants filled with "0" to "7" */
4727 dimensions [0].lLbound = 0;
4728 dimensions [0].cElements = 8;
4730 hr = SafeArrayRedim (*safearray, dimensions);
4734 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
4736 VariantInit (&vOut);
4738 _ltow (i,buffer,10);
4739 vOut.bstrVal = SysAllocString (buffer);
4741 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
4742 VariantClear (&vOut);
4743 SafeArrayDestroy (*safearray);
4746 VariantClear (&vOut);
4751 LIBTEST_API int STDCALL
4752 mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4754 /* Check that the input array is what is expected and change it so the caller can check */
4755 /* correct marshalling back to managed code */
4758 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4759 SAFEARRAYBOUND dimensions [1];
4760 long i, j, k, failed;
4761 wchar_t buffer [20];
4766 VariantInit (&element);
4768 /* Check that in array is three dimensional and contains the expected values */
4770 dim = SafeArrayGetDim (*safearray);
4774 SafeArrayGetLBound (*safearray, 1, &lbound1);
4775 SafeArrayGetUBound (*safearray, 1, &ubound1);
4777 if ((lbound1 != 0) || (ubound1 != 1))
4780 SafeArrayGetLBound (*safearray, 2, &lbound2);
4781 SafeArrayGetUBound (*safearray, 2, &ubound2);
4783 if ((lbound2 != 0) || (ubound2 != 1))
4786 SafeArrayGetLBound (*safearray, 3, &lbound3);
4787 SafeArrayGetUBound (*safearray, 3, &ubound3);
4789 if ((lbound3 != 0) || (ubound3 != 2))
4792 for (i= lbound1; i <= ubound1; i++) {
4794 for (j= lbound2; j <= ubound2; j++) {
4796 for (k= lbound3; k <= ubound3; k++) {
4798 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
4800 failed = ((element.vt != VT_BSTR)
4801 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4802 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4803 VariantClear (&element);
4810 hr = SafeArrayDestroy (*safearray);
4814 /* Return a new one-dimensional array of 8 variants filled with "0" to "7" */
4816 dimensions [0].lLbound = 0;
4817 dimensions [0].cElements = 8;
4819 *safearray = SafeArrayCreate (VT_VARIANT, 1, dimensions);
4821 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
4823 VariantInit (&vOut);
4825 _ltow (i,buffer,10);
4826 vOut.bstrVal = SysAllocString (buffer);
4828 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
4829 VariantClear (&vOut);
4830 SafeArrayDestroy (*safearray);
4833 VariantClear (&vOut);
4838 LIBTEST_API int STDCALL
4839 mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 (SAFEARRAY** safearray)
4841 /* Check that the input array is what is expected and change it so the caller can check */
4842 /* correct marshalling back to managed code */
4845 long lbound1, ubound1;
4851 VariantInit (&element);
4853 /* Check that in array is one dimensional and contains the expected value */
4855 dim = SafeArrayGetDim (*safearray);
4859 SafeArrayGetLBound (*safearray, 1, &lbound1);
4860 SafeArrayGetUBound (*safearray, 1, &ubound1);
4863 if ((lbound1 != 0) || (ubound1 != 1))
4867 for (i= lbound1; i <= ubound1; i++) {
4869 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
4871 failed = (element.vt != VT_I4) || (element.lVal != i+1);
4872 VariantClear (&element);
4877 /* Change one of the elements of the array to verify that [out] parameter is marshalled back to the managed side */
4882 SafeArrayPutElement (*safearray, indices, &element);
4883 VariantClear (&element);
4888 LIBTEST_API int STDCALL
4889 mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (SAFEARRAY* safearray)
4891 /* Check that the input array is what is expected and change it so the caller can check */
4892 /* correct marshalling back to managed code */
4895 long lbound1, ubound1;
4896 SAFEARRAYBOUND dimensions [1];
4902 VariantInit (&element);
4904 /* Check that in array is one dimensional and contains the expected value */
4906 dim = SafeArrayGetDim (safearray);
4910 SafeArrayGetLBound (safearray, 1, &lbound1);
4911 SafeArrayGetUBound (safearray, 1, &ubound1);
4913 if ((lbound1 != 0) || (ubound1 != 0))
4916 for (i= lbound1; i <= ubound1; i++) {
4918 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4920 failed = (element.vt != VT_I4) || (element.lVal != i+1);
4921 VariantClear (&element);
4926 /* Change the array to verify how [out] parameter is marshalled back to the managed side */
4928 /* Redimension the array */
4929 dimensions [0].lLbound = lbound1;
4930 dimensions [0].cElements = 2;
4931 hr = SafeArrayRedim(safearray, dimensions);
4935 element.lVal = 12345;
4936 SafeArrayPutElement (safearray, indices, &element);
4937 VariantClear (&element);
4941 element.lVal = -12345;
4942 SafeArrayPutElement (safearray, indices, &element);
4943 VariantClear (&element);
4948 LIBTEST_API int STDCALL
4949 mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr (SAFEARRAY* safearray)
4951 /* Check that the input array is what is expected and change it so the caller can check */
4952 /* correct marshalling back to managed code */
4955 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4956 long i, j, k, failed;
4961 VariantInit (&element);
4963 /* Check that in array is three dimensional and contains the expected values */
4965 dim = SafeArrayGetDim (safearray);
4969 SafeArrayGetLBound (safearray, 1, &lbound1);
4970 SafeArrayGetUBound (safearray, 1, &ubound1);
4972 if ((lbound1 != 0) || (ubound1 != 1))
4975 SafeArrayGetLBound (safearray, 2, &lbound2);
4976 SafeArrayGetUBound (safearray, 2, &ubound2);
4978 if ((lbound2 != 0) || (ubound2 != 1))
4981 SafeArrayGetLBound (safearray, 3, &lbound3);
4982 SafeArrayGetUBound (safearray, 3, &ubound3);
4984 if ((lbound3 != 0) || (ubound3 != 2))
4987 for (i= lbound1; i <= ubound1; i++) {
4989 for (j= lbound2; j <= ubound2; j++) {
4991 for (k= lbound3; k <= ubound3; k++) {
4993 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4995 failed = ((element.vt != VT_BSTR)
4996 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4997 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4998 VariantClear (&element);
5005 /* Change the elements of the array to verify that [out] parameter is marshalled back to the managed side */
5012 SafeArrayPutElement (safearray, indices, &element);
5013 VariantClear (&element);
5020 SafeArrayPutElement (safearray, indices, &element);
5021 VariantClear (&element);
5026 element.vt = VT_BSTR;
5027 element.bstrVal = marshal_bstr_alloc("ABCDEFG");
5028 SafeArrayPutElement (safearray, indices, &element);
5029 VariantClear (&element);
5034 LIBTEST_API int STDCALL
5035 mono_test_marshal_safearray_mixed(
5036 SAFEARRAY *safearray1,
5037 SAFEARRAY **safearray2,
5038 SAFEARRAY *safearray3,
5039 SAFEARRAY **safearray4
5044 /* Initialize out parameters */
5047 /* array1: Check that in array is one dimensional and contains the expected value */
5048 hr = mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (safearray1);
5050 /* array2: Fill in with some values to check on the managed side */
5052 hr = mono_test_marshal_safearray_out_1dim_vt_bstr (safearray2);
5054 /* array3: Check that in array is one dimensional and contains the expected value */
5056 hr = mono_test_marshal_safearray_in_byval_1dim_vt_mixed(safearray3);
5058 /* array4: Check input values and fill in with some values to check on the managed side */
5060 hr = mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr(safearray4);
5067 static int call_managed_res;
5070 call_managed (gpointer arg)
5072 SimpleDelegate del = arg;
5074 call_managed_res = del (42);
5077 LIBTEST_API int STDCALL
5078 mono_test_marshal_thread_attach (SimpleDelegate del)
5086 res = pthread_create (&t, NULL, (gpointer)call_managed, del);
5087 g_assert (res == 0);
5088 pthread_join (t, NULL);
5090 return call_managed_res;
5094 typedef int (STDCALL *Callback) (void);
5096 static Callback callback;
5098 LIBTEST_API void STDCALL
5099 mono_test_marshal_set_callback (Callback cb)
5104 LIBTEST_API int STDCALL
5105 mono_test_marshal_call_callback (void)
5110 LIBTEST_API int STDCALL
5111 mono_test_marshal_lpstr (char *str)
5113 return strcmp ("ABC", str);
5116 LIBTEST_API int STDCALL
5117 mono_test_marshal_lpwstr (gunichar2 *str)
5122 s = g_utf16_to_utf8 (str, -1, NULL, NULL, NULL);
5123 res = strcmp ("ABC", s);
5129 LIBTEST_API char* STDCALL
5130 mono_test_marshal_return_lpstr (void)
5132 char *res = marshal_alloc (4);
5133 strcpy (res, "XYZ");
5138 LIBTEST_API gunichar2* STDCALL
5139 mono_test_marshal_return_lpwstr (void)
5141 gunichar2 *res = marshal_alloc (8);
5142 gunichar2* tmp = g_utf8_to_utf16 ("XYZ", -1, NULL, NULL, NULL);
5144 memcpy (res, tmp, 8);