9 #define STDCALL __stdcall
14 typedef int (STDCALL *SimpleDelegate) (int a);
17 test_lpwstr_marshal (unsigned short* chars, long length)
22 res = malloc (2 * (length + 1));
24 // printf("test_lpwstr_marshal()\n");
26 while ( i < length ) {
27 // printf("X|%u|\n", chars[i]);
43 int mono_union_test_1 (union_test_1_type u1) {
44 // printf ("Got values %d %d %d\n", u1.b, u1.a, u1.c);
45 return u1.a + u1.b + u1.c;
48 int mono_return_int (int a) {
49 // printf ("Got value %d\n", a);
58 int mono_return_int_ss (struct ss a) {
59 // printf ("Got value %d\n", a.i);
63 struct ss mono_return_ss (struct ss a) {
64 // printf ("Got value %d\n", a.i);
74 struct sc1 mono_return_sc1 (struct sc1 a) {
75 // printf ("Got value %d\n", a.c[0]);
86 struct sc3 mono_return_sc3 (struct sc3 a) {
87 // printf ("Got values %d %d %d\n", a.c[0], a.c[1], a.c[2]);
99 struct sc5 mono_return_sc5 (struct sc5 a) {
100 // printf ("Got values %d %d %d %d %d\n", a.c[0], a.c[1], a.c[2], a.c[3], a.c[4]);
115 int mono_return_int_su (union su a) {
116 // printf ("Got value %d\n", a.i1);
120 int mono_test_many_int_arguments (int a, int b, int c, int d, int e,
121 int f, int g, int h, int i, int j);
122 short mono_test_many_short_arguments (short a, short b, short c, short d, short e,
123 short f, short g, short h, short i, short j);
124 char mono_test_many_char_arguments (char a, char b, char c, char d, char e,
125 char f, char g, char h, char i, char j);
128 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)
130 return a + b + c + d + e + f + g + h + i + j;
134 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)
136 return a + b + c + d + e + f + g + h + i + j;
140 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)
142 return a + b + c + d + e + f + g + h + i + j;
146 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)
148 return a + b + c + d + e + f + g + h + i + j;
152 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)
154 return a + b + c + d + e + f + g + h + i + j;
158 mono_test_split_double_arguments (double a, double b, float c, double d, double e)
160 return a + b + c + d + e;
164 mono_test_puts_static (char *s)
166 // printf ("TEST %s\n", s);
170 typedef int (STDCALL *SimpleDelegate3) (int a, int b);
173 mono_invoke_delegate (SimpleDelegate3 delegate)
177 // printf ("start invoke %p\n", delegate);
179 res = delegate (2, 3);
181 // printf ("end invoke\n");
187 mono_test_marshal_char (short a1)
196 mono_test_marshal_char_array (gunichar2 *s)
198 const char m[] = "abcdef";
202 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
211 mono_test_empty_pinvoke (int i)
217 mono_test_marshal_bool_byref (int a, int *b, int c)
227 mono_test_marshal_array (int *a1)
231 for (i = 0; i < 50; i++)
238 mono_test_marshal_inout_array (int *a1)
242 for (i = 0; i < 50; i++) {
244 a1 [i] = 50 - a1 [i];
251 mono_test_marshal_inout_nonblittable_array (gunichar2 *a1)
255 for (i = 0; i < 10; i++) {
270 mono_test_return_vtype (int i)
283 mono_test_delegate_struct (void)
285 // printf ("TEST\n");
288 typedef char* (STDCALL *ReturnStringDelegate) (const char *s);
291 mono_test_return_string (ReturnStringDelegate func)
295 // printf ("mono_test_return_string\n");
299 // printf ("got string: %s\n", res);
303 typedef int (STDCALL *RefVTypeDelegate) (int a, simplestruct *ss, int b);
306 mono_test_ref_vtype (int a, simplestruct *ss, int b, RefVTypeDelegate func)
308 if (a == 1 && b == 2 && ss->a == 0 && ss->b == 1 && ss->c == 0 &&
309 !strcmp (ss->d, "TEST1")) {
315 return func (a, ss, b);
321 typedef int (STDCALL *OutVTypeDelegate) (int a, simplestruct *ss, int b);
324 mono_test_marshal_out_struct (int a, simplestruct *ss, int b, OutVTypeDelegate func)
328 /* Check that the input pointer is ignored */
329 ss->d = (gpointer)0x12345678;
333 if (ss->a && ss->b && ss->c && !strcmp (ss->d, "TEST3"))
341 SimpleDelegate func, func2;
345 mono_test_marshal_delegate_struct (DelegateStruct ds)
347 return ds.func (ds.a) + ds.func2 (ds.a);
351 mono_test_marshal_struct (simplestruct ss)
353 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
354 !strcmp (ss.d, "TEST"))
372 mono_test_marshal_struct2 (simplestruct2 ss)
374 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
375 !strcmp (ss.d, "TEST") &&
376 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
382 /* on HP some of the struct should be on the stack and not in registers */
384 mono_test_marshal_struct2_2 (int i, int j, int k, simplestruct2 ss)
386 if (i != 10 || j != 11 || k != 12)
388 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
389 !strcmp (ss.d, "TEST") &&
390 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
397 mono_test_marshal_struct_array (simplestruct2 *ss)
399 if (! (ss[0].a == 0 && ss[0].b == 1 && ss[0].c == 0 &&
400 !strcmp (ss[0].d, "TEST") &&
401 ss[0].e == 99 && ss[0].f == 1.5 && ss[0].g == 42 && ss[0].h == (guint64)123))
404 if (! (ss[1].a == 0 && ss[1].b == 0 && ss[1].c == 0 &&
405 !strcmp (ss[1].d, "TEST2") &&
406 ss[1].e == 100 && ss[1].f == 2.5 && ss[1].g == 43 && ss[1].h == (guint64)124))
412 typedef struct long_align_struct {
419 mono_test_marshal_long_align_struct_array (long_align_struct *ss)
421 return ss[0].a + ss[0].b + ss[0].c + ss[1].a + ss[1].b + ss[1].c;
425 mono_test_marshal_class (int i, int j, int k, simplestruct2 *ss, int l)
432 if (i != 10 || j != 11 || k != 12 || l != 14)
434 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
435 !strcmp (ss->d, "TEST") &&
436 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
439 res = g_new0 (simplestruct2, 1);
440 memcpy (res, ss, sizeof (simplestruct2));
441 res->d = g_strdup ("TEST");
446 mono_test_marshal_byref_class (simplestruct2 **ssp)
448 simplestruct2 *ss = *ssp;
451 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
452 !strcmp (ss->d, "TEST") &&
453 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
456 res = g_new0 (simplestruct2, 1);
457 memcpy (res, ss, sizeof (simplestruct2));
458 res->d = g_strdup ("TEST-RES");
475 mono_test_marshal_delegate (SimpleDelegate delegate)
479 /* Check that the delegate wrapper is stdcall */
484 g_assert (sp1 == sp2);
489 typedef simplestruct (STDCALL *SimpleDelegate2) (simplestruct ss);
492 mono_test_marshal_delegate2 (SimpleDelegate2 delegate)
494 simplestruct ss, res;
502 if (! (res.a && !res.b && res.c && !strcmp (res.d, "TEST-RES")))
508 typedef simplestruct* (STDCALL *SimpleDelegate4) (simplestruct *ss);
511 mono_test_marshal_delegate4 (SimpleDelegate4 delegate)
522 res = delegate (&ss);
526 /* Check return value */
527 if (! (!res->a && res->b && !res->c && !strcmp (res->d, "TEST")))
530 /* Check NULL argument and NULL result */
531 res = delegate (NULL);
538 typedef int (STDCALL *SimpleDelegate5) (simplestruct **ss);
541 mono_test_marshal_delegate5 (SimpleDelegate5 delegate)
554 res = delegate (&ptr);
558 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
565 mono_test_marshal_delegate6 (SimpleDelegate5 delegate)
569 res = delegate (NULL);
574 typedef int (STDCALL *SimpleDelegate7) (simplestruct **ss);
577 mono_test_marshal_delegate7 (SimpleDelegate7 delegate)
582 /* Check that the input pointer is ignored */
583 ptr = (gpointer)0x12345678;
585 res = delegate (&ptr);
589 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
595 typedef int (STDCALL *SimpleDelegate8) (gunichar2 *s);
598 mono_test_marshal_delegate8 (SimpleDelegate8 delegate, gunichar2 *s)
603 typedef int (STDCALL *return_int_fnt) (int i);
604 typedef int (STDCALL *SimpleDelegate9) (return_int_fnt *d);
607 mono_test_marshal_delegate9 (SimpleDelegate9 delegate, gpointer ftn)
609 return delegate (ftn);
619 mono_test_marshal_delegate10 (SimpleDelegate9 delegate)
621 return delegate (return_self);
624 typedef int (STDCALL *PrimitiveByrefDelegate) (int *i);
627 mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate delegate)
631 int res = delegate (&i);
641 typedef int (STDCALL *return_int_delegate) (int i);
643 typedef return_int_delegate (STDCALL *ReturnDelegateDelegate) ();
646 mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d)
653 mono_test_marshal_stringbuilder (char *s, int n)
655 const char m[] = "This is my message. Isn't it nice?";
657 if (strcmp (s, "ABCD") != 0)
664 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
666 const char m[] = "This is my message. Isn't it nice?";
670 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
689 mono_test_marshal_empty_string_array (char **array)
691 return (array == NULL) ? 0 : 1;
695 mono_test_marshal_string_array (char **array)
697 if (strcmp (array [0], "ABC"))
699 if (strcmp (array [1], "DEF"))
702 if (array [2] != NULL)
709 mono_test_marshal_byref_string_array (char ***array)
714 if (strcmp ((*array) [0], "Alpha"))
716 if (strcmp ((*array) [1], "Beta"))
718 if (strcmp ((*array) [2], "Gamma"))
725 mono_test_marshal_stringbuilder_array (char **array)
727 if (strcmp (array [0], "ABC"))
729 if (strcmp (array [1], "DEF"))
732 strcpy (array [0], "DEF");
733 strcpy (array [1], "ABC");
739 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
741 GError *error = NULL;
744 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
745 if (strcmp (s, "ABC")) {
752 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
753 if (strcmp (s, "DEF")) {
760 if (strcmp (array2 [0], "ABC"))
763 if (strcmp (array2 [1], "DEF"))
769 /* this does not work on Redhat gcc 2.96 */
771 mono_test_empty_struct (int a, EmptyStruct es, int b)
773 // printf ("mono_test_empty_struct %d %d\n", a, b);
775 if (a == 1 && b == 2)
785 mono_test_byvalstr_gen (void)
789 ret = malloc(sizeof(ByValStrStruct));
790 memset(ret, 'a', sizeof(ByValStrStruct)-1);
791 ret->a[sizeof(ByValStrStruct)-1] = 0;
797 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
801 ret = strcmp(data->a, correctString);
802 // printf ("T1: %s\n", data->a);
803 // printf ("T2: %s\n", correctString);
815 printf ("HEXDUMP DEFAULT VERSION\n");
818 for (i=0; i < 8; ++i)
821 printf("%0x ", (int) *(p++));
834 printf ("HEXDUMP ANSI VERSION\n");
837 for (i=0; i < 8; ++i)
840 printf("%0x ", (int) *(p++));
848 HexDump1W(char *data)
853 printf ("HEXDUMP UNICODE VERSION\n");
856 for (i=0; i < 8; ++i)
859 printf("%0x ", (int) *(p++));
863 return res + 1000000;
866 typedef int (STDCALL *intcharFunc)(const char*);
869 callFunction (intcharFunc f)
880 class_marshal_test0 (SimpleObj *obj1)
882 // printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
884 if (strcmp(obj1->str, "T1"))
893 class_marshal_test4 (SimpleObj *obj1)
902 class_marshal_test1 (SimpleObj **obj1)
904 SimpleObj *res = malloc (sizeof (SimpleObj));
906 res->str = g_strdup ("ABC");
913 class_marshal_test2 (SimpleObj **obj1)
915 // printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
917 if (strcmp((*obj1)->str, "ABC"))
926 string_marshal_test0 (char *str)
928 if (strcmp (str, "TEST0"))
935 string_marshal_test1 (const char **str)
941 string_marshal_test2 (char **str)
943 // printf ("string_marshal_test2 %s\n", *str);
945 if (strcmp (*str, "TEST1"))
952 string_marshal_test3 (char *str)
966 VectorList* TestVectorList (VectorList *vl)
970 // printf ("TestVectorList %d %d\n", vl->a, vl->b);
975 res = g_new0 (VectorList, 1);
976 memcpy (res, vl, sizeof (VectorList));
982 typedef struct _OSVERSIONINFO
989 GetVersionEx (OSVERSIONINFO *osvi)
992 // printf ("GOT %d %d\n", osvi->a, osvi->b);
997 return osvi->a + osvi->b;
1001 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO *osvi)
1004 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1009 return osvi->a + osvi->b;
1018 mono_test_marshal_point (point pt)
1020 // printf("point %g %g\n", pt.x, pt.y);
1021 if (pt.x == 1.25 && pt.y == 3.5)
1033 mono_test_marshal_mixed_point (mixed_point pt)
1035 // printf("mixed point %d %g\n", pt.x, pt.y);
1036 if (pt.x == 5 && pt.y == 6.75)
1043 mono_test_marshal_mixed_point_2 (mixed_point *pt)
1045 if (pt->x != 5 || pt->y != 6.75)
1055 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
1058 if (*b1 != 0 && *b1 != 1)
1060 if (*b2 != 0 && *b2 != -1) /* variant_bool */
1062 if (*b3 != 0 && *b3 != 1)
1064 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
1076 short b2; /* variant_bool */
1081 marshal_test_bool_struct(struct BoolStruct *s)
1084 if (s->b1 != 0 && s->b1 != 1)
1086 if (s->b2 != 0 && s->b2 != -1)
1088 if (s->b3 != 0 && s->b3 != 1)
1090 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1099 extern __declspec(dllimport) __stdcall void SetLastError(int x);
1103 mono_test_last_error (int err)
1113 mono_test_asany (void *ptr, int what)
1117 return (*(int*)ptr == 5) ? 0 : 1;
1119 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1121 simplestruct2 ss = *(simplestruct2*)ptr;
1123 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1124 !strcmp (ss.d, "TEST") &&
1125 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1131 GError *error = NULL;
1134 s = g_utf16_to_utf8 (ptr, -1, NULL, NULL, &error);
1135 if (!strcmp (s, "ABC")) {
1145 g_assert_not_reached ();
1152 * AMD64 marshalling tests.
1155 typedef struct amd64_struct1 {
1163 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
1173 typedef struct amd64_struct2 {
1179 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
1187 typedef struct amd64_struct3 {
1192 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s)
1199 typedef struct amd64_struct4 {
1204 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s)
1212 static guint32 custom_res [2];
1215 mono_test_marshal_pass_return_custom (int i, guint32 *ptr, int j)
1217 /* ptr will be freed by CleanupNative, so make a copy */
1218 custom_res [0] = 0; /* not allocated by AllocHGlobal */
1219 custom_res [1] = ptr [1];
1224 typedef void *(STDCALL *PassReturnPtrDelegate) (void *ptr);
1227 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del)
1241 /* FIXME: Freed with FreeHGlobal */
1250 __declspec(dllexport)
1253 mono_test_stdcall_name_mangling (int a, int b, int c)