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);
319 mono_test_marshal_delegate_struct (DelegateStruct ds)
321 return ds.func (ds.a);
325 mono_test_marshal_struct (simplestruct ss)
327 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
328 !strcmp (ss.d, "TEST"))
346 mono_test_marshal_struct2 (simplestruct2 ss)
348 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
349 !strcmp (ss.d, "TEST") &&
350 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
356 /* on HP some of the struct should be on the stack and not in registers */
358 mono_test_marshal_struct2_2 (int i, int j, int k, simplestruct2 ss)
360 if (i != 10 || j != 11 || k != 12)
362 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
363 !strcmp (ss.d, "TEST") &&
364 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
371 mono_test_marshal_struct_array (simplestruct2 *ss)
373 if (! (ss[0].a == 0 && ss[0].b == 1 && ss[0].c == 0 &&
374 !strcmp (ss[0].d, "TEST") &&
375 ss[0].e == 99 && ss[0].f == 1.5 && ss[0].g == 42 && ss[0].h == (guint64)123))
378 if (! (ss[1].a == 0 && ss[1].b == 0 && ss[1].c == 0 &&
379 !strcmp (ss[1].d, "TEST2") &&
380 ss[1].e == 100 && ss[1].f == 2.5 && ss[1].g == 43 && ss[1].h == (guint64)124))
387 mono_test_marshal_class (int i, int j, int k, simplestruct2 *ss, int l)
394 if (i != 10 || j != 11 || k != 12 || l != 14)
396 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
397 !strcmp (ss->d, "TEST") &&
398 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
401 res = g_new0 (simplestruct2, 1);
402 memcpy (res, ss, sizeof (simplestruct2));
407 mono_test_marshal_byref_class (simplestruct2 **ssp)
409 simplestruct2 *ss = *ssp;
412 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
413 !strcmp (ss->d, "TEST") &&
414 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
417 res = g_new0 (simplestruct2, 1);
418 memcpy (res, ss, sizeof (simplestruct2));
419 res->d = (char*)"TEST-RES";
426 typedef int (__stdcall *SimpleDelegate) (int a);
428 typedef int (*SimpleDelegate) (int a);
442 mono_test_marshal_delegate (SimpleDelegate delegate)
446 /* Check that the delegate wrapper is stdcall */
451 g_assert (sp1 == sp2);
456 typedef simplestruct (*SimpleDelegate2) (simplestruct ss);
459 mono_test_marshal_delegate2 (SimpleDelegate2 delegate)
461 simplestruct ss, res;
469 if (! (res.a && !res.b && res.c && !strcmp (res.d, "TEST-RES")))
475 typedef simplestruct* (*SimpleDelegate4) (simplestruct *ss);
478 mono_test_marshal_delegate4 (SimpleDelegate4 delegate)
489 res = delegate (&ss);
493 /* Check return value */
494 if (! (!res->a && res->b && !res->c && !strcmp (res->d, "TEST")))
497 /* Check NULL argument and NULL result */
498 res = delegate (NULL);
505 typedef int (*SimpleDelegate5) (simplestruct **ss);
508 mono_test_marshal_delegate5 (SimpleDelegate5 delegate)
521 res = delegate (&ptr);
525 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
532 mono_test_marshal_delegate6 (SimpleDelegate5 delegate)
536 res = delegate (NULL);
541 typedef int (*SimpleDelegate7) (simplestruct **ss);
544 mono_test_marshal_delegate7 (SimpleDelegate7 delegate)
549 /* Check that the input pointer is ignored */
550 ptr = (gpointer)0x12345678;
552 res = delegate (&ptr);
556 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
563 mono_test_marshal_stringbuilder (char *s, int n)
565 const char m[] = "This is my message. Isn't it nice?";
571 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
573 const char m[] = "This is my message. Isn't it nice?";
577 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
596 mono_test_marshal_empty_string_array (char **array)
598 return (array == NULL) ? 0 : 1;
602 mono_test_marshal_string_array (char **array)
604 if (strcmp (array [0], "ABC"))
606 if (strcmp (array [1], "DEF"))
613 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
615 GError *error = NULL;
618 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
619 if (strcmp (s, "ABC"))
622 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
623 if (strcmp (s, "DEF"))
626 if (strcmp (array2 [0], "ABC"))
629 if (strcmp (array2 [1], "DEF"))
635 /* this does not work on Redhat gcc 2.96 */
637 mono_test_empty_struct (int a, EmptyStruct es, int b)
639 printf ("mono_test_empty_struct %d %d\n", a, b);
641 if (a == 1 && b == 2)
651 mono_test_byvalstr_gen (void)
655 ret = malloc(sizeof(ByValStrStruct));
656 memset(ret, 'a', sizeof(ByValStrStruct)-1);
657 ret->a[sizeof(ByValStrStruct)-1] = 0;
663 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
667 ret = strcmp(data->a, correctString);
668 printf ("T1: %s\n", data->a);
669 printf ("T2: %s\n", correctString);
681 printf ("HEXDUMP DEFAULT VERSION\n");
684 for (i=0; i < 8; ++i)
687 printf("%0x ", (int) *(p++));
700 printf ("HEXDUMP ANSI VERSION\n");
703 for (i=0; i < 8; ++i)
706 printf("%0x ", (int) *(p++));
714 HexDump1W(char *data)
719 printf ("HEXDUMP UNICODE VERSION\n");
722 for (i=0; i < 8; ++i)
725 printf("%0x ", (int) *(p++));
729 return res + 1000000;
732 typedef int (*intcharFunc)(const char*);
735 callFunction (intcharFunc f)
741 printInt (int* number)
743 printf( "<%d>\n", *number );
754 class_marshal_test0 (SimpleObj *obj1)
756 printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
758 if (strcmp(obj1->str, "T1"))
767 class_marshal_test4 (SimpleObj *obj1)
776 class_marshal_test1 (SimpleObj **obj1)
778 SimpleObj *res = malloc (sizeof (SimpleObj));
787 class_marshal_test2 (SimpleObj **obj1)
789 printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
791 if (strcmp((*obj1)->str, "ABC"))
800 string_marshal_test0 (char *str)
802 if (strcmp (str, "TEST0"))
809 string_marshal_test1 (const char **str)
815 string_marshal_test2 (char **str)
817 printf ("string_marshal_test2 %s\n", *str);
819 if (strcmp (*str, "TEST1"))
826 string_marshal_test3 (char *str)
835 functionReturningString (void)
846 VectorList* TestVectorList (VectorList *vl)
848 printf ("TestVectorList %d %d\n", vl->a, vl->b);
857 typedef struct _OSVERSIONINFO
864 GetVersionEx (OSVERSIONINFO *osvi)
867 printf ("GOT %d %d\n", osvi->a, osvi->b);
872 return osvi->a + osvi->b;
876 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO *osvi)
879 printf ("GOT %d %d\n", osvi->a, osvi->b);
884 return osvi->a + osvi->b;
893 mono_test_marshal_point (point pt)
895 printf("point %g %g\n", pt.x, pt.y);
896 if (pt.x == 1.25 && pt.y == 3.5)
908 mono_test_marshal_mixed_point (mixed_point pt)
910 printf("mixed point %d %g\n", pt.x, pt.y);
911 if (pt.x == 5 && pt.y == 6.75)
920 return sizeof (time_t);
924 mono_test_marshal_time_t (time_t *t)
926 /* Skip forward an hour */
927 /* t can be unaligned on 64bit machines at present owing to the magic 4 bytes currently added
928 for custom marshaling which may or may not be correct... cope for the moment */
930 memcpy(&s, t, sizeof *t);
935 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
938 if (*b1 != 0 && *b1 != 1)
940 if (*b2 != 0 && *b2 != -1) /* variant_bool */
942 if (*b3 != 0 && *b3 != 1)
944 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
956 short b2; /* variant_bool */
961 marshal_test_bool_struct(struct BoolStruct *s)
964 if (s->b1 != 0 && s->b1 != 1)
966 if (s->b2 != 0 && s->b2 != -1)
968 if (s->b3 != 0 && s->b3 != 1)
970 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
979 extern __declspec(dllimport) __stdcall void SetLastError(int x);
983 mono_test_last_error (int err)