9 test_lpwstr_marshal (unsigned short* chars, long length)
14 res = malloc (2 * (length + 1));
16 printf("test_lpwstr_marshal()\n");
18 while ( i < length ) {
19 printf("X|%u|\n", chars[i]);
35 int mono_union_test_1 (union_test_1_type u1) {
36 printf ("Got values %d %d %d\n", u1.b, u1.a, u1.c);
37 return u1.a + u1.b + u1.c;
40 int mono_return_int (int a) {
41 printf ("Got value %d\n", a);
50 int mono_return_int_ss (struct ss a) {
51 printf ("Got value %d\n", a.i);
55 struct ss mono_return_ss (struct ss a) {
56 printf ("Got value %d\n", a.i);
66 struct sc1 mono_return_sc1 (struct sc1 a) {
67 printf ("Got value %d\n", a.c[0]);
78 struct sc3 mono_return_sc3 (struct sc3 a) {
79 printf ("Got values %d %d %d\n", a.c[0], a.c[1], a.c[2]);
91 struct sc5 mono_return_sc5 (struct sc5 a) {
92 printf ("Got values %d %d %d %d %d\n", a.c[0], a.c[1], a.c[2], a.c[3], a.c[4]);
107 int mono_return_int_su (union su a) {
108 printf ("Got value %d\n", a.i1);
112 int mono_test_many_int_arguments (int a, int b, int c, int d, int e,
113 int f, int g, int h, int i, int j);
114 short mono_test_many_short_arguments (short a, short b, short c, short d, short e,
115 short f, short g, short h, short i, short j);
116 char mono_test_many_char_arguments (char a, char b, char c, char d, char e,
117 char f, char g, char h, char i, char j);
120 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)
122 return a + b + c + d + e + f + g + h + i + j;
126 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)
128 return a + b + c + d + e + f + g + h + i + j;
132 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)
134 return a + b + c + d + e + f + g + h + i + j;
138 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)
140 return a + b + c + d + e + f + g + h + i + j;
144 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)
146 return a + b + c + d + e + f + g + h + i + j;
150 mono_test_split_double_arguments (double a, double b, float c, double d, double e)
152 return a + b + c + d + e;
156 mono_test_puts_static (char *s)
158 printf ("TEST %s\n", s);
162 typedef int (*SimpleDelegate3) (int a, int b);
165 mono_invoke_delegate (SimpleDelegate3 delegate)
169 printf ("start invoke %p\n", delegate);
171 res = delegate (2, 3);
173 printf ("end invoke\n");
179 mono_test_marshal_char (short a1)
188 mono_test_marshal_char_array (gunichar2 *s)
190 const char m[] = "abcdef";
194 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
203 mono_test_empty_pinvoke (int i)
209 mono_test_marshal_bool_byref (int a, int *b, int c)
219 mono_test_marshal_array (int *a1)
223 for (i = 0; i < 50; i++)
230 mono_test_marshal_inout_array (int *a1)
234 for (i = 0; i < 50; i++) {
236 a1 [i] = 50 - a1 [i];
243 mono_test_marshal_inout_nonblittable_array (gunichar2 *a1)
247 for (i = 0; i < 10; i++) {
262 mono_test_return_vtype (int i)
275 mono_test_delegate_struct (void)
280 typedef char* (*ReturnStringDelegate) (const char *s);
283 mono_test_return_string (ReturnStringDelegate func)
287 printf ("mono_test_return_string\n");
291 printf ("got string: %s\n", res);
295 typedef int (*RefVTypeDelegate) (int a, simplestruct *ss, int b);
298 mono_test_ref_vtype (int a, simplestruct *ss, int b, RefVTypeDelegate func)
300 if (a == 1 && b == 2 && ss->a == 0 && ss->b == 1 && ss->c == 0 &&
301 !strcmp (ss->d, "TEST1")) {
307 return func (a, ss, b);
313 typedef int (*OutVTypeDelegate) (int a, simplestruct *ss, int b);
316 mono_test_marshal_out_struct (int a, simplestruct *ss, int b, OutVTypeDelegate func)
320 /* Check that the input pointer is ignored */
321 ss->d = (gpointer)0x12345678;
325 if (ss->a && ss->b && ss->c && !strcmp (ss->d, "TEST3"))
338 mono_test_marshal_delegate_struct (DelegateStruct ds)
340 return ds.func (ds.a) + ds.func2 (ds.a);
344 mono_test_marshal_struct (simplestruct ss)
346 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
347 !strcmp (ss.d, "TEST"))
365 mono_test_marshal_struct2 (simplestruct2 ss)
367 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
368 !strcmp (ss.d, "TEST") &&
369 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
375 /* on HP some of the struct should be on the stack and not in registers */
377 mono_test_marshal_struct2_2 (int i, int j, int k, simplestruct2 ss)
379 if (i != 10 || j != 11 || k != 12)
381 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
382 !strcmp (ss.d, "TEST") &&
383 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
390 mono_test_marshal_struct_array (simplestruct2 *ss)
392 if (! (ss[0].a == 0 && ss[0].b == 1 && ss[0].c == 0 &&
393 !strcmp (ss[0].d, "TEST") &&
394 ss[0].e == 99 && ss[0].f == 1.5 && ss[0].g == 42 && ss[0].h == (guint64)123))
397 if (! (ss[1].a == 0 && ss[1].b == 0 && ss[1].c == 0 &&
398 !strcmp (ss[1].d, "TEST2") &&
399 ss[1].e == 100 && ss[1].f == 2.5 && ss[1].g == 43 && ss[1].h == (guint64)124))
405 typedef struct long_align_struct {
412 mono_test_marshal_long_align_struct_array (long_align_struct *ss)
414 return ss[0].a + ss[0].b + ss[0].c + ss[1].a + ss[1].b + ss[1].c;
418 mono_test_marshal_class (int i, int j, int k, simplestruct2 *ss, int l)
425 if (i != 10 || j != 11 || k != 12 || l != 14)
427 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
428 !strcmp (ss->d, "TEST") &&
429 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
432 res = g_new0 (simplestruct2, 1);
433 memcpy (res, ss, sizeof (simplestruct2));
438 mono_test_marshal_byref_class (simplestruct2 **ssp)
440 simplestruct2 *ss = *ssp;
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))
448 res = g_new0 (simplestruct2, 1);
449 memcpy (res, ss, sizeof (simplestruct2));
450 res->d = (char*)"TEST-RES";
457 typedef int (__stdcall *SimpleDelegate) (int a);
459 typedef int (*SimpleDelegate) (int a);
473 mono_test_marshal_delegate (SimpleDelegate delegate)
477 /* Check that the delegate wrapper is stdcall */
482 g_assert (sp1 == sp2);
487 typedef simplestruct (*SimpleDelegate2) (simplestruct ss);
490 mono_test_marshal_delegate2 (SimpleDelegate2 delegate)
492 simplestruct ss, res;
500 if (! (res.a && !res.b && res.c && !strcmp (res.d, "TEST-RES")))
506 typedef simplestruct* (*SimpleDelegate4) (simplestruct *ss);
509 mono_test_marshal_delegate4 (SimpleDelegate4 delegate)
520 res = delegate (&ss);
524 /* Check return value */
525 if (! (!res->a && res->b && !res->c && !strcmp (res->d, "TEST")))
528 /* Check NULL argument and NULL result */
529 res = delegate (NULL);
536 typedef int (*SimpleDelegate5) (simplestruct **ss);
539 mono_test_marshal_delegate5 (SimpleDelegate5 delegate)
552 res = delegate (&ptr);
556 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
563 mono_test_marshal_delegate6 (SimpleDelegate5 delegate)
567 res = delegate (NULL);
572 typedef int (*SimpleDelegate7) (simplestruct **ss);
575 mono_test_marshal_delegate7 (SimpleDelegate7 delegate)
580 /* Check that the input pointer is ignored */
581 ptr = (gpointer)0x12345678;
583 res = delegate (&ptr);
587 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
593 typedef int (*SimpleDelegate8) (gunichar2 *s);
596 mono_test_marshal_delegate8 (SimpleDelegate8 delegate, gunichar2 *s)
601 typedef int (*return_int_fnt) (int i);
602 typedef int (*SimpleDelegate9) (return_int_fnt *d);
605 mono_test_marshal_delegate9 (SimpleDelegate9 delegate, gpointer ftn)
607 return delegate (ftn);
617 mono_test_marshal_delegate10 (SimpleDelegate9 delegate)
619 return delegate (return_self);
622 typedef int (*PrimitiveByrefDelegate) (int *i);
625 mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate delegate)
629 int res = delegate (&i);
639 typedef int (*return_int_delegate) (int i);
641 typedef return_int_delegate (*ReturnDelegateDelegate) ();
644 mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d)
651 mono_test_marshal_stringbuilder (char *s, int n)
653 const char m[] = "This is my message. Isn't it nice?";
655 if (strcmp (s, "ABCD") != 0)
662 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
664 const char m[] = "This is my message. Isn't it nice?";
668 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
687 mono_test_marshal_empty_string_array (char **array)
689 return (array == NULL) ? 0 : 1;
693 mono_test_marshal_string_array (char **array)
695 if (strcmp (array [0], "ABC"))
697 if (strcmp (array [1], "DEF"))
704 mono_test_marshal_byref_string_array (char ***array)
709 if (strcmp ((*array) [0], "Alpha"))
711 if (strcmp ((*array) [1], "Beta"))
713 if (strcmp ((*array) [2], "Gamma"))
720 mono_test_marshal_stringbuilder_array (char **array)
722 if (strcmp (array [0], "ABC"))
724 if (strcmp (array [1], "DEF"))
727 strcpy (array [0], "DEF");
728 strcpy (array [1], "ABC");
734 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
736 GError *error = NULL;
739 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
740 if (strcmp (s, "ABC"))
743 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
744 if (strcmp (s, "DEF"))
747 if (strcmp (array2 [0], "ABC"))
750 if (strcmp (array2 [1], "DEF"))
756 /* this does not work on Redhat gcc 2.96 */
758 mono_test_empty_struct (int a, EmptyStruct es, int b)
760 printf ("mono_test_empty_struct %d %d\n", a, b);
762 if (a == 1 && b == 2)
772 mono_test_byvalstr_gen (void)
776 ret = malloc(sizeof(ByValStrStruct));
777 memset(ret, 'a', sizeof(ByValStrStruct)-1);
778 ret->a[sizeof(ByValStrStruct)-1] = 0;
784 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
788 ret = strcmp(data->a, correctString);
789 printf ("T1: %s\n", data->a);
790 printf ("T2: %s\n", correctString);
802 printf ("HEXDUMP DEFAULT VERSION\n");
805 for (i=0; i < 8; ++i)
808 printf("%0x ", (int) *(p++));
821 printf ("HEXDUMP ANSI VERSION\n");
824 for (i=0; i < 8; ++i)
827 printf("%0x ", (int) *(p++));
835 HexDump1W(char *data)
840 printf ("HEXDUMP UNICODE VERSION\n");
843 for (i=0; i < 8; ++i)
846 printf("%0x ", (int) *(p++));
850 return res + 1000000;
853 typedef int (*intcharFunc)(const char*);
856 callFunction (intcharFunc f)
867 class_marshal_test0 (SimpleObj *obj1)
869 printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
871 if (strcmp(obj1->str, "T1"))
880 class_marshal_test4 (SimpleObj *obj1)
889 class_marshal_test1 (SimpleObj **obj1)
891 SimpleObj *res = malloc (sizeof (SimpleObj));
900 class_marshal_test2 (SimpleObj **obj1)
902 printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
904 if (strcmp((*obj1)->str, "ABC"))
913 string_marshal_test0 (char *str)
915 if (strcmp (str, "TEST0"))
922 string_marshal_test1 (const char **str)
928 string_marshal_test2 (char **str)
930 printf ("string_marshal_test2 %s\n", *str);
932 if (strcmp (*str, "TEST1"))
939 string_marshal_test3 (char *str)
953 VectorList* TestVectorList (VectorList *vl)
955 printf ("TestVectorList %d %d\n", vl->a, vl->b);
964 typedef struct _OSVERSIONINFO
971 GetVersionEx (OSVERSIONINFO *osvi)
974 printf ("GOT %d %d\n", osvi->a, osvi->b);
979 return osvi->a + osvi->b;
983 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO *osvi)
986 printf ("GOT %d %d\n", osvi->a, osvi->b);
991 return osvi->a + osvi->b;
1000 mono_test_marshal_point (point pt)
1002 printf("point %g %g\n", pt.x, pt.y);
1003 if (pt.x == 1.25 && pt.y == 3.5)
1015 mono_test_marshal_mixed_point (mixed_point pt)
1017 printf("mixed point %d %g\n", pt.x, pt.y);
1018 if (pt.x == 5 && pt.y == 6.75)
1025 mono_test_marshal_mixed_point_2 (mixed_point *pt)
1027 if (pt->x != 5 || pt->y != 6.75)
1037 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
1040 if (*b1 != 0 && *b1 != 1)
1042 if (*b2 != 0 && *b2 != -1) /* variant_bool */
1044 if (*b3 != 0 && *b3 != 1)
1046 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
1058 short b2; /* variant_bool */
1063 marshal_test_bool_struct(struct BoolStruct *s)
1066 if (s->b1 != 0 && s->b1 != 1)
1068 if (s->b2 != 0 && s->b2 != -1)
1070 if (s->b3 != 0 && s->b3 != 1)
1072 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1081 extern __declspec(dllimport) __stdcall void SetLastError(int x);
1085 mono_test_last_error (int err)
1095 mono_test_asany (void *ptr, int what)
1099 return (*(int*)ptr == 5) ? 0 : 1;
1101 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1103 simplestruct2 ss = *(simplestruct2*)ptr;
1105 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1106 !strcmp (ss.d, "TEST") &&
1107 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1113 GError *error = NULL;
1116 s = g_utf16_to_utf8 (ptr, -1, NULL, NULL, &error);
1117 if (!strcmp (s, "ABC"))
1123 g_assert_not_reached ();
1130 * AMD64 marshalling tests.
1133 typedef struct amd64_struct1 {
1141 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
1151 typedef struct amd64_struct2 {
1157 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
1165 typedef struct amd64_struct3 {
1170 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s)
1177 typedef struct amd64_struct4 {
1182 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s)
1191 mono_test_marshal_pass_return_custom (int i, guint32 *ptr, int j)
1193 /* ptr will be freed by CleanupNative, so make a copy */
1194 guint32 *res = g_new0 (guint32, 1);
1200 typedef void *(*PassReturnPtrDelegate) (void *ptr);
1203 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del)
1207 guint32 *ptr = del (&num);