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);
320 mono_test_marshal_delegate_struct (DelegateStruct ds)
322 return ds.func (ds.a) + ds.func2 (ds.a);
326 mono_test_marshal_struct (simplestruct ss)
328 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
329 !strcmp (ss.d, "TEST"))
347 mono_test_marshal_struct2 (simplestruct2 ss)
349 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
350 !strcmp (ss.d, "TEST") &&
351 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
357 /* on HP some of the struct should be on the stack and not in registers */
359 mono_test_marshal_struct2_2 (int i, int j, int k, simplestruct2 ss)
361 if (i != 10 || j != 11 || k != 12)
363 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
364 !strcmp (ss.d, "TEST") &&
365 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
372 mono_test_marshal_struct_array (simplestruct2 *ss)
374 if (! (ss[0].a == 0 && ss[0].b == 1 && ss[0].c == 0 &&
375 !strcmp (ss[0].d, "TEST") &&
376 ss[0].e == 99 && ss[0].f == 1.5 && ss[0].g == 42 && ss[0].h == (guint64)123))
379 if (! (ss[1].a == 0 && ss[1].b == 0 && ss[1].c == 0 &&
380 !strcmp (ss[1].d, "TEST2") &&
381 ss[1].e == 100 && ss[1].f == 2.5 && ss[1].g == 43 && ss[1].h == (guint64)124))
387 typedef struct long_align_struct {
394 mono_test_marshal_long_align_struct_array (long_align_struct *ss)
396 return ss[0].a + ss[0].b + ss[0].c + ss[1].a + ss[1].b + ss[1].c;
400 mono_test_marshal_class (int i, int j, int k, simplestruct2 *ss, int l)
407 if (i != 10 || j != 11 || k != 12 || l != 14)
409 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
410 !strcmp (ss->d, "TEST") &&
411 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
414 res = g_new0 (simplestruct2, 1);
415 memcpy (res, ss, sizeof (simplestruct2));
420 mono_test_marshal_byref_class (simplestruct2 **ssp)
422 simplestruct2 *ss = *ssp;
425 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
426 !strcmp (ss->d, "TEST") &&
427 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
430 res = g_new0 (simplestruct2, 1);
431 memcpy (res, ss, sizeof (simplestruct2));
432 res->d = (char*)"TEST-RES";
439 typedef int (__stdcall *SimpleDelegate) (int a);
441 typedef int (*SimpleDelegate) (int a);
455 mono_test_marshal_delegate (SimpleDelegate delegate)
459 /* Check that the delegate wrapper is stdcall */
464 g_assert (sp1 == sp2);
469 typedef simplestruct (*SimpleDelegate2) (simplestruct ss);
472 mono_test_marshal_delegate2 (SimpleDelegate2 delegate)
474 simplestruct ss, res;
482 if (! (res.a && !res.b && res.c && !strcmp (res.d, "TEST-RES")))
488 typedef simplestruct* (*SimpleDelegate4) (simplestruct *ss);
491 mono_test_marshal_delegate4 (SimpleDelegate4 delegate)
502 res = delegate (&ss);
506 /* Check return value */
507 if (! (!res->a && res->b && !res->c && !strcmp (res->d, "TEST")))
510 /* Check NULL argument and NULL result */
511 res = delegate (NULL);
518 typedef int (*SimpleDelegate5) (simplestruct **ss);
521 mono_test_marshal_delegate5 (SimpleDelegate5 delegate)
534 res = delegate (&ptr);
538 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
545 mono_test_marshal_delegate6 (SimpleDelegate5 delegate)
549 res = delegate (NULL);
554 typedef int (*SimpleDelegate7) (simplestruct **ss);
557 mono_test_marshal_delegate7 (SimpleDelegate7 delegate)
562 /* Check that the input pointer is ignored */
563 ptr = (gpointer)0x12345678;
565 res = delegate (&ptr);
569 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
575 typedef int (*SimpleDelegate8) (gunichar2 *s);
578 mono_test_marshal_delegate8 (SimpleDelegate8 delegate, gunichar2 *s)
583 typedef int (*return_int_fnt) (int i);
584 typedef int (*SimpleDelegate9) (return_int_fnt *d);
587 mono_test_marshal_delegate9 (SimpleDelegate9 delegate, gpointer ftn)
589 return delegate (ftn);
599 mono_test_marshal_delegate10 (SimpleDelegate9 delegate)
601 return delegate (return_self);
605 mono_test_marshal_stringbuilder (char *s, int n)
607 const char m[] = "This is my message. Isn't it nice?";
613 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
615 const char m[] = "This is my message. Isn't it nice?";
619 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
638 mono_test_marshal_empty_string_array (char **array)
640 return (array == NULL) ? 0 : 1;
644 mono_test_marshal_string_array (char **array)
646 if (strcmp (array [0], "ABC"))
648 if (strcmp (array [1], "DEF"))
655 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
657 GError *error = NULL;
660 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
661 if (strcmp (s, "ABC"))
664 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
665 if (strcmp (s, "DEF"))
668 if (strcmp (array2 [0], "ABC"))
671 if (strcmp (array2 [1], "DEF"))
677 /* this does not work on Redhat gcc 2.96 */
679 mono_test_empty_struct (int a, EmptyStruct es, int b)
681 printf ("mono_test_empty_struct %d %d\n", a, b);
683 if (a == 1 && b == 2)
693 mono_test_byvalstr_gen (void)
697 ret = malloc(sizeof(ByValStrStruct));
698 memset(ret, 'a', sizeof(ByValStrStruct)-1);
699 ret->a[sizeof(ByValStrStruct)-1] = 0;
705 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
709 ret = strcmp(data->a, correctString);
710 printf ("T1: %s\n", data->a);
711 printf ("T2: %s\n", correctString);
723 printf ("HEXDUMP DEFAULT VERSION\n");
726 for (i=0; i < 8; ++i)
729 printf("%0x ", (int) *(p++));
742 printf ("HEXDUMP ANSI VERSION\n");
745 for (i=0; i < 8; ++i)
748 printf("%0x ", (int) *(p++));
756 HexDump1W(char *data)
761 printf ("HEXDUMP UNICODE VERSION\n");
764 for (i=0; i < 8; ++i)
767 printf("%0x ", (int) *(p++));
771 return res + 1000000;
774 typedef int (*intcharFunc)(const char*);
777 callFunction (intcharFunc f)
783 printInt (int* number)
785 printf( "<%d>\n", *number );
796 class_marshal_test0 (SimpleObj *obj1)
798 printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
800 if (strcmp(obj1->str, "T1"))
809 class_marshal_test4 (SimpleObj *obj1)
818 class_marshal_test1 (SimpleObj **obj1)
820 SimpleObj *res = malloc (sizeof (SimpleObj));
829 class_marshal_test2 (SimpleObj **obj1)
831 printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
833 if (strcmp((*obj1)->str, "ABC"))
842 string_marshal_test0 (char *str)
844 if (strcmp (str, "TEST0"))
851 string_marshal_test1 (const char **str)
857 string_marshal_test2 (char **str)
859 printf ("string_marshal_test2 %s\n", *str);
861 if (strcmp (*str, "TEST1"))
868 string_marshal_test3 (char *str)
877 functionReturningString (void)
888 VectorList* TestVectorList (VectorList *vl)
890 printf ("TestVectorList %d %d\n", vl->a, vl->b);
899 typedef struct _OSVERSIONINFO
906 GetVersionEx (OSVERSIONINFO *osvi)
909 printf ("GOT %d %d\n", osvi->a, osvi->b);
914 return osvi->a + osvi->b;
918 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO *osvi)
921 printf ("GOT %d %d\n", osvi->a, osvi->b);
926 return osvi->a + osvi->b;
935 mono_test_marshal_point (point pt)
937 printf("point %g %g\n", pt.x, pt.y);
938 if (pt.x == 1.25 && pt.y == 3.5)
950 mono_test_marshal_mixed_point (mixed_point pt)
952 printf("mixed point %d %g\n", pt.x, pt.y);
953 if (pt.x == 5 && pt.y == 6.75)
962 return sizeof (time_t);
966 mono_test_marshal_time_t (time_t *t)
968 /* Skip forward an hour */
969 /* t can be unaligned on 64bit machines at present owing to the magic 4 bytes currently added
970 for custom marshaling which may or may not be correct... cope for the moment */
972 memcpy(&s, t, sizeof *t);
977 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
980 if (*b1 != 0 && *b1 != 1)
982 if (*b2 != 0 && *b2 != -1) /* variant_bool */
984 if (*b3 != 0 && *b3 != 1)
986 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
998 short b2; /* variant_bool */
1003 marshal_test_bool_struct(struct BoolStruct *s)
1006 if (s->b1 != 0 && s->b1 != 1)
1008 if (s->b2 != 0 && s->b2 != -1)
1010 if (s->b3 != 0 && s->b3 != 1)
1012 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1021 extern __declspec(dllimport) __stdcall void SetLastError(int x);
1025 mono_test_last_error (int err)
1035 mono_test_asany (void *ptr, int what)
1039 return (*(int*)ptr == 5) ? 0 : 1;
1041 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1043 simplestruct2 ss = *(simplestruct2*)ptr;
1045 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1046 !strcmp (ss.d, "TEST") &&
1047 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1053 GError *error = NULL;
1056 s = g_utf16_to_utf8 (ptr, -1, NULL, NULL, &error);
1057 if (!strcmp (s, "ABC"))
1063 g_assert_not_reached ();