14 #define STDCALL __stdcall
20 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
24 extern __declspec(dllimport) __stdcall void CoTaskMemFree(void *ptr);
27 typedef int (STDCALL *SimpleDelegate) (int a);
29 static void marshal_free (void *ptr)
38 static void* marshal_alloc (gsize size)
41 return CoTaskMemAlloc (size);
43 return g_malloc (size);
47 STDCALL unsigned short*
48 test_lpwstr_marshal (unsigned short* chars, long length)
53 res = marshal_alloc (2 * (length + 1));
55 // printf("test_lpwstr_marshal()\n");
57 while ( i < length ) {
58 // printf("X|%u|\n", chars[i]);
70 test_lpwstr_marshal_out (unsigned short** chars)
73 const char abc[] = "ABC";
74 glong len = strlen(abc);
76 *chars = marshal_alloc (2 * (len + 1));
79 (*chars) [i] = abc[i];
93 mono_union_test_1 (union_test_1_type u1) {
94 // printf ("Got values %d %d %d\n", u1.b, u1.a, u1.c);
95 return u1.a + u1.b + u1.c;
99 mono_return_int (int a) {
100 // printf ("Got value %d\n", a);
110 mono_return_int_ss (struct ss a) {
111 // printf ("Got value %d\n", a.i);
116 mono_return_ss (struct ss a) {
117 // printf ("Got value %d\n", a.i);
128 mono_return_sc1 (struct sc1 a) {
129 // printf ("Got value %d\n", a.c[0]);
141 mono_return_sc3 (struct sc3 a) {
142 // printf ("Got values %d %d %d\n", a.c[0], a.c[1], a.c[2]);
155 mono_return_sc5 (struct sc5 a) {
156 // printf ("Got values %d %d %d %d %d\n", a.c[0], a.c[1], a.c[2], a.c[3], a.c[4]);
172 mono_return_int_su (union su a) {
173 // printf ("Got value %d\n", a.i1);
178 mono_test_many_int_arguments (int a, int b, int c, int d, int e,
179 int f, int g, int h, int i, int j);
181 mono_test_many_short_arguments (short a, short b, short c, short d, short e,
182 short f, short g, short h, short i, short j);
184 mono_test_many_char_arguments (char a, char b, char c, char d, char e,
185 char f, char g, char h, char i, char j);
188 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)
190 return a + b + c + d + e + f + g + h + i + j;
194 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)
196 return a + b + c + d + e + f + g + h + i + j;
200 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)
202 return a + b + c + d + e + f + g + h + i + j;
206 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)
208 return a + b + c + d + e + f + g + h + i + j;
212 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)
214 return a + b + c + d + e + f + g + h + i + j;
218 mono_test_split_double_arguments (double a, double b, float c, double d, double e)
220 return a + b + c + d + e;
224 mono_test_puts_static (char *s)
226 // printf ("TEST %s\n", s);
230 typedef int (STDCALL *SimpleDelegate3) (int a, int b);
233 mono_invoke_delegate (SimpleDelegate3 delegate)
237 // printf ("start invoke %p\n", delegate);
239 res = delegate (2, 3);
241 // printf ("end invoke\n");
247 mono_test_marshal_char (short a1)
256 mono_test_marshal_char_array (gunichar2 *s)
258 const char m[] = "abcdef";
262 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
271 mono_test_empty_pinvoke (int i)
277 mono_test_marshal_bool_byref (int a, int *b, int c)
287 mono_test_marshal_bool_in_as_I1_U1 (char bTrue, char bFalse)
297 mono_test_marshal_bool_out_as_I1_U1 (char* bTrue, char* bFalse)
299 if (!bTrue || !bFalse)
309 mono_test_marshal_bool_ref_as_I1_U1 (char* bTrue, char* bFalse)
311 if (!bTrue || !bFalse)
326 mono_test_marshal_array (int *a1)
330 for (i = 0; i < 50; i++)
337 mono_test_marshal_inout_array (int *a1)
341 for (i = 0; i < 50; i++) {
343 a1 [i] = 50 - a1 [i];
350 mono_test_marshal_out_array (int *a1)
354 for (i = 0; i < 50; i++) {
362 mono_test_marshal_inout_nonblittable_array (gunichar2 *a1)
366 for (i = 0; i < 10; i++) {
387 mono_test_return_vtype (int i)
390 static gunichar2 test2 [] = { 'T', 'E', 'S', 'T', '2', 0 };
402 mono_test_delegate_struct (void)
404 // printf ("TEST\n");
407 typedef char* (STDCALL *ReturnStringDelegate) (const char *s);
410 mono_test_return_string (ReturnStringDelegate func)
414 // printf ("mono_test_return_string\n");
419 // printf ("got string: %s\n", res);
420 return g_strdup ("12345");
423 typedef int (STDCALL *RefVTypeDelegate) (int a, simplestruct *ss, int b);
426 mono_test_ref_vtype (int a, simplestruct *ss, int b, RefVTypeDelegate func)
428 if (a == 1 && b == 2 && ss->a == 0 && ss->b == 1 && ss->c == 0 &&
429 !strcmp (ss->d, "TEST1")) {
435 return func (a, ss, b);
441 typedef int (STDCALL *OutVTypeDelegate) (int a, simplestruct *ss, int b);
444 mono_test_marshal_out_struct (int a, simplestruct *ss, int b, OutVTypeDelegate func)
446 /* Check that the input pointer is ignored */
447 ss->d = (gpointer)0x12345678;
451 if (ss->a && ss->b && ss->c && !strcmp (ss->d, "TEST3"))
459 SimpleDelegate func, func2;
462 STDCALL DelegateStruct
463 mono_test_marshal_delegate_struct (DelegateStruct ds)
467 res.a = ds.func (ds.a) + ds.func2 (ds.a);
469 res.func2 = ds.func2;
475 mono_test_marshal_struct (simplestruct ss)
477 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
478 !strcmp (ss.d, "TEST"))
485 mono_test_marshal_byref_struct (simplestruct *ss, int a, int b, int c, char *d)
487 gboolean res = (ss->a == a && ss->b == b && ss->c == c && strcmp (ss->d, d) == 0);
489 marshal_free ((char*)ss->d);
494 ss->d = g_strdup ("DEF");
511 mono_test_marshal_struct2 (simplestruct2 ss)
513 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
514 !strcmp (ss.d, "TEST") &&
515 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
521 /* on HP some of the struct should be on the stack and not in registers */
523 mono_test_marshal_struct2_2 (int i, int j, int k, simplestruct2 ss)
525 if (i != 10 || j != 11 || k != 12)
527 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
528 !strcmp (ss.d, "TEST") &&
529 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
536 mono_test_marshal_lpstruct (simplestruct *ss)
538 if (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
539 !strcmp (ss->d, "TEST"))
546 mono_test_marshal_lpstruct_blittable (point *p)
548 if (p->x == 1.0 && p->y == 2.0)
555 mono_test_marshal_struct_array (simplestruct2 *ss)
557 if (! (ss[0].a == 0 && ss[0].b == 1 && ss[0].c == 0 &&
558 !strcmp (ss[0].d, "TEST") &&
559 ss[0].e == 99 && ss[0].f == 1.5 && ss[0].g == 42 && ss[0].h == (guint64)123))
562 if (! (ss[1].a == 0 && ss[1].b == 0 && ss[1].c == 0 &&
563 !strcmp (ss[1].d, "TEST2") &&
564 ss[1].e == 100 && ss[1].f == 2.5 && ss[1].g == 43 && ss[1].h == (guint64)124))
570 typedef struct long_align_struct {
577 mono_test_marshal_long_align_struct_array (long_align_struct *ss)
579 return ss[0].a + ss[0].b + ss[0].c + ss[1].a + ss[1].b + ss[1].c;
582 STDCALL simplestruct2 *
583 mono_test_marshal_class (int i, int j, int k, simplestruct2 *ss, int l)
590 if (i != 10 || j != 11 || k != 12 || l != 14)
592 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
593 !strcmp (ss->d, "TEST") &&
594 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
597 res = g_new0 (simplestruct2, 1);
598 memcpy (res, ss, sizeof (simplestruct2));
599 res->d = g_strdup ("TEST");
604 mono_test_marshal_byref_class (simplestruct2 **ssp)
606 simplestruct2 *ss = *ssp;
609 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
610 !strcmp (ss->d, "TEST") &&
611 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
614 res = g_new0 (simplestruct2, 1);
615 memcpy (res, ss, sizeof (simplestruct2));
616 res->d = g_strdup ("TEST-RES");
628 /* Yes, this is correct, we are only trying to determine the value of the stack here */
634 reliable_delegate (int a)
640 * Checks whether get_sp() works as expected. It doesn't work with gcc-2.95.3 on linux.
643 is_get_sp_reliable (void)
647 reliable_delegate(1);
649 reliable_delegate(1);
655 mono_test_marshal_delegate (SimpleDelegate delegate)
659 /* Check that the delegate wrapper is stdcall */
664 if (is_get_sp_reliable())
665 g_assert (sp1 == sp2);
670 STDCALL SimpleDelegate
671 mono_test_marshal_return_delegate (SimpleDelegate delegate)
677 return_plus_one (int i)
682 STDCALL SimpleDelegate
683 mono_test_marshal_return_delegate_2 (void)
685 return return_plus_one;
688 typedef simplestruct (STDCALL *SimpleDelegate2) (simplestruct ss);
691 is_utf16_equals (gunichar2 *s1, const char *s2)
696 s = g_utf16_to_utf8 (s1, -1, NULL, NULL, NULL);
697 res = strcmp (s, s2);
704 mono_test_marshal_delegate2 (SimpleDelegate2 delegate)
706 simplestruct ss, res;
712 ss.d2 = g_utf8_to_utf16 ("TEST2", -1, NULL, NULL, NULL);
715 if (! (res.a && !res.b && res.c && !strcmp (res.d, "TEST-RES") && is_utf16_equals (res.d2, "TEST2-RES")))
721 typedef simplestruct* (STDCALL *SimpleDelegate4) (simplestruct *ss);
724 mono_test_marshal_delegate4 (SimpleDelegate4 delegate)
735 res = delegate (&ss);
739 /* Check return value */
740 if (! (!res->a && res->b && !res->c && !strcmp (res->d, "TEST")))
743 /* Check NULL argument and NULL result */
744 res = delegate (NULL);
751 typedef int (STDCALL *SimpleDelegate5) (simplestruct **ss);
754 mono_test_marshal_delegate5 (SimpleDelegate5 delegate)
767 res = delegate (&ptr);
771 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
778 mono_test_marshal_delegate6 (SimpleDelegate5 delegate)
782 res = delegate (NULL);
787 typedef int (STDCALL *SimpleDelegate7) (simplestruct **ss);
790 mono_test_marshal_delegate7 (SimpleDelegate7 delegate)
795 /* Check that the input pointer is ignored */
796 ptr = (gpointer)0x12345678;
798 res = delegate (&ptr);
802 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
808 typedef int (STDCALL *InOutByvalClassDelegate) (simplestruct *ss);
811 mono_test_marshal_inout_byval_class_delegate (InOutByvalClassDelegate delegate)
819 ss.d = g_strdup_printf ("%s", "FOO");
821 res = delegate (&ss);
825 if (!(ss.a && !ss.b && ss.c && !strcmp (ss.d, "RES")))
831 typedef int (STDCALL *SimpleDelegate8) (gunichar2 *s);
834 mono_test_marshal_delegate8 (SimpleDelegate8 delegate, gunichar2 *s)
839 typedef int (STDCALL *return_int_fnt) (int i);
840 typedef int (STDCALL *SimpleDelegate9) (return_int_fnt d);
843 mono_test_marshal_delegate9 (SimpleDelegate9 delegate, gpointer ftn)
845 return delegate (ftn);
855 mono_test_marshal_delegate10 (SimpleDelegate9 delegate)
857 return delegate (return_self);
860 typedef int (STDCALL *PrimitiveByrefDelegate) (int *i);
863 mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate delegate)
867 int res = delegate (&i);
877 typedef int (STDCALL *return_int_delegate) (int i);
879 typedef return_int_delegate (STDCALL *ReturnDelegateDelegate) (void);
882 mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d)
888 mono_test_marshal_stringbuilder (char *s, int n)
890 const char m[] = "This is my message. Isn't it nice?";
892 if (strcmp (s, "ABCD") != 0)
900 mono_test_marshal_stringbuilder_default (char *s, int n)
902 const char m[] = "This is my message. Isn't it nice?";
910 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
912 const char m[] = "This is my message. Isn't it nice?";
916 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
935 mono_test_marshal_empty_string_array (char **array)
937 return (array == NULL) ? 0 : 1;
941 mono_test_marshal_string_array (char **array)
943 if (strcmp (array [0], "ABC"))
945 if (strcmp (array [1], "DEF"))
948 if (array [2] != NULL)
955 mono_test_marshal_byref_string_array (char ***array)
960 if (strcmp ((*array) [0], "Alpha"))
962 if (strcmp ((*array) [1], "Beta"))
964 if (strcmp ((*array) [2], "Gamma"))
971 mono_test_marshal_stringbuilder_array (char **array)
973 if (strcmp (array [0], "ABC"))
975 if (strcmp (array [1], "DEF"))
978 strcpy (array [0], "DEF");
979 strcpy (array [1], "ABC");
985 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
987 GError *error = NULL;
990 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
991 if (strcmp (s, "ABC")) {
998 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
999 if (strcmp (s, "DEF")) {
1006 if (strcmp (array2 [0], "ABC"))
1009 if (strcmp (array2 [1], "DEF"))
1015 /* this does not work on Redhat gcc 2.96 */
1017 mono_test_empty_struct (int a, EmptyStruct es, int b)
1019 // printf ("mono_test_empty_struct %d %d\n", a, b);
1021 // Intel icc on ia64 passes 'es' in 2 registers
1022 #if defined(__ia64) && defined(__INTEL_COMPILER)
1025 if (a == 1 && b == 2)
1035 STDCALL ByValStrStruct *
1036 mono_test_byvalstr_gen (void)
1038 ByValStrStruct *ret;
1040 ret = malloc(sizeof(ByValStrStruct));
1041 memset(ret, 'a', sizeof(ByValStrStruct)-1);
1042 ret->a[sizeof(ByValStrStruct)-1] = 0;
1048 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
1052 ret = strcmp(data->a, correctString);
1053 // printf ("T1: %s\n", data->a);
1054 // printf ("T2: %s\n", correctString);
1056 marshal_free (data);
1063 } ByValStrStruct_Unicode;
1066 mono_test_byvalstr_check_unicode (ByValStrStruct_Unicode *ref, int test)
1068 if (ref->flag != 0x1234abcd){
1069 printf ("overwritten data");
1073 if (test == 1 || test == 3){
1074 if (ref->a [0] != '1' ||
1075 ref->a [1] != '2' ||
1081 if (ref->a [0] != '1' ||
1090 NameManglingAnsi (char *data)
1092 return data [0] + data [1] + data [2];
1096 NameManglingAnsiA (char *data)
1098 g_assert_not_reached ();
1102 NameManglingAnsiW (char *data)
1104 g_assert_not_reached ();
1108 NameManglingAnsi2A (char *data)
1110 return data [0] + data [1] + data [2];
1114 NameManglingAnsi2W (char *data)
1116 g_assert_not_reached ();
1120 NameManglingUnicode (char *data)
1122 g_assert_not_reached ();
1126 NameManglingUnicodeW (gunichar2 *data)
1128 return data [0] + data [1] + data [2];
1132 NameManglingUnicode2 (gunichar2 *data)
1134 return data [0] + data [1] + data [2];
1138 NameManglingAutoW (char *data)
1141 return (data [0] + data [1] + data [2]) == 131 ? 0 : 1;
1143 g_assert_not_reached ();
1148 NameManglingAuto (char *data)
1151 return (data [0] + data [1] + data [2]) == 198 ? 0 : 1;
1153 g_assert_not_reached ();
1157 typedef int (STDCALL *intcharFunc)(const char*);
1160 callFunction (intcharFunc f)
1171 class_marshal_test0 (SimpleObj *obj1)
1173 // printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
1175 if (strcmp(obj1->str, "T1"))
1184 class_marshal_test4 (SimpleObj *obj1)
1193 class_marshal_test1 (SimpleObj **obj1)
1195 SimpleObj *res = malloc (sizeof (SimpleObj));
1197 res->str = g_strdup ("ABC");
1204 class_marshal_test2 (SimpleObj **obj1)
1206 // printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
1208 if (strcmp((*obj1)->str, "ABC"))
1210 if ((*obj1)->i != 5)
1217 string_marshal_test0 (char *str)
1219 if (strcmp (str, "TEST0"))
1226 string_marshal_test1 (const char **str)
1228 *str = g_strdup ("TEST1");
1232 string_marshal_test2 (char **str)
1234 // printf ("string_marshal_test2 %s\n", *str);
1236 if (strcmp (*str, "TEST1"))
1243 string_marshal_test3 (char *str)
1256 STDCALL BlittableClass*
1257 TestBlittableClass (BlittableClass *vl)
1259 BlittableClass *res;
1261 // printf ("TestBlittableClass %d %d\n", vl->a, vl->b);
1267 res = g_new0 (BlittableClass, 1);
1268 memcpy (res, vl, sizeof (BlittableClass));
1270 res = g_new0 (BlittableClass, 1);
1278 typedef struct OSVERSIONINFO_STRUCT
1282 } OSVERSIONINFO_STRUCT;
1285 MyGetVersionEx (OSVERSIONINFO_STRUCT *osvi)
1288 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1293 return osvi->a + osvi->b;
1297 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO_STRUCT *osvi)
1300 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1305 return osvi->a + osvi->b;
1309 mono_test_marshal_point (point pt)
1311 // printf("point %g %g\n", pt.x, pt.y);
1312 if (pt.x == 1.25 && pt.y == 3.5)
1324 mono_test_marshal_mixed_point (mixed_point pt)
1326 // printf("mixed point %d %g\n", pt.x, pt.y);
1327 if (pt.x == 5 && pt.y == 6.75)
1334 mono_test_marshal_mixed_point_2 (mixed_point *pt)
1336 if (pt->x != 5 || pt->y != 6.75)
1346 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
1349 if (*b1 != 0 && *b1 != 1)
1351 if (*b2 != 0 && *b2 != -1) /* variant_bool */
1353 if (*b3 != 0 && *b3 != 1)
1355 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
1367 short b2; /* variant_bool */
1372 marshal_test_bool_struct(struct BoolStruct *s)
1375 if (s->b1 != 0 && s->b1 != 1)
1377 if (s->b2 != 0 && s->b2 != -1)
1379 if (s->b3 != 0 && s->b3 != 1)
1381 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1390 mono_test_last_error (int err)
1400 mono_test_asany (void *ptr, int what)
1404 return (*(int*)ptr == 5) ? 0 : 1;
1406 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1408 simplestruct2 ss = *(simplestruct2*)ptr;
1410 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1411 !strcmp (ss.d, "TEST") &&
1412 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1418 GError *error = NULL;
1421 s = g_utf16_to_utf8 (ptr, -1, NULL, NULL, &error);
1422 if (!strcmp (s, "ABC")) {
1432 g_assert_not_reached ();
1447 mono_test_marshal_asany_in (void* ptr)
1449 AsAnyStruct* asAny = ptr;
1450 int res = asAny->i + asAny->j + asAny->k;
1456 mono_test_marshal_asany_inout (void* ptr)
1458 AsAnyStruct* asAny = ptr;
1459 int res = asAny->i + asAny->j + asAny->k;
1461 marshal_free (asAny->s);
1472 mono_test_marshal_asany_out (void* ptr)
1474 AsAnyStruct* asAny = ptr;
1475 int res = asAny->i + asAny->j + asAny->k;
1486 * AMD64 marshalling tests.
1489 typedef struct amd64_struct1 {
1496 STDCALL amd64_struct1
1497 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
1507 typedef struct amd64_struct2 {
1512 STDCALL amd64_struct2
1513 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
1521 typedef struct amd64_struct3 {
1525 STDCALL amd64_struct3
1526 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s)
1533 typedef struct amd64_struct4 {
1537 STDCALL amd64_struct4
1538 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s)
1547 * IA64 marshalling tests.
1549 typedef struct test_struct5 {
1553 STDCALL test_struct5
1554 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, test_struct5 s, double d3, double d4)
1562 typedef struct test_struct6 {
1566 STDCALL test_struct6
1567 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, test_struct6 s, double d3, double d4)
1575 static guint32 custom_res [2];
1578 mono_test_marshal_pass_return_custom (int i, guint32 *ptr, int j)
1580 /* ptr will be freed by CleanupNative, so make a copy */
1581 custom_res [0] = 0; /* not allocated by AllocHGlobal */
1582 custom_res [1] = ptr [1];
1588 mono_test_marshal_pass_out_custom (int i, guint32 **ptr, int j)
1591 custom_res [1] = i + j + 10;
1599 mono_test_marshal_pass_inout_custom (int i, guint32 *ptr, int j)
1602 ptr [1] = i + ptr [1] + j;
1608 mono_test_marshal_pass_out_byval_custom (int i, guint32 *ptr, int j)
1610 return ptr == NULL ? 0 : 1;
1614 mono_test_marshal_pass_byref_custom (int i, guint32 **ptr, int j)
1622 mono_test_marshal_pass_return_custom2 (int i, guint32 *ptr, int j)
1624 g_assert_not_reached ();
1630 mono_test_marshal_pass_return_custom_null (int i, guint32 *ptr, int j)
1632 g_assert (ptr == NULL);
1637 typedef void *(STDCALL *PassReturnPtrDelegate) (void *ptr);
1640 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del)
1654 /* FIXME: Freed with FreeHGlobal */
1663 mono_test_marshal_pass_return_custom_null_in_delegate (PassReturnPtrDelegate del)
1665 void *ptr = del (NULL);
1667 return (ptr == NULL) ? 15 : 0;
1670 typedef void (STDCALL *CustomOutParamDelegate) (void **pptr);
1673 mono_test_marshal_custom_out_param_delegate (CustomOutParamDelegate del)
1685 typedef int (STDCALL *ReturnEnumDelegate) (int e);
1688 mono_test_marshal_return_enum_delegate (ReturnEnumDelegate func)
1698 typedef BlittableStruct (STDCALL *SimpleDelegate10) (BlittableStruct ss);
1701 mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 delegate)
1703 BlittableStruct ss, res;
1710 res = delegate (ss);
1711 if (! ((res.a == -1) && (res.b == -2) && (res.c == -3) && (res.d == -55)))
1718 mono_test_stdcall_name_mangling (int a, int b, int c)
1724 * PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
1731 typedef SmallStruct1 (STDCALL *SmallStructDelegate1) (SmallStruct1 ss);
1734 mono_test_marshal_small_struct_delegate1 (SmallStructDelegate1 delegate)
1736 SmallStruct1 ss, res;
1740 res = delegate (ss);
1741 if (! (res.i == -1))
1751 typedef SmallStruct2 (STDCALL *SmallStructDelegate2) (SmallStruct2 ss);
1754 mono_test_marshal_small_struct_delegate2 (SmallStructDelegate2 delegate)
1756 SmallStruct2 ss, res;
1761 res = delegate (ss);
1762 if (! ((res.i == -2) && (res.j == -3)))
1773 typedef SmallStruct3 (STDCALL *SmallStructDelegate3) (SmallStruct3 ss);
1776 mono_test_marshal_small_struct_delegate3 (SmallStructDelegate3 delegate)
1778 SmallStruct3 ss, res;
1783 res = delegate (ss);
1784 if (! ((res.i == -1) && (res.j == -2)))
1794 typedef SmallStruct4 (STDCALL *SmallStructDelegate4) (SmallStruct4 ss);
1797 mono_test_marshal_small_struct_delegate4 (SmallStructDelegate4 delegate)
1799 SmallStruct4 ss, res;
1803 res = delegate (ss);
1804 if (! (res.i == -1))
1814 typedef SmallStruct5 (STDCALL *SmallStructDelegate5) (SmallStruct5 ss);
1817 mono_test_marshal_small_struct_delegate5 (SmallStructDelegate5 delegate)
1819 SmallStruct5 ss, res;
1823 res = delegate (ss);
1824 if (! (res.i == -5))
1834 typedef SmallStruct6 (STDCALL *SmallStructDelegate6) (SmallStruct6 ss);
1837 mono_test_marshal_small_struct_delegate6 (SmallStructDelegate6 delegate)
1839 SmallStruct6 ss, res;
1844 res = delegate (ss);
1845 if (! ((res.i == -1) && (res.j == -2)))
1856 typedef SmallStruct7 (STDCALL *SmallStructDelegate7) (SmallStruct7 ss);
1859 mono_test_marshal_small_struct_delegate7 (SmallStructDelegate7 delegate)
1861 SmallStruct7 ss, res;
1866 res = delegate (ss);
1867 if (! ((res.i == -1) && (res.j == -2)))
1877 typedef SmallStruct8 (STDCALL *SmallStructDelegate8) (SmallStruct8 ss);
1880 mono_test_marshal_small_struct_delegate8 (SmallStructDelegate8 delegate)
1882 SmallStruct8 ss, res;
1886 res = delegate (ss);
1887 if (! ((res.i == -1.0)))
1897 typedef SmallStruct9 (STDCALL *SmallStructDelegate9) (SmallStruct9 ss);
1900 mono_test_marshal_small_struct_delegate9 (SmallStructDelegate9 delegate)
1902 SmallStruct9 ss, res;
1906 res = delegate (ss);
1907 if (! ((res.i == -1.0)))
1917 typedef SmallStruct10 (STDCALL *SmallStructDelegate10) (SmallStruct10 ss);
1920 mono_test_marshal_small_struct_delegate10 (SmallStructDelegate10 delegate)
1922 SmallStruct10 ss, res;
1927 res = delegate (ss);
1928 if (! ((res.i == -1.0) && (res.j == -2.0)))
1939 typedef SmallStruct11 (STDCALL *SmallStructDelegate11) (SmallStruct11 ss);
1942 mono_test_marshal_small_struct_delegate11 (SmallStructDelegate11 delegate)
1944 SmallStruct11 ss, res;
1949 res = delegate (ss);
1950 if (! ((res.i == -1.0) && (res.j == -2)))
1956 typedef int (STDCALL *ArrayDelegate) (int i, char *j, void *arr);
1959 mono_test_marshal_array_delegate (void *arr, int len, ArrayDelegate del)
1961 return del (len, NULL, arr);
1965 mono_test_marshal_out_array_delegate (int *arr, int len, ArrayDelegate del)
1967 del (len, NULL, arr);
1969 if ((arr [0] != 1) || (arr [1] != 2))
1975 typedef gunichar2* (STDCALL *UnicodeStringDelegate) (gunichar2 *message);
1978 mono_test_marshal_return_unicode_string_delegate (UnicodeStringDelegate del)
1980 const char m[] = "abcdef";
1981 gunichar2 *s2, *res;
1984 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1994 mono_test_marshal_out_string_array_delegate (char **arr, int len, ArrayDelegate del)
1996 del (len, NULL, arr);
1998 if (!strcmp (arr [0], "ABC") && !strcmp (arr [1], "DEF"))
2004 typedef int (*CdeclDelegate) (int i, int j);
2007 mono_test_marshal_cdecl_delegate (CdeclDelegate del)
2011 for (i = 0; i < 1000; ++i)
2017 typedef char** (*ReturnStringArrayDelegate) (int i);
2020 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d)
2028 if (strcmp (arr [0], "ABC") || strcmp (arr [1], "DEF"))
2039 add_delegate (int i, int j)
2045 mono_test_marshal_return_fnptr (void)
2047 return &add_delegate;
2053 printf ("codigo %x\n", code);
2062 mono_xr_as_handle (int code)
2077 mono_safe_handle_struct_ref (HandleStructs *x)
2079 printf ("Dingus Ref! \n");
2080 printf ("Values: %d %d %p %p\n", x->a, x->b, x->handle1, x->handle2);
2086 if (x->handle1 != (void*) 0x7080feed)
2089 if (x->handle2 != (void*) 0x1234abcd)
2096 mono_safe_handle_struct (HandleStructs x)
2098 printf ("Dingus Standard! \n");
2099 printf ("Values: %d %d %p %p\n", x.a, x.b, x.handle1, x.handle2);
2105 if (x.handle1 != (void*) 0x7080feed)
2108 if (x.handle2 != (void*) 0x1234abcd)
2119 mono_safe_handle_struct_simple (TrivialHandle x)
2121 printf ("The value is %p\n", x.a);
2122 return ((int)(gsize)x.a) * 2;
2126 mono_safe_handle_return (void)
2132 mono_safe_handle_ref (void **handle)
2135 *handle = (void *) 0xbad;
2139 *handle = (void *) 0x800d;
2148 mono_test_marshal_bstr_in(BSTR bstr)
2150 if (!wcscmp(bstr, L"mono_test_marshal_bstr_in"))
2156 mono_test_marshal_bstr_out(BSTR* bstr)
2158 *bstr = SysAllocString(L"mono_test_marshal_bstr_out");
2163 mono_test_marshal_bstr_in_null(BSTR bstr)
2171 mono_test_marshal_bstr_out_null(BSTR* bstr)
2178 mono_test_marshal_variant_in_sbyte(VARIANT variant)
2180 if (variant.vt == VT_I1 && variant.cVal == 100)
2186 mono_test_marshal_variant_in_byte(VARIANT variant)
2188 if (variant.vt == VT_UI1 && variant.bVal == 100)
2194 mono_test_marshal_variant_in_short(VARIANT variant)
2196 if (variant.vt == VT_I2 && variant.iVal == 314)
2202 mono_test_marshal_variant_in_ushort(VARIANT variant)
2204 if (variant.vt == VT_UI2 && variant.uiVal == 314)
2210 mono_test_marshal_variant_in_int(VARIANT variant)
2212 if (variant.vt == VT_I4 && variant.lVal == 314)
2218 mono_test_marshal_variant_in_uint(VARIANT variant)
2220 if (variant.vt == VT_UI4 && variant.ulVal == 314)
2226 mono_test_marshal_variant_in_long(VARIANT variant)
2228 if (variant.vt == VT_I8 && variant.llVal == 314)
2234 mono_test_marshal_variant_in_ulong(VARIANT variant)
2236 if (variant.vt == VT_UI8 && variant.ullVal == 314)
2242 mono_test_marshal_variant_in_float(VARIANT variant)
2244 if (variant.vt == VT_R4 && (variant.fltVal - 3.14)/3.14 < .001)
2250 mono_test_marshal_variant_in_double(VARIANT variant)
2252 if (variant.vt == VT_R8 && (variant.dblVal - 3.14)/3.14 < .001)
2258 mono_test_marshal_variant_in_bstr(VARIANT variant)
2260 if (variant.vt == VT_BSTR && !wcscmp(variant.bstrVal, L"PI"))
2266 mono_test_marshal_variant_in_bool_true (VARIANT variant)
2268 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_TRUE)
2274 mono_test_marshal_variant_in_bool_false (VARIANT variant)
2276 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_FALSE)
2282 mono_test_marshal_variant_out_sbyte(VARIANT* variant)
2284 variant->vt = VT_I1;
2285 variant->cVal = 100;
2291 mono_test_marshal_variant_out_byte(VARIANT* variant)
2293 variant->vt = VT_UI1;
2294 variant->bVal = 100;
2300 mono_test_marshal_variant_out_short(VARIANT* variant)
2302 variant->vt = VT_I2;
2303 variant->iVal = 314;
2309 mono_test_marshal_variant_out_ushort(VARIANT* variant)
2311 variant->vt = VT_UI2;
2312 variant->uiVal = 314;
2318 mono_test_marshal_variant_out_int(VARIANT* variant)
2320 variant->vt = VT_I4;
2321 variant->lVal = 314;
2327 mono_test_marshal_variant_out_uint(VARIANT* variant)
2329 variant->vt = VT_UI4;
2330 variant->ulVal = 314;
2336 mono_test_marshal_variant_out_long(VARIANT* variant)
2338 variant->vt = VT_I8;
2339 variant->llVal = 314;
2345 mono_test_marshal_variant_out_ulong(VARIANT* variant)
2347 variant->vt = VT_UI8;
2348 variant->ullVal = 314;
2354 mono_test_marshal_variant_out_float(VARIANT* variant)
2356 variant->vt = VT_R4;
2357 variant->fltVal = 3.14;
2363 mono_test_marshal_variant_out_double(VARIANT* variant)
2365 variant->vt = VT_R8;
2366 variant->dblVal = 3.14;
2372 mono_test_marshal_variant_out_bstr(VARIANT* variant)
2374 variant->vt = VT_BSTR;
2375 variant->bstrVal = SysAllocString(L"PI");
2381 mono_test_marshal_variant_out_bool_true (VARIANT* variant)
2383 variant->vt = VT_BOOL;
2384 variant->boolVal = VARIANT_TRUE;
2390 mono_test_marshal_variant_out_bool_false (VARIANT* variant)
2392 variant->vt = VT_BOOL;
2393 variant->boolVal = VARIANT_FALSE;
2398 typedef int (STDCALL *VarFunc) (int vt, VARIANT variant);
2399 typedef int (STDCALL *VarRefFunc) (int vt, VARIANT* variant);
2402 mono_test_marshal_variant_in_sbyte_unmanaged(VarFunc func)
2407 return func (VT_I1, vt);
2411 mono_test_marshal_variant_in_byte_unmanaged(VarFunc func)
2416 return func (VT_UI1, vt);
2420 mono_test_marshal_variant_in_short_unmanaged(VarFunc func)
2425 return func (VT_I2, vt);
2429 mono_test_marshal_variant_in_ushort_unmanaged(VarFunc func)
2434 return func (VT_UI2, vt);
2438 mono_test_marshal_variant_in_int_unmanaged(VarFunc func)
2443 return func (VT_I4, vt);
2447 mono_test_marshal_variant_in_uint_unmanaged(VarFunc func)
2452 return func (VT_UI4, vt);
2456 mono_test_marshal_variant_in_long_unmanaged(VarFunc func)
2461 return func (VT_I8, vt);
2465 mono_test_marshal_variant_in_ulong_unmanaged(VarFunc func)
2470 return func (VT_UI8, vt);
2474 mono_test_marshal_variant_in_float_unmanaged(VarFunc func)
2479 return func (VT_R4, vt);
2483 mono_test_marshal_variant_in_double_unmanaged(VarFunc func)
2488 return func (VT_R8, vt);
2492 mono_test_marshal_variant_in_bstr_unmanaged(VarFunc func)
2496 vt.bstrVal = SysAllocString(L"PI");
2497 return func (VT_BSTR, vt);
2501 mono_test_marshal_variant_in_bool_true_unmanaged(VarFunc func)
2505 vt.boolVal = VARIANT_TRUE;
2506 return func (VT_BOOL, vt);
2510 mono_test_marshal_variant_in_bool_false_unmanaged(VarFunc func)
2514 vt.boolVal = VARIANT_FALSE;
2515 return func (VT_BOOL, vt);
2519 mono_test_marshal_variant_out_sbyte_unmanaged(VarRefFunc func)
2524 if (vt.vt == VT_I1 && vt.cVal == -100)
2530 mono_test_marshal_variant_out_byte_unmanaged(VarRefFunc func)
2535 if (vt.vt == VT_UI1 && vt.bVal == 100)
2541 mono_test_marshal_variant_out_short_unmanaged(VarRefFunc func)
2546 if (vt.vt == VT_I2 && vt.iVal == -100)
2552 mono_test_marshal_variant_out_ushort_unmanaged(VarRefFunc func)
2557 if (vt.vt == VT_UI2 && vt.uiVal == 100)
2563 mono_test_marshal_variant_out_int_unmanaged(VarRefFunc func)
2568 if (vt.vt == VT_I4 && vt.lVal == -100)
2574 mono_test_marshal_variant_out_uint_unmanaged(VarRefFunc func)
2579 if (vt.vt == VT_UI4 && vt.ulVal == 100)
2585 mono_test_marshal_variant_out_long_unmanaged(VarRefFunc func)
2590 if (vt.vt == VT_I8 && vt.llVal == -100)
2596 mono_test_marshal_variant_out_ulong_unmanaged(VarRefFunc func)
2601 if (vt.vt == VT_UI8 && vt.ullVal == 100)
2607 mono_test_marshal_variant_out_float_unmanaged(VarRefFunc func)
2612 if (vt.vt == VT_R4 && fabs (vt.fltVal - 3.14f) < 1e-10)
2618 mono_test_marshal_variant_out_double_unmanaged(VarRefFunc func)
2623 if (vt.vt == VT_R8 && fabs (vt.dblVal - 3.14) < 1e-10)
2629 mono_test_marshal_variant_out_bstr_unmanaged(VarRefFunc func)
2633 func (VT_BSTR, &vt);
2634 if (vt.vt == VT_BSTR && !wcscmp(vt.bstrVal, L"PI"))
2640 mono_test_marshal_variant_out_bool_true_unmanaged(VarRefFunc func)
2644 func (VT_BOOL, &vt);
2645 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
2651 mono_test_marshal_variant_out_bool_false_unmanaged(VarRefFunc func)
2655 func (VT_BOOL, &vt);
2656 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
2661 typedef struct MonoComObject MonoComObject;
2665 int (STDCALL *QueryInterface)(MonoComObject* pUnk, gpointer riid, gpointer* ppv);
2666 int (STDCALL *AddRef)(MonoComObject* pUnk);
2667 int (STDCALL *Release)(MonoComObject* pUnk);
2668 int (STDCALL *get_ITest)(MonoComObject* pUnk, MonoComObject* *ppUnk);
2669 int (STDCALL *SByteIn)(MonoComObject* pUnk, char a);
2670 int (STDCALL *ByteIn)(MonoComObject* pUnk, unsigned char a);
2671 int (STDCALL *ShortIn)(MonoComObject* pUnk, short a);
2672 int (STDCALL *UShortIn)(MonoComObject* pUnk, unsigned short a);
2673 int (STDCALL *IntIn)(MonoComObject* pUnk, int a);
2674 int (STDCALL *UIntIn)(MonoComObject* pUnk, unsigned int a);
2675 int (STDCALL *LongIn)(MonoComObject* pUnk, LONGLONG a);
2676 int (STDCALL *ULongIn)(MonoComObject* pUnk, ULONGLONG a);
2677 int (STDCALL *FloatIn)(MonoComObject* pUnk, float a);
2678 int (STDCALL *DoubleIn)(MonoComObject* pUnk, double a);
2679 int (STDCALL *ITestIn)(MonoComObject* pUnk, MonoComObject* pUnk2);
2680 int (STDCALL *ITestOut)(MonoComObject* pUnk, MonoComObject* *ppUnk);
2683 struct MonoComObject
2689 DEFINE_GUID(IID_ITest, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
2690 DEFINE_GUID(IID_IMonoUnknown, 0, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46);
2691 DEFINE_GUID(IID_IMonoDispatch, 0x00020400, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46);
2693 int STDCALL MonoQueryInterface(MonoComObject* pUnk, gpointer riid, gpointer* ppv)
2696 if (!memcmp(riid, &IID_IMonoUnknown, sizeof(GUID))) {
2700 else if (!memcmp(riid, &IID_ITest, sizeof(GUID))) {
2704 else if (!memcmp(riid, &IID_IMonoDispatch, sizeof(GUID))) {
2708 return E_NOINTERFACE;
2711 int STDCALL MonoAddRef(MonoComObject* pUnk)
2713 return ++(pUnk->m_ref);
2716 int STDCALL MonoRelease(MonoComObject* pUnk)
2718 return --(pUnk->m_ref);
2721 int STDCALL SByteIn(MonoComObject* pUnk, char a)
2726 int STDCALL ByteIn(MonoComObject* pUnk, unsigned char a)
2731 int STDCALL ShortIn(MonoComObject* pUnk, short a)
2736 int STDCALL UShortIn(MonoComObject* pUnk, unsigned short a)
2741 int STDCALL IntIn(MonoComObject* pUnk, int a)
2746 int STDCALL UIntIn(MonoComObject* pUnk, unsigned int a)
2751 int STDCALL LongIn(MonoComObject* pUnk, LONGLONG a)
2756 int STDCALL ULongIn(MonoComObject* pUnk, ULONGLONG a)
2761 int STDCALL FloatIn(MonoComObject* pUnk, float a)
2766 int STDCALL DoubleIn(MonoComObject* pUnk, double a)
2771 int STDCALL ITestIn(MonoComObject* pUnk, MonoComObject *pUnk2)
2776 int STDCALL ITestOut(MonoComObject* pUnk, MonoComObject* *ppUnk)
2781 int STDCALL get_ITest(MonoComObject* pUnk, MonoComObject* *ppUnk)
2786 static void create_com_object (MonoComObject** pOut)
2788 *pOut = g_new0 (MonoComObject, 1);
2789 (*pOut)->vtbl = g_new0 (MonoIUnknown, 1);
2792 (*pOut)->vtbl->QueryInterface = MonoQueryInterface;
2793 (*pOut)->vtbl->AddRef = MonoAddRef;
2794 (*pOut)->vtbl->Release = MonoRelease;
2795 (*pOut)->vtbl->SByteIn = SByteIn;
2796 (*pOut)->vtbl->ByteIn = ByteIn;
2797 (*pOut)->vtbl->ShortIn = ShortIn;
2798 (*pOut)->vtbl->UShortIn = UShortIn;
2799 (*pOut)->vtbl->IntIn = IntIn;
2800 (*pOut)->vtbl->UIntIn = UIntIn;
2801 (*pOut)->vtbl->LongIn = LongIn;
2802 (*pOut)->vtbl->ULongIn = ULongIn;
2803 (*pOut)->vtbl->FloatIn = FloatIn;
2804 (*pOut)->vtbl->DoubleIn = DoubleIn;
2805 (*pOut)->vtbl->ITestIn = ITestIn;
2806 (*pOut)->vtbl->ITestOut = ITestOut;
2807 (*pOut)->vtbl->get_ITest = get_ITest;
2810 static MonoComObject* same_object = NULL;
2813 mono_test_marshal_com_object_create(MonoComObject* *pUnk)
2815 create_com_object (pUnk);
2818 same_object = *pUnk;
2824 mono_test_marshal_com_object_same(MonoComObject* *pUnk)
2826 *pUnk = same_object;
2832 mono_test_marshal_com_object_destroy(MonoComObject *pUnk)
2834 int ref = --(pUnk->m_ref);
2842 mono_test_marshal_com_object_ref_count(MonoComObject *pUnk)
2848 mono_test_marshal_ccw_itest (MonoComObject *pUnk)
2851 MonoComObject* pTest;
2856 hr = pUnk->vtbl->SByteIn (pUnk, -100);
2859 hr = pUnk->vtbl->ByteIn (pUnk, 100);
2862 hr = pUnk->vtbl->ShortIn (pUnk, -100);
2865 hr = pUnk->vtbl->UShortIn (pUnk, 100);
2868 hr = pUnk->vtbl->IntIn (pUnk, -100);
2871 hr = pUnk->vtbl->UIntIn (pUnk, 100);
2874 hr = pUnk->vtbl->LongIn (pUnk, -100);
2877 hr = pUnk->vtbl->ULongIn (pUnk, 100);
2880 hr = pUnk->vtbl->FloatIn (pUnk, 3.14f);
2883 hr = pUnk->vtbl->DoubleIn (pUnk, 3.14);
2886 hr = pUnk->vtbl->ITestIn (pUnk, pUnk);
2889 hr = pUnk->vtbl->ITestOut (pUnk, &pTest);