16 #define STDCALL __stdcall
22 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
26 extern __declspec(dllimport) void __stdcall CoTaskMemFree(void *ptr);
29 typedef int (STDCALL *SimpleDelegate) (int a);
31 #if defined(WIN32) && defined (_MSC_VER)
32 #define LIBTEST_API __declspec(dllexport)
37 static void marshal_free (void *ptr)
46 static void* marshal_alloc (gsize size)
49 return CoTaskMemAlloc (size);
51 return g_malloc (size);
55 LIBTEST_API unsigned short* STDCALL
56 test_lpwstr_marshal (unsigned short* chars, long length)
61 res = marshal_alloc (2 * (length + 1));
63 // printf("test_lpwstr_marshal()\n");
65 while ( i < length ) {
66 // printf("X|%u|\n", chars[i]);
77 LIBTEST_API void STDCALL
78 test_lpwstr_marshal_out (unsigned short** chars)
81 const char abc[] = "ABC";
82 glong len = strlen(abc);
84 *chars = marshal_alloc (2 * (len + 1));
87 (*chars) [i] = abc[i];
100 LIBTEST_API int STDCALL
101 mono_union_test_1 (union_test_1_type u1) {
102 // printf ("Got values %d %d %d\n", u1.b, u1.a, u1.c);
103 return u1.a + u1.b + u1.c;
106 LIBTEST_API int STDCALL
107 mono_return_int (int a) {
108 // printf ("Got value %d\n", a);
117 LIBTEST_API int STDCALL
118 mono_return_int_ss (struct ss a) {
119 // printf ("Got value %d\n", a.i);
123 LIBTEST_API struct ss STDCALL
124 mono_return_ss (struct ss a) {
125 // printf ("Got value %d\n", a.i);
135 LIBTEST_API struct sc1 STDCALL
136 mono_return_sc1 (struct sc1 a) {
137 // printf ("Got value %d\n", a.c[0]);
148 LIBTEST_API struct sc3 STDCALL
149 mono_return_sc3 (struct sc3 a) {
150 // printf ("Got values %d %d %d\n", a.c[0], a.c[1], a.c[2]);
162 LIBTEST_API struct sc5 STDCALL
163 mono_return_sc5 (struct sc5 a) {
164 // printf ("Got values %d %d %d %d %d\n", a.c[0], a.c[1], a.c[2], a.c[3], a.c[4]);
179 LIBTEST_API int STDCALL
180 mono_return_int_su (union su a) {
181 // printf ("Got value %d\n", a.i1);
185 LIBTEST_API int STDCALL
186 mono_test_many_int_arguments (int a, int b, int c, int d, int e,
187 int f, int g, int h, int i, int j);
188 LIBTEST_API short STDCALL
189 mono_test_many_short_arguments (short a, short b, short c, short d, short e,
190 short f, short g, short h, short i, short j);
191 LIBTEST_API char STDCALL
192 mono_test_many_char_arguments (char a, char b, char c, char d, char e,
193 char f, char g, char h, char i, char j);
195 LIBTEST_API int STDCALL
196 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)
198 return a + b + c + d + e + f + g + h + i + j;
201 LIBTEST_API short STDCALL
202 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)
204 return a + b + c + d + e + f + g + h + i + j;
207 LIBTEST_API char STDCALL
208 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)
210 return a + b + c + d + e + f + g + h + i + j;
213 LIBTEST_API float STDCALL
214 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)
216 return a + b + c + d + e + f + g + h + i + j;
219 LIBTEST_API double STDCALL
220 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)
222 return a + b + c + d + e + f + g + h + i + j;
225 LIBTEST_API double STDCALL
226 mono_test_split_double_arguments (double a, double b, float c, double d, double e)
228 return a + b + c + d + e;
231 LIBTEST_API int STDCALL
232 mono_test_puts_static (char *s)
234 // printf ("TEST %s\n", s);
238 typedef int (STDCALL *SimpleDelegate3) (int a, int b);
240 LIBTEST_API int STDCALL
241 mono_invoke_delegate (SimpleDelegate3 delegate)
245 // printf ("start invoke %p\n", delegate);
247 res = delegate (2, 3);
249 // printf ("end invoke\n");
254 LIBTEST_API int STDCALL
255 mono_test_marshal_char (short a1)
263 LIBTEST_API void STDCALL
264 mono_test_marshal_char_array (gunichar2 *s)
266 const char m[] = "abcdef";
270 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
278 LIBTEST_API int STDCALL
279 mono_test_empty_pinvoke (int i)
284 LIBTEST_API int STDCALL
285 mono_test_marshal_bool_byref (int a, int *b, int c)
294 LIBTEST_API int STDCALL
295 mono_test_marshal_bool_in_as_I1_U1 (char bTrue, char bFalse)
304 LIBTEST_API int STDCALL
305 mono_test_marshal_bool_out_as_I1_U1 (char* bTrue, char* bFalse)
307 if (!bTrue || !bFalse)
316 LIBTEST_API int STDCALL
317 mono_test_marshal_bool_ref_as_I1_U1 (char* bTrue, char* bFalse)
319 if (!bTrue || !bFalse)
333 LIBTEST_API int STDCALL
334 mono_test_marshal_array (int *a1)
338 for (i = 0; i < 50; i++)
344 LIBTEST_API int STDCALL
345 mono_test_marshal_inout_array (int *a1)
349 for (i = 0; i < 50; i++) {
351 a1 [i] = 50 - a1 [i];
357 LIBTEST_API int STDCALL
358 mono_test_marshal_out_array (int *a1)
362 for (i = 0; i < 50; i++) {
369 LIBTEST_API int STDCALL
370 mono_test_marshal_inout_nonblittable_array (gunichar2 *a1)
374 for (i = 0; i < 10; i++) {
394 LIBTEST_API simplestruct STDCALL
395 mono_test_return_vtype (int i)
398 static gunichar2 test2 [] = { 'T', 'E', 'S', 'T', '2', 0 };
409 LIBTEST_API void STDCALL
410 mono_test_delegate_struct (void)
412 // printf ("TEST\n");
415 typedef char* (STDCALL *ReturnStringDelegate) (const char *s);
417 LIBTEST_API char * STDCALL
418 mono_test_return_string (ReturnStringDelegate func)
422 // printf ("mono_test_return_string\n");
427 // printf ("got string: %s\n", res);
428 return g_strdup ("12345");
431 typedef int (STDCALL *RefVTypeDelegate) (int a, simplestruct *ss, int b);
433 LIBTEST_API int STDCALL
434 mono_test_ref_vtype (int a, simplestruct *ss, int b, RefVTypeDelegate func)
436 if (a == 1 && b == 2 && ss->a == 0 && ss->b == 1 && ss->c == 0 &&
437 !strcmp (ss->d, "TEST1")) {
443 return func (a, ss, b);
449 typedef int (STDCALL *OutVTypeDelegate) (int a, simplestruct *ss, int b);
451 LIBTEST_API int STDCALL
452 mono_test_marshal_out_struct (int a, simplestruct *ss, int b, OutVTypeDelegate func)
454 /* Check that the input pointer is ignored */
455 ss->d = (gpointer)0x12345678;
459 if (ss->a && ss->b && ss->c && !strcmp (ss->d, "TEST3"))
467 SimpleDelegate func, func2;
470 LIBTEST_API DelegateStruct STDCALL
471 mono_test_marshal_delegate_struct (DelegateStruct ds)
475 res.a = ds.func (ds.a) + ds.func2 (ds.a);
477 res.func2 = ds.func2;
482 LIBTEST_API int STDCALL
483 mono_test_marshal_struct (simplestruct ss)
485 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
486 !strcmp (ss.d, "TEST"))
492 LIBTEST_API int STDCALL
493 mono_test_marshal_byref_struct (simplestruct *ss, int a, int b, int c, char *d)
495 gboolean res = (ss->a == a && ss->b == b && ss->c == c && strcmp (ss->d, d) == 0);
497 marshal_free ((char*)ss->d);
502 ss->d = g_strdup ("DEF");
518 LIBTEST_API int STDCALL
519 mono_test_marshal_struct2 (simplestruct2 ss)
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)
529 /* on HP some of the struct should be on the stack and not in registers */
530 LIBTEST_API int STDCALL
531 mono_test_marshal_struct2_2 (int i, int j, int k, simplestruct2 ss)
533 if (i != 10 || j != 11 || k != 12)
535 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
536 !strcmp (ss.d, "TEST") &&
537 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
543 LIBTEST_API int STDCALL
544 mono_test_marshal_lpstruct (simplestruct *ss)
546 if (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
547 !strcmp (ss->d, "TEST"))
553 LIBTEST_API int STDCALL
554 mono_test_marshal_lpstruct_blittable (point *p)
556 if (p->x == 1.0 && p->y == 2.0)
562 LIBTEST_API int STDCALL
563 mono_test_marshal_struct_array (simplestruct2 *ss)
565 if (! (ss[0].a == 0 && ss[0].b == 1 && ss[0].c == 0 &&
566 !strcmp (ss[0].d, "TEST") &&
567 ss[0].e == 99 && ss[0].f == 1.5 && ss[0].g == 42 && ss[0].h == (guint64)123))
570 if (! (ss[1].a == 0 && ss[1].b == 0 && ss[1].c == 0 &&
571 !strcmp (ss[1].d, "TEST2") &&
572 ss[1].e == 100 && ss[1].f == 2.5 && ss[1].g == 43 && ss[1].h == (guint64)124))
578 typedef struct long_align_struct {
584 LIBTEST_API int STDCALL
585 mono_test_marshal_long_align_struct_array (long_align_struct *ss)
587 return ss[0].a + ss[0].b + ss[0].c + ss[1].a + ss[1].b + ss[1].c;
590 LIBTEST_API simplestruct2 * STDCALL
591 mono_test_marshal_class (int i, int j, int k, simplestruct2 *ss, int l)
598 if (i != 10 || j != 11 || k != 12 || l != 14)
600 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
601 !strcmp (ss->d, "TEST") &&
602 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
605 res = g_new0 (simplestruct2, 1);
606 memcpy (res, ss, sizeof (simplestruct2));
607 res->d = g_strdup ("TEST");
611 LIBTEST_API int STDCALL
612 mono_test_marshal_byref_class (simplestruct2 **ssp)
614 simplestruct2 *ss = *ssp;
617 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
618 !strcmp (ss->d, "TEST") &&
619 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
622 res = g_new0 (simplestruct2, 1);
623 memcpy (res, ss, sizeof (simplestruct2));
624 res->d = g_strdup ("TEST-RES");
636 /* Yes, this is correct, we are only trying to determine the value of the stack here */
641 LIBTEST_API int STDCALL
642 reliable_delegate (int a)
648 * Checks whether get_sp() works as expected. It doesn't work with gcc-2.95.3 on linux.
651 is_get_sp_reliable (void)
655 reliable_delegate(1);
657 reliable_delegate(1);
662 LIBTEST_API int STDCALL
663 mono_test_marshal_delegate (SimpleDelegate delegate)
667 /* Check that the delegate wrapper is stdcall */
672 if (is_get_sp_reliable())
673 g_assert (sp1 == sp2);
678 LIBTEST_API SimpleDelegate STDCALL
679 mono_test_marshal_return_delegate (SimpleDelegate delegate)
685 return_plus_one (int i)
690 LIBTEST_API SimpleDelegate STDCALL
691 mono_test_marshal_return_delegate_2 (void)
693 return return_plus_one;
696 typedef simplestruct (STDCALL *SimpleDelegate2) (simplestruct ss);
699 is_utf16_equals (gunichar2 *s1, const char *s2)
704 s = g_utf16_to_utf8 (s1, -1, NULL, NULL, NULL);
705 res = strcmp (s, s2);
711 LIBTEST_API int STDCALL
712 mono_test_marshal_delegate2 (SimpleDelegate2 delegate)
714 simplestruct ss, res;
720 ss.d2 = g_utf8_to_utf16 ("TEST2", -1, NULL, NULL, NULL);
723 if (! (res.a && !res.b && res.c && !strcmp (res.d, "TEST-RES") && is_utf16_equals (res.d2, "TEST2-RES")))
729 typedef simplestruct* (STDCALL *SimpleDelegate4) (simplestruct *ss);
731 LIBTEST_API int STDCALL
732 mono_test_marshal_delegate4 (SimpleDelegate4 delegate)
743 res = delegate (&ss);
747 /* Check return value */
748 if (! (!res->a && res->b && !res->c && !strcmp (res->d, "TEST")))
751 /* Check NULL argument and NULL result */
752 res = delegate (NULL);
759 typedef int (STDCALL *SimpleDelegate5) (simplestruct **ss);
761 LIBTEST_API int STDCALL
762 mono_test_marshal_delegate5 (SimpleDelegate5 delegate)
775 res = delegate (&ptr);
779 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
785 LIBTEST_API int STDCALL
786 mono_test_marshal_delegate6 (SimpleDelegate5 delegate)
790 res = delegate (NULL);
795 typedef int (STDCALL *SimpleDelegate7) (simplestruct **ss);
797 LIBTEST_API int STDCALL
798 mono_test_marshal_delegate7 (SimpleDelegate7 delegate)
803 /* Check that the input pointer is ignored */
804 ptr = (gpointer)0x12345678;
806 res = delegate (&ptr);
810 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
816 typedef int (STDCALL *InOutByvalClassDelegate) (simplestruct *ss);
818 LIBTEST_API int STDCALL
819 mono_test_marshal_inout_byval_class_delegate (InOutByvalClassDelegate delegate)
827 ss.d = g_strdup_printf ("%s", "FOO");
829 res = delegate (&ss);
833 if (!(ss.a && !ss.b && ss.c && !strcmp (ss.d, "RES")))
839 typedef int (STDCALL *SimpleDelegate8) (gunichar2 *s);
841 LIBTEST_API int STDCALL
842 mono_test_marshal_delegate8 (SimpleDelegate8 delegate, gunichar2 *s)
847 typedef int (STDCALL *return_int_fnt) (int i);
848 typedef int (STDCALL *SimpleDelegate9) (return_int_fnt d);
850 LIBTEST_API int STDCALL
851 mono_test_marshal_delegate9 (SimpleDelegate9 delegate, gpointer ftn)
853 return delegate (ftn);
862 LIBTEST_API int STDCALL
863 mono_test_marshal_delegate10 (SimpleDelegate9 delegate)
865 return delegate (return_self);
868 typedef int (STDCALL *PrimitiveByrefDelegate) (int *i);
870 LIBTEST_API int STDCALL
871 mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate delegate)
875 int res = delegate (&i);
885 typedef int (STDCALL *return_int_delegate) (int i);
887 typedef return_int_delegate (STDCALL *ReturnDelegateDelegate) (void);
889 LIBTEST_API int STDCALL
890 mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d)
895 LIBTEST_API int STDCALL
896 mono_test_marshal_stringbuilder (char *s, int n)
898 const char m[] = "This is my message. Isn't it nice?";
900 if (strcmp (s, "ABCD") != 0)
907 LIBTEST_API int STDCALL
908 mono_test_marshal_stringbuilder_default (char *s, int n)
910 const char m[] = "This is my message. Isn't it nice?";
917 LIBTEST_API int STDCALL
918 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
920 const char m[] = "This is my message. Isn't it nice?";
924 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
942 LIBTEST_API int STDCALL
943 mono_test_marshal_empty_string_array (char **array)
945 return (array == NULL) ? 0 : 1;
948 LIBTEST_API int STDCALL
949 mono_test_marshal_string_array (char **array)
951 if (strcmp (array [0], "ABC"))
953 if (strcmp (array [1], "DEF"))
956 if (array [2] != NULL)
962 LIBTEST_API int STDCALL
963 mono_test_marshal_byref_string_array (char ***array)
968 if (strcmp ((*array) [0], "Alpha"))
970 if (strcmp ((*array) [1], "Beta"))
972 if (strcmp ((*array) [2], "Gamma"))
978 LIBTEST_API int STDCALL
979 mono_test_marshal_stringbuilder_array (char **array)
981 if (strcmp (array [0], "ABC"))
983 if (strcmp (array [1], "DEF"))
986 strcpy (array [0], "DEF");
987 strcpy (array [1], "ABC");
992 LIBTEST_API int STDCALL
993 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
995 GError *error = NULL;
998 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
999 if (strcmp (s, "ABC")) {
1006 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
1007 if (strcmp (s, "DEF")) {
1014 if (strcmp (array2 [0], "ABC"))
1017 if (strcmp (array2 [1], "DEF"))
1023 /* this does not work on Redhat gcc 2.96 */
1024 LIBTEST_API int STDCALL
1025 mono_test_empty_struct (int a, EmptyStruct es, int b)
1027 // printf ("mono_test_empty_struct %d %d\n", a, b);
1029 // Intel icc on ia64 passes 'es' in 2 registers
1030 #if defined(__ia64) && defined(__INTEL_COMPILER)
1033 if (a == 1 && b == 2)
1043 LIBTEST_API ByValStrStruct * STDCALL
1044 mono_test_byvalstr_gen (void)
1046 ByValStrStruct *ret;
1048 ret = malloc(sizeof(ByValStrStruct));
1049 memset(ret, 'a', sizeof(ByValStrStruct)-1);
1050 ret->a[sizeof(ByValStrStruct)-1] = 0;
1055 LIBTEST_API int STDCALL
1056 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
1060 ret = strcmp(data->a, correctString);
1061 // printf ("T1: %s\n", data->a);
1062 // printf ("T2: %s\n", correctString);
1064 marshal_free (data);
1071 } ByValStrStruct_Unicode;
1073 LIBTEST_API int STDCALL
1074 mono_test_byvalstr_check_unicode (ByValStrStruct_Unicode *ref, int test)
1076 if (ref->flag != 0x1234abcd){
1077 printf ("overwritten data");
1081 if (test == 1 || test == 3){
1082 if (ref->a [0] != '1' ||
1083 ref->a [1] != '2' ||
1089 if (ref->a [0] != '1' ||
1097 LIBTEST_API int STDCALL
1098 NameManglingAnsi (char *data)
1100 return data [0] + data [1] + data [2];
1103 LIBTEST_API int STDCALL
1104 NameManglingAnsiA (char *data)
1106 g_assert_not_reached ();
1109 LIBTEST_API int STDCALL
1110 NameManglingAnsiW (char *data)
1112 g_assert_not_reached ();
1115 LIBTEST_API int STDCALL
1116 NameManglingAnsi2A (char *data)
1118 return data [0] + data [1] + data [2];
1121 LIBTEST_API int STDCALL
1122 NameManglingAnsi2W (char *data)
1124 g_assert_not_reached ();
1127 LIBTEST_API int STDCALL
1128 NameManglingUnicode (char *data)
1130 g_assert_not_reached ();
1133 LIBTEST_API int STDCALL
1134 NameManglingUnicodeW (gunichar2 *data)
1136 return data [0] + data [1] + data [2];
1139 LIBTEST_API int STDCALL
1140 NameManglingUnicode2 (gunichar2 *data)
1142 return data [0] + data [1] + data [2];
1145 LIBTEST_API int STDCALL
1146 NameManglingAutoW (char *data)
1149 return (data [0] + data [1] + data [2]) == 131 ? 0 : 1;
1151 g_assert_not_reached ();
1155 LIBTEST_API int STDCALL
1156 NameManglingAuto (char *data)
1159 return (data [0] + data [1] + data [2]) == 198 ? 0 : 1;
1161 g_assert_not_reached ();
1165 typedef int (STDCALL *intcharFunc)(const char*);
1167 LIBTEST_API void STDCALL
1168 callFunction (intcharFunc f)
1178 LIBTEST_API int STDCALL
1179 class_marshal_test0 (SimpleObj *obj1)
1181 // printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
1183 if (strcmp(obj1->str, "T1"))
1191 LIBTEST_API int STDCALL
1192 class_marshal_test4 (SimpleObj *obj1)
1200 LIBTEST_API void STDCALL
1201 class_marshal_test1 (SimpleObj **obj1)
1203 SimpleObj *res = malloc (sizeof (SimpleObj));
1205 res->str = g_strdup ("ABC");
1211 LIBTEST_API int STDCALL
1212 class_marshal_test2 (SimpleObj **obj1)
1214 // printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
1216 if (strcmp((*obj1)->str, "ABC"))
1218 if ((*obj1)->i != 5)
1224 LIBTEST_API int STDCALL
1225 string_marshal_test0 (char *str)
1227 if (strcmp (str, "TEST0"))
1233 LIBTEST_API void STDCALL
1234 string_marshal_test1 (const char **str)
1236 *str = g_strdup ("TEST1");
1239 LIBTEST_API int STDCALL
1240 string_marshal_test2 (char **str)
1242 // printf ("string_marshal_test2 %s\n", *str);
1244 if (strcmp (*str, "TEST1"))
1250 LIBTEST_API int STDCALL
1251 string_marshal_test3 (char *str)
1264 LIBTEST_API BlittableClass* STDCALL
1265 TestBlittableClass (BlittableClass *vl)
1267 BlittableClass *res;
1269 // printf ("TestBlittableClass %d %d\n", vl->a, vl->b);
1275 res = g_new0 (BlittableClass, 1);
1276 memcpy (res, vl, sizeof (BlittableClass));
1278 res = g_new0 (BlittableClass, 1);
1286 typedef struct OSVERSIONINFO_STRUCT
1290 } OSVERSIONINFO_STRUCT;
1292 LIBTEST_API int STDCALL
1293 MyGetVersionEx (OSVERSIONINFO_STRUCT *osvi)
1296 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1301 return osvi->a + osvi->b;
1304 LIBTEST_API int STDCALL
1305 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO_STRUCT *osvi)
1308 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1313 return osvi->a + osvi->b;
1316 LIBTEST_API int STDCALL
1317 mono_test_marshal_point (point pt)
1319 // printf("point %g %g\n", pt.x, pt.y);
1320 if (pt.x == 1.25 && pt.y == 3.5)
1331 LIBTEST_API int STDCALL
1332 mono_test_marshal_mixed_point (mixed_point pt)
1334 // printf("mixed point %d %g\n", pt.x, pt.y);
1335 if (pt.x == 5 && pt.y == 6.75)
1341 LIBTEST_API int STDCALL
1342 mono_test_marshal_mixed_point_2 (mixed_point *pt)
1344 if (pt->x != 5 || pt->y != 6.75)
1353 LIBTEST_API int STDCALL
1354 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
1357 if (*b1 != 0 && *b1 != 1)
1359 if (*b2 != 0 && *b2 != -1) /* variant_bool */
1361 if (*b3 != 0 && *b3 != 1)
1363 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
1375 short b2; /* variant_bool */
1379 LIBTEST_API int STDCALL
1380 marshal_test_bool_struct(struct BoolStruct *s)
1383 if (s->b1 != 0 && s->b1 != 1)
1385 if (s->b2 != 0 && s->b2 != -1)
1387 if (s->b3 != 0 && s->b3 != 1)
1389 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1397 LIBTEST_API void STDCALL
1398 mono_test_last_error (int err)
1407 LIBTEST_API int STDCALL
1408 mono_test_asany (void *ptr, int what)
1412 return (*(int*)ptr == 5) ? 0 : 1;
1414 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1416 simplestruct2 ss = *(simplestruct2*)ptr;
1418 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1419 !strcmp (ss.d, "TEST") &&
1420 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1426 GError *error = NULL;
1429 s = g_utf16_to_utf8 (ptr, -1, NULL, NULL, &error);
1430 if (!strcmp (s, "ABC")) {
1440 g_assert_not_reached ();
1454 LIBTEST_API int STDCALL
1455 mono_test_marshal_asany_in (void* ptr)
1457 AsAnyStruct* asAny = ptr;
1458 int res = asAny->i + asAny->j + asAny->k;
1463 LIBTEST_API int STDCALL
1464 mono_test_marshal_asany_inout (void* ptr)
1466 AsAnyStruct* asAny = ptr;
1467 int res = asAny->i + asAny->j + asAny->k;
1469 marshal_free (asAny->s);
1479 LIBTEST_API int STDCALL
1480 mono_test_marshal_asany_out (void* ptr)
1482 AsAnyStruct* asAny = ptr;
1483 int res = asAny->i + asAny->j + asAny->k;
1494 * AMD64 marshalling tests.
1497 typedef struct amd64_struct1 {
1504 LIBTEST_API amd64_struct1 STDCALL
1505 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
1515 typedef struct amd64_struct2 {
1520 LIBTEST_API amd64_struct2 STDCALL
1521 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
1529 typedef struct amd64_struct3 {
1533 LIBTEST_API amd64_struct3 STDCALL
1534 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s)
1541 typedef struct amd64_struct4 {
1545 LIBTEST_API amd64_struct4 STDCALL
1546 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s)
1555 * IA64 marshalling tests.
1557 typedef struct test_struct5 {
1561 LIBTEST_API test_struct5 STDCALL
1562 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, test_struct5 s, double d3, double d4)
1570 typedef struct test_struct6 {
1574 LIBTEST_API test_struct6 STDCALL
1575 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, test_struct6 s, double d3, double d4)
1583 static guint32 custom_res [2];
1585 LIBTEST_API void* STDCALL
1586 mono_test_marshal_pass_return_custom (int i, guint32 *ptr, int j)
1588 /* ptr will be freed by CleanupNative, so make a copy */
1589 custom_res [0] = 0; /* not allocated by AllocHGlobal */
1590 custom_res [1] = ptr [1];
1595 LIBTEST_API int STDCALL
1596 mono_test_marshal_pass_out_custom (int i, guint32 **ptr, int j)
1599 custom_res [1] = i + j + 10;
1606 LIBTEST_API int STDCALL
1607 mono_test_marshal_pass_inout_custom (int i, guint32 *ptr, int j)
1610 ptr [1] = i + ptr [1] + j;
1615 LIBTEST_API int STDCALL
1616 mono_test_marshal_pass_out_byval_custom (int i, guint32 *ptr, int j)
1618 return ptr == NULL ? 0 : 1;
1621 LIBTEST_API int STDCALL
1622 mono_test_marshal_pass_byref_custom (int i, guint32 **ptr, int j)
1629 LIBTEST_API void* STDCALL
1630 mono_test_marshal_pass_return_custom2 (int i, guint32 *ptr, int j)
1632 g_assert_not_reached ();
1637 LIBTEST_API void* STDCALL
1638 mono_test_marshal_pass_return_custom_null (int i, guint32 *ptr, int j)
1640 g_assert (ptr == NULL);
1645 typedef void *(STDCALL *PassReturnPtrDelegate) (void *ptr);
1647 LIBTEST_API int STDCALL
1648 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del)
1662 /* FIXME: Freed with FreeHGlobal */
1670 LIBTEST_API int STDCALL
1671 mono_test_marshal_pass_return_custom_null_in_delegate (PassReturnPtrDelegate del)
1673 void *ptr = del (NULL);
1675 return (ptr == NULL) ? 15 : 0;
1678 typedef void (STDCALL *CustomOutParamDelegate) (void **pptr);
1680 LIBTEST_API int STDCALL
1681 mono_test_marshal_custom_out_param_delegate (CustomOutParamDelegate del)
1693 typedef int (STDCALL *ReturnEnumDelegate) (int e);
1695 LIBTEST_API int STDCALL
1696 mono_test_marshal_return_enum_delegate (ReturnEnumDelegate func)
1706 typedef BlittableStruct (STDCALL *SimpleDelegate10) (BlittableStruct ss);
1708 LIBTEST_API int STDCALL
1709 mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 delegate)
1711 BlittableStruct ss, res;
1718 res = delegate (ss);
1719 if (! ((res.a == -1) && (res.b == -2) && (res.c == -3) && (res.d == -55)))
1725 LIBTEST_API int STDCALL
1726 mono_test_stdcall_name_mangling (int a, int b, int c)
1732 * PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
1739 typedef SmallStruct1 (STDCALL *SmallStructDelegate1) (SmallStruct1 ss);
1741 LIBTEST_API int STDCALL
1742 mono_test_marshal_small_struct_delegate1 (SmallStructDelegate1 delegate)
1744 SmallStruct1 ss, res;
1748 res = delegate (ss);
1749 if (! (res.i == -1))
1759 typedef SmallStruct2 (STDCALL *SmallStructDelegate2) (SmallStruct2 ss);
1761 LIBTEST_API int STDCALL
1762 mono_test_marshal_small_struct_delegate2 (SmallStructDelegate2 delegate)
1764 SmallStruct2 ss, res;
1769 res = delegate (ss);
1770 if (! ((res.i == -2) && (res.j == -3)))
1781 typedef SmallStruct3 (STDCALL *SmallStructDelegate3) (SmallStruct3 ss);
1783 LIBTEST_API int STDCALL
1784 mono_test_marshal_small_struct_delegate3 (SmallStructDelegate3 delegate)
1786 SmallStruct3 ss, res;
1791 res = delegate (ss);
1792 if (! ((res.i == -1) && (res.j == -2)))
1802 typedef SmallStruct4 (STDCALL *SmallStructDelegate4) (SmallStruct4 ss);
1804 LIBTEST_API int STDCALL
1805 mono_test_marshal_small_struct_delegate4 (SmallStructDelegate4 delegate)
1807 SmallStruct4 ss, res;
1811 res = delegate (ss);
1812 if (! (res.i == -1))
1822 typedef SmallStruct5 (STDCALL *SmallStructDelegate5) (SmallStruct5 ss);
1824 LIBTEST_API int STDCALL
1825 mono_test_marshal_small_struct_delegate5 (SmallStructDelegate5 delegate)
1827 SmallStruct5 ss, res;
1831 res = delegate (ss);
1832 if (! (res.i == -5))
1842 typedef SmallStruct6 (STDCALL *SmallStructDelegate6) (SmallStruct6 ss);
1844 LIBTEST_API int STDCALL
1845 mono_test_marshal_small_struct_delegate6 (SmallStructDelegate6 delegate)
1847 SmallStruct6 ss, res;
1852 res = delegate (ss);
1853 if (! ((res.i == -1) && (res.j == -2)))
1864 typedef SmallStruct7 (STDCALL *SmallStructDelegate7) (SmallStruct7 ss);
1866 LIBTEST_API int STDCALL
1867 mono_test_marshal_small_struct_delegate7 (SmallStructDelegate7 delegate)
1869 SmallStruct7 ss, res;
1874 res = delegate (ss);
1875 if (! ((res.i == -1) && (res.j == -2)))
1885 typedef SmallStruct8 (STDCALL *SmallStructDelegate8) (SmallStruct8 ss);
1887 LIBTEST_API int STDCALL
1888 mono_test_marshal_small_struct_delegate8 (SmallStructDelegate8 delegate)
1890 SmallStruct8 ss, res;
1894 res = delegate (ss);
1895 if (! ((res.i == -1.0)))
1905 typedef SmallStruct9 (STDCALL *SmallStructDelegate9) (SmallStruct9 ss);
1907 LIBTEST_API int STDCALL
1908 mono_test_marshal_small_struct_delegate9 (SmallStructDelegate9 delegate)
1910 SmallStruct9 ss, res;
1914 res = delegate (ss);
1915 if (! ((res.i == -1.0)))
1925 typedef SmallStruct10 (STDCALL *SmallStructDelegate10) (SmallStruct10 ss);
1927 LIBTEST_API int STDCALL
1928 mono_test_marshal_small_struct_delegate10 (SmallStructDelegate10 delegate)
1930 SmallStruct10 ss, res;
1935 res = delegate (ss);
1936 if (! ((res.i == -1.0) && (res.j == -2.0)))
1947 typedef SmallStruct11 (STDCALL *SmallStructDelegate11) (SmallStruct11 ss);
1949 LIBTEST_API int STDCALL
1950 mono_test_marshal_small_struct_delegate11 (SmallStructDelegate11 delegate)
1952 SmallStruct11 ss, res;
1957 res = delegate (ss);
1958 if (! ((res.i == -1.0) && (res.j == -2)))
1964 typedef int (STDCALL *ArrayDelegate) (int i, char *j, void *arr);
1966 LIBTEST_API int STDCALL
1967 mono_test_marshal_array_delegate (void *arr, int len, ArrayDelegate del)
1969 return del (len, NULL, arr);
1972 LIBTEST_API int STDCALL
1973 mono_test_marshal_out_array_delegate (int *arr, int len, ArrayDelegate del)
1975 del (len, NULL, arr);
1977 if ((arr [0] != 1) || (arr [1] != 2))
1983 typedef gunichar2* (STDCALL *UnicodeStringDelegate) (gunichar2 *message);
1985 LIBTEST_API int STDCALL
1986 mono_test_marshal_return_unicode_string_delegate (UnicodeStringDelegate del)
1988 const char m[] = "abcdef";
1989 gunichar2 *s2, *res;
1992 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
2001 LIBTEST_API int STDCALL
2002 mono_test_marshal_out_string_array_delegate (char **arr, int len, ArrayDelegate del)
2004 del (len, NULL, arr);
2006 if (!strcmp (arr [0], "ABC") && !strcmp (arr [1], "DEF"))
2012 typedef int (*CdeclDelegate) (int i, int j);
2014 LIBTEST_API int STDCALL
2015 mono_test_marshal_cdecl_delegate (CdeclDelegate del)
2019 for (i = 0; i < 1000; ++i)
2025 typedef char** (*ReturnStringArrayDelegate) (int i);
2027 LIBTEST_API int STDCALL
2028 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d)
2036 if (strcmp (arr [0], "ABC") || strcmp (arr [1], "DEF"))
2046 LIBTEST_API int STDCALL
2047 add_delegate (int i, int j)
2052 LIBTEST_API gpointer STDCALL
2053 mono_test_marshal_return_fnptr (void)
2055 return &add_delegate;
2058 LIBTEST_API int STDCALL
2061 printf ("codigo %x\n", code);
2069 LIBTEST_API HandleRef STDCALL
2070 mono_xr_as_handle (int code)
2084 LIBTEST_API int STDCALL
2085 mono_safe_handle_struct_ref (HandleStructs *x)
2087 printf ("Dingus Ref! \n");
2088 printf ("Values: %d %d %p %p\n", x->a, x->b, x->handle1, x->handle2);
2094 if (x->handle1 != (void*) 0x7080feed)
2097 if (x->handle2 != (void*) 0x1234abcd)
2103 LIBTEST_API int STDCALL
2104 mono_safe_handle_struct (HandleStructs x)
2106 printf ("Dingus Standard! \n");
2107 printf ("Values: %d %d %p %p\n", x.a, x.b, x.handle1, x.handle2);
2113 if (x.handle1 != (void*) 0x7080feed)
2116 if (x.handle2 != (void*) 0x1234abcd)
2126 LIBTEST_API int STDCALL
2127 mono_safe_handle_struct_simple (TrivialHandle x)
2129 printf ("The value is %p\n", x.a);
2130 return ((int)(gsize)x.a) * 2;
2133 LIBTEST_API int STDCALL
2134 mono_safe_handle_return (void)
2139 LIBTEST_API void STDCALL
2140 mono_safe_handle_ref (void **handle)
2143 *handle = (void *) 0xbad;
2147 *handle = (void *) 0x800d;
2155 LIBTEST_API int STDCALL
2156 mono_test_marshal_bstr_in(BSTR bstr)
2158 if (!wcscmp(bstr, L"mono_test_marshal_bstr_in"))
2163 LIBTEST_API int STDCALL
2164 mono_test_marshal_bstr_out(BSTR* bstr)
2166 *bstr = SysAllocString(L"mono_test_marshal_bstr_out");
2170 LIBTEST_API int STDCALL
2171 mono_test_marshal_bstr_in_null(BSTR bstr)
2178 LIBTEST_API int STDCALL
2179 mono_test_marshal_bstr_out_null(BSTR* bstr)
2185 LIBTEST_API int STDCALL
2186 mono_test_marshal_variant_in_sbyte(VARIANT variant)
2188 if (variant.vt == VT_I1 && variant.cVal == 100)
2193 LIBTEST_API int STDCALL
2194 mono_test_marshal_variant_in_byte(VARIANT variant)
2196 if (variant.vt == VT_UI1 && variant.bVal == 100)
2201 LIBTEST_API int STDCALL
2202 mono_test_marshal_variant_in_short(VARIANT variant)
2204 if (variant.vt == VT_I2 && variant.iVal == 314)
2209 LIBTEST_API int STDCALL
2210 mono_test_marshal_variant_in_ushort(VARIANT variant)
2212 if (variant.vt == VT_UI2 && variant.uiVal == 314)
2217 LIBTEST_API int STDCALL
2218 mono_test_marshal_variant_in_int(VARIANT variant)
2220 if (variant.vt == VT_I4 && variant.lVal == 314)
2225 LIBTEST_API int STDCALL
2226 mono_test_marshal_variant_in_uint(VARIANT variant)
2228 if (variant.vt == VT_UI4 && variant.ulVal == 314)
2233 LIBTEST_API int STDCALL
2234 mono_test_marshal_variant_in_long(VARIANT variant)
2236 if (variant.vt == VT_I8 && variant.llVal == 314)
2241 LIBTEST_API int STDCALL
2242 mono_test_marshal_variant_in_ulong(VARIANT variant)
2244 if (variant.vt == VT_UI8 && variant.ullVal == 314)
2249 LIBTEST_API int STDCALL
2250 mono_test_marshal_variant_in_float(VARIANT variant)
2252 if (variant.vt == VT_R4 && (variant.fltVal - 3.14)/3.14 < .001)
2257 LIBTEST_API int STDCALL
2258 mono_test_marshal_variant_in_double(VARIANT variant)
2260 if (variant.vt == VT_R8 && (variant.dblVal - 3.14)/3.14 < .001)
2265 LIBTEST_API int STDCALL
2266 mono_test_marshal_variant_in_bstr(VARIANT variant)
2268 if (variant.vt == VT_BSTR && !wcscmp(variant.bstrVal, L"PI"))
2273 LIBTEST_API int STDCALL
2274 mono_test_marshal_variant_in_bool_true (VARIANT variant)
2276 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_TRUE)
2281 LIBTEST_API int STDCALL
2282 mono_test_marshal_variant_in_bool_false (VARIANT variant)
2284 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_FALSE)
2289 LIBTEST_API int STDCALL
2290 mono_test_marshal_variant_out_sbyte(VARIANT* variant)
2292 variant->vt = VT_I1;
2293 variant->cVal = 100;
2298 LIBTEST_API int STDCALL
2299 mono_test_marshal_variant_out_byte(VARIANT* variant)
2301 variant->vt = VT_UI1;
2302 variant->bVal = 100;
2307 LIBTEST_API int STDCALL
2308 mono_test_marshal_variant_out_short(VARIANT* variant)
2310 variant->vt = VT_I2;
2311 variant->iVal = 314;
2316 LIBTEST_API int STDCALL
2317 mono_test_marshal_variant_out_ushort(VARIANT* variant)
2319 variant->vt = VT_UI2;
2320 variant->uiVal = 314;
2325 LIBTEST_API int STDCALL
2326 mono_test_marshal_variant_out_int(VARIANT* variant)
2328 variant->vt = VT_I4;
2329 variant->lVal = 314;
2334 LIBTEST_API int STDCALL
2335 mono_test_marshal_variant_out_uint(VARIANT* variant)
2337 variant->vt = VT_UI4;
2338 variant->ulVal = 314;
2343 LIBTEST_API int STDCALL
2344 mono_test_marshal_variant_out_long(VARIANT* variant)
2346 variant->vt = VT_I8;
2347 variant->llVal = 314;
2352 LIBTEST_API int STDCALL
2353 mono_test_marshal_variant_out_ulong(VARIANT* variant)
2355 variant->vt = VT_UI8;
2356 variant->ullVal = 314;
2361 LIBTEST_API int STDCALL
2362 mono_test_marshal_variant_out_float(VARIANT* variant)
2364 variant->vt = VT_R4;
2365 variant->fltVal = 3.14;
2370 LIBTEST_API int STDCALL
2371 mono_test_marshal_variant_out_double(VARIANT* variant)
2373 variant->vt = VT_R8;
2374 variant->dblVal = 3.14;
2379 LIBTEST_API int STDCALL
2380 mono_test_marshal_variant_out_bstr(VARIANT* variant)
2382 variant->vt = VT_BSTR;
2383 variant->bstrVal = SysAllocString(L"PI");
2388 LIBTEST_API int STDCALL
2389 mono_test_marshal_variant_out_bool_true (VARIANT* variant)
2391 variant->vt = VT_BOOL;
2392 variant->boolVal = VARIANT_TRUE;
2397 LIBTEST_API int STDCALL
2398 mono_test_marshal_variant_out_bool_false (VARIANT* variant)
2400 variant->vt = VT_BOOL;
2401 variant->boolVal = VARIANT_FALSE;
2406 typedef int (STDCALL *VarFunc) (int vt, VARIANT variant);
2407 typedef int (STDCALL *VarRefFunc) (int vt, VARIANT* variant);
2409 LIBTEST_API int STDCALL
2410 mono_test_marshal_variant_in_sbyte_unmanaged(VarFunc func)
2415 return func (VT_I1, vt);
2418 LIBTEST_API int STDCALL
2419 mono_test_marshal_variant_in_byte_unmanaged(VarFunc func)
2424 return func (VT_UI1, vt);
2427 LIBTEST_API int STDCALL
2428 mono_test_marshal_variant_in_short_unmanaged(VarFunc func)
2433 return func (VT_I2, vt);
2436 LIBTEST_API int STDCALL
2437 mono_test_marshal_variant_in_ushort_unmanaged(VarFunc func)
2442 return func (VT_UI2, vt);
2445 LIBTEST_API int STDCALL
2446 mono_test_marshal_variant_in_int_unmanaged(VarFunc func)
2451 return func (VT_I4, vt);
2454 LIBTEST_API int STDCALL
2455 mono_test_marshal_variant_in_uint_unmanaged(VarFunc func)
2460 return func (VT_UI4, vt);
2463 LIBTEST_API int STDCALL
2464 mono_test_marshal_variant_in_long_unmanaged(VarFunc func)
2469 return func (VT_I8, vt);
2472 LIBTEST_API int STDCALL
2473 mono_test_marshal_variant_in_ulong_unmanaged(VarFunc func)
2478 return func (VT_UI8, vt);
2481 LIBTEST_API int STDCALL
2482 mono_test_marshal_variant_in_float_unmanaged(VarFunc func)
2487 return func (VT_R4, vt);
2490 LIBTEST_API int STDCALL
2491 mono_test_marshal_variant_in_double_unmanaged(VarFunc func)
2496 return func (VT_R8, vt);
2499 LIBTEST_API int STDCALL
2500 mono_test_marshal_variant_in_bstr_unmanaged(VarFunc func)
2504 vt.bstrVal = SysAllocString(L"PI");
2505 return func (VT_BSTR, vt);
2508 LIBTEST_API int STDCALL
2509 mono_test_marshal_variant_in_bool_true_unmanaged(VarFunc func)
2513 vt.boolVal = VARIANT_TRUE;
2514 return func (VT_BOOL, vt);
2517 LIBTEST_API int STDCALL
2518 mono_test_marshal_variant_in_bool_false_unmanaged(VarFunc func)
2522 vt.boolVal = VARIANT_FALSE;
2523 return func (VT_BOOL, vt);
2526 LIBTEST_API int STDCALL
2527 mono_test_marshal_variant_out_sbyte_unmanaged(VarRefFunc func)
2532 if (vt.vt == VT_I1 && vt.cVal == -100)
2537 LIBTEST_API int STDCALL
2538 mono_test_marshal_variant_out_byte_unmanaged(VarRefFunc func)
2543 if (vt.vt == VT_UI1 && vt.bVal == 100)
2548 LIBTEST_API int STDCALL
2549 mono_test_marshal_variant_out_short_unmanaged(VarRefFunc func)
2554 if (vt.vt == VT_I2 && vt.iVal == -100)
2559 LIBTEST_API int STDCALL
2560 mono_test_marshal_variant_out_ushort_unmanaged(VarRefFunc func)
2565 if (vt.vt == VT_UI2 && vt.uiVal == 100)
2570 LIBTEST_API int STDCALL
2571 mono_test_marshal_variant_out_int_unmanaged(VarRefFunc func)
2576 if (vt.vt == VT_I4 && vt.lVal == -100)
2581 LIBTEST_API int STDCALL
2582 mono_test_marshal_variant_out_uint_unmanaged(VarRefFunc func)
2587 if (vt.vt == VT_UI4 && vt.ulVal == 100)
2592 LIBTEST_API int STDCALL
2593 mono_test_marshal_variant_out_long_unmanaged(VarRefFunc func)
2598 if (vt.vt == VT_I8 && vt.llVal == -100)
2603 LIBTEST_API int STDCALL
2604 mono_test_marshal_variant_out_ulong_unmanaged(VarRefFunc func)
2609 if (vt.vt == VT_UI8 && vt.ullVal == 100)
2614 LIBTEST_API int STDCALL
2615 mono_test_marshal_variant_out_float_unmanaged(VarRefFunc func)
2620 if (vt.vt == VT_R4 && fabs (vt.fltVal - 3.14f) < 1e-10)
2625 LIBTEST_API int STDCALL
2626 mono_test_marshal_variant_out_double_unmanaged(VarRefFunc func)
2631 if (vt.vt == VT_R8 && fabs (vt.dblVal - 3.14) < 1e-10)
2636 LIBTEST_API int STDCALL
2637 mono_test_marshal_variant_out_bstr_unmanaged(VarRefFunc func)
2641 func (VT_BSTR, &vt);
2642 if (vt.vt == VT_BSTR && !wcscmp(vt.bstrVal, L"PI"))
2647 LIBTEST_API int STDCALL
2648 mono_test_marshal_variant_out_bool_true_unmanaged(VarRefFunc func)
2652 func (VT_BOOL, &vt);
2653 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
2658 LIBTEST_API int STDCALL
2659 mono_test_marshal_variant_out_bool_false_unmanaged(VarRefFunc func)
2663 func (VT_BOOL, &vt);
2664 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
2669 typedef struct MonoComObject MonoComObject;
2673 int (STDCALL *QueryInterface)(MonoComObject* pUnk, gpointer riid, gpointer* ppv);
2674 int (STDCALL *AddRef)(MonoComObject* pUnk);
2675 int (STDCALL *Release)(MonoComObject* pUnk);
2676 int (STDCALL *get_ITest)(MonoComObject* pUnk, MonoComObject* *ppUnk);
2677 int (STDCALL *SByteIn)(MonoComObject* pUnk, char a);
2678 int (STDCALL *ByteIn)(MonoComObject* pUnk, unsigned char a);
2679 int (STDCALL *ShortIn)(MonoComObject* pUnk, short a);
2680 int (STDCALL *UShortIn)(MonoComObject* pUnk, unsigned short a);
2681 int (STDCALL *IntIn)(MonoComObject* pUnk, int a);
2682 int (STDCALL *UIntIn)(MonoComObject* pUnk, unsigned int a);
2683 int (STDCALL *LongIn)(MonoComObject* pUnk, LONGLONG a);
2684 int (STDCALL *ULongIn)(MonoComObject* pUnk, ULONGLONG a);
2685 int (STDCALL *FloatIn)(MonoComObject* pUnk, float a);
2686 int (STDCALL *DoubleIn)(MonoComObject* pUnk, double a);
2687 int (STDCALL *ITestIn)(MonoComObject* pUnk, MonoComObject* pUnk2);
2688 int (STDCALL *ITestOut)(MonoComObject* pUnk, MonoComObject* *ppUnk);
2691 struct MonoComObject
2697 DEFINE_GUID(IID_ITest, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
2698 DEFINE_GUID(IID_IMonoUnknown, 0, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46);
2699 DEFINE_GUID(IID_IMonoDispatch, 0x00020400, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46);
2701 LIBTEST_API int STDCALL
2702 MonoQueryInterface(MonoComObject* pUnk, gpointer riid, gpointer* ppv)
2705 if (!memcmp(riid, &IID_IMonoUnknown, sizeof(GUID))) {
2709 else if (!memcmp(riid, &IID_ITest, sizeof(GUID))) {
2713 else if (!memcmp(riid, &IID_IMonoDispatch, sizeof(GUID))) {
2717 return E_NOINTERFACE;
2720 LIBTEST_API int STDCALL
2721 MonoAddRef(MonoComObject* pUnk)
2723 return ++(pUnk->m_ref);
2726 LIBTEST_API int STDCALL
2727 MonoRelease(MonoComObject* pUnk)
2729 return --(pUnk->m_ref);
2732 LIBTEST_API int STDCALL
2733 SByteIn(MonoComObject* pUnk, char a)
2738 LIBTEST_API int STDCALL
2739 ByteIn(MonoComObject* pUnk, unsigned char a)
2744 LIBTEST_API int STDCALL
2745 ShortIn(MonoComObject* pUnk, short a)
2750 LIBTEST_API int STDCALL
2751 UShortIn(MonoComObject* pUnk, unsigned short a)
2756 LIBTEST_API int STDCALL
2757 IntIn(MonoComObject* pUnk, int a)
2762 LIBTEST_API int STDCALL
2763 UIntIn(MonoComObject* pUnk, unsigned int a)
2768 LIBTEST_API int STDCALL
2769 LongIn(MonoComObject* pUnk, LONGLONG a)
2774 LIBTEST_API int STDCALL
2775 ULongIn(MonoComObject* pUnk, ULONGLONG a)
2780 LIBTEST_API int STDCALL
2781 FloatIn(MonoComObject* pUnk, float a)
2786 LIBTEST_API int STDCALL
2787 DoubleIn(MonoComObject* pUnk, double a)
2792 LIBTEST_API int STDCALL
2793 ITestIn(MonoComObject* pUnk, MonoComObject *pUnk2)
2798 LIBTEST_API int STDCALL
2799 ITestOut(MonoComObject* pUnk, MonoComObject* *ppUnk)
2804 LIBTEST_API int STDCALL
2805 get_ITest(MonoComObject* pUnk, MonoComObject* *ppUnk)
2810 static void create_com_object (MonoComObject** pOut)
2812 *pOut = g_new0 (MonoComObject, 1);
2813 (*pOut)->vtbl = g_new0 (MonoIUnknown, 1);
2816 (*pOut)->vtbl->QueryInterface = MonoQueryInterface;
2817 (*pOut)->vtbl->AddRef = MonoAddRef;
2818 (*pOut)->vtbl->Release = MonoRelease;
2819 (*pOut)->vtbl->SByteIn = SByteIn;
2820 (*pOut)->vtbl->ByteIn = ByteIn;
2821 (*pOut)->vtbl->ShortIn = ShortIn;
2822 (*pOut)->vtbl->UShortIn = UShortIn;
2823 (*pOut)->vtbl->IntIn = IntIn;
2824 (*pOut)->vtbl->UIntIn = UIntIn;
2825 (*pOut)->vtbl->LongIn = LongIn;
2826 (*pOut)->vtbl->ULongIn = ULongIn;
2827 (*pOut)->vtbl->FloatIn = FloatIn;
2828 (*pOut)->vtbl->DoubleIn = DoubleIn;
2829 (*pOut)->vtbl->ITestIn = ITestIn;
2830 (*pOut)->vtbl->ITestOut = ITestOut;
2831 (*pOut)->vtbl->get_ITest = get_ITest;
2834 static MonoComObject* same_object = NULL;
2836 LIBTEST_API int STDCALL
2837 mono_test_marshal_com_object_create(MonoComObject* *pUnk)
2839 create_com_object (pUnk);
2842 same_object = *pUnk;
2847 LIBTEST_API int STDCALL
2848 mono_test_marshal_com_object_same(MonoComObject* *pUnk)
2850 *pUnk = same_object;
2855 LIBTEST_API int STDCALL
2856 mono_test_marshal_com_object_destroy(MonoComObject *pUnk)
2858 int ref = --(pUnk->m_ref);
2865 LIBTEST_API int STDCALL
2866 mono_test_marshal_com_object_ref_count(MonoComObject *pUnk)
2871 LIBTEST_API int STDCALL
2872 mono_test_marshal_ccw_itest (MonoComObject *pUnk)
2875 MonoComObject* pTest;
2880 hr = pUnk->vtbl->SByteIn (pUnk, -100);
2883 hr = pUnk->vtbl->ByteIn (pUnk, 100);
2886 hr = pUnk->vtbl->ShortIn (pUnk, -100);
2889 hr = pUnk->vtbl->UShortIn (pUnk, 100);
2892 hr = pUnk->vtbl->IntIn (pUnk, -100);
2895 hr = pUnk->vtbl->UIntIn (pUnk, 100);
2898 hr = pUnk->vtbl->LongIn (pUnk, -100);
2901 hr = pUnk->vtbl->ULongIn (pUnk, 100);
2904 hr = pUnk->vtbl->FloatIn (pUnk, 3.14f);
2907 hr = pUnk->vtbl->DoubleIn (pUnk, 3.14);
2910 hr = pUnk->vtbl->ITestIn (pUnk, pUnk);
2913 hr = pUnk->vtbl->ITestOut (pUnk, &pTest);
2925 * mono_method_get_unmanaged_thunk tests
2928 #if defined(__GNUC__) && defined(__i386__) && (defined(__linux__) || defined (__APPLE__))
2929 #define ALIGN(size) __attribute__ ((aligned(size)))
2935 /* thunks.cs:TestStruct */
2936 typedef struct _TestStruct {
2938 double B ALIGN(8); /* align according to mono's struct layout */
2941 /* Searches for mono symbols in all loaded modules */
2943 lookup_mono_symbol (char *symbol_name)
2946 if (g_module_symbol (g_module_open (NULL, G_MODULE_BIND_LAZY), symbol_name, &symbol))
2953 * test_method_thunk:
2955 * @test_id: the test number
2956 * @test_method_handle: MonoMethod* of the C# test method
2957 * @create_object_method_handle: MonoMethod* of thunks.cs:Test.CreateObject
2959 LIBTEST_API int STDCALL
2960 test_method_thunk (int test_id, gpointer test_method_handle, gpointer create_object_method_handle)
2962 gpointer (*mono_method_get_unmanaged_thunk)(gpointer)
2963 = lookup_mono_symbol ("mono_method_get_unmanaged_thunk");
2965 gpointer (*mono_string_new_wrapper)(char *)
2966 = lookup_mono_symbol ("mono_string_new_wrapper");
2968 char* (*mono_string_to_utf8)(gpointer)
2969 = lookup_mono_symbol ("mono_string_to_utf8");
2971 gpointer (*mono_object_unbox)(gpointer)
2972 = lookup_mono_symbol ("mono_object_unbox");
2974 gpointer test_method, ex = NULL;
2975 gpointer (STDCALL *CreateObject)(gpointer*);
2978 if (!mono_method_get_unmanaged_thunk)
2981 test_method = mono_method_get_unmanaged_thunk (test_method_handle);
2985 CreateObject = mono_method_get_unmanaged_thunk (create_object_method_handle);
2993 /* thunks.cs:Test.Test0 */
2994 void (STDCALL *F)(gpointer*) = test_method;
3000 /* thunks.cs:Test.Test1 */
3001 int (STDCALL *F)(gpointer*) = test_method;
3008 /* thunks.cs:Test.Test2 */
3009 gpointer (STDCALL *F)(gpointer, gpointer*) = test_method;
3010 gpointer str = mono_string_new_wrapper ("foo");
3011 if (str != F (str, &ex))
3017 /* thunks.cs:Test.Test3 */
3018 gpointer (STDCALL *F)(gpointer, gpointer, gpointer*);
3023 obj = CreateObject (&ex);
3024 str = mono_string_new_wrapper ("bar");
3026 if (str != F (obj, str, &ex))
3032 /* thunks.cs:Test.Test4 */
3033 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3038 obj = CreateObject (&ex);
3039 str = mono_string_new_wrapper ("bar");
3041 if (42 != F (obj, str, 42, &ex))
3048 /* thunks.cs:Test.Test5 */
3049 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3054 obj = CreateObject (&ex);
3055 str = mono_string_new_wrapper ("bar");
3057 F (obj, str, 42, &ex);
3065 /* thunks.cs:Test.Test6 */
3066 int (STDCALL *F)(gpointer, guint8, gint16, gint32, gint64, float, double,
3067 gpointer, gpointer*);
3069 gpointer str = mono_string_new_wrapper ("Test6");
3073 obj = CreateObject (&ex);
3075 res = F (obj, 254, 32700, -245378, 6789600, 3.1415, 3.1415, str, &ex);
3086 /* thunks.cs:Test.Test7 */
3087 gint64 (STDCALL *F)(gpointer*) = test_method;
3088 if (F (&ex) != G_MAXINT64)
3094 /* thunks.cs:Test.Test8 */
3095 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3096 gpointer*, gpointer*);
3108 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3116 (fabs (a5 - 3.1415) < 0.001) &&
3117 (fabs (a6 - 3.1415) < 0.001) &&
3118 strcmp (mono_string_to_utf8 (a7), "Test8") == 0))
3125 /* thunks.cs:Test.Test9 */
3126 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3127 gpointer*, gpointer*);
3139 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3147 /* thunks.cs:Test.Test10 */
3148 void (STDCALL *F)(gpointer*, gpointer*);
3150 gpointer obj1, obj2;
3152 obj1 = obj2 = CreateObject (&ex);
3169 /* thunks.cs:TestStruct.Test0 */
3170 int (STDCALL *F)(gpointer*, gpointer*);
3176 obj = CreateObject (&ex);
3183 a1 = mono_object_unbox (obj);
3199 /* check whether the call was really by value */
3200 if (a1->A != 42 || a1->B != 3.1415)
3207 /* thunks.cs:TestStruct.Test1 */
3208 void (STDCALL *F)(gpointer, gpointer*);
3213 obj = CreateObject (&ex);
3220 a1 = mono_object_unbox (obj);
3233 if (!fabs (a1->B - 3.1415) < 0.001)
3240 /* thunks.cs:TestStruct.Test2 */
3241 gpointer (STDCALL *F)(gpointer*);
3255 a1 = mono_object_unbox (obj);
3260 if (!fabs (a1->B - 3.1415) < 0.001)
3267 /* thunks.cs:TestStruct.Test3 */
3268 void (STDCALL *F)(gpointer, gpointer*);
3273 obj = CreateObject (&ex);
3280 a1 = mono_object_unbox (obj);
3316 LIBTEST_API int STDCALL
3317 mono_test_Winx64_struct1_in (winx64_struct1 var)
3330 LIBTEST_API int STDCALL
3331 mono_test_Winx64_struct2_in (winx64_struct2 var)
3348 LIBTEST_API int STDCALL
3349 mono_test_Winx64_struct3_in (winx64_struct3 var)
3355 if (var.c != 0x1234)
3368 LIBTEST_API int STDCALL
3369 mono_test_Winx64_struct4_in (winx64_struct4 var)
3375 if (var.c != 0x1234)
3377 if (var.d != 0x87654321)
3389 LIBTEST_API int STDCALL
3390 mono_test_Winx64_struct5_in (winx64_struct5 var)
3408 LIBTEST_API int STDCALL
3409 mono_test_Winx64_struct6_in (winx64_struct6 var)
3420 LIBTEST_API int STDCALL
3421 mono_test_Winx64_structs_in1 (winx64_struct1 var1,
3422 winx64_struct2 var2,
3423 winx64_struct3 var3,
3424 winx64_struct4 var4)
3438 if (var3.c != 0x1234)
3445 if (var4.c != 0x1234)
3447 if (var4.d != 0x87654321)
3452 LIBTEST_API int STDCALL
3453 mono_test_Winx64_structs_in2 (winx64_struct1 var1,
3454 winx64_struct1 var2,
3455 winx64_struct1 var3,
3456 winx64_struct1 var4,
3457 winx64_struct1 var5)
3473 LIBTEST_API int STDCALL
3474 mono_test_Winx64_structs_in3 (winx64_struct1 var1,
3475 winx64_struct5 var2,
3476 winx64_struct1 var3,
3477 winx64_struct5 var4,
3478 winx64_struct1 var5,
3479 winx64_struct5 var6)
3514 LIBTEST_API winx64_struct1 STDCALL
3515 mono_test_Winx64_struct1_ret ()
3522 LIBTEST_API winx64_struct2 STDCALL
3523 mono_test_Winx64_struct2_ret ()
3531 LIBTEST_API winx64_struct3 STDCALL
3532 mono_test_Winx64_struct3_ret ()
3541 LIBTEST_API winx64_struct4 STDCALL
3542 mono_test_Winx64_struct4_ret ()
3552 LIBTEST_API winx64_struct5 STDCALL
3553 mono_test_Winx64_struct5_ret ()
3566 } winx64_floatStruct;
3568 LIBTEST_API int STDCALL
3569 mono_test_Winx64_floatStruct (winx64_floatStruct a)
3571 if (a.a > 5.6 || a.a < 5.4)
3574 if (a.b > 9.6 || a.b < 9.4)
3583 } winx64_doubleStruct;
3585 LIBTEST_API int STDCALL
3586 mono_test_Winx64_doubleStruct (winx64_doubleStruct a)
3588 if (a.a > 5.6 || a.a < 5.4)
3594 typedef int (STDCALL *managed_struct1_delegate) (winx64_struct1 a);
3596 LIBTEST_API int STDCALL
3597 mono_test_managed_Winx64_struct1_in(managed_struct1_delegate func)