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 mono_test_stdcall_mismatch_1 (int a, int b, int c)
1982 LIBTEST_API int STDCALL
1983 mono_test_stdcall_mismatch_2 (int a, int b, int c)
1989 * PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
1996 typedef SmallStruct1 (STDCALL *SmallStructDelegate1) (SmallStruct1 ss);
1998 LIBTEST_API int STDCALL
1999 mono_test_marshal_small_struct_delegate1 (SmallStructDelegate1 delegate)
2001 SmallStruct1 ss, res;
2005 res = delegate (ss);
2006 if (! (res.i == -1))
2016 typedef SmallStruct2 (STDCALL *SmallStructDelegate2) (SmallStruct2 ss);
2018 LIBTEST_API int STDCALL
2019 mono_test_marshal_small_struct_delegate2 (SmallStructDelegate2 delegate)
2021 SmallStruct2 ss, res;
2026 res = delegate (ss);
2027 if (! ((res.i == -2) && (res.j == -3)))
2038 typedef SmallStruct3 (STDCALL *SmallStructDelegate3) (SmallStruct3 ss);
2040 LIBTEST_API int STDCALL
2041 mono_test_marshal_small_struct_delegate3 (SmallStructDelegate3 delegate)
2043 SmallStruct3 ss, res;
2048 res = delegate (ss);
2049 if (! ((res.i == -1) && (res.j == -2)))
2059 typedef SmallStruct4 (STDCALL *SmallStructDelegate4) (SmallStruct4 ss);
2061 LIBTEST_API int STDCALL
2062 mono_test_marshal_small_struct_delegate4 (SmallStructDelegate4 delegate)
2064 SmallStruct4 ss, res;
2068 res = delegate (ss);
2069 if (! (res.i == -1))
2079 typedef SmallStruct5 (STDCALL *SmallStructDelegate5) (SmallStruct5 ss);
2081 LIBTEST_API int STDCALL
2082 mono_test_marshal_small_struct_delegate5 (SmallStructDelegate5 delegate)
2084 SmallStruct5 ss, res;
2088 res = delegate (ss);
2089 if (! (res.i == -5))
2099 typedef SmallStruct6 (STDCALL *SmallStructDelegate6) (SmallStruct6 ss);
2101 LIBTEST_API int STDCALL
2102 mono_test_marshal_small_struct_delegate6 (SmallStructDelegate6 delegate)
2104 SmallStruct6 ss, res;
2109 res = delegate (ss);
2110 if (! ((res.i == -1) && (res.j == -2)))
2121 typedef SmallStruct7 (STDCALL *SmallStructDelegate7) (SmallStruct7 ss);
2123 LIBTEST_API int STDCALL
2124 mono_test_marshal_small_struct_delegate7 (SmallStructDelegate7 delegate)
2126 SmallStruct7 ss, res;
2131 res = delegate (ss);
2132 if (! ((res.i == -1) && (res.j == -2)))
2142 typedef SmallStruct8 (STDCALL *SmallStructDelegate8) (SmallStruct8 ss);
2144 LIBTEST_API int STDCALL
2145 mono_test_marshal_small_struct_delegate8 (SmallStructDelegate8 delegate)
2147 SmallStruct8 ss, res;
2151 res = delegate (ss);
2152 if (! ((res.i == -1.0)))
2162 typedef SmallStruct9 (STDCALL *SmallStructDelegate9) (SmallStruct9 ss);
2164 LIBTEST_API int STDCALL
2165 mono_test_marshal_small_struct_delegate9 (SmallStructDelegate9 delegate)
2167 SmallStruct9 ss, res;
2171 res = delegate (ss);
2172 if (! ((res.i == -1.0)))
2182 typedef SmallStruct10 (STDCALL *SmallStructDelegate10) (SmallStruct10 ss);
2184 LIBTEST_API int STDCALL
2185 mono_test_marshal_small_struct_delegate10 (SmallStructDelegate10 delegate)
2187 SmallStruct10 ss, res;
2192 res = delegate (ss);
2193 if (! ((res.i == -1.0) && (res.j == -2.0)))
2204 typedef SmallStruct11 (STDCALL *SmallStructDelegate11) (SmallStruct11 ss);
2206 LIBTEST_API int STDCALL
2207 mono_test_marshal_small_struct_delegate11 (SmallStructDelegate11 delegate)
2209 SmallStruct11 ss, res;
2214 res = delegate (ss);
2215 if (! ((res.i == -1.0) && (res.j == -2)))
2221 typedef int (STDCALL *ArrayDelegate) (int i, char *j, void *arr);
2223 LIBTEST_API int STDCALL
2224 mono_test_marshal_array_delegate (void *arr, int len, ArrayDelegate del)
2226 return del (len, NULL, arr);
2229 typedef int (STDCALL *ArrayDelegateLong) (gint64 i, char *j, void *arr);
2231 LIBTEST_API int STDCALL
2232 mono_test_marshal_array_delegate_long (void *arr, gint64 len, ArrayDelegateLong del)
2234 return del (len, NULL, arr);
2237 LIBTEST_API int STDCALL
2238 mono_test_marshal_out_array_delegate (int *arr, int len, ArrayDelegate del)
2240 del (len, NULL, arr);
2242 if ((arr [0] != 1) || (arr [1] != 2))
2248 typedef gunichar2* (STDCALL *UnicodeStringDelegate) (gunichar2 *message);
2250 LIBTEST_API int STDCALL
2251 mono_test_marshal_return_unicode_string_delegate (UnicodeStringDelegate del)
2253 const char m[] = "abcdef";
2254 gunichar2 *s2, *res;
2257 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
2266 LIBTEST_API int STDCALL
2267 mono_test_marshal_out_string_array_delegate (char **arr, int len, ArrayDelegate del)
2269 del (len, NULL, arr);
2271 if (!strcmp (arr [0], "ABC") && !strcmp (arr [1], "DEF"))
2277 typedef int (*CdeclDelegate) (int i, int j);
2279 LIBTEST_API int STDCALL
2280 mono_test_marshal_cdecl_delegate (CdeclDelegate del)
2284 for (i = 0; i < 1000; ++i)
2290 typedef char** (STDCALL *ReturnStringArrayDelegate) (int i);
2292 LIBTEST_API int STDCALL
2293 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d)
2301 if (strcmp (arr [0], "ABC") || strcmp (arr [1], "DEF"))
2311 typedef int (STDCALL *ByrefStringDelegate) (char **s);
2313 LIBTEST_API int STDCALL
2314 mono_test_marshal_byref_string_delegate (ByrefStringDelegate d)
2316 char *s = (char*)"ABC";
2323 if (!strcmp (s, "DEF"))
2333 LIBTEST_API int STDCALL
2334 add_delegate (int i, int j)
2339 LIBTEST_API gpointer STDCALL
2340 mono_test_marshal_return_fnptr (void)
2342 return &add_delegate;
2345 LIBTEST_API int STDCALL
2348 printf ("codigo %x\n", code);
2356 LIBTEST_API HandleRef STDCALL
2357 mono_xr_as_handle (int code)
2361 memset (&ref, 0, sizeof (ref));
2373 LIBTEST_API int STDCALL
2374 mono_safe_handle_struct_ref (HandleStructs *x)
2376 printf ("Dingus Ref! \n");
2377 printf ("Values: %d %d %p %p\n", x->a, x->b, x->handle1, x->handle2);
2383 if (x->handle1 != (void*) 0x7080feed)
2386 if (x->handle2 != (void*) 0x1234abcd)
2392 LIBTEST_API int STDCALL
2393 mono_safe_handle_struct (HandleStructs x)
2395 printf ("Dingus Standard! \n");
2396 printf ("Values: %d %d %p %p\n", x.a, x.b, x.handle1, x.handle2);
2402 if (x.handle1 != (void*) 0x7080feed)
2405 if (x.handle2 != (void*) 0x1234abcd)
2415 LIBTEST_API int STDCALL
2416 mono_safe_handle_struct_simple (TrivialHandle x)
2418 printf ("The value is %p\n", x.a);
2419 return ((int)(gsize)x.a) * 2;
2422 LIBTEST_API int STDCALL
2423 mono_safe_handle_return (void)
2428 LIBTEST_API void STDCALL
2429 mono_safe_handle_ref (void **handle)
2432 *handle = (void *) 0xbad;
2436 *handle = (void *) 0x800d;
2439 LIBTEST_API double STDCALL
2440 mono_test_marshal_date_time (double d, double *d2)
2512 VT_USERDEFINED = 29,
2520 VT_STREAMED_OBJECT = 68,
2521 VT_STORED_OBJECT = 69,
2522 VT_BLOB_OBJECT = 70,
2530 void VariantInit(VARIANT* vt)
2547 LIBTEST_API int STDCALL
2548 mono_test_marshal_bstr_in(gunichar2* bstr)
2551 gchar* bstr_utf8 = g_utf16_to_utf8 (bstr, -1, NULL, NULL, NULL);
2552 result = strcmp("mono_test_marshal_bstr_in", bstr_utf8);
2559 LIBTEST_API int STDCALL
2560 mono_test_marshal_bstr_out(gunichar2** bstr)
2562 *bstr = marshal_bstr_alloc ("mono_test_marshal_bstr_out");
2566 LIBTEST_API int STDCALL
2567 mono_test_marshal_bstr_in_null(gunichar2* bstr)
2574 LIBTEST_API int STDCALL
2575 mono_test_marshal_bstr_out_null(gunichar2** bstr)
2581 LIBTEST_API int STDCALL
2582 mono_test_marshal_variant_in_sbyte(VARIANT variant)
2584 if (variant.vt == VT_I1 && variant.cVal == 100)
2589 LIBTEST_API int STDCALL
2590 mono_test_marshal_variant_in_byte(VARIANT variant)
2592 if (variant.vt == VT_UI1 && variant.bVal == 100)
2597 LIBTEST_API int STDCALL
2598 mono_test_marshal_variant_in_short(VARIANT variant)
2600 if (variant.vt == VT_I2 && variant.iVal == 314)
2605 LIBTEST_API int STDCALL
2606 mono_test_marshal_variant_in_ushort(VARIANT variant)
2608 if (variant.vt == VT_UI2 && variant.uiVal == 314)
2613 LIBTEST_API int STDCALL
2614 mono_test_marshal_variant_in_int(VARIANT variant)
2616 if (variant.vt == VT_I4 && variant.lVal == 314)
2621 LIBTEST_API int STDCALL
2622 mono_test_marshal_variant_in_uint(VARIANT variant)
2624 if (variant.vt == VT_UI4 && variant.ulVal == 314)
2629 LIBTEST_API int STDCALL
2630 mono_test_marshal_variant_in_long(VARIANT variant)
2632 if (variant.vt == VT_I8 && variant.llVal == 314)
2637 LIBTEST_API int STDCALL
2638 mono_test_marshal_variant_in_ulong(VARIANT variant)
2640 if (variant.vt == VT_UI8 && variant.ullVal == 314)
2645 LIBTEST_API int STDCALL
2646 mono_test_marshal_variant_in_float(VARIANT variant)
2648 if (variant.vt == VT_R4 && (variant.fltVal - 3.14)/3.14 < .001)
2653 LIBTEST_API int STDCALL
2654 mono_test_marshal_variant_in_double(VARIANT variant)
2656 if (variant.vt == VT_R8 && (variant.dblVal - 3.14)/3.14 < .001)
2661 LIBTEST_API int STDCALL
2662 mono_test_marshal_variant_in_bstr(VARIANT variant)
2665 gchar* bstr_utf8 = g_utf16_to_utf8 (variant.bstrVal, -1, NULL, NULL, NULL);
2666 result = strcmp("PI", bstr_utf8);
2669 if (variant.vt == VT_BSTR && !result)
2674 LIBTEST_API int STDCALL
2675 mono_test_marshal_variant_in_bool_true (VARIANT variant)
2677 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_TRUE)
2682 LIBTEST_API int STDCALL
2683 mono_test_marshal_variant_in_bool_false (VARIANT variant)
2685 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_FALSE)
2690 LIBTEST_API int STDCALL
2691 mono_test_marshal_variant_out_sbyte(VARIANT* variant)
2693 variant->vt = VT_I1;
2694 variant->cVal = 100;
2699 LIBTEST_API int STDCALL
2700 mono_test_marshal_variant_out_sbyte_byref(VARIANT* variant)
2702 variant->vt = VT_I1|VT_BYREF;
2703 variant->byref = marshal_alloc(1);
2704 *((gint8*)variant->byref) = 100;
2709 LIBTEST_API int STDCALL
2710 mono_test_marshal_variant_out_byte(VARIANT* variant)
2712 variant->vt = VT_UI1;
2713 variant->bVal = 100;
2718 LIBTEST_API int STDCALL
2719 mono_test_marshal_variant_out_byte_byref(VARIANT* variant)
2721 variant->vt = VT_UI1|VT_BYREF;
2722 variant->byref = marshal_alloc(1);
2723 *((gint8*)variant->byref) = 100;
2728 LIBTEST_API int STDCALL
2729 mono_test_marshal_variant_out_short(VARIANT* variant)
2731 variant->vt = VT_I2;
2732 variant->iVal = 314;
2737 LIBTEST_API int STDCALL
2738 mono_test_marshal_variant_out_short_byref(VARIANT* variant)
2740 variant->vt = VT_I2|VT_BYREF;
2741 variant->byref = marshal_alloc(2);
2742 *((gint16*)variant->byref) = 314;
2747 LIBTEST_API int STDCALL
2748 mono_test_marshal_variant_out_ushort(VARIANT* variant)
2750 variant->vt = VT_UI2;
2751 variant->uiVal = 314;
2756 LIBTEST_API int STDCALL
2757 mono_test_marshal_variant_out_ushort_byref(VARIANT* variant)
2759 variant->vt = VT_UI2|VT_BYREF;
2760 variant->byref = marshal_alloc(2);
2761 *((guint16*)variant->byref) = 314;
2766 LIBTEST_API int STDCALL
2767 mono_test_marshal_variant_out_int(VARIANT* variant)
2769 variant->vt = VT_I4;
2770 variant->lVal = 314;
2775 LIBTEST_API int STDCALL
2776 mono_test_marshal_variant_out_int_byref(VARIANT* variant)
2778 variant->vt = VT_I4|VT_BYREF;
2779 variant->byref = marshal_alloc(4);
2780 *((gint32*)variant->byref) = 314;
2785 LIBTEST_API int STDCALL
2786 mono_test_marshal_variant_out_uint(VARIANT* variant)
2788 variant->vt = VT_UI4;
2789 variant->ulVal = 314;
2794 LIBTEST_API int STDCALL
2795 mono_test_marshal_variant_out_uint_byref(VARIANT* variant)
2797 variant->vt = VT_UI4|VT_BYREF;
2798 variant->byref = marshal_alloc(4);
2799 *((guint32*)variant->byref) = 314;
2804 LIBTEST_API int STDCALL
2805 mono_test_marshal_variant_out_long(VARIANT* variant)
2807 variant->vt = VT_I8;
2808 variant->llVal = 314;
2813 LIBTEST_API int STDCALL
2814 mono_test_marshal_variant_out_long_byref(VARIANT* variant)
2816 variant->vt = VT_I8|VT_BYREF;
2817 variant->byref = marshal_alloc(8);
2818 *((gint64*)variant->byref) = 314;
2823 LIBTEST_API int STDCALL
2824 mono_test_marshal_variant_out_ulong(VARIANT* variant)
2826 variant->vt = VT_UI8;
2827 variant->ullVal = 314;
2832 LIBTEST_API int STDCALL
2833 mono_test_marshal_variant_out_ulong_byref(VARIANT* variant)
2835 variant->vt = VT_UI8|VT_BYREF;
2836 variant->byref = marshal_alloc(8);
2837 *((guint64*)variant->byref) = 314;
2842 LIBTEST_API int STDCALL
2843 mono_test_marshal_variant_out_float(VARIANT* variant)
2845 variant->vt = VT_R4;
2846 variant->fltVal = 3.14;
2851 LIBTEST_API int STDCALL
2852 mono_test_marshal_variant_out_float_byref(VARIANT* variant)
2854 variant->vt = VT_R4|VT_BYREF;
2855 variant->byref = marshal_alloc(4);
2856 *((float*)variant->byref) = 3.14;
2861 LIBTEST_API int STDCALL
2862 mono_test_marshal_variant_out_double(VARIANT* variant)
2864 variant->vt = VT_R8;
2865 variant->dblVal = 3.14;
2870 LIBTEST_API int STDCALL
2871 mono_test_marshal_variant_out_double_byref(VARIANT* variant)
2873 variant->vt = VT_R8|VT_BYREF;
2874 variant->byref = marshal_alloc(8);
2875 *((double*)variant->byref) = 3.14;
2880 LIBTEST_API int STDCALL
2881 mono_test_marshal_variant_out_bstr(VARIANT* variant)
2883 variant->vt = VT_BSTR;
2884 variant->bstrVal = marshal_bstr_alloc("PI");
2889 LIBTEST_API int STDCALL
2890 mono_test_marshal_variant_out_bstr_byref(VARIANT* variant)
2892 variant->vt = VT_BSTR|VT_BYREF;
2893 variant->byref = marshal_alloc(sizeof(gpointer));
2894 *((gunichar**)variant->byref) = (gunichar*)marshal_bstr_alloc("PI");
2899 LIBTEST_API int STDCALL
2900 mono_test_marshal_variant_out_bool_true (VARIANT* variant)
2902 variant->vt = VT_BOOL;
2903 variant->boolVal = VARIANT_TRUE;
2908 LIBTEST_API int STDCALL
2909 mono_test_marshal_variant_out_bool_true_byref (VARIANT* variant)
2911 variant->vt = VT_BOOL|VT_BYREF;
2912 variant->byref = marshal_alloc(2);
2913 *((gint16*)variant->byref) = VARIANT_TRUE;
2918 LIBTEST_API int STDCALL
2919 mono_test_marshal_variant_out_bool_false (VARIANT* variant)
2921 variant->vt = VT_BOOL;
2922 variant->boolVal = VARIANT_FALSE;
2927 LIBTEST_API int STDCALL
2928 mono_test_marshal_variant_out_bool_false_byref (VARIANT* variant)
2930 variant->vt = VT_BOOL|VT_BYREF;
2931 variant->byref = marshal_alloc(2);
2932 *((gint16*)variant->byref) = VARIANT_FALSE;
2937 typedef int (STDCALL *VarFunc) (int vt, VARIANT variant);
2938 typedef int (STDCALL *VarRefFunc) (int vt, VARIANT* variant);
2940 LIBTEST_API int STDCALL
2941 mono_test_marshal_variant_in_sbyte_unmanaged(VarFunc func)
2946 return func (VT_I1, vt);
2949 LIBTEST_API int STDCALL
2950 mono_test_marshal_variant_in_byte_unmanaged(VarFunc func)
2955 return func (VT_UI1, vt);
2958 LIBTEST_API int STDCALL
2959 mono_test_marshal_variant_in_short_unmanaged(VarFunc func)
2964 return func (VT_I2, vt);
2967 LIBTEST_API int STDCALL
2968 mono_test_marshal_variant_in_ushort_unmanaged(VarFunc func)
2973 return func (VT_UI2, vt);
2976 LIBTEST_API int STDCALL
2977 mono_test_marshal_variant_in_int_unmanaged(VarFunc func)
2982 return func (VT_I4, vt);
2985 LIBTEST_API int STDCALL
2986 mono_test_marshal_variant_in_uint_unmanaged(VarFunc func)
2991 return func (VT_UI4, vt);
2994 LIBTEST_API int STDCALL
2995 mono_test_marshal_variant_in_long_unmanaged(VarFunc func)
3000 return func (VT_I8, vt);
3003 LIBTEST_API int STDCALL
3004 mono_test_marshal_variant_in_ulong_unmanaged(VarFunc func)
3009 return func (VT_UI8, vt);
3012 LIBTEST_API int STDCALL
3013 mono_test_marshal_variant_in_float_unmanaged(VarFunc func)
3018 return func (VT_R4, vt);
3021 LIBTEST_API int STDCALL
3022 mono_test_marshal_variant_in_double_unmanaged(VarFunc func)
3027 return func (VT_R8, vt);
3030 LIBTEST_API int STDCALL
3031 mono_test_marshal_variant_in_bstr_unmanaged(VarFunc func)
3035 vt.bstrVal = marshal_bstr_alloc("PI");
3036 return func (VT_BSTR, vt);
3039 LIBTEST_API int STDCALL
3040 mono_test_marshal_variant_in_bool_true_unmanaged(VarFunc func)
3044 vt.boolVal = VARIANT_TRUE;
3045 return func (VT_BOOL, vt);
3048 LIBTEST_API int STDCALL
3049 mono_test_marshal_variant_in_bool_false_unmanaged(VarFunc func)
3053 vt.boolVal = VARIANT_FALSE;
3054 return func (VT_BOOL, vt);
3057 LIBTEST_API int STDCALL
3058 mono_test_marshal_variant_out_sbyte_unmanaged(VarRefFunc func)
3063 if (vt.vt == VT_I1 && vt.cVal == -100)
3068 LIBTEST_API int STDCALL
3069 mono_test_marshal_variant_out_byte_unmanaged(VarRefFunc func)
3074 if (vt.vt == VT_UI1 && vt.bVal == 100)
3079 LIBTEST_API int STDCALL
3080 mono_test_marshal_variant_out_short_unmanaged(VarRefFunc func)
3085 if (vt.vt == VT_I2 && vt.iVal == -100)
3090 LIBTEST_API int STDCALL
3091 mono_test_marshal_variant_out_ushort_unmanaged(VarRefFunc func)
3096 if (vt.vt == VT_UI2 && vt.uiVal == 100)
3101 LIBTEST_API int STDCALL
3102 mono_test_marshal_variant_out_int_unmanaged(VarRefFunc func)
3107 if (vt.vt == VT_I4 && vt.lVal == -100)
3112 LIBTEST_API int STDCALL
3113 mono_test_marshal_variant_out_uint_unmanaged(VarRefFunc func)
3118 if (vt.vt == VT_UI4 && vt.ulVal == 100)
3123 LIBTEST_API int STDCALL
3124 mono_test_marshal_variant_out_long_unmanaged(VarRefFunc func)
3129 if (vt.vt == VT_I8 && vt.llVal == -100)
3134 LIBTEST_API int STDCALL
3135 mono_test_marshal_variant_out_ulong_unmanaged(VarRefFunc func)
3140 if (vt.vt == VT_UI8 && vt.ullVal == 100)
3145 LIBTEST_API int STDCALL
3146 mono_test_marshal_variant_out_float_unmanaged(VarRefFunc func)
3151 if (vt.vt == VT_R4 && fabs (vt.fltVal - 3.14f) < 1e-10)
3156 LIBTEST_API int STDCALL
3157 mono_test_marshal_variant_out_double_unmanaged(VarRefFunc func)
3162 if (vt.vt == VT_R8 && fabs (vt.dblVal - 3.14) < 1e-10)
3167 LIBTEST_API int STDCALL
3168 mono_test_marshal_variant_out_bstr_unmanaged(VarRefFunc func)
3176 func (VT_BSTR, &vt);
3177 bstr_utf8 = g_utf16_to_utf8 (vt.bstrVal, -1, NULL, NULL, NULL);
3178 result = strcmp("PI", bstr_utf8);
3180 if (vt.vt == VT_BSTR && !result)
3185 LIBTEST_API int STDCALL
3186 mono_test_marshal_variant_out_bool_true_unmanaged(VarRefFunc func)
3190 func (VT_BOOL, &vt);
3191 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3196 LIBTEST_API int STDCALL
3197 mono_test_marshal_variant_out_bool_false_unmanaged(VarRefFunc func)
3201 func (VT_BOOL, &vt);
3202 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3207 typedef struct MonoComObject MonoComObject;
3211 int (STDCALL *QueryInterface)(MonoComObject* pUnk, gpointer riid, gpointer* ppv);
3212 int (STDCALL *AddRef)(MonoComObject* pUnk);
3213 int (STDCALL *Release)(MonoComObject* pUnk);
3214 int (STDCALL *get_ITest)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3215 int (STDCALL *SByteIn)(MonoComObject* pUnk, char a);
3216 int (STDCALL *ByteIn)(MonoComObject* pUnk, unsigned char a);
3217 int (STDCALL *ShortIn)(MonoComObject* pUnk, short a);
3218 int (STDCALL *UShortIn)(MonoComObject* pUnk, unsigned short a);
3219 int (STDCALL *IntIn)(MonoComObject* pUnk, int a);
3220 int (STDCALL *UIntIn)(MonoComObject* pUnk, unsigned int a);
3221 int (STDCALL *LongIn)(MonoComObject* pUnk, gint64 a);
3222 int (STDCALL *ULongIn)(MonoComObject* pUnk, guint64 a);
3223 int (STDCALL *FloatIn)(MonoComObject* pUnk, float a);
3224 int (STDCALL *DoubleIn)(MonoComObject* pUnk, double a);
3225 int (STDCALL *ITestIn)(MonoComObject* pUnk, MonoComObject* pUnk2);
3226 int (STDCALL *ITestOut)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3229 struct MonoComObject
3235 static GUID IID_ITest = {0, 0, 0, {0,0,0,0,0,0,0,1}};
3236 static GUID IID_IMonoUnknown = {0, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3237 static GUID IID_IMonoDispatch = {0x00020400, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3239 LIBTEST_API int STDCALL
3240 MonoQueryInterface(MonoComObject* pUnk, gpointer riid, gpointer* ppv)
3244 if (!memcmp(riid, &IID_IMonoUnknown, sizeof(GUID))) {
3248 else if (!memcmp(riid, &IID_ITest, sizeof(GUID))) {
3252 else if (!memcmp(riid, &IID_IMonoDispatch, sizeof(GUID))) {
3256 return 0x80004002; //E_NOINTERFACE;
3259 LIBTEST_API int STDCALL
3260 MonoAddRef(MonoComObject* pUnk)
3262 return ++(pUnk->m_ref);
3265 LIBTEST_API int STDCALL
3266 MonoRelease(MonoComObject* pUnk)
3268 return --(pUnk->m_ref);
3271 LIBTEST_API int STDCALL
3272 SByteIn(MonoComObject* pUnk, char a)
3277 LIBTEST_API int STDCALL
3278 ByteIn(MonoComObject* pUnk, unsigned char a)
3283 LIBTEST_API int STDCALL
3284 ShortIn(MonoComObject* pUnk, short a)
3289 LIBTEST_API int STDCALL
3290 UShortIn(MonoComObject* pUnk, unsigned short a)
3295 LIBTEST_API int STDCALL
3296 IntIn(MonoComObject* pUnk, int a)
3301 LIBTEST_API int STDCALL
3302 UIntIn(MonoComObject* pUnk, unsigned int a)
3307 LIBTEST_API int STDCALL
3308 LongIn(MonoComObject* pUnk, gint64 a)
3313 LIBTEST_API int STDCALL
3314 ULongIn(MonoComObject* pUnk, guint64 a)
3319 LIBTEST_API int STDCALL
3320 FloatIn(MonoComObject* pUnk, float a)
3325 LIBTEST_API int STDCALL
3326 DoubleIn(MonoComObject* pUnk, double a)
3331 LIBTEST_API int STDCALL
3332 ITestIn(MonoComObject* pUnk, MonoComObject *pUnk2)
3337 LIBTEST_API int STDCALL
3338 ITestOut(MonoComObject* pUnk, MonoComObject* *ppUnk)
3343 static void create_com_object (MonoComObject** pOut);
3345 LIBTEST_API int STDCALL
3346 get_ITest(MonoComObject* pUnk, MonoComObject* *ppUnk)
3348 create_com_object (ppUnk);
3352 static void create_com_object (MonoComObject** pOut)
3354 *pOut = marshal_new0 (MonoComObject, 1);
3355 (*pOut)->vtbl = marshal_new0 (MonoIUnknown, 1);
3358 (*pOut)->vtbl->QueryInterface = MonoQueryInterface;
3359 (*pOut)->vtbl->AddRef = MonoAddRef;
3360 (*pOut)->vtbl->Release = MonoRelease;
3361 (*pOut)->vtbl->SByteIn = SByteIn;
3362 (*pOut)->vtbl->ByteIn = ByteIn;
3363 (*pOut)->vtbl->ShortIn = ShortIn;
3364 (*pOut)->vtbl->UShortIn = UShortIn;
3365 (*pOut)->vtbl->IntIn = IntIn;
3366 (*pOut)->vtbl->UIntIn = UIntIn;
3367 (*pOut)->vtbl->LongIn = LongIn;
3368 (*pOut)->vtbl->ULongIn = ULongIn;
3369 (*pOut)->vtbl->FloatIn = FloatIn;
3370 (*pOut)->vtbl->DoubleIn = DoubleIn;
3371 (*pOut)->vtbl->ITestIn = ITestIn;
3372 (*pOut)->vtbl->ITestOut = ITestOut;
3373 (*pOut)->vtbl->get_ITest = get_ITest;
3376 static MonoComObject* same_object = NULL;
3378 LIBTEST_API int STDCALL
3379 mono_test_marshal_com_object_create(MonoComObject* *pUnk)
3381 create_com_object (pUnk);
3384 same_object = *pUnk;
3389 LIBTEST_API int STDCALL
3390 mono_test_marshal_com_object_same(MonoComObject* *pUnk)
3392 *pUnk = same_object;
3397 LIBTEST_API int STDCALL
3398 mono_test_marshal_com_object_destroy(MonoComObject *pUnk)
3400 int ref = --(pUnk->m_ref);
3407 LIBTEST_API int STDCALL
3408 mono_test_marshal_com_object_ref_count(MonoComObject *pUnk)
3413 LIBTEST_API int STDCALL
3414 mono_test_marshal_ccw_itest (MonoComObject *pUnk)
3417 MonoComObject* pTest;
3422 hr = pUnk->vtbl->SByteIn (pUnk, -100);
3425 hr = pUnk->vtbl->ByteIn (pUnk, 100);
3428 hr = pUnk->vtbl->ShortIn (pUnk, -100);
3431 hr = pUnk->vtbl->UShortIn (pUnk, 100);
3434 hr = pUnk->vtbl->IntIn (pUnk, -100);
3437 hr = pUnk->vtbl->UIntIn (pUnk, 100);
3440 hr = pUnk->vtbl->LongIn (pUnk, -100);
3443 hr = pUnk->vtbl->ULongIn (pUnk, 100);
3446 hr = pUnk->vtbl->FloatIn (pUnk, 3.14f);
3449 hr = pUnk->vtbl->DoubleIn (pUnk, 3.14);
3452 hr = pUnk->vtbl->ITestIn (pUnk, pUnk);
3455 hr = pUnk->vtbl->ITestOut (pUnk, &pTest);
3463 * mono_method_get_unmanaged_thunk tests
3466 #if defined(__GNUC__) && ((defined(__i386__) && (defined(__linux__) || defined (__APPLE__)) || defined (__FreeBSD__) || defined(__OpenBSD__)) || (defined(__ppc__) && defined(__APPLE__)))
3467 #define ALIGN(size) __attribute__ ((aligned(size)))
3473 /* thunks.cs:TestStruct */
3474 typedef struct _TestStruct {
3479 /* Searches for mono symbols in all loaded modules */
3481 lookup_mono_symbol (const char *symbol_name)
3484 if (g_module_symbol (g_module_open (NULL, G_MODULE_BIND_LAZY), symbol_name, &symbol))
3490 LIBTEST_API gpointer STDCALL
3491 mono_test_marshal_lookup_symbol (const char *symbol_name)
3493 return lookup_mono_symbol (symbol_name);
3497 * test_method_thunk:
3499 * @test_id: the test number
3500 * @test_method_handle: MonoMethod* of the C# test method
3501 * @create_object_method_handle: MonoMethod* of thunks.cs:Test.CreateObject
3503 LIBTEST_API int STDCALL
3504 test_method_thunk (int test_id, gpointer test_method_handle, gpointer create_object_method_handle)
3506 gpointer (*mono_method_get_unmanaged_thunk)(gpointer)
3507 = lookup_mono_symbol ("mono_method_get_unmanaged_thunk");
3509 gpointer (*mono_string_new_wrapper)(const char *)
3510 = lookup_mono_symbol ("mono_string_new_wrapper");
3512 char* (*mono_string_to_utf8)(gpointer)
3513 = lookup_mono_symbol ("mono_string_to_utf8");
3515 gpointer (*mono_object_unbox)(gpointer)
3516 = lookup_mono_symbol ("mono_object_unbox");
3518 gpointer test_method, ex = NULL;
3519 gpointer (STDCALL *CreateObject)(gpointer*);
3522 if (!mono_method_get_unmanaged_thunk)
3525 test_method = mono_method_get_unmanaged_thunk (test_method_handle);
3529 CreateObject = mono_method_get_unmanaged_thunk (create_object_method_handle);
3537 /* thunks.cs:Test.Test0 */
3538 void (STDCALL *F)(gpointer*) = test_method;
3544 /* thunks.cs:Test.Test1 */
3545 int (STDCALL *F)(gpointer*) = test_method;
3552 /* thunks.cs:Test.Test2 */
3553 gpointer (STDCALL *F)(gpointer, gpointer*) = test_method;
3554 gpointer str = mono_string_new_wrapper ("foo");
3555 if (str != F (str, &ex))
3561 /* thunks.cs:Test.Test3 */
3562 gpointer (STDCALL *F)(gpointer, gpointer, gpointer*);
3567 obj = CreateObject (&ex);
3568 str = mono_string_new_wrapper ("bar");
3570 if (str != F (obj, str, &ex))
3576 /* thunks.cs:Test.Test4 */
3577 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3582 obj = CreateObject (&ex);
3583 str = mono_string_new_wrapper ("bar");
3585 if (42 != F (obj, str, 42, &ex))
3592 /* thunks.cs:Test.Test5 */
3593 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3598 obj = CreateObject (&ex);
3599 str = mono_string_new_wrapper ("bar");
3601 F (obj, str, 42, &ex);
3609 /* thunks.cs:Test.Test6 */
3610 int (STDCALL *F)(gpointer, guint8, gint16, gint32, gint64, float, double,
3611 gpointer, gpointer*);
3613 gpointer str = mono_string_new_wrapper ("Test6");
3617 obj = CreateObject (&ex);
3619 res = F (obj, 254, 32700, -245378, 6789600, 3.1415, 3.1415, str, &ex);
3630 /* thunks.cs:Test.Test7 */
3631 gint64 (STDCALL *F)(gpointer*) = test_method;
3632 if (F (&ex) != G_MAXINT64)
3638 /* thunks.cs:Test.Test8 */
3639 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3640 gpointer*, gpointer*);
3652 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3660 (fabs (a5 - 3.1415) < 0.001) &&
3661 (fabs (a6 - 3.1415) < 0.001) &&
3662 strcmp (mono_string_to_utf8 (a7), "Test8") == 0))
3669 /* thunks.cs:Test.Test9 */
3670 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3671 gpointer*, gpointer*);
3683 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3691 /* thunks.cs:Test.Test10 */
3692 void (STDCALL *F)(gpointer*, gpointer*);
3694 gpointer obj1, obj2;
3696 obj1 = obj2 = CreateObject (&ex);
3713 /* thunks.cs:TestStruct.Test0 */
3714 int (STDCALL *F)(gpointer*, gpointer*);
3720 obj = CreateObject (&ex);
3727 a1 = mono_object_unbox (obj);
3743 /* check whether the call was really by value */
3744 if (a1->A != 42 || a1->B != 3.1415)
3751 /* thunks.cs:TestStruct.Test1 */
3752 void (STDCALL *F)(gpointer, gpointer*);
3757 obj = CreateObject (&ex);
3764 a1 = mono_object_unbox (obj);
3777 if (!fabs (a1->B - 3.1415) < 0.001)
3784 /* thunks.cs:TestStruct.Test2 */
3785 gpointer (STDCALL *F)(gpointer*);
3799 a1 = mono_object_unbox (obj);
3804 if (!fabs (a1->B - 3.1415) < 0.001)
3811 /* thunks.cs:TestStruct.Test3 */
3812 void (STDCALL *F)(gpointer, gpointer*);
3817 obj = CreateObject (&ex);
3824 a1 = mono_object_unbox (obj);
3860 LIBTEST_API int STDCALL
3861 mono_test_Winx64_struct1_in (winx64_struct1 var)
3874 LIBTEST_API int STDCALL
3875 mono_test_Winx64_struct2_in (winx64_struct2 var)
3892 LIBTEST_API int STDCALL
3893 mono_test_Winx64_struct3_in (winx64_struct3 var)
3899 if (var.c != 0x1234)
3912 LIBTEST_API int STDCALL
3913 mono_test_Winx64_struct4_in (winx64_struct4 var)
3919 if (var.c != 0x1234)
3921 if (var.d != 0x87654321)
3933 LIBTEST_API int STDCALL
3934 mono_test_Winx64_struct5_in (winx64_struct5 var)
3952 LIBTEST_API int STDCALL
3953 mono_test_Winx64_struct6_in (winx64_struct6 var)
3964 LIBTEST_API int STDCALL
3965 mono_test_Winx64_structs_in1 (winx64_struct1 var1,
3966 winx64_struct2 var2,
3967 winx64_struct3 var3,
3968 winx64_struct4 var4)
3982 if (var3.c != 0x1234)
3989 if (var4.c != 0x1234)
3991 if (var4.d != 0x87654321)
3996 LIBTEST_API int STDCALL
3997 mono_test_Winx64_structs_in2 (winx64_struct1 var1,
3998 winx64_struct1 var2,
3999 winx64_struct1 var3,
4000 winx64_struct1 var4,
4001 winx64_struct1 var5)
4017 LIBTEST_API int STDCALL
4018 mono_test_Winx64_structs_in3 (winx64_struct1 var1,
4019 winx64_struct5 var2,
4020 winx64_struct1 var3,
4021 winx64_struct5 var4,
4022 winx64_struct1 var5,
4023 winx64_struct5 var6)
4058 LIBTEST_API winx64_struct1 STDCALL
4059 mono_test_Winx64_struct1_ret (void)
4066 LIBTEST_API winx64_struct2 STDCALL
4067 mono_test_Winx64_struct2_ret (void)
4075 LIBTEST_API winx64_struct3 STDCALL
4076 mono_test_Winx64_struct3_ret (void)
4085 LIBTEST_API winx64_struct4 STDCALL
4086 mono_test_Winx64_struct4_ret (void)
4096 LIBTEST_API winx64_struct5 STDCALL
4097 mono_test_Winx64_struct5_ret (void)
4106 LIBTEST_API winx64_struct1 STDCALL
4107 mono_test_Winx64_struct1_ret_5_args (char a, char b, char c, char d, char e)
4110 ret.a = a + b + c + d + e;
4114 LIBTEST_API winx64_struct5 STDCALL
4115 mono_test_Winx64_struct5_ret6_args (char a, char b, char c, char d, char e)
4128 } winx64_floatStruct;
4130 LIBTEST_API int STDCALL
4131 mono_test_Winx64_floatStruct (winx64_floatStruct a)
4133 if (a.a > 5.6 || a.a < 5.4)
4136 if (a.b > 9.6 || a.b < 9.4)
4145 } winx64_doubleStruct;
4147 LIBTEST_API int STDCALL
4148 mono_test_Winx64_doubleStruct (winx64_doubleStruct a)
4150 if (a.a > 5.6 || a.a < 5.4)
4156 typedef int (STDCALL *managed_struct1_delegate) (winx64_struct1 a);
4158 LIBTEST_API int STDCALL
4159 mono_test_managed_Winx64_struct1_in(managed_struct1_delegate func)
4166 typedef int (STDCALL *managed_struct5_delegate) (winx64_struct5 a);
4168 LIBTEST_API int STDCALL
4169 mono_test_managed_Winx64_struct5_in(managed_struct5_delegate func)
4178 typedef int (STDCALL *managed_struct1_struct5_delegate) (winx64_struct1 a, winx64_struct5 b,
4179 winx64_struct1 c, winx64_struct5 d,
4180 winx64_struct1 e, winx64_struct5 f);
4182 LIBTEST_API int STDCALL
4183 mono_test_managed_Winx64_struct1_struct5_in(managed_struct1_struct5_delegate func)
4185 winx64_struct1 a, c, e;
4186 winx64_struct5 b, d, f;
4188 b.a = 2; b.b = 3; b.c = 4;
4190 d.a = 6; d.b = 7; d.c = 8;
4192 f.a = 10; f.b = 11; f.c = 12;
4194 return func (a, b, c, d, e, f);
4197 typedef winx64_struct1 (STDCALL *managed_struct1_ret_delegate) (void);
4199 LIBTEST_API int STDCALL
4200 mono_test_Winx64_struct1_ret_managed (managed_struct1_ret_delegate func)
4212 typedef winx64_struct5 (STDCALL *managed_struct5_ret_delegate) (void);
4214 LIBTEST_API int STDCALL
4215 mono_test_Winx64_struct5_ret_managed (managed_struct5_ret_delegate func)
4231 LIBTEST_API int STDCALL
4232 mono_test_marshal_bool_in (int arg, unsigned int expected, unsigned int bDefaultMarsh, unsigned int bBoolCustMarsh,
4233 char bI1CustMarsh, unsigned char bU1CustMarsh, short bVBCustMarsh)
4237 if (bDefaultMarsh != expected)
4241 if (bBoolCustMarsh != expected)
4245 if (bI1CustMarsh != expected)
4249 if (bU1CustMarsh != expected)
4253 if (bVBCustMarsh != expected)
4262 LIBTEST_API int STDCALL
4263 mono_test_marshal_bool_out (int arg, unsigned int testVal, unsigned int* bDefaultMarsh, unsigned int* bBoolCustMarsh,
4264 char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh)
4270 *bDefaultMarsh = testVal;
4273 if (!bBoolCustMarsh)
4275 *bBoolCustMarsh = testVal;
4280 *bI1CustMarsh = (char)testVal;
4285 *bU1CustMarsh = (unsigned char)testVal;
4290 *bVBCustMarsh = (unsigned short)testVal;
4298 LIBTEST_API int STDCALL
4299 mono_test_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4300 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh,
4301 unsigned short* bVBCustMarsh)
4307 if (*bDefaultMarsh != expected)
4309 *bDefaultMarsh = testVal;
4312 if (!bBoolCustMarsh)
4314 if (*bBoolCustMarsh != expected)
4316 *bBoolCustMarsh = testVal;
4321 if (*bI1CustMarsh != expected)
4323 *bI1CustMarsh = (char)testVal;
4328 if (*bU1CustMarsh != expected)
4330 *bU1CustMarsh = (unsigned char)testVal;
4335 if (*bVBCustMarsh != expected)
4337 *bVBCustMarsh = (unsigned short)testVal;
4346 typedef int (STDCALL *MarshalBoolInDelegate) (int arg, unsigned int expected, unsigned int bDefaultMarsh,
4347 unsigned int bBoolCustMarsh, char bI1CustMarsh, unsigned char bU1CustMarsh, unsigned short bVBCustMarsh);
4349 LIBTEST_API int STDCALL
4350 mono_test_managed_marshal_bool_in (int arg, unsigned int expected, unsigned int testVal, MarshalBoolInDelegate pfcn)
4357 return pfcn (arg, expected, testVal, 0, 0, 0, 0);
4359 return pfcn (arg, expected, 0, testVal, 0, 0, 0);
4361 return pfcn (arg, expected, 0, 0, testVal, 0, 0);
4363 return pfcn (arg, expected, 0, 0, 0, testVal, 0);
4365 return pfcn (arg, expected, 0, 0, 0, 0, testVal);
4373 typedef int (STDCALL *MarshalBoolOutDelegate) (int arg, unsigned int expected, unsigned int* bDefaultMarsh,
4374 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4376 LIBTEST_API int STDCALL
4377 mono_test_managed_marshal_bool_out (int arg, unsigned int expected, unsigned int testVal, MarshalBoolOutDelegate pfcn)
4380 unsigned int lDefaultMarsh, lBoolCustMarsh;
4381 char lI1CustMarsh = 0;
4382 unsigned char lU1CustMarsh = 0;
4383 unsigned short lVBCustMarsh = 0;
4384 lDefaultMarsh = lBoolCustMarsh = 0;
4391 unsigned int ltVal = 0;
4392 ret = pfcn (arg, testVal, <Val, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4394 return 0x0100 + ret;
4395 if (expected != ltVal)
4400 unsigned int ltVal = 0;
4401 ret = pfcn (arg, testVal, &lDefaultMarsh, <Val, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4403 return 0x0300 + ret;
4404 if (expected != ltVal)
4410 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, <Val, &lU1CustMarsh, &lVBCustMarsh);
4412 return 0x0500 + ret;
4413 if (expected != ltVal)
4418 unsigned char ltVal = 0;
4419 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <Val, &lVBCustMarsh);
4421 return 0x0700 + ret;
4422 if (expected != ltVal)
4427 unsigned short ltVal = 0;
4428 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <Val);
4430 return 0x0900 + ret;
4431 if (expected != ltVal)
4442 typedef int (STDCALL *MarshalBoolRefDelegate) (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4443 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4445 LIBTEST_API int STDCALL
4446 mono_test_managed_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int outExpected,
4447 unsigned int outTestVal, MarshalBoolRefDelegate pfcn)
4450 unsigned int lDefaultMarsh, lBoolCustMarsh;
4451 char lI1CustMarsh = 0;
4452 unsigned char lU1CustMarsh = 0;
4453 unsigned short lVBCustMarsh = 0;
4454 lDefaultMarsh = lBoolCustMarsh = 0;
4462 unsigned int ltestVal = testVal;
4463 ret = pfcn (arg, expected, outTestVal, <estVal, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4465 return 0x0100 + ret;
4466 if (outExpected != ltestVal)
4472 unsigned int ltestVal = testVal;
4473 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, <estVal, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4475 return 0x0300 + ret;
4476 if (outExpected != ltestVal)
4482 char ltestVal = testVal;
4483 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, <estVal, &lU1CustMarsh, &lVBCustMarsh);
4485 return 0x0500 + ret;
4486 if (outExpected != ltestVal)
4492 unsigned char ltestVal = testVal;
4493 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <estVal, &lVBCustMarsh);
4495 return 0x0700 + ret;
4496 if (outExpected != ltestVal)
4502 unsigned short ltestVal = testVal;
4503 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <estVal);
4505 return 0x0900 + ret;
4506 if (outExpected != ltestVal)
4519 LIBTEST_API int STDCALL
4520 mono_test_marshal_safearray_out_1dim_vt_bstr_empty (SAFEARRAY** safearray)
4522 /* Create an empty one-dimensional array of variants */
4524 SAFEARRAYBOUND dimensions [1];
4526 dimensions [0].lLbound = 0;
4527 dimensions [0].cElements = 0;
4529 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4534 LIBTEST_API int STDCALL
4535 mono_test_marshal_safearray_out_1dim_vt_bstr (SAFEARRAY** safearray)
4537 /* Create a one-dimensional array of 10 variants filled with "0" to "9" */
4539 SAFEARRAYBOUND dimensions [1];
4545 dimensions [0].lLbound = 0;
4546 dimensions [0].cElements = 10;
4548 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4549 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4551 VariantInit (&vOut);
4553 _ltoa (i,buffer,10);
4554 vOut.bstrVal= marshal_bstr_alloc (buffer);
4556 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4557 VariantClear (&vOut);
4558 SafeArrayDestroy (pSA);
4561 VariantClear (&vOut);
4567 LIBTEST_API int STDCALL
4568 mono_test_marshal_safearray_out_2dim_vt_i4 (SAFEARRAY** safearray)
4570 /* Create a two-dimensional array of 4x3 variants filled with 11, 12, 13, etc. */
4572 SAFEARRAYBOUND dimensions [2];
4577 dimensions [0].lLbound = 0;
4578 dimensions [0].cElements = 4;
4579 dimensions [1].lLbound = 0;
4580 dimensions [1].cElements = 3;
4582 pSA= SafeArrayCreate(VT_VARIANT, 2, dimensions);
4583 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4584 for (j= dimensions [1].lLbound; j< (dimensions [1].cElements + dimensions [1].lLbound); j++) {
4586 VariantInit (&vOut);
4588 vOut.lVal = (i+1)*10+(j+1);
4591 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4592 VariantClear (&vOut);
4593 SafeArrayDestroy (pSA);
4596 VariantClear (&vOut); // does a deep destroy of source VARIANT
4603 LIBTEST_API int STDCALL
4604 mono_test_marshal_safearray_out_4dim_vt_i4 (SAFEARRAY** safearray)
4606 /* Create a four-dimensional array of 10x3x6x7 variants filled with their indices */
4607 /* Also use non zero lower bounds */
4609 SAFEARRAYBOUND dimensions [4];
4614 dimensions [0].lLbound = 15;
4615 dimensions [0].cElements = 10;
4616 dimensions [1].lLbound = 20;
4617 dimensions [1].cElements = 3;
4618 dimensions [2].lLbound = 5;
4619 dimensions [2].cElements = 6;
4620 dimensions [3].lLbound = 12;
4621 dimensions [3].cElements = 7;
4623 pSA= SafeArrayCreate (VT_VARIANT, 4, dimensions);
4625 SafeArrayAccessData (pSA, (void **)&pData);
4627 for (i= 0; i< 10*3*6*7; i++) {
4628 VariantInit(&pData [i]);
4629 pData [i].vt = VT_I4;
4632 SafeArrayUnaccessData (pSA);
4637 LIBTEST_API int STDCALL
4638 mono_test_marshal_safearray_in_byval_1dim_empty (SAFEARRAY* safearray)
4640 /* Check that array is one dimensional and empty */
4643 long lbound, ubound;
4645 dim = SafeArrayGetDim (safearray);
4649 SafeArrayGetLBound (safearray, 1, &lbound);
4650 SafeArrayGetUBound (safearray, 1, &ubound);
4652 if ((lbound > 0) || (ubound > 0))
4658 LIBTEST_API int STDCALL
4659 mono_test_marshal_safearray_in_byval_1dim_vt_i4 (SAFEARRAY* safearray)
4661 /* Check that array is one dimensional containing integers from 1 to 10 */
4664 long lbound, ubound;
4669 dim = SafeArrayGetDim (safearray);
4673 SafeArrayGetLBound (safearray, 1, &lbound);
4674 SafeArrayGetUBound (safearray, 1, &ubound);
4676 if ((lbound != 0) || (ubound != 9))
4679 SafeArrayAccessData (safearray, (void **)&pData);
4680 for (i= lbound; i <= ubound; i++) {
4681 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i + 1))
4684 SafeArrayUnaccessData (safearray);
4689 LIBTEST_API int STDCALL
4690 mono_test_marshal_safearray_in_byval_1dim_vt_mixed (SAFEARRAY* safearray)
4692 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4695 long lbound, ubound;
4702 VariantInit (&element);
4704 dim = SafeArrayGetDim (safearray);
4708 SafeArrayGetLBound (safearray, 1, &lbound);
4709 SafeArrayGetUBound (safearray, 1, &ubound);
4711 if ((lbound != 0) || (ubound != 12))
4714 SafeArrayAccessData (safearray, (void **)&pData);
4715 for (i= lbound; i <= ubound; i++) {
4716 if ((i%2 == 0) && (pData [i].vt != VT_I4))
4718 if ((i%2 == 1) && (pData [i].vt != VT_BSTR))
4720 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i))
4723 SafeArrayUnaccessData (safearray);
4725 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4730 SafeArrayPutElement (safearray, indices, &element);
4731 VariantClear (&element);
4736 LIBTEST_API int STDCALL
4737 mono_test_marshal_safearray_in_byval_2dim_vt_i4 (SAFEARRAY* safearray)
4739 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4742 long lbound1, ubound1, lbound2, ubound2;
4747 VariantInit (&element);
4749 dim = SafeArrayGetDim (safearray);
4753 SafeArrayGetLBound (safearray, 1, &lbound1);
4754 SafeArrayGetUBound (safearray, 1, &ubound1);
4756 if ((lbound1 != 0) || (ubound1 != 1))
4759 SafeArrayGetLBound (safearray, 2, &lbound2);
4760 SafeArrayGetUBound (safearray, 2, &ubound2);
4762 if ((lbound2 != 0) || (ubound2 != 3)) {
4766 for (i= lbound1; i <= ubound1; i++) {
4768 for (j= lbound2; j <= ubound2; j++) {
4770 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4772 failed = ((element.vt != VT_I4) || (element.lVal != 10*(i+1)+(j+1)));
4773 VariantClear (&element);
4779 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4785 SafeArrayPutElement (safearray, indices, &element);
4786 VariantClear (&element);
4791 LIBTEST_API int STDCALL
4792 mono_test_marshal_safearray_in_byval_3dim_vt_bstr (SAFEARRAY* safearray)
4794 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4797 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4798 long i, j, k, failed;
4802 VariantInit (&element);
4804 dim = SafeArrayGetDim (safearray);
4808 SafeArrayGetLBound (safearray, 1, &lbound1);
4809 SafeArrayGetUBound (safearray, 1, &ubound1);
4811 if ((lbound1 != 0) || (ubound1 != 1))
4814 SafeArrayGetLBound (safearray, 2, &lbound2);
4815 SafeArrayGetUBound (safearray, 2, &ubound2);
4817 if ((lbound2 != 0) || (ubound2 != 1))
4820 SafeArrayGetLBound (safearray, 3, &lbound3);
4821 SafeArrayGetUBound (safearray, 3, &ubound3);
4823 if ((lbound3 != 0) || (ubound3 != 2))
4826 for (i= lbound1; i <= ubound1; i++) {
4828 for (j= lbound2; j <= ubound2; j++) {
4830 for (k= lbound3; k <= ubound3; k++) {
4832 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4834 failed = ((element.vt != VT_BSTR)
4835 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4836 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4837 VariantClear (&element);
4844 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4849 element.vt = VT_BSTR;
4850 element.bstrVal = SysAllocString(L"Should not be copied");
4851 SafeArrayPutElement (safearray, indices, &element);
4852 VariantClear (&element);
4857 LIBTEST_API int STDCALL
4858 mono_test_marshal_safearray_in_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4860 return mono_test_marshal_safearray_in_byval_3dim_vt_bstr (*safearray);
4863 LIBTEST_API int STDCALL
4864 mono_test_marshal_safearray_in_out_byref_1dim_empty (SAFEARRAY** safearray)
4866 /* Check that the input array is what is expected and change it so the caller can check */
4867 /* correct marshalling back to managed code */
4870 long lbound, ubound;
4871 SAFEARRAYBOUND dimensions [1];
4873 wchar_t buffer [20];
4877 /* Check that in array is one dimensional and empty */
4879 dim = SafeArrayGetDim (*safearray);
4884 SafeArrayGetLBound (*safearray, 1, &lbound);
4885 SafeArrayGetUBound (*safearray, 1, &ubound);
4887 if ((lbound > 0) || (ubound > 0)) {
4891 /* Re-dimension the array and return a one-dimensional array of 8 variants filled with "0" to "7" */
4893 dimensions [0].lLbound = 0;
4894 dimensions [0].cElements = 8;
4896 hr = SafeArrayRedim (*safearray, dimensions);
4900 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
4902 VariantInit (&vOut);
4904 _ltow (i,buffer,10);
4905 vOut.bstrVal = SysAllocString (buffer);
4907 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
4908 VariantClear (&vOut);
4909 SafeArrayDestroy (*safearray);
4912 VariantClear (&vOut);
4917 LIBTEST_API int STDCALL
4918 mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4920 /* Check that the input array is what is expected and change it so the caller can check */
4921 /* correct marshalling back to managed code */
4924 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4925 SAFEARRAYBOUND dimensions [1];
4926 long i, j, k, failed;
4927 wchar_t buffer [20];
4932 VariantInit (&element);
4934 /* Check that in array is three dimensional and contains the expected values */
4936 dim = SafeArrayGetDim (*safearray);
4940 SafeArrayGetLBound (*safearray, 1, &lbound1);
4941 SafeArrayGetUBound (*safearray, 1, &ubound1);
4943 if ((lbound1 != 0) || (ubound1 != 1))
4946 SafeArrayGetLBound (*safearray, 2, &lbound2);
4947 SafeArrayGetUBound (*safearray, 2, &ubound2);
4949 if ((lbound2 != 0) || (ubound2 != 1))
4952 SafeArrayGetLBound (*safearray, 3, &lbound3);
4953 SafeArrayGetUBound (*safearray, 3, &ubound3);
4955 if ((lbound3 != 0) || (ubound3 != 2))
4958 for (i= lbound1; i <= ubound1; i++) {
4960 for (j= lbound2; j <= ubound2; j++) {
4962 for (k= lbound3; k <= ubound3; k++) {
4964 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
4966 failed = ((element.vt != VT_BSTR)
4967 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4968 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4969 VariantClear (&element);
4976 hr = SafeArrayDestroy (*safearray);
4980 /* Return a new one-dimensional array of 8 variants filled with "0" to "7" */
4982 dimensions [0].lLbound = 0;
4983 dimensions [0].cElements = 8;
4985 *safearray = SafeArrayCreate (VT_VARIANT, 1, dimensions);
4987 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
4989 VariantInit (&vOut);
4991 _ltow (i,buffer,10);
4992 vOut.bstrVal = SysAllocString (buffer);
4994 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
4995 VariantClear (&vOut);
4996 SafeArrayDestroy (*safearray);
4999 VariantClear (&vOut);
5004 LIBTEST_API int STDCALL
5005 mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 (SAFEARRAY** safearray)
5007 /* Check that the input array is what is expected and change it so the caller can check */
5008 /* correct marshalling back to managed code */
5011 long lbound1, ubound1;
5017 VariantInit (&element);
5019 /* Check that in array is one dimensional and contains the expected value */
5021 dim = SafeArrayGetDim (*safearray);
5025 SafeArrayGetLBound (*safearray, 1, &lbound1);
5026 SafeArrayGetUBound (*safearray, 1, &ubound1);
5029 if ((lbound1 != 0) || (ubound1 != 1))
5033 for (i= lbound1; i <= ubound1; i++) {
5035 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
5037 failed = (element.vt != VT_I4) || (element.lVal != i+1);
5038 VariantClear (&element);
5043 /* Change one of the elements of the array to verify that [out] parameter is marshalled back to the managed side */
5048 SafeArrayPutElement (*safearray, indices, &element);
5049 VariantClear (&element);
5054 LIBTEST_API int STDCALL
5055 mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (SAFEARRAY* safearray)
5057 /* Check that the input array is what is expected and change it so the caller can check */
5058 /* correct marshalling back to managed code */
5061 long lbound1, ubound1;
5062 SAFEARRAYBOUND dimensions [1];
5068 VariantInit (&element);
5070 /* Check that in array is one dimensional and contains the expected value */
5072 dim = SafeArrayGetDim (safearray);
5076 SafeArrayGetLBound (safearray, 1, &lbound1);
5077 SafeArrayGetUBound (safearray, 1, &ubound1);
5079 if ((lbound1 != 0) || (ubound1 != 0))
5082 for (i= lbound1; i <= ubound1; i++) {
5084 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
5086 failed = (element.vt != VT_I4) || (element.lVal != i+1);
5087 VariantClear (&element);
5092 /* Change the array to verify how [out] parameter is marshalled back to the managed side */
5094 /* Redimension the array */
5095 dimensions [0].lLbound = lbound1;
5096 dimensions [0].cElements = 2;
5097 hr = SafeArrayRedim(safearray, dimensions);
5101 element.lVal = 12345;
5102 SafeArrayPutElement (safearray, indices, &element);
5103 VariantClear (&element);
5107 element.lVal = -12345;
5108 SafeArrayPutElement (safearray, indices, &element);
5109 VariantClear (&element);
5114 LIBTEST_API int STDCALL
5115 mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr (SAFEARRAY* safearray)
5117 /* Check that the input array is what is expected and change it so the caller can check */
5118 /* correct marshalling back to managed code */
5121 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
5122 long i, j, k, failed;
5127 VariantInit (&element);
5129 /* Check that in array is three dimensional and contains the expected values */
5131 dim = SafeArrayGetDim (safearray);
5135 SafeArrayGetLBound (safearray, 1, &lbound1);
5136 SafeArrayGetUBound (safearray, 1, &ubound1);
5138 if ((lbound1 != 0) || (ubound1 != 1))
5141 SafeArrayGetLBound (safearray, 2, &lbound2);
5142 SafeArrayGetUBound (safearray, 2, &ubound2);
5144 if ((lbound2 != 0) || (ubound2 != 1))
5147 SafeArrayGetLBound (safearray, 3, &lbound3);
5148 SafeArrayGetUBound (safearray, 3, &ubound3);
5150 if ((lbound3 != 0) || (ubound3 != 2))
5153 for (i= lbound1; i <= ubound1; i++) {
5155 for (j= lbound2; j <= ubound2; j++) {
5157 for (k= lbound3; k <= ubound3; k++) {
5159 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
5161 failed = ((element.vt != VT_BSTR)
5162 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
5163 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
5164 VariantClear (&element);
5171 /* Change the elements of the array to verify that [out] parameter is marshalled back to the managed side */
5178 SafeArrayPutElement (safearray, indices, &element);
5179 VariantClear (&element);
5186 SafeArrayPutElement (safearray, indices, &element);
5187 VariantClear (&element);
5192 element.vt = VT_BSTR;
5193 element.bstrVal = marshal_bstr_alloc("ABCDEFG");
5194 SafeArrayPutElement (safearray, indices, &element);
5195 VariantClear (&element);
5200 LIBTEST_API int STDCALL
5201 mono_test_marshal_safearray_mixed(
5202 SAFEARRAY *safearray1,
5203 SAFEARRAY **safearray2,
5204 SAFEARRAY *safearray3,
5205 SAFEARRAY **safearray4
5210 /* Initialize out parameters */
5213 /* array1: Check that in array is one dimensional and contains the expected value */
5214 hr = mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (safearray1);
5216 /* array2: Fill in with some values to check on the managed side */
5218 hr = mono_test_marshal_safearray_out_1dim_vt_bstr (safearray2);
5220 /* array3: Check that in array is one dimensional and contains the expected value */
5222 hr = mono_test_marshal_safearray_in_byval_1dim_vt_mixed(safearray3);
5224 /* array4: Check input values and fill in with some values to check on the managed side */
5226 hr = mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr(safearray4);
5233 static int call_managed_res;
5236 call_managed (gpointer arg)
5238 SimpleDelegate del = arg;
5240 call_managed_res = del (42);
5243 LIBTEST_API int STDCALL
5244 mono_test_marshal_thread_attach (SimpleDelegate del)
5252 res = pthread_create (&t, NULL, (gpointer)call_managed, del);
5253 g_assert (res == 0);
5254 pthread_join (t, NULL);
5256 return call_managed_res;
5260 typedef int (STDCALL *Callback) (void);
5262 static Callback callback;
5264 LIBTEST_API void STDCALL
5265 mono_test_marshal_set_callback (Callback cb)
5270 LIBTEST_API int STDCALL
5271 mono_test_marshal_call_callback (void)
5276 LIBTEST_API int STDCALL
5277 mono_test_marshal_lpstr (char *str)
5279 return strcmp ("ABC", str);
5282 LIBTEST_API int STDCALL
5283 mono_test_marshal_lpwstr (gunichar2 *str)
5288 s = g_utf16_to_utf8 (str, -1, NULL, NULL, NULL);
5289 res = strcmp ("ABC", s);
5295 LIBTEST_API char* STDCALL
5296 mono_test_marshal_return_lpstr (void)
5298 char *res = marshal_alloc (4);
5299 strcpy (res, "XYZ");
5304 LIBTEST_API gunichar2* STDCALL
5305 mono_test_marshal_return_lpwstr (void)
5307 gunichar2 *res = marshal_alloc (8);
5308 gunichar2* tmp = g_utf8_to_utf16 ("XYZ", -1, NULL, NULL, NULL);
5310 memcpy (res, tmp, 8);
5319 LIBTEST_API int STDCALL
5320 mono_test_has_thiscall (void)
5326 _mono_test_native_thiscall1 (int arg)
5332 _mono_test_native_thiscall2 (int arg, int arg2)
5334 return arg + (arg2^1);
5338 _mono_test_native_thiscall3 (int arg, int arg2, int arg3)
5340 return arg + (arg2^1) + (arg3^2);
5343 #elif defined(__GNUC__)
5345 LIBTEST_API int STDCALL
5346 mono_test_has_thiscall (void)
5351 #define def_asm_fn(name) \
5353 "\t.globl _" #name "\n" \
5355 "\t.globl __" #name "\n" \
5360 def_asm_fn(mono_test_native_thiscall1)
5361 "\tmovl %ecx,%eax\n"
5364 def_asm_fn(mono_test_native_thiscall2)
5365 "\tmovl %ecx,%eax\n"
5366 "\tmovl 4(%esp),%ecx\n"
5368 "\taddl %ecx,%eax\n"
5371 def_asm_fn(mono_test_native_thiscall3)
5372 "\tmovl %ecx,%eax\n"
5373 "\tmovl 4(%esp),%ecx\n"
5375 "\taddl %ecx,%eax\n"
5376 "\tmovl 8(%esp),%ecx\n"
5378 "\taddl %ecx,%eax\n"
5385 LIBTEST_API int STDCALL
5386 mono_test_has_thiscall (void)