19 #define STDCALL __stdcall
25 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
29 extern __declspec(dllimport) void __stdcall CoTaskMemFree(void *ptr);
32 typedef int (STDCALL *SimpleDelegate) (int a);
34 #if defined(WIN32) && defined (_MSC_VER)
35 #define LIBTEST_API __declspec(dllexport)
40 static void marshal_free (void *ptr)
49 static void* marshal_alloc (gsize size)
52 return CoTaskMemAlloc (size);
54 return g_malloc (size);
58 static void* marshal_alloc0 (gsize size)
61 void* ptr = CoTaskMemAlloc (size);
65 return g_malloc0 (size);
69 static char* marshal_strdup (const char *str)
79 buf = (char *) CoTaskMemAlloc (len + 1);
80 return strcpy (buf, str);
82 return g_strdup (str);
86 static gunichar2* marshal_bstr_alloc(const gchar* str)
89 gunichar2* ret = NULL;
90 gunichar2* temp = NULL;
91 temp = g_utf8_to_utf16 (str, -1, NULL, NULL, NULL);
92 ret = SysAllocString (temp);
97 int slen = strlen (str);
99 /* allocate len + 1 utf16 characters plus 4 byte integer for length*/
100 ret = g_malloc ((slen + 1) * sizeof(gunichar2) + sizeof(guint32));
103 temp = g_utf8_to_utf16 (str, -1, NULL, NULL, NULL);
104 memcpy (ret + sizeof(guint32), temp, slen * sizeof(gunichar2));
105 * ((guint32 *) ret) = slen * sizeof(gunichar2);
106 ret [4 + slen * sizeof(gunichar2)] = 0;
107 ret [5 + slen * sizeof(gunichar2)] = 0;
109 return (gunichar2*)(ret + 4);
113 #define marshal_new0(type,size) ((type *) marshal_alloc0 (sizeof (type)* (size)))
115 LIBTEST_API int STDCALL
116 mono_cominterop_is_supported (void)
118 #if defined(TARGET_X86) || defined(TARGET_AMD64)
124 LIBTEST_API unsigned short* STDCALL
125 test_lpwstr_marshal (unsigned short* chars, long length)
130 res = marshal_alloc (2 * (length + 1));
132 // printf("test_lpwstr_marshal()\n");
134 while ( i < length ) {
135 // printf("X|%u|\n", chars[i]);
146 LIBTEST_API void STDCALL
147 test_lpwstr_marshal_out (unsigned short** chars)
150 const char abc[] = "ABC";
151 glong len = strlen(abc);
153 *chars = marshal_alloc (2 * (len + 1));
156 (*chars) [i] = abc[i];
169 LIBTEST_API int STDCALL
170 mono_union_test_1 (union_test_1_type u1) {
171 // printf ("Got values %d %d %d\n", u1.b, u1.a, u1.c);
172 return u1.a + u1.b + u1.c;
175 LIBTEST_API int STDCALL
176 mono_return_int (int a) {
177 // printf ("Got value %d\n", a);
181 LIBTEST_API float STDCALL
182 mono_test_marshal_pass_return_float (float f) {
191 LIBTEST_API int STDCALL
192 mono_return_int_ss (struct ss a) {
193 // printf ("Got value %d\n", a.i);
197 LIBTEST_API struct ss STDCALL
198 mono_return_ss (struct ss a) {
199 // printf ("Got value %d\n", a.i);
209 LIBTEST_API struct sc1 STDCALL
210 mono_return_sc1 (struct sc1 a) {
211 // printf ("Got value %d\n", a.c[0]);
222 LIBTEST_API struct sc3 STDCALL
223 mono_return_sc3 (struct sc3 a) {
224 // printf ("Got values %d %d %d\n", a.c[0], a.c[1], a.c[2]);
236 LIBTEST_API struct sc5 STDCALL
237 mono_return_sc5 (struct sc5 a) {
238 // printf ("Got values %d %d %d %d %d\n", a.c[0], a.c[1], a.c[2], a.c[3], a.c[4]);
253 LIBTEST_API int STDCALL
254 mono_return_int_su (union su a) {
255 // printf ("Got value %d\n", a.i1);
259 LIBTEST_API int STDCALL
260 mono_test_many_int_arguments (int a, int b, int c, int d, int e,
261 int f, int g, int h, int i, int j);
262 LIBTEST_API short STDCALL
263 mono_test_many_short_arguments (short a, short b, short c, short d, short e,
264 short f, short g, short h, short i, short j);
265 LIBTEST_API char STDCALL
266 mono_test_many_char_arguments (char a, char b, char c, char d, char e,
267 char f, char g, char h, char i, char j);
269 LIBTEST_API int STDCALL
270 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)
272 return a + b + c + d + e + f + g + h + i + j;
275 LIBTEST_API short STDCALL
276 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)
278 return a + b + c + d + e + f + g + h + i + j;
281 LIBTEST_API char STDCALL
282 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)
284 return a + b + c + d + e + f + g + h + i + j;
287 LIBTEST_API float STDCALL
288 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)
290 return a + b + c + d + e + f + g + h + i + j;
293 LIBTEST_API double STDCALL
294 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)
296 return a + b + c + d + e + f + g + h + i + j;
299 LIBTEST_API double STDCALL
300 mono_test_split_double_arguments (double a, double b, float c, double d, double e)
302 return a + b + c + d + e;
305 LIBTEST_API int STDCALL
306 mono_test_puts_static (char *s)
308 // printf ("TEST %s\n", s);
312 typedef int (STDCALL *SimpleDelegate3) (int a, int b);
314 LIBTEST_API int STDCALL
315 mono_invoke_delegate (SimpleDelegate3 delegate)
319 // printf ("start invoke %p\n", delegate);
321 res = delegate (2, 3);
323 // printf ("end invoke\n");
328 LIBTEST_API int STDCALL
329 mono_invoke_simple_delegate (SimpleDelegate d)
334 LIBTEST_API int STDCALL
335 mono_test_marshal_char (short a1)
343 LIBTEST_API void STDCALL
344 mono_test_marshal_char_array (gunichar2 *s)
346 const char m[] = "abcdef";
350 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
358 LIBTEST_API int STDCALL
359 mono_test_marshal_ansi_char_array (char *s)
361 const char m[] = "abcdef";
363 if (strncmp ("qwer", s, 4))
366 memcpy (s, m, sizeof (m));
370 LIBTEST_API int STDCALL
371 mono_test_marshal_unicode_char_array (gunichar2 *s)
373 const char m[] = "abcdef";
374 const char expected[] = "qwer";
378 s1 = g_utf8_to_utf16 (m, -1, NULL, &len1, NULL);
379 s2 = g_utf8_to_utf16 (expected, -1, NULL, &len2, NULL);
383 if (memcmp (s, s2, len2))
386 memcpy (s, s1, len1);
391 LIBTEST_API int STDCALL
392 mono_test_empty_pinvoke (int i)
397 LIBTEST_API int STDCALL
398 mono_test_marshal_bool_byref (int a, int *b, int c)
407 LIBTEST_API int STDCALL
408 mono_test_marshal_bool_in_as_I1_U1 (char bTrue, char bFalse)
417 LIBTEST_API int STDCALL
418 mono_test_marshal_bool_out_as_I1_U1 (char* bTrue, char* bFalse)
420 if (!bTrue || !bFalse)
429 LIBTEST_API int STDCALL
430 mono_test_marshal_bool_ref_as_I1_U1 (char* bTrue, char* bFalse)
432 if (!bTrue || !bFalse)
446 LIBTEST_API int STDCALL
447 mono_test_marshal_array (int *a1)
451 for (i = 0; i < 50; i++)
457 LIBTEST_API int STDCALL
458 mono_test_marshal_inout_array (int *a1)
462 for (i = 0; i < 50; i++) {
464 a1 [i] = 50 - a1 [i];
470 LIBTEST_API int /* cdecl */
471 mono_test_marshal_inout_array_cdecl (int *a1)
473 return mono_test_marshal_inout_array (a1);
476 LIBTEST_API int STDCALL
477 mono_test_marshal_out_array (int *a1)
481 for (i = 0; i < 50; i++) {
488 LIBTEST_API int STDCALL
489 mono_test_marshal_inout_nonblittable_array (gunichar2 *a1)
493 for (i = 0; i < 10; i++) {
513 LIBTEST_API simplestruct STDCALL
514 mono_test_return_vtype (int i)
517 static gunichar2 test2 [] = { 'T', 'E', 'S', 'T', '2', 0 };
528 LIBTEST_API void STDCALL
529 mono_test_delegate_struct (void)
531 // printf ("TEST\n");
534 typedef char* (STDCALL *ReturnStringDelegate) (const char *s);
536 LIBTEST_API char * STDCALL
537 mono_test_return_string (ReturnStringDelegate func)
541 // printf ("mono_test_return_string\n");
546 // printf ("got string: %s\n", res);
547 return marshal_strdup ("12345");
550 typedef int (STDCALL *RefVTypeDelegate) (int a, simplestruct *ss, int b);
552 LIBTEST_API int STDCALL
553 mono_test_ref_vtype (int a, simplestruct *ss, int b, RefVTypeDelegate func)
555 if (a == 1 && b == 2 && ss->a == 0 && ss->b == 1 && ss->c == 0 &&
556 !strcmp (ss->d, "TEST1")) {
562 return func (a, ss, b);
568 typedef int (STDCALL *OutVTypeDelegate) (int a, simplestruct *ss, int b);
570 LIBTEST_API int STDCALL
571 mono_test_marshal_out_struct (int a, simplestruct *ss, int b, OutVTypeDelegate func)
573 /* Check that the input pointer is ignored */
574 ss->d = (gpointer)0x12345678;
578 if (ss->a && ss->b && ss->c && !strcmp (ss->d, "TEST3"))
584 typedef int (STDCALL *InVTypeDelegate) (int a, simplestruct *ss, int b);
586 LIBTEST_API int STDCALL
587 mono_test_marshal_in_struct (int a, simplestruct *ss, int b, InVTypeDelegate func)
592 memcpy (&ss2, ss, sizeof (simplestruct));
594 res = func (a, ss, b);
596 printf ("mono_test_marshal_in_struct () failed: %d\n", res);
600 /* Check that no modifications is made to the struct */
601 if (ss2.a == ss->a && ss2.b == ss->b && ss2.c == ss->c && ss2.d == ss->d)
609 SimpleDelegate func, func2, func3;
612 LIBTEST_API DelegateStruct STDCALL
613 mono_test_marshal_delegate_struct (DelegateStruct ds)
617 res.a = ds.func (ds.a) + ds.func2 (ds.a) + (ds.func3 == NULL ? 0 : 1);
619 res.func2 = ds.func2;
625 LIBTEST_API int STDCALL
626 mono_test_marshal_struct (simplestruct ss)
628 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
629 !strcmp (ss.d, "TEST"))
635 LIBTEST_API int STDCALL
636 mono_test_marshal_byref_struct (simplestruct *ss, int a, int b, int c, char *d)
638 gboolean res = (ss->a == a && ss->b == b && ss->c == c && strcmp (ss->d, d) == 0);
640 marshal_free ((char*)ss->d);
645 ss->d = marshal_strdup ("DEF");
661 LIBTEST_API int STDCALL
662 mono_test_marshal_struct2 (simplestruct2 ss)
664 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
665 !strcmp (ss.d, "TEST") &&
666 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
672 /* on HP some of the struct should be on the stack and not in registers */
673 LIBTEST_API int STDCALL
674 mono_test_marshal_struct2_2 (int i, int j, int k, simplestruct2 ss)
676 if (i != 10 || j != 11 || k != 12)
678 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
679 !strcmp (ss.d, "TEST") &&
680 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
686 LIBTEST_API int STDCALL
687 mono_test_marshal_lpstruct (simplestruct *ss)
689 if (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
690 !strcmp (ss->d, "TEST"))
696 LIBTEST_API int STDCALL
697 mono_test_marshal_lpstruct_blittable (point *p)
699 if (p->x == 1.0 && p->y == 2.0)
705 LIBTEST_API int STDCALL
706 mono_test_marshal_struct_array (simplestruct2 *ss)
708 if (! (ss[0].a == 0 && ss[0].b == 1 && ss[0].c == 0 &&
709 !strcmp (ss[0].d, "TEST") &&
710 ss[0].e == 99 && ss[0].f == 1.5 && ss[0].g == 42 && ss[0].h == (guint64)123))
713 if (! (ss[1].a == 0 && ss[1].b == 0 && ss[1].c == 0 &&
714 !strcmp (ss[1].d, "TEST2") &&
715 ss[1].e == 100 && ss[1].f == 2.5 && ss[1].g == 43 && ss[1].h == (guint64)124))
721 typedef struct long_align_struct {
727 LIBTEST_API int STDCALL
728 mono_test_marshal_long_align_struct_array (long_align_struct *ss)
730 return ss[0].a + ss[0].b + ss[0].c + ss[1].a + ss[1].b + ss[1].c;
733 LIBTEST_API simplestruct2 * STDCALL
734 mono_test_marshal_class (int i, int j, int k, simplestruct2 *ss, int l)
741 if (i != 10 || j != 11 || k != 12 || l != 14)
743 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
744 !strcmp (ss->d, "TEST") &&
745 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
748 res = marshal_new0 (simplestruct2, 1);
749 memcpy (res, ss, sizeof (simplestruct2));
750 res->d = marshal_strdup ("TEST");
754 LIBTEST_API int STDCALL
755 mono_test_marshal_byref_class (simplestruct2 **ssp)
757 simplestruct2 *ss = *ssp;
760 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
761 !strcmp (ss->d, "TEST") &&
762 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
765 res = marshal_new0 (simplestruct2, 1);
766 memcpy (res, ss, sizeof (simplestruct2));
767 res->d = marshal_strdup ("TEST-RES");
779 /* Yes, this is correct, we are only trying to determine the value of the stack here */
784 LIBTEST_API int STDCALL
785 reliable_delegate (int a)
791 * Checks whether get_sp() works as expected. It doesn't work with gcc-2.95.3 on linux.
794 is_get_sp_reliable (void)
798 reliable_delegate(1);
800 reliable_delegate(1);
805 LIBTEST_API int STDCALL
806 mono_test_marshal_delegate (SimpleDelegate delegate)
810 /* Check that the delegate wrapper is stdcall */
815 if (is_get_sp_reliable())
816 g_assert (sp1 == sp2);
821 static int STDCALL inc_cb (int i)
826 LIBTEST_API int STDCALL
827 mono_test_marshal_out_delegate (SimpleDelegate *delegate)
834 LIBTEST_API SimpleDelegate STDCALL
835 mono_test_marshal_return_delegate (SimpleDelegate delegate)
841 return_plus_one (int i)
846 LIBTEST_API SimpleDelegate STDCALL
847 mono_test_marshal_return_delegate_2 (void)
849 return return_plus_one;
852 typedef simplestruct (STDCALL *SimpleDelegate2) (simplestruct ss);
855 is_utf16_equals (gunichar2 *s1, const char *s2)
860 s = g_utf16_to_utf8 (s1, -1, NULL, NULL, NULL);
861 res = strcmp (s, s2);
867 LIBTEST_API int STDCALL
868 mono_test_marshal_delegate2 (SimpleDelegate2 delegate)
870 simplestruct ss, res;
876 ss.d2 = g_utf8_to_utf16 ("TEST2", -1, NULL, NULL, NULL);
879 if (! (res.a && !res.b && res.c && !strcmp (res.d, "TEST-RES") && is_utf16_equals (res.d2, "TEST2-RES")))
885 typedef simplestruct* (STDCALL *SimpleDelegate4) (simplestruct *ss);
887 LIBTEST_API int STDCALL
888 mono_test_marshal_delegate4 (SimpleDelegate4 delegate)
899 res = delegate (&ss);
903 /* Check return value */
904 if (! (!res->a && res->b && !res->c && !strcmp (res->d, "TEST")))
907 /* Check NULL argument and NULL result */
908 res = delegate (NULL);
915 typedef int (STDCALL *SimpleDelegate5) (simplestruct **ss);
917 LIBTEST_API int STDCALL
918 mono_test_marshal_delegate5 (SimpleDelegate5 delegate)
931 res = delegate (&ptr);
935 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
941 LIBTEST_API int STDCALL
942 mono_test_marshal_delegate6 (SimpleDelegate5 delegate)
946 res = delegate (NULL);
951 typedef int (STDCALL *SimpleDelegate7) (simplestruct **ss);
953 LIBTEST_API int STDCALL
954 mono_test_marshal_delegate7 (SimpleDelegate7 delegate)
959 /* Check that the input pointer is ignored */
960 ptr = (gpointer)0x12345678;
962 res = delegate (&ptr);
966 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
972 typedef int (STDCALL *InOutByvalClassDelegate) (simplestruct *ss);
974 LIBTEST_API int STDCALL
975 mono_test_marshal_inout_byval_class_delegate (InOutByvalClassDelegate delegate)
983 ss.d = g_strdup_printf ("%s", "FOO");
985 res = delegate (&ss);
989 if (!(ss.a && !ss.b && ss.c && !strcmp (ss.d, "RES")))
995 typedef int (STDCALL *SimpleDelegate8) (gunichar2 *s);
997 LIBTEST_API int STDCALL
998 mono_test_marshal_delegate8 (SimpleDelegate8 delegate, gunichar2 *s)
1000 return delegate (s);
1003 typedef int (STDCALL *return_int_fnt) (int i);
1004 typedef int (STDCALL *SimpleDelegate9) (return_int_fnt d);
1006 LIBTEST_API int STDCALL
1007 mono_test_marshal_delegate9 (SimpleDelegate9 delegate, gpointer ftn)
1009 return delegate (ftn);
1018 LIBTEST_API int STDCALL
1019 mono_test_marshal_delegate10 (SimpleDelegate9 delegate)
1021 return delegate (return_self);
1024 typedef int (STDCALL *PrimitiveByrefDelegate) (int *i);
1026 LIBTEST_API int STDCALL
1027 mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate delegate)
1031 int res = delegate (&i);
1041 typedef int (STDCALL *return_int_delegate) (int i);
1043 typedef return_int_delegate (STDCALL *ReturnDelegateDelegate) (void);
1045 LIBTEST_API int STDCALL
1046 mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d)
1051 LIBTEST_API int STDCALL
1052 mono_test_marshal_stringbuilder (char *s, int n)
1054 const char m[] = "This is my message. Isn't it nice?";
1056 if (strcmp (s, "ABCD") != 0)
1063 LIBTEST_API int STDCALL
1064 mono_test_marshal_stringbuilder2 (char *s, int n)
1066 const char m[] = "EFGH";
1073 LIBTEST_API int STDCALL
1074 mono_test_marshal_stringbuilder_default (char *s, int n)
1076 const char m[] = "This is my message. Isn't it nice?";
1083 LIBTEST_API int STDCALL
1084 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
1086 const char m[] = "This is my message. Isn't it nice?";
1090 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1092 len = (len * 2) + 2;
1095 memcpy (s, s2, len);
1102 LIBTEST_API void STDCALL
1103 mono_test_marshal_stringbuilder_out (char **s)
1105 const char m[] = "This is my message. Isn't it nice?";
1108 str = marshal_alloc (strlen (m) + 1);
1109 memcpy (str, m, strlen (m) + 1);
1114 LIBTEST_API int STDCALL
1115 mono_test_marshal_stringbuilder_out_unicode (gunichar2 **s)
1117 const char m[] = "This is my message. Isn't it nice?";
1121 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1123 len = (len * 2) + 2;
1124 *s = marshal_alloc (len);
1125 memcpy (*s, s2, len);
1132 LIBTEST_API int STDCALL
1133 mono_test_marshal_stringbuilder_ref (char **s)
1135 const char m[] = "This is my message. Isn't it nice?";
1138 if (strcmp (*s, "ABC"))
1141 str = marshal_alloc (strlen (m) + 1);
1142 memcpy (str, m, strlen (m) + 1);
1154 LIBTEST_API int STDCALL
1155 mono_test_marshal_empty_string_array (char **array)
1157 return (array == NULL) ? 0 : 1;
1160 LIBTEST_API int STDCALL
1161 mono_test_marshal_string_array (char **array)
1163 if (strcmp (array [0], "ABC"))
1165 if (strcmp (array [1], "DEF"))
1168 if (array [2] != NULL)
1174 LIBTEST_API int STDCALL
1175 mono_test_marshal_byref_string_array (char ***array)
1180 if (strcmp ((*array) [0], "Alpha"))
1182 if (strcmp ((*array) [1], "Beta"))
1184 if (strcmp ((*array) [2], "Gamma"))
1190 LIBTEST_API int STDCALL
1191 mono_test_marshal_stringbuilder_array (char **array)
1193 if (strcmp (array [0], "ABC"))
1195 if (strcmp (array [1], "DEF"))
1198 strcpy (array [0], "DEF");
1199 strcpy (array [1], "ABC");
1204 LIBTEST_API int STDCALL
1205 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
1207 GError *error = NULL;
1210 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
1211 if (strcmp (s, "ABC")) {
1218 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
1219 if (strcmp (s, "DEF")) {
1226 if (strcmp (array2 [0], "ABC"))
1229 if (strcmp (array2 [1], "DEF"))
1235 /* this does not work on Redhat gcc 2.96 */
1236 LIBTEST_API int STDCALL
1237 mono_test_empty_struct (int a, EmptyStruct es, int b)
1239 // printf ("mono_test_empty_struct %d %d\n", a, b);
1241 // Intel icc on ia64 passes 'es' in 2 registers
1242 #if defined(__ia64) && defined(__INTEL_COMPILER)
1245 if (a == 1 && b == 2)
1255 LIBTEST_API ByValStrStruct * STDCALL
1256 mono_test_byvalstr_gen (void)
1258 ByValStrStruct *ret;
1260 ret = malloc(sizeof(ByValStrStruct));
1261 memset(ret, 'a', sizeof(ByValStrStruct)-1);
1262 ret->a[sizeof(ByValStrStruct)-1] = 0;
1267 LIBTEST_API int STDCALL
1268 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
1272 ret = strcmp(data->a, correctString);
1273 // printf ("T1: %s\n", data->a);
1274 // printf ("T2: %s\n", correctString);
1276 /* we need g_free because the allocation was performed by mono_test_byvalstr_gen */
1284 } ByValStrStruct_Unicode;
1286 LIBTEST_API int STDCALL
1287 mono_test_byvalstr_check_unicode (ByValStrStruct_Unicode *ref, int test)
1289 if (ref->flag != 0x1234abcd){
1290 printf ("overwritten data");
1294 if (test == 1 || test == 3){
1295 if (ref->a [0] != '1' ||
1296 ref->a [1] != '2' ||
1302 if (ref->a [0] != '1' ||
1310 LIBTEST_API int STDCALL
1311 NameManglingAnsi (char *data)
1313 return data [0] + data [1] + data [2];
1316 LIBTEST_API int STDCALL
1317 NameManglingAnsiA (char *data)
1319 g_assert_not_reached ();
1322 LIBTEST_API int STDCALL
1323 NameManglingAnsiW (char *data)
1325 g_assert_not_reached ();
1328 LIBTEST_API int STDCALL
1329 NameManglingAnsi2A (char *data)
1331 return data [0] + data [1] + data [2];
1334 LIBTEST_API int STDCALL
1335 NameManglingAnsi2W (char *data)
1337 g_assert_not_reached ();
1340 LIBTEST_API int STDCALL
1341 NameManglingUnicode (char *data)
1343 g_assert_not_reached ();
1346 LIBTEST_API int STDCALL
1347 NameManglingUnicodeW (gunichar2 *data)
1349 return data [0] + data [1] + data [2];
1352 LIBTEST_API int STDCALL
1353 NameManglingUnicode2 (gunichar2 *data)
1355 return data [0] + data [1] + data [2];
1358 LIBTEST_API int STDCALL
1359 NameManglingAutoW (char *data)
1362 return (data [0] + data [1] + data [2]) == 131 ? 0 : 1;
1364 g_assert_not_reached ();
1368 LIBTEST_API int STDCALL
1369 NameManglingAuto (char *data)
1372 return (data [0] + data [1] + data [2]) == 198 ? 0 : 1;
1374 g_assert_not_reached ();
1378 typedef int (STDCALL *intcharFunc)(const char*);
1380 LIBTEST_API void STDCALL
1381 callFunction (intcharFunc f)
1391 LIBTEST_API int STDCALL
1392 class_marshal_test0 (SimpleObj *obj1)
1394 // printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
1396 if (strcmp(obj1->str, "T1"))
1404 LIBTEST_API int STDCALL
1405 class_marshal_test4 (SimpleObj *obj1)
1413 LIBTEST_API void STDCALL
1414 class_marshal_test1 (SimpleObj **obj1)
1416 SimpleObj *res = malloc (sizeof (SimpleObj));
1418 res->str = marshal_strdup ("ABC");
1424 LIBTEST_API int STDCALL
1425 class_marshal_test2 (SimpleObj **obj1)
1427 // printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
1429 if (strcmp((*obj1)->str, "ABC"))
1431 if ((*obj1)->i != 5)
1437 LIBTEST_API int STDCALL
1438 string_marshal_test0 (char *str)
1440 if (strcmp (str, "TEST0"))
1446 LIBTEST_API void STDCALL
1447 string_marshal_test1 (const char **str)
1449 *str = marshal_strdup ("TEST1");
1452 LIBTEST_API int STDCALL
1453 string_marshal_test2 (char **str)
1455 // printf ("string_marshal_test2 %s\n", *str);
1457 if (strcmp (*str, "TEST1"))
1460 *str = marshal_strdup ("TEST2");
1465 LIBTEST_API int STDCALL
1466 string_marshal_test3 (char *str)
1479 LIBTEST_API BlittableClass* STDCALL
1480 TestBlittableClass (BlittableClass *vl)
1482 BlittableClass *res;
1484 // printf ("TestBlittableClass %d %d\n", vl->a, vl->b);
1490 res = marshal_new0 (BlittableClass, 1);
1491 memcpy (res, vl, sizeof (BlittableClass));
1493 res = marshal_new0 (BlittableClass, 1);
1501 typedef struct OSVERSIONINFO_STRUCT
1505 } OSVERSIONINFO_STRUCT;
1507 LIBTEST_API int STDCALL
1508 MyGetVersionEx (OSVERSIONINFO_STRUCT *osvi)
1511 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1516 return osvi->a + osvi->b;
1519 LIBTEST_API int STDCALL
1520 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO_STRUCT *osvi)
1523 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1528 return osvi->a + osvi->b;
1531 LIBTEST_API int STDCALL
1532 mono_test_marshal_point (point pt)
1534 // printf("point %g %g\n", pt.x, pt.y);
1535 if (pt.x == 1.25 && pt.y == 3.5)
1546 LIBTEST_API int STDCALL
1547 mono_test_marshal_mixed_point (mixed_point pt)
1549 // printf("mixed point %d %g\n", pt.x, pt.y);
1550 if (pt.x == 5 && pt.y == 6.75)
1556 LIBTEST_API int STDCALL
1557 mono_test_marshal_mixed_point_2 (mixed_point *pt)
1559 if (pt->x != 5 || pt->y != 6.75)
1568 LIBTEST_API int STDCALL
1569 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
1572 if (*b1 != 0 && *b1 != 1)
1574 if (*b2 != 0 && *b2 != -1) /* variant_bool */
1576 if (*b3 != 0 && *b3 != 1)
1578 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
1590 short b2; /* variant_bool */
1594 LIBTEST_API int STDCALL
1595 marshal_test_bool_struct(struct BoolStruct *s)
1598 if (s->b1 != 0 && s->b1 != 1)
1600 if (s->b2 != 0 && s->b2 != -1)
1602 if (s->b3 != 0 && s->b3 != 1)
1604 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1621 LIBTEST_API int STDCALL
1622 mono_test_marshal_long_struct (LongStruct *s)
1624 return s->i + s->l.l;
1627 LIBTEST_API void STDCALL
1628 mono_test_last_error (int err)
1637 LIBTEST_API int STDCALL
1638 mono_test_asany (void *ptr, int what)
1642 return (*(int*)ptr == 5) ? 0 : 1;
1644 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1646 simplestruct2 ss = *(simplestruct2*)ptr;
1648 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1649 !strcmp (ss.d, "TEST") &&
1650 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1656 GError *error = NULL;
1659 s = g_utf16_to_utf8 (ptr, -1, NULL, NULL, &error);
1664 if (!strcmp (s, "ABC")) {
1674 g_assert_not_reached ();
1688 LIBTEST_API int STDCALL
1689 mono_test_marshal_asany_in (void* ptr)
1691 AsAnyStruct* asAny = ptr;
1692 int res = asAny->i + asAny->j + asAny->k;
1697 LIBTEST_API int STDCALL
1698 mono_test_marshal_asany_inout (void* ptr)
1700 AsAnyStruct* asAny = ptr;
1701 int res = asAny->i + asAny->j + asAny->k;
1703 marshal_free (asAny->s);
1713 LIBTEST_API int STDCALL
1714 mono_test_marshal_asany_out (void* ptr)
1716 AsAnyStruct* asAny = ptr;
1717 int res = asAny->i + asAny->j + asAny->k;
1728 * AMD64 marshalling tests.
1731 typedef struct amd64_struct1 {
1738 LIBTEST_API amd64_struct1 STDCALL
1739 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
1749 LIBTEST_API amd64_struct1 STDCALL
1750 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)
1755 s.l += 1 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8;
1760 typedef struct amd64_struct2 {
1765 LIBTEST_API amd64_struct2 STDCALL
1766 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
1774 typedef struct amd64_struct3 {
1778 LIBTEST_API amd64_struct3 STDCALL
1779 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s)
1786 typedef struct amd64_struct4 {
1790 LIBTEST_API amd64_struct4 STDCALL
1791 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s)
1800 * IA64 marshalling tests.
1802 typedef struct test_struct5 {
1806 LIBTEST_API test_struct5 STDCALL
1807 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, test_struct5 s, int i, double d3, double d4)
1809 s.d1 += d1 + d2 + i;
1810 s.d2 += d3 + d4 + i;
1815 typedef struct test_struct6 {
1819 LIBTEST_API test_struct6 STDCALL
1820 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, test_struct6 s, int i, double d3, double d4)
1822 s.d1 += d1 + d2 + i;
1828 static guint32 custom_res [2];
1830 LIBTEST_API void* STDCALL
1831 mono_test_marshal_pass_return_custom (int i, guint32 *ptr, int j)
1833 /* ptr will be freed by CleanupNative, so make a copy */
1834 custom_res [0] = 0; /* not allocated by AllocHGlobal */
1835 custom_res [1] = ptr [1];
1840 LIBTEST_API int STDCALL
1841 mono_test_marshal_pass_out_custom (int i, guint32 **ptr, int j)
1844 custom_res [1] = i + j + 10;
1851 LIBTEST_API int STDCALL
1852 mono_test_marshal_pass_inout_custom (int i, guint32 *ptr, int j)
1855 ptr [1] = i + ptr [1] + j;
1860 LIBTEST_API int STDCALL
1861 mono_test_marshal_pass_out_byval_custom (int i, guint32 *ptr, int j)
1863 return ptr == NULL ? 0 : 1;
1866 LIBTEST_API int STDCALL
1867 mono_test_marshal_pass_byref_custom (int i, guint32 **ptr, int j)
1874 LIBTEST_API void* STDCALL
1875 mono_test_marshal_pass_return_custom2 (int i, guint32 *ptr, int j)
1877 g_assert_not_reached ();
1882 LIBTEST_API void* STDCALL
1883 mono_test_marshal_pass_return_custom_null (int i, guint32 *ptr, int j)
1885 g_assert (ptr == NULL);
1890 typedef void *(STDCALL *PassReturnPtrDelegate) (void *ptr);
1892 LIBTEST_API int STDCALL
1893 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del)
1907 /* FIXME: Freed with FreeHGlobal */
1915 LIBTEST_API int STDCALL
1916 mono_test_marshal_pass_return_custom_null_in_delegate (PassReturnPtrDelegate del)
1918 void *ptr = del (NULL);
1920 return (ptr == NULL) ? 15 : 0;
1923 typedef void (STDCALL *CustomOutParamDelegate) (void **pptr);
1925 LIBTEST_API int STDCALL
1926 mono_test_marshal_custom_out_param_delegate (CustomOutParamDelegate del)
1938 typedef int (STDCALL *ReturnEnumDelegate) (int e);
1940 LIBTEST_API int STDCALL
1941 mono_test_marshal_return_enum_delegate (ReturnEnumDelegate func)
1951 typedef BlittableStruct (STDCALL *SimpleDelegate10) (BlittableStruct ss);
1953 LIBTEST_API int STDCALL
1954 mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 delegate)
1956 BlittableStruct ss, res;
1963 res = delegate (ss);
1964 if (! ((res.a == -1) && (res.b == -2) && (res.c == -3) && (res.d == -55)))
1970 LIBTEST_API int STDCALL
1971 mono_test_stdcall_name_mangling (int a, int b, int c)
1977 * PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
1984 typedef SmallStruct1 (STDCALL *SmallStructDelegate1) (SmallStruct1 ss);
1986 LIBTEST_API int STDCALL
1987 mono_test_marshal_small_struct_delegate1 (SmallStructDelegate1 delegate)
1989 SmallStruct1 ss, res;
1993 res = delegate (ss);
1994 if (! (res.i == -1))
2004 typedef SmallStruct2 (STDCALL *SmallStructDelegate2) (SmallStruct2 ss);
2006 LIBTEST_API int STDCALL
2007 mono_test_marshal_small_struct_delegate2 (SmallStructDelegate2 delegate)
2009 SmallStruct2 ss, res;
2014 res = delegate (ss);
2015 if (! ((res.i == -2) && (res.j == -3)))
2026 typedef SmallStruct3 (STDCALL *SmallStructDelegate3) (SmallStruct3 ss);
2028 LIBTEST_API int STDCALL
2029 mono_test_marshal_small_struct_delegate3 (SmallStructDelegate3 delegate)
2031 SmallStruct3 ss, res;
2036 res = delegate (ss);
2037 if (! ((res.i == -1) && (res.j == -2)))
2047 typedef SmallStruct4 (STDCALL *SmallStructDelegate4) (SmallStruct4 ss);
2049 LIBTEST_API int STDCALL
2050 mono_test_marshal_small_struct_delegate4 (SmallStructDelegate4 delegate)
2052 SmallStruct4 ss, res;
2056 res = delegate (ss);
2057 if (! (res.i == -1))
2067 typedef SmallStruct5 (STDCALL *SmallStructDelegate5) (SmallStruct5 ss);
2069 LIBTEST_API int STDCALL
2070 mono_test_marshal_small_struct_delegate5 (SmallStructDelegate5 delegate)
2072 SmallStruct5 ss, res;
2076 res = delegate (ss);
2077 if (! (res.i == -5))
2087 typedef SmallStruct6 (STDCALL *SmallStructDelegate6) (SmallStruct6 ss);
2089 LIBTEST_API int STDCALL
2090 mono_test_marshal_small_struct_delegate6 (SmallStructDelegate6 delegate)
2092 SmallStruct6 ss, res;
2097 res = delegate (ss);
2098 if (! ((res.i == -1) && (res.j == -2)))
2109 typedef SmallStruct7 (STDCALL *SmallStructDelegate7) (SmallStruct7 ss);
2111 LIBTEST_API int STDCALL
2112 mono_test_marshal_small_struct_delegate7 (SmallStructDelegate7 delegate)
2114 SmallStruct7 ss, res;
2119 res = delegate (ss);
2120 if (! ((res.i == -1) && (res.j == -2)))
2130 typedef SmallStruct8 (STDCALL *SmallStructDelegate8) (SmallStruct8 ss);
2132 LIBTEST_API int STDCALL
2133 mono_test_marshal_small_struct_delegate8 (SmallStructDelegate8 delegate)
2135 SmallStruct8 ss, res;
2139 res = delegate (ss);
2140 if (! ((res.i == -1.0)))
2150 typedef SmallStruct9 (STDCALL *SmallStructDelegate9) (SmallStruct9 ss);
2152 LIBTEST_API int STDCALL
2153 mono_test_marshal_small_struct_delegate9 (SmallStructDelegate9 delegate)
2155 SmallStruct9 ss, res;
2159 res = delegate (ss);
2160 if (! ((res.i == -1.0)))
2170 typedef SmallStruct10 (STDCALL *SmallStructDelegate10) (SmallStruct10 ss);
2172 LIBTEST_API int STDCALL
2173 mono_test_marshal_small_struct_delegate10 (SmallStructDelegate10 delegate)
2175 SmallStruct10 ss, res;
2180 res = delegate (ss);
2181 if (! ((res.i == -1.0) && (res.j == -2.0)))
2192 typedef SmallStruct11 (STDCALL *SmallStructDelegate11) (SmallStruct11 ss);
2194 LIBTEST_API int STDCALL
2195 mono_test_marshal_small_struct_delegate11 (SmallStructDelegate11 delegate)
2197 SmallStruct11 ss, res;
2202 res = delegate (ss);
2203 if (! ((res.i == -1.0) && (res.j == -2)))
2209 typedef int (STDCALL *ArrayDelegate) (int i, char *j, void *arr);
2211 LIBTEST_API int STDCALL
2212 mono_test_marshal_array_delegate (void *arr, int len, ArrayDelegate del)
2214 return del (len, NULL, arr);
2217 typedef int (STDCALL *ArrayDelegateLong) (gint64 i, char *j, void *arr);
2219 LIBTEST_API int STDCALL
2220 mono_test_marshal_array_delegate_long (void *arr, gint64 len, ArrayDelegateLong del)
2222 return del (len, NULL, arr);
2225 LIBTEST_API int STDCALL
2226 mono_test_marshal_out_array_delegate (int *arr, int len, ArrayDelegate del)
2228 del (len, NULL, arr);
2230 if ((arr [0] != 1) || (arr [1] != 2))
2236 typedef gunichar2* (STDCALL *UnicodeStringDelegate) (gunichar2 *message);
2238 LIBTEST_API int STDCALL
2239 mono_test_marshal_return_unicode_string_delegate (UnicodeStringDelegate del)
2241 const char m[] = "abcdef";
2242 gunichar2 *s2, *res;
2245 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
2254 LIBTEST_API int STDCALL
2255 mono_test_marshal_out_string_array_delegate (char **arr, int len, ArrayDelegate del)
2257 del (len, NULL, arr);
2259 if (!strcmp (arr [0], "ABC") && !strcmp (arr [1], "DEF"))
2265 typedef int (*CdeclDelegate) (int i, int j);
2267 LIBTEST_API int STDCALL
2268 mono_test_marshal_cdecl_delegate (CdeclDelegate del)
2272 for (i = 0; i < 1000; ++i)
2278 typedef char** (STDCALL *ReturnStringArrayDelegate) (int i);
2280 LIBTEST_API int STDCALL
2281 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d)
2289 if (strcmp (arr [0], "ABC") || strcmp (arr [1], "DEF"))
2299 typedef int (STDCALL *ByrefStringDelegate) (char **s);
2301 LIBTEST_API int STDCALL
2302 mono_test_marshal_byref_string_delegate (ByrefStringDelegate d)
2304 char *s = (char*)"ABC";
2311 if (!strcmp (s, "DEF"))
2321 LIBTEST_API int STDCALL
2322 add_delegate (int i, int j)
2327 LIBTEST_API gpointer STDCALL
2328 mono_test_marshal_return_fnptr (void)
2330 return &add_delegate;
2333 LIBTEST_API int STDCALL
2336 printf ("codigo %x\n", code);
2344 LIBTEST_API HandleRef STDCALL
2345 mono_xr_as_handle (int code)
2349 memset (&ref, 0, sizeof (ref));
2361 LIBTEST_API int STDCALL
2362 mono_safe_handle_struct_ref (HandleStructs *x)
2364 printf ("Dingus Ref! \n");
2365 printf ("Values: %d %d %p %p\n", x->a, x->b, x->handle1, x->handle2);
2371 if (x->handle1 != (void*) 0x7080feed)
2374 if (x->handle2 != (void*) 0x1234abcd)
2380 LIBTEST_API int STDCALL
2381 mono_safe_handle_struct (HandleStructs x)
2383 printf ("Dingus Standard! \n");
2384 printf ("Values: %d %d %p %p\n", x.a, x.b, x.handle1, x.handle2);
2390 if (x.handle1 != (void*) 0x7080feed)
2393 if (x.handle2 != (void*) 0x1234abcd)
2403 LIBTEST_API int STDCALL
2404 mono_safe_handle_struct_simple (TrivialHandle x)
2406 printf ("The value is %p\n", x.a);
2407 return ((int)(gsize)x.a) * 2;
2410 LIBTEST_API int STDCALL
2411 mono_safe_handle_return (void)
2416 LIBTEST_API void STDCALL
2417 mono_safe_handle_ref (void **handle)
2420 *handle = (void *) 0xbad;
2424 *handle = (void *) 0x800d;
2427 LIBTEST_API double STDCALL
2428 mono_test_marshal_date_time (double d, double *d2)
2500 VT_USERDEFINED = 29,
2508 VT_STREAMED_OBJECT = 68,
2509 VT_STORED_OBJECT = 69,
2510 VT_BLOB_OBJECT = 70,
2518 void VariantInit(VARIANT* vt)
2535 LIBTEST_API int STDCALL
2536 mono_test_marshal_bstr_in(gunichar2* bstr)
2539 gchar* bstr_utf8 = g_utf16_to_utf8 (bstr, -1, NULL, NULL, NULL);
2540 result = strcmp("mono_test_marshal_bstr_in", bstr_utf8);
2547 LIBTEST_API int STDCALL
2548 mono_test_marshal_bstr_out(gunichar2** bstr)
2550 *bstr = marshal_bstr_alloc ("mono_test_marshal_bstr_out");
2554 LIBTEST_API int STDCALL
2555 mono_test_marshal_bstr_in_null(gunichar2* bstr)
2562 LIBTEST_API int STDCALL
2563 mono_test_marshal_bstr_out_null(gunichar2** bstr)
2569 LIBTEST_API int STDCALL
2570 mono_test_marshal_variant_in_sbyte(VARIANT variant)
2572 if (variant.vt == VT_I1 && variant.cVal == 100)
2577 LIBTEST_API int STDCALL
2578 mono_test_marshal_variant_in_byte(VARIANT variant)
2580 if (variant.vt == VT_UI1 && variant.bVal == 100)
2585 LIBTEST_API int STDCALL
2586 mono_test_marshal_variant_in_short(VARIANT variant)
2588 if (variant.vt == VT_I2 && variant.iVal == 314)
2593 LIBTEST_API int STDCALL
2594 mono_test_marshal_variant_in_ushort(VARIANT variant)
2596 if (variant.vt == VT_UI2 && variant.uiVal == 314)
2601 LIBTEST_API int STDCALL
2602 mono_test_marshal_variant_in_int(VARIANT variant)
2604 if (variant.vt == VT_I4 && variant.lVal == 314)
2609 LIBTEST_API int STDCALL
2610 mono_test_marshal_variant_in_uint(VARIANT variant)
2612 if (variant.vt == VT_UI4 && variant.ulVal == 314)
2617 LIBTEST_API int STDCALL
2618 mono_test_marshal_variant_in_long(VARIANT variant)
2620 if (variant.vt == VT_I8 && variant.llVal == 314)
2625 LIBTEST_API int STDCALL
2626 mono_test_marshal_variant_in_ulong(VARIANT variant)
2628 if (variant.vt == VT_UI8 && variant.ullVal == 314)
2633 LIBTEST_API int STDCALL
2634 mono_test_marshal_variant_in_float(VARIANT variant)
2636 if (variant.vt == VT_R4 && (variant.fltVal - 3.14)/3.14 < .001)
2641 LIBTEST_API int STDCALL
2642 mono_test_marshal_variant_in_double(VARIANT variant)
2644 if (variant.vt == VT_R8 && (variant.dblVal - 3.14)/3.14 < .001)
2649 LIBTEST_API int STDCALL
2650 mono_test_marshal_variant_in_bstr(VARIANT variant)
2653 gchar* bstr_utf8 = g_utf16_to_utf8 (variant.bstrVal, -1, NULL, NULL, NULL);
2654 result = strcmp("PI", bstr_utf8);
2657 if (variant.vt == VT_BSTR && !result)
2662 LIBTEST_API int STDCALL
2663 mono_test_marshal_variant_in_bool_true (VARIANT variant)
2665 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_TRUE)
2670 LIBTEST_API int STDCALL
2671 mono_test_marshal_variant_in_bool_false (VARIANT variant)
2673 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_FALSE)
2678 LIBTEST_API int STDCALL
2679 mono_test_marshal_variant_out_sbyte(VARIANT* variant)
2681 variant->vt = VT_I1;
2682 variant->cVal = 100;
2687 LIBTEST_API int STDCALL
2688 mono_test_marshal_variant_out_sbyte_byref(VARIANT* variant)
2690 variant->vt = VT_I1|VT_BYREF;
2691 variant->byref = marshal_alloc(1);
2692 *((gint8*)variant->byref) = 100;
2697 LIBTEST_API int STDCALL
2698 mono_test_marshal_variant_out_byte(VARIANT* variant)
2700 variant->vt = VT_UI1;
2701 variant->bVal = 100;
2706 LIBTEST_API int STDCALL
2707 mono_test_marshal_variant_out_byte_byref(VARIANT* variant)
2709 variant->vt = VT_UI1|VT_BYREF;
2710 variant->byref = marshal_alloc(1);
2711 *((gint8*)variant->byref) = 100;
2716 LIBTEST_API int STDCALL
2717 mono_test_marshal_variant_out_short(VARIANT* variant)
2719 variant->vt = VT_I2;
2720 variant->iVal = 314;
2725 LIBTEST_API int STDCALL
2726 mono_test_marshal_variant_out_short_byref(VARIANT* variant)
2728 variant->vt = VT_I2|VT_BYREF;
2729 variant->byref = marshal_alloc(2);
2730 *((gint16*)variant->byref) = 314;
2735 LIBTEST_API int STDCALL
2736 mono_test_marshal_variant_out_ushort(VARIANT* variant)
2738 variant->vt = VT_UI2;
2739 variant->uiVal = 314;
2744 LIBTEST_API int STDCALL
2745 mono_test_marshal_variant_out_ushort_byref(VARIANT* variant)
2747 variant->vt = VT_UI2|VT_BYREF;
2748 variant->byref = marshal_alloc(2);
2749 *((guint16*)variant->byref) = 314;
2754 LIBTEST_API int STDCALL
2755 mono_test_marshal_variant_out_int(VARIANT* variant)
2757 variant->vt = VT_I4;
2758 variant->lVal = 314;
2763 LIBTEST_API int STDCALL
2764 mono_test_marshal_variant_out_int_byref(VARIANT* variant)
2766 variant->vt = VT_I4|VT_BYREF;
2767 variant->byref = marshal_alloc(4);
2768 *((gint32*)variant->byref) = 314;
2773 LIBTEST_API int STDCALL
2774 mono_test_marshal_variant_out_uint(VARIANT* variant)
2776 variant->vt = VT_UI4;
2777 variant->ulVal = 314;
2782 LIBTEST_API int STDCALL
2783 mono_test_marshal_variant_out_uint_byref(VARIANT* variant)
2785 variant->vt = VT_UI4|VT_BYREF;
2786 variant->byref = marshal_alloc(4);
2787 *((guint32*)variant->byref) = 314;
2792 LIBTEST_API int STDCALL
2793 mono_test_marshal_variant_out_long(VARIANT* variant)
2795 variant->vt = VT_I8;
2796 variant->llVal = 314;
2801 LIBTEST_API int STDCALL
2802 mono_test_marshal_variant_out_long_byref(VARIANT* variant)
2804 variant->vt = VT_I8|VT_BYREF;
2805 variant->byref = marshal_alloc(8);
2806 *((gint64*)variant->byref) = 314;
2811 LIBTEST_API int STDCALL
2812 mono_test_marshal_variant_out_ulong(VARIANT* variant)
2814 variant->vt = VT_UI8;
2815 variant->ullVal = 314;
2820 LIBTEST_API int STDCALL
2821 mono_test_marshal_variant_out_ulong_byref(VARIANT* variant)
2823 variant->vt = VT_UI8|VT_BYREF;
2824 variant->byref = marshal_alloc(8);
2825 *((guint64*)variant->byref) = 314;
2830 LIBTEST_API int STDCALL
2831 mono_test_marshal_variant_out_float(VARIANT* variant)
2833 variant->vt = VT_R4;
2834 variant->fltVal = 3.14;
2839 LIBTEST_API int STDCALL
2840 mono_test_marshal_variant_out_float_byref(VARIANT* variant)
2842 variant->vt = VT_R4|VT_BYREF;
2843 variant->byref = marshal_alloc(4);
2844 *((float*)variant->byref) = 3.14;
2849 LIBTEST_API int STDCALL
2850 mono_test_marshal_variant_out_double(VARIANT* variant)
2852 variant->vt = VT_R8;
2853 variant->dblVal = 3.14;
2858 LIBTEST_API int STDCALL
2859 mono_test_marshal_variant_out_double_byref(VARIANT* variant)
2861 variant->vt = VT_R8|VT_BYREF;
2862 variant->byref = marshal_alloc(8);
2863 *((double*)variant->byref) = 3.14;
2868 LIBTEST_API int STDCALL
2869 mono_test_marshal_variant_out_bstr(VARIANT* variant)
2871 variant->vt = VT_BSTR;
2872 variant->bstrVal = marshal_bstr_alloc("PI");
2877 LIBTEST_API int STDCALL
2878 mono_test_marshal_variant_out_bstr_byref(VARIANT* variant)
2880 variant->vt = VT_BSTR|VT_BYREF;
2881 variant->byref = marshal_alloc(sizeof(gpointer));
2882 *((gunichar**)variant->byref) = (gunichar*)marshal_bstr_alloc("PI");
2887 LIBTEST_API int STDCALL
2888 mono_test_marshal_variant_out_bool_true (VARIANT* variant)
2890 variant->vt = VT_BOOL;
2891 variant->boolVal = VARIANT_TRUE;
2896 LIBTEST_API int STDCALL
2897 mono_test_marshal_variant_out_bool_true_byref (VARIANT* variant)
2899 variant->vt = VT_BOOL|VT_BYREF;
2900 variant->byref = marshal_alloc(2);
2901 *((gint16*)variant->byref) = VARIANT_TRUE;
2906 LIBTEST_API int STDCALL
2907 mono_test_marshal_variant_out_bool_false (VARIANT* variant)
2909 variant->vt = VT_BOOL;
2910 variant->boolVal = VARIANT_FALSE;
2915 LIBTEST_API int STDCALL
2916 mono_test_marshal_variant_out_bool_false_byref (VARIANT* variant)
2918 variant->vt = VT_BOOL|VT_BYREF;
2919 variant->byref = marshal_alloc(2);
2920 *((gint16*)variant->byref) = VARIANT_FALSE;
2925 typedef int (STDCALL *VarFunc) (int vt, VARIANT variant);
2926 typedef int (STDCALL *VarRefFunc) (int vt, VARIANT* variant);
2928 LIBTEST_API int STDCALL
2929 mono_test_marshal_variant_in_sbyte_unmanaged(VarFunc func)
2934 return func (VT_I1, vt);
2937 LIBTEST_API int STDCALL
2938 mono_test_marshal_variant_in_byte_unmanaged(VarFunc func)
2943 return func (VT_UI1, vt);
2946 LIBTEST_API int STDCALL
2947 mono_test_marshal_variant_in_short_unmanaged(VarFunc func)
2952 return func (VT_I2, vt);
2955 LIBTEST_API int STDCALL
2956 mono_test_marshal_variant_in_ushort_unmanaged(VarFunc func)
2961 return func (VT_UI2, vt);
2964 LIBTEST_API int STDCALL
2965 mono_test_marshal_variant_in_int_unmanaged(VarFunc func)
2970 return func (VT_I4, vt);
2973 LIBTEST_API int STDCALL
2974 mono_test_marshal_variant_in_uint_unmanaged(VarFunc func)
2979 return func (VT_UI4, vt);
2982 LIBTEST_API int STDCALL
2983 mono_test_marshal_variant_in_long_unmanaged(VarFunc func)
2988 return func (VT_I8, vt);
2991 LIBTEST_API int STDCALL
2992 mono_test_marshal_variant_in_ulong_unmanaged(VarFunc func)
2997 return func (VT_UI8, vt);
3000 LIBTEST_API int STDCALL
3001 mono_test_marshal_variant_in_float_unmanaged(VarFunc func)
3006 return func (VT_R4, vt);
3009 LIBTEST_API int STDCALL
3010 mono_test_marshal_variant_in_double_unmanaged(VarFunc func)
3015 return func (VT_R8, vt);
3018 LIBTEST_API int STDCALL
3019 mono_test_marshal_variant_in_bstr_unmanaged(VarFunc func)
3023 vt.bstrVal = marshal_bstr_alloc("PI");
3024 return func (VT_BSTR, vt);
3027 LIBTEST_API int STDCALL
3028 mono_test_marshal_variant_in_bool_true_unmanaged(VarFunc func)
3032 vt.boolVal = VARIANT_TRUE;
3033 return func (VT_BOOL, vt);
3036 LIBTEST_API int STDCALL
3037 mono_test_marshal_variant_in_bool_false_unmanaged(VarFunc func)
3041 vt.boolVal = VARIANT_FALSE;
3042 return func (VT_BOOL, vt);
3045 LIBTEST_API int STDCALL
3046 mono_test_marshal_variant_out_sbyte_unmanaged(VarRefFunc func)
3051 if (vt.vt == VT_I1 && vt.cVal == -100)
3056 LIBTEST_API int STDCALL
3057 mono_test_marshal_variant_out_byte_unmanaged(VarRefFunc func)
3062 if (vt.vt == VT_UI1 && vt.bVal == 100)
3067 LIBTEST_API int STDCALL
3068 mono_test_marshal_variant_out_short_unmanaged(VarRefFunc func)
3073 if (vt.vt == VT_I2 && vt.iVal == -100)
3078 LIBTEST_API int STDCALL
3079 mono_test_marshal_variant_out_ushort_unmanaged(VarRefFunc func)
3084 if (vt.vt == VT_UI2 && vt.uiVal == 100)
3089 LIBTEST_API int STDCALL
3090 mono_test_marshal_variant_out_int_unmanaged(VarRefFunc func)
3095 if (vt.vt == VT_I4 && vt.lVal == -100)
3100 LIBTEST_API int STDCALL
3101 mono_test_marshal_variant_out_uint_unmanaged(VarRefFunc func)
3106 if (vt.vt == VT_UI4 && vt.ulVal == 100)
3111 LIBTEST_API int STDCALL
3112 mono_test_marshal_variant_out_long_unmanaged(VarRefFunc func)
3117 if (vt.vt == VT_I8 && vt.llVal == -100)
3122 LIBTEST_API int STDCALL
3123 mono_test_marshal_variant_out_ulong_unmanaged(VarRefFunc func)
3128 if (vt.vt == VT_UI8 && vt.ullVal == 100)
3133 LIBTEST_API int STDCALL
3134 mono_test_marshal_variant_out_float_unmanaged(VarRefFunc func)
3139 if (vt.vt == VT_R4 && fabs (vt.fltVal - 3.14f) < 1e-10)
3144 LIBTEST_API int STDCALL
3145 mono_test_marshal_variant_out_double_unmanaged(VarRefFunc func)
3150 if (vt.vt == VT_R8 && fabs (vt.dblVal - 3.14) < 1e-10)
3155 LIBTEST_API int STDCALL
3156 mono_test_marshal_variant_out_bstr_unmanaged(VarRefFunc func)
3164 func (VT_BSTR, &vt);
3165 bstr_utf8 = g_utf16_to_utf8 (vt.bstrVal, -1, NULL, NULL, NULL);
3166 result = strcmp("PI", bstr_utf8);
3168 if (vt.vt == VT_BSTR && !result)
3173 LIBTEST_API int STDCALL
3174 mono_test_marshal_variant_out_bool_true_unmanaged(VarRefFunc func)
3178 func (VT_BOOL, &vt);
3179 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3184 LIBTEST_API int STDCALL
3185 mono_test_marshal_variant_out_bool_false_unmanaged(VarRefFunc func)
3189 func (VT_BOOL, &vt);
3190 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3195 typedef struct MonoComObject MonoComObject;
3199 int (STDCALL *QueryInterface)(MonoComObject* pUnk, gpointer riid, gpointer* ppv);
3200 int (STDCALL *AddRef)(MonoComObject* pUnk);
3201 int (STDCALL *Release)(MonoComObject* pUnk);
3202 int (STDCALL *get_ITest)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3203 int (STDCALL *SByteIn)(MonoComObject* pUnk, char a);
3204 int (STDCALL *ByteIn)(MonoComObject* pUnk, unsigned char a);
3205 int (STDCALL *ShortIn)(MonoComObject* pUnk, short a);
3206 int (STDCALL *UShortIn)(MonoComObject* pUnk, unsigned short a);
3207 int (STDCALL *IntIn)(MonoComObject* pUnk, int a);
3208 int (STDCALL *UIntIn)(MonoComObject* pUnk, unsigned int a);
3209 int (STDCALL *LongIn)(MonoComObject* pUnk, gint64 a);
3210 int (STDCALL *ULongIn)(MonoComObject* pUnk, guint64 a);
3211 int (STDCALL *FloatIn)(MonoComObject* pUnk, float a);
3212 int (STDCALL *DoubleIn)(MonoComObject* pUnk, double a);
3213 int (STDCALL *ITestIn)(MonoComObject* pUnk, MonoComObject* pUnk2);
3214 int (STDCALL *ITestOut)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3217 struct MonoComObject
3223 static GUID IID_ITest = {0, 0, 0, {0,0,0,0,0,0,0,1}};
3224 static GUID IID_IMonoUnknown = {0, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3225 static GUID IID_IMonoDispatch = {0x00020400, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3227 LIBTEST_API int STDCALL
3228 MonoQueryInterface(MonoComObject* pUnk, gpointer riid, gpointer* ppv)
3232 if (!memcmp(riid, &IID_IMonoUnknown, sizeof(GUID))) {
3236 else if (!memcmp(riid, &IID_ITest, sizeof(GUID))) {
3240 else if (!memcmp(riid, &IID_IMonoDispatch, sizeof(GUID))) {
3244 return 0x80004002; //E_NOINTERFACE;
3247 LIBTEST_API int STDCALL
3248 MonoAddRef(MonoComObject* pUnk)
3250 return ++(pUnk->m_ref);
3253 LIBTEST_API int STDCALL
3254 MonoRelease(MonoComObject* pUnk)
3256 return --(pUnk->m_ref);
3259 LIBTEST_API int STDCALL
3260 SByteIn(MonoComObject* pUnk, char a)
3265 LIBTEST_API int STDCALL
3266 ByteIn(MonoComObject* pUnk, unsigned char a)
3271 LIBTEST_API int STDCALL
3272 ShortIn(MonoComObject* pUnk, short a)
3277 LIBTEST_API int STDCALL
3278 UShortIn(MonoComObject* pUnk, unsigned short a)
3283 LIBTEST_API int STDCALL
3284 IntIn(MonoComObject* pUnk, int a)
3289 LIBTEST_API int STDCALL
3290 UIntIn(MonoComObject* pUnk, unsigned int a)
3295 LIBTEST_API int STDCALL
3296 LongIn(MonoComObject* pUnk, gint64 a)
3301 LIBTEST_API int STDCALL
3302 ULongIn(MonoComObject* pUnk, guint64 a)
3307 LIBTEST_API int STDCALL
3308 FloatIn(MonoComObject* pUnk, float a)
3313 LIBTEST_API int STDCALL
3314 DoubleIn(MonoComObject* pUnk, double a)
3319 LIBTEST_API int STDCALL
3320 ITestIn(MonoComObject* pUnk, MonoComObject *pUnk2)
3325 LIBTEST_API int STDCALL
3326 ITestOut(MonoComObject* pUnk, MonoComObject* *ppUnk)
3331 static void create_com_object (MonoComObject** pOut);
3333 LIBTEST_API int STDCALL
3334 get_ITest(MonoComObject* pUnk, MonoComObject* *ppUnk)
3336 create_com_object (ppUnk);
3340 static void create_com_object (MonoComObject** pOut)
3342 *pOut = marshal_new0 (MonoComObject, 1);
3343 (*pOut)->vtbl = marshal_new0 (MonoIUnknown, 1);
3346 (*pOut)->vtbl->QueryInterface = MonoQueryInterface;
3347 (*pOut)->vtbl->AddRef = MonoAddRef;
3348 (*pOut)->vtbl->Release = MonoRelease;
3349 (*pOut)->vtbl->SByteIn = SByteIn;
3350 (*pOut)->vtbl->ByteIn = ByteIn;
3351 (*pOut)->vtbl->ShortIn = ShortIn;
3352 (*pOut)->vtbl->UShortIn = UShortIn;
3353 (*pOut)->vtbl->IntIn = IntIn;
3354 (*pOut)->vtbl->UIntIn = UIntIn;
3355 (*pOut)->vtbl->LongIn = LongIn;
3356 (*pOut)->vtbl->ULongIn = ULongIn;
3357 (*pOut)->vtbl->FloatIn = FloatIn;
3358 (*pOut)->vtbl->DoubleIn = DoubleIn;
3359 (*pOut)->vtbl->ITestIn = ITestIn;
3360 (*pOut)->vtbl->ITestOut = ITestOut;
3361 (*pOut)->vtbl->get_ITest = get_ITest;
3364 static MonoComObject* same_object = NULL;
3366 LIBTEST_API int STDCALL
3367 mono_test_marshal_com_object_create(MonoComObject* *pUnk)
3369 create_com_object (pUnk);
3372 same_object = *pUnk;
3377 LIBTEST_API int STDCALL
3378 mono_test_marshal_com_object_same(MonoComObject* *pUnk)
3380 *pUnk = same_object;
3385 LIBTEST_API int STDCALL
3386 mono_test_marshal_com_object_destroy(MonoComObject *pUnk)
3388 int ref = --(pUnk->m_ref);
3395 LIBTEST_API int STDCALL
3396 mono_test_marshal_com_object_ref_count(MonoComObject *pUnk)
3401 LIBTEST_API int STDCALL
3402 mono_test_marshal_ccw_itest (MonoComObject *pUnk)
3405 MonoComObject* pTest;
3410 hr = pUnk->vtbl->SByteIn (pUnk, -100);
3413 hr = pUnk->vtbl->ByteIn (pUnk, 100);
3416 hr = pUnk->vtbl->ShortIn (pUnk, -100);
3419 hr = pUnk->vtbl->UShortIn (pUnk, 100);
3422 hr = pUnk->vtbl->IntIn (pUnk, -100);
3425 hr = pUnk->vtbl->UIntIn (pUnk, 100);
3428 hr = pUnk->vtbl->LongIn (pUnk, -100);
3431 hr = pUnk->vtbl->ULongIn (pUnk, 100);
3434 hr = pUnk->vtbl->FloatIn (pUnk, 3.14f);
3437 hr = pUnk->vtbl->DoubleIn (pUnk, 3.14);
3440 hr = pUnk->vtbl->ITestIn (pUnk, pUnk);
3443 hr = pUnk->vtbl->ITestOut (pUnk, &pTest);
3451 * mono_method_get_unmanaged_thunk tests
3454 #if defined(__GNUC__) && ((defined(__i386__) && (defined(__linux__) || defined (__APPLE__)) || defined (__FreeBSD__) || defined(__OpenBSD__)) || (defined(__ppc__) && defined(__APPLE__)))
3455 #define ALIGN(size) __attribute__ ((aligned(size)))
3461 /* thunks.cs:TestStruct */
3462 typedef struct _TestStruct {
3467 /* Searches for mono symbols in all loaded modules */
3469 lookup_mono_symbol (const char *symbol_name)
3472 if (g_module_symbol (g_module_open (NULL, G_MODULE_BIND_LAZY), symbol_name, &symbol))
3478 LIBTEST_API gpointer STDCALL
3479 mono_test_marshal_lookup_symbol (const char *symbol_name)
3481 return lookup_mono_symbol (symbol_name);
3485 * test_method_thunk:
3487 * @test_id: the test number
3488 * @test_method_handle: MonoMethod* of the C# test method
3489 * @create_object_method_handle: MonoMethod* of thunks.cs:Test.CreateObject
3491 LIBTEST_API int STDCALL
3492 test_method_thunk (int test_id, gpointer test_method_handle, gpointer create_object_method_handle)
3494 gpointer (*mono_method_get_unmanaged_thunk)(gpointer)
3495 = lookup_mono_symbol ("mono_method_get_unmanaged_thunk");
3497 gpointer (*mono_string_new_wrapper)(const char *)
3498 = lookup_mono_symbol ("mono_string_new_wrapper");
3500 char* (*mono_string_to_utf8)(gpointer)
3501 = lookup_mono_symbol ("mono_string_to_utf8");
3503 gpointer (*mono_object_unbox)(gpointer)
3504 = lookup_mono_symbol ("mono_object_unbox");
3506 gpointer test_method, ex = NULL;
3507 gpointer (STDCALL *CreateObject)(gpointer*);
3510 if (!mono_method_get_unmanaged_thunk)
3513 test_method = mono_method_get_unmanaged_thunk (test_method_handle);
3517 CreateObject = mono_method_get_unmanaged_thunk (create_object_method_handle);
3525 /* thunks.cs:Test.Test0 */
3526 void (STDCALL *F)(gpointer*) = test_method;
3532 /* thunks.cs:Test.Test1 */
3533 int (STDCALL *F)(gpointer*) = test_method;
3540 /* thunks.cs:Test.Test2 */
3541 gpointer (STDCALL *F)(gpointer, gpointer*) = test_method;
3542 gpointer str = mono_string_new_wrapper ("foo");
3543 if (str != F (str, &ex))
3549 /* thunks.cs:Test.Test3 */
3550 gpointer (STDCALL *F)(gpointer, gpointer, gpointer*);
3555 obj = CreateObject (&ex);
3556 str = mono_string_new_wrapper ("bar");
3558 if (str != F (obj, str, &ex))
3564 /* thunks.cs:Test.Test4 */
3565 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3570 obj = CreateObject (&ex);
3571 str = mono_string_new_wrapper ("bar");
3573 if (42 != F (obj, str, 42, &ex))
3580 /* thunks.cs:Test.Test5 */
3581 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3586 obj = CreateObject (&ex);
3587 str = mono_string_new_wrapper ("bar");
3589 F (obj, str, 42, &ex);
3597 /* thunks.cs:Test.Test6 */
3598 int (STDCALL *F)(gpointer, guint8, gint16, gint32, gint64, float, double,
3599 gpointer, gpointer*);
3601 gpointer str = mono_string_new_wrapper ("Test6");
3605 obj = CreateObject (&ex);
3607 res = F (obj, 254, 32700, -245378, 6789600, 3.1415, 3.1415, str, &ex);
3618 /* thunks.cs:Test.Test7 */
3619 gint64 (STDCALL *F)(gpointer*) = test_method;
3620 if (F (&ex) != G_MAXINT64)
3626 /* thunks.cs:Test.Test8 */
3627 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3628 gpointer*, gpointer*);
3640 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3648 (fabs (a5 - 3.1415) < 0.001) &&
3649 (fabs (a6 - 3.1415) < 0.001) &&
3650 strcmp (mono_string_to_utf8 (a7), "Test8") == 0))
3657 /* thunks.cs:Test.Test9 */
3658 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3659 gpointer*, gpointer*);
3671 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3679 /* thunks.cs:Test.Test10 */
3680 void (STDCALL *F)(gpointer*, gpointer*);
3682 gpointer obj1, obj2;
3684 obj1 = obj2 = CreateObject (&ex);
3701 /* thunks.cs:TestStruct.Test0 */
3702 int (STDCALL *F)(gpointer*, gpointer*);
3708 obj = CreateObject (&ex);
3715 a1 = mono_object_unbox (obj);
3731 /* check whether the call was really by value */
3732 if (a1->A != 42 || a1->B != 3.1415)
3739 /* thunks.cs:TestStruct.Test1 */
3740 void (STDCALL *F)(gpointer, gpointer*);
3745 obj = CreateObject (&ex);
3752 a1 = mono_object_unbox (obj);
3765 if (!fabs (a1->B - 3.1415) < 0.001)
3772 /* thunks.cs:TestStruct.Test2 */
3773 gpointer (STDCALL *F)(gpointer*);
3787 a1 = mono_object_unbox (obj);
3792 if (!fabs (a1->B - 3.1415) < 0.001)
3799 /* thunks.cs:TestStruct.Test3 */
3800 void (STDCALL *F)(gpointer, gpointer*);
3805 obj = CreateObject (&ex);
3812 a1 = mono_object_unbox (obj);
3848 LIBTEST_API int STDCALL
3849 mono_test_Winx64_struct1_in (winx64_struct1 var)
3862 LIBTEST_API int STDCALL
3863 mono_test_Winx64_struct2_in (winx64_struct2 var)
3880 LIBTEST_API int STDCALL
3881 mono_test_Winx64_struct3_in (winx64_struct3 var)
3887 if (var.c != 0x1234)
3900 LIBTEST_API int STDCALL
3901 mono_test_Winx64_struct4_in (winx64_struct4 var)
3907 if (var.c != 0x1234)
3909 if (var.d != 0x87654321)
3921 LIBTEST_API int STDCALL
3922 mono_test_Winx64_struct5_in (winx64_struct5 var)
3940 LIBTEST_API int STDCALL
3941 mono_test_Winx64_struct6_in (winx64_struct6 var)
3952 LIBTEST_API int STDCALL
3953 mono_test_Winx64_structs_in1 (winx64_struct1 var1,
3954 winx64_struct2 var2,
3955 winx64_struct3 var3,
3956 winx64_struct4 var4)
3970 if (var3.c != 0x1234)
3977 if (var4.c != 0x1234)
3979 if (var4.d != 0x87654321)
3984 LIBTEST_API int STDCALL
3985 mono_test_Winx64_structs_in2 (winx64_struct1 var1,
3986 winx64_struct1 var2,
3987 winx64_struct1 var3,
3988 winx64_struct1 var4,
3989 winx64_struct1 var5)
4005 LIBTEST_API int STDCALL
4006 mono_test_Winx64_structs_in3 (winx64_struct1 var1,
4007 winx64_struct5 var2,
4008 winx64_struct1 var3,
4009 winx64_struct5 var4,
4010 winx64_struct1 var5,
4011 winx64_struct5 var6)
4046 LIBTEST_API winx64_struct1 STDCALL
4047 mono_test_Winx64_struct1_ret (void)
4054 LIBTEST_API winx64_struct2 STDCALL
4055 mono_test_Winx64_struct2_ret (void)
4063 LIBTEST_API winx64_struct3 STDCALL
4064 mono_test_Winx64_struct3_ret (void)
4073 LIBTEST_API winx64_struct4 STDCALL
4074 mono_test_Winx64_struct4_ret (void)
4084 LIBTEST_API winx64_struct5 STDCALL
4085 mono_test_Winx64_struct5_ret (void)
4094 LIBTEST_API winx64_struct1 STDCALL
4095 mono_test_Winx64_struct1_ret_5_args (char a, char b, char c, char d, char e)
4098 ret.a = a + b + c + d + e;
4102 LIBTEST_API winx64_struct5 STDCALL
4103 mono_test_Winx64_struct5_ret6_args (char a, char b, char c, char d, char e)
4116 } winx64_floatStruct;
4118 LIBTEST_API int STDCALL
4119 mono_test_Winx64_floatStruct (winx64_floatStruct a)
4121 if (a.a > 5.6 || a.a < 5.4)
4124 if (a.b > 9.6 || a.b < 9.4)
4133 } winx64_doubleStruct;
4135 LIBTEST_API int STDCALL
4136 mono_test_Winx64_doubleStruct (winx64_doubleStruct a)
4138 if (a.a > 5.6 || a.a < 5.4)
4144 typedef int (STDCALL *managed_struct1_delegate) (winx64_struct1 a);
4146 LIBTEST_API int STDCALL
4147 mono_test_managed_Winx64_struct1_in(managed_struct1_delegate func)
4154 typedef int (STDCALL *managed_struct5_delegate) (winx64_struct5 a);
4156 LIBTEST_API int STDCALL
4157 mono_test_managed_Winx64_struct5_in(managed_struct5_delegate func)
4166 typedef int (STDCALL *managed_struct1_struct5_delegate) (winx64_struct1 a, winx64_struct5 b,
4167 winx64_struct1 c, winx64_struct5 d,
4168 winx64_struct1 e, winx64_struct5 f);
4170 LIBTEST_API int STDCALL
4171 mono_test_managed_Winx64_struct1_struct5_in(managed_struct1_struct5_delegate func)
4173 winx64_struct1 a, c, e;
4174 winx64_struct5 b, d, f;
4176 b.a = 2; b.b = 3; b.c = 4;
4178 d.a = 6; d.b = 7; d.c = 8;
4180 f.a = 10; f.b = 11; f.c = 12;
4182 return func (a, b, c, d, e, f);
4185 typedef winx64_struct1 (STDCALL *managed_struct1_ret_delegate) (void);
4187 LIBTEST_API int STDCALL
4188 mono_test_Winx64_struct1_ret_managed (managed_struct1_ret_delegate func)
4200 typedef winx64_struct5 (STDCALL *managed_struct5_ret_delegate) (void);
4202 LIBTEST_API int STDCALL
4203 mono_test_Winx64_struct5_ret_managed (managed_struct5_ret_delegate func)
4219 LIBTEST_API int STDCALL
4220 mono_test_marshal_bool_in (int arg, unsigned int expected, unsigned int bDefaultMarsh, unsigned int bBoolCustMarsh,
4221 char bI1CustMarsh, unsigned char bU1CustMarsh, short bVBCustMarsh)
4225 if (bDefaultMarsh != expected)
4229 if (bBoolCustMarsh != expected)
4233 if (bI1CustMarsh != expected)
4237 if (bU1CustMarsh != expected)
4241 if (bVBCustMarsh != expected)
4250 LIBTEST_API int STDCALL
4251 mono_test_marshal_bool_out (int arg, unsigned int testVal, unsigned int* bDefaultMarsh, unsigned int* bBoolCustMarsh,
4252 char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh)
4258 *bDefaultMarsh = testVal;
4261 if (!bBoolCustMarsh)
4263 *bBoolCustMarsh = testVal;
4268 *bI1CustMarsh = (char)testVal;
4273 *bU1CustMarsh = (unsigned char)testVal;
4278 *bVBCustMarsh = (unsigned short)testVal;
4286 LIBTEST_API int STDCALL
4287 mono_test_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4288 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh,
4289 unsigned short* bVBCustMarsh)
4295 if (*bDefaultMarsh != expected)
4297 *bDefaultMarsh = testVal;
4300 if (!bBoolCustMarsh)
4302 if (*bBoolCustMarsh != expected)
4304 *bBoolCustMarsh = testVal;
4309 if (*bI1CustMarsh != expected)
4311 *bI1CustMarsh = (char)testVal;
4316 if (*bU1CustMarsh != expected)
4318 *bU1CustMarsh = (unsigned char)testVal;
4323 if (*bVBCustMarsh != expected)
4325 *bVBCustMarsh = (unsigned short)testVal;
4334 typedef int (STDCALL *MarshalBoolInDelegate) (int arg, unsigned int expected, unsigned int bDefaultMarsh,
4335 unsigned int bBoolCustMarsh, char bI1CustMarsh, unsigned char bU1CustMarsh, unsigned short bVBCustMarsh);
4337 LIBTEST_API int STDCALL
4338 mono_test_managed_marshal_bool_in (int arg, unsigned int expected, unsigned int testVal, MarshalBoolInDelegate pfcn)
4345 return pfcn (arg, expected, testVal, 0, 0, 0, 0);
4347 return pfcn (arg, expected, 0, testVal, 0, 0, 0);
4349 return pfcn (arg, expected, 0, 0, testVal, 0, 0);
4351 return pfcn (arg, expected, 0, 0, 0, testVal, 0);
4353 return pfcn (arg, expected, 0, 0, 0, 0, testVal);
4361 typedef int (STDCALL *MarshalBoolOutDelegate) (int arg, unsigned int expected, unsigned int* bDefaultMarsh,
4362 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4364 LIBTEST_API int STDCALL
4365 mono_test_managed_marshal_bool_out (int arg, unsigned int expected, unsigned int testVal, MarshalBoolOutDelegate pfcn)
4368 unsigned int lDefaultMarsh, lBoolCustMarsh;
4369 char lI1CustMarsh = 0;
4370 unsigned char lU1CustMarsh = 0;
4371 unsigned short lVBCustMarsh = 0;
4372 lDefaultMarsh = lBoolCustMarsh = 0;
4379 unsigned int ltVal = 0;
4380 ret = pfcn (arg, testVal, <Val, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4382 return 0x0100 + ret;
4383 if (expected != ltVal)
4388 unsigned int ltVal = 0;
4389 ret = pfcn (arg, testVal, &lDefaultMarsh, <Val, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4391 return 0x0300 + ret;
4392 if (expected != ltVal)
4398 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, <Val, &lU1CustMarsh, &lVBCustMarsh);
4400 return 0x0500 + ret;
4401 if (expected != ltVal)
4406 unsigned char ltVal = 0;
4407 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <Val, &lVBCustMarsh);
4409 return 0x0700 + ret;
4410 if (expected != ltVal)
4415 unsigned short ltVal = 0;
4416 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <Val);
4418 return 0x0900 + ret;
4419 if (expected != ltVal)
4430 typedef int (STDCALL *MarshalBoolRefDelegate) (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4431 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4433 LIBTEST_API int STDCALL
4434 mono_test_managed_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int outExpected,
4435 unsigned int outTestVal, MarshalBoolRefDelegate pfcn)
4438 unsigned int lDefaultMarsh, lBoolCustMarsh;
4439 char lI1CustMarsh = 0;
4440 unsigned char lU1CustMarsh = 0;
4441 unsigned short lVBCustMarsh = 0;
4442 lDefaultMarsh = lBoolCustMarsh = 0;
4450 unsigned int ltestVal = testVal;
4451 ret = pfcn (arg, expected, outTestVal, <estVal, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4453 return 0x0100 + ret;
4454 if (outExpected != ltestVal)
4460 unsigned int ltestVal = testVal;
4461 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, <estVal, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4463 return 0x0300 + ret;
4464 if (outExpected != ltestVal)
4470 char ltestVal = testVal;
4471 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, <estVal, &lU1CustMarsh, &lVBCustMarsh);
4473 return 0x0500 + ret;
4474 if (outExpected != ltestVal)
4480 unsigned char ltestVal = testVal;
4481 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <estVal, &lVBCustMarsh);
4483 return 0x0700 + ret;
4484 if (outExpected != ltestVal)
4490 unsigned short ltestVal = testVal;
4491 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <estVal);
4493 return 0x0900 + ret;
4494 if (outExpected != ltestVal)
4507 LIBTEST_API int STDCALL
4508 mono_test_marshal_safearray_out_1dim_vt_bstr_empty (SAFEARRAY** safearray)
4510 /* Create an empty one-dimensional array of variants */
4512 SAFEARRAYBOUND dimensions [1];
4514 dimensions [0].lLbound = 0;
4515 dimensions [0].cElements = 0;
4517 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4522 LIBTEST_API int STDCALL
4523 mono_test_marshal_safearray_out_1dim_vt_bstr (SAFEARRAY** safearray)
4525 /* Create a one-dimensional array of 10 variants filled with "0" to "9" */
4527 SAFEARRAYBOUND dimensions [1];
4533 dimensions [0].lLbound = 0;
4534 dimensions [0].cElements = 10;
4536 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4537 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4539 VariantInit (&vOut);
4541 _ltoa (i,buffer,10);
4542 vOut.bstrVal= marshal_bstr_alloc (buffer);
4544 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4545 VariantClear (&vOut);
4546 SafeArrayDestroy (pSA);
4549 VariantClear (&vOut);
4555 LIBTEST_API int STDCALL
4556 mono_test_marshal_safearray_out_2dim_vt_i4 (SAFEARRAY** safearray)
4558 /* Create a two-dimensional array of 4x3 variants filled with 11, 12, 13, etc. */
4560 SAFEARRAYBOUND dimensions [2];
4565 dimensions [0].lLbound = 0;
4566 dimensions [0].cElements = 4;
4567 dimensions [1].lLbound = 0;
4568 dimensions [1].cElements = 3;
4570 pSA= SafeArrayCreate(VT_VARIANT, 2, dimensions);
4571 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4572 for (j= dimensions [1].lLbound; j< (dimensions [1].cElements + dimensions [1].lLbound); j++) {
4574 VariantInit (&vOut);
4576 vOut.lVal = (i+1)*10+(j+1);
4579 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4580 VariantClear (&vOut);
4581 SafeArrayDestroy (pSA);
4584 VariantClear (&vOut); // does a deep destroy of source VARIANT
4591 LIBTEST_API int STDCALL
4592 mono_test_marshal_safearray_out_4dim_vt_i4 (SAFEARRAY** safearray)
4594 /* Create a four-dimensional array of 10x3x6x7 variants filled with their indices */
4595 /* Also use non zero lower bounds */
4597 SAFEARRAYBOUND dimensions [4];
4602 dimensions [0].lLbound = 15;
4603 dimensions [0].cElements = 10;
4604 dimensions [1].lLbound = 20;
4605 dimensions [1].cElements = 3;
4606 dimensions [2].lLbound = 5;
4607 dimensions [2].cElements = 6;
4608 dimensions [3].lLbound = 12;
4609 dimensions [3].cElements = 7;
4611 pSA= SafeArrayCreate (VT_VARIANT, 4, dimensions);
4613 SafeArrayAccessData (pSA, (void **)&pData);
4615 for (i= 0; i< 10*3*6*7; i++) {
4616 VariantInit(&pData [i]);
4617 pData [i].vt = VT_I4;
4620 SafeArrayUnaccessData (pSA);
4625 LIBTEST_API int STDCALL
4626 mono_test_marshal_safearray_in_byval_1dim_empty (SAFEARRAY* safearray)
4628 /* Check that array is one dimensional and empty */
4631 long lbound, ubound;
4633 dim = SafeArrayGetDim (safearray);
4637 SafeArrayGetLBound (safearray, 1, &lbound);
4638 SafeArrayGetUBound (safearray, 1, &ubound);
4640 if ((lbound > 0) || (ubound > 0))
4646 LIBTEST_API int STDCALL
4647 mono_test_marshal_safearray_in_byval_1dim_vt_i4 (SAFEARRAY* safearray)
4649 /* Check that array is one dimensional containing integers from 1 to 10 */
4652 long lbound, ubound;
4657 dim = SafeArrayGetDim (safearray);
4661 SafeArrayGetLBound (safearray, 1, &lbound);
4662 SafeArrayGetUBound (safearray, 1, &ubound);
4664 if ((lbound != 0) || (ubound != 9))
4667 SafeArrayAccessData (safearray, (void **)&pData);
4668 for (i= lbound; i <= ubound; i++) {
4669 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i + 1))
4672 SafeArrayUnaccessData (safearray);
4677 LIBTEST_API int STDCALL
4678 mono_test_marshal_safearray_in_byval_1dim_vt_mixed (SAFEARRAY* safearray)
4680 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4683 long lbound, ubound;
4690 VariantInit (&element);
4692 dim = SafeArrayGetDim (safearray);
4696 SafeArrayGetLBound (safearray, 1, &lbound);
4697 SafeArrayGetUBound (safearray, 1, &ubound);
4699 if ((lbound != 0) || (ubound != 12))
4702 SafeArrayAccessData (safearray, (void **)&pData);
4703 for (i= lbound; i <= ubound; i++) {
4704 if ((i%2 == 0) && (pData [i].vt != VT_I4))
4706 if ((i%2 == 1) && (pData [i].vt != VT_BSTR))
4708 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i))
4711 SafeArrayUnaccessData (safearray);
4713 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4718 SafeArrayPutElement (safearray, indices, &element);
4719 VariantClear (&element);
4724 LIBTEST_API int STDCALL
4725 mono_test_marshal_safearray_in_byval_2dim_vt_i4 (SAFEARRAY* safearray)
4727 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4730 long lbound1, ubound1, lbound2, ubound2;
4735 VariantInit (&element);
4737 dim = SafeArrayGetDim (safearray);
4741 SafeArrayGetLBound (safearray, 1, &lbound1);
4742 SafeArrayGetUBound (safearray, 1, &ubound1);
4744 if ((lbound1 != 0) || (ubound1 != 1))
4747 SafeArrayGetLBound (safearray, 2, &lbound2);
4748 SafeArrayGetUBound (safearray, 2, &ubound2);
4750 if ((lbound2 != 0) || (ubound2 != 3)) {
4754 for (i= lbound1; i <= ubound1; i++) {
4756 for (j= lbound2; j <= ubound2; j++) {
4758 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4760 failed = ((element.vt != VT_I4) || (element.lVal != 10*(i+1)+(j+1)));
4761 VariantClear (&element);
4767 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4773 SafeArrayPutElement (safearray, indices, &element);
4774 VariantClear (&element);
4779 LIBTEST_API int STDCALL
4780 mono_test_marshal_safearray_in_byval_3dim_vt_bstr (SAFEARRAY* safearray)
4782 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4785 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4786 long i, j, k, failed;
4790 VariantInit (&element);
4792 dim = SafeArrayGetDim (safearray);
4796 SafeArrayGetLBound (safearray, 1, &lbound1);
4797 SafeArrayGetUBound (safearray, 1, &ubound1);
4799 if ((lbound1 != 0) || (ubound1 != 1))
4802 SafeArrayGetLBound (safearray, 2, &lbound2);
4803 SafeArrayGetUBound (safearray, 2, &ubound2);
4805 if ((lbound2 != 0) || (ubound2 != 1))
4808 SafeArrayGetLBound (safearray, 3, &lbound3);
4809 SafeArrayGetUBound (safearray, 3, &ubound3);
4811 if ((lbound3 != 0) || (ubound3 != 2))
4814 for (i= lbound1; i <= ubound1; i++) {
4816 for (j= lbound2; j <= ubound2; j++) {
4818 for (k= lbound3; k <= ubound3; k++) {
4820 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4822 failed = ((element.vt != VT_BSTR)
4823 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4824 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4825 VariantClear (&element);
4832 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4837 element.vt = VT_BSTR;
4838 element.bstrVal = SysAllocString(L"Should not be copied");
4839 SafeArrayPutElement (safearray, indices, &element);
4840 VariantClear (&element);
4845 LIBTEST_API int STDCALL
4846 mono_test_marshal_safearray_in_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4848 return mono_test_marshal_safearray_in_byval_3dim_vt_bstr (*safearray);
4851 LIBTEST_API int STDCALL
4852 mono_test_marshal_safearray_in_out_byref_1dim_empty (SAFEARRAY** safearray)
4854 /* Check that the input array is what is expected and change it so the caller can check */
4855 /* correct marshalling back to managed code */
4858 long lbound, ubound;
4859 SAFEARRAYBOUND dimensions [1];
4861 wchar_t buffer [20];
4865 /* Check that in array is one dimensional and empty */
4867 dim = SafeArrayGetDim (*safearray);
4872 SafeArrayGetLBound (*safearray, 1, &lbound);
4873 SafeArrayGetUBound (*safearray, 1, &ubound);
4875 if ((lbound > 0) || (ubound > 0)) {
4879 /* Re-dimension the array and return a one-dimensional array of 8 variants filled with "0" to "7" */
4881 dimensions [0].lLbound = 0;
4882 dimensions [0].cElements = 8;
4884 hr = SafeArrayRedim (*safearray, dimensions);
4888 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
4890 VariantInit (&vOut);
4892 _ltow (i,buffer,10);
4893 vOut.bstrVal = SysAllocString (buffer);
4895 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
4896 VariantClear (&vOut);
4897 SafeArrayDestroy (*safearray);
4900 VariantClear (&vOut);
4905 LIBTEST_API int STDCALL
4906 mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4908 /* Check that the input array is what is expected and change it so the caller can check */
4909 /* correct marshalling back to managed code */
4912 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4913 SAFEARRAYBOUND dimensions [1];
4914 long i, j, k, failed;
4915 wchar_t buffer [20];
4920 VariantInit (&element);
4922 /* Check that in array is three dimensional and contains the expected values */
4924 dim = SafeArrayGetDim (*safearray);
4928 SafeArrayGetLBound (*safearray, 1, &lbound1);
4929 SafeArrayGetUBound (*safearray, 1, &ubound1);
4931 if ((lbound1 != 0) || (ubound1 != 1))
4934 SafeArrayGetLBound (*safearray, 2, &lbound2);
4935 SafeArrayGetUBound (*safearray, 2, &ubound2);
4937 if ((lbound2 != 0) || (ubound2 != 1))
4940 SafeArrayGetLBound (*safearray, 3, &lbound3);
4941 SafeArrayGetUBound (*safearray, 3, &ubound3);
4943 if ((lbound3 != 0) || (ubound3 != 2))
4946 for (i= lbound1; i <= ubound1; i++) {
4948 for (j= lbound2; j <= ubound2; j++) {
4950 for (k= lbound3; k <= ubound3; k++) {
4952 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
4954 failed = ((element.vt != VT_BSTR)
4955 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4956 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4957 VariantClear (&element);
4964 hr = SafeArrayDestroy (*safearray);
4968 /* Return a new one-dimensional array of 8 variants filled with "0" to "7" */
4970 dimensions [0].lLbound = 0;
4971 dimensions [0].cElements = 8;
4973 *safearray = SafeArrayCreate (VT_VARIANT, 1, dimensions);
4975 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
4977 VariantInit (&vOut);
4979 _ltow (i,buffer,10);
4980 vOut.bstrVal = SysAllocString (buffer);
4982 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
4983 VariantClear (&vOut);
4984 SafeArrayDestroy (*safearray);
4987 VariantClear (&vOut);
4992 LIBTEST_API int STDCALL
4993 mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 (SAFEARRAY** safearray)
4995 /* Check that the input array is what is expected and change it so the caller can check */
4996 /* correct marshalling back to managed code */
4999 long lbound1, ubound1;
5005 VariantInit (&element);
5007 /* Check that in array is one dimensional and contains the expected value */
5009 dim = SafeArrayGetDim (*safearray);
5013 SafeArrayGetLBound (*safearray, 1, &lbound1);
5014 SafeArrayGetUBound (*safearray, 1, &ubound1);
5017 if ((lbound1 != 0) || (ubound1 != 1))
5021 for (i= lbound1; i <= ubound1; i++) {
5023 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
5025 failed = (element.vt != VT_I4) || (element.lVal != i+1);
5026 VariantClear (&element);
5031 /* Change one of the elements of the array to verify that [out] parameter is marshalled back to the managed side */
5036 SafeArrayPutElement (*safearray, indices, &element);
5037 VariantClear (&element);
5042 LIBTEST_API int STDCALL
5043 mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (SAFEARRAY* safearray)
5045 /* Check that the input array is what is expected and change it so the caller can check */
5046 /* correct marshalling back to managed code */
5049 long lbound1, ubound1;
5050 SAFEARRAYBOUND dimensions [1];
5056 VariantInit (&element);
5058 /* Check that in array is one dimensional and contains the expected value */
5060 dim = SafeArrayGetDim (safearray);
5064 SafeArrayGetLBound (safearray, 1, &lbound1);
5065 SafeArrayGetUBound (safearray, 1, &ubound1);
5067 if ((lbound1 != 0) || (ubound1 != 0))
5070 for (i= lbound1; i <= ubound1; i++) {
5072 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
5074 failed = (element.vt != VT_I4) || (element.lVal != i+1);
5075 VariantClear (&element);
5080 /* Change the array to verify how [out] parameter is marshalled back to the managed side */
5082 /* Redimension the array */
5083 dimensions [0].lLbound = lbound1;
5084 dimensions [0].cElements = 2;
5085 hr = SafeArrayRedim(safearray, dimensions);
5089 element.lVal = 12345;
5090 SafeArrayPutElement (safearray, indices, &element);
5091 VariantClear (&element);
5095 element.lVal = -12345;
5096 SafeArrayPutElement (safearray, indices, &element);
5097 VariantClear (&element);
5102 LIBTEST_API int STDCALL
5103 mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr (SAFEARRAY* safearray)
5105 /* Check that the input array is what is expected and change it so the caller can check */
5106 /* correct marshalling back to managed code */
5109 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
5110 long i, j, k, failed;
5115 VariantInit (&element);
5117 /* Check that in array is three dimensional and contains the expected values */
5119 dim = SafeArrayGetDim (safearray);
5123 SafeArrayGetLBound (safearray, 1, &lbound1);
5124 SafeArrayGetUBound (safearray, 1, &ubound1);
5126 if ((lbound1 != 0) || (ubound1 != 1))
5129 SafeArrayGetLBound (safearray, 2, &lbound2);
5130 SafeArrayGetUBound (safearray, 2, &ubound2);
5132 if ((lbound2 != 0) || (ubound2 != 1))
5135 SafeArrayGetLBound (safearray, 3, &lbound3);
5136 SafeArrayGetUBound (safearray, 3, &ubound3);
5138 if ((lbound3 != 0) || (ubound3 != 2))
5141 for (i= lbound1; i <= ubound1; i++) {
5143 for (j= lbound2; j <= ubound2; j++) {
5145 for (k= lbound3; k <= ubound3; k++) {
5147 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
5149 failed = ((element.vt != VT_BSTR)
5150 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
5151 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
5152 VariantClear (&element);
5159 /* Change the elements of the array to verify that [out] parameter is marshalled back to the managed side */
5166 SafeArrayPutElement (safearray, indices, &element);
5167 VariantClear (&element);
5174 SafeArrayPutElement (safearray, indices, &element);
5175 VariantClear (&element);
5180 element.vt = VT_BSTR;
5181 element.bstrVal = marshal_bstr_alloc("ABCDEFG");
5182 SafeArrayPutElement (safearray, indices, &element);
5183 VariantClear (&element);
5188 LIBTEST_API int STDCALL
5189 mono_test_marshal_safearray_mixed(
5190 SAFEARRAY *safearray1,
5191 SAFEARRAY **safearray2,
5192 SAFEARRAY *safearray3,
5193 SAFEARRAY **safearray4
5198 /* Initialize out parameters */
5201 /* array1: Check that in array is one dimensional and contains the expected value */
5202 hr = mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (safearray1);
5204 /* array2: Fill in with some values to check on the managed side */
5206 hr = mono_test_marshal_safearray_out_1dim_vt_bstr (safearray2);
5208 /* array3: Check that in array is one dimensional and contains the expected value */
5210 hr = mono_test_marshal_safearray_in_byval_1dim_vt_mixed(safearray3);
5212 /* array4: Check input values and fill in with some values to check on the managed side */
5214 hr = mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr(safearray4);
5221 static int call_managed_res;
5224 call_managed (gpointer arg)
5226 SimpleDelegate del = arg;
5228 call_managed_res = del (42);
5231 LIBTEST_API int STDCALL
5232 mono_test_marshal_thread_attach (SimpleDelegate del)
5240 res = pthread_create (&t, NULL, (gpointer)call_managed, del);
5241 g_assert (res == 0);
5242 pthread_join (t, NULL);
5244 return call_managed_res;
5248 typedef int (STDCALL *Callback) (void);
5250 static Callback callback;
5252 LIBTEST_API void STDCALL
5253 mono_test_marshal_set_callback (Callback cb)
5258 LIBTEST_API int STDCALL
5259 mono_test_marshal_call_callback (void)
5264 LIBTEST_API int STDCALL
5265 mono_test_marshal_lpstr (char *str)
5267 return strcmp ("ABC", str);
5270 LIBTEST_API int STDCALL
5271 mono_test_marshal_lpwstr (gunichar2 *str)
5276 s = g_utf16_to_utf8 (str, -1, NULL, NULL, NULL);
5277 res = strcmp ("ABC", s);
5283 LIBTEST_API char* STDCALL
5284 mono_test_marshal_return_lpstr (void)
5286 char *res = marshal_alloc (4);
5287 strcpy (res, "XYZ");
5292 LIBTEST_API gunichar2* STDCALL
5293 mono_test_marshal_return_lpwstr (void)
5295 gunichar2 *res = marshal_alloc (8);
5296 gunichar2* tmp = g_utf8_to_utf16 ("XYZ", -1, NULL, NULL, NULL);
5298 memcpy (res, tmp, 8);
5307 LIBTEST_API int STDCALL
5308 mono_test_has_thiscall (void)
5314 _mono_test_native_thiscall1 (int arg)
5320 _mono_test_native_thiscall2 (int arg, int arg2)
5322 return arg + (arg2^1);
5326 _mono_test_native_thiscall3 (int arg, int arg2, int arg3)
5328 return arg + (arg2^1) + (arg3^2);
5331 #elif defined(__GNUC__)
5333 LIBTEST_API int STDCALL
5334 mono_test_has_thiscall (void)
5339 #define def_asm_fn(name) \
5341 "\t.globl _" #name "\n" \
5343 "\t.globl __" #name "\n" \
5348 def_asm_fn(mono_test_native_thiscall1)
5349 "\tmovl %ecx,%eax\n"
5352 def_asm_fn(mono_test_native_thiscall2)
5353 "\tmovl %ecx,%eax\n"
5354 "\tmovl 4(%esp),%ecx\n"
5356 "\taddl %ecx,%eax\n"
5359 def_asm_fn(mono_test_native_thiscall3)
5360 "\tmovl %ecx,%eax\n"
5361 "\tmovl 4(%esp),%ecx\n"
5363 "\taddl %ecx,%eax\n"
5364 "\tmovl 8(%esp),%ecx\n"
5366 "\taddl %ecx,%eax\n"
5373 LIBTEST_API int STDCALL
5374 mono_test_has_thiscall (void)