14 #define STDCALL __stdcall
20 extern __declspec(dllimport) __stdcall void CoTaskMemFree(void *ptr);
23 typedef int (STDCALL *SimpleDelegate) (int a);
25 static void marshal_free (void *ptr)
34 STDCALL unsigned short*
35 test_lpwstr_marshal (unsigned short* chars, long length)
40 res = malloc (2 * (length + 1));
42 // printf("test_lpwstr_marshal()\n");
44 while ( i < length ) {
45 // printf("X|%u|\n", chars[i]);
62 mono_union_test_1 (union_test_1_type u1) {
63 // printf ("Got values %d %d %d\n", u1.b, u1.a, u1.c);
64 return u1.a + u1.b + u1.c;
68 mono_return_int (int a) {
69 // printf ("Got value %d\n", a);
79 mono_return_int_ss (struct ss a) {
80 // printf ("Got value %d\n", a.i);
85 mono_return_ss (struct ss a) {
86 // printf ("Got value %d\n", a.i);
97 mono_return_sc1 (struct sc1 a) {
98 // printf ("Got value %d\n", a.c[0]);
110 mono_return_sc3 (struct sc3 a) {
111 // printf ("Got values %d %d %d\n", a.c[0], a.c[1], a.c[2]);
124 mono_return_sc5 (struct sc5 a) {
125 // printf ("Got values %d %d %d %d %d\n", a.c[0], a.c[1], a.c[2], a.c[3], a.c[4]);
141 mono_return_int_su (union su a) {
142 // printf ("Got value %d\n", a.i1);
147 mono_test_many_int_arguments (int a, int b, int c, int d, int e,
148 int f, int g, int h, int i, int j);
150 mono_test_many_short_arguments (short a, short b, short c, short d, short e,
151 short f, short g, short h, short i, short j);
153 mono_test_many_char_arguments (char a, char b, char c, char d, char e,
154 char f, char g, char h, char i, char j);
157 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)
159 return a + b + c + d + e + f + g + h + i + j;
163 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)
165 return a + b + c + d + e + f + g + h + i + j;
169 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)
171 return a + b + c + d + e + f + g + h + i + j;
175 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)
177 return a + b + c + d + e + f + g + h + i + j;
181 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)
183 return a + b + c + d + e + f + g + h + i + j;
187 mono_test_split_double_arguments (double a, double b, float c, double d, double e)
189 return a + b + c + d + e;
193 mono_test_puts_static (char *s)
195 // printf ("TEST %s\n", s);
199 typedef int (STDCALL *SimpleDelegate3) (int a, int b);
202 mono_invoke_delegate (SimpleDelegate3 delegate)
206 // printf ("start invoke %p\n", delegate);
208 res = delegate (2, 3);
210 // printf ("end invoke\n");
216 mono_test_marshal_char (short a1)
225 mono_test_marshal_char_array (gunichar2 *s)
227 const char m[] = "abcdef";
231 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
240 mono_test_empty_pinvoke (int i)
246 mono_test_marshal_bool_byref (int a, int *b, int c)
256 mono_test_marshal_array (int *a1)
260 for (i = 0; i < 50; i++)
267 mono_test_marshal_inout_array (int *a1)
271 for (i = 0; i < 50; i++) {
273 a1 [i] = 50 - a1 [i];
280 mono_test_marshal_out_array (int *a1)
284 for (i = 0; i < 50; i++) {
292 mono_test_marshal_inout_nonblittable_array (gunichar2 *a1)
296 for (i = 0; i < 10; i++) {
317 mono_test_return_vtype (int i)
320 static gunichar2 test2 [] = { 'T', 'E', 'S', 'T', '2', 0 };
332 mono_test_delegate_struct (void)
334 // printf ("TEST\n");
337 typedef char* (STDCALL *ReturnStringDelegate) (const char *s);
340 mono_test_return_string (ReturnStringDelegate func)
344 // printf ("mono_test_return_string\n");
349 // printf ("got string: %s\n", res);
350 return g_strdup ("12345");
353 typedef int (STDCALL *RefVTypeDelegate) (int a, simplestruct *ss, int b);
356 mono_test_ref_vtype (int a, simplestruct *ss, int b, RefVTypeDelegate func)
358 if (a == 1 && b == 2 && ss->a == 0 && ss->b == 1 && ss->c == 0 &&
359 !strcmp (ss->d, "TEST1")) {
365 return func (a, ss, b);
371 typedef int (STDCALL *OutVTypeDelegate) (int a, simplestruct *ss, int b);
374 mono_test_marshal_out_struct (int a, simplestruct *ss, int b, OutVTypeDelegate func)
376 /* Check that the input pointer is ignored */
377 ss->d = (gpointer)0x12345678;
381 if (ss->a && ss->b && ss->c && !strcmp (ss->d, "TEST3"))
389 SimpleDelegate func, func2;
392 STDCALL DelegateStruct
393 mono_test_marshal_delegate_struct (DelegateStruct ds)
397 res.a = ds.func (ds.a) + ds.func2 (ds.a);
399 res.func2 = ds.func2;
405 mono_test_marshal_struct (simplestruct ss)
407 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
408 !strcmp (ss.d, "TEST"))
415 mono_test_marshal_byref_struct (simplestruct *ss, int a, int b, int c, char *d)
417 gboolean res = (ss->a == a && ss->b == b && ss->c == c && strcmp (ss->d, d) == 0);
419 marshal_free (ss->d);
424 ss->d = g_strdup ("DEF");
441 mono_test_marshal_struct2 (simplestruct2 ss)
443 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
444 !strcmp (ss.d, "TEST") &&
445 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
451 /* on HP some of the struct should be on the stack and not in registers */
453 mono_test_marshal_struct2_2 (int i, int j, int k, simplestruct2 ss)
455 if (i != 10 || j != 11 || k != 12)
457 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
458 !strcmp (ss.d, "TEST") &&
459 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
466 mono_test_marshal_lpstruct (simplestruct *ss)
468 if (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
469 !strcmp (ss->d, "TEST"))
476 mono_test_marshal_lpstruct_blittable (point *p)
478 if (p->x == 1.0 && p->y == 2.0)
485 mono_test_marshal_struct_array (simplestruct2 *ss)
487 if (! (ss[0].a == 0 && ss[0].b == 1 && ss[0].c == 0 &&
488 !strcmp (ss[0].d, "TEST") &&
489 ss[0].e == 99 && ss[0].f == 1.5 && ss[0].g == 42 && ss[0].h == (guint64)123))
492 if (! (ss[1].a == 0 && ss[1].b == 0 && ss[1].c == 0 &&
493 !strcmp (ss[1].d, "TEST2") &&
494 ss[1].e == 100 && ss[1].f == 2.5 && ss[1].g == 43 && ss[1].h == (guint64)124))
500 typedef struct long_align_struct {
507 mono_test_marshal_long_align_struct_array (long_align_struct *ss)
509 return ss[0].a + ss[0].b + ss[0].c + ss[1].a + ss[1].b + ss[1].c;
512 STDCALL simplestruct2 *
513 mono_test_marshal_class (int i, int j, int k, simplestruct2 *ss, int l)
520 if (i != 10 || j != 11 || k != 12 || l != 14)
522 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
523 !strcmp (ss->d, "TEST") &&
524 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
527 res = g_new0 (simplestruct2, 1);
528 memcpy (res, ss, sizeof (simplestruct2));
529 res->d = g_strdup ("TEST");
534 mono_test_marshal_byref_class (simplestruct2 **ssp)
536 simplestruct2 *ss = *ssp;
539 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
540 !strcmp (ss->d, "TEST") &&
541 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
544 res = g_new0 (simplestruct2, 1);
545 memcpy (res, ss, sizeof (simplestruct2));
546 res->d = g_strdup ("TEST-RES");
558 /* Yes, this is correct, we are only trying to determine the value of the stack here */
564 reliable_delegate (int a)
570 * Checks whether get_sp() works as expected. It doesn't work with gcc-2.95.3 on linux.
573 is_get_sp_reliable (void)
577 reliable_delegate(1);
579 reliable_delegate(1);
585 mono_test_marshal_delegate (SimpleDelegate delegate)
589 /* Check that the delegate wrapper is stdcall */
594 if (is_get_sp_reliable())
595 g_assert (sp1 == sp2);
600 STDCALL SimpleDelegate
601 mono_test_marshal_return_delegate (SimpleDelegate delegate)
607 return_plus_one (int i)
612 STDCALL SimpleDelegate
613 mono_test_marshal_return_delegate_2 ()
615 return return_plus_one;
618 typedef simplestruct (STDCALL *SimpleDelegate2) (simplestruct ss);
621 is_utf16_equals (gunichar2 *s1, const char *s2)
626 s = g_utf16_to_utf8 (s1, -1, NULL, NULL, NULL);
627 res = strcmp (s, s2);
634 mono_test_marshal_delegate2 (SimpleDelegate2 delegate)
636 simplestruct ss, res;
642 ss.d2 = g_utf8_to_utf16 ("TEST2", -1, NULL, NULL, NULL);
645 if (! (res.a && !res.b && res.c && !strcmp (res.d, "TEST-RES") && is_utf16_equals (res.d2, "TEST2-RES")))
651 typedef simplestruct* (STDCALL *SimpleDelegate4) (simplestruct *ss);
654 mono_test_marshal_delegate4 (SimpleDelegate4 delegate)
665 res = delegate (&ss);
669 /* Check return value */
670 if (! (!res->a && res->b && !res->c && !strcmp (res->d, "TEST")))
673 /* Check NULL argument and NULL result */
674 res = delegate (NULL);
681 typedef int (STDCALL *SimpleDelegate5) (simplestruct **ss);
684 mono_test_marshal_delegate5 (SimpleDelegate5 delegate)
697 res = delegate (&ptr);
701 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
708 mono_test_marshal_delegate6 (SimpleDelegate5 delegate)
712 res = delegate (NULL);
717 typedef int (STDCALL *SimpleDelegate7) (simplestruct **ss);
720 mono_test_marshal_delegate7 (SimpleDelegate7 delegate)
725 /* Check that the input pointer is ignored */
726 ptr = (gpointer)0x12345678;
728 res = delegate (&ptr);
732 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
738 typedef int (STDCALL *InOutByvalClassDelegate) (simplestruct *ss);
741 mono_test_marshal_inout_byval_class_delegate (InOutByvalClassDelegate delegate)
749 ss.d = g_strdup_printf ("%s", "FOO");
751 res = delegate (&ss);
755 if (!(ss.a && !ss.b && ss.c && !strcmp (ss.d, "RES")))
761 typedef int (STDCALL *SimpleDelegate8) (gunichar2 *s);
764 mono_test_marshal_delegate8 (SimpleDelegate8 delegate, gunichar2 *s)
769 typedef int (STDCALL *return_int_fnt) (int i);
770 typedef int (STDCALL *SimpleDelegate9) (return_int_fnt d);
773 mono_test_marshal_delegate9 (SimpleDelegate9 delegate, gpointer ftn)
775 return delegate (ftn);
785 mono_test_marshal_delegate10 (SimpleDelegate9 delegate)
787 return delegate (return_self);
790 typedef int (STDCALL *PrimitiveByrefDelegate) (int *i);
793 mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate delegate)
797 int res = delegate (&i);
807 typedef int (STDCALL *return_int_delegate) (int i);
809 typedef return_int_delegate (STDCALL *ReturnDelegateDelegate) (void);
812 mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d)
818 mono_test_marshal_stringbuilder (char *s, int n)
820 const char m[] = "This is my message. Isn't it nice?";
822 if (strcmp (s, "ABCD") != 0)
830 mono_test_marshal_stringbuilder_default (char *s, int n)
832 const char m[] = "This is my message. Isn't it nice?";
840 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
842 const char m[] = "This is my message. Isn't it nice?";
846 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
865 mono_test_marshal_empty_string_array (char **array)
867 return (array == NULL) ? 0 : 1;
871 mono_test_marshal_string_array (char **array)
873 if (strcmp (array [0], "ABC"))
875 if (strcmp (array [1], "DEF"))
878 if (array [2] != NULL)
885 mono_test_marshal_byref_string_array (char ***array)
890 if (strcmp ((*array) [0], "Alpha"))
892 if (strcmp ((*array) [1], "Beta"))
894 if (strcmp ((*array) [2], "Gamma"))
901 mono_test_marshal_stringbuilder_array (char **array)
903 if (strcmp (array [0], "ABC"))
905 if (strcmp (array [1], "DEF"))
908 strcpy (array [0], "DEF");
909 strcpy (array [1], "ABC");
915 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
917 GError *error = NULL;
920 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
921 if (strcmp (s, "ABC")) {
928 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
929 if (strcmp (s, "DEF")) {
936 if (strcmp (array2 [0], "ABC"))
939 if (strcmp (array2 [1], "DEF"))
945 /* this does not work on Redhat gcc 2.96 */
947 mono_test_empty_struct (int a, EmptyStruct es, int b)
949 // printf ("mono_test_empty_struct %d %d\n", a, b);
951 // Intel icc on ia64 passes 'es' in 2 registers
952 #if defined(__ia64) && defined(__INTEL_COMPILER)
955 if (a == 1 && b == 2)
965 STDCALL ByValStrStruct *
966 mono_test_byvalstr_gen (void)
970 ret = malloc(sizeof(ByValStrStruct));
971 memset(ret, 'a', sizeof(ByValStrStruct)-1);
972 ret->a[sizeof(ByValStrStruct)-1] = 0;
978 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
982 ret = strcmp(data->a, correctString);
983 // printf ("T1: %s\n", data->a);
984 // printf ("T2: %s\n", correctString);
993 } ByValStrStruct_Unicode;
996 mono_test_byvalstr_check_unicode (ByValStrStruct_Unicode *ref, int test)
998 if (ref->flag != 0x1234abcd){
999 printf ("overwritten data");
1003 if (test == 1 || test == 3){
1004 if (ref->a [0] != '1' ||
1005 ref->a [1] != '2' ||
1011 if (ref->a [0] != '1' ||
1020 NameManglingAnsi (char *data)
1022 return data [0] + data [1] + data [2];
1026 NameManglingAnsiA (char *data)
1028 g_assert_not_reached ();
1032 NameManglingAnsiW (char *data)
1034 g_assert_not_reached ();
1038 NameManglingAnsi2A (char *data)
1040 return data [0] + data [1] + data [2];
1044 NameManglingAnsi2W (char *data)
1046 g_assert_not_reached ();
1050 NameManglingUnicode (char *data)
1052 g_assert_not_reached ();
1056 NameManglingUnicodeW (gunichar2 *data)
1058 return data [0] + data [1] + data [2];
1062 NameManglingUnicode2 (gunichar2 *data)
1064 return data [0] + data [1] + data [2];
1068 NameManglingAutoW (char *data)
1071 return (data [0] + data [1] + data [2]) == 131 ? 0 : 1;
1073 g_assert_not_reached ();
1078 NameManglingAuto (char *data)
1081 return (data [0] + data [1] + data [2]) == 198 ? 0 : 1;
1083 g_assert_not_reached ();
1087 typedef int (STDCALL *intcharFunc)(const char*);
1090 callFunction (intcharFunc f)
1101 class_marshal_test0 (SimpleObj *obj1)
1103 // printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
1105 if (strcmp(obj1->str, "T1"))
1114 class_marshal_test4 (SimpleObj *obj1)
1123 class_marshal_test1 (SimpleObj **obj1)
1125 SimpleObj *res = malloc (sizeof (SimpleObj));
1127 res->str = g_strdup ("ABC");
1134 class_marshal_test2 (SimpleObj **obj1)
1136 // printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
1138 if (strcmp((*obj1)->str, "ABC"))
1140 if ((*obj1)->i != 5)
1147 string_marshal_test0 (char *str)
1149 if (strcmp (str, "TEST0"))
1156 string_marshal_test1 (const char **str)
1162 string_marshal_test2 (char **str)
1164 // printf ("string_marshal_test2 %s\n", *str);
1166 if (strcmp (*str, "TEST1"))
1173 string_marshal_test3 (char *str)
1186 STDCALL BlittableClass*
1187 TestBlittableClass (BlittableClass *vl)
1189 BlittableClass *res;
1191 // printf ("TestBlittableClass %d %d\n", vl->a, vl->b);
1197 res = g_new0 (BlittableClass, 1);
1198 memcpy (res, vl, sizeof (BlittableClass));
1200 res = g_new0 (BlittableClass, 1);
1208 typedef struct OSVERSIONINFO_STRUCT
1212 } OSVERSIONINFO_STRUCT;
1215 MyGetVersionEx (OSVERSIONINFO_STRUCT *osvi)
1218 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1223 return osvi->a + osvi->b;
1227 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO_STRUCT *osvi)
1230 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1235 return osvi->a + osvi->b;
1239 mono_test_marshal_point (point pt)
1241 // printf("point %g %g\n", pt.x, pt.y);
1242 if (pt.x == 1.25 && pt.y == 3.5)
1254 mono_test_marshal_mixed_point (mixed_point pt)
1256 // printf("mixed point %d %g\n", pt.x, pt.y);
1257 if (pt.x == 5 && pt.y == 6.75)
1264 mono_test_marshal_mixed_point_2 (mixed_point *pt)
1266 if (pt->x != 5 || pt->y != 6.75)
1276 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
1279 if (*b1 != 0 && *b1 != 1)
1281 if (*b2 != 0 && *b2 != -1) /* variant_bool */
1283 if (*b3 != 0 && *b3 != 1)
1285 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
1297 short b2; /* variant_bool */
1302 marshal_test_bool_struct(struct BoolStruct *s)
1305 if (s->b1 != 0 && s->b1 != 1)
1307 if (s->b2 != 0 && s->b2 != -1)
1309 if (s->b3 != 0 && s->b3 != 1)
1311 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1320 mono_test_last_error (int err)
1330 mono_test_asany (void *ptr, int what)
1334 return (*(int*)ptr == 5) ? 0 : 1;
1336 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1338 simplestruct2 ss = *(simplestruct2*)ptr;
1340 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1341 !strcmp (ss.d, "TEST") &&
1342 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1348 GError *error = NULL;
1351 s = g_utf16_to_utf8 (ptr, -1, NULL, NULL, &error);
1352 if (!strcmp (s, "ABC")) {
1362 g_assert_not_reached ();
1377 mono_test_marshal_asany_in (void* ptr)
1379 AsAnyStruct* asAny = ptr;
1380 int res = asAny->i + asAny->j + asAny->k;
1386 mono_test_marshal_asany_inout (void* ptr)
1388 AsAnyStruct* asAny = ptr;
1389 int res = asAny->i + asAny->j + asAny->k;
1391 marshal_free (asAny->s);
1402 mono_test_marshal_asany_out (void* ptr)
1404 AsAnyStruct* asAny = ptr;
1405 int res = asAny->i + asAny->j + asAny->k;
1416 * AMD64 marshalling tests.
1419 typedef struct amd64_struct1 {
1426 STDCALL amd64_struct1
1427 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
1437 typedef struct amd64_struct2 {
1442 STDCALL amd64_struct2
1443 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
1451 typedef struct amd64_struct3 {
1455 STDCALL amd64_struct3
1456 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s)
1463 typedef struct amd64_struct4 {
1467 STDCALL amd64_struct4
1468 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s)
1477 * IA64 marshalling tests.
1479 typedef struct test_struct5 {
1483 STDCALL test_struct5
1484 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, test_struct5 s, double d3, double d4)
1492 typedef struct test_struct6 {
1496 STDCALL test_struct6
1497 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, test_struct6 s, double d3, double d4)
1505 static guint32 custom_res [2];
1508 mono_test_marshal_pass_return_custom (int i, guint32 *ptr, int j)
1510 /* ptr will be freed by CleanupNative, so make a copy */
1511 custom_res [0] = 0; /* not allocated by AllocHGlobal */
1512 custom_res [1] = ptr [1];
1518 mono_test_marshal_pass_out_custom (int i, guint32 **ptr, int j)
1521 custom_res [1] = i + j + 10;
1529 mono_test_marshal_pass_inout_custom (int i, guint32 *ptr, int j)
1532 ptr [1] = i + ptr [1] + j;
1538 mono_test_marshal_pass_out_byval_custom (int i, guint32 *ptr, int j)
1540 return ptr == NULL ? 0 : 1;
1544 mono_test_marshal_pass_byref_custom (int i, guint32 **ptr, int j)
1552 mono_test_marshal_pass_return_custom2 (int i, guint32 *ptr, int j)
1554 g_assert_not_reached ();
1560 mono_test_marshal_pass_return_custom_null (int i, guint32 *ptr, int j)
1562 g_assert (ptr == NULL);
1567 typedef void *(STDCALL *PassReturnPtrDelegate) (void *ptr);
1570 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del)
1584 /* FIXME: Freed with FreeHGlobal */
1593 mono_test_marshal_pass_return_custom_null_in_delegate (PassReturnPtrDelegate del)
1595 void *ptr = del (NULL);
1597 return (ptr == NULL) ? 15 : 0;
1600 typedef void (STDCALL *CustomOutParamDelegate) (void **pptr);
1603 mono_test_marshal_custom_out_param_delegate (CustomOutParamDelegate del)
1615 typedef int (STDCALL *ReturnEnumDelegate) (int e);
1618 mono_test_marshal_return_enum_delegate (ReturnEnumDelegate func)
1628 typedef BlittableStruct (STDCALL *SimpleDelegate10) (BlittableStruct ss);
1631 mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 delegate)
1633 BlittableStruct ss, res;
1640 res = delegate (ss);
1641 if (! ((res.a == -1) && (res.b == -2) && (res.c == -3) && (res.d == -55)))
1648 mono_test_stdcall_name_mangling (int a, int b, int c)
1654 * PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
1661 typedef SmallStruct1 (STDCALL *SmallStructDelegate1) (SmallStruct1 ss);
1664 mono_test_marshal_small_struct_delegate1 (SmallStructDelegate1 delegate)
1666 SmallStruct1 ss, res;
1670 res = delegate (ss);
1671 if (! (res.i == -1))
1681 typedef SmallStruct2 (STDCALL *SmallStructDelegate2) (SmallStruct2 ss);
1684 mono_test_marshal_small_struct_delegate2 (SmallStructDelegate2 delegate)
1686 SmallStruct2 ss, res;
1691 res = delegate (ss);
1692 if (! ((res.i == -2) && (res.j == -3)))
1703 typedef SmallStruct3 (STDCALL *SmallStructDelegate3) (SmallStruct3 ss);
1706 mono_test_marshal_small_struct_delegate3 (SmallStructDelegate3 delegate)
1708 SmallStruct3 ss, res;
1713 res = delegate (ss);
1714 if (! ((res.i == -1) && (res.j == -2)))
1724 typedef SmallStruct4 (STDCALL *SmallStructDelegate4) (SmallStruct4 ss);
1727 mono_test_marshal_small_struct_delegate4 (SmallStructDelegate4 delegate)
1729 SmallStruct4 ss, res;
1733 res = delegate (ss);
1734 if (! (res.i == -1))
1744 typedef SmallStruct5 (STDCALL *SmallStructDelegate5) (SmallStruct5 ss);
1747 mono_test_marshal_small_struct_delegate5 (SmallStructDelegate5 delegate)
1749 SmallStruct5 ss, res;
1753 res = delegate (ss);
1754 if (! (res.i == -5))
1764 typedef SmallStruct6 (STDCALL *SmallStructDelegate6) (SmallStruct6 ss);
1767 mono_test_marshal_small_struct_delegate6 (SmallStructDelegate6 delegate)
1769 SmallStruct6 ss, res;
1774 res = delegate (ss);
1775 if (! ((res.i == -1) && (res.j == -2)))
1786 typedef SmallStruct7 (STDCALL *SmallStructDelegate7) (SmallStruct7 ss);
1789 mono_test_marshal_small_struct_delegate7 (SmallStructDelegate7 delegate)
1791 SmallStruct7 ss, res;
1796 res = delegate (ss);
1797 if (! ((res.i == -1) && (res.j == -2)))
1807 typedef SmallStruct8 (STDCALL *SmallStructDelegate8) (SmallStruct8 ss);
1810 mono_test_marshal_small_struct_delegate8 (SmallStructDelegate8 delegate)
1812 SmallStruct8 ss, res;
1816 res = delegate (ss);
1817 if (! ((res.i == -1.0)))
1827 typedef SmallStruct9 (STDCALL *SmallStructDelegate9) (SmallStruct9 ss);
1830 mono_test_marshal_small_struct_delegate9 (SmallStructDelegate9 delegate)
1832 SmallStruct9 ss, res;
1836 res = delegate (ss);
1837 if (! ((res.i == -1.0)))
1847 typedef SmallStruct10 (STDCALL *SmallStructDelegate10) (SmallStruct10 ss);
1850 mono_test_marshal_small_struct_delegate10 (SmallStructDelegate10 delegate)
1852 SmallStruct10 ss, res;
1857 res = delegate (ss);
1858 if (! ((res.i == -1.0) && (res.j == -2.0)))
1869 typedef SmallStruct11 (STDCALL *SmallStructDelegate11) (SmallStruct11 ss);
1872 mono_test_marshal_small_struct_delegate11 (SmallStructDelegate11 delegate)
1874 SmallStruct11 ss, res;
1879 res = delegate (ss);
1880 if (! ((res.i == -1.0) && (res.j == -2)))
1886 typedef int (STDCALL *ArrayDelegate) (int i, char *j, void *arr);
1889 mono_test_marshal_array_delegate (void *arr, int len, ArrayDelegate del)
1891 return del (len, NULL, arr);
1895 mono_test_marshal_out_array_delegate (int *arr, int len, ArrayDelegate del)
1897 del (len, NULL, arr);
1899 if ((arr [0] != 1) || (arr [1] != 2))
1905 typedef gunichar2* (STDCALL *UnicodeStringDelegate) (gunichar2 *message);
1908 mono_test_marshal_return_unicode_string_delegate (UnicodeStringDelegate del)
1910 const char m[] = "abcdef";
1911 gunichar2 *s2, *res;
1914 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1924 mono_test_marshal_out_string_array_delegate (char **arr, int len, ArrayDelegate del)
1926 del (len, NULL, arr);
1928 if (!strcmp (arr [0], "ABC") && !strcmp (arr [1], "DEF"))
1934 typedef int (*CdeclDelegate) (int i, int j);
1937 mono_test_marshal_cdecl_delegate (CdeclDelegate del)
1941 for (i = 0; i < 1000; ++i)
1947 typedef char** (*ReturnStringArrayDelegate) (int i);
1950 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d)
1958 if (strcmp (arr [0], "ABC") || strcmp (arr [1], "DEF"))
1969 add_delegate (int i, int j)
1975 mono_test_marshal_return_fnptr (void)
1977 return &add_delegate;
1983 printf ("codigo %x\n", code);
1992 mono_xr_as_handle (int code)
2007 mono_safe_handle_struct_ref (HandleStructs *x)
2009 printf ("Dingus Ref! \n");
2010 printf ("Values: %d %d %d %d\n", x->a, x->b, x->handle1, x->handle2);
2016 if (x->handle1 != (void*) 0x7080feed)
2019 if (x->handle2 != (void*) 0x1234abcd)
2026 mono_safe_handle_struct (HandleStructs x)
2028 printf ("Dingus Standard! \n");
2029 printf ("Values: %d %d %d %d\n", x.a, x.b, x.handle1, x.handle2);
2035 if (x.handle1 != (void*) 0x7080feed)
2038 if (x.handle2 != (void*) 0x1234abcd)
2049 mono_safe_handle_struct_simple (TrivialHandle x)
2051 printf ("The value is %d\n", x.a);
2052 return ((int)x.a) * 2;
2056 mono_safe_handle_return ()
2062 mono_safe_handle_ref (void **handle)
2065 *handle = (void *) 0xbad;
2069 *handle = (void *) 0x800d;
2078 mono_test_marshal_bstr_in(BSTR bstr)
2080 if (!wcscmp(bstr, L"mono_test_marshal_bstr_in"))
2086 mono_test_marshal_bstr_out(BSTR* bstr)
2088 *bstr = SysAllocString(L"mono_test_marshal_bstr_out");
2093 mono_test_marshal_bstr_in_null(BSTR bstr)
2101 mono_test_marshal_bstr_out_null(BSTR* bstr)
2108 mono_test_marshal_variant_in_sbyte(VARIANT variant)
2110 if (variant.vt == VT_I1 && variant.cVal == 100)
2116 mono_test_marshal_variant_in_byte(VARIANT variant)
2118 if (variant.vt == VT_UI1 && variant.bVal == 100)
2124 mono_test_marshal_variant_in_short(VARIANT variant)
2126 if (variant.vt == VT_I2 && variant.iVal == 314)
2132 mono_test_marshal_variant_in_ushort(VARIANT variant)
2134 if (variant.vt == VT_UI2 && variant.uiVal == 314)
2140 mono_test_marshal_variant_in_int(VARIANT variant)
2142 if (variant.vt == VT_I4 && variant.lVal == 314)
2148 mono_test_marshal_variant_in_uint(VARIANT variant)
2150 if (variant.vt == VT_UI4 && variant.ulVal == 314)
2156 mono_test_marshal_variant_in_long(VARIANT variant)
2158 if (variant.vt == VT_I8 && variant.llVal == 314)
2164 mono_test_marshal_variant_in_ulong(VARIANT variant)
2166 if (variant.vt == VT_UI8 && variant.ullVal == 314)
2172 mono_test_marshal_variant_in_float(VARIANT variant)
2174 if (variant.vt == VT_R4 && (variant.fltVal - 3.14)/3.14 < .001)
2180 mono_test_marshal_variant_in_double(VARIANT variant)
2182 if (variant.vt == VT_R8 && (variant.dblVal - 3.14)/3.14 < .001)
2188 mono_test_marshal_variant_in_bstr(VARIANT variant)
2190 if (variant.vt == VT_BSTR && !wcscmp(variant.bstrVal, L"PI"))
2196 mono_test_marshal_variant_in_bool_true (VARIANT variant)
2198 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_TRUE)
2204 mono_test_marshal_variant_in_bool_false (VARIANT variant)
2206 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_FALSE)
2212 mono_test_marshal_variant_out_sbyte(VARIANT* variant)
2214 variant->vt = VT_I1;
2215 variant->cVal = 100;
2221 mono_test_marshal_variant_out_byte(VARIANT* variant)
2223 variant->vt = VT_UI1;
2224 variant->bVal = 100;
2230 mono_test_marshal_variant_out_short(VARIANT* variant)
2232 variant->vt = VT_I2;
2233 variant->iVal = 314;
2239 mono_test_marshal_variant_out_ushort(VARIANT* variant)
2241 variant->vt = VT_UI2;
2242 variant->uiVal = 314;
2248 mono_test_marshal_variant_out_int(VARIANT* variant)
2250 variant->vt = VT_I4;
2251 variant->lVal = 314;
2257 mono_test_marshal_variant_out_uint(VARIANT* variant)
2259 variant->vt = VT_UI4;
2260 variant->ulVal = 314;
2266 mono_test_marshal_variant_out_long(VARIANT* variant)
2268 variant->vt = VT_I8;
2269 variant->llVal = 314;
2275 mono_test_marshal_variant_out_ulong(VARIANT* variant)
2277 variant->vt = VT_UI8;
2278 variant->ullVal = 314;
2284 mono_test_marshal_variant_out_float(VARIANT* variant)
2286 variant->vt = VT_R4;
2287 variant->fltVal = 3.14;
2293 mono_test_marshal_variant_out_double(VARIANT* variant)
2295 variant->vt = VT_R8;
2296 variant->dblVal = 3.14;
2302 mono_test_marshal_variant_out_bstr(VARIANT* variant)
2304 variant->vt = VT_BSTR;
2305 variant->bstrVal = SysAllocString(L"PI");
2311 mono_test_marshal_variant_out_bool_true (VARIANT* variant)
2313 variant->vt = VT_BOOL;
2314 variant->boolVal = VARIANT_TRUE;
2320 mono_test_marshal_variant_out_bool_false (VARIANT* variant)
2322 variant->vt = VT_BOOL;
2323 variant->boolVal = VARIANT_FALSE;
2328 typedef int (STDCALL *VarFunc) (int vt, VARIANT variant);
2329 typedef int (STDCALL *VarRefFunc) (int vt, VARIANT* variant);
2332 mono_test_marshal_variant_in_sbyte_unmanaged(VarFunc func)
2337 return func (VT_I1, vt);
2341 mono_test_marshal_variant_in_byte_unmanaged(VarFunc func)
2346 return func (VT_UI1, vt);
2350 mono_test_marshal_variant_in_short_unmanaged(VarFunc func)
2355 return func (VT_I2, vt);
2359 mono_test_marshal_variant_in_ushort_unmanaged(VarFunc func)
2364 return func (VT_UI2, vt);
2368 mono_test_marshal_variant_in_int_unmanaged(VarFunc func)
2373 return func (VT_I4, vt);
2377 mono_test_marshal_variant_in_uint_unmanaged(VarFunc func)
2382 return func (VT_UI4, vt);
2386 mono_test_marshal_variant_in_long_unmanaged(VarFunc func)
2391 return func (VT_I8, vt);
2395 mono_test_marshal_variant_in_ulong_unmanaged(VarFunc func)
2400 return func (VT_UI8, vt);
2404 mono_test_marshal_variant_in_float_unmanaged(VarFunc func)
2409 return func (VT_R4, vt);
2413 mono_test_marshal_variant_in_double_unmanaged(VarFunc func)
2418 return func (VT_R8, vt);
2422 mono_test_marshal_variant_in_bstr_unmanaged(VarFunc func)
2426 vt.bstrVal = SysAllocString(L"PI");
2427 return func (VT_BSTR, vt);
2431 mono_test_marshal_variant_in_bool_true_unmanaged(VarFunc func)
2435 vt.boolVal = VARIANT_TRUE;
2436 return func (VT_BOOL, vt);
2440 mono_test_marshal_variant_in_bool_false_unmanaged(VarFunc func)
2444 vt.boolVal = VARIANT_FALSE;
2445 return func (VT_BOOL, vt);
2449 mono_test_marshal_variant_out_sbyte_unmanaged(VarRefFunc func)
2454 if (vt.vt == VT_I1 && vt.cVal == -100)
2460 mono_test_marshal_variant_out_byte_unmanaged(VarRefFunc func)
2465 if (vt.vt == VT_UI1 && vt.bVal == 100)
2471 mono_test_marshal_variant_out_short_unmanaged(VarRefFunc func)
2476 if (vt.vt == VT_I2 && vt.iVal == -100)
2482 mono_test_marshal_variant_out_ushort_unmanaged(VarRefFunc func)
2487 if (vt.vt == VT_UI2 && vt.uiVal == 100)
2493 mono_test_marshal_variant_out_int_unmanaged(VarRefFunc func)
2498 if (vt.vt == VT_I4 && vt.lVal == -100)
2504 mono_test_marshal_variant_out_uint_unmanaged(VarRefFunc func)
2509 if (vt.vt == VT_UI4 && vt.ulVal == 100)
2515 mono_test_marshal_variant_out_long_unmanaged(VarRefFunc func)
2520 if (vt.vt == VT_I8 && vt.llVal == -100)
2526 mono_test_marshal_variant_out_ulong_unmanaged(VarRefFunc func)
2531 if (vt.vt == VT_UI8 && vt.ullVal == 100)
2537 mono_test_marshal_variant_out_float_unmanaged(VarRefFunc func)
2542 if (vt.vt == VT_R4 && fabs (vt.fltVal - 3.14f) < 1e-10)
2548 mono_test_marshal_variant_out_double_unmanaged(VarRefFunc func)
2553 if (vt.vt == VT_R8 && fabs (vt.dblVal - 3.14) < 1e-10)
2559 mono_test_marshal_variant_out_bstr_unmanaged(VarRefFunc func)
2563 func (VT_BSTR, &vt);
2564 if (vt.vt == VT_BSTR && !wcscmp(vt.bstrVal, L"PI"))
2570 mono_test_marshal_variant_out_bool_true_unmanaged(VarRefFunc func)
2574 func (VT_BOOL, &vt);
2575 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
2581 mono_test_marshal_variant_out_bool_false_unmanaged(VarRefFunc func)
2585 func (VT_BOOL, &vt);
2586 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
2591 typedef struct MonoComObject MonoComObject;
2595 int (STDCALL *QueryInterface)(MonoComObject* pUnk, gpointer riid, gpointer* ppv);
2596 int (STDCALL *AddRef)(MonoComObject* pUnk);
2597 int (STDCALL *Release)(MonoComObject* pUnk);
2598 int (STDCALL *get_ITest)(MonoComObject* pUnk, MonoComObject* *ppUnk);
2599 int (STDCALL *SByteIn)(MonoComObject* pUnk, char a);
2600 int (STDCALL *ByteIn)(MonoComObject* pUnk, unsigned char a);
2601 int (STDCALL *ShortIn)(MonoComObject* pUnk, short a);
2602 int (STDCALL *UShortIn)(MonoComObject* pUnk, unsigned short a);
2603 int (STDCALL *IntIn)(MonoComObject* pUnk, int a);
2604 int (STDCALL *UIntIn)(MonoComObject* pUnk, unsigned int a);
2605 int (STDCALL *LongIn)(MonoComObject* pUnk, LONGLONG a);
2606 int (STDCALL *ULongIn)(MonoComObject* pUnk, ULONGLONG a);
2607 int (STDCALL *FloatIn)(MonoComObject* pUnk, float a);
2608 int (STDCALL *DoubleIn)(MonoComObject* pUnk, double a);
2609 int (STDCALL *ITestIn)(MonoComObject* pUnk, MonoComObject* pUnk2);
2610 int (STDCALL *ITestOut)(MonoComObject* pUnk, MonoComObject* *ppUnk);
2613 struct MonoComObject
2619 DEFINE_GUID(IID_ITest, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
2620 DEFINE_GUID(IID_IMonoUnknown, 0, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46);
2621 DEFINE_GUID(IID_IMonoDispatch, 0x00020400, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46);
2623 int STDCALL MonoQueryInterface(MonoComObject* pUnk, gpointer riid, gpointer* ppv)
2626 if (!memcmp(riid, &IID_IMonoUnknown, sizeof(GUID))) {
2630 else if (!memcmp(riid, &IID_ITest, sizeof(GUID))) {
2634 else if (!memcmp(riid, &IID_IMonoDispatch, sizeof(GUID))) {
2638 return E_NOINTERFACE;
2641 int STDCALL MonoAddRef(MonoComObject* pUnk)
2643 return ++(pUnk->m_ref);
2646 int STDCALL MonoRelease(MonoComObject* pUnk)
2648 return --(pUnk->m_ref);
2651 int STDCALL SByteIn(MonoComObject* pUnk, char a)
2656 int STDCALL ByteIn(MonoComObject* pUnk, unsigned char a)
2661 int STDCALL ShortIn(MonoComObject* pUnk, short a)
2666 int STDCALL UShortIn(MonoComObject* pUnk, unsigned short a)
2671 int STDCALL IntIn(MonoComObject* pUnk, int a)
2676 int STDCALL UIntIn(MonoComObject* pUnk, unsigned int a)
2681 int STDCALL LongIn(MonoComObject* pUnk, LONGLONG a)
2686 int STDCALL ULongIn(MonoComObject* pUnk, ULONGLONG a)
2691 int STDCALL FloatIn(MonoComObject* pUnk, float a)
2696 int STDCALL DoubleIn(MonoComObject* pUnk, double a)
2701 int STDCALL ITestIn(MonoComObject* pUnk, MonoComObject *pUnk2)
2706 int STDCALL ITestOut(MonoComObject* pUnk, MonoComObject* *ppUnk)
2711 int STDCALL get_ITest(MonoComObject* pUnk, MonoComObject* *ppUnk)
2716 static void create_com_object (MonoComObject** pOut)
2718 *pOut = g_new0 (MonoComObject, 1);
2719 (*pOut)->vtbl = g_new0 (MonoIUnknown, 1);
2722 (*pOut)->vtbl->QueryInterface = MonoQueryInterface;
2723 (*pOut)->vtbl->AddRef = MonoAddRef;
2724 (*pOut)->vtbl->Release = MonoRelease;
2725 (*pOut)->vtbl->SByteIn = SByteIn;
2726 (*pOut)->vtbl->ByteIn = ByteIn;
2727 (*pOut)->vtbl->ShortIn = ShortIn;
2728 (*pOut)->vtbl->UShortIn = UShortIn;
2729 (*pOut)->vtbl->IntIn = IntIn;
2730 (*pOut)->vtbl->UIntIn = UIntIn;
2731 (*pOut)->vtbl->LongIn = LongIn;
2732 (*pOut)->vtbl->ULongIn = ULongIn;
2733 (*pOut)->vtbl->FloatIn = FloatIn;
2734 (*pOut)->vtbl->DoubleIn = DoubleIn;
2735 (*pOut)->vtbl->ITestIn = ITestIn;
2736 (*pOut)->vtbl->ITestOut = ITestOut;
2737 (*pOut)->vtbl->get_ITest = get_ITest;
2740 static MonoComObject* same_object = NULL;
2743 mono_test_marshal_com_object_create(MonoComObject* *pUnk)
2745 create_com_object (pUnk);
2748 same_object = *pUnk;
2754 mono_test_marshal_com_object_same(MonoComObject* *pUnk)
2756 *pUnk = same_object;
2762 mono_test_marshal_com_object_destroy(MonoComObject *pUnk)
2764 int ref = --(pUnk->m_ref);
2772 mono_test_marshal_com_object_ref_count(MonoComObject *pUnk)
2778 mono_test_marshal_ccw_itest (MonoComObject *pUnk)
2781 MonoComObject* pTest;
2786 hr = pUnk->vtbl->SByteIn (pUnk, -100);
2789 hr = pUnk->vtbl->ByteIn (pUnk, 100);
2792 hr = pUnk->vtbl->ShortIn (pUnk, -100);
2795 hr = pUnk->vtbl->UShortIn (pUnk, 100);
2798 hr = pUnk->vtbl->IntIn (pUnk, -100);
2801 hr = pUnk->vtbl->UIntIn (pUnk, 100);
2804 hr = pUnk->vtbl->LongIn (pUnk, -100);
2807 hr = pUnk->vtbl->ULongIn (pUnk, 100);
2810 hr = pUnk->vtbl->FloatIn (pUnk, 3.14f);
2813 hr = pUnk->vtbl->DoubleIn (pUnk, 3.14);
2816 hr = pUnk->vtbl->ITestIn (pUnk, pUnk);
2819 hr = pUnk->vtbl->ITestOut (pUnk, &pTest);