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);
270 LIBTEST_API struct NestedFloat STDCALL
271 mono_return_nested_float (void)
273 struct NestedFloat f;
281 LIBTEST_API int STDCALL
282 mono_test_many_int_arguments (int a, int b, int c, int d, int e,
283 int f, int g, int h, int i, int j);
284 LIBTEST_API short STDCALL
285 mono_test_many_short_arguments (short a, short b, short c, short d, short e,
286 short f, short g, short h, short i, short j);
287 LIBTEST_API char STDCALL
288 mono_test_many_char_arguments (char a, char b, char c, char d, char e,
289 char f, char g, char h, char i, char j);
291 LIBTEST_API int STDCALL
292 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)
294 return a + b + c + d + e + f + g + h + i + j;
297 LIBTEST_API short STDCALL
298 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)
300 return a + b + c + d + e + f + g + h + i + j;
303 LIBTEST_API char STDCALL
304 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)
306 return a + b + c + d + e + f + g + h + i + j;
309 LIBTEST_API float STDCALL
310 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)
312 return a + b + c + d + e + f + g + h + i + j;
315 LIBTEST_API double STDCALL
316 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)
318 return a + b + c + d + e + f + g + h + i + j;
321 LIBTEST_API double STDCALL
322 mono_test_split_double_arguments (double a, double b, float c, double d, double e)
324 return a + b + c + d + e;
327 LIBTEST_API int STDCALL
328 mono_test_puts_static (char *s)
330 // printf ("TEST %s\n", s);
334 typedef int (STDCALL *SimpleDelegate3) (int a, int b);
336 LIBTEST_API int STDCALL
337 mono_invoke_delegate (SimpleDelegate3 delegate)
341 // printf ("start invoke %p\n", delegate);
343 res = delegate (2, 3);
345 // printf ("end invoke\n");
350 LIBTEST_API int STDCALL
351 mono_invoke_simple_delegate (SimpleDelegate d)
356 LIBTEST_API int STDCALL
357 mono_test_marshal_char (short a1)
365 LIBTEST_API void STDCALL
366 mono_test_marshal_char_array (gunichar2 *s)
368 const char m[] = "abcdef";
372 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
380 LIBTEST_API int STDCALL
381 mono_test_marshal_ansi_char_array (char *s)
383 const char m[] = "abcdef";
385 if (strncmp ("qwer", s, 4))
388 memcpy (s, m, sizeof (m));
392 LIBTEST_API int STDCALL
393 mono_test_marshal_unicode_char_array (gunichar2 *s)
395 const char m[] = "abcdef";
396 const char expected[] = "qwer";
400 s1 = g_utf8_to_utf16 (m, -1, NULL, &len1, NULL);
401 s2 = g_utf8_to_utf16 (expected, -1, NULL, &len2, NULL);
405 if (memcmp (s, s2, len2))
408 memcpy (s, s1, len1);
413 LIBTEST_API int STDCALL
414 mono_test_empty_pinvoke (int i)
419 LIBTEST_API int STDCALL
420 mono_test_marshal_bool_byref (int a, int *b, int c)
429 LIBTEST_API int STDCALL
430 mono_test_marshal_bool_in_as_I1_U1 (char bTrue, char bFalse)
439 LIBTEST_API int STDCALL
440 mono_test_marshal_bool_out_as_I1_U1 (char* bTrue, char* bFalse)
442 if (!bTrue || !bFalse)
451 LIBTEST_API int STDCALL
452 mono_test_marshal_bool_ref_as_I1_U1 (char* bTrue, char* bFalse)
454 if (!bTrue || !bFalse)
468 LIBTEST_API int STDCALL
469 mono_test_marshal_array (int *a1)
473 for (i = 0; i < 50; i++)
479 LIBTEST_API int STDCALL
480 mono_test_marshal_inout_array (int *a1)
484 for (i = 0; i < 50; i++) {
486 a1 [i] = 50 - a1 [i];
492 LIBTEST_API int /* cdecl */
493 mono_test_marshal_inout_array_cdecl (int *a1)
495 return mono_test_marshal_inout_array (a1);
498 LIBTEST_API int STDCALL
499 mono_test_marshal_out_array (int *a1)
503 for (i = 0; i < 50; i++) {
510 LIBTEST_API int STDCALL
511 mono_test_marshal_inout_nonblittable_array (gunichar2 *a1)
515 for (i = 0; i < 10; i++) {
535 LIBTEST_API simplestruct STDCALL
536 mono_test_return_vtype (int i)
539 static gunichar2 test2 [] = { 'T', 'E', 'S', 'T', '2', 0 };
550 LIBTEST_API void STDCALL
551 mono_test_delegate_struct (void)
553 // printf ("TEST\n");
556 typedef char* (STDCALL *ReturnStringDelegate) (const char *s);
558 LIBTEST_API char * STDCALL
559 mono_test_return_string (ReturnStringDelegate func)
563 // printf ("mono_test_return_string\n");
568 // printf ("got string: %s\n", res);
569 return marshal_strdup ("12345");
572 typedef int (STDCALL *RefVTypeDelegate) (int a, simplestruct *ss, int b);
574 LIBTEST_API int STDCALL
575 mono_test_ref_vtype (int a, simplestruct *ss, int b, RefVTypeDelegate func)
577 if (a == 1 && b == 2 && ss->a == 0 && ss->b == 1 && ss->c == 0 &&
578 !strcmp (ss->d, "TEST1")) {
584 return func (a, ss, b);
590 typedef int (STDCALL *OutVTypeDelegate) (int a, simplestruct *ss, int b);
592 LIBTEST_API int STDCALL
593 mono_test_marshal_out_struct (int a, simplestruct *ss, int b, OutVTypeDelegate func)
595 /* Check that the input pointer is ignored */
596 ss->d = (gpointer)0x12345678;
600 if (ss->a && ss->b && ss->c && !strcmp (ss->d, "TEST3"))
606 typedef int (STDCALL *InVTypeDelegate) (int a, simplestruct *ss, int b);
608 LIBTEST_API int STDCALL
609 mono_test_marshal_in_struct (int a, simplestruct *ss, int b, InVTypeDelegate func)
614 memcpy (&ss2, ss, sizeof (simplestruct));
616 res = func (a, ss, b);
618 printf ("mono_test_marshal_in_struct () failed: %d\n", res);
622 /* Check that no modifications is made to the struct */
623 if (ss2.a == ss->a && ss2.b == ss->b && ss2.c == ss->c && ss2.d == ss->d)
631 SimpleDelegate func, func2, func3;
634 LIBTEST_API DelegateStruct STDCALL
635 mono_test_marshal_delegate_struct (DelegateStruct ds)
639 res.a = ds.func (ds.a) + ds.func2 (ds.a) + (ds.func3 == NULL ? 0 : 1);
641 res.func2 = ds.func2;
647 LIBTEST_API int STDCALL
648 mono_test_marshal_struct (simplestruct ss)
650 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
651 !strcmp (ss.d, "TEST"))
657 LIBTEST_API int STDCALL
658 mono_test_marshal_byref_struct (simplestruct *ss, int a, int b, int c, char *d)
660 gboolean res = (ss->a == a && ss->b == b && ss->c == c && strcmp (ss->d, d) == 0);
662 marshal_free ((char*)ss->d);
667 ss->d = marshal_strdup ("DEF");
683 LIBTEST_API int STDCALL
684 mono_test_marshal_struct2 (simplestruct2 ss)
686 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
687 !strcmp (ss.d, "TEST") &&
688 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
694 /* on HP some of the struct should be on the stack and not in registers */
695 LIBTEST_API int STDCALL
696 mono_test_marshal_struct2_2 (int i, int j, int k, simplestruct2 ss)
698 if (i != 10 || j != 11 || k != 12)
700 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
701 !strcmp (ss.d, "TEST") &&
702 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
708 LIBTEST_API int STDCALL
709 mono_test_marshal_lpstruct (simplestruct *ss)
711 if (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
712 !strcmp (ss->d, "TEST"))
718 LIBTEST_API int STDCALL
719 mono_test_marshal_lpstruct_blittable (point *p)
721 if (p->x == 1.0 && p->y == 2.0)
727 LIBTEST_API int STDCALL
728 mono_test_marshal_struct_array (simplestruct2 *ss)
730 if (! (ss[0].a == 0 && ss[0].b == 1 && ss[0].c == 0 &&
731 !strcmp (ss[0].d, "TEST") &&
732 ss[0].e == 99 && ss[0].f == 1.5 && ss[0].g == 42 && ss[0].h == (guint64)123))
735 if (! (ss[1].a == 0 && ss[1].b == 0 && ss[1].c == 0 &&
736 !strcmp (ss[1].d, "TEST2") &&
737 ss[1].e == 100 && ss[1].f == 2.5 && ss[1].g == 43 && ss[1].h == (guint64)124))
743 typedef struct long_align_struct {
749 LIBTEST_API int STDCALL
750 mono_test_marshal_long_align_struct_array (long_align_struct *ss)
752 return ss[0].a + ss[0].b + ss[0].c + ss[1].a + ss[1].b + ss[1].c;
755 LIBTEST_API simplestruct2 * STDCALL
756 mono_test_marshal_class (int i, int j, int k, simplestruct2 *ss, int l)
763 if (i != 10 || j != 11 || k != 12 || l != 14)
765 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
766 !strcmp (ss->d, "TEST") &&
767 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
770 res = marshal_new0 (simplestruct2, 1);
771 memcpy (res, ss, sizeof (simplestruct2));
772 res->d = marshal_strdup ("TEST");
776 LIBTEST_API int STDCALL
777 mono_test_marshal_byref_class (simplestruct2 **ssp)
779 simplestruct2 *ss = *ssp;
782 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
783 !strcmp (ss->d, "TEST") &&
784 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
787 res = marshal_new0 (simplestruct2, 1);
788 memcpy (res, ss, sizeof (simplestruct2));
789 res->d = marshal_strdup ("TEST-RES");
801 /* Yes, this is correct, we are only trying to determine the value of the stack here */
806 LIBTEST_API int STDCALL
807 reliable_delegate (int a)
813 * Checks whether get_sp() works as expected. It doesn't work with gcc-2.95.3 on linux.
816 is_get_sp_reliable (void)
820 reliable_delegate(1);
822 reliable_delegate(1);
827 LIBTEST_API int STDCALL
828 mono_test_marshal_delegate (SimpleDelegate delegate)
832 /* Check that the delegate wrapper is stdcall */
837 if (is_get_sp_reliable())
838 g_assert (sp1 == sp2);
843 static int STDCALL inc_cb (int i)
848 LIBTEST_API int STDCALL
849 mono_test_marshal_out_delegate (SimpleDelegate *delegate)
856 LIBTEST_API SimpleDelegate STDCALL
857 mono_test_marshal_return_delegate (SimpleDelegate delegate)
863 return_plus_one (int i)
868 LIBTEST_API SimpleDelegate STDCALL
869 mono_test_marshal_return_delegate_2 (void)
871 return return_plus_one;
874 typedef simplestruct (STDCALL *SimpleDelegate2) (simplestruct ss);
877 is_utf16_equals (gunichar2 *s1, const char *s2)
882 s = g_utf16_to_utf8 (s1, -1, NULL, NULL, NULL);
883 res = strcmp (s, s2);
889 LIBTEST_API int STDCALL
890 mono_test_marshal_delegate2 (SimpleDelegate2 delegate)
892 simplestruct ss, res;
898 ss.d2 = g_utf8_to_utf16 ("TEST2", -1, NULL, NULL, NULL);
901 if (! (res.a && !res.b && res.c && !strcmp (res.d, "TEST-RES") && is_utf16_equals (res.d2, "TEST2-RES")))
907 typedef simplestruct* (STDCALL *SimpleDelegate4) (simplestruct *ss);
909 LIBTEST_API int STDCALL
910 mono_test_marshal_delegate4 (SimpleDelegate4 delegate)
921 res = delegate (&ss);
925 /* Check return value */
926 if (! (!res->a && res->b && !res->c && !strcmp (res->d, "TEST")))
929 /* Check NULL argument and NULL result */
930 res = delegate (NULL);
937 typedef int (STDCALL *SimpleDelegate5) (simplestruct **ss);
939 LIBTEST_API int STDCALL
940 mono_test_marshal_delegate5 (SimpleDelegate5 delegate)
953 res = delegate (&ptr);
957 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
963 LIBTEST_API int STDCALL
964 mono_test_marshal_delegate6 (SimpleDelegate5 delegate)
968 res = delegate (NULL);
973 typedef int (STDCALL *SimpleDelegate7) (simplestruct **ss);
975 LIBTEST_API int STDCALL
976 mono_test_marshal_delegate7 (SimpleDelegate7 delegate)
981 /* Check that the input pointer is ignored */
982 ptr = (gpointer)0x12345678;
984 res = delegate (&ptr);
988 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
994 typedef int (STDCALL *InOutByvalClassDelegate) (simplestruct *ss);
996 LIBTEST_API int STDCALL
997 mono_test_marshal_inout_byval_class_delegate (InOutByvalClassDelegate delegate)
1005 ss.d = g_strdup_printf ("%s", "FOO");
1007 res = delegate (&ss);
1011 if (!(ss.a && !ss.b && ss.c && !strcmp (ss.d, "RES")))
1017 typedef int (STDCALL *SimpleDelegate8) (gunichar2 *s);
1019 LIBTEST_API int STDCALL
1020 mono_test_marshal_delegate8 (SimpleDelegate8 delegate, gunichar2 *s)
1022 return delegate (s);
1025 typedef int (STDCALL *return_int_fnt) (int i);
1026 typedef int (STDCALL *SimpleDelegate9) (return_int_fnt d);
1028 LIBTEST_API int STDCALL
1029 mono_test_marshal_delegate9 (SimpleDelegate9 delegate, gpointer ftn)
1031 return delegate (ftn);
1040 LIBTEST_API int STDCALL
1041 mono_test_marshal_delegate10 (SimpleDelegate9 delegate)
1043 return delegate (return_self);
1046 typedef int (STDCALL *PrimitiveByrefDelegate) (int *i);
1048 LIBTEST_API int STDCALL
1049 mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate delegate)
1053 int res = delegate (&i);
1063 typedef int (STDCALL *return_int_delegate) (int i);
1065 typedef return_int_delegate (STDCALL *ReturnDelegateDelegate) (void);
1067 LIBTEST_API int STDCALL
1068 mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d)
1073 LIBTEST_API int STDCALL
1074 mono_test_marshal_stringbuilder (char *s, int n)
1076 const char m[] = "This is my message. Isn't it nice?";
1078 if (strcmp (s, "ABCD") != 0)
1085 LIBTEST_API int STDCALL
1086 mono_test_marshal_stringbuilder2 (char *s, int n)
1088 const char m[] = "EFGH";
1095 LIBTEST_API int STDCALL
1096 mono_test_marshal_stringbuilder_default (char *s, int n)
1098 const char m[] = "This is my message. Isn't it nice?";
1105 LIBTEST_API int STDCALL
1106 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
1108 const char m[] = "This is my message. Isn't it nice?";
1112 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1114 len = (len * 2) + 2;
1117 memcpy (s, s2, len);
1124 LIBTEST_API void STDCALL
1125 mono_test_marshal_stringbuilder_out (char **s)
1127 const char m[] = "This is my message. Isn't it nice?";
1130 str = marshal_alloc (strlen (m) + 1);
1131 memcpy (str, m, strlen (m) + 1);
1136 LIBTEST_API int STDCALL
1137 mono_test_marshal_stringbuilder_out_unicode (gunichar2 **s)
1139 const char m[] = "This is my message. Isn't it nice?";
1143 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1145 len = (len * 2) + 2;
1146 *s = marshal_alloc (len);
1147 memcpy (*s, s2, len);
1154 LIBTEST_API int STDCALL
1155 mono_test_marshal_stringbuilder_ref (char **s)
1157 const char m[] = "This is my message. Isn't it nice?";
1160 if (strcmp (*s, "ABC"))
1163 str = marshal_alloc (strlen (m) + 1);
1164 memcpy (str, m, strlen (m) + 1);
1176 LIBTEST_API int STDCALL
1177 mono_test_marshal_empty_string_array (char **array)
1179 return (array == NULL) ? 0 : 1;
1182 LIBTEST_API int STDCALL
1183 mono_test_marshal_string_array (char **array)
1185 if (strcmp (array [0], "ABC"))
1187 if (strcmp (array [1], "DEF"))
1190 if (array [2] != NULL)
1196 LIBTEST_API int STDCALL
1197 mono_test_marshal_byref_string_array (char ***array)
1202 if (strcmp ((*array) [0], "Alpha"))
1204 if (strcmp ((*array) [1], "Beta"))
1206 if (strcmp ((*array) [2], "Gamma"))
1212 LIBTEST_API int STDCALL
1213 mono_test_marshal_stringbuilder_array (char **array)
1215 if (strcmp (array [0], "ABC"))
1217 if (strcmp (array [1], "DEF"))
1220 strcpy (array [0], "DEF");
1221 strcpy (array [1], "ABC");
1226 LIBTEST_API int STDCALL
1227 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
1229 GError *error = NULL;
1232 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
1233 if (strcmp (s, "ABC")) {
1240 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
1241 if (strcmp (s, "DEF")) {
1248 if (strcmp (array2 [0], "ABC"))
1251 if (strcmp (array2 [1], "DEF"))
1257 /* this does not work on Redhat gcc 2.96 */
1258 LIBTEST_API int STDCALL
1259 mono_test_empty_struct (int a, EmptyStruct es, int b)
1261 // printf ("mono_test_empty_struct %d %d\n", a, b);
1263 // Intel icc on ia64 passes 'es' in 2 registers
1264 #if defined(__ia64) && defined(__INTEL_COMPILER)
1267 if (a == 1 && b == 2)
1277 LIBTEST_API ByValStrStruct * STDCALL
1278 mono_test_byvalstr_gen (void)
1280 ByValStrStruct *ret;
1282 ret = malloc(sizeof(ByValStrStruct));
1283 memset(ret, 'a', sizeof(ByValStrStruct)-1);
1284 ret->a[sizeof(ByValStrStruct)-1] = 0;
1289 LIBTEST_API int STDCALL
1290 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
1294 ret = strcmp(data->a, correctString);
1295 // printf ("T1: %s\n", data->a);
1296 // printf ("T2: %s\n", correctString);
1298 /* we need g_free because the allocation was performed by mono_test_byvalstr_gen */
1306 } ByValStrStruct_Unicode;
1308 LIBTEST_API int STDCALL
1309 mono_test_byvalstr_check_unicode (ByValStrStruct_Unicode *ref, int test)
1311 if (ref->flag != 0x1234abcd){
1312 printf ("overwritten data");
1316 if (test == 1 || test == 3){
1317 if (ref->a [0] != '1' ||
1318 ref->a [1] != '2' ||
1324 if (ref->a [0] != '1' ||
1332 LIBTEST_API int STDCALL
1333 NameManglingAnsi (char *data)
1335 return data [0] + data [1] + data [2];
1338 LIBTEST_API int STDCALL
1339 NameManglingAnsiA (char *data)
1341 g_assert_not_reached ();
1344 LIBTEST_API int STDCALL
1345 NameManglingAnsiW (char *data)
1347 g_assert_not_reached ();
1350 LIBTEST_API int STDCALL
1351 NameManglingAnsi2A (char *data)
1353 return data [0] + data [1] + data [2];
1356 LIBTEST_API int STDCALL
1357 NameManglingAnsi2W (char *data)
1359 g_assert_not_reached ();
1362 LIBTEST_API int STDCALL
1363 NameManglingUnicode (char *data)
1365 g_assert_not_reached ();
1368 LIBTEST_API int STDCALL
1369 NameManglingUnicodeW (gunichar2 *data)
1371 return data [0] + data [1] + data [2];
1374 LIBTEST_API int STDCALL
1375 NameManglingUnicode2 (gunichar2 *data)
1377 return data [0] + data [1] + data [2];
1380 LIBTEST_API int STDCALL
1381 NameManglingAutoW (char *data)
1384 return (data [0] + data [1] + data [2]) == 131 ? 0 : 1;
1386 g_assert_not_reached ();
1390 LIBTEST_API int STDCALL
1391 NameManglingAuto (char *data)
1394 return (data [0] + data [1] + data [2]) == 198 ? 0 : 1;
1396 g_assert_not_reached ();
1400 typedef int (STDCALL *intcharFunc)(const char*);
1402 LIBTEST_API void STDCALL
1403 callFunction (intcharFunc f)
1413 LIBTEST_API int STDCALL
1414 class_marshal_test0 (SimpleObj *obj1)
1416 // printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
1418 if (strcmp(obj1->str, "T1"))
1426 LIBTEST_API int STDCALL
1427 class_marshal_test4 (SimpleObj *obj1)
1435 LIBTEST_API void STDCALL
1436 class_marshal_test1 (SimpleObj **obj1)
1438 SimpleObj *res = malloc (sizeof (SimpleObj));
1440 res->str = marshal_strdup ("ABC");
1446 LIBTEST_API int STDCALL
1447 class_marshal_test2 (SimpleObj **obj1)
1449 // printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
1451 if (strcmp((*obj1)->str, "ABC"))
1453 if ((*obj1)->i != 5)
1459 LIBTEST_API int STDCALL
1460 string_marshal_test0 (char *str)
1462 if (strcmp (str, "TEST0"))
1468 LIBTEST_API void STDCALL
1469 string_marshal_test1 (const char **str)
1471 *str = marshal_strdup ("TEST1");
1474 LIBTEST_API int STDCALL
1475 string_marshal_test2 (char **str)
1477 // printf ("string_marshal_test2 %s\n", *str);
1479 if (strcmp (*str, "TEST1"))
1482 *str = marshal_strdup ("TEST2");
1487 LIBTEST_API int STDCALL
1488 string_marshal_test3 (char *str)
1501 LIBTEST_API BlittableClass* STDCALL
1502 TestBlittableClass (BlittableClass *vl)
1504 BlittableClass *res;
1506 // printf ("TestBlittableClass %d %d\n", vl->a, vl->b);
1512 res = marshal_new0 (BlittableClass, 1);
1513 memcpy (res, vl, sizeof (BlittableClass));
1515 res = marshal_new0 (BlittableClass, 1);
1523 typedef struct OSVERSIONINFO_STRUCT
1527 } OSVERSIONINFO_STRUCT;
1529 LIBTEST_API int STDCALL
1530 MyGetVersionEx (OSVERSIONINFO_STRUCT *osvi)
1533 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1538 return osvi->a + osvi->b;
1541 LIBTEST_API int STDCALL
1542 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO_STRUCT *osvi)
1545 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1550 return osvi->a + osvi->b;
1553 LIBTEST_API int STDCALL
1554 mono_test_marshal_point (point pt)
1556 // printf("point %g %g\n", pt.x, pt.y);
1557 if (pt.x == 1.25 && pt.y == 3.5)
1568 LIBTEST_API int STDCALL
1569 mono_test_marshal_mixed_point (mixed_point pt)
1571 // printf("mixed point %d %g\n", pt.x, pt.y);
1572 if (pt.x == 5 && pt.y == 6.75)
1578 LIBTEST_API int STDCALL
1579 mono_test_marshal_mixed_point_2 (mixed_point *pt)
1581 if (pt->x != 5 || pt->y != 6.75)
1590 LIBTEST_API int STDCALL
1591 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
1594 if (*b1 != 0 && *b1 != 1)
1596 if (*b2 != 0 && *b2 != -1) /* variant_bool */
1598 if (*b3 != 0 && *b3 != 1)
1600 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
1612 short b2; /* variant_bool */
1616 LIBTEST_API int STDCALL
1617 marshal_test_bool_struct(struct BoolStruct *s)
1620 if (s->b1 != 0 && s->b1 != 1)
1622 if (s->b2 != 0 && s->b2 != -1)
1624 if (s->b3 != 0 && s->b3 != 1)
1626 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1643 LIBTEST_API int STDCALL
1644 mono_test_marshal_long_struct (LongStruct *s)
1646 return s->i + s->l.l;
1649 LIBTEST_API void STDCALL
1650 mono_test_last_error (int err)
1659 LIBTEST_API int STDCALL
1660 mono_test_asany (void *ptr, int what)
1664 return (*(int*)ptr == 5) ? 0 : 1;
1666 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1668 simplestruct2 ss = *(simplestruct2*)ptr;
1670 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1671 !strcmp (ss.d, "TEST") &&
1672 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1678 GError *error = NULL;
1681 s = g_utf16_to_utf8 (ptr, -1, NULL, NULL, &error);
1686 if (!strcmp (s, "ABC")) {
1696 g_assert_not_reached ();
1710 LIBTEST_API int STDCALL
1711 mono_test_marshal_asany_in (void* ptr)
1713 AsAnyStruct* asAny = ptr;
1714 int res = asAny->i + asAny->j + asAny->k;
1719 LIBTEST_API int STDCALL
1720 mono_test_marshal_asany_inout (void* ptr)
1722 AsAnyStruct* asAny = ptr;
1723 int res = asAny->i + asAny->j + asAny->k;
1725 marshal_free (asAny->s);
1735 LIBTEST_API int STDCALL
1736 mono_test_marshal_asany_out (void* ptr)
1738 AsAnyStruct* asAny = ptr;
1739 int res = asAny->i + asAny->j + asAny->k;
1750 * AMD64 marshalling tests.
1753 typedef struct amd64_struct1 {
1760 LIBTEST_API amd64_struct1 STDCALL
1761 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
1771 LIBTEST_API amd64_struct1 STDCALL
1772 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)
1777 s.l += 1 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8;
1782 typedef struct amd64_struct2 {
1787 LIBTEST_API amd64_struct2 STDCALL
1788 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
1796 typedef struct amd64_struct3 {
1800 LIBTEST_API amd64_struct3 STDCALL
1801 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s)
1808 typedef struct amd64_struct4 {
1812 LIBTEST_API amd64_struct4 STDCALL
1813 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s)
1822 * IA64 marshalling tests.
1824 typedef struct test_struct5 {
1828 LIBTEST_API test_struct5 STDCALL
1829 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, test_struct5 s, int i, double d3, double d4)
1831 s.d1 += d1 + d2 + i;
1832 s.d2 += d3 + d4 + i;
1837 typedef struct test_struct6 {
1841 LIBTEST_API test_struct6 STDCALL
1842 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, test_struct6 s, int i, double d3, double d4)
1844 s.d1 += d1 + d2 + i;
1850 static guint32 custom_res [2];
1852 LIBTEST_API void* STDCALL
1853 mono_test_marshal_pass_return_custom (int i, guint32 *ptr, int j)
1855 /* ptr will be freed by CleanupNative, so make a copy */
1856 custom_res [0] = 0; /* not allocated by AllocHGlobal */
1857 custom_res [1] = ptr [1];
1862 LIBTEST_API int STDCALL
1863 mono_test_marshal_pass_out_custom (int i, guint32 **ptr, int j)
1866 custom_res [1] = i + j + 10;
1873 LIBTEST_API int STDCALL
1874 mono_test_marshal_pass_inout_custom (int i, guint32 *ptr, int j)
1877 ptr [1] = i + ptr [1] + j;
1882 LIBTEST_API int STDCALL
1883 mono_test_marshal_pass_out_byval_custom (int i, guint32 *ptr, int j)
1885 return ptr == NULL ? 0 : 1;
1888 LIBTEST_API int STDCALL
1889 mono_test_marshal_pass_byref_custom (int i, guint32 **ptr, int j)
1896 LIBTEST_API void* STDCALL
1897 mono_test_marshal_pass_return_custom2 (int i, guint32 *ptr, int j)
1899 g_assert_not_reached ();
1904 LIBTEST_API void* STDCALL
1905 mono_test_marshal_pass_return_custom_null (int i, guint32 *ptr, int j)
1907 g_assert (ptr == NULL);
1912 typedef void *(STDCALL *PassReturnPtrDelegate) (void *ptr);
1914 LIBTEST_API int STDCALL
1915 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del)
1929 /* FIXME: Freed with FreeHGlobal */
1937 LIBTEST_API int STDCALL
1938 mono_test_marshal_pass_return_custom_null_in_delegate (PassReturnPtrDelegate del)
1940 void *ptr = del (NULL);
1942 return (ptr == NULL) ? 15 : 0;
1945 typedef void (STDCALL *CustomOutParamDelegate) (void **pptr);
1947 LIBTEST_API int STDCALL
1948 mono_test_marshal_custom_out_param_delegate (CustomOutParamDelegate del)
1960 typedef int (STDCALL *ReturnEnumDelegate) (int e);
1962 LIBTEST_API int STDCALL
1963 mono_test_marshal_return_enum_delegate (ReturnEnumDelegate func)
1973 typedef BlittableStruct (STDCALL *SimpleDelegate10) (BlittableStruct ss);
1975 LIBTEST_API int STDCALL
1976 mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 delegate)
1978 BlittableStruct ss, res;
1985 res = delegate (ss);
1986 if (! ((res.a == -1) && (res.b == -2) && (res.c == -3) && (res.d == -55)))
1992 LIBTEST_API int STDCALL
1993 mono_test_stdcall_name_mangling (int a, int b, int c)
1999 mono_test_stdcall_mismatch_1 (int a, int b, int c)
2004 LIBTEST_API int STDCALL
2005 mono_test_stdcall_mismatch_2 (int a, int b, int c)
2011 * PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
2018 typedef SmallStruct1 (STDCALL *SmallStructDelegate1) (SmallStruct1 ss);
2020 LIBTEST_API int STDCALL
2021 mono_test_marshal_small_struct_delegate1 (SmallStructDelegate1 delegate)
2023 SmallStruct1 ss, res;
2027 res = delegate (ss);
2028 if (! (res.i == -1))
2038 typedef SmallStruct2 (STDCALL *SmallStructDelegate2) (SmallStruct2 ss);
2040 LIBTEST_API int STDCALL
2041 mono_test_marshal_small_struct_delegate2 (SmallStructDelegate2 delegate)
2043 SmallStruct2 ss, res;
2048 res = delegate (ss);
2049 if (! ((res.i == -2) && (res.j == -3)))
2060 typedef SmallStruct3 (STDCALL *SmallStructDelegate3) (SmallStruct3 ss);
2062 LIBTEST_API int STDCALL
2063 mono_test_marshal_small_struct_delegate3 (SmallStructDelegate3 delegate)
2065 SmallStruct3 ss, res;
2070 res = delegate (ss);
2071 if (! ((res.i == -1) && (res.j == -2)))
2081 typedef SmallStruct4 (STDCALL *SmallStructDelegate4) (SmallStruct4 ss);
2083 LIBTEST_API int STDCALL
2084 mono_test_marshal_small_struct_delegate4 (SmallStructDelegate4 delegate)
2086 SmallStruct4 ss, res;
2090 res = delegate (ss);
2091 if (! (res.i == -1))
2101 typedef SmallStruct5 (STDCALL *SmallStructDelegate5) (SmallStruct5 ss);
2103 LIBTEST_API int STDCALL
2104 mono_test_marshal_small_struct_delegate5 (SmallStructDelegate5 delegate)
2106 SmallStruct5 ss, res;
2110 res = delegate (ss);
2111 if (! (res.i == -5))
2121 typedef SmallStruct6 (STDCALL *SmallStructDelegate6) (SmallStruct6 ss);
2123 LIBTEST_API int STDCALL
2124 mono_test_marshal_small_struct_delegate6 (SmallStructDelegate6 delegate)
2126 SmallStruct6 ss, res;
2131 res = delegate (ss);
2132 if (! ((res.i == -1) && (res.j == -2)))
2143 typedef SmallStruct7 (STDCALL *SmallStructDelegate7) (SmallStruct7 ss);
2145 LIBTEST_API int STDCALL
2146 mono_test_marshal_small_struct_delegate7 (SmallStructDelegate7 delegate)
2148 SmallStruct7 ss, res;
2153 res = delegate (ss);
2154 if (! ((res.i == -1) && (res.j == -2)))
2164 typedef SmallStruct8 (STDCALL *SmallStructDelegate8) (SmallStruct8 ss);
2166 LIBTEST_API int STDCALL
2167 mono_test_marshal_small_struct_delegate8 (SmallStructDelegate8 delegate)
2169 SmallStruct8 ss, res;
2173 res = delegate (ss);
2174 if (! ((res.i == -1.0)))
2184 typedef SmallStruct9 (STDCALL *SmallStructDelegate9) (SmallStruct9 ss);
2186 LIBTEST_API int STDCALL
2187 mono_test_marshal_small_struct_delegate9 (SmallStructDelegate9 delegate)
2189 SmallStruct9 ss, res;
2193 res = delegate (ss);
2194 if (! ((res.i == -1.0)))
2204 typedef SmallStruct10 (STDCALL *SmallStructDelegate10) (SmallStruct10 ss);
2206 LIBTEST_API int STDCALL
2207 mono_test_marshal_small_struct_delegate10 (SmallStructDelegate10 delegate)
2209 SmallStruct10 ss, res;
2214 res = delegate (ss);
2215 if (! ((res.i == -1.0) && (res.j == -2.0)))
2226 typedef SmallStruct11 (STDCALL *SmallStructDelegate11) (SmallStruct11 ss);
2228 LIBTEST_API int STDCALL
2229 mono_test_marshal_small_struct_delegate11 (SmallStructDelegate11 delegate)
2231 SmallStruct11 ss, res;
2236 res = delegate (ss);
2237 if (! ((res.i == -1.0) && (res.j == -2)))
2243 typedef int (STDCALL *ArrayDelegate) (int i, char *j, void *arr);
2245 LIBTEST_API int STDCALL
2246 mono_test_marshal_array_delegate (void *arr, int len, ArrayDelegate del)
2248 return del (len, NULL, arr);
2251 typedef int (STDCALL *ArrayDelegateLong) (gint64 i, char *j, void *arr);
2253 LIBTEST_API int STDCALL
2254 mono_test_marshal_array_delegate_long (void *arr, gint64 len, ArrayDelegateLong del)
2256 return del (len, NULL, arr);
2259 LIBTEST_API int STDCALL
2260 mono_test_marshal_out_array_delegate (int *arr, int len, ArrayDelegate del)
2262 del (len, NULL, arr);
2264 if ((arr [0] != 1) || (arr [1] != 2))
2270 typedef gunichar2* (STDCALL *UnicodeStringDelegate) (gunichar2 *message);
2272 LIBTEST_API int STDCALL
2273 mono_test_marshal_return_unicode_string_delegate (UnicodeStringDelegate del)
2275 const char m[] = "abcdef";
2276 gunichar2 *s2, *res;
2279 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
2288 LIBTEST_API int STDCALL
2289 mono_test_marshal_out_string_array_delegate (char **arr, int len, ArrayDelegate del)
2291 del (len, NULL, arr);
2293 if (!strcmp (arr [0], "ABC") && !strcmp (arr [1], "DEF"))
2299 typedef int (*CdeclDelegate) (int i, int j);
2301 LIBTEST_API int STDCALL
2302 mono_test_marshal_cdecl_delegate (CdeclDelegate del)
2306 for (i = 0; i < 1000; ++i)
2312 typedef char** (STDCALL *ReturnStringArrayDelegate) (int i);
2314 LIBTEST_API int STDCALL
2315 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d)
2323 if (strcmp (arr [0], "ABC") || strcmp (arr [1], "DEF"))
2333 typedef int (STDCALL *ByrefStringDelegate) (char **s);
2335 LIBTEST_API int STDCALL
2336 mono_test_marshal_byref_string_delegate (ByrefStringDelegate d)
2338 char *s = (char*)"ABC";
2345 if (!strcmp (s, "DEF"))
2355 LIBTEST_API int STDCALL
2356 add_delegate (int i, int j)
2361 LIBTEST_API gpointer STDCALL
2362 mono_test_marshal_return_fnptr (void)
2364 return &add_delegate;
2367 LIBTEST_API int STDCALL
2370 printf ("codigo %x\n", code);
2378 LIBTEST_API HandleRef STDCALL
2379 mono_xr_as_handle (int code)
2383 memset (&ref, 0, sizeof (ref));
2395 LIBTEST_API int STDCALL
2396 mono_safe_handle_struct_ref (HandleStructs *x)
2398 printf ("Dingus Ref! \n");
2399 printf ("Values: %d %d %p %p\n", x->a, x->b, x->handle1, x->handle2);
2405 if (x->handle1 != (void*) 0x7080feed)
2408 if (x->handle2 != (void*) 0x1234abcd)
2414 LIBTEST_API int STDCALL
2415 mono_safe_handle_struct (HandleStructs x)
2417 printf ("Dingus Standard! \n");
2418 printf ("Values: %d %d %p %p\n", x.a, x.b, x.handle1, x.handle2);
2424 if (x.handle1 != (void*) 0x7080feed)
2427 if (x.handle2 != (void*) 0x1234abcd)
2437 LIBTEST_API int STDCALL
2438 mono_safe_handle_struct_simple (TrivialHandle x)
2440 printf ("The value is %p\n", x.a);
2441 return ((int)(gsize)x.a) * 2;
2444 LIBTEST_API int STDCALL
2445 mono_safe_handle_return (void)
2450 LIBTEST_API void STDCALL
2451 mono_safe_handle_ref (void **handle)
2454 *handle = (void *) 0xbad;
2458 *handle = (void *) 0x800d;
2461 LIBTEST_API double STDCALL
2462 mono_test_marshal_date_time (double d, double *d2)
2534 VT_USERDEFINED = 29,
2542 VT_STREAMED_OBJECT = 68,
2543 VT_STORED_OBJECT = 69,
2544 VT_BLOB_OBJECT = 70,
2552 void VariantInit(VARIANT* vt)
2569 LIBTEST_API int STDCALL
2570 mono_test_marshal_bstr_in(gunichar2* bstr)
2573 gchar* bstr_utf8 = g_utf16_to_utf8 (bstr, -1, NULL, NULL, NULL);
2574 result = strcmp("mono_test_marshal_bstr_in", bstr_utf8);
2581 LIBTEST_API int STDCALL
2582 mono_test_marshal_bstr_out(gunichar2** bstr)
2584 *bstr = marshal_bstr_alloc ("mono_test_marshal_bstr_out");
2588 LIBTEST_API int STDCALL
2589 mono_test_marshal_bstr_in_null(gunichar2* bstr)
2596 LIBTEST_API int STDCALL
2597 mono_test_marshal_bstr_out_null(gunichar2** bstr)
2603 LIBTEST_API int STDCALL
2604 mono_test_marshal_variant_in_sbyte(VARIANT variant)
2606 if (variant.vt == VT_I1 && variant.cVal == 100)
2611 LIBTEST_API int STDCALL
2612 mono_test_marshal_variant_in_byte(VARIANT variant)
2614 if (variant.vt == VT_UI1 && variant.bVal == 100)
2619 LIBTEST_API int STDCALL
2620 mono_test_marshal_variant_in_short(VARIANT variant)
2622 if (variant.vt == VT_I2 && variant.iVal == 314)
2627 LIBTEST_API int STDCALL
2628 mono_test_marshal_variant_in_ushort(VARIANT variant)
2630 if (variant.vt == VT_UI2 && variant.uiVal == 314)
2635 LIBTEST_API int STDCALL
2636 mono_test_marshal_variant_in_int(VARIANT variant)
2638 if (variant.vt == VT_I4 && variant.lVal == 314)
2643 LIBTEST_API int STDCALL
2644 mono_test_marshal_variant_in_uint(VARIANT variant)
2646 if (variant.vt == VT_UI4 && variant.ulVal == 314)
2651 LIBTEST_API int STDCALL
2652 mono_test_marshal_variant_in_long(VARIANT variant)
2654 if (variant.vt == VT_I8 && variant.llVal == 314)
2659 LIBTEST_API int STDCALL
2660 mono_test_marshal_variant_in_ulong(VARIANT variant)
2662 if (variant.vt == VT_UI8 && variant.ullVal == 314)
2667 LIBTEST_API int STDCALL
2668 mono_test_marshal_variant_in_float(VARIANT variant)
2670 if (variant.vt == VT_R4 && (variant.fltVal - 3.14)/3.14 < .001)
2675 LIBTEST_API int STDCALL
2676 mono_test_marshal_variant_in_double(VARIANT variant)
2678 if (variant.vt == VT_R8 && (variant.dblVal - 3.14)/3.14 < .001)
2683 LIBTEST_API int STDCALL
2684 mono_test_marshal_variant_in_bstr(VARIANT variant)
2687 gchar* bstr_utf8 = g_utf16_to_utf8 (variant.bstrVal, -1, NULL, NULL, NULL);
2688 result = strcmp("PI", bstr_utf8);
2691 if (variant.vt == VT_BSTR && !result)
2696 LIBTEST_API int STDCALL
2697 mono_test_marshal_variant_in_bool_true (VARIANT variant)
2699 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_TRUE)
2704 LIBTEST_API int STDCALL
2705 mono_test_marshal_variant_in_bool_false (VARIANT variant)
2707 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_FALSE)
2712 LIBTEST_API int STDCALL
2713 mono_test_marshal_variant_out_sbyte(VARIANT* variant)
2715 variant->vt = VT_I1;
2716 variant->cVal = 100;
2721 LIBTEST_API int STDCALL
2722 mono_test_marshal_variant_out_sbyte_byref(VARIANT* variant)
2724 variant->vt = VT_I1|VT_BYREF;
2725 variant->byref = marshal_alloc(1);
2726 *((gint8*)variant->byref) = 100;
2731 LIBTEST_API int STDCALL
2732 mono_test_marshal_variant_out_byte(VARIANT* variant)
2734 variant->vt = VT_UI1;
2735 variant->bVal = 100;
2740 LIBTEST_API int STDCALL
2741 mono_test_marshal_variant_out_byte_byref(VARIANT* variant)
2743 variant->vt = VT_UI1|VT_BYREF;
2744 variant->byref = marshal_alloc(1);
2745 *((gint8*)variant->byref) = 100;
2750 LIBTEST_API int STDCALL
2751 mono_test_marshal_variant_out_short(VARIANT* variant)
2753 variant->vt = VT_I2;
2754 variant->iVal = 314;
2759 LIBTEST_API int STDCALL
2760 mono_test_marshal_variant_out_short_byref(VARIANT* variant)
2762 variant->vt = VT_I2|VT_BYREF;
2763 variant->byref = marshal_alloc(2);
2764 *((gint16*)variant->byref) = 314;
2769 LIBTEST_API int STDCALL
2770 mono_test_marshal_variant_out_ushort(VARIANT* variant)
2772 variant->vt = VT_UI2;
2773 variant->uiVal = 314;
2778 LIBTEST_API int STDCALL
2779 mono_test_marshal_variant_out_ushort_byref(VARIANT* variant)
2781 variant->vt = VT_UI2|VT_BYREF;
2782 variant->byref = marshal_alloc(2);
2783 *((guint16*)variant->byref) = 314;
2788 LIBTEST_API int STDCALL
2789 mono_test_marshal_variant_out_int(VARIANT* variant)
2791 variant->vt = VT_I4;
2792 variant->lVal = 314;
2797 LIBTEST_API int STDCALL
2798 mono_test_marshal_variant_out_int_byref(VARIANT* variant)
2800 variant->vt = VT_I4|VT_BYREF;
2801 variant->byref = marshal_alloc(4);
2802 *((gint32*)variant->byref) = 314;
2807 LIBTEST_API int STDCALL
2808 mono_test_marshal_variant_out_uint(VARIANT* variant)
2810 variant->vt = VT_UI4;
2811 variant->ulVal = 314;
2816 LIBTEST_API int STDCALL
2817 mono_test_marshal_variant_out_uint_byref(VARIANT* variant)
2819 variant->vt = VT_UI4|VT_BYREF;
2820 variant->byref = marshal_alloc(4);
2821 *((guint32*)variant->byref) = 314;
2826 LIBTEST_API int STDCALL
2827 mono_test_marshal_variant_out_long(VARIANT* variant)
2829 variant->vt = VT_I8;
2830 variant->llVal = 314;
2835 LIBTEST_API int STDCALL
2836 mono_test_marshal_variant_out_long_byref(VARIANT* variant)
2838 variant->vt = VT_I8|VT_BYREF;
2839 variant->byref = marshal_alloc(8);
2840 *((gint64*)variant->byref) = 314;
2845 LIBTEST_API int STDCALL
2846 mono_test_marshal_variant_out_ulong(VARIANT* variant)
2848 variant->vt = VT_UI8;
2849 variant->ullVal = 314;
2854 LIBTEST_API int STDCALL
2855 mono_test_marshal_variant_out_ulong_byref(VARIANT* variant)
2857 variant->vt = VT_UI8|VT_BYREF;
2858 variant->byref = marshal_alloc(8);
2859 *((guint64*)variant->byref) = 314;
2864 LIBTEST_API int STDCALL
2865 mono_test_marshal_variant_out_float(VARIANT* variant)
2867 variant->vt = VT_R4;
2868 variant->fltVal = 3.14;
2873 LIBTEST_API int STDCALL
2874 mono_test_marshal_variant_out_float_byref(VARIANT* variant)
2876 variant->vt = VT_R4|VT_BYREF;
2877 variant->byref = marshal_alloc(4);
2878 *((float*)variant->byref) = 3.14;
2883 LIBTEST_API int STDCALL
2884 mono_test_marshal_variant_out_double(VARIANT* variant)
2886 variant->vt = VT_R8;
2887 variant->dblVal = 3.14;
2892 LIBTEST_API int STDCALL
2893 mono_test_marshal_variant_out_double_byref(VARIANT* variant)
2895 variant->vt = VT_R8|VT_BYREF;
2896 variant->byref = marshal_alloc(8);
2897 *((double*)variant->byref) = 3.14;
2902 LIBTEST_API int STDCALL
2903 mono_test_marshal_variant_out_bstr(VARIANT* variant)
2905 variant->vt = VT_BSTR;
2906 variant->bstrVal = marshal_bstr_alloc("PI");
2911 LIBTEST_API int STDCALL
2912 mono_test_marshal_variant_out_bstr_byref(VARIANT* variant)
2914 variant->vt = VT_BSTR|VT_BYREF;
2915 variant->byref = marshal_alloc(sizeof(gpointer));
2916 *((gunichar**)variant->byref) = (gunichar*)marshal_bstr_alloc("PI");
2921 LIBTEST_API int STDCALL
2922 mono_test_marshal_variant_out_bool_true (VARIANT* variant)
2924 variant->vt = VT_BOOL;
2925 variant->boolVal = VARIANT_TRUE;
2930 LIBTEST_API int STDCALL
2931 mono_test_marshal_variant_out_bool_true_byref (VARIANT* variant)
2933 variant->vt = VT_BOOL|VT_BYREF;
2934 variant->byref = marshal_alloc(2);
2935 *((gint16*)variant->byref) = VARIANT_TRUE;
2940 LIBTEST_API int STDCALL
2941 mono_test_marshal_variant_out_bool_false (VARIANT* variant)
2943 variant->vt = VT_BOOL;
2944 variant->boolVal = VARIANT_FALSE;
2949 LIBTEST_API int STDCALL
2950 mono_test_marshal_variant_out_bool_false_byref (VARIANT* variant)
2952 variant->vt = VT_BOOL|VT_BYREF;
2953 variant->byref = marshal_alloc(2);
2954 *((gint16*)variant->byref) = VARIANT_FALSE;
2959 typedef int (STDCALL *VarFunc) (int vt, VARIANT variant);
2960 typedef int (STDCALL *VarRefFunc) (int vt, VARIANT* variant);
2962 LIBTEST_API int STDCALL
2963 mono_test_marshal_variant_in_sbyte_unmanaged(VarFunc func)
2968 return func (VT_I1, vt);
2971 LIBTEST_API int STDCALL
2972 mono_test_marshal_variant_in_byte_unmanaged(VarFunc func)
2977 return func (VT_UI1, vt);
2980 LIBTEST_API int STDCALL
2981 mono_test_marshal_variant_in_short_unmanaged(VarFunc func)
2986 return func (VT_I2, vt);
2989 LIBTEST_API int STDCALL
2990 mono_test_marshal_variant_in_ushort_unmanaged(VarFunc func)
2995 return func (VT_UI2, vt);
2998 LIBTEST_API int STDCALL
2999 mono_test_marshal_variant_in_int_unmanaged(VarFunc func)
3004 return func (VT_I4, vt);
3007 LIBTEST_API int STDCALL
3008 mono_test_marshal_variant_in_uint_unmanaged(VarFunc func)
3013 return func (VT_UI4, vt);
3016 LIBTEST_API int STDCALL
3017 mono_test_marshal_variant_in_long_unmanaged(VarFunc func)
3022 return func (VT_I8, vt);
3025 LIBTEST_API int STDCALL
3026 mono_test_marshal_variant_in_ulong_unmanaged(VarFunc func)
3031 return func (VT_UI8, vt);
3034 LIBTEST_API int STDCALL
3035 mono_test_marshal_variant_in_float_unmanaged(VarFunc func)
3040 return func (VT_R4, vt);
3043 LIBTEST_API int STDCALL
3044 mono_test_marshal_variant_in_double_unmanaged(VarFunc func)
3049 return func (VT_R8, vt);
3052 LIBTEST_API int STDCALL
3053 mono_test_marshal_variant_in_bstr_unmanaged(VarFunc func)
3057 vt.bstrVal = marshal_bstr_alloc("PI");
3058 return func (VT_BSTR, vt);
3061 LIBTEST_API int STDCALL
3062 mono_test_marshal_variant_in_bool_true_unmanaged(VarFunc func)
3066 vt.boolVal = VARIANT_TRUE;
3067 return func (VT_BOOL, vt);
3070 LIBTEST_API int STDCALL
3071 mono_test_marshal_variant_in_bool_false_unmanaged(VarFunc func)
3075 vt.boolVal = VARIANT_FALSE;
3076 return func (VT_BOOL, vt);
3079 LIBTEST_API int STDCALL
3080 mono_test_marshal_variant_out_sbyte_unmanaged(VarRefFunc func)
3085 if (vt.vt == VT_I1 && vt.cVal == -100)
3090 LIBTEST_API int STDCALL
3091 mono_test_marshal_variant_out_byte_unmanaged(VarRefFunc func)
3096 if (vt.vt == VT_UI1 && vt.bVal == 100)
3101 LIBTEST_API int STDCALL
3102 mono_test_marshal_variant_out_short_unmanaged(VarRefFunc func)
3107 if (vt.vt == VT_I2 && vt.iVal == -100)
3112 LIBTEST_API int STDCALL
3113 mono_test_marshal_variant_out_ushort_unmanaged(VarRefFunc func)
3118 if (vt.vt == VT_UI2 && vt.uiVal == 100)
3123 LIBTEST_API int STDCALL
3124 mono_test_marshal_variant_out_int_unmanaged(VarRefFunc func)
3129 if (vt.vt == VT_I4 && vt.lVal == -100)
3134 LIBTEST_API int STDCALL
3135 mono_test_marshal_variant_out_uint_unmanaged(VarRefFunc func)
3140 if (vt.vt == VT_UI4 && vt.ulVal == 100)
3145 LIBTEST_API int STDCALL
3146 mono_test_marshal_variant_out_long_unmanaged(VarRefFunc func)
3151 if (vt.vt == VT_I8 && vt.llVal == -100)
3156 LIBTEST_API int STDCALL
3157 mono_test_marshal_variant_out_ulong_unmanaged(VarRefFunc func)
3162 if (vt.vt == VT_UI8 && vt.ullVal == 100)
3167 LIBTEST_API int STDCALL
3168 mono_test_marshal_variant_out_float_unmanaged(VarRefFunc func)
3173 if (vt.vt == VT_R4 && fabs (vt.fltVal - 3.14f) < 1e-10)
3178 LIBTEST_API int STDCALL
3179 mono_test_marshal_variant_out_double_unmanaged(VarRefFunc func)
3184 if (vt.vt == VT_R8 && fabs (vt.dblVal - 3.14) < 1e-10)
3189 LIBTEST_API int STDCALL
3190 mono_test_marshal_variant_out_bstr_unmanaged(VarRefFunc func)
3198 func (VT_BSTR, &vt);
3199 bstr_utf8 = g_utf16_to_utf8 (vt.bstrVal, -1, NULL, NULL, NULL);
3200 result = strcmp("PI", bstr_utf8);
3202 if (vt.vt == VT_BSTR && !result)
3207 LIBTEST_API int STDCALL
3208 mono_test_marshal_variant_out_bool_true_unmanaged(VarRefFunc func)
3212 func (VT_BOOL, &vt);
3213 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3218 LIBTEST_API int STDCALL
3219 mono_test_marshal_variant_out_bool_false_unmanaged(VarRefFunc func)
3223 func (VT_BOOL, &vt);
3224 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3229 typedef struct MonoComObject MonoComObject;
3233 int (STDCALL *QueryInterface)(MonoComObject* pUnk, gpointer riid, gpointer* ppv);
3234 int (STDCALL *AddRef)(MonoComObject* pUnk);
3235 int (STDCALL *Release)(MonoComObject* pUnk);
3236 int (STDCALL *get_ITest)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3237 int (STDCALL *SByteIn)(MonoComObject* pUnk, char a);
3238 int (STDCALL *ByteIn)(MonoComObject* pUnk, unsigned char a);
3239 int (STDCALL *ShortIn)(MonoComObject* pUnk, short a);
3240 int (STDCALL *UShortIn)(MonoComObject* pUnk, unsigned short a);
3241 int (STDCALL *IntIn)(MonoComObject* pUnk, int a);
3242 int (STDCALL *UIntIn)(MonoComObject* pUnk, unsigned int a);
3243 int (STDCALL *LongIn)(MonoComObject* pUnk, gint64 a);
3244 int (STDCALL *ULongIn)(MonoComObject* pUnk, guint64 a);
3245 int (STDCALL *FloatIn)(MonoComObject* pUnk, float a);
3246 int (STDCALL *DoubleIn)(MonoComObject* pUnk, double a);
3247 int (STDCALL *ITestIn)(MonoComObject* pUnk, MonoComObject* pUnk2);
3248 int (STDCALL *ITestOut)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3251 struct MonoComObject
3257 static GUID IID_ITest = {0, 0, 0, {0,0,0,0,0,0,0,1}};
3258 static GUID IID_IMonoUnknown = {0, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3259 static GUID IID_IMonoDispatch = {0x00020400, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3261 LIBTEST_API int STDCALL
3262 MonoQueryInterface(MonoComObject* pUnk, gpointer riid, gpointer* ppv)
3266 if (!memcmp(riid, &IID_IMonoUnknown, sizeof(GUID))) {
3270 else if (!memcmp(riid, &IID_ITest, sizeof(GUID))) {
3274 else if (!memcmp(riid, &IID_IMonoDispatch, sizeof(GUID))) {
3278 return 0x80004002; //E_NOINTERFACE;
3281 LIBTEST_API int STDCALL
3282 MonoAddRef(MonoComObject* pUnk)
3284 return ++(pUnk->m_ref);
3287 LIBTEST_API int STDCALL
3288 MonoRelease(MonoComObject* pUnk)
3290 return --(pUnk->m_ref);
3293 LIBTEST_API int STDCALL
3294 SByteIn(MonoComObject* pUnk, char a)
3299 LIBTEST_API int STDCALL
3300 ByteIn(MonoComObject* pUnk, unsigned char a)
3305 LIBTEST_API int STDCALL
3306 ShortIn(MonoComObject* pUnk, short a)
3311 LIBTEST_API int STDCALL
3312 UShortIn(MonoComObject* pUnk, unsigned short a)
3317 LIBTEST_API int STDCALL
3318 IntIn(MonoComObject* pUnk, int a)
3323 LIBTEST_API int STDCALL
3324 UIntIn(MonoComObject* pUnk, unsigned int a)
3329 LIBTEST_API int STDCALL
3330 LongIn(MonoComObject* pUnk, gint64 a)
3335 LIBTEST_API int STDCALL
3336 ULongIn(MonoComObject* pUnk, guint64 a)
3341 LIBTEST_API int STDCALL
3342 FloatIn(MonoComObject* pUnk, float a)
3347 LIBTEST_API int STDCALL
3348 DoubleIn(MonoComObject* pUnk, double a)
3353 LIBTEST_API int STDCALL
3354 ITestIn(MonoComObject* pUnk, MonoComObject *pUnk2)
3359 LIBTEST_API int STDCALL
3360 ITestOut(MonoComObject* pUnk, MonoComObject* *ppUnk)
3365 static void create_com_object (MonoComObject** pOut);
3367 LIBTEST_API int STDCALL
3368 get_ITest(MonoComObject* pUnk, MonoComObject* *ppUnk)
3370 create_com_object (ppUnk);
3374 static void create_com_object (MonoComObject** pOut)
3376 *pOut = marshal_new0 (MonoComObject, 1);
3377 (*pOut)->vtbl = marshal_new0 (MonoIUnknown, 1);
3380 (*pOut)->vtbl->QueryInterface = MonoQueryInterface;
3381 (*pOut)->vtbl->AddRef = MonoAddRef;
3382 (*pOut)->vtbl->Release = MonoRelease;
3383 (*pOut)->vtbl->SByteIn = SByteIn;
3384 (*pOut)->vtbl->ByteIn = ByteIn;
3385 (*pOut)->vtbl->ShortIn = ShortIn;
3386 (*pOut)->vtbl->UShortIn = UShortIn;
3387 (*pOut)->vtbl->IntIn = IntIn;
3388 (*pOut)->vtbl->UIntIn = UIntIn;
3389 (*pOut)->vtbl->LongIn = LongIn;
3390 (*pOut)->vtbl->ULongIn = ULongIn;
3391 (*pOut)->vtbl->FloatIn = FloatIn;
3392 (*pOut)->vtbl->DoubleIn = DoubleIn;
3393 (*pOut)->vtbl->ITestIn = ITestIn;
3394 (*pOut)->vtbl->ITestOut = ITestOut;
3395 (*pOut)->vtbl->get_ITest = get_ITest;
3398 static MonoComObject* same_object = NULL;
3400 LIBTEST_API int STDCALL
3401 mono_test_marshal_com_object_create(MonoComObject* *pUnk)
3403 create_com_object (pUnk);
3406 same_object = *pUnk;
3411 LIBTEST_API int STDCALL
3412 mono_test_marshal_com_object_same(MonoComObject* *pUnk)
3414 *pUnk = same_object;
3419 LIBTEST_API int STDCALL
3420 mono_test_marshal_com_object_destroy(MonoComObject *pUnk)
3422 int ref = --(pUnk->m_ref);
3429 LIBTEST_API int STDCALL
3430 mono_test_marshal_com_object_ref_count(MonoComObject *pUnk)
3435 LIBTEST_API int STDCALL
3436 mono_test_marshal_ccw_itest (MonoComObject *pUnk)
3439 MonoComObject* pTest;
3444 hr = pUnk->vtbl->SByteIn (pUnk, -100);
3447 hr = pUnk->vtbl->ByteIn (pUnk, 100);
3450 hr = pUnk->vtbl->ShortIn (pUnk, -100);
3453 hr = pUnk->vtbl->UShortIn (pUnk, 100);
3456 hr = pUnk->vtbl->IntIn (pUnk, -100);
3459 hr = pUnk->vtbl->UIntIn (pUnk, 100);
3462 hr = pUnk->vtbl->LongIn (pUnk, -100);
3465 hr = pUnk->vtbl->ULongIn (pUnk, 100);
3468 hr = pUnk->vtbl->FloatIn (pUnk, 3.14f);
3471 hr = pUnk->vtbl->DoubleIn (pUnk, 3.14);
3474 hr = pUnk->vtbl->ITestIn (pUnk, pUnk);
3477 hr = pUnk->vtbl->ITestOut (pUnk, &pTest);
3485 * mono_method_get_unmanaged_thunk tests
3488 #if defined(__GNUC__) && ((defined(__i386__) && (defined(__linux__) || defined (__APPLE__)) || defined (__FreeBSD__) || defined(__OpenBSD__)) || (defined(__ppc__) && defined(__APPLE__)))
3489 #define ALIGN(size) __attribute__ ((aligned(size)))
3495 /* thunks.cs:TestStruct */
3496 typedef struct _TestStruct {
3501 /* Searches for mono symbols in all loaded modules */
3503 lookup_mono_symbol (const char *symbol_name)
3506 if (g_module_symbol (g_module_open (NULL, G_MODULE_BIND_LAZY), symbol_name, &symbol))
3512 LIBTEST_API gpointer STDCALL
3513 mono_test_marshal_lookup_symbol (const char *symbol_name)
3515 return lookup_mono_symbol (symbol_name);
3519 * test_method_thunk:
3521 * @test_id: the test number
3522 * @test_method_handle: MonoMethod* of the C# test method
3523 * @create_object_method_handle: MonoMethod* of thunks.cs:Test.CreateObject
3525 LIBTEST_API int STDCALL
3526 test_method_thunk (int test_id, gpointer test_method_handle, gpointer create_object_method_handle)
3528 gpointer (*mono_method_get_unmanaged_thunk)(gpointer)
3529 = lookup_mono_symbol ("mono_method_get_unmanaged_thunk");
3531 gpointer (*mono_string_new_wrapper)(const char *)
3532 = lookup_mono_symbol ("mono_string_new_wrapper");
3534 char* (*mono_string_to_utf8)(gpointer)
3535 = lookup_mono_symbol ("mono_string_to_utf8");
3537 gpointer (*mono_object_unbox)(gpointer)
3538 = lookup_mono_symbol ("mono_object_unbox");
3540 gpointer test_method, ex = NULL;
3541 gpointer (STDCALL *CreateObject)(gpointer*);
3544 if (!mono_method_get_unmanaged_thunk)
3547 test_method = mono_method_get_unmanaged_thunk (test_method_handle);
3551 CreateObject = mono_method_get_unmanaged_thunk (create_object_method_handle);
3559 /* thunks.cs:Test.Test0 */
3560 void (STDCALL *F)(gpointer*) = test_method;
3566 /* thunks.cs:Test.Test1 */
3567 int (STDCALL *F)(gpointer*) = test_method;
3574 /* thunks.cs:Test.Test2 */
3575 gpointer (STDCALL *F)(gpointer, gpointer*) = test_method;
3576 gpointer str = mono_string_new_wrapper ("foo");
3577 if (str != F (str, &ex))
3583 /* thunks.cs:Test.Test3 */
3584 gpointer (STDCALL *F)(gpointer, gpointer, gpointer*);
3589 obj = CreateObject (&ex);
3590 str = mono_string_new_wrapper ("bar");
3592 if (str != F (obj, str, &ex))
3598 /* thunks.cs:Test.Test4 */
3599 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3604 obj = CreateObject (&ex);
3605 str = mono_string_new_wrapper ("bar");
3607 if (42 != F (obj, str, 42, &ex))
3614 /* thunks.cs:Test.Test5 */
3615 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3620 obj = CreateObject (&ex);
3621 str = mono_string_new_wrapper ("bar");
3623 F (obj, str, 42, &ex);
3631 /* thunks.cs:Test.Test6 */
3632 int (STDCALL *F)(gpointer, guint8, gint16, gint32, gint64, float, double,
3633 gpointer, gpointer*);
3635 gpointer str = mono_string_new_wrapper ("Test6");
3639 obj = CreateObject (&ex);
3641 res = F (obj, 254, 32700, -245378, 6789600, 3.1415, 3.1415, str, &ex);
3652 /* thunks.cs:Test.Test7 */
3653 gint64 (STDCALL *F)(gpointer*) = test_method;
3654 if (F (&ex) != G_MAXINT64)
3660 /* thunks.cs:Test.Test8 */
3661 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3662 gpointer*, gpointer*);
3674 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3682 (fabs (a5 - 3.1415) < 0.001) &&
3683 (fabs (a6 - 3.1415) < 0.001) &&
3684 strcmp (mono_string_to_utf8 (a7), "Test8") == 0))
3691 /* thunks.cs:Test.Test9 */
3692 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3693 gpointer*, gpointer*);
3705 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3713 /* thunks.cs:Test.Test10 */
3714 void (STDCALL *F)(gpointer*, gpointer*);
3716 gpointer obj1, obj2;
3718 obj1 = obj2 = CreateObject (&ex);
3735 /* thunks.cs:TestStruct.Test0 */
3736 int (STDCALL *F)(gpointer*, gpointer*);
3742 obj = CreateObject (&ex);
3749 a1 = mono_object_unbox (obj);
3765 /* check whether the call was really by value */
3766 if (a1->A != 42 || a1->B != 3.1415)
3773 /* thunks.cs:TestStruct.Test1 */
3774 void (STDCALL *F)(gpointer, gpointer*);
3779 obj = CreateObject (&ex);
3786 a1 = mono_object_unbox (obj);
3799 if (!fabs (a1->B - 3.1415) < 0.001)
3806 /* thunks.cs:TestStruct.Test2 */
3807 gpointer (STDCALL *F)(gpointer*);
3821 a1 = mono_object_unbox (obj);
3826 if (!fabs (a1->B - 3.1415) < 0.001)
3833 /* thunks.cs:TestStruct.Test3 */
3834 void (STDCALL *F)(gpointer, gpointer*);
3839 obj = CreateObject (&ex);
3846 a1 = mono_object_unbox (obj);
3882 LIBTEST_API int STDCALL
3883 mono_test_Winx64_struct1_in (winx64_struct1 var)
3896 LIBTEST_API int STDCALL
3897 mono_test_Winx64_struct2_in (winx64_struct2 var)
3914 LIBTEST_API int STDCALL
3915 mono_test_Winx64_struct3_in (winx64_struct3 var)
3921 if (var.c != 0x1234)
3934 LIBTEST_API int STDCALL
3935 mono_test_Winx64_struct4_in (winx64_struct4 var)
3941 if (var.c != 0x1234)
3943 if (var.d != 0x87654321)
3955 LIBTEST_API int STDCALL
3956 mono_test_Winx64_struct5_in (winx64_struct5 var)
3974 LIBTEST_API int STDCALL
3975 mono_test_Winx64_struct6_in (winx64_struct6 var)
3986 LIBTEST_API int STDCALL
3987 mono_test_Winx64_structs_in1 (winx64_struct1 var1,
3988 winx64_struct2 var2,
3989 winx64_struct3 var3,
3990 winx64_struct4 var4)
4004 if (var3.c != 0x1234)
4011 if (var4.c != 0x1234)
4013 if (var4.d != 0x87654321)
4018 LIBTEST_API int STDCALL
4019 mono_test_Winx64_structs_in2 (winx64_struct1 var1,
4020 winx64_struct1 var2,
4021 winx64_struct1 var3,
4022 winx64_struct1 var4,
4023 winx64_struct1 var5)
4039 LIBTEST_API int STDCALL
4040 mono_test_Winx64_structs_in3 (winx64_struct1 var1,
4041 winx64_struct5 var2,
4042 winx64_struct1 var3,
4043 winx64_struct5 var4,
4044 winx64_struct1 var5,
4045 winx64_struct5 var6)
4080 LIBTEST_API winx64_struct1 STDCALL
4081 mono_test_Winx64_struct1_ret (void)
4088 LIBTEST_API winx64_struct2 STDCALL
4089 mono_test_Winx64_struct2_ret (void)
4097 LIBTEST_API winx64_struct3 STDCALL
4098 mono_test_Winx64_struct3_ret (void)
4107 LIBTEST_API winx64_struct4 STDCALL
4108 mono_test_Winx64_struct4_ret (void)
4118 LIBTEST_API winx64_struct5 STDCALL
4119 mono_test_Winx64_struct5_ret (void)
4128 LIBTEST_API winx64_struct1 STDCALL
4129 mono_test_Winx64_struct1_ret_5_args (char a, char b, char c, char d, char e)
4132 ret.a = a + b + c + d + e;
4136 LIBTEST_API winx64_struct5 STDCALL
4137 mono_test_Winx64_struct5_ret6_args (char a, char b, char c, char d, char e)
4150 } winx64_floatStruct;
4152 LIBTEST_API int STDCALL
4153 mono_test_Winx64_floatStruct (winx64_floatStruct a)
4155 if (a.a > 5.6 || a.a < 5.4)
4158 if (a.b > 9.6 || a.b < 9.4)
4167 } winx64_doubleStruct;
4169 LIBTEST_API int STDCALL
4170 mono_test_Winx64_doubleStruct (winx64_doubleStruct a)
4172 if (a.a > 5.6 || a.a < 5.4)
4178 typedef int (STDCALL *managed_struct1_delegate) (winx64_struct1 a);
4180 LIBTEST_API int STDCALL
4181 mono_test_managed_Winx64_struct1_in(managed_struct1_delegate func)
4188 typedef int (STDCALL *managed_struct5_delegate) (winx64_struct5 a);
4190 LIBTEST_API int STDCALL
4191 mono_test_managed_Winx64_struct5_in(managed_struct5_delegate func)
4200 typedef int (STDCALL *managed_struct1_struct5_delegate) (winx64_struct1 a, winx64_struct5 b,
4201 winx64_struct1 c, winx64_struct5 d,
4202 winx64_struct1 e, winx64_struct5 f);
4204 LIBTEST_API int STDCALL
4205 mono_test_managed_Winx64_struct1_struct5_in(managed_struct1_struct5_delegate func)
4207 winx64_struct1 a, c, e;
4208 winx64_struct5 b, d, f;
4210 b.a = 2; b.b = 3; b.c = 4;
4212 d.a = 6; d.b = 7; d.c = 8;
4214 f.a = 10; f.b = 11; f.c = 12;
4216 return func (a, b, c, d, e, f);
4219 typedef winx64_struct1 (STDCALL *managed_struct1_ret_delegate) (void);
4221 LIBTEST_API int STDCALL
4222 mono_test_Winx64_struct1_ret_managed (managed_struct1_ret_delegate func)
4234 typedef winx64_struct5 (STDCALL *managed_struct5_ret_delegate) (void);
4236 LIBTEST_API int STDCALL
4237 mono_test_Winx64_struct5_ret_managed (managed_struct5_ret_delegate func)
4253 LIBTEST_API int STDCALL
4254 mono_test_marshal_bool_in (int arg, unsigned int expected, unsigned int bDefaultMarsh, unsigned int bBoolCustMarsh,
4255 char bI1CustMarsh, unsigned char bU1CustMarsh, short bVBCustMarsh)
4259 if (bDefaultMarsh != expected)
4263 if (bBoolCustMarsh != expected)
4267 if (bI1CustMarsh != expected)
4271 if (bU1CustMarsh != expected)
4275 if (bVBCustMarsh != expected)
4284 LIBTEST_API int STDCALL
4285 mono_test_marshal_bool_out (int arg, unsigned int testVal, unsigned int* bDefaultMarsh, unsigned int* bBoolCustMarsh,
4286 char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh)
4292 *bDefaultMarsh = testVal;
4295 if (!bBoolCustMarsh)
4297 *bBoolCustMarsh = testVal;
4302 *bI1CustMarsh = (char)testVal;
4307 *bU1CustMarsh = (unsigned char)testVal;
4312 *bVBCustMarsh = (unsigned short)testVal;
4320 LIBTEST_API int STDCALL
4321 mono_test_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4322 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh,
4323 unsigned short* bVBCustMarsh)
4329 if (*bDefaultMarsh != expected)
4331 *bDefaultMarsh = testVal;
4334 if (!bBoolCustMarsh)
4336 if (*bBoolCustMarsh != expected)
4338 *bBoolCustMarsh = testVal;
4343 if (*bI1CustMarsh != expected)
4345 *bI1CustMarsh = (char)testVal;
4350 if (*bU1CustMarsh != expected)
4352 *bU1CustMarsh = (unsigned char)testVal;
4357 if (*bVBCustMarsh != expected)
4359 *bVBCustMarsh = (unsigned short)testVal;
4368 typedef int (STDCALL *MarshalBoolInDelegate) (int arg, unsigned int expected, unsigned int bDefaultMarsh,
4369 unsigned int bBoolCustMarsh, char bI1CustMarsh, unsigned char bU1CustMarsh, unsigned short bVBCustMarsh);
4371 LIBTEST_API int STDCALL
4372 mono_test_managed_marshal_bool_in (int arg, unsigned int expected, unsigned int testVal, MarshalBoolInDelegate pfcn)
4379 return pfcn (arg, expected, testVal, 0, 0, 0, 0);
4381 return pfcn (arg, expected, 0, testVal, 0, 0, 0);
4383 return pfcn (arg, expected, 0, 0, testVal, 0, 0);
4385 return pfcn (arg, expected, 0, 0, 0, testVal, 0);
4387 return pfcn (arg, expected, 0, 0, 0, 0, testVal);
4395 typedef int (STDCALL *MarshalBoolOutDelegate) (int arg, unsigned int expected, unsigned int* bDefaultMarsh,
4396 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4398 LIBTEST_API int STDCALL
4399 mono_test_managed_marshal_bool_out (int arg, unsigned int expected, unsigned int testVal, MarshalBoolOutDelegate pfcn)
4402 unsigned int lDefaultMarsh, lBoolCustMarsh;
4403 char lI1CustMarsh = 0;
4404 unsigned char lU1CustMarsh = 0;
4405 unsigned short lVBCustMarsh = 0;
4406 lDefaultMarsh = lBoolCustMarsh = 0;
4413 unsigned int ltVal = 0;
4414 ret = pfcn (arg, testVal, <Val, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4416 return 0x0100 + ret;
4417 if (expected != ltVal)
4422 unsigned int ltVal = 0;
4423 ret = pfcn (arg, testVal, &lDefaultMarsh, <Val, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4425 return 0x0300 + ret;
4426 if (expected != ltVal)
4432 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, <Val, &lU1CustMarsh, &lVBCustMarsh);
4434 return 0x0500 + ret;
4435 if (expected != ltVal)
4440 unsigned char ltVal = 0;
4441 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <Val, &lVBCustMarsh);
4443 return 0x0700 + ret;
4444 if (expected != ltVal)
4449 unsigned short ltVal = 0;
4450 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <Val);
4452 return 0x0900 + ret;
4453 if (expected != ltVal)
4464 typedef int (STDCALL *MarshalBoolRefDelegate) (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4465 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4467 LIBTEST_API int STDCALL
4468 mono_test_managed_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int outExpected,
4469 unsigned int outTestVal, MarshalBoolRefDelegate pfcn)
4472 unsigned int lDefaultMarsh, lBoolCustMarsh;
4473 char lI1CustMarsh = 0;
4474 unsigned char lU1CustMarsh = 0;
4475 unsigned short lVBCustMarsh = 0;
4476 lDefaultMarsh = lBoolCustMarsh = 0;
4484 unsigned int ltestVal = testVal;
4485 ret = pfcn (arg, expected, outTestVal, <estVal, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4487 return 0x0100 + ret;
4488 if (outExpected != ltestVal)
4494 unsigned int ltestVal = testVal;
4495 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, <estVal, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4497 return 0x0300 + ret;
4498 if (outExpected != ltestVal)
4504 char ltestVal = testVal;
4505 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, <estVal, &lU1CustMarsh, &lVBCustMarsh);
4507 return 0x0500 + ret;
4508 if (outExpected != ltestVal)
4514 unsigned char ltestVal = testVal;
4515 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <estVal, &lVBCustMarsh);
4517 return 0x0700 + ret;
4518 if (outExpected != ltestVal)
4524 unsigned short ltestVal = testVal;
4525 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <estVal);
4527 return 0x0900 + ret;
4528 if (outExpected != ltestVal)
4541 LIBTEST_API int STDCALL
4542 mono_test_marshal_safearray_out_1dim_vt_bstr_empty (SAFEARRAY** safearray)
4544 /* Create an empty one-dimensional array of variants */
4546 SAFEARRAYBOUND dimensions [1];
4548 dimensions [0].lLbound = 0;
4549 dimensions [0].cElements = 0;
4551 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4556 LIBTEST_API int STDCALL
4557 mono_test_marshal_safearray_out_1dim_vt_bstr (SAFEARRAY** safearray)
4559 /* Create a one-dimensional array of 10 variants filled with "0" to "9" */
4561 SAFEARRAYBOUND dimensions [1];
4567 dimensions [0].lLbound = 0;
4568 dimensions [0].cElements = 10;
4570 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4571 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4573 VariantInit (&vOut);
4575 _ltoa (i,buffer,10);
4576 vOut.bstrVal= marshal_bstr_alloc (buffer);
4578 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4579 VariantClear (&vOut);
4580 SafeArrayDestroy (pSA);
4583 VariantClear (&vOut);
4589 LIBTEST_API int STDCALL
4590 mono_test_marshal_safearray_out_2dim_vt_i4 (SAFEARRAY** safearray)
4592 /* Create a two-dimensional array of 4x3 variants filled with 11, 12, 13, etc. */
4594 SAFEARRAYBOUND dimensions [2];
4599 dimensions [0].lLbound = 0;
4600 dimensions [0].cElements = 4;
4601 dimensions [1].lLbound = 0;
4602 dimensions [1].cElements = 3;
4604 pSA= SafeArrayCreate(VT_VARIANT, 2, dimensions);
4605 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4606 for (j= dimensions [1].lLbound; j< (dimensions [1].cElements + dimensions [1].lLbound); j++) {
4608 VariantInit (&vOut);
4610 vOut.lVal = (i+1)*10+(j+1);
4613 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4614 VariantClear (&vOut);
4615 SafeArrayDestroy (pSA);
4618 VariantClear (&vOut); // does a deep destroy of source VARIANT
4625 LIBTEST_API int STDCALL
4626 mono_test_marshal_safearray_out_4dim_vt_i4 (SAFEARRAY** safearray)
4628 /* Create a four-dimensional array of 10x3x6x7 variants filled with their indices */
4629 /* Also use non zero lower bounds */
4631 SAFEARRAYBOUND dimensions [4];
4636 dimensions [0].lLbound = 15;
4637 dimensions [0].cElements = 10;
4638 dimensions [1].lLbound = 20;
4639 dimensions [1].cElements = 3;
4640 dimensions [2].lLbound = 5;
4641 dimensions [2].cElements = 6;
4642 dimensions [3].lLbound = 12;
4643 dimensions [3].cElements = 7;
4645 pSA= SafeArrayCreate (VT_VARIANT, 4, dimensions);
4647 SafeArrayAccessData (pSA, (void **)&pData);
4649 for (i= 0; i< 10*3*6*7; i++) {
4650 VariantInit(&pData [i]);
4651 pData [i].vt = VT_I4;
4654 SafeArrayUnaccessData (pSA);
4659 LIBTEST_API int STDCALL
4660 mono_test_marshal_safearray_in_byval_1dim_empty (SAFEARRAY* safearray)
4662 /* Check that array is one dimensional and empty */
4665 long lbound, ubound;
4667 dim = SafeArrayGetDim (safearray);
4671 SafeArrayGetLBound (safearray, 1, &lbound);
4672 SafeArrayGetUBound (safearray, 1, &ubound);
4674 if ((lbound > 0) || (ubound > 0))
4680 LIBTEST_API int STDCALL
4681 mono_test_marshal_safearray_in_byval_1dim_vt_i4 (SAFEARRAY* safearray)
4683 /* Check that array is one dimensional containing integers from 1 to 10 */
4686 long lbound, ubound;
4691 dim = SafeArrayGetDim (safearray);
4695 SafeArrayGetLBound (safearray, 1, &lbound);
4696 SafeArrayGetUBound (safearray, 1, &ubound);
4698 if ((lbound != 0) || (ubound != 9))
4701 SafeArrayAccessData (safearray, (void **)&pData);
4702 for (i= lbound; i <= ubound; i++) {
4703 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i + 1))
4706 SafeArrayUnaccessData (safearray);
4711 LIBTEST_API int STDCALL
4712 mono_test_marshal_safearray_in_byval_1dim_vt_mixed (SAFEARRAY* safearray)
4714 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4717 long lbound, ubound;
4724 VariantInit (&element);
4726 dim = SafeArrayGetDim (safearray);
4730 SafeArrayGetLBound (safearray, 1, &lbound);
4731 SafeArrayGetUBound (safearray, 1, &ubound);
4733 if ((lbound != 0) || (ubound != 12))
4736 SafeArrayAccessData (safearray, (void **)&pData);
4737 for (i= lbound; i <= ubound; i++) {
4738 if ((i%2 == 0) && (pData [i].vt != VT_I4))
4740 if ((i%2 == 1) && (pData [i].vt != VT_BSTR))
4742 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i))
4745 SafeArrayUnaccessData (safearray);
4747 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4752 SafeArrayPutElement (safearray, indices, &element);
4753 VariantClear (&element);
4758 LIBTEST_API int STDCALL
4759 mono_test_marshal_safearray_in_byval_2dim_vt_i4 (SAFEARRAY* safearray)
4761 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4764 long lbound1, ubound1, lbound2, ubound2;
4769 VariantInit (&element);
4771 dim = SafeArrayGetDim (safearray);
4775 SafeArrayGetLBound (safearray, 1, &lbound1);
4776 SafeArrayGetUBound (safearray, 1, &ubound1);
4778 if ((lbound1 != 0) || (ubound1 != 1))
4781 SafeArrayGetLBound (safearray, 2, &lbound2);
4782 SafeArrayGetUBound (safearray, 2, &ubound2);
4784 if ((lbound2 != 0) || (ubound2 != 3)) {
4788 for (i= lbound1; i <= ubound1; i++) {
4790 for (j= lbound2; j <= ubound2; j++) {
4792 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4794 failed = ((element.vt != VT_I4) || (element.lVal != 10*(i+1)+(j+1)));
4795 VariantClear (&element);
4801 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4807 SafeArrayPutElement (safearray, indices, &element);
4808 VariantClear (&element);
4813 LIBTEST_API int STDCALL
4814 mono_test_marshal_safearray_in_byval_3dim_vt_bstr (SAFEARRAY* safearray)
4816 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4819 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4820 long i, j, k, failed;
4824 VariantInit (&element);
4826 dim = SafeArrayGetDim (safearray);
4830 SafeArrayGetLBound (safearray, 1, &lbound1);
4831 SafeArrayGetUBound (safearray, 1, &ubound1);
4833 if ((lbound1 != 0) || (ubound1 != 1))
4836 SafeArrayGetLBound (safearray, 2, &lbound2);
4837 SafeArrayGetUBound (safearray, 2, &ubound2);
4839 if ((lbound2 != 0) || (ubound2 != 1))
4842 SafeArrayGetLBound (safearray, 3, &lbound3);
4843 SafeArrayGetUBound (safearray, 3, &ubound3);
4845 if ((lbound3 != 0) || (ubound3 != 2))
4848 for (i= lbound1; i <= ubound1; i++) {
4850 for (j= lbound2; j <= ubound2; j++) {
4852 for (k= lbound3; k <= ubound3; k++) {
4854 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4856 failed = ((element.vt != VT_BSTR)
4857 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4858 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4859 VariantClear (&element);
4866 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4871 element.vt = VT_BSTR;
4872 element.bstrVal = SysAllocString(L"Should not be copied");
4873 SafeArrayPutElement (safearray, indices, &element);
4874 VariantClear (&element);
4879 LIBTEST_API int STDCALL
4880 mono_test_marshal_safearray_in_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4882 return mono_test_marshal_safearray_in_byval_3dim_vt_bstr (*safearray);
4885 LIBTEST_API int STDCALL
4886 mono_test_marshal_safearray_in_out_byref_1dim_empty (SAFEARRAY** safearray)
4888 /* Check that the input array is what is expected and change it so the caller can check */
4889 /* correct marshalling back to managed code */
4892 long lbound, ubound;
4893 SAFEARRAYBOUND dimensions [1];
4895 wchar_t buffer [20];
4899 /* Check that in array is one dimensional and empty */
4901 dim = SafeArrayGetDim (*safearray);
4906 SafeArrayGetLBound (*safearray, 1, &lbound);
4907 SafeArrayGetUBound (*safearray, 1, &ubound);
4909 if ((lbound > 0) || (ubound > 0)) {
4913 /* Re-dimension the array and return a one-dimensional array of 8 variants filled with "0" to "7" */
4915 dimensions [0].lLbound = 0;
4916 dimensions [0].cElements = 8;
4918 hr = SafeArrayRedim (*safearray, dimensions);
4922 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
4924 VariantInit (&vOut);
4926 _ltow (i,buffer,10);
4927 vOut.bstrVal = SysAllocString (buffer);
4929 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
4930 VariantClear (&vOut);
4931 SafeArrayDestroy (*safearray);
4934 VariantClear (&vOut);
4939 LIBTEST_API int STDCALL
4940 mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4942 /* Check that the input array is what is expected and change it so the caller can check */
4943 /* correct marshalling back to managed code */
4946 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4947 SAFEARRAYBOUND dimensions [1];
4948 long i, j, k, failed;
4949 wchar_t buffer [20];
4954 VariantInit (&element);
4956 /* Check that in array is three dimensional and contains the expected values */
4958 dim = SafeArrayGetDim (*safearray);
4962 SafeArrayGetLBound (*safearray, 1, &lbound1);
4963 SafeArrayGetUBound (*safearray, 1, &ubound1);
4965 if ((lbound1 != 0) || (ubound1 != 1))
4968 SafeArrayGetLBound (*safearray, 2, &lbound2);
4969 SafeArrayGetUBound (*safearray, 2, &ubound2);
4971 if ((lbound2 != 0) || (ubound2 != 1))
4974 SafeArrayGetLBound (*safearray, 3, &lbound3);
4975 SafeArrayGetUBound (*safearray, 3, &ubound3);
4977 if ((lbound3 != 0) || (ubound3 != 2))
4980 for (i= lbound1; i <= ubound1; i++) {
4982 for (j= lbound2; j <= ubound2; j++) {
4984 for (k= lbound3; k <= ubound3; k++) {
4986 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
4988 failed = ((element.vt != VT_BSTR)
4989 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4990 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4991 VariantClear (&element);
4998 hr = SafeArrayDestroy (*safearray);
5002 /* Return a new one-dimensional array of 8 variants filled with "0" to "7" */
5004 dimensions [0].lLbound = 0;
5005 dimensions [0].cElements = 8;
5007 *safearray = SafeArrayCreate (VT_VARIANT, 1, dimensions);
5009 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
5011 VariantInit (&vOut);
5013 _ltow (i,buffer,10);
5014 vOut.bstrVal = SysAllocString (buffer);
5016 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
5017 VariantClear (&vOut);
5018 SafeArrayDestroy (*safearray);
5021 VariantClear (&vOut);
5026 LIBTEST_API int STDCALL
5027 mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 (SAFEARRAY** safearray)
5029 /* Check that the input array is what is expected and change it so the caller can check */
5030 /* correct marshalling back to managed code */
5033 long lbound1, ubound1;
5039 VariantInit (&element);
5041 /* Check that in array is one dimensional and contains the expected value */
5043 dim = SafeArrayGetDim (*safearray);
5047 SafeArrayGetLBound (*safearray, 1, &lbound1);
5048 SafeArrayGetUBound (*safearray, 1, &ubound1);
5051 if ((lbound1 != 0) || (ubound1 != 1))
5055 for (i= lbound1; i <= ubound1; i++) {
5057 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
5059 failed = (element.vt != VT_I4) || (element.lVal != i+1);
5060 VariantClear (&element);
5065 /* Change one of the elements of the array to verify that [out] parameter is marshalled back to the managed side */
5070 SafeArrayPutElement (*safearray, indices, &element);
5071 VariantClear (&element);
5076 LIBTEST_API int STDCALL
5077 mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (SAFEARRAY* safearray)
5079 /* Check that the input array is what is expected and change it so the caller can check */
5080 /* correct marshalling back to managed code */
5083 long lbound1, ubound1;
5084 SAFEARRAYBOUND dimensions [1];
5090 VariantInit (&element);
5092 /* Check that in array is one dimensional and contains the expected value */
5094 dim = SafeArrayGetDim (safearray);
5098 SafeArrayGetLBound (safearray, 1, &lbound1);
5099 SafeArrayGetUBound (safearray, 1, &ubound1);
5101 if ((lbound1 != 0) || (ubound1 != 0))
5104 for (i= lbound1; i <= ubound1; i++) {
5106 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
5108 failed = (element.vt != VT_I4) || (element.lVal != i+1);
5109 VariantClear (&element);
5114 /* Change the array to verify how [out] parameter is marshalled back to the managed side */
5116 /* Redimension the array */
5117 dimensions [0].lLbound = lbound1;
5118 dimensions [0].cElements = 2;
5119 hr = SafeArrayRedim(safearray, dimensions);
5123 element.lVal = 12345;
5124 SafeArrayPutElement (safearray, indices, &element);
5125 VariantClear (&element);
5129 element.lVal = -12345;
5130 SafeArrayPutElement (safearray, indices, &element);
5131 VariantClear (&element);
5136 LIBTEST_API int STDCALL
5137 mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr (SAFEARRAY* safearray)
5139 /* Check that the input array is what is expected and change it so the caller can check */
5140 /* correct marshalling back to managed code */
5143 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
5144 long i, j, k, failed;
5149 VariantInit (&element);
5151 /* Check that in array is three dimensional and contains the expected values */
5153 dim = SafeArrayGetDim (safearray);
5157 SafeArrayGetLBound (safearray, 1, &lbound1);
5158 SafeArrayGetUBound (safearray, 1, &ubound1);
5160 if ((lbound1 != 0) || (ubound1 != 1))
5163 SafeArrayGetLBound (safearray, 2, &lbound2);
5164 SafeArrayGetUBound (safearray, 2, &ubound2);
5166 if ((lbound2 != 0) || (ubound2 != 1))
5169 SafeArrayGetLBound (safearray, 3, &lbound3);
5170 SafeArrayGetUBound (safearray, 3, &ubound3);
5172 if ((lbound3 != 0) || (ubound3 != 2))
5175 for (i= lbound1; i <= ubound1; i++) {
5177 for (j= lbound2; j <= ubound2; j++) {
5179 for (k= lbound3; k <= ubound3; k++) {
5181 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
5183 failed = ((element.vt != VT_BSTR)
5184 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
5185 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
5186 VariantClear (&element);
5193 /* Change the elements of the array to verify that [out] parameter is marshalled back to the managed side */
5200 SafeArrayPutElement (safearray, indices, &element);
5201 VariantClear (&element);
5208 SafeArrayPutElement (safearray, indices, &element);
5209 VariantClear (&element);
5214 element.vt = VT_BSTR;
5215 element.bstrVal = marshal_bstr_alloc("ABCDEFG");
5216 SafeArrayPutElement (safearray, indices, &element);
5217 VariantClear (&element);
5222 LIBTEST_API int STDCALL
5223 mono_test_marshal_safearray_mixed(
5224 SAFEARRAY *safearray1,
5225 SAFEARRAY **safearray2,
5226 SAFEARRAY *safearray3,
5227 SAFEARRAY **safearray4
5232 /* Initialize out parameters */
5235 /* array1: Check that in array is one dimensional and contains the expected value */
5236 hr = mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (safearray1);
5238 /* array2: Fill in with some values to check on the managed side */
5240 hr = mono_test_marshal_safearray_out_1dim_vt_bstr (safearray2);
5242 /* array3: Check that in array is one dimensional and contains the expected value */
5244 hr = mono_test_marshal_safearray_in_byval_1dim_vt_mixed(safearray3);
5246 /* array4: Check input values and fill in with some values to check on the managed side */
5248 hr = mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr(safearray4);
5255 static int call_managed_res;
5258 call_managed (gpointer arg)
5260 SimpleDelegate del = arg;
5262 call_managed_res = del (42);
5265 LIBTEST_API int STDCALL
5266 mono_test_marshal_thread_attach (SimpleDelegate del)
5274 res = pthread_create (&t, NULL, (gpointer)call_managed, del);
5275 g_assert (res == 0);
5276 pthread_join (t, NULL);
5278 return call_managed_res;
5282 typedef int (STDCALL *Callback) (void);
5284 static Callback callback;
5286 LIBTEST_API void STDCALL
5287 mono_test_marshal_set_callback (Callback cb)
5292 LIBTEST_API int STDCALL
5293 mono_test_marshal_call_callback (void)
5298 LIBTEST_API int STDCALL
5299 mono_test_marshal_lpstr (char *str)
5301 return strcmp ("ABC", str);
5304 LIBTEST_API int STDCALL
5305 mono_test_marshal_lpwstr (gunichar2 *str)
5310 s = g_utf16_to_utf8 (str, -1, NULL, NULL, NULL);
5311 res = strcmp ("ABC", s);
5317 LIBTEST_API char* STDCALL
5318 mono_test_marshal_return_lpstr (void)
5320 char *res = marshal_alloc (4);
5321 strcpy (res, "XYZ");
5326 LIBTEST_API gunichar2* STDCALL
5327 mono_test_marshal_return_lpwstr (void)
5329 gunichar2 *res = marshal_alloc (8);
5330 gunichar2* tmp = g_utf8_to_utf16 ("XYZ", -1, NULL, NULL, NULL);
5332 memcpy (res, tmp, 8);
5340 } SingleDoubleStruct;
5342 LIBTEST_API SingleDoubleStruct STDCALL
5343 mono_test_marshal_return_single_double_struct (void)
5345 SingleDoubleStruct res;
5355 LIBTEST_API int STDCALL
5356 mono_test_has_thiscall (void)
5362 _mono_test_native_thiscall1 (int arg)
5368 _mono_test_native_thiscall2 (int arg, int arg2)
5370 return arg + (arg2^1);
5374 _mono_test_native_thiscall3 (int arg, int arg2, int arg3)
5376 return arg + (arg2^1) + (arg3^2);
5379 #elif defined(__GNUC__)
5381 LIBTEST_API int STDCALL
5382 mono_test_has_thiscall (void)
5387 #define def_asm_fn(name) \
5389 "\t.globl _" #name "\n" \
5391 "\t.globl __" #name "\n" \
5396 def_asm_fn(mono_test_native_thiscall1)
5397 "\tmovl %ecx,%eax\n"
5400 def_asm_fn(mono_test_native_thiscall2)
5401 "\tmovl %ecx,%eax\n"
5402 "\tmovl 4(%esp),%ecx\n"
5404 "\taddl %ecx,%eax\n"
5407 def_asm_fn(mono_test_native_thiscall3)
5408 "\tmovl %ecx,%eax\n"
5409 "\tmovl 4(%esp),%ecx\n"
5411 "\taddl %ecx,%eax\n"
5412 "\tmovl 8(%esp),%ecx\n"
5414 "\taddl %ecx,%eax\n"
5421 LIBTEST_API int STDCALL
5422 mono_test_has_thiscall (void)