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);
640 mono_test_marshal_stringbuilder (char *s, int n)
642 const char m[] = "This is my message. Isn't it nice?";
648 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
650 const char m[] = "This is my message. Isn't it nice?";
654 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
673 mono_test_marshal_empty_string_array (char **array)
675 return (array == NULL) ? 0 : 1;
679 mono_test_marshal_string_array (char **array)
681 if (strcmp (array [0], "ABC"))
683 if (strcmp (array [1], "DEF"))
690 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
692 GError *error = NULL;
695 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
696 if (strcmp (s, "ABC"))
699 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
700 if (strcmp (s, "DEF"))
703 if (strcmp (array2 [0], "ABC"))
706 if (strcmp (array2 [1], "DEF"))
712 /* this does not work on Redhat gcc 2.96 */
714 mono_test_empty_struct (int a, EmptyStruct es, int b)
716 printf ("mono_test_empty_struct %d %d\n", a, b);
718 if (a == 1 && b == 2)
728 mono_test_byvalstr_gen (void)
732 ret = malloc(sizeof(ByValStrStruct));
733 memset(ret, 'a', sizeof(ByValStrStruct)-1);
734 ret->a[sizeof(ByValStrStruct)-1] = 0;
740 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
744 ret = strcmp(data->a, correctString);
745 printf ("T1: %s\n", data->a);
746 printf ("T2: %s\n", correctString);
758 printf ("HEXDUMP DEFAULT VERSION\n");
761 for (i=0; i < 8; ++i)
764 printf("%0x ", (int) *(p++));
777 printf ("HEXDUMP ANSI VERSION\n");
780 for (i=0; i < 8; ++i)
783 printf("%0x ", (int) *(p++));
791 HexDump1W(char *data)
796 printf ("HEXDUMP UNICODE VERSION\n");
799 for (i=0; i < 8; ++i)
802 printf("%0x ", (int) *(p++));
806 return res + 1000000;
809 typedef int (*intcharFunc)(const char*);
812 callFunction (intcharFunc f)
818 printInt (int* number)
820 printf( "<%d>\n", *number );
831 class_marshal_test0 (SimpleObj *obj1)
833 printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
835 if (strcmp(obj1->str, "T1"))
844 class_marshal_test4 (SimpleObj *obj1)
853 class_marshal_test1 (SimpleObj **obj1)
855 SimpleObj *res = malloc (sizeof (SimpleObj));
864 class_marshal_test2 (SimpleObj **obj1)
866 printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
868 if (strcmp((*obj1)->str, "ABC"))
877 string_marshal_test0 (char *str)
879 if (strcmp (str, "TEST0"))
886 string_marshal_test1 (const char **str)
892 string_marshal_test2 (char **str)
894 printf ("string_marshal_test2 %s\n", *str);
896 if (strcmp (*str, "TEST1"))
903 string_marshal_test3 (char *str)
912 functionReturningString (void)
923 VectorList* TestVectorList (VectorList *vl)
925 printf ("TestVectorList %d %d\n", vl->a, vl->b);
934 typedef struct _OSVERSIONINFO
941 GetVersionEx (OSVERSIONINFO *osvi)
944 printf ("GOT %d %d\n", osvi->a, osvi->b);
949 return osvi->a + osvi->b;
953 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO *osvi)
956 printf ("GOT %d %d\n", osvi->a, osvi->b);
961 return osvi->a + osvi->b;
970 mono_test_marshal_point (point pt)
972 printf("point %g %g\n", pt.x, pt.y);
973 if (pt.x == 1.25 && pt.y == 3.5)
985 mono_test_marshal_mixed_point (mixed_point pt)
987 printf("mixed point %d %g\n", pt.x, pt.y);
988 if (pt.x == 5 && pt.y == 6.75)
997 return sizeof (time_t);
1001 mono_test_marshal_time_t (time_t *t)
1003 /* Skip forward an hour */
1004 /* t can be unaligned on 64bit machines at present owing to the magic 4 bytes currently added
1005 for custom marshaling which may or may not be correct... cope for the moment */
1007 memcpy(&s, t, sizeof *t);
1012 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
1015 if (*b1 != 0 && *b1 != 1)
1017 if (*b2 != 0 && *b2 != -1) /* variant_bool */
1019 if (*b3 != 0 && *b3 != 1)
1021 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
1033 short b2; /* variant_bool */
1038 marshal_test_bool_struct(struct BoolStruct *s)
1041 if (s->b1 != 0 && s->b1 != 1)
1043 if (s->b2 != 0 && s->b2 != -1)
1045 if (s->b3 != 0 && s->b3 != 1)
1047 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1056 extern __declspec(dllimport) __stdcall void SetLastError(int x);
1060 mono_test_last_error (int err)
1070 mono_test_asany (void *ptr, int what)
1074 return (*(int*)ptr == 5) ? 0 : 1;
1076 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1078 simplestruct2 ss = *(simplestruct2*)ptr;
1080 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1081 !strcmp (ss.d, "TEST") &&
1082 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1088 GError *error = NULL;
1091 s = g_utf16_to_utf8 (ptr, -1, NULL, NULL, &error);
1092 if (!strcmp (s, "ABC"))
1098 g_assert_not_reached ();