13 #define STDCALL __stdcall
19 extern __declspec(dllimport) __stdcall void CoTaskMemFree(void *ptr);
22 typedef int (STDCALL *SimpleDelegate) (int a);
24 static void marshal_free (void *ptr)
33 STDCALL unsigned short*
34 test_lpwstr_marshal (unsigned short* chars, long length)
39 res = malloc (2 * (length + 1));
41 // printf("test_lpwstr_marshal()\n");
43 while ( i < length ) {
44 // printf("X|%u|\n", chars[i]);
61 mono_union_test_1 (union_test_1_type u1) {
62 // printf ("Got values %d %d %d\n", u1.b, u1.a, u1.c);
63 return u1.a + u1.b + u1.c;
67 mono_return_int (int a) {
68 // printf ("Got value %d\n", a);
78 mono_return_int_ss (struct ss a) {
79 // printf ("Got value %d\n", a.i);
84 mono_return_ss (struct ss a) {
85 // printf ("Got value %d\n", a.i);
96 mono_return_sc1 (struct sc1 a) {
97 // printf ("Got value %d\n", a.c[0]);
109 mono_return_sc3 (struct sc3 a) {
110 // printf ("Got values %d %d %d\n", a.c[0], a.c[1], a.c[2]);
123 mono_return_sc5 (struct sc5 a) {
124 // printf ("Got values %d %d %d %d %d\n", a.c[0], a.c[1], a.c[2], a.c[3], a.c[4]);
140 mono_return_int_su (union su a) {
141 // printf ("Got value %d\n", a.i1);
146 mono_test_many_int_arguments (int a, int b, int c, int d, int e,
147 int f, int g, int h, int i, int j);
149 mono_test_many_short_arguments (short a, short b, short c, short d, short e,
150 short f, short g, short h, short i, short j);
152 mono_test_many_char_arguments (char a, char b, char c, char d, char e,
153 char f, char g, char h, char i, char j);
156 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)
158 return a + b + c + d + e + f + g + h + i + j;
162 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)
164 return a + b + c + d + e + f + g + h + i + j;
168 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)
170 return a + b + c + d + e + f + g + h + i + j;
174 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)
176 return a + b + c + d + e + f + g + h + i + j;
180 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)
182 return a + b + c + d + e + f + g + h + i + j;
186 mono_test_split_double_arguments (double a, double b, float c, double d, double e)
188 return a + b + c + d + e;
192 mono_test_puts_static (char *s)
194 // printf ("TEST %s\n", s);
198 typedef int (STDCALL *SimpleDelegate3) (int a, int b);
201 mono_invoke_delegate (SimpleDelegate3 delegate)
205 // printf ("start invoke %p\n", delegate);
207 res = delegate (2, 3);
209 // printf ("end invoke\n");
215 mono_test_marshal_char (short a1)
224 mono_test_marshal_char_array (gunichar2 *s)
226 const char m[] = "abcdef";
230 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
239 mono_test_empty_pinvoke (int i)
245 mono_test_marshal_bool_byref (int a, int *b, int c)
255 mono_test_marshal_array (int *a1)
259 for (i = 0; i < 50; i++)
266 mono_test_marshal_inout_array (int *a1)
270 for (i = 0; i < 50; i++) {
272 a1 [i] = 50 - a1 [i];
279 mono_test_marshal_out_array (int *a1)
283 for (i = 0; i < 50; i++) {
291 mono_test_marshal_inout_nonblittable_array (gunichar2 *a1)
295 for (i = 0; i < 10; i++) {
316 mono_test_return_vtype (int i)
319 static gunichar2 test2 [] = { 'T', 'E', 'S', 'T', '2', 0 };
331 mono_test_delegate_struct (void)
333 // printf ("TEST\n");
336 typedef char* (STDCALL *ReturnStringDelegate) (const char *s);
339 mono_test_return_string (ReturnStringDelegate func)
343 // printf ("mono_test_return_string\n");
348 // printf ("got string: %s\n", res);
349 return g_strdup ("12345");
352 typedef int (STDCALL *RefVTypeDelegate) (int a, simplestruct *ss, int b);
355 mono_test_ref_vtype (int a, simplestruct *ss, int b, RefVTypeDelegate func)
357 if (a == 1 && b == 2 && ss->a == 0 && ss->b == 1 && ss->c == 0 &&
358 !strcmp (ss->d, "TEST1")) {
365 return func (a, ss, b);
372 typedef int (STDCALL *OutVTypeDelegate) (int a, simplestruct *ss, int b);
375 mono_test_marshal_out_struct (int a, simplestruct *ss, int b, OutVTypeDelegate func)
377 /* Check that the input pointer is ignored */
378 ss->d = (gpointer)0x12345678;
382 if (ss->a && ss->b && ss->c && !strcmp (ss->d, "TEST3"))
390 SimpleDelegate func, func2;
393 STDCALL DelegateStruct
394 mono_test_marshal_delegate_struct (DelegateStruct ds)
398 res.a = ds.func (ds.a) + ds.func2 (ds.a);
400 res.func2 = ds.func2;
406 mono_test_marshal_struct (simplestruct ss)
408 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
409 !strcmp (ss.d, "TEST"))
416 mono_test_marshal_byref_struct (simplestruct *ss, int a, int b, int c, char *d)
418 gboolean res = (ss->a == a && ss->b == b && ss->c == c && strcmp (ss->d, d) == 0);
423 ss->d = g_strdup ("DEF");
440 mono_test_marshal_struct2 (simplestruct2 ss)
442 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
443 !strcmp (ss.d, "TEST") &&
444 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
450 /* on HP some of the struct should be on the stack and not in registers */
452 mono_test_marshal_struct2_2 (int i, int j, int k, simplestruct2 ss)
454 if (i != 10 || j != 11 || k != 12)
456 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
457 !strcmp (ss.d, "TEST") &&
458 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
465 mono_test_marshal_lpstruct (simplestruct *ss)
467 if (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
468 !strcmp (ss->d, "TEST"))
475 mono_test_marshal_lpstruct_blittable (point *p)
477 if (p->x == 1.0 && p->y == 2.0)
484 mono_test_marshal_struct_array (simplestruct2 *ss)
486 if (! (ss[0].a == 0 && ss[0].b == 1 && ss[0].c == 0 &&
487 !strcmp (ss[0].d, "TEST") &&
488 ss[0].e == 99 && ss[0].f == 1.5 && ss[0].g == 42 && ss[0].h == (guint64)123))
491 if (! (ss[1].a == 0 && ss[1].b == 0 && ss[1].c == 0 &&
492 !strcmp (ss[1].d, "TEST2") &&
493 ss[1].e == 100 && ss[1].f == 2.5 && ss[1].g == 43 && ss[1].h == (guint64)124))
499 typedef struct long_align_struct {
506 mono_test_marshal_long_align_struct_array (long_align_struct *ss)
508 return ss[0].a + ss[0].b + ss[0].c + ss[1].a + ss[1].b + ss[1].c;
511 STDCALL simplestruct2 *
512 mono_test_marshal_class (int i, int j, int k, simplestruct2 *ss, int l)
519 if (i != 10 || j != 11 || k != 12 || l != 14)
521 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
522 !strcmp (ss->d, "TEST") &&
523 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
526 res = g_new0 (simplestruct2, 1);
527 memcpy (res, ss, sizeof (simplestruct2));
528 res->d = g_strdup ("TEST");
533 mono_test_marshal_byref_class (simplestruct2 **ssp)
535 simplestruct2 *ss = *ssp;
538 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
539 !strcmp (ss->d, "TEST") &&
540 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
543 res = g_new0 (simplestruct2, 1);
544 memcpy (res, ss, sizeof (simplestruct2));
545 res->d = g_strdup ("TEST-RES");
557 /* Yes, this is correct, we are only trying to determine the value of the stack here */
563 reliable_delegate (int a)
569 * Checks whether get_sp() works as expected. It doesn't work with gcc-2.95.3 on linux.
572 is_get_sp_reliable (void)
576 reliable_delegate(1);
578 reliable_delegate(1);
584 mono_test_marshal_delegate (SimpleDelegate delegate)
588 /* Check that the delegate wrapper is stdcall */
593 if (is_get_sp_reliable())
594 g_assert (sp1 == sp2);
599 STDCALL SimpleDelegate
600 mono_test_marshal_return_delegate (SimpleDelegate delegate)
606 return_plus_one (int i)
611 STDCALL SimpleDelegate
612 mono_test_marshal_return_delegate_2 ()
614 return return_plus_one;
617 typedef simplestruct (STDCALL *SimpleDelegate2) (simplestruct ss);
620 is_utf16_equals (gunichar2 *s1, const char *s2)
625 s = g_utf16_to_utf8 (s1, -1, NULL, NULL, NULL);
626 res = strcmp (s, s2);
633 mono_test_marshal_delegate2 (SimpleDelegate2 delegate)
635 simplestruct ss, res;
641 ss.d2 = g_utf8_to_utf16 ("TEST2", -1, NULL, NULL, NULL);
644 if (! (res.a && !res.b && res.c && !strcmp (res.d, "TEST-RES") && is_utf16_equals (res.d2, "TEST2-RES")))
650 typedef simplestruct* (STDCALL *SimpleDelegate4) (simplestruct *ss);
653 mono_test_marshal_delegate4 (SimpleDelegate4 delegate)
664 res = delegate (&ss);
668 /* Check return value */
669 if (! (!res->a && res->b && !res->c && !strcmp (res->d, "TEST")))
672 /* Check NULL argument and NULL result */
673 res = delegate (NULL);
680 typedef int (STDCALL *SimpleDelegate5) (simplestruct **ss);
683 mono_test_marshal_delegate5 (SimpleDelegate5 delegate)
696 res = delegate (&ptr);
700 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
707 mono_test_marshal_delegate6 (SimpleDelegate5 delegate)
711 res = delegate (NULL);
716 typedef int (STDCALL *SimpleDelegate7) (simplestruct **ss);
719 mono_test_marshal_delegate7 (SimpleDelegate7 delegate)
724 /* Check that the input pointer is ignored */
725 ptr = (gpointer)0x12345678;
727 res = delegate (&ptr);
731 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
737 typedef int (STDCALL *SimpleDelegate8) (gunichar2 *s);
740 mono_test_marshal_delegate8 (SimpleDelegate8 delegate, gunichar2 *s)
745 typedef int (STDCALL *return_int_fnt) (int i);
746 typedef int (STDCALL *SimpleDelegate9) (return_int_fnt d);
749 mono_test_marshal_delegate9 (SimpleDelegate9 delegate, gpointer ftn)
751 return delegate (ftn);
761 mono_test_marshal_delegate10 (SimpleDelegate9 delegate)
763 return delegate (return_self);
766 typedef int (STDCALL *PrimitiveByrefDelegate) (int *i);
769 mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate delegate)
773 int res = delegate (&i);
783 typedef int (STDCALL *return_int_delegate) (int i);
785 typedef return_int_delegate (STDCALL *ReturnDelegateDelegate) (void);
788 mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d)
794 mono_test_marshal_stringbuilder (char *s, int n)
796 const char m[] = "This is my message. Isn't it nice?";
798 if (strcmp (s, "ABCD") != 0)
805 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
807 const char m[] = "This is my message. Isn't it nice?";
811 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
830 mono_test_marshal_empty_string_array (char **array)
832 return (array == NULL) ? 0 : 1;
836 mono_test_marshal_string_array (char **array)
838 if (strcmp (array [0], "ABC"))
840 if (strcmp (array [1], "DEF"))
843 if (array [2] != NULL)
850 mono_test_marshal_byref_string_array (char ***array)
855 if (strcmp ((*array) [0], "Alpha"))
857 if (strcmp ((*array) [1], "Beta"))
859 if (strcmp ((*array) [2], "Gamma"))
866 mono_test_marshal_stringbuilder_array (char **array)
868 if (strcmp (array [0], "ABC"))
870 if (strcmp (array [1], "DEF"))
873 strcpy (array [0], "DEF");
874 strcpy (array [1], "ABC");
880 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
882 GError *error = NULL;
885 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
886 if (strcmp (s, "ABC")) {
893 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
894 if (strcmp (s, "DEF")) {
901 if (strcmp (array2 [0], "ABC"))
904 if (strcmp (array2 [1], "DEF"))
910 /* this does not work on Redhat gcc 2.96 */
912 mono_test_empty_struct (int a, EmptyStruct es, int b)
914 // printf ("mono_test_empty_struct %d %d\n", a, b);
916 // Intel icc on ia64 passes 'es' in 2 registers
917 #if defined(__ia64) && defined(__INTEL_COMPILER)
920 if (a == 1 && b == 2)
930 STDCALL ByValStrStruct *
931 mono_test_byvalstr_gen (void)
935 ret = malloc(sizeof(ByValStrStruct));
936 memset(ret, 'a', sizeof(ByValStrStruct)-1);
937 ret->a[sizeof(ByValStrStruct)-1] = 0;
943 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
947 ret = strcmp(data->a, correctString);
948 // printf ("T1: %s\n", data->a);
949 // printf ("T2: %s\n", correctString);
956 NameManglingAnsi (char *data)
958 return data [0] + data [1] + data [2];
962 NameManglingAnsiA (char *data)
964 g_assert_not_reached ();
968 NameManglingAnsiW (char *data)
970 g_assert_not_reached ();
974 NameManglingAnsi2A (char *data)
976 return data [0] + data [1] + data [2];
980 NameManglingAnsi2W (char *data)
982 g_assert_not_reached ();
986 NameManglingUnicode (char *data)
988 g_assert_not_reached ();
992 NameManglingUnicodeW (gunichar2 *data)
994 return data [0] + data [1] + data [2];
998 NameManglingUnicode2 (gunichar2 *data)
1000 return data [0] + data [1] + data [2];
1004 NameManglingAutoW (char *data)
1007 return (data [0] + data [1] + data [2]) == 131 ? 0 : 1;
1009 g_assert_not_reached ();
1014 NameManglingAuto (char *data)
1017 return (data [0] + data [1] + data [2]) == 198 ? 0 : 1;
1019 g_assert_not_reached ();
1023 typedef int (STDCALL *intcharFunc)(const char*);
1026 callFunction (intcharFunc f)
1037 class_marshal_test0 (SimpleObj *obj1)
1039 // printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
1041 if (strcmp(obj1->str, "T1"))
1050 class_marshal_test4 (SimpleObj *obj1)
1059 class_marshal_test1 (SimpleObj **obj1)
1061 SimpleObj *res = malloc (sizeof (SimpleObj));
1063 res->str = g_strdup ("ABC");
1070 class_marshal_test2 (SimpleObj **obj1)
1072 // printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
1074 if (strcmp((*obj1)->str, "ABC"))
1076 if ((*obj1)->i != 5)
1083 string_marshal_test0 (char *str)
1085 if (strcmp (str, "TEST0"))
1092 string_marshal_test1 (const char **str)
1098 string_marshal_test2 (char **str)
1100 // printf ("string_marshal_test2 %s\n", *str);
1102 if (strcmp (*str, "TEST1"))
1109 string_marshal_test3 (char *str)
1123 TestVectorList (VectorList *vl)
1127 // printf ("TestVectorList %d %d\n", vl->a, vl->b);
1132 res = g_new0 (VectorList, 1);
1133 memcpy (res, vl, sizeof (VectorList));
1138 typedef struct OSVERSIONINFO_STRUCT
1142 } OSVERSIONINFO_STRUCT;
1145 MyGetVersionEx (OSVERSIONINFO_STRUCT *osvi)
1148 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1153 return osvi->a + osvi->b;
1157 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO_STRUCT *osvi)
1160 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1165 return osvi->a + osvi->b;
1169 mono_test_marshal_point (point pt)
1171 // printf("point %g %g\n", pt.x, pt.y);
1172 if (pt.x == 1.25 && pt.y == 3.5)
1184 mono_test_marshal_mixed_point (mixed_point pt)
1186 // printf("mixed point %d %g\n", pt.x, pt.y);
1187 if (pt.x == 5 && pt.y == 6.75)
1194 mono_test_marshal_mixed_point_2 (mixed_point *pt)
1196 if (pt->x != 5 || pt->y != 6.75)
1206 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
1209 if (*b1 != 0 && *b1 != 1)
1211 if (*b2 != 0 && *b2 != -1) /* variant_bool */
1213 if (*b3 != 0 && *b3 != 1)
1215 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
1227 short b2; /* variant_bool */
1232 marshal_test_bool_struct(struct BoolStruct *s)
1235 if (s->b1 != 0 && s->b1 != 1)
1237 if (s->b2 != 0 && s->b2 != -1)
1239 if (s->b3 != 0 && s->b3 != 1)
1241 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1250 mono_test_last_error (int err)
1260 mono_test_asany (void *ptr, int what)
1264 return (*(int*)ptr == 5) ? 0 : 1;
1266 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1268 simplestruct2 ss = *(simplestruct2*)ptr;
1270 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1271 !strcmp (ss.d, "TEST") &&
1272 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1278 GError *error = NULL;
1281 s = g_utf16_to_utf8 (ptr, -1, NULL, NULL, &error);
1282 if (!strcmp (s, "ABC")) {
1292 g_assert_not_reached ();
1307 mono_test_marshal_asany_inout (void* ptr)
1309 AsAnyStruct* asAny = ptr;
1310 int res = asAny->i + asAny->j + asAny->k;
1321 * AMD64 marshalling tests.
1324 typedef struct amd64_struct1 {
1331 STDCALL amd64_struct1
1332 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
1342 typedef struct amd64_struct2 {
1347 STDCALL amd64_struct2
1348 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
1356 typedef struct amd64_struct3 {
1360 STDCALL amd64_struct3
1361 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s)
1368 typedef struct amd64_struct4 {
1372 STDCALL amd64_struct4
1373 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s)
1382 * IA64 marshalling tests.
1384 typedef struct test_struct5 {
1388 STDCALL test_struct5
1389 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, test_struct5 s, double d3, double d4)
1397 typedef struct test_struct6 {
1401 STDCALL test_struct6
1402 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, test_struct6 s, double d3, double d4)
1410 static guint32 custom_res [2];
1413 mono_test_marshal_pass_return_custom (int i, guint32 *ptr, int j)
1415 /* ptr will be freed by CleanupNative, so make a copy */
1416 custom_res [0] = 0; /* not allocated by AllocHGlobal */
1417 custom_res [1] = ptr [1];
1423 mono_test_marshal_pass_out_custom (int i, guint32 **ptr, int j)
1426 custom_res [1] = i + j + 10;
1434 mono_test_marshal_pass_byref_custom (int i, guint32 **ptr, int j)
1442 mono_test_marshal_pass_return_custom2 (int i, guint32 *ptr, int j)
1444 g_assert_not_reached ();
1450 mono_test_marshal_pass_return_custom_null (int i, guint32 *ptr, int j)
1452 g_assert (ptr == NULL);
1457 typedef void *(STDCALL *PassReturnPtrDelegate) (void *ptr);
1460 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del)
1474 /* FIXME: Freed with FreeHGlobal */
1483 mono_test_marshal_pass_return_custom_null_in_delegate (PassReturnPtrDelegate del)
1485 void *ptr = del (NULL);
1487 return (ptr == NULL) ? 15 : 0;
1490 typedef int (STDCALL *ReturnEnumDelegate) (int e);
1493 mono_test_marshal_return_enum_delegate (ReturnEnumDelegate func)
1503 typedef BlittableStruct (STDCALL *SimpleDelegate10) (BlittableStruct ss);
1506 mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 delegate)
1508 BlittableStruct ss, res;
1515 res = delegate (ss);
1516 if (! ((res.a == -1) && (res.b == -2) && (res.c == -3) && (res.d == -55)))
1523 mono_test_stdcall_name_mangling (int a, int b, int c)
1529 * PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
1536 typedef SmallStruct1 (STDCALL *SmallStructDelegate1) (SmallStruct1 ss);
1539 mono_test_marshal_small_struct_delegate1 (SmallStructDelegate1 delegate)
1541 SmallStruct1 ss, res;
1545 res = delegate (ss);
1546 if (! (res.i == -1))
1556 typedef SmallStruct2 (STDCALL *SmallStructDelegate2) (SmallStruct2 ss);
1559 mono_test_marshal_small_struct_delegate2 (SmallStructDelegate2 delegate)
1561 SmallStruct2 ss, res;
1566 res = delegate (ss);
1567 if (! ((res.i == -2) && (res.j == -3)))
1578 typedef SmallStruct3 (STDCALL *SmallStructDelegate3) (SmallStruct3 ss);
1581 mono_test_marshal_small_struct_delegate3 (SmallStructDelegate3 delegate)
1583 SmallStruct3 ss, res;
1588 res = delegate (ss);
1589 if (! ((res.i == -1) && (res.j == -2)))
1599 typedef SmallStruct4 (STDCALL *SmallStructDelegate4) (SmallStruct4 ss);
1602 mono_test_marshal_small_struct_delegate4 (SmallStructDelegate4 delegate)
1604 SmallStruct4 ss, res;
1608 res = delegate (ss);
1609 if (! (res.i == -1))
1619 typedef SmallStruct5 (STDCALL *SmallStructDelegate5) (SmallStruct5 ss);
1622 mono_test_marshal_small_struct_delegate5 (SmallStructDelegate5 delegate)
1624 SmallStruct5 ss, res;
1628 res = delegate (ss);
1629 if (! (res.i == -5))
1639 typedef SmallStruct6 (STDCALL *SmallStructDelegate6) (SmallStruct6 ss);
1642 mono_test_marshal_small_struct_delegate6 (SmallStructDelegate6 delegate)
1644 SmallStruct6 ss, res;
1649 res = delegate (ss);
1650 if (! ((res.i == -1) && (res.j == -2)))
1661 typedef SmallStruct7 (STDCALL *SmallStructDelegate7) (SmallStruct7 ss);
1664 mono_test_marshal_small_struct_delegate7 (SmallStructDelegate7 delegate)
1666 SmallStruct7 ss, res;
1671 res = delegate (ss);
1672 if (! ((res.i == -1) && (res.j == -2)))
1682 typedef SmallStruct8 (STDCALL *SmallStructDelegate8) (SmallStruct8 ss);
1685 mono_test_marshal_small_struct_delegate8 (SmallStructDelegate8 delegate)
1687 SmallStruct8 ss, res;
1691 res = delegate (ss);
1692 if (! ((res.i == -1.0)))
1702 typedef SmallStruct9 (STDCALL *SmallStructDelegate9) (SmallStruct9 ss);
1705 mono_test_marshal_small_struct_delegate9 (SmallStructDelegate9 delegate)
1707 SmallStruct9 ss, res;
1711 res = delegate (ss);
1712 if (! ((res.i == -1.0)))
1722 typedef SmallStruct10 (STDCALL *SmallStructDelegate10) (SmallStruct10 ss);
1725 mono_test_marshal_small_struct_delegate10 (SmallStructDelegate10 delegate)
1727 SmallStruct10 ss, res;
1732 res = delegate (ss);
1733 if (! ((res.i == -1.0) && (res.j == -2.0)))
1744 typedef SmallStruct11 (STDCALL *SmallStructDelegate11) (SmallStruct11 ss);
1747 mono_test_marshal_small_struct_delegate11 (SmallStructDelegate11 delegate)
1749 SmallStruct11 ss, res;
1754 res = delegate (ss);
1755 if (! ((res.i == -1.0) && (res.j == -2)))
1761 typedef int (STDCALL *ArrayDelegate) (int i, char *j, void *arr);
1764 mono_test_marshal_array_delegate (void *arr, int len, ArrayDelegate del)
1766 return del (len, NULL, arr);
1770 mono_test_marshal_out_array_delegate (int *arr, int len, ArrayDelegate del)
1772 del (len, NULL, arr);
1774 if ((arr [0] != 1) || (arr [1] != 2))
1781 mono_test_marshal_out_string_array_delegate (char **arr, int len, ArrayDelegate del)
1783 del (len, NULL, arr);
1785 if (!strcmp (arr [0], "ABC") && !strcmp (arr [1], "DEF"))
1791 typedef int (*CdeclDelegate) (int i, int j);
1794 mono_test_marshal_cdecl_delegate (CdeclDelegate del)
1798 for (i = 0; i < 1000; ++i)
1804 typedef char** (*ReturnStringArrayDelegate) (int i);
1807 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d)
1815 if (strcmp (arr [0], "ABC") || strcmp (arr [1], "DEF"))
1832 mono_test_marshal_bstr_in(BSTR bstr)
1834 if (!wcscmp(bstr, L"mono_test_marshal_bstr_in"))
1840 mono_test_marshal_bstr_out(BSTR* bstr)
1842 *bstr = SysAllocString(L"mono_test_marshal_bstr_out");
1847 mono_test_marshal_variant_in_sbyte(VARIANT variant)
1849 if (variant.vt == VT_I1 && variant.cVal == 100)
1855 mono_test_marshal_variant_in_byte(VARIANT variant)
1857 if (variant.vt == VT_UI1 && variant.bVal == 100)
1863 mono_test_marshal_variant_in_short(VARIANT variant)
1865 if (variant.vt == VT_I2 && variant.iVal == 314)
1871 mono_test_marshal_variant_in_ushort(VARIANT variant)
1873 if (variant.vt == VT_UI2 && variant.uiVal == 314)
1879 mono_test_marshal_variant_in_int(VARIANT variant)
1881 if (variant.vt == VT_I4 && variant.lVal == 314)
1887 mono_test_marshal_variant_in_uint(VARIANT variant)
1889 if (variant.vt == VT_UI4 && variant.ulVal == 314)
1895 mono_test_marshal_variant_in_long(VARIANT variant)
1897 if (variant.vt == VT_I8 && variant.llVal == 314)
1903 mono_test_marshal_variant_in_ulong(VARIANT variant)
1905 if (variant.vt == VT_UI8 && variant.ullVal == 314)
1911 mono_test_marshal_variant_in_float(VARIANT variant)
1913 if (variant.vt == VT_R4 && (variant.fltVal - 3.14)/3.14 < .001)
1919 mono_test_marshal_variant_in_double(VARIANT variant)
1921 if (variant.vt == VT_R8 && (variant.dblVal - 3.14)/3.14 < .001)
1927 mono_test_marshal_variant_in_bstr(VARIANT variant)
1929 if (variant.vt == VT_BSTR && !wcscmp(variant.bstrVal, L"PI"))
1935 mono_test_marshal_variant_out_sbyte(VARIANT* variant)
1937 variant->vt = VT_I1;
1938 variant->cVal = 100;
1944 mono_test_marshal_variant_out_byte(VARIANT* variant)
1946 variant->vt = VT_UI1;
1947 variant->bVal = 100;
1953 mono_test_marshal_variant_out_short(VARIANT* variant)
1955 variant->vt = VT_I2;
1956 variant->iVal = 314;
1962 mono_test_marshal_variant_out_ushort(VARIANT* variant)
1964 variant->vt = VT_UI2;
1965 variant->uiVal = 314;
1971 mono_test_marshal_variant_out_int(VARIANT* variant)
1973 variant->vt = VT_I4;
1974 variant->lVal = 314;
1980 mono_test_marshal_variant_out_uint(VARIANT* variant)
1982 variant->vt = VT_UI4;
1983 variant->ulVal = 314;
1989 mono_test_marshal_variant_out_long(VARIANT* variant)
1991 variant->vt = VT_I8;
1992 variant->llVal = 314;
1998 mono_test_marshal_variant_out_ulong(VARIANT* variant)
2000 variant->vt = VT_UI8;
2001 variant->ullVal = 314;
2007 mono_test_marshal_variant_out_float(VARIANT* variant)
2009 variant->vt = VT_R4;
2010 variant->fltVal = 3.14;
2016 mono_test_marshal_variant_out_double(VARIANT* variant)
2018 variant->vt = VT_R8;
2019 variant->dblVal = 3.14;
2025 mono_test_marshal_variant_out_bstr(VARIANT* variant)
2027 variant->vt = VT_BSTR;
2028 variant->bstrVal = SysAllocString(L"PI");