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);
112 LIBTEST_API float STDCALL
113 mono_test_marshal_pass_return_float (float f) {
122 LIBTEST_API int STDCALL
123 mono_return_int_ss (struct ss a) {
124 // printf ("Got value %d\n", a.i);
128 LIBTEST_API struct ss STDCALL
129 mono_return_ss (struct ss a) {
130 // printf ("Got value %d\n", a.i);
140 LIBTEST_API struct sc1 STDCALL
141 mono_return_sc1 (struct sc1 a) {
142 // printf ("Got value %d\n", a.c[0]);
153 LIBTEST_API struct sc3 STDCALL
154 mono_return_sc3 (struct sc3 a) {
155 // printf ("Got values %d %d %d\n", a.c[0], a.c[1], a.c[2]);
167 LIBTEST_API struct sc5 STDCALL
168 mono_return_sc5 (struct sc5 a) {
169 // printf ("Got values %d %d %d %d %d\n", a.c[0], a.c[1], a.c[2], a.c[3], a.c[4]);
184 LIBTEST_API int STDCALL
185 mono_return_int_su (union su a) {
186 // printf ("Got value %d\n", a.i1);
190 LIBTEST_API int STDCALL
191 mono_test_many_int_arguments (int a, int b, int c, int d, int e,
192 int f, int g, int h, int i, int j);
193 LIBTEST_API short STDCALL
194 mono_test_many_short_arguments (short a, short b, short c, short d, short e,
195 short f, short g, short h, short i, short j);
196 LIBTEST_API char STDCALL
197 mono_test_many_char_arguments (char a, char b, char c, char d, char e,
198 char f, char g, char h, char i, char j);
200 LIBTEST_API int STDCALL
201 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)
203 return a + b + c + d + e + f + g + h + i + j;
206 LIBTEST_API short STDCALL
207 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)
209 return a + b + c + d + e + f + g + h + i + j;
212 LIBTEST_API char STDCALL
213 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)
215 return a + b + c + d + e + f + g + h + i + j;
218 LIBTEST_API float STDCALL
219 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)
221 return a + b + c + d + e + f + g + h + i + j;
224 LIBTEST_API double STDCALL
225 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)
227 return a + b + c + d + e + f + g + h + i + j;
230 LIBTEST_API double STDCALL
231 mono_test_split_double_arguments (double a, double b, float c, double d, double e)
233 return a + b + c + d + e;
236 LIBTEST_API int STDCALL
237 mono_test_puts_static (char *s)
239 // printf ("TEST %s\n", s);
243 typedef int (STDCALL *SimpleDelegate3) (int a, int b);
245 LIBTEST_API int STDCALL
246 mono_invoke_delegate (SimpleDelegate3 delegate)
250 // printf ("start invoke %p\n", delegate);
252 res = delegate (2, 3);
254 // printf ("end invoke\n");
259 LIBTEST_API int STDCALL
260 mono_test_marshal_char (short a1)
268 LIBTEST_API void STDCALL
269 mono_test_marshal_char_array (gunichar2 *s)
271 const char m[] = "abcdef";
275 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
283 LIBTEST_API int STDCALL
284 mono_test_empty_pinvoke (int i)
289 LIBTEST_API int STDCALL
290 mono_test_marshal_bool_byref (int a, int *b, int c)
299 LIBTEST_API int STDCALL
300 mono_test_marshal_bool_in_as_I1_U1 (char bTrue, char bFalse)
309 LIBTEST_API int STDCALL
310 mono_test_marshal_bool_out_as_I1_U1 (char* bTrue, char* bFalse)
312 if (!bTrue || !bFalse)
321 LIBTEST_API int STDCALL
322 mono_test_marshal_bool_ref_as_I1_U1 (char* bTrue, char* bFalse)
324 if (!bTrue || !bFalse)
338 LIBTEST_API int STDCALL
339 mono_test_marshal_array (int *a1)
343 for (i = 0; i < 50; i++)
349 LIBTEST_API int STDCALL
350 mono_test_marshal_inout_array (int *a1)
354 for (i = 0; i < 50; i++) {
356 a1 [i] = 50 - a1 [i];
362 LIBTEST_API int STDCALL
363 mono_test_marshal_out_array (int *a1)
367 for (i = 0; i < 50; i++) {
374 LIBTEST_API int STDCALL
375 mono_test_marshal_inout_nonblittable_array (gunichar2 *a1)
379 for (i = 0; i < 10; i++) {
399 LIBTEST_API simplestruct STDCALL
400 mono_test_return_vtype (int i)
403 static gunichar2 test2 [] = { 'T', 'E', 'S', 'T', '2', 0 };
414 LIBTEST_API void STDCALL
415 mono_test_delegate_struct (void)
417 // printf ("TEST\n");
420 typedef char* (STDCALL *ReturnStringDelegate) (const char *s);
422 LIBTEST_API char * STDCALL
423 mono_test_return_string (ReturnStringDelegate func)
427 // printf ("mono_test_return_string\n");
432 // printf ("got string: %s\n", res);
433 return g_strdup ("12345");
436 typedef int (STDCALL *RefVTypeDelegate) (int a, simplestruct *ss, int b);
438 LIBTEST_API int STDCALL
439 mono_test_ref_vtype (int a, simplestruct *ss, int b, RefVTypeDelegate func)
441 if (a == 1 && b == 2 && ss->a == 0 && ss->b == 1 && ss->c == 0 &&
442 !strcmp (ss->d, "TEST1")) {
448 return func (a, ss, b);
454 typedef int (STDCALL *OutVTypeDelegate) (int a, simplestruct *ss, int b);
456 LIBTEST_API int STDCALL
457 mono_test_marshal_out_struct (int a, simplestruct *ss, int b, OutVTypeDelegate func)
459 /* Check that the input pointer is ignored */
460 ss->d = (gpointer)0x12345678;
464 if (ss->a && ss->b && ss->c && !strcmp (ss->d, "TEST3"))
472 SimpleDelegate func, func2;
475 LIBTEST_API DelegateStruct STDCALL
476 mono_test_marshal_delegate_struct (DelegateStruct ds)
480 res.a = ds.func (ds.a) + ds.func2 (ds.a);
482 res.func2 = ds.func2;
487 LIBTEST_API int STDCALL
488 mono_test_marshal_struct (simplestruct ss)
490 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
491 !strcmp (ss.d, "TEST"))
497 LIBTEST_API int STDCALL
498 mono_test_marshal_byref_struct (simplestruct *ss, int a, int b, int c, char *d)
500 gboolean res = (ss->a == a && ss->b == b && ss->c == c && strcmp (ss->d, d) == 0);
502 marshal_free ((char*)ss->d);
507 ss->d = g_strdup ("DEF");
523 LIBTEST_API int STDCALL
524 mono_test_marshal_struct2 (simplestruct2 ss)
526 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
527 !strcmp (ss.d, "TEST") &&
528 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
534 /* on HP some of the struct should be on the stack and not in registers */
535 LIBTEST_API int STDCALL
536 mono_test_marshal_struct2_2 (int i, int j, int k, simplestruct2 ss)
538 if (i != 10 || j != 11 || k != 12)
540 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
541 !strcmp (ss.d, "TEST") &&
542 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
548 LIBTEST_API int STDCALL
549 mono_test_marshal_lpstruct (simplestruct *ss)
551 if (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
552 !strcmp (ss->d, "TEST"))
558 LIBTEST_API int STDCALL
559 mono_test_marshal_lpstruct_blittable (point *p)
561 if (p->x == 1.0 && p->y == 2.0)
567 LIBTEST_API int STDCALL
568 mono_test_marshal_struct_array (simplestruct2 *ss)
570 if (! (ss[0].a == 0 && ss[0].b == 1 && ss[0].c == 0 &&
571 !strcmp (ss[0].d, "TEST") &&
572 ss[0].e == 99 && ss[0].f == 1.5 && ss[0].g == 42 && ss[0].h == (guint64)123))
575 if (! (ss[1].a == 0 && ss[1].b == 0 && ss[1].c == 0 &&
576 !strcmp (ss[1].d, "TEST2") &&
577 ss[1].e == 100 && ss[1].f == 2.5 && ss[1].g == 43 && ss[1].h == (guint64)124))
583 typedef struct long_align_struct {
589 LIBTEST_API int STDCALL
590 mono_test_marshal_long_align_struct_array (long_align_struct *ss)
592 return ss[0].a + ss[0].b + ss[0].c + ss[1].a + ss[1].b + ss[1].c;
595 LIBTEST_API simplestruct2 * STDCALL
596 mono_test_marshal_class (int i, int j, int k, simplestruct2 *ss, int l)
603 if (i != 10 || j != 11 || k != 12 || l != 14)
605 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
606 !strcmp (ss->d, "TEST") &&
607 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
610 res = g_new0 (simplestruct2, 1);
611 memcpy (res, ss, sizeof (simplestruct2));
612 res->d = g_strdup ("TEST");
616 LIBTEST_API int STDCALL
617 mono_test_marshal_byref_class (simplestruct2 **ssp)
619 simplestruct2 *ss = *ssp;
622 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
623 !strcmp (ss->d, "TEST") &&
624 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
627 res = g_new0 (simplestruct2, 1);
628 memcpy (res, ss, sizeof (simplestruct2));
629 res->d = g_strdup ("TEST-RES");
641 /* Yes, this is correct, we are only trying to determine the value of the stack here */
646 LIBTEST_API int STDCALL
647 reliable_delegate (int a)
653 * Checks whether get_sp() works as expected. It doesn't work with gcc-2.95.3 on linux.
656 is_get_sp_reliable (void)
660 reliable_delegate(1);
662 reliable_delegate(1);
667 LIBTEST_API int STDCALL
668 mono_test_marshal_delegate (SimpleDelegate delegate)
672 /* Check that the delegate wrapper is stdcall */
677 if (is_get_sp_reliable())
678 g_assert (sp1 == sp2);
683 static int STDCALL inc_cb (int i)
688 LIBTEST_API int STDCALL
689 mono_test_marshal_out_delegate (SimpleDelegate *delegate)
696 LIBTEST_API SimpleDelegate STDCALL
697 mono_test_marshal_return_delegate (SimpleDelegate delegate)
703 return_plus_one (int i)
708 LIBTEST_API SimpleDelegate STDCALL
709 mono_test_marshal_return_delegate_2 (void)
711 return return_plus_one;
714 typedef simplestruct (STDCALL *SimpleDelegate2) (simplestruct ss);
717 is_utf16_equals (gunichar2 *s1, const char *s2)
722 s = g_utf16_to_utf8 (s1, -1, NULL, NULL, NULL);
723 res = strcmp (s, s2);
729 LIBTEST_API int STDCALL
730 mono_test_marshal_delegate2 (SimpleDelegate2 delegate)
732 simplestruct ss, res;
738 ss.d2 = g_utf8_to_utf16 ("TEST2", -1, NULL, NULL, NULL);
741 if (! (res.a && !res.b && res.c && !strcmp (res.d, "TEST-RES") && is_utf16_equals (res.d2, "TEST2-RES")))
747 typedef simplestruct* (STDCALL *SimpleDelegate4) (simplestruct *ss);
749 LIBTEST_API int STDCALL
750 mono_test_marshal_delegate4 (SimpleDelegate4 delegate)
761 res = delegate (&ss);
765 /* Check return value */
766 if (! (!res->a && res->b && !res->c && !strcmp (res->d, "TEST")))
769 /* Check NULL argument and NULL result */
770 res = delegate (NULL);
777 typedef int (STDCALL *SimpleDelegate5) (simplestruct **ss);
779 LIBTEST_API int STDCALL
780 mono_test_marshal_delegate5 (SimpleDelegate5 delegate)
793 res = delegate (&ptr);
797 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
803 LIBTEST_API int STDCALL
804 mono_test_marshal_delegate6 (SimpleDelegate5 delegate)
808 res = delegate (NULL);
813 typedef int (STDCALL *SimpleDelegate7) (simplestruct **ss);
815 LIBTEST_API int STDCALL
816 mono_test_marshal_delegate7 (SimpleDelegate7 delegate)
821 /* Check that the input pointer is ignored */
822 ptr = (gpointer)0x12345678;
824 res = delegate (&ptr);
828 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
834 typedef int (STDCALL *InOutByvalClassDelegate) (simplestruct *ss);
836 LIBTEST_API int STDCALL
837 mono_test_marshal_inout_byval_class_delegate (InOutByvalClassDelegate delegate)
845 ss.d = g_strdup_printf ("%s", "FOO");
847 res = delegate (&ss);
851 if (!(ss.a && !ss.b && ss.c && !strcmp (ss.d, "RES")))
857 typedef int (STDCALL *SimpleDelegate8) (gunichar2 *s);
859 LIBTEST_API int STDCALL
860 mono_test_marshal_delegate8 (SimpleDelegate8 delegate, gunichar2 *s)
865 typedef int (STDCALL *return_int_fnt) (int i);
866 typedef int (STDCALL *SimpleDelegate9) (return_int_fnt d);
868 LIBTEST_API int STDCALL
869 mono_test_marshal_delegate9 (SimpleDelegate9 delegate, gpointer ftn)
871 return delegate (ftn);
880 LIBTEST_API int STDCALL
881 mono_test_marshal_delegate10 (SimpleDelegate9 delegate)
883 return delegate (return_self);
886 typedef int (STDCALL *PrimitiveByrefDelegate) (int *i);
888 LIBTEST_API int STDCALL
889 mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate delegate)
893 int res = delegate (&i);
903 typedef int (STDCALL *return_int_delegate) (int i);
905 typedef return_int_delegate (STDCALL *ReturnDelegateDelegate) (void);
907 LIBTEST_API int STDCALL
908 mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d)
913 LIBTEST_API int STDCALL
914 mono_test_marshal_stringbuilder (char *s, int n)
916 const char m[] = "This is my message. Isn't it nice?";
918 if (strcmp (s, "ABCD") != 0)
925 LIBTEST_API int STDCALL
926 mono_test_marshal_stringbuilder_default (char *s, int n)
928 const char m[] = "This is my message. Isn't it nice?";
935 LIBTEST_API int STDCALL
936 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
938 const char m[] = "This is my message. Isn't it nice?";
942 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
960 LIBTEST_API int STDCALL
961 mono_test_marshal_empty_string_array (char **array)
963 return (array == NULL) ? 0 : 1;
966 LIBTEST_API int STDCALL
967 mono_test_marshal_string_array (char **array)
969 if (strcmp (array [0], "ABC"))
971 if (strcmp (array [1], "DEF"))
974 if (array [2] != NULL)
980 LIBTEST_API int STDCALL
981 mono_test_marshal_byref_string_array (char ***array)
986 if (strcmp ((*array) [0], "Alpha"))
988 if (strcmp ((*array) [1], "Beta"))
990 if (strcmp ((*array) [2], "Gamma"))
996 LIBTEST_API int STDCALL
997 mono_test_marshal_stringbuilder_array (char **array)
999 if (strcmp (array [0], "ABC"))
1001 if (strcmp (array [1], "DEF"))
1004 strcpy (array [0], "DEF");
1005 strcpy (array [1], "ABC");
1010 LIBTEST_API int STDCALL
1011 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
1013 GError *error = NULL;
1016 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
1017 if (strcmp (s, "ABC")) {
1024 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
1025 if (strcmp (s, "DEF")) {
1032 if (strcmp (array2 [0], "ABC"))
1035 if (strcmp (array2 [1], "DEF"))
1041 /* this does not work on Redhat gcc 2.96 */
1042 LIBTEST_API int STDCALL
1043 mono_test_empty_struct (int a, EmptyStruct es, int b)
1045 // printf ("mono_test_empty_struct %d %d\n", a, b);
1047 // Intel icc on ia64 passes 'es' in 2 registers
1048 #if defined(__ia64) && defined(__INTEL_COMPILER)
1051 if (a == 1 && b == 2)
1061 LIBTEST_API ByValStrStruct * STDCALL
1062 mono_test_byvalstr_gen (void)
1064 ByValStrStruct *ret;
1066 ret = malloc(sizeof(ByValStrStruct));
1067 memset(ret, 'a', sizeof(ByValStrStruct)-1);
1068 ret->a[sizeof(ByValStrStruct)-1] = 0;
1073 LIBTEST_API int STDCALL
1074 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
1078 ret = strcmp(data->a, correctString);
1079 // printf ("T1: %s\n", data->a);
1080 // printf ("T2: %s\n", correctString);
1082 marshal_free (data);
1089 } ByValStrStruct_Unicode;
1091 LIBTEST_API int STDCALL
1092 mono_test_byvalstr_check_unicode (ByValStrStruct_Unicode *ref, int test)
1094 if (ref->flag != 0x1234abcd){
1095 printf ("overwritten data");
1099 if (test == 1 || test == 3){
1100 if (ref->a [0] != '1' ||
1101 ref->a [1] != '2' ||
1107 if (ref->a [0] != '1' ||
1115 LIBTEST_API int STDCALL
1116 NameManglingAnsi (char *data)
1118 return data [0] + data [1] + data [2];
1121 LIBTEST_API int STDCALL
1122 NameManglingAnsiA (char *data)
1124 g_assert_not_reached ();
1127 LIBTEST_API int STDCALL
1128 NameManglingAnsiW (char *data)
1130 g_assert_not_reached ();
1133 LIBTEST_API int STDCALL
1134 NameManglingAnsi2A (char *data)
1136 return data [0] + data [1] + data [2];
1139 LIBTEST_API int STDCALL
1140 NameManglingAnsi2W (char *data)
1142 g_assert_not_reached ();
1145 LIBTEST_API int STDCALL
1146 NameManglingUnicode (char *data)
1148 g_assert_not_reached ();
1151 LIBTEST_API int STDCALL
1152 NameManglingUnicodeW (gunichar2 *data)
1154 return data [0] + data [1] + data [2];
1157 LIBTEST_API int STDCALL
1158 NameManglingUnicode2 (gunichar2 *data)
1160 return data [0] + data [1] + data [2];
1163 LIBTEST_API int STDCALL
1164 NameManglingAutoW (char *data)
1167 return (data [0] + data [1] + data [2]) == 131 ? 0 : 1;
1169 g_assert_not_reached ();
1173 LIBTEST_API int STDCALL
1174 NameManglingAuto (char *data)
1177 return (data [0] + data [1] + data [2]) == 198 ? 0 : 1;
1179 g_assert_not_reached ();
1183 typedef int (STDCALL *intcharFunc)(const char*);
1185 LIBTEST_API void STDCALL
1186 callFunction (intcharFunc f)
1196 LIBTEST_API int STDCALL
1197 class_marshal_test0 (SimpleObj *obj1)
1199 // printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
1201 if (strcmp(obj1->str, "T1"))
1209 LIBTEST_API int STDCALL
1210 class_marshal_test4 (SimpleObj *obj1)
1218 LIBTEST_API void STDCALL
1219 class_marshal_test1 (SimpleObj **obj1)
1221 SimpleObj *res = malloc (sizeof (SimpleObj));
1223 res->str = g_strdup ("ABC");
1229 LIBTEST_API int STDCALL
1230 class_marshal_test2 (SimpleObj **obj1)
1232 // printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
1234 if (strcmp((*obj1)->str, "ABC"))
1236 if ((*obj1)->i != 5)
1242 LIBTEST_API int STDCALL
1243 string_marshal_test0 (char *str)
1245 if (strcmp (str, "TEST0"))
1251 LIBTEST_API void STDCALL
1252 string_marshal_test1 (const char **str)
1254 *str = g_strdup ("TEST1");
1257 LIBTEST_API int STDCALL
1258 string_marshal_test2 (char **str)
1260 // printf ("string_marshal_test2 %s\n", *str);
1262 if (strcmp (*str, "TEST1"))
1268 LIBTEST_API int STDCALL
1269 string_marshal_test3 (char *str)
1282 LIBTEST_API BlittableClass* STDCALL
1283 TestBlittableClass (BlittableClass *vl)
1285 BlittableClass *res;
1287 // printf ("TestBlittableClass %d %d\n", vl->a, vl->b);
1293 res = g_new0 (BlittableClass, 1);
1294 memcpy (res, vl, sizeof (BlittableClass));
1296 res = g_new0 (BlittableClass, 1);
1304 typedef struct OSVERSIONINFO_STRUCT
1308 } OSVERSIONINFO_STRUCT;
1310 LIBTEST_API int STDCALL
1311 MyGetVersionEx (OSVERSIONINFO_STRUCT *osvi)
1314 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1319 return osvi->a + osvi->b;
1322 LIBTEST_API int STDCALL
1323 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO_STRUCT *osvi)
1326 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1331 return osvi->a + osvi->b;
1334 LIBTEST_API int STDCALL
1335 mono_test_marshal_point (point pt)
1337 // printf("point %g %g\n", pt.x, pt.y);
1338 if (pt.x == 1.25 && pt.y == 3.5)
1349 LIBTEST_API int STDCALL
1350 mono_test_marshal_mixed_point (mixed_point pt)
1352 // printf("mixed point %d %g\n", pt.x, pt.y);
1353 if (pt.x == 5 && pt.y == 6.75)
1359 LIBTEST_API int STDCALL
1360 mono_test_marshal_mixed_point_2 (mixed_point *pt)
1362 if (pt->x != 5 || pt->y != 6.75)
1371 LIBTEST_API int STDCALL
1372 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
1375 if (*b1 != 0 && *b1 != 1)
1377 if (*b2 != 0 && *b2 != -1) /* variant_bool */
1379 if (*b3 != 0 && *b3 != 1)
1381 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
1393 short b2; /* variant_bool */
1397 LIBTEST_API int STDCALL
1398 marshal_test_bool_struct(struct BoolStruct *s)
1401 if (s->b1 != 0 && s->b1 != 1)
1403 if (s->b2 != 0 && s->b2 != -1)
1405 if (s->b3 != 0 && s->b3 != 1)
1407 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1424 LIBTEST_API int STDCALL
1425 mono_test_marshal_long_struct (LongStruct *s)
1427 return s->i + s->l.l;
1430 LIBTEST_API void STDCALL
1431 mono_test_last_error (int err)
1440 LIBTEST_API int STDCALL
1441 mono_test_asany (void *ptr, int what)
1445 return (*(int*)ptr == 5) ? 0 : 1;
1447 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1449 simplestruct2 ss = *(simplestruct2*)ptr;
1451 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1452 !strcmp (ss.d, "TEST") &&
1453 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1459 GError *error = NULL;
1462 s = g_utf16_to_utf8 (ptr, -1, NULL, NULL, &error);
1463 if (!strcmp (s, "ABC")) {
1473 g_assert_not_reached ();
1487 LIBTEST_API int STDCALL
1488 mono_test_marshal_asany_in (void* ptr)
1490 AsAnyStruct* asAny = ptr;
1491 int res = asAny->i + asAny->j + asAny->k;
1496 LIBTEST_API int STDCALL
1497 mono_test_marshal_asany_inout (void* ptr)
1499 AsAnyStruct* asAny = ptr;
1500 int res = asAny->i + asAny->j + asAny->k;
1502 marshal_free (asAny->s);
1512 LIBTEST_API int STDCALL
1513 mono_test_marshal_asany_out (void* ptr)
1515 AsAnyStruct* asAny = ptr;
1516 int res = asAny->i + asAny->j + asAny->k;
1527 * AMD64 marshalling tests.
1530 typedef struct amd64_struct1 {
1537 LIBTEST_API amd64_struct1 STDCALL
1538 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
1548 LIBTEST_API amd64_struct1 STDCALL
1549 mono_test_marshal_amd64_pass_return_struct1_many_args (amd64_struct1 s, int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8)
1554 s.l += 1 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8;
1559 typedef struct amd64_struct2 {
1564 LIBTEST_API amd64_struct2 STDCALL
1565 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
1573 typedef struct amd64_struct3 {
1577 LIBTEST_API amd64_struct3 STDCALL
1578 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s)
1585 typedef struct amd64_struct4 {
1589 LIBTEST_API amd64_struct4 STDCALL
1590 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s)
1599 * IA64 marshalling tests.
1601 typedef struct test_struct5 {
1605 LIBTEST_API test_struct5 STDCALL
1606 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, test_struct5 s, int i, double d3, double d4)
1608 s.d1 += d1 + d2 + i;
1609 s.d2 += d3 + d4 + i;
1614 typedef struct test_struct6 {
1618 LIBTEST_API test_struct6 STDCALL
1619 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, test_struct6 s, int i, double d3, double d4)
1621 s.d1 += d1 + d2 + i;
1627 static guint32 custom_res [2];
1629 LIBTEST_API void* STDCALL
1630 mono_test_marshal_pass_return_custom (int i, guint32 *ptr, int j)
1632 /* ptr will be freed by CleanupNative, so make a copy */
1633 custom_res [0] = 0; /* not allocated by AllocHGlobal */
1634 custom_res [1] = ptr [1];
1639 LIBTEST_API int STDCALL
1640 mono_test_marshal_pass_out_custom (int i, guint32 **ptr, int j)
1643 custom_res [1] = i + j + 10;
1650 LIBTEST_API int STDCALL
1651 mono_test_marshal_pass_inout_custom (int i, guint32 *ptr, int j)
1654 ptr [1] = i + ptr [1] + j;
1659 LIBTEST_API int STDCALL
1660 mono_test_marshal_pass_out_byval_custom (int i, guint32 *ptr, int j)
1662 return ptr == NULL ? 0 : 1;
1665 LIBTEST_API int STDCALL
1666 mono_test_marshal_pass_byref_custom (int i, guint32 **ptr, int j)
1673 LIBTEST_API void* STDCALL
1674 mono_test_marshal_pass_return_custom2 (int i, guint32 *ptr, int j)
1676 g_assert_not_reached ();
1681 LIBTEST_API void* STDCALL
1682 mono_test_marshal_pass_return_custom_null (int i, guint32 *ptr, int j)
1684 g_assert (ptr == NULL);
1689 typedef void *(STDCALL *PassReturnPtrDelegate) (void *ptr);
1691 LIBTEST_API int STDCALL
1692 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del)
1706 /* FIXME: Freed with FreeHGlobal */
1714 LIBTEST_API int STDCALL
1715 mono_test_marshal_pass_return_custom_null_in_delegate (PassReturnPtrDelegate del)
1717 void *ptr = del (NULL);
1719 return (ptr == NULL) ? 15 : 0;
1722 typedef void (STDCALL *CustomOutParamDelegate) (void **pptr);
1724 LIBTEST_API int STDCALL
1725 mono_test_marshal_custom_out_param_delegate (CustomOutParamDelegate del)
1737 typedef int (STDCALL *ReturnEnumDelegate) (int e);
1739 LIBTEST_API int STDCALL
1740 mono_test_marshal_return_enum_delegate (ReturnEnumDelegate func)
1750 typedef BlittableStruct (STDCALL *SimpleDelegate10) (BlittableStruct ss);
1752 LIBTEST_API int STDCALL
1753 mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 delegate)
1755 BlittableStruct ss, res;
1762 res = delegate (ss);
1763 if (! ((res.a == -1) && (res.b == -2) && (res.c == -3) && (res.d == -55)))
1769 LIBTEST_API int STDCALL
1770 mono_test_stdcall_name_mangling (int a, int b, int c)
1776 * PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
1783 typedef SmallStruct1 (STDCALL *SmallStructDelegate1) (SmallStruct1 ss);
1785 LIBTEST_API int STDCALL
1786 mono_test_marshal_small_struct_delegate1 (SmallStructDelegate1 delegate)
1788 SmallStruct1 ss, res;
1792 res = delegate (ss);
1793 if (! (res.i == -1))
1803 typedef SmallStruct2 (STDCALL *SmallStructDelegate2) (SmallStruct2 ss);
1805 LIBTEST_API int STDCALL
1806 mono_test_marshal_small_struct_delegate2 (SmallStructDelegate2 delegate)
1808 SmallStruct2 ss, res;
1813 res = delegate (ss);
1814 if (! ((res.i == -2) && (res.j == -3)))
1825 typedef SmallStruct3 (STDCALL *SmallStructDelegate3) (SmallStruct3 ss);
1827 LIBTEST_API int STDCALL
1828 mono_test_marshal_small_struct_delegate3 (SmallStructDelegate3 delegate)
1830 SmallStruct3 ss, res;
1835 res = delegate (ss);
1836 if (! ((res.i == -1) && (res.j == -2)))
1846 typedef SmallStruct4 (STDCALL *SmallStructDelegate4) (SmallStruct4 ss);
1848 LIBTEST_API int STDCALL
1849 mono_test_marshal_small_struct_delegate4 (SmallStructDelegate4 delegate)
1851 SmallStruct4 ss, res;
1855 res = delegate (ss);
1856 if (! (res.i == -1))
1866 typedef SmallStruct5 (STDCALL *SmallStructDelegate5) (SmallStruct5 ss);
1868 LIBTEST_API int STDCALL
1869 mono_test_marshal_small_struct_delegate5 (SmallStructDelegate5 delegate)
1871 SmallStruct5 ss, res;
1875 res = delegate (ss);
1876 if (! (res.i == -5))
1886 typedef SmallStruct6 (STDCALL *SmallStructDelegate6) (SmallStruct6 ss);
1888 LIBTEST_API int STDCALL
1889 mono_test_marshal_small_struct_delegate6 (SmallStructDelegate6 delegate)
1891 SmallStruct6 ss, res;
1896 res = delegate (ss);
1897 if (! ((res.i == -1) && (res.j == -2)))
1908 typedef SmallStruct7 (STDCALL *SmallStructDelegate7) (SmallStruct7 ss);
1910 LIBTEST_API int STDCALL
1911 mono_test_marshal_small_struct_delegate7 (SmallStructDelegate7 delegate)
1913 SmallStruct7 ss, res;
1918 res = delegate (ss);
1919 if (! ((res.i == -1) && (res.j == -2)))
1929 typedef SmallStruct8 (STDCALL *SmallStructDelegate8) (SmallStruct8 ss);
1931 LIBTEST_API int STDCALL
1932 mono_test_marshal_small_struct_delegate8 (SmallStructDelegate8 delegate)
1934 SmallStruct8 ss, res;
1938 res = delegate (ss);
1939 if (! ((res.i == -1.0)))
1949 typedef SmallStruct9 (STDCALL *SmallStructDelegate9) (SmallStruct9 ss);
1951 LIBTEST_API int STDCALL
1952 mono_test_marshal_small_struct_delegate9 (SmallStructDelegate9 delegate)
1954 SmallStruct9 ss, res;
1958 res = delegate (ss);
1959 if (! ((res.i == -1.0)))
1969 typedef SmallStruct10 (STDCALL *SmallStructDelegate10) (SmallStruct10 ss);
1971 LIBTEST_API int STDCALL
1972 mono_test_marshal_small_struct_delegate10 (SmallStructDelegate10 delegate)
1974 SmallStruct10 ss, res;
1979 res = delegate (ss);
1980 if (! ((res.i == -1.0) && (res.j == -2.0)))
1991 typedef SmallStruct11 (STDCALL *SmallStructDelegate11) (SmallStruct11 ss);
1993 LIBTEST_API int STDCALL
1994 mono_test_marshal_small_struct_delegate11 (SmallStructDelegate11 delegate)
1996 SmallStruct11 ss, res;
2001 res = delegate (ss);
2002 if (! ((res.i == -1.0) && (res.j == -2)))
2008 typedef int (STDCALL *ArrayDelegate) (int i, char *j, void *arr);
2010 LIBTEST_API int STDCALL
2011 mono_test_marshal_array_delegate (void *arr, int len, ArrayDelegate del)
2013 return del (len, NULL, arr);
2016 LIBTEST_API int STDCALL
2017 mono_test_marshal_out_array_delegate (int *arr, int len, ArrayDelegate del)
2019 del (len, NULL, arr);
2021 if ((arr [0] != 1) || (arr [1] != 2))
2027 typedef gunichar2* (STDCALL *UnicodeStringDelegate) (gunichar2 *message);
2029 LIBTEST_API int STDCALL
2030 mono_test_marshal_return_unicode_string_delegate (UnicodeStringDelegate del)
2032 const char m[] = "abcdef";
2033 gunichar2 *s2, *res;
2036 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
2045 LIBTEST_API int STDCALL
2046 mono_test_marshal_out_string_array_delegate (char **arr, int len, ArrayDelegate del)
2048 del (len, NULL, arr);
2050 if (!strcmp (arr [0], "ABC") && !strcmp (arr [1], "DEF"))
2056 typedef int (*CdeclDelegate) (int i, int j);
2058 LIBTEST_API int STDCALL
2059 mono_test_marshal_cdecl_delegate (CdeclDelegate del)
2063 for (i = 0; i < 1000; ++i)
2069 typedef char** (STDCALL *ReturnStringArrayDelegate) (int i);
2071 LIBTEST_API int STDCALL
2072 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d)
2080 if (strcmp (arr [0], "ABC") || strcmp (arr [1], "DEF"))
2090 typedef int (STDCALL *ByrefStringDelegate) (char **s);
2092 LIBTEST_API int STDCALL
2093 mono_test_marshal_byref_string_delegate (ByrefStringDelegate d)
2095 char *s = (char*)"ABC";
2102 if (!strcmp (s, "DEF"))
2112 LIBTEST_API int STDCALL
2113 add_delegate (int i, int j)
2118 LIBTEST_API gpointer STDCALL
2119 mono_test_marshal_return_fnptr (void)
2121 return &add_delegate;
2124 LIBTEST_API int STDCALL
2127 printf ("codigo %x\n", code);
2135 LIBTEST_API HandleRef STDCALL
2136 mono_xr_as_handle (int code)
2140 memset (&ref, 0, sizeof (ref));
2152 LIBTEST_API int STDCALL
2153 mono_safe_handle_struct_ref (HandleStructs *x)
2155 printf ("Dingus Ref! \n");
2156 printf ("Values: %d %d %p %p\n", x->a, x->b, x->handle1, x->handle2);
2162 if (x->handle1 != (void*) 0x7080feed)
2165 if (x->handle2 != (void*) 0x1234abcd)
2171 LIBTEST_API int STDCALL
2172 mono_safe_handle_struct (HandleStructs x)
2174 printf ("Dingus Standard! \n");
2175 printf ("Values: %d %d %p %p\n", x.a, x.b, x.handle1, x.handle2);
2181 if (x.handle1 != (void*) 0x7080feed)
2184 if (x.handle2 != (void*) 0x1234abcd)
2194 LIBTEST_API int STDCALL
2195 mono_safe_handle_struct_simple (TrivialHandle x)
2197 printf ("The value is %p\n", x.a);
2198 return ((int)(gsize)x.a) * 2;
2201 LIBTEST_API int STDCALL
2202 mono_safe_handle_return (void)
2207 LIBTEST_API void STDCALL
2208 mono_safe_handle_ref (void **handle)
2211 *handle = (void *) 0xbad;
2215 *handle = (void *) 0x800d;
2223 LIBTEST_API int STDCALL
2224 mono_test_marshal_bstr_in(BSTR bstr)
2226 if (!wcscmp(bstr, L"mono_test_marshal_bstr_in"))
2231 LIBTEST_API int STDCALL
2232 mono_test_marshal_bstr_out(BSTR* bstr)
2234 *bstr = SysAllocString(L"mono_test_marshal_bstr_out");
2238 LIBTEST_API int STDCALL
2239 mono_test_marshal_bstr_in_null(BSTR bstr)
2246 LIBTEST_API int STDCALL
2247 mono_test_marshal_bstr_out_null(BSTR* bstr)
2253 LIBTEST_API int STDCALL
2254 mono_test_marshal_variant_in_sbyte(VARIANT variant)
2256 if (variant.vt == VT_I1 && variant.cVal == 100)
2261 LIBTEST_API int STDCALL
2262 mono_test_marshal_variant_in_byte(VARIANT variant)
2264 if (variant.vt == VT_UI1 && variant.bVal == 100)
2269 LIBTEST_API int STDCALL
2270 mono_test_marshal_variant_in_short(VARIANT variant)
2272 if (variant.vt == VT_I2 && variant.iVal == 314)
2277 LIBTEST_API int STDCALL
2278 mono_test_marshal_variant_in_ushort(VARIANT variant)
2280 if (variant.vt == VT_UI2 && variant.uiVal == 314)
2285 LIBTEST_API int STDCALL
2286 mono_test_marshal_variant_in_int(VARIANT variant)
2288 if (variant.vt == VT_I4 && variant.lVal == 314)
2293 LIBTEST_API int STDCALL
2294 mono_test_marshal_variant_in_uint(VARIANT variant)
2296 if (variant.vt == VT_UI4 && variant.ulVal == 314)
2301 LIBTEST_API int STDCALL
2302 mono_test_marshal_variant_in_long(VARIANT variant)
2304 if (variant.vt == VT_I8 && variant.llVal == 314)
2309 LIBTEST_API int STDCALL
2310 mono_test_marshal_variant_in_ulong(VARIANT variant)
2312 if (variant.vt == VT_UI8 && variant.ullVal == 314)
2317 LIBTEST_API int STDCALL
2318 mono_test_marshal_variant_in_float(VARIANT variant)
2320 if (variant.vt == VT_R4 && (variant.fltVal - 3.14)/3.14 < .001)
2325 LIBTEST_API int STDCALL
2326 mono_test_marshal_variant_in_double(VARIANT variant)
2328 if (variant.vt == VT_R8 && (variant.dblVal - 3.14)/3.14 < .001)
2333 LIBTEST_API int STDCALL
2334 mono_test_marshal_variant_in_bstr(VARIANT variant)
2336 if (variant.vt == VT_BSTR && !wcscmp(variant.bstrVal, L"PI"))
2341 LIBTEST_API int STDCALL
2342 mono_test_marshal_variant_in_bool_true (VARIANT variant)
2344 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_TRUE)
2349 LIBTEST_API int STDCALL
2350 mono_test_marshal_variant_in_bool_false (VARIANT variant)
2352 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_FALSE)
2357 LIBTEST_API int STDCALL
2358 mono_test_marshal_variant_out_sbyte(VARIANT* variant)
2360 variant->vt = VT_I1;
2361 variant->cVal = 100;
2366 LIBTEST_API int STDCALL
2367 mono_test_marshal_variant_out_byte(VARIANT* variant)
2369 variant->vt = VT_UI1;
2370 variant->bVal = 100;
2375 LIBTEST_API int STDCALL
2376 mono_test_marshal_variant_out_short(VARIANT* variant)
2378 variant->vt = VT_I2;
2379 variant->iVal = 314;
2384 LIBTEST_API int STDCALL
2385 mono_test_marshal_variant_out_ushort(VARIANT* variant)
2387 variant->vt = VT_UI2;
2388 variant->uiVal = 314;
2393 LIBTEST_API int STDCALL
2394 mono_test_marshal_variant_out_int(VARIANT* variant)
2396 variant->vt = VT_I4;
2397 variant->lVal = 314;
2402 LIBTEST_API int STDCALL
2403 mono_test_marshal_variant_out_uint(VARIANT* variant)
2405 variant->vt = VT_UI4;
2406 variant->ulVal = 314;
2411 LIBTEST_API int STDCALL
2412 mono_test_marshal_variant_out_long(VARIANT* variant)
2414 variant->vt = VT_I8;
2415 variant->llVal = 314;
2420 LIBTEST_API int STDCALL
2421 mono_test_marshal_variant_out_ulong(VARIANT* variant)
2423 variant->vt = VT_UI8;
2424 variant->ullVal = 314;
2429 LIBTEST_API int STDCALL
2430 mono_test_marshal_variant_out_float(VARIANT* variant)
2432 variant->vt = VT_R4;
2433 variant->fltVal = 3.14;
2438 LIBTEST_API int STDCALL
2439 mono_test_marshal_variant_out_double(VARIANT* variant)
2441 variant->vt = VT_R8;
2442 variant->dblVal = 3.14;
2447 LIBTEST_API int STDCALL
2448 mono_test_marshal_variant_out_bstr(VARIANT* variant)
2450 variant->vt = VT_BSTR;
2451 variant->bstrVal = SysAllocString(L"PI");
2456 LIBTEST_API int STDCALL
2457 mono_test_marshal_variant_out_bool_true (VARIANT* variant)
2459 variant->vt = VT_BOOL;
2460 variant->boolVal = VARIANT_TRUE;
2465 LIBTEST_API int STDCALL
2466 mono_test_marshal_variant_out_bool_false (VARIANT* variant)
2468 variant->vt = VT_BOOL;
2469 variant->boolVal = VARIANT_FALSE;
2474 typedef int (STDCALL *VarFunc) (int vt, VARIANT variant);
2475 typedef int (STDCALL *VarRefFunc) (int vt, VARIANT* variant);
2477 LIBTEST_API int STDCALL
2478 mono_test_marshal_variant_in_sbyte_unmanaged(VarFunc func)
2483 return func (VT_I1, vt);
2486 LIBTEST_API int STDCALL
2487 mono_test_marshal_variant_in_byte_unmanaged(VarFunc func)
2492 return func (VT_UI1, vt);
2495 LIBTEST_API int STDCALL
2496 mono_test_marshal_variant_in_short_unmanaged(VarFunc func)
2501 return func (VT_I2, vt);
2504 LIBTEST_API int STDCALL
2505 mono_test_marshal_variant_in_ushort_unmanaged(VarFunc func)
2510 return func (VT_UI2, vt);
2513 LIBTEST_API int STDCALL
2514 mono_test_marshal_variant_in_int_unmanaged(VarFunc func)
2519 return func (VT_I4, vt);
2522 LIBTEST_API int STDCALL
2523 mono_test_marshal_variant_in_uint_unmanaged(VarFunc func)
2528 return func (VT_UI4, vt);
2531 LIBTEST_API int STDCALL
2532 mono_test_marshal_variant_in_long_unmanaged(VarFunc func)
2537 return func (VT_I8, vt);
2540 LIBTEST_API int STDCALL
2541 mono_test_marshal_variant_in_ulong_unmanaged(VarFunc func)
2546 return func (VT_UI8, vt);
2549 LIBTEST_API int STDCALL
2550 mono_test_marshal_variant_in_float_unmanaged(VarFunc func)
2555 return func (VT_R4, vt);
2558 LIBTEST_API int STDCALL
2559 mono_test_marshal_variant_in_double_unmanaged(VarFunc func)
2564 return func (VT_R8, vt);
2567 LIBTEST_API int STDCALL
2568 mono_test_marshal_variant_in_bstr_unmanaged(VarFunc func)
2572 vt.bstrVal = SysAllocString(L"PI");
2573 return func (VT_BSTR, vt);
2576 LIBTEST_API int STDCALL
2577 mono_test_marshal_variant_in_bool_true_unmanaged(VarFunc func)
2581 vt.boolVal = VARIANT_TRUE;
2582 return func (VT_BOOL, vt);
2585 LIBTEST_API int STDCALL
2586 mono_test_marshal_variant_in_bool_false_unmanaged(VarFunc func)
2590 vt.boolVal = VARIANT_FALSE;
2591 return func (VT_BOOL, vt);
2594 LIBTEST_API int STDCALL
2595 mono_test_marshal_variant_out_sbyte_unmanaged(VarRefFunc func)
2600 if (vt.vt == VT_I1 && vt.cVal == -100)
2605 LIBTEST_API int STDCALL
2606 mono_test_marshal_variant_out_byte_unmanaged(VarRefFunc func)
2611 if (vt.vt == VT_UI1 && vt.bVal == 100)
2616 LIBTEST_API int STDCALL
2617 mono_test_marshal_variant_out_short_unmanaged(VarRefFunc func)
2622 if (vt.vt == VT_I2 && vt.iVal == -100)
2627 LIBTEST_API int STDCALL
2628 mono_test_marshal_variant_out_ushort_unmanaged(VarRefFunc func)
2633 if (vt.vt == VT_UI2 && vt.uiVal == 100)
2638 LIBTEST_API int STDCALL
2639 mono_test_marshal_variant_out_int_unmanaged(VarRefFunc func)
2644 if (vt.vt == VT_I4 && vt.lVal == -100)
2649 LIBTEST_API int STDCALL
2650 mono_test_marshal_variant_out_uint_unmanaged(VarRefFunc func)
2655 if (vt.vt == VT_UI4 && vt.ulVal == 100)
2660 LIBTEST_API int STDCALL
2661 mono_test_marshal_variant_out_long_unmanaged(VarRefFunc func)
2666 if (vt.vt == VT_I8 && vt.llVal == -100)
2671 LIBTEST_API int STDCALL
2672 mono_test_marshal_variant_out_ulong_unmanaged(VarRefFunc func)
2677 if (vt.vt == VT_UI8 && vt.ullVal == 100)
2682 LIBTEST_API int STDCALL
2683 mono_test_marshal_variant_out_float_unmanaged(VarRefFunc func)
2688 if (vt.vt == VT_R4 && fabs (vt.fltVal - 3.14f) < 1e-10)
2693 LIBTEST_API int STDCALL
2694 mono_test_marshal_variant_out_double_unmanaged(VarRefFunc func)
2699 if (vt.vt == VT_R8 && fabs (vt.dblVal - 3.14) < 1e-10)
2704 LIBTEST_API int STDCALL
2705 mono_test_marshal_variant_out_bstr_unmanaged(VarRefFunc func)
2709 func (VT_BSTR, &vt);
2710 if (vt.vt == VT_BSTR && !wcscmp(vt.bstrVal, L"PI"))
2715 LIBTEST_API int STDCALL
2716 mono_test_marshal_variant_out_bool_true_unmanaged(VarRefFunc func)
2720 func (VT_BOOL, &vt);
2721 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
2726 LIBTEST_API int STDCALL
2727 mono_test_marshal_variant_out_bool_false_unmanaged(VarRefFunc func)
2731 func (VT_BOOL, &vt);
2732 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
2737 typedef struct MonoComObject MonoComObject;
2741 int (STDCALL *QueryInterface)(MonoComObject* pUnk, gpointer riid, gpointer* ppv);
2742 int (STDCALL *AddRef)(MonoComObject* pUnk);
2743 int (STDCALL *Release)(MonoComObject* pUnk);
2744 int (STDCALL *get_ITest)(MonoComObject* pUnk, MonoComObject* *ppUnk);
2745 int (STDCALL *SByteIn)(MonoComObject* pUnk, char a);
2746 int (STDCALL *ByteIn)(MonoComObject* pUnk, unsigned char a);
2747 int (STDCALL *ShortIn)(MonoComObject* pUnk, short a);
2748 int (STDCALL *UShortIn)(MonoComObject* pUnk, unsigned short a);
2749 int (STDCALL *IntIn)(MonoComObject* pUnk, int a);
2750 int (STDCALL *UIntIn)(MonoComObject* pUnk, unsigned int a);
2751 int (STDCALL *LongIn)(MonoComObject* pUnk, LONGLONG a);
2752 int (STDCALL *ULongIn)(MonoComObject* pUnk, ULONGLONG a);
2753 int (STDCALL *FloatIn)(MonoComObject* pUnk, float a);
2754 int (STDCALL *DoubleIn)(MonoComObject* pUnk, double a);
2755 int (STDCALL *ITestIn)(MonoComObject* pUnk, MonoComObject* pUnk2);
2756 int (STDCALL *ITestOut)(MonoComObject* pUnk, MonoComObject* *ppUnk);
2759 struct MonoComObject
2765 DEFINE_GUID(IID_ITest, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1);
2766 DEFINE_GUID(IID_IMonoUnknown, 0, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46);
2767 DEFINE_GUID(IID_IMonoDispatch, 0x00020400, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46);
2769 LIBTEST_API int STDCALL
2770 MonoQueryInterface(MonoComObject* pUnk, gpointer riid, gpointer* ppv)
2773 if (!memcmp(riid, &IID_IMonoUnknown, sizeof(GUID))) {
2777 else if (!memcmp(riid, &IID_ITest, sizeof(GUID))) {
2781 else if (!memcmp(riid, &IID_IMonoDispatch, sizeof(GUID))) {
2785 return E_NOINTERFACE;
2788 LIBTEST_API int STDCALL
2789 MonoAddRef(MonoComObject* pUnk)
2791 return ++(pUnk->m_ref);
2794 LIBTEST_API int STDCALL
2795 MonoRelease(MonoComObject* pUnk)
2797 return --(pUnk->m_ref);
2800 LIBTEST_API int STDCALL
2801 SByteIn(MonoComObject* pUnk, char a)
2806 LIBTEST_API int STDCALL
2807 ByteIn(MonoComObject* pUnk, unsigned char a)
2812 LIBTEST_API int STDCALL
2813 ShortIn(MonoComObject* pUnk, short a)
2818 LIBTEST_API int STDCALL
2819 UShortIn(MonoComObject* pUnk, unsigned short a)
2824 LIBTEST_API int STDCALL
2825 IntIn(MonoComObject* pUnk, int a)
2830 LIBTEST_API int STDCALL
2831 UIntIn(MonoComObject* pUnk, unsigned int a)
2836 LIBTEST_API int STDCALL
2837 LongIn(MonoComObject* pUnk, LONGLONG a)
2842 LIBTEST_API int STDCALL
2843 ULongIn(MonoComObject* pUnk, ULONGLONG a)
2848 LIBTEST_API int STDCALL
2849 FloatIn(MonoComObject* pUnk, float a)
2854 LIBTEST_API int STDCALL
2855 DoubleIn(MonoComObject* pUnk, double a)
2860 LIBTEST_API int STDCALL
2861 ITestIn(MonoComObject* pUnk, MonoComObject *pUnk2)
2866 LIBTEST_API int STDCALL
2867 ITestOut(MonoComObject* pUnk, MonoComObject* *ppUnk)
2872 LIBTEST_API int STDCALL
2873 get_ITest(MonoComObject* pUnk, MonoComObject* *ppUnk)
2878 static void create_com_object (MonoComObject** pOut)
2880 *pOut = g_new0 (MonoComObject, 1);
2881 (*pOut)->vtbl = g_new0 (MonoIUnknown, 1);
2884 (*pOut)->vtbl->QueryInterface = MonoQueryInterface;
2885 (*pOut)->vtbl->AddRef = MonoAddRef;
2886 (*pOut)->vtbl->Release = MonoRelease;
2887 (*pOut)->vtbl->SByteIn = SByteIn;
2888 (*pOut)->vtbl->ByteIn = ByteIn;
2889 (*pOut)->vtbl->ShortIn = ShortIn;
2890 (*pOut)->vtbl->UShortIn = UShortIn;
2891 (*pOut)->vtbl->IntIn = IntIn;
2892 (*pOut)->vtbl->UIntIn = UIntIn;
2893 (*pOut)->vtbl->LongIn = LongIn;
2894 (*pOut)->vtbl->ULongIn = ULongIn;
2895 (*pOut)->vtbl->FloatIn = FloatIn;
2896 (*pOut)->vtbl->DoubleIn = DoubleIn;
2897 (*pOut)->vtbl->ITestIn = ITestIn;
2898 (*pOut)->vtbl->ITestOut = ITestOut;
2899 (*pOut)->vtbl->get_ITest = get_ITest;
2902 static MonoComObject* same_object = NULL;
2904 LIBTEST_API int STDCALL
2905 mono_test_marshal_com_object_create(MonoComObject* *pUnk)
2907 create_com_object (pUnk);
2910 same_object = *pUnk;
2915 LIBTEST_API int STDCALL
2916 mono_test_marshal_com_object_same(MonoComObject* *pUnk)
2918 *pUnk = same_object;
2923 LIBTEST_API int STDCALL
2924 mono_test_marshal_com_object_destroy(MonoComObject *pUnk)
2926 int ref = --(pUnk->m_ref);
2933 LIBTEST_API int STDCALL
2934 mono_test_marshal_com_object_ref_count(MonoComObject *pUnk)
2939 LIBTEST_API int STDCALL
2940 mono_test_marshal_ccw_itest (MonoComObject *pUnk)
2943 MonoComObject* pTest;
2948 hr = pUnk->vtbl->SByteIn (pUnk, -100);
2951 hr = pUnk->vtbl->ByteIn (pUnk, 100);
2954 hr = pUnk->vtbl->ShortIn (pUnk, -100);
2957 hr = pUnk->vtbl->UShortIn (pUnk, 100);
2960 hr = pUnk->vtbl->IntIn (pUnk, -100);
2963 hr = pUnk->vtbl->UIntIn (pUnk, 100);
2966 hr = pUnk->vtbl->LongIn (pUnk, -100);
2969 hr = pUnk->vtbl->ULongIn (pUnk, 100);
2972 hr = pUnk->vtbl->FloatIn (pUnk, 3.14f);
2975 hr = pUnk->vtbl->DoubleIn (pUnk, 3.14);
2978 hr = pUnk->vtbl->ITestIn (pUnk, pUnk);
2981 hr = pUnk->vtbl->ITestOut (pUnk, &pTest);
2993 * mono_method_get_unmanaged_thunk tests
2996 #if defined(__GNUC__) && ((defined(__i386__) && (defined(__linux__) || defined (__APPLE__))) || (defined(__ppc__) && defined(__APPLE__)))
2997 #define ALIGN(size) __attribute__ ((aligned(size)))
3003 /* thunks.cs:TestStruct */
3004 typedef struct _TestStruct {
3006 double B ALIGN(8); /* align according to mono's struct layout */
3009 /* Searches for mono symbols in all loaded modules */
3011 lookup_mono_symbol (const char *symbol_name)
3014 if (g_module_symbol (g_module_open (NULL, G_MODULE_BIND_LAZY), symbol_name, &symbol))
3021 * test_method_thunk:
3023 * @test_id: the test number
3024 * @test_method_handle: MonoMethod* of the C# test method
3025 * @create_object_method_handle: MonoMethod* of thunks.cs:Test.CreateObject
3027 LIBTEST_API int STDCALL
3028 test_method_thunk (int test_id, gpointer test_method_handle, gpointer create_object_method_handle)
3030 gpointer (*mono_method_get_unmanaged_thunk)(gpointer)
3031 = lookup_mono_symbol ("mono_method_get_unmanaged_thunk");
3033 gpointer (*mono_string_new_wrapper)(const char *)
3034 = lookup_mono_symbol ("mono_string_new_wrapper");
3036 char* (*mono_string_to_utf8)(gpointer)
3037 = lookup_mono_symbol ("mono_string_to_utf8");
3039 gpointer (*mono_object_unbox)(gpointer)
3040 = lookup_mono_symbol ("mono_object_unbox");
3042 gpointer test_method, ex = NULL;
3043 gpointer (STDCALL *CreateObject)(gpointer*);
3046 if (!mono_method_get_unmanaged_thunk)
3049 test_method = mono_method_get_unmanaged_thunk (test_method_handle);
3053 CreateObject = mono_method_get_unmanaged_thunk (create_object_method_handle);
3061 /* thunks.cs:Test.Test0 */
3062 void (STDCALL *F)(gpointer*) = test_method;
3068 /* thunks.cs:Test.Test1 */
3069 int (STDCALL *F)(gpointer*) = test_method;
3076 /* thunks.cs:Test.Test2 */
3077 gpointer (STDCALL *F)(gpointer, gpointer*) = test_method;
3078 gpointer str = mono_string_new_wrapper ("foo");
3079 if (str != F (str, &ex))
3085 /* thunks.cs:Test.Test3 */
3086 gpointer (STDCALL *F)(gpointer, gpointer, gpointer*);
3091 obj = CreateObject (&ex);
3092 str = mono_string_new_wrapper ("bar");
3094 if (str != F (obj, str, &ex))
3100 /* thunks.cs:Test.Test4 */
3101 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3106 obj = CreateObject (&ex);
3107 str = mono_string_new_wrapper ("bar");
3109 if (42 != F (obj, str, 42, &ex))
3116 /* thunks.cs:Test.Test5 */
3117 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3122 obj = CreateObject (&ex);
3123 str = mono_string_new_wrapper ("bar");
3125 F (obj, str, 42, &ex);
3133 /* thunks.cs:Test.Test6 */
3134 int (STDCALL *F)(gpointer, guint8, gint16, gint32, gint64, float, double,
3135 gpointer, gpointer*);
3137 gpointer str = mono_string_new_wrapper ("Test6");
3141 obj = CreateObject (&ex);
3143 res = F (obj, 254, 32700, -245378, 6789600, 3.1415, 3.1415, str, &ex);
3154 /* thunks.cs:Test.Test7 */
3155 gint64 (STDCALL *F)(gpointer*) = test_method;
3156 if (F (&ex) != G_MAXINT64)
3162 /* thunks.cs:Test.Test8 */
3163 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3164 gpointer*, gpointer*);
3176 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3184 (fabs (a5 - 3.1415) < 0.001) &&
3185 (fabs (a6 - 3.1415) < 0.001) &&
3186 strcmp (mono_string_to_utf8 (a7), "Test8") == 0))
3193 /* thunks.cs:Test.Test9 */
3194 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3195 gpointer*, gpointer*);
3207 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3215 /* thunks.cs:Test.Test10 */
3216 void (STDCALL *F)(gpointer*, gpointer*);
3218 gpointer obj1, obj2;
3220 obj1 = obj2 = CreateObject (&ex);
3237 /* thunks.cs:TestStruct.Test0 */
3238 int (STDCALL *F)(gpointer*, gpointer*);
3244 obj = CreateObject (&ex);
3251 a1 = mono_object_unbox (obj);
3267 /* check whether the call was really by value */
3268 if (a1->A != 42 || a1->B != 3.1415)
3275 /* thunks.cs:TestStruct.Test1 */
3276 void (STDCALL *F)(gpointer, gpointer*);
3281 obj = CreateObject (&ex);
3288 a1 = mono_object_unbox (obj);
3301 if (!fabs (a1->B - 3.1415) < 0.001)
3308 /* thunks.cs:TestStruct.Test2 */
3309 gpointer (STDCALL *F)(gpointer*);
3323 a1 = mono_object_unbox (obj);
3328 if (!fabs (a1->B - 3.1415) < 0.001)
3335 /* thunks.cs:TestStruct.Test3 */
3336 void (STDCALL *F)(gpointer, gpointer*);
3341 obj = CreateObject (&ex);
3348 a1 = mono_object_unbox (obj);
3384 LIBTEST_API int STDCALL
3385 mono_test_Winx64_struct1_in (winx64_struct1 var)
3398 LIBTEST_API int STDCALL
3399 mono_test_Winx64_struct2_in (winx64_struct2 var)
3416 LIBTEST_API int STDCALL
3417 mono_test_Winx64_struct3_in (winx64_struct3 var)
3423 if (var.c != 0x1234)
3436 LIBTEST_API int STDCALL
3437 mono_test_Winx64_struct4_in (winx64_struct4 var)
3443 if (var.c != 0x1234)
3445 if (var.d != 0x87654321)
3457 LIBTEST_API int STDCALL
3458 mono_test_Winx64_struct5_in (winx64_struct5 var)
3476 LIBTEST_API int STDCALL
3477 mono_test_Winx64_struct6_in (winx64_struct6 var)
3488 LIBTEST_API int STDCALL
3489 mono_test_Winx64_structs_in1 (winx64_struct1 var1,
3490 winx64_struct2 var2,
3491 winx64_struct3 var3,
3492 winx64_struct4 var4)
3506 if (var3.c != 0x1234)
3513 if (var4.c != 0x1234)
3515 if (var4.d != 0x87654321)
3520 LIBTEST_API int STDCALL
3521 mono_test_Winx64_structs_in2 (winx64_struct1 var1,
3522 winx64_struct1 var2,
3523 winx64_struct1 var3,
3524 winx64_struct1 var4,
3525 winx64_struct1 var5)
3541 LIBTEST_API int STDCALL
3542 mono_test_Winx64_structs_in3 (winx64_struct1 var1,
3543 winx64_struct5 var2,
3544 winx64_struct1 var3,
3545 winx64_struct5 var4,
3546 winx64_struct1 var5,
3547 winx64_struct5 var6)
3582 LIBTEST_API winx64_struct1 STDCALL
3583 mono_test_Winx64_struct1_ret (void)
3590 LIBTEST_API winx64_struct2 STDCALL
3591 mono_test_Winx64_struct2_ret (void)
3599 LIBTEST_API winx64_struct3 STDCALL
3600 mono_test_Winx64_struct3_ret (void)
3609 LIBTEST_API winx64_struct4 STDCALL
3610 mono_test_Winx64_struct4_ret (void)
3620 LIBTEST_API winx64_struct5 STDCALL
3621 mono_test_Winx64_struct5_ret (void)
3630 LIBTEST_API winx64_struct1 STDCALL
3631 mono_test_Winx64_struct1_ret_5_args (char a, char b, char c, char d, char e)
3634 ret.a = a + b + c + d + e;
3638 LIBTEST_API winx64_struct5 STDCALL
3639 mono_test_Winx64_struct5_ret6_args (char a, char b, char c, char d, char e)
3652 } winx64_floatStruct;
3654 LIBTEST_API int STDCALL
3655 mono_test_Winx64_floatStruct (winx64_floatStruct a)
3657 if (a.a > 5.6 || a.a < 5.4)
3660 if (a.b > 9.6 || a.b < 9.4)
3669 } winx64_doubleStruct;
3671 LIBTEST_API int STDCALL
3672 mono_test_Winx64_doubleStruct (winx64_doubleStruct a)
3674 if (a.a > 5.6 || a.a < 5.4)
3680 typedef int (STDCALL *managed_struct1_delegate) (winx64_struct1 a);
3682 LIBTEST_API int STDCALL
3683 mono_test_managed_Winx64_struct1_in(managed_struct1_delegate func)
3690 typedef int (STDCALL *managed_struct5_delegate) (winx64_struct5 a);
3692 LIBTEST_API int STDCALL
3693 mono_test_managed_Winx64_struct5_in(managed_struct5_delegate func)
3702 typedef int (STDCALL *managed_struct1_struct5_delegate) (winx64_struct1 a, winx64_struct5 b,
3703 winx64_struct1 c, winx64_struct5 d,
3704 winx64_struct1 e, winx64_struct5 f);
3706 LIBTEST_API int STDCALL
3707 mono_test_managed_Winx64_struct1_struct5_in(managed_struct1_struct5_delegate func)
3709 winx64_struct1 a, c, e;
3710 winx64_struct5 b, d, f;
3712 b.a = 2; b.b = 3; b.c = 4;
3714 d.a = 6; d.b = 7; d.c = 8;
3716 f.a = 10; f.b = 11; f.c = 12;
3718 return func (a, b, c, d, e, f);
3721 typedef winx64_struct1 (STDCALL *managed_struct1_ret_delegate) (void);
3723 LIBTEST_API int STDCALL
3724 mono_test_Winx64_struct1_ret_managed (managed_struct1_ret_delegate func)
3736 typedef winx64_struct5 (STDCALL *managed_struct5_ret_delegate) (void);
3738 LIBTEST_API int STDCALL
3739 mono_test_Winx64_struct5_ret_managed (managed_struct5_ret_delegate func)