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"))
586 SimpleDelegate func, func2, func3;
589 LIBTEST_API DelegateStruct STDCALL
590 mono_test_marshal_delegate_struct (DelegateStruct ds)
594 res.a = ds.func (ds.a) + ds.func2 (ds.a) + (ds.func3 == NULL ? 0 : 1);
596 res.func2 = ds.func2;
602 LIBTEST_API int STDCALL
603 mono_test_marshal_struct (simplestruct ss)
605 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
606 !strcmp (ss.d, "TEST"))
612 LIBTEST_API int STDCALL
613 mono_test_marshal_byref_struct (simplestruct *ss, int a, int b, int c, char *d)
615 gboolean res = (ss->a == a && ss->b == b && ss->c == c && strcmp (ss->d, d) == 0);
617 marshal_free ((char*)ss->d);
622 ss->d = marshal_strdup ("DEF");
638 LIBTEST_API int STDCALL
639 mono_test_marshal_struct2 (simplestruct2 ss)
641 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
642 !strcmp (ss.d, "TEST") &&
643 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
649 /* on HP some of the struct should be on the stack and not in registers */
650 LIBTEST_API int STDCALL
651 mono_test_marshal_struct2_2 (int i, int j, int k, simplestruct2 ss)
653 if (i != 10 || j != 11 || k != 12)
655 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
656 !strcmp (ss.d, "TEST") &&
657 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
663 LIBTEST_API int STDCALL
664 mono_test_marshal_lpstruct (simplestruct *ss)
666 if (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
667 !strcmp (ss->d, "TEST"))
673 LIBTEST_API int STDCALL
674 mono_test_marshal_lpstruct_blittable (point *p)
676 if (p->x == 1.0 && p->y == 2.0)
682 LIBTEST_API int STDCALL
683 mono_test_marshal_struct_array (simplestruct2 *ss)
685 if (! (ss[0].a == 0 && ss[0].b == 1 && ss[0].c == 0 &&
686 !strcmp (ss[0].d, "TEST") &&
687 ss[0].e == 99 && ss[0].f == 1.5 && ss[0].g == 42 && ss[0].h == (guint64)123))
690 if (! (ss[1].a == 0 && ss[1].b == 0 && ss[1].c == 0 &&
691 !strcmp (ss[1].d, "TEST2") &&
692 ss[1].e == 100 && ss[1].f == 2.5 && ss[1].g == 43 && ss[1].h == (guint64)124))
698 typedef struct long_align_struct {
704 LIBTEST_API int STDCALL
705 mono_test_marshal_long_align_struct_array (long_align_struct *ss)
707 return ss[0].a + ss[0].b + ss[0].c + ss[1].a + ss[1].b + ss[1].c;
710 LIBTEST_API simplestruct2 * STDCALL
711 mono_test_marshal_class (int i, int j, int k, simplestruct2 *ss, int l)
718 if (i != 10 || j != 11 || k != 12 || l != 14)
720 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
721 !strcmp (ss->d, "TEST") &&
722 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
725 res = marshal_new0 (simplestruct2, 1);
726 memcpy (res, ss, sizeof (simplestruct2));
727 res->d = marshal_strdup ("TEST");
731 LIBTEST_API int STDCALL
732 mono_test_marshal_byref_class (simplestruct2 **ssp)
734 simplestruct2 *ss = *ssp;
737 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
738 !strcmp (ss->d, "TEST") &&
739 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
742 res = marshal_new0 (simplestruct2, 1);
743 memcpy (res, ss, sizeof (simplestruct2));
744 res->d = marshal_strdup ("TEST-RES");
756 /* Yes, this is correct, we are only trying to determine the value of the stack here */
761 LIBTEST_API int STDCALL
762 reliable_delegate (int a)
768 * Checks whether get_sp() works as expected. It doesn't work with gcc-2.95.3 on linux.
771 is_get_sp_reliable (void)
775 reliable_delegate(1);
777 reliable_delegate(1);
782 LIBTEST_API int STDCALL
783 mono_test_marshal_delegate (SimpleDelegate delegate)
787 /* Check that the delegate wrapper is stdcall */
792 if (is_get_sp_reliable())
793 g_assert (sp1 == sp2);
798 static int STDCALL inc_cb (int i)
803 LIBTEST_API int STDCALL
804 mono_test_marshal_out_delegate (SimpleDelegate *delegate)
811 LIBTEST_API SimpleDelegate STDCALL
812 mono_test_marshal_return_delegate (SimpleDelegate delegate)
818 return_plus_one (int i)
823 LIBTEST_API SimpleDelegate STDCALL
824 mono_test_marshal_return_delegate_2 (void)
826 return return_plus_one;
829 typedef simplestruct (STDCALL *SimpleDelegate2) (simplestruct ss);
832 is_utf16_equals (gunichar2 *s1, const char *s2)
837 s = g_utf16_to_utf8 (s1, -1, NULL, NULL, NULL);
838 res = strcmp (s, s2);
844 LIBTEST_API int STDCALL
845 mono_test_marshal_delegate2 (SimpleDelegate2 delegate)
847 simplestruct ss, res;
853 ss.d2 = g_utf8_to_utf16 ("TEST2", -1, NULL, NULL, NULL);
856 if (! (res.a && !res.b && res.c && !strcmp (res.d, "TEST-RES") && is_utf16_equals (res.d2, "TEST2-RES")))
862 typedef simplestruct* (STDCALL *SimpleDelegate4) (simplestruct *ss);
864 LIBTEST_API int STDCALL
865 mono_test_marshal_delegate4 (SimpleDelegate4 delegate)
876 res = delegate (&ss);
880 /* Check return value */
881 if (! (!res->a && res->b && !res->c && !strcmp (res->d, "TEST")))
884 /* Check NULL argument and NULL result */
885 res = delegate (NULL);
892 typedef int (STDCALL *SimpleDelegate5) (simplestruct **ss);
894 LIBTEST_API int STDCALL
895 mono_test_marshal_delegate5 (SimpleDelegate5 delegate)
908 res = delegate (&ptr);
912 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
918 LIBTEST_API int STDCALL
919 mono_test_marshal_delegate6 (SimpleDelegate5 delegate)
923 res = delegate (NULL);
928 typedef int (STDCALL *SimpleDelegate7) (simplestruct **ss);
930 LIBTEST_API int STDCALL
931 mono_test_marshal_delegate7 (SimpleDelegate7 delegate)
936 /* Check that the input pointer is ignored */
937 ptr = (gpointer)0x12345678;
939 res = delegate (&ptr);
943 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
949 typedef int (STDCALL *InOutByvalClassDelegate) (simplestruct *ss);
951 LIBTEST_API int STDCALL
952 mono_test_marshal_inout_byval_class_delegate (InOutByvalClassDelegate delegate)
960 ss.d = g_strdup_printf ("%s", "FOO");
962 res = delegate (&ss);
966 if (!(ss.a && !ss.b && ss.c && !strcmp (ss.d, "RES")))
972 typedef int (STDCALL *SimpleDelegate8) (gunichar2 *s);
974 LIBTEST_API int STDCALL
975 mono_test_marshal_delegate8 (SimpleDelegate8 delegate, gunichar2 *s)
980 typedef int (STDCALL *return_int_fnt) (int i);
981 typedef int (STDCALL *SimpleDelegate9) (return_int_fnt d);
983 LIBTEST_API int STDCALL
984 mono_test_marshal_delegate9 (SimpleDelegate9 delegate, gpointer ftn)
986 return delegate (ftn);
995 LIBTEST_API int STDCALL
996 mono_test_marshal_delegate10 (SimpleDelegate9 delegate)
998 return delegate (return_self);
1001 typedef int (STDCALL *PrimitiveByrefDelegate) (int *i);
1003 LIBTEST_API int STDCALL
1004 mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate delegate)
1008 int res = delegate (&i);
1018 typedef int (STDCALL *return_int_delegate) (int i);
1020 typedef return_int_delegate (STDCALL *ReturnDelegateDelegate) (void);
1022 LIBTEST_API int STDCALL
1023 mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d)
1028 LIBTEST_API int STDCALL
1029 mono_test_marshal_stringbuilder (char *s, int n)
1031 const char m[] = "This is my message. Isn't it nice?";
1033 if (strcmp (s, "ABCD") != 0)
1040 LIBTEST_API int STDCALL
1041 mono_test_marshal_stringbuilder_default (char *s, int n)
1043 const char m[] = "This is my message. Isn't it nice?";
1050 LIBTEST_API int STDCALL
1051 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
1053 const char m[] = "This is my message. Isn't it nice?";
1057 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1059 len = (len * 2) + 2;
1062 memcpy (s, s2, len);
1069 LIBTEST_API void STDCALL
1070 mono_test_marshal_stringbuilder_out (char **s)
1072 const char m[] = "This is my message. Isn't it nice?";
1075 str = marshal_alloc (strlen (m) + 1);
1076 memcpy (str, m, strlen (m) + 1);
1081 LIBTEST_API int STDCALL
1082 mono_test_marshal_stringbuilder_out_unicode (gunichar2 **s)
1084 const char m[] = "This is my message. Isn't it nice?";
1088 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1090 len = (len * 2) + 2;
1091 *s = marshal_alloc (len);
1092 memcpy (*s, s2, len);
1099 LIBTEST_API int STDCALL
1100 mono_test_marshal_stringbuilder_ref (char **s)
1102 const char m[] = "This is my message. Isn't it nice?";
1105 if (strcmp (*s, "ABC"))
1108 str = marshal_alloc (strlen (m) + 1);
1109 memcpy (str, m, strlen (m) + 1);
1121 LIBTEST_API int STDCALL
1122 mono_test_marshal_empty_string_array (char **array)
1124 return (array == NULL) ? 0 : 1;
1127 LIBTEST_API int STDCALL
1128 mono_test_marshal_string_array (char **array)
1130 if (strcmp (array [0], "ABC"))
1132 if (strcmp (array [1], "DEF"))
1135 if (array [2] != NULL)
1141 LIBTEST_API int STDCALL
1142 mono_test_marshal_byref_string_array (char ***array)
1147 if (strcmp ((*array) [0], "Alpha"))
1149 if (strcmp ((*array) [1], "Beta"))
1151 if (strcmp ((*array) [2], "Gamma"))
1157 LIBTEST_API int STDCALL
1158 mono_test_marshal_stringbuilder_array (char **array)
1160 if (strcmp (array [0], "ABC"))
1162 if (strcmp (array [1], "DEF"))
1165 strcpy (array [0], "DEF");
1166 strcpy (array [1], "ABC");
1171 LIBTEST_API int STDCALL
1172 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
1174 GError *error = NULL;
1177 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
1178 if (strcmp (s, "ABC")) {
1185 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
1186 if (strcmp (s, "DEF")) {
1193 if (strcmp (array2 [0], "ABC"))
1196 if (strcmp (array2 [1], "DEF"))
1202 /* this does not work on Redhat gcc 2.96 */
1203 LIBTEST_API int STDCALL
1204 mono_test_empty_struct (int a, EmptyStruct es, int b)
1206 // printf ("mono_test_empty_struct %d %d\n", a, b);
1208 // Intel icc on ia64 passes 'es' in 2 registers
1209 #if defined(__ia64) && defined(__INTEL_COMPILER)
1212 if (a == 1 && b == 2)
1222 LIBTEST_API ByValStrStruct * STDCALL
1223 mono_test_byvalstr_gen (void)
1225 ByValStrStruct *ret;
1227 ret = malloc(sizeof(ByValStrStruct));
1228 memset(ret, 'a', sizeof(ByValStrStruct)-1);
1229 ret->a[sizeof(ByValStrStruct)-1] = 0;
1234 LIBTEST_API int STDCALL
1235 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
1239 ret = strcmp(data->a, correctString);
1240 // printf ("T1: %s\n", data->a);
1241 // printf ("T2: %s\n", correctString);
1243 /* we need g_free because the allocation was performed by mono_test_byvalstr_gen */
1251 } ByValStrStruct_Unicode;
1253 LIBTEST_API int STDCALL
1254 mono_test_byvalstr_check_unicode (ByValStrStruct_Unicode *ref, int test)
1256 if (ref->flag != 0x1234abcd){
1257 printf ("overwritten data");
1261 if (test == 1 || test == 3){
1262 if (ref->a [0] != '1' ||
1263 ref->a [1] != '2' ||
1269 if (ref->a [0] != '1' ||
1277 LIBTEST_API int STDCALL
1278 NameManglingAnsi (char *data)
1280 return data [0] + data [1] + data [2];
1283 LIBTEST_API int STDCALL
1284 NameManglingAnsiA (char *data)
1286 g_assert_not_reached ();
1289 LIBTEST_API int STDCALL
1290 NameManglingAnsiW (char *data)
1292 g_assert_not_reached ();
1295 LIBTEST_API int STDCALL
1296 NameManglingAnsi2A (char *data)
1298 return data [0] + data [1] + data [2];
1301 LIBTEST_API int STDCALL
1302 NameManglingAnsi2W (char *data)
1304 g_assert_not_reached ();
1307 LIBTEST_API int STDCALL
1308 NameManglingUnicode (char *data)
1310 g_assert_not_reached ();
1313 LIBTEST_API int STDCALL
1314 NameManglingUnicodeW (gunichar2 *data)
1316 return data [0] + data [1] + data [2];
1319 LIBTEST_API int STDCALL
1320 NameManglingUnicode2 (gunichar2 *data)
1322 return data [0] + data [1] + data [2];
1325 LIBTEST_API int STDCALL
1326 NameManglingAutoW (char *data)
1329 return (data [0] + data [1] + data [2]) == 131 ? 0 : 1;
1331 g_assert_not_reached ();
1335 LIBTEST_API int STDCALL
1336 NameManglingAuto (char *data)
1339 return (data [0] + data [1] + data [2]) == 198 ? 0 : 1;
1341 g_assert_not_reached ();
1345 typedef int (STDCALL *intcharFunc)(const char*);
1347 LIBTEST_API void STDCALL
1348 callFunction (intcharFunc f)
1358 LIBTEST_API int STDCALL
1359 class_marshal_test0 (SimpleObj *obj1)
1361 // printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
1363 if (strcmp(obj1->str, "T1"))
1371 LIBTEST_API int STDCALL
1372 class_marshal_test4 (SimpleObj *obj1)
1380 LIBTEST_API void STDCALL
1381 class_marshal_test1 (SimpleObj **obj1)
1383 SimpleObj *res = malloc (sizeof (SimpleObj));
1385 res->str = marshal_strdup ("ABC");
1391 LIBTEST_API int STDCALL
1392 class_marshal_test2 (SimpleObj **obj1)
1394 // printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
1396 if (strcmp((*obj1)->str, "ABC"))
1398 if ((*obj1)->i != 5)
1404 LIBTEST_API int STDCALL
1405 string_marshal_test0 (char *str)
1407 if (strcmp (str, "TEST0"))
1413 LIBTEST_API void STDCALL
1414 string_marshal_test1 (const char **str)
1416 *str = marshal_strdup ("TEST1");
1419 LIBTEST_API int STDCALL
1420 string_marshal_test2 (char **str)
1422 // printf ("string_marshal_test2 %s\n", *str);
1424 if (strcmp (*str, "TEST1"))
1427 *str = marshal_strdup ("TEST2");
1432 LIBTEST_API int STDCALL
1433 string_marshal_test3 (char *str)
1446 LIBTEST_API BlittableClass* STDCALL
1447 TestBlittableClass (BlittableClass *vl)
1449 BlittableClass *res;
1451 // printf ("TestBlittableClass %d %d\n", vl->a, vl->b);
1457 res = marshal_new0 (BlittableClass, 1);
1458 memcpy (res, vl, sizeof (BlittableClass));
1460 res = marshal_new0 (BlittableClass, 1);
1468 typedef struct OSVERSIONINFO_STRUCT
1472 } OSVERSIONINFO_STRUCT;
1474 LIBTEST_API int STDCALL
1475 MyGetVersionEx (OSVERSIONINFO_STRUCT *osvi)
1478 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1483 return osvi->a + osvi->b;
1486 LIBTEST_API int STDCALL
1487 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO_STRUCT *osvi)
1490 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1495 return osvi->a + osvi->b;
1498 LIBTEST_API int STDCALL
1499 mono_test_marshal_point (point pt)
1501 // printf("point %g %g\n", pt.x, pt.y);
1502 if (pt.x == 1.25 && pt.y == 3.5)
1513 LIBTEST_API int STDCALL
1514 mono_test_marshal_mixed_point (mixed_point pt)
1516 // printf("mixed point %d %g\n", pt.x, pt.y);
1517 if (pt.x == 5 && pt.y == 6.75)
1523 LIBTEST_API int STDCALL
1524 mono_test_marshal_mixed_point_2 (mixed_point *pt)
1526 if (pt->x != 5 || pt->y != 6.75)
1535 LIBTEST_API int STDCALL
1536 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
1539 if (*b1 != 0 && *b1 != 1)
1541 if (*b2 != 0 && *b2 != -1) /* variant_bool */
1543 if (*b3 != 0 && *b3 != 1)
1545 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
1557 short b2; /* variant_bool */
1561 LIBTEST_API int STDCALL
1562 marshal_test_bool_struct(struct BoolStruct *s)
1565 if (s->b1 != 0 && s->b1 != 1)
1567 if (s->b2 != 0 && s->b2 != -1)
1569 if (s->b3 != 0 && s->b3 != 1)
1571 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1588 LIBTEST_API int STDCALL
1589 mono_test_marshal_long_struct (LongStruct *s)
1591 return s->i + s->l.l;
1594 LIBTEST_API void STDCALL
1595 mono_test_last_error (int err)
1604 LIBTEST_API int STDCALL
1605 mono_test_asany (void *ptr, int what)
1609 return (*(int*)ptr == 5) ? 0 : 1;
1611 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1613 simplestruct2 ss = *(simplestruct2*)ptr;
1615 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1616 !strcmp (ss.d, "TEST") &&
1617 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1623 GError *error = NULL;
1626 s = g_utf16_to_utf8 (ptr, -1, NULL, NULL, &error);
1631 if (!strcmp (s, "ABC")) {
1641 g_assert_not_reached ();
1655 LIBTEST_API int STDCALL
1656 mono_test_marshal_asany_in (void* ptr)
1658 AsAnyStruct* asAny = ptr;
1659 int res = asAny->i + asAny->j + asAny->k;
1664 LIBTEST_API int STDCALL
1665 mono_test_marshal_asany_inout (void* ptr)
1667 AsAnyStruct* asAny = ptr;
1668 int res = asAny->i + asAny->j + asAny->k;
1670 marshal_free (asAny->s);
1680 LIBTEST_API int STDCALL
1681 mono_test_marshal_asany_out (void* ptr)
1683 AsAnyStruct* asAny = ptr;
1684 int res = asAny->i + asAny->j + asAny->k;
1695 * AMD64 marshalling tests.
1698 typedef struct amd64_struct1 {
1705 LIBTEST_API amd64_struct1 STDCALL
1706 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
1716 LIBTEST_API amd64_struct1 STDCALL
1717 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)
1722 s.l += 1 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8;
1727 typedef struct amd64_struct2 {
1732 LIBTEST_API amd64_struct2 STDCALL
1733 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
1741 typedef struct amd64_struct3 {
1745 LIBTEST_API amd64_struct3 STDCALL
1746 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s)
1753 typedef struct amd64_struct4 {
1757 LIBTEST_API amd64_struct4 STDCALL
1758 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s)
1767 * IA64 marshalling tests.
1769 typedef struct test_struct5 {
1773 LIBTEST_API test_struct5 STDCALL
1774 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, test_struct5 s, int i, double d3, double d4)
1776 s.d1 += d1 + d2 + i;
1777 s.d2 += d3 + d4 + i;
1782 typedef struct test_struct6 {
1786 LIBTEST_API test_struct6 STDCALL
1787 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, test_struct6 s, int i, double d3, double d4)
1789 s.d1 += d1 + d2 + i;
1795 static guint32 custom_res [2];
1797 LIBTEST_API void* STDCALL
1798 mono_test_marshal_pass_return_custom (int i, guint32 *ptr, int j)
1800 /* ptr will be freed by CleanupNative, so make a copy */
1801 custom_res [0] = 0; /* not allocated by AllocHGlobal */
1802 custom_res [1] = ptr [1];
1807 LIBTEST_API int STDCALL
1808 mono_test_marshal_pass_out_custom (int i, guint32 **ptr, int j)
1811 custom_res [1] = i + j + 10;
1818 LIBTEST_API int STDCALL
1819 mono_test_marshal_pass_inout_custom (int i, guint32 *ptr, int j)
1822 ptr [1] = i + ptr [1] + j;
1827 LIBTEST_API int STDCALL
1828 mono_test_marshal_pass_out_byval_custom (int i, guint32 *ptr, int j)
1830 return ptr == NULL ? 0 : 1;
1833 LIBTEST_API int STDCALL
1834 mono_test_marshal_pass_byref_custom (int i, guint32 **ptr, int j)
1841 LIBTEST_API void* STDCALL
1842 mono_test_marshal_pass_return_custom2 (int i, guint32 *ptr, int j)
1844 g_assert_not_reached ();
1849 LIBTEST_API void* STDCALL
1850 mono_test_marshal_pass_return_custom_null (int i, guint32 *ptr, int j)
1852 g_assert (ptr == NULL);
1857 typedef void *(STDCALL *PassReturnPtrDelegate) (void *ptr);
1859 LIBTEST_API int STDCALL
1860 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del)
1874 /* FIXME: Freed with FreeHGlobal */
1882 LIBTEST_API int STDCALL
1883 mono_test_marshal_pass_return_custom_null_in_delegate (PassReturnPtrDelegate del)
1885 void *ptr = del (NULL);
1887 return (ptr == NULL) ? 15 : 0;
1890 typedef void (STDCALL *CustomOutParamDelegate) (void **pptr);
1892 LIBTEST_API int STDCALL
1893 mono_test_marshal_custom_out_param_delegate (CustomOutParamDelegate del)
1905 typedef int (STDCALL *ReturnEnumDelegate) (int e);
1907 LIBTEST_API int STDCALL
1908 mono_test_marshal_return_enum_delegate (ReturnEnumDelegate func)
1918 typedef BlittableStruct (STDCALL *SimpleDelegate10) (BlittableStruct ss);
1920 LIBTEST_API int STDCALL
1921 mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 delegate)
1923 BlittableStruct ss, res;
1930 res = delegate (ss);
1931 if (! ((res.a == -1) && (res.b == -2) && (res.c == -3) && (res.d == -55)))
1937 LIBTEST_API int STDCALL
1938 mono_test_stdcall_name_mangling (int a, int b, int c)
1944 * PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
1951 typedef SmallStruct1 (STDCALL *SmallStructDelegate1) (SmallStruct1 ss);
1953 LIBTEST_API int STDCALL
1954 mono_test_marshal_small_struct_delegate1 (SmallStructDelegate1 delegate)
1956 SmallStruct1 ss, res;
1960 res = delegate (ss);
1961 if (! (res.i == -1))
1971 typedef SmallStruct2 (STDCALL *SmallStructDelegate2) (SmallStruct2 ss);
1973 LIBTEST_API int STDCALL
1974 mono_test_marshal_small_struct_delegate2 (SmallStructDelegate2 delegate)
1976 SmallStruct2 ss, res;
1981 res = delegate (ss);
1982 if (! ((res.i == -2) && (res.j == -3)))
1993 typedef SmallStruct3 (STDCALL *SmallStructDelegate3) (SmallStruct3 ss);
1995 LIBTEST_API int STDCALL
1996 mono_test_marshal_small_struct_delegate3 (SmallStructDelegate3 delegate)
1998 SmallStruct3 ss, res;
2003 res = delegate (ss);
2004 if (! ((res.i == -1) && (res.j == -2)))
2014 typedef SmallStruct4 (STDCALL *SmallStructDelegate4) (SmallStruct4 ss);
2016 LIBTEST_API int STDCALL
2017 mono_test_marshal_small_struct_delegate4 (SmallStructDelegate4 delegate)
2019 SmallStruct4 ss, res;
2023 res = delegate (ss);
2024 if (! (res.i == -1))
2034 typedef SmallStruct5 (STDCALL *SmallStructDelegate5) (SmallStruct5 ss);
2036 LIBTEST_API int STDCALL
2037 mono_test_marshal_small_struct_delegate5 (SmallStructDelegate5 delegate)
2039 SmallStruct5 ss, res;
2043 res = delegate (ss);
2044 if (! (res.i == -5))
2054 typedef SmallStruct6 (STDCALL *SmallStructDelegate6) (SmallStruct6 ss);
2056 LIBTEST_API int STDCALL
2057 mono_test_marshal_small_struct_delegate6 (SmallStructDelegate6 delegate)
2059 SmallStruct6 ss, res;
2064 res = delegate (ss);
2065 if (! ((res.i == -1) && (res.j == -2)))
2076 typedef SmallStruct7 (STDCALL *SmallStructDelegate7) (SmallStruct7 ss);
2078 LIBTEST_API int STDCALL
2079 mono_test_marshal_small_struct_delegate7 (SmallStructDelegate7 delegate)
2081 SmallStruct7 ss, res;
2086 res = delegate (ss);
2087 if (! ((res.i == -1) && (res.j == -2)))
2097 typedef SmallStruct8 (STDCALL *SmallStructDelegate8) (SmallStruct8 ss);
2099 LIBTEST_API int STDCALL
2100 mono_test_marshal_small_struct_delegate8 (SmallStructDelegate8 delegate)
2102 SmallStruct8 ss, res;
2106 res = delegate (ss);
2107 if (! ((res.i == -1.0)))
2117 typedef SmallStruct9 (STDCALL *SmallStructDelegate9) (SmallStruct9 ss);
2119 LIBTEST_API int STDCALL
2120 mono_test_marshal_small_struct_delegate9 (SmallStructDelegate9 delegate)
2122 SmallStruct9 ss, res;
2126 res = delegate (ss);
2127 if (! ((res.i == -1.0)))
2137 typedef SmallStruct10 (STDCALL *SmallStructDelegate10) (SmallStruct10 ss);
2139 LIBTEST_API int STDCALL
2140 mono_test_marshal_small_struct_delegate10 (SmallStructDelegate10 delegate)
2142 SmallStruct10 ss, res;
2147 res = delegate (ss);
2148 if (! ((res.i == -1.0) && (res.j == -2.0)))
2159 typedef SmallStruct11 (STDCALL *SmallStructDelegate11) (SmallStruct11 ss);
2161 LIBTEST_API int STDCALL
2162 mono_test_marshal_small_struct_delegate11 (SmallStructDelegate11 delegate)
2164 SmallStruct11 ss, res;
2169 res = delegate (ss);
2170 if (! ((res.i == -1.0) && (res.j == -2)))
2176 typedef int (STDCALL *ArrayDelegate) (int i, char *j, void *arr);
2178 LIBTEST_API int STDCALL
2179 mono_test_marshal_array_delegate (void *arr, int len, ArrayDelegate del)
2181 return del (len, NULL, arr);
2184 typedef int (STDCALL *ArrayDelegateLong) (gint64 i, char *j, void *arr);
2186 LIBTEST_API int STDCALL
2187 mono_test_marshal_array_delegate_long (void *arr, gint64 len, ArrayDelegateLong del)
2189 return del (len, NULL, arr);
2192 LIBTEST_API int STDCALL
2193 mono_test_marshal_out_array_delegate (int *arr, int len, ArrayDelegate del)
2195 del (len, NULL, arr);
2197 if ((arr [0] != 1) || (arr [1] != 2))
2203 typedef gunichar2* (STDCALL *UnicodeStringDelegate) (gunichar2 *message);
2205 LIBTEST_API int STDCALL
2206 mono_test_marshal_return_unicode_string_delegate (UnicodeStringDelegate del)
2208 const char m[] = "abcdef";
2209 gunichar2 *s2, *res;
2212 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
2221 LIBTEST_API int STDCALL
2222 mono_test_marshal_out_string_array_delegate (char **arr, int len, ArrayDelegate del)
2224 del (len, NULL, arr);
2226 if (!strcmp (arr [0], "ABC") && !strcmp (arr [1], "DEF"))
2232 typedef int (*CdeclDelegate) (int i, int j);
2234 LIBTEST_API int STDCALL
2235 mono_test_marshal_cdecl_delegate (CdeclDelegate del)
2239 for (i = 0; i < 1000; ++i)
2245 typedef char** (STDCALL *ReturnStringArrayDelegate) (int i);
2247 LIBTEST_API int STDCALL
2248 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d)
2256 if (strcmp (arr [0], "ABC") || strcmp (arr [1], "DEF"))
2266 typedef int (STDCALL *ByrefStringDelegate) (char **s);
2268 LIBTEST_API int STDCALL
2269 mono_test_marshal_byref_string_delegate (ByrefStringDelegate d)
2271 char *s = (char*)"ABC";
2278 if (!strcmp (s, "DEF"))
2288 LIBTEST_API int STDCALL
2289 add_delegate (int i, int j)
2294 LIBTEST_API gpointer STDCALL
2295 mono_test_marshal_return_fnptr (void)
2297 return &add_delegate;
2300 LIBTEST_API int STDCALL
2303 printf ("codigo %x\n", code);
2311 LIBTEST_API HandleRef STDCALL
2312 mono_xr_as_handle (int code)
2316 memset (&ref, 0, sizeof (ref));
2328 LIBTEST_API int STDCALL
2329 mono_safe_handle_struct_ref (HandleStructs *x)
2331 printf ("Dingus Ref! \n");
2332 printf ("Values: %d %d %p %p\n", x->a, x->b, x->handle1, x->handle2);
2338 if (x->handle1 != (void*) 0x7080feed)
2341 if (x->handle2 != (void*) 0x1234abcd)
2347 LIBTEST_API int STDCALL
2348 mono_safe_handle_struct (HandleStructs x)
2350 printf ("Dingus Standard! \n");
2351 printf ("Values: %d %d %p %p\n", x.a, x.b, x.handle1, x.handle2);
2357 if (x.handle1 != (void*) 0x7080feed)
2360 if (x.handle2 != (void*) 0x1234abcd)
2370 LIBTEST_API int STDCALL
2371 mono_safe_handle_struct_simple (TrivialHandle x)
2373 printf ("The value is %p\n", x.a);
2374 return ((int)(gsize)x.a) * 2;
2377 LIBTEST_API int STDCALL
2378 mono_safe_handle_return (void)
2383 LIBTEST_API void STDCALL
2384 mono_safe_handle_ref (void **handle)
2387 *handle = (void *) 0xbad;
2391 *handle = (void *) 0x800d;
2394 LIBTEST_API double STDCALL
2395 mono_test_marshal_date_time (double d, double *d2)
2466 VT_USERDEFINED = 29,
2474 VT_STREAMED_OBJECT = 68,
2475 VT_STORED_OBJECT = 69,
2476 VT_BLOB_OBJECT = 70,
2484 void VariantInit(VARIANT* vt)
2501 LIBTEST_API int STDCALL
2502 mono_test_marshal_bstr_in(gunichar2* bstr)
2505 gchar* bstr_utf8 = g_utf16_to_utf8 (bstr, -1, NULL, NULL, NULL);
2506 result = strcmp("mono_test_marshal_bstr_in", bstr_utf8);
2513 LIBTEST_API int STDCALL
2514 mono_test_marshal_bstr_out(gunichar2** bstr)
2516 *bstr = marshal_bstr_alloc ("mono_test_marshal_bstr_out");
2520 LIBTEST_API int STDCALL
2521 mono_test_marshal_bstr_in_null(gunichar2* bstr)
2528 LIBTEST_API int STDCALL
2529 mono_test_marshal_bstr_out_null(gunichar2** bstr)
2535 LIBTEST_API int STDCALL
2536 mono_test_marshal_variant_in_sbyte(VARIANT variant)
2538 if (variant.vt == VT_I1 && variant.cVal == 100)
2543 LIBTEST_API int STDCALL
2544 mono_test_marshal_variant_in_byte(VARIANT variant)
2546 if (variant.vt == VT_UI1 && variant.bVal == 100)
2551 LIBTEST_API int STDCALL
2552 mono_test_marshal_variant_in_short(VARIANT variant)
2554 if (variant.vt == VT_I2 && variant.iVal == 314)
2559 LIBTEST_API int STDCALL
2560 mono_test_marshal_variant_in_ushort(VARIANT variant)
2562 if (variant.vt == VT_UI2 && variant.uiVal == 314)
2567 LIBTEST_API int STDCALL
2568 mono_test_marshal_variant_in_int(VARIANT variant)
2570 if (variant.vt == VT_I4 && variant.lVal == 314)
2575 LIBTEST_API int STDCALL
2576 mono_test_marshal_variant_in_uint(VARIANT variant)
2578 if (variant.vt == VT_UI4 && variant.ulVal == 314)
2583 LIBTEST_API int STDCALL
2584 mono_test_marshal_variant_in_long(VARIANT variant)
2586 if (variant.vt == VT_I8 && variant.llVal == 314)
2591 LIBTEST_API int STDCALL
2592 mono_test_marshal_variant_in_ulong(VARIANT variant)
2594 if (variant.vt == VT_UI8 && variant.ullVal == 314)
2599 LIBTEST_API int STDCALL
2600 mono_test_marshal_variant_in_float(VARIANT variant)
2602 if (variant.vt == VT_R4 && (variant.fltVal - 3.14)/3.14 < .001)
2607 LIBTEST_API int STDCALL
2608 mono_test_marshal_variant_in_double(VARIANT variant)
2610 if (variant.vt == VT_R8 && (variant.dblVal - 3.14)/3.14 < .001)
2615 LIBTEST_API int STDCALL
2616 mono_test_marshal_variant_in_bstr(VARIANT variant)
2619 gchar* bstr_utf8 = g_utf16_to_utf8 (variant.bstrVal, -1, NULL, NULL, NULL);
2620 result = strcmp("PI", bstr_utf8);
2623 if (variant.vt == VT_BSTR && !result)
2628 LIBTEST_API int STDCALL
2629 mono_test_marshal_variant_in_bool_true (VARIANT variant)
2631 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_TRUE)
2636 LIBTEST_API int STDCALL
2637 mono_test_marshal_variant_in_bool_false (VARIANT variant)
2639 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_FALSE)
2644 LIBTEST_API int STDCALL
2645 mono_test_marshal_variant_out_sbyte(VARIANT* variant)
2647 variant->vt = VT_I1;
2648 variant->cVal = 100;
2653 LIBTEST_API int STDCALL
2654 mono_test_marshal_variant_out_byte(VARIANT* variant)
2656 variant->vt = VT_UI1;
2657 variant->bVal = 100;
2662 LIBTEST_API int STDCALL
2663 mono_test_marshal_variant_out_short(VARIANT* variant)
2665 variant->vt = VT_I2;
2666 variant->iVal = 314;
2671 LIBTEST_API int STDCALL
2672 mono_test_marshal_variant_out_ushort(VARIANT* variant)
2674 variant->vt = VT_UI2;
2675 variant->uiVal = 314;
2680 LIBTEST_API int STDCALL
2681 mono_test_marshal_variant_out_int(VARIANT* variant)
2683 variant->vt = VT_I4;
2684 variant->lVal = 314;
2689 LIBTEST_API int STDCALL
2690 mono_test_marshal_variant_out_uint(VARIANT* variant)
2692 variant->vt = VT_UI4;
2693 variant->ulVal = 314;
2698 LIBTEST_API int STDCALL
2699 mono_test_marshal_variant_out_long(VARIANT* variant)
2701 variant->vt = VT_I8;
2702 variant->llVal = 314;
2707 LIBTEST_API int STDCALL
2708 mono_test_marshal_variant_out_ulong(VARIANT* variant)
2710 variant->vt = VT_UI8;
2711 variant->ullVal = 314;
2716 LIBTEST_API int STDCALL
2717 mono_test_marshal_variant_out_float(VARIANT* variant)
2719 variant->vt = VT_R4;
2720 variant->fltVal = 3.14;
2725 LIBTEST_API int STDCALL
2726 mono_test_marshal_variant_out_double(VARIANT* variant)
2728 variant->vt = VT_R8;
2729 variant->dblVal = 3.14;
2734 LIBTEST_API int STDCALL
2735 mono_test_marshal_variant_out_bstr(VARIANT* variant)
2737 variant->vt = VT_BSTR;
2738 variant->bstrVal = marshal_bstr_alloc("PI");
2743 LIBTEST_API int STDCALL
2744 mono_test_marshal_variant_out_bool_true (VARIANT* variant)
2746 variant->vt = VT_BOOL;
2747 variant->boolVal = VARIANT_TRUE;
2752 LIBTEST_API int STDCALL
2753 mono_test_marshal_variant_out_bool_false (VARIANT* variant)
2755 variant->vt = VT_BOOL;
2756 variant->boolVal = VARIANT_FALSE;
2761 typedef int (STDCALL *VarFunc) (int vt, VARIANT variant);
2762 typedef int (STDCALL *VarRefFunc) (int vt, VARIANT* variant);
2764 LIBTEST_API int STDCALL
2765 mono_test_marshal_variant_in_sbyte_unmanaged(VarFunc func)
2770 return func (VT_I1, vt);
2773 LIBTEST_API int STDCALL
2774 mono_test_marshal_variant_in_byte_unmanaged(VarFunc func)
2779 return func (VT_UI1, vt);
2782 LIBTEST_API int STDCALL
2783 mono_test_marshal_variant_in_short_unmanaged(VarFunc func)
2788 return func (VT_I2, vt);
2791 LIBTEST_API int STDCALL
2792 mono_test_marshal_variant_in_ushort_unmanaged(VarFunc func)
2797 return func (VT_UI2, vt);
2800 LIBTEST_API int STDCALL
2801 mono_test_marshal_variant_in_int_unmanaged(VarFunc func)
2806 return func (VT_I4, vt);
2809 LIBTEST_API int STDCALL
2810 mono_test_marshal_variant_in_uint_unmanaged(VarFunc func)
2815 return func (VT_UI4, vt);
2818 LIBTEST_API int STDCALL
2819 mono_test_marshal_variant_in_long_unmanaged(VarFunc func)
2824 return func (VT_I8, vt);
2827 LIBTEST_API int STDCALL
2828 mono_test_marshal_variant_in_ulong_unmanaged(VarFunc func)
2833 return func (VT_UI8, vt);
2836 LIBTEST_API int STDCALL
2837 mono_test_marshal_variant_in_float_unmanaged(VarFunc func)
2842 return func (VT_R4, vt);
2845 LIBTEST_API int STDCALL
2846 mono_test_marshal_variant_in_double_unmanaged(VarFunc func)
2851 return func (VT_R8, vt);
2854 LIBTEST_API int STDCALL
2855 mono_test_marshal_variant_in_bstr_unmanaged(VarFunc func)
2859 vt.bstrVal = marshal_bstr_alloc("PI");
2860 return func (VT_BSTR, vt);
2863 LIBTEST_API int STDCALL
2864 mono_test_marshal_variant_in_bool_true_unmanaged(VarFunc func)
2868 vt.boolVal = VARIANT_TRUE;
2869 return func (VT_BOOL, vt);
2872 LIBTEST_API int STDCALL
2873 mono_test_marshal_variant_in_bool_false_unmanaged(VarFunc func)
2877 vt.boolVal = VARIANT_FALSE;
2878 return func (VT_BOOL, vt);
2881 LIBTEST_API int STDCALL
2882 mono_test_marshal_variant_out_sbyte_unmanaged(VarRefFunc func)
2887 if (vt.vt == VT_I1 && vt.cVal == -100)
2892 LIBTEST_API int STDCALL
2893 mono_test_marshal_variant_out_byte_unmanaged(VarRefFunc func)
2898 if (vt.vt == VT_UI1 && vt.bVal == 100)
2903 LIBTEST_API int STDCALL
2904 mono_test_marshal_variant_out_short_unmanaged(VarRefFunc func)
2909 if (vt.vt == VT_I2 && vt.iVal == -100)
2914 LIBTEST_API int STDCALL
2915 mono_test_marshal_variant_out_ushort_unmanaged(VarRefFunc func)
2920 if (vt.vt == VT_UI2 && vt.uiVal == 100)
2925 LIBTEST_API int STDCALL
2926 mono_test_marshal_variant_out_int_unmanaged(VarRefFunc func)
2931 if (vt.vt == VT_I4 && vt.lVal == -100)
2936 LIBTEST_API int STDCALL
2937 mono_test_marshal_variant_out_uint_unmanaged(VarRefFunc func)
2942 if (vt.vt == VT_UI4 && vt.ulVal == 100)
2947 LIBTEST_API int STDCALL
2948 mono_test_marshal_variant_out_long_unmanaged(VarRefFunc func)
2953 if (vt.vt == VT_I8 && vt.llVal == -100)
2958 LIBTEST_API int STDCALL
2959 mono_test_marshal_variant_out_ulong_unmanaged(VarRefFunc func)
2964 if (vt.vt == VT_UI8 && vt.ullVal == 100)
2969 LIBTEST_API int STDCALL
2970 mono_test_marshal_variant_out_float_unmanaged(VarRefFunc func)
2975 if (vt.vt == VT_R4 && fabs (vt.fltVal - 3.14f) < 1e-10)
2980 LIBTEST_API int STDCALL
2981 mono_test_marshal_variant_out_double_unmanaged(VarRefFunc func)
2986 if (vt.vt == VT_R8 && fabs (vt.dblVal - 3.14) < 1e-10)
2991 LIBTEST_API int STDCALL
2992 mono_test_marshal_variant_out_bstr_unmanaged(VarRefFunc func)
3000 func (VT_BSTR, &vt);
3001 bstr_utf8 = g_utf16_to_utf8 (vt.bstrVal, -1, NULL, NULL, NULL);
3002 result = strcmp("PI", bstr_utf8);
3004 if (vt.vt == VT_BSTR && !result)
3009 LIBTEST_API int STDCALL
3010 mono_test_marshal_variant_out_bool_true_unmanaged(VarRefFunc func)
3014 func (VT_BOOL, &vt);
3015 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3020 LIBTEST_API int STDCALL
3021 mono_test_marshal_variant_out_bool_false_unmanaged(VarRefFunc func)
3025 func (VT_BOOL, &vt);
3026 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3031 typedef struct MonoComObject MonoComObject;
3035 int (STDCALL *QueryInterface)(MonoComObject* pUnk, gpointer riid, gpointer* ppv);
3036 int (STDCALL *AddRef)(MonoComObject* pUnk);
3037 int (STDCALL *Release)(MonoComObject* pUnk);
3038 int (STDCALL *get_ITest)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3039 int (STDCALL *SByteIn)(MonoComObject* pUnk, char a);
3040 int (STDCALL *ByteIn)(MonoComObject* pUnk, unsigned char a);
3041 int (STDCALL *ShortIn)(MonoComObject* pUnk, short a);
3042 int (STDCALL *UShortIn)(MonoComObject* pUnk, unsigned short a);
3043 int (STDCALL *IntIn)(MonoComObject* pUnk, int a);
3044 int (STDCALL *UIntIn)(MonoComObject* pUnk, unsigned int a);
3045 int (STDCALL *LongIn)(MonoComObject* pUnk, gint64 a);
3046 int (STDCALL *ULongIn)(MonoComObject* pUnk, guint64 a);
3047 int (STDCALL *FloatIn)(MonoComObject* pUnk, float a);
3048 int (STDCALL *DoubleIn)(MonoComObject* pUnk, double a);
3049 int (STDCALL *ITestIn)(MonoComObject* pUnk, MonoComObject* pUnk2);
3050 int (STDCALL *ITestOut)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3053 struct MonoComObject
3059 static GUID IID_ITest = {0, 0, 0, {0,0,0,0,0,0,0,1}};
3060 static GUID IID_IMonoUnknown = {0, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3061 static GUID IID_IMonoDispatch = {0x00020400, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3063 LIBTEST_API int STDCALL
3064 MonoQueryInterface(MonoComObject* pUnk, gpointer riid, gpointer* ppv)
3068 if (!memcmp(riid, &IID_IMonoUnknown, sizeof(GUID))) {
3072 else if (!memcmp(riid, &IID_ITest, sizeof(GUID))) {
3076 else if (!memcmp(riid, &IID_IMonoDispatch, sizeof(GUID))) {
3080 return 0x80004002; //E_NOINTERFACE;
3083 LIBTEST_API int STDCALL
3084 MonoAddRef(MonoComObject* pUnk)
3086 return ++(pUnk->m_ref);
3089 LIBTEST_API int STDCALL
3090 MonoRelease(MonoComObject* pUnk)
3092 return --(pUnk->m_ref);
3095 LIBTEST_API int STDCALL
3096 SByteIn(MonoComObject* pUnk, char a)
3101 LIBTEST_API int STDCALL
3102 ByteIn(MonoComObject* pUnk, unsigned char a)
3107 LIBTEST_API int STDCALL
3108 ShortIn(MonoComObject* pUnk, short a)
3113 LIBTEST_API int STDCALL
3114 UShortIn(MonoComObject* pUnk, unsigned short a)
3119 LIBTEST_API int STDCALL
3120 IntIn(MonoComObject* pUnk, int a)
3125 LIBTEST_API int STDCALL
3126 UIntIn(MonoComObject* pUnk, unsigned int a)
3131 LIBTEST_API int STDCALL
3132 LongIn(MonoComObject* pUnk, gint64 a)
3137 LIBTEST_API int STDCALL
3138 ULongIn(MonoComObject* pUnk, guint64 a)
3143 LIBTEST_API int STDCALL
3144 FloatIn(MonoComObject* pUnk, float a)
3149 LIBTEST_API int STDCALL
3150 DoubleIn(MonoComObject* pUnk, double a)
3155 LIBTEST_API int STDCALL
3156 ITestIn(MonoComObject* pUnk, MonoComObject *pUnk2)
3161 LIBTEST_API int STDCALL
3162 ITestOut(MonoComObject* pUnk, MonoComObject* *ppUnk)
3167 static void create_com_object (MonoComObject** pOut);
3169 LIBTEST_API int STDCALL
3170 get_ITest(MonoComObject* pUnk, MonoComObject* *ppUnk)
3172 create_com_object (ppUnk);
3176 static void create_com_object (MonoComObject** pOut)
3178 *pOut = marshal_new0 (MonoComObject, 1);
3179 (*pOut)->vtbl = marshal_new0 (MonoIUnknown, 1);
3182 (*pOut)->vtbl->QueryInterface = MonoQueryInterface;
3183 (*pOut)->vtbl->AddRef = MonoAddRef;
3184 (*pOut)->vtbl->Release = MonoRelease;
3185 (*pOut)->vtbl->SByteIn = SByteIn;
3186 (*pOut)->vtbl->ByteIn = ByteIn;
3187 (*pOut)->vtbl->ShortIn = ShortIn;
3188 (*pOut)->vtbl->UShortIn = UShortIn;
3189 (*pOut)->vtbl->IntIn = IntIn;
3190 (*pOut)->vtbl->UIntIn = UIntIn;
3191 (*pOut)->vtbl->LongIn = LongIn;
3192 (*pOut)->vtbl->ULongIn = ULongIn;
3193 (*pOut)->vtbl->FloatIn = FloatIn;
3194 (*pOut)->vtbl->DoubleIn = DoubleIn;
3195 (*pOut)->vtbl->ITestIn = ITestIn;
3196 (*pOut)->vtbl->ITestOut = ITestOut;
3197 (*pOut)->vtbl->get_ITest = get_ITest;
3200 static MonoComObject* same_object = NULL;
3202 LIBTEST_API int STDCALL
3203 mono_test_marshal_com_object_create(MonoComObject* *pUnk)
3205 create_com_object (pUnk);
3208 same_object = *pUnk;
3213 LIBTEST_API int STDCALL
3214 mono_test_marshal_com_object_same(MonoComObject* *pUnk)
3216 *pUnk = same_object;
3221 LIBTEST_API int STDCALL
3222 mono_test_marshal_com_object_destroy(MonoComObject *pUnk)
3224 int ref = --(pUnk->m_ref);
3231 LIBTEST_API int STDCALL
3232 mono_test_marshal_com_object_ref_count(MonoComObject *pUnk)
3237 LIBTEST_API int STDCALL
3238 mono_test_marshal_ccw_itest (MonoComObject *pUnk)
3241 MonoComObject* pTest;
3246 hr = pUnk->vtbl->SByteIn (pUnk, -100);
3249 hr = pUnk->vtbl->ByteIn (pUnk, 100);
3252 hr = pUnk->vtbl->ShortIn (pUnk, -100);
3255 hr = pUnk->vtbl->UShortIn (pUnk, 100);
3258 hr = pUnk->vtbl->IntIn (pUnk, -100);
3261 hr = pUnk->vtbl->UIntIn (pUnk, 100);
3264 hr = pUnk->vtbl->LongIn (pUnk, -100);
3267 hr = pUnk->vtbl->ULongIn (pUnk, 100);
3270 hr = pUnk->vtbl->FloatIn (pUnk, 3.14f);
3273 hr = pUnk->vtbl->DoubleIn (pUnk, 3.14);
3276 hr = pUnk->vtbl->ITestIn (pUnk, pUnk);
3279 hr = pUnk->vtbl->ITestOut (pUnk, &pTest);
3287 * mono_method_get_unmanaged_thunk tests
3290 #if defined(__GNUC__) && ((defined(__i386__) && (defined(__linux__) || defined (__APPLE__)) || defined (__FreeBSD__) || defined(__OpenBSD__)) || (defined(__ppc__) && defined(__APPLE__)))
3291 #define ALIGN(size) __attribute__ ((aligned(size)))
3297 /* thunks.cs:TestStruct */
3298 typedef struct _TestStruct {
3303 /* Searches for mono symbols in all loaded modules */
3305 lookup_mono_symbol (const char *symbol_name)
3308 if (g_module_symbol (g_module_open (NULL, G_MODULE_BIND_LAZY), symbol_name, &symbol))
3314 LIBTEST_API gpointer STDCALL
3315 mono_test_marshal_lookup_symbol (const char *symbol_name)
3317 return lookup_mono_symbol (symbol_name);
3321 * test_method_thunk:
3323 * @test_id: the test number
3324 * @test_method_handle: MonoMethod* of the C# test method
3325 * @create_object_method_handle: MonoMethod* of thunks.cs:Test.CreateObject
3327 LIBTEST_API int STDCALL
3328 test_method_thunk (int test_id, gpointer test_method_handle, gpointer create_object_method_handle)
3330 gpointer (*mono_method_get_unmanaged_thunk)(gpointer)
3331 = lookup_mono_symbol ("mono_method_get_unmanaged_thunk");
3333 gpointer (*mono_string_new_wrapper)(const char *)
3334 = lookup_mono_symbol ("mono_string_new_wrapper");
3336 char* (*mono_string_to_utf8)(gpointer)
3337 = lookup_mono_symbol ("mono_string_to_utf8");
3339 gpointer (*mono_object_unbox)(gpointer)
3340 = lookup_mono_symbol ("mono_object_unbox");
3342 gpointer test_method, ex = NULL;
3343 gpointer (STDCALL *CreateObject)(gpointer*);
3346 if (!mono_method_get_unmanaged_thunk)
3349 test_method = mono_method_get_unmanaged_thunk (test_method_handle);
3353 CreateObject = mono_method_get_unmanaged_thunk (create_object_method_handle);
3361 /* thunks.cs:Test.Test0 */
3362 void (STDCALL *F)(gpointer*) = test_method;
3368 /* thunks.cs:Test.Test1 */
3369 int (STDCALL *F)(gpointer*) = test_method;
3376 /* thunks.cs:Test.Test2 */
3377 gpointer (STDCALL *F)(gpointer, gpointer*) = test_method;
3378 gpointer str = mono_string_new_wrapper ("foo");
3379 if (str != F (str, &ex))
3385 /* thunks.cs:Test.Test3 */
3386 gpointer (STDCALL *F)(gpointer, gpointer, gpointer*);
3391 obj = CreateObject (&ex);
3392 str = mono_string_new_wrapper ("bar");
3394 if (str != F (obj, str, &ex))
3400 /* thunks.cs:Test.Test4 */
3401 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3406 obj = CreateObject (&ex);
3407 str = mono_string_new_wrapper ("bar");
3409 if (42 != F (obj, str, 42, &ex))
3416 /* thunks.cs:Test.Test5 */
3417 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3422 obj = CreateObject (&ex);
3423 str = mono_string_new_wrapper ("bar");
3425 F (obj, str, 42, &ex);
3433 /* thunks.cs:Test.Test6 */
3434 int (STDCALL *F)(gpointer, guint8, gint16, gint32, gint64, float, double,
3435 gpointer, gpointer*);
3437 gpointer str = mono_string_new_wrapper ("Test6");
3441 obj = CreateObject (&ex);
3443 res = F (obj, 254, 32700, -245378, 6789600, 3.1415, 3.1415, str, &ex);
3454 /* thunks.cs:Test.Test7 */
3455 gint64 (STDCALL *F)(gpointer*) = test_method;
3456 if (F (&ex) != G_MAXINT64)
3462 /* thunks.cs:Test.Test8 */
3463 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3464 gpointer*, gpointer*);
3476 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3484 (fabs (a5 - 3.1415) < 0.001) &&
3485 (fabs (a6 - 3.1415) < 0.001) &&
3486 strcmp (mono_string_to_utf8 (a7), "Test8") == 0))
3493 /* thunks.cs:Test.Test9 */
3494 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3495 gpointer*, gpointer*);
3507 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3515 /* thunks.cs:Test.Test10 */
3516 void (STDCALL *F)(gpointer*, gpointer*);
3518 gpointer obj1, obj2;
3520 obj1 = obj2 = CreateObject (&ex);
3537 /* thunks.cs:TestStruct.Test0 */
3538 int (STDCALL *F)(gpointer*, gpointer*);
3544 obj = CreateObject (&ex);
3551 a1 = mono_object_unbox (obj);
3567 /* check whether the call was really by value */
3568 if (a1->A != 42 || a1->B != 3.1415)
3575 /* thunks.cs:TestStruct.Test1 */
3576 void (STDCALL *F)(gpointer, gpointer*);
3581 obj = CreateObject (&ex);
3588 a1 = mono_object_unbox (obj);
3601 if (!fabs (a1->B - 3.1415) < 0.001)
3608 /* thunks.cs:TestStruct.Test2 */
3609 gpointer (STDCALL *F)(gpointer*);
3623 a1 = mono_object_unbox (obj);
3628 if (!fabs (a1->B - 3.1415) < 0.001)
3635 /* thunks.cs:TestStruct.Test3 */
3636 void (STDCALL *F)(gpointer, gpointer*);
3641 obj = CreateObject (&ex);
3648 a1 = mono_object_unbox (obj);
3684 LIBTEST_API int STDCALL
3685 mono_test_Winx64_struct1_in (winx64_struct1 var)
3698 LIBTEST_API int STDCALL
3699 mono_test_Winx64_struct2_in (winx64_struct2 var)
3716 LIBTEST_API int STDCALL
3717 mono_test_Winx64_struct3_in (winx64_struct3 var)
3723 if (var.c != 0x1234)
3736 LIBTEST_API int STDCALL
3737 mono_test_Winx64_struct4_in (winx64_struct4 var)
3743 if (var.c != 0x1234)
3745 if (var.d != 0x87654321)
3757 LIBTEST_API int STDCALL
3758 mono_test_Winx64_struct5_in (winx64_struct5 var)
3776 LIBTEST_API int STDCALL
3777 mono_test_Winx64_struct6_in (winx64_struct6 var)
3788 LIBTEST_API int STDCALL
3789 mono_test_Winx64_structs_in1 (winx64_struct1 var1,
3790 winx64_struct2 var2,
3791 winx64_struct3 var3,
3792 winx64_struct4 var4)
3806 if (var3.c != 0x1234)
3813 if (var4.c != 0x1234)
3815 if (var4.d != 0x87654321)
3820 LIBTEST_API int STDCALL
3821 mono_test_Winx64_structs_in2 (winx64_struct1 var1,
3822 winx64_struct1 var2,
3823 winx64_struct1 var3,
3824 winx64_struct1 var4,
3825 winx64_struct1 var5)
3841 LIBTEST_API int STDCALL
3842 mono_test_Winx64_structs_in3 (winx64_struct1 var1,
3843 winx64_struct5 var2,
3844 winx64_struct1 var3,
3845 winx64_struct5 var4,
3846 winx64_struct1 var5,
3847 winx64_struct5 var6)
3882 LIBTEST_API winx64_struct1 STDCALL
3883 mono_test_Winx64_struct1_ret (void)
3890 LIBTEST_API winx64_struct2 STDCALL
3891 mono_test_Winx64_struct2_ret (void)
3899 LIBTEST_API winx64_struct3 STDCALL
3900 mono_test_Winx64_struct3_ret (void)
3909 LIBTEST_API winx64_struct4 STDCALL
3910 mono_test_Winx64_struct4_ret (void)
3920 LIBTEST_API winx64_struct5 STDCALL
3921 mono_test_Winx64_struct5_ret (void)
3930 LIBTEST_API winx64_struct1 STDCALL
3931 mono_test_Winx64_struct1_ret_5_args (char a, char b, char c, char d, char e)
3934 ret.a = a + b + c + d + e;
3938 LIBTEST_API winx64_struct5 STDCALL
3939 mono_test_Winx64_struct5_ret6_args (char a, char b, char c, char d, char e)
3952 } winx64_floatStruct;
3954 LIBTEST_API int STDCALL
3955 mono_test_Winx64_floatStruct (winx64_floatStruct a)
3957 if (a.a > 5.6 || a.a < 5.4)
3960 if (a.b > 9.6 || a.b < 9.4)
3969 } winx64_doubleStruct;
3971 LIBTEST_API int STDCALL
3972 mono_test_Winx64_doubleStruct (winx64_doubleStruct a)
3974 if (a.a > 5.6 || a.a < 5.4)
3980 typedef int (STDCALL *managed_struct1_delegate) (winx64_struct1 a);
3982 LIBTEST_API int STDCALL
3983 mono_test_managed_Winx64_struct1_in(managed_struct1_delegate func)
3990 typedef int (STDCALL *managed_struct5_delegate) (winx64_struct5 a);
3992 LIBTEST_API int STDCALL
3993 mono_test_managed_Winx64_struct5_in(managed_struct5_delegate func)
4002 typedef int (STDCALL *managed_struct1_struct5_delegate) (winx64_struct1 a, winx64_struct5 b,
4003 winx64_struct1 c, winx64_struct5 d,
4004 winx64_struct1 e, winx64_struct5 f);
4006 LIBTEST_API int STDCALL
4007 mono_test_managed_Winx64_struct1_struct5_in(managed_struct1_struct5_delegate func)
4009 winx64_struct1 a, c, e;
4010 winx64_struct5 b, d, f;
4012 b.a = 2; b.b = 3; b.c = 4;
4014 d.a = 6; d.b = 7; d.c = 8;
4016 f.a = 10; f.b = 11; f.c = 12;
4018 return func (a, b, c, d, e, f);
4021 typedef winx64_struct1 (STDCALL *managed_struct1_ret_delegate) (void);
4023 LIBTEST_API int STDCALL
4024 mono_test_Winx64_struct1_ret_managed (managed_struct1_ret_delegate func)
4036 typedef winx64_struct5 (STDCALL *managed_struct5_ret_delegate) (void);
4038 LIBTEST_API int STDCALL
4039 mono_test_Winx64_struct5_ret_managed (managed_struct5_ret_delegate func)
4055 LIBTEST_API int STDCALL
4056 mono_test_marshal_bool_in (int arg, unsigned int expected, unsigned int bDefaultMarsh, unsigned int bBoolCustMarsh,
4057 char bI1CustMarsh, unsigned char bU1CustMarsh, short bVBCustMarsh)
4061 if (bDefaultMarsh != expected)
4065 if (bBoolCustMarsh != expected)
4069 if (bI1CustMarsh != expected)
4073 if (bU1CustMarsh != expected)
4077 if (bVBCustMarsh != expected)
4086 LIBTEST_API int STDCALL
4087 mono_test_marshal_bool_out (int arg, unsigned int testVal, unsigned int* bDefaultMarsh, unsigned int* bBoolCustMarsh,
4088 char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh)
4094 *bDefaultMarsh = testVal;
4097 if (!bBoolCustMarsh)
4099 *bBoolCustMarsh = testVal;
4104 *bI1CustMarsh = (char)testVal;
4109 *bU1CustMarsh = (unsigned char)testVal;
4114 *bVBCustMarsh = (unsigned short)testVal;
4122 LIBTEST_API int STDCALL
4123 mono_test_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4124 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh,
4125 unsigned short* bVBCustMarsh)
4131 if (*bDefaultMarsh != expected)
4133 *bDefaultMarsh = testVal;
4136 if (!bBoolCustMarsh)
4138 if (*bBoolCustMarsh != expected)
4140 *bBoolCustMarsh = testVal;
4145 if (*bI1CustMarsh != expected)
4147 *bI1CustMarsh = (char)testVal;
4152 if (*bU1CustMarsh != expected)
4154 *bU1CustMarsh = (unsigned char)testVal;
4159 if (*bVBCustMarsh != expected)
4161 *bVBCustMarsh = (unsigned short)testVal;
4170 typedef int (STDCALL *MarshalBoolInDelegate) (int arg, unsigned int expected, unsigned int bDefaultMarsh,
4171 unsigned int bBoolCustMarsh, char bI1CustMarsh, unsigned char bU1CustMarsh, unsigned short bVBCustMarsh);
4173 LIBTEST_API int STDCALL
4174 mono_test_managed_marshal_bool_in (int arg, unsigned int expected, unsigned int testVal, MarshalBoolInDelegate pfcn)
4181 return pfcn (arg, expected, testVal, 0, 0, 0, 0);
4183 return pfcn (arg, expected, 0, testVal, 0, 0, 0);
4185 return pfcn (arg, expected, 0, 0, testVal, 0, 0);
4187 return pfcn (arg, expected, 0, 0, 0, testVal, 0);
4189 return pfcn (arg, expected, 0, 0, 0, 0, testVal);
4197 typedef int (STDCALL *MarshalBoolOutDelegate) (int arg, unsigned int expected, unsigned int* bDefaultMarsh,
4198 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4200 LIBTEST_API int STDCALL
4201 mono_test_managed_marshal_bool_out (int arg, unsigned int expected, unsigned int testVal, MarshalBoolOutDelegate pfcn)
4204 unsigned int lDefaultMarsh, lBoolCustMarsh;
4205 char lI1CustMarsh = 0;
4206 unsigned char lU1CustMarsh = 0;
4207 unsigned short lVBCustMarsh = 0;
4208 lDefaultMarsh = lBoolCustMarsh = 0;
4215 unsigned int ltVal = 0;
4216 ret = pfcn (arg, testVal, <Val, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4218 return 0x0100 + ret;
4219 if (expected != ltVal)
4224 unsigned int ltVal = 0;
4225 ret = pfcn (arg, testVal, &lDefaultMarsh, <Val, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4227 return 0x0300 + ret;
4228 if (expected != ltVal)
4234 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, <Val, &lU1CustMarsh, &lVBCustMarsh);
4236 return 0x0500 + ret;
4237 if (expected != ltVal)
4242 unsigned char ltVal = 0;
4243 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <Val, &lVBCustMarsh);
4245 return 0x0700 + ret;
4246 if (expected != ltVal)
4251 unsigned short ltVal = 0;
4252 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <Val);
4254 return 0x0900 + ret;
4255 if (expected != ltVal)
4266 typedef int (STDCALL *MarshalBoolRefDelegate) (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4267 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4269 LIBTEST_API int STDCALL
4270 mono_test_managed_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int outExpected,
4271 unsigned int outTestVal, MarshalBoolRefDelegate pfcn)
4274 unsigned int lDefaultMarsh, lBoolCustMarsh;
4275 char lI1CustMarsh = 0;
4276 unsigned char lU1CustMarsh = 0;
4277 unsigned short lVBCustMarsh = 0;
4278 lDefaultMarsh = lBoolCustMarsh = 0;
4286 unsigned int ltestVal = testVal;
4287 ret = pfcn (arg, expected, outTestVal, <estVal, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4289 return 0x0100 + ret;
4290 if (outExpected != ltestVal)
4296 unsigned int ltestVal = testVal;
4297 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, <estVal, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4299 return 0x0300 + ret;
4300 if (outExpected != ltestVal)
4306 char ltestVal = testVal;
4307 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, <estVal, &lU1CustMarsh, &lVBCustMarsh);
4309 return 0x0500 + ret;
4310 if (outExpected != ltestVal)
4316 unsigned char ltestVal = testVal;
4317 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <estVal, &lVBCustMarsh);
4319 return 0x0700 + ret;
4320 if (outExpected != ltestVal)
4326 unsigned short ltestVal = testVal;
4327 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <estVal);
4329 return 0x0900 + ret;
4330 if (outExpected != ltestVal)
4343 LIBTEST_API int STDCALL
4344 mono_test_marshal_safearray_out_1dim_vt_bstr_empty (SAFEARRAY** safearray)
4346 /* Create an empty one-dimensional array of variants */
4348 SAFEARRAYBOUND dimensions [1];
4350 dimensions [0].lLbound = 0;
4351 dimensions [0].cElements = 0;
4353 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4358 LIBTEST_API int STDCALL
4359 mono_test_marshal_safearray_out_1dim_vt_bstr (SAFEARRAY** safearray)
4361 /* Create a one-dimensional array of 10 variants filled with "0" to "9" */
4363 SAFEARRAYBOUND dimensions [1];
4369 dimensions [0].lLbound = 0;
4370 dimensions [0].cElements = 10;
4372 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4373 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4375 VariantInit (&vOut);
4377 _ltoa (i,buffer,10);
4378 vOut.bstrVal= marshal_bstr_alloc (buffer);
4380 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4381 VariantClear (&vOut);
4382 SafeArrayDestroy (pSA);
4385 VariantClear (&vOut);
4391 LIBTEST_API int STDCALL
4392 mono_test_marshal_safearray_out_2dim_vt_i4 (SAFEARRAY** safearray)
4394 /* Create a two-dimensional array of 4x3 variants filled with 11, 12, 13, etc. */
4396 SAFEARRAYBOUND dimensions [2];
4401 dimensions [0].lLbound = 0;
4402 dimensions [0].cElements = 4;
4403 dimensions [1].lLbound = 0;
4404 dimensions [1].cElements = 3;
4406 pSA= SafeArrayCreate(VT_VARIANT, 2, dimensions);
4407 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4408 for (j= dimensions [1].lLbound; j< (dimensions [1].cElements + dimensions [1].lLbound); j++) {
4410 VariantInit (&vOut);
4412 vOut.lVal = (i+1)*10+(j+1);
4415 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4416 VariantClear (&vOut);
4417 SafeArrayDestroy (pSA);
4420 VariantClear (&vOut); // does a deep destroy of source VARIANT
4427 LIBTEST_API int STDCALL
4428 mono_test_marshal_safearray_out_4dim_vt_i4 (SAFEARRAY** safearray)
4430 /* Create a four-dimensional array of 10x3x6x7 variants filled with their indices */
4431 /* Also use non zero lower bounds */
4433 SAFEARRAYBOUND dimensions [4];
4438 dimensions [0].lLbound = 15;
4439 dimensions [0].cElements = 10;
4440 dimensions [1].lLbound = 20;
4441 dimensions [1].cElements = 3;
4442 dimensions [2].lLbound = 5;
4443 dimensions [2].cElements = 6;
4444 dimensions [3].lLbound = 12;
4445 dimensions [3].cElements = 7;
4447 pSA= SafeArrayCreate (VT_VARIANT, 4, dimensions);
4449 SafeArrayAccessData (pSA, (void **)&pData);
4451 for (i= 0; i< 10*3*6*7; i++) {
4452 VariantInit(&pData [i]);
4453 pData [i].vt = VT_I4;
4456 SafeArrayUnaccessData (pSA);
4461 LIBTEST_API int STDCALL
4462 mono_test_marshal_safearray_in_byval_1dim_empty (SAFEARRAY* safearray)
4464 /* Check that array is one dimensional and empty */
4467 long lbound, ubound;
4469 dim = SafeArrayGetDim (safearray);
4473 SafeArrayGetLBound (safearray, 1, &lbound);
4474 SafeArrayGetUBound (safearray, 1, &ubound);
4476 if ((lbound > 0) || (ubound > 0))
4482 LIBTEST_API int STDCALL
4483 mono_test_marshal_safearray_in_byval_1dim_vt_i4 (SAFEARRAY* safearray)
4485 /* Check that array is one dimensional containing integers from 1 to 10 */
4488 long lbound, ubound;
4493 dim = SafeArrayGetDim (safearray);
4497 SafeArrayGetLBound (safearray, 1, &lbound);
4498 SafeArrayGetUBound (safearray, 1, &ubound);
4500 if ((lbound != 0) || (ubound != 9))
4503 SafeArrayAccessData (safearray, (void **)&pData);
4504 for (i= lbound; i <= ubound; i++) {
4505 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i + 1))
4508 SafeArrayUnaccessData (safearray);
4513 LIBTEST_API int STDCALL
4514 mono_test_marshal_safearray_in_byval_1dim_vt_mixed (SAFEARRAY* safearray)
4516 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4519 long lbound, ubound;
4526 VariantInit (&element);
4528 dim = SafeArrayGetDim (safearray);
4532 SafeArrayGetLBound (safearray, 1, &lbound);
4533 SafeArrayGetUBound (safearray, 1, &ubound);
4535 if ((lbound != 0) || (ubound != 12))
4538 SafeArrayAccessData (safearray, (void **)&pData);
4539 for (i= lbound; i <= ubound; i++) {
4540 if ((i%2 == 0) && (pData [i].vt != VT_I4))
4542 if ((i%2 == 1) && (pData [i].vt != VT_BSTR))
4544 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i))
4547 SafeArrayUnaccessData (safearray);
4549 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4554 SafeArrayPutElement (safearray, indices, &element);
4555 VariantClear (&element);
4560 LIBTEST_API int STDCALL
4561 mono_test_marshal_safearray_in_byval_2dim_vt_i4 (SAFEARRAY* safearray)
4563 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4566 long lbound1, ubound1, lbound2, ubound2;
4571 VariantInit (&element);
4573 dim = SafeArrayGetDim (safearray);
4577 SafeArrayGetLBound (safearray, 1, &lbound1);
4578 SafeArrayGetUBound (safearray, 1, &ubound1);
4580 if ((lbound1 != 0) || (ubound1 != 1))
4583 SafeArrayGetLBound (safearray, 2, &lbound2);
4584 SafeArrayGetUBound (safearray, 2, &ubound2);
4586 if ((lbound2 != 0) || (ubound2 != 3)) {
4590 for (i= lbound1; i <= ubound1; i++) {
4592 for (j= lbound2; j <= ubound2; j++) {
4594 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4596 failed = ((element.vt != VT_I4) || (element.lVal != 10*(i+1)+(j+1)));
4597 VariantClear (&element);
4603 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4609 SafeArrayPutElement (safearray, indices, &element);
4610 VariantClear (&element);
4615 LIBTEST_API int STDCALL
4616 mono_test_marshal_safearray_in_byval_3dim_vt_bstr (SAFEARRAY* safearray)
4618 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4621 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4622 long i, j, k, failed;
4626 VariantInit (&element);
4628 dim = SafeArrayGetDim (safearray);
4632 SafeArrayGetLBound (safearray, 1, &lbound1);
4633 SafeArrayGetUBound (safearray, 1, &ubound1);
4635 if ((lbound1 != 0) || (ubound1 != 1))
4638 SafeArrayGetLBound (safearray, 2, &lbound2);
4639 SafeArrayGetUBound (safearray, 2, &ubound2);
4641 if ((lbound2 != 0) || (ubound2 != 1))
4644 SafeArrayGetLBound (safearray, 3, &lbound3);
4645 SafeArrayGetUBound (safearray, 3, &ubound3);
4647 if ((lbound3 != 0) || (ubound3 != 2))
4650 for (i= lbound1; i <= ubound1; i++) {
4652 for (j= lbound2; j <= ubound2; j++) {
4654 for (k= lbound3; k <= ubound3; k++) {
4656 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4658 failed = ((element.vt != VT_BSTR)
4659 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4660 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4661 VariantClear (&element);
4668 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4673 element.vt = VT_BSTR;
4674 element.bstrVal = SysAllocString(L"Should not be copied");
4675 SafeArrayPutElement (safearray, indices, &element);
4676 VariantClear (&element);
4681 LIBTEST_API int STDCALL
4682 mono_test_marshal_safearray_in_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4684 return mono_test_marshal_safearray_in_byval_3dim_vt_bstr (*safearray);
4687 LIBTEST_API int STDCALL
4688 mono_test_marshal_safearray_in_out_byref_1dim_empty (SAFEARRAY** safearray)
4690 /* Check that the input array is what is expected and change it so the caller can check */
4691 /* correct marshalling back to managed code */
4694 long lbound, ubound;
4695 SAFEARRAYBOUND dimensions [1];
4697 wchar_t buffer [20];
4701 /* Check that in array is one dimensional and empty */
4703 dim = SafeArrayGetDim (*safearray);
4708 SafeArrayGetLBound (*safearray, 1, &lbound);
4709 SafeArrayGetUBound (*safearray, 1, &ubound);
4711 if ((lbound > 0) || (ubound > 0)) {
4715 /* Re-dimension the array and return a one-dimensional array of 8 variants filled with "0" to "7" */
4717 dimensions [0].lLbound = 0;
4718 dimensions [0].cElements = 8;
4720 hr = SafeArrayRedim (*safearray, dimensions);
4724 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
4726 VariantInit (&vOut);
4728 _ltow (i,buffer,10);
4729 vOut.bstrVal = SysAllocString (buffer);
4731 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
4732 VariantClear (&vOut);
4733 SafeArrayDestroy (*safearray);
4736 VariantClear (&vOut);
4741 LIBTEST_API int STDCALL
4742 mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4744 /* Check that the input array is what is expected and change it so the caller can check */
4745 /* correct marshalling back to managed code */
4748 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4749 SAFEARRAYBOUND dimensions [1];
4750 long i, j, k, failed;
4751 wchar_t buffer [20];
4756 VariantInit (&element);
4758 /* Check that in array is three dimensional and contains the expected values */
4760 dim = SafeArrayGetDim (*safearray);
4764 SafeArrayGetLBound (*safearray, 1, &lbound1);
4765 SafeArrayGetUBound (*safearray, 1, &ubound1);
4767 if ((lbound1 != 0) || (ubound1 != 1))
4770 SafeArrayGetLBound (*safearray, 2, &lbound2);
4771 SafeArrayGetUBound (*safearray, 2, &ubound2);
4773 if ((lbound2 != 0) || (ubound2 != 1))
4776 SafeArrayGetLBound (*safearray, 3, &lbound3);
4777 SafeArrayGetUBound (*safearray, 3, &ubound3);
4779 if ((lbound3 != 0) || (ubound3 != 2))
4782 for (i= lbound1; i <= ubound1; i++) {
4784 for (j= lbound2; j <= ubound2; j++) {
4786 for (k= lbound3; k <= ubound3; k++) {
4788 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
4790 failed = ((element.vt != VT_BSTR)
4791 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4792 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4793 VariantClear (&element);
4800 hr = SafeArrayDestroy (*safearray);
4804 /* Return a new one-dimensional array of 8 variants filled with "0" to "7" */
4806 dimensions [0].lLbound = 0;
4807 dimensions [0].cElements = 8;
4809 *safearray = SafeArrayCreate (VT_VARIANT, 1, dimensions);
4811 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
4813 VariantInit (&vOut);
4815 _ltow (i,buffer,10);
4816 vOut.bstrVal = SysAllocString (buffer);
4818 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
4819 VariantClear (&vOut);
4820 SafeArrayDestroy (*safearray);
4823 VariantClear (&vOut);
4828 LIBTEST_API int STDCALL
4829 mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 (SAFEARRAY** safearray)
4831 /* Check that the input array is what is expected and change it so the caller can check */
4832 /* correct marshalling back to managed code */
4835 long lbound1, ubound1;
4841 VariantInit (&element);
4843 /* Check that in array is one dimensional and contains the expected value */
4845 dim = SafeArrayGetDim (*safearray);
4849 SafeArrayGetLBound (*safearray, 1, &lbound1);
4850 SafeArrayGetUBound (*safearray, 1, &ubound1);
4853 if ((lbound1 != 0) || (ubound1 != 1))
4857 for (i= lbound1; i <= ubound1; i++) {
4859 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
4861 failed = (element.vt != VT_I4) || (element.lVal != i+1);
4862 VariantClear (&element);
4867 /* Change one of the elements of the array to verify that [out] parameter is marshalled back to the managed side */
4872 SafeArrayPutElement (*safearray, indices, &element);
4873 VariantClear (&element);
4878 LIBTEST_API int STDCALL
4879 mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (SAFEARRAY* safearray)
4881 /* Check that the input array is what is expected and change it so the caller can check */
4882 /* correct marshalling back to managed code */
4885 long lbound1, ubound1;
4886 SAFEARRAYBOUND dimensions [1];
4892 VariantInit (&element);
4894 /* Check that in array is one dimensional and contains the expected value */
4896 dim = SafeArrayGetDim (safearray);
4900 SafeArrayGetLBound (safearray, 1, &lbound1);
4901 SafeArrayGetUBound (safearray, 1, &ubound1);
4903 if ((lbound1 != 0) || (ubound1 != 0))
4906 for (i= lbound1; i <= ubound1; i++) {
4908 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4910 failed = (element.vt != VT_I4) || (element.lVal != i+1);
4911 VariantClear (&element);
4916 /* Change the array to verify how [out] parameter is marshalled back to the managed side */
4918 /* Redimension the array */
4919 dimensions [0].lLbound = lbound1;
4920 dimensions [0].cElements = 2;
4921 hr = SafeArrayRedim(safearray, dimensions);
4925 element.lVal = 12345;
4926 SafeArrayPutElement (safearray, indices, &element);
4927 VariantClear (&element);
4931 element.lVal = -12345;
4932 SafeArrayPutElement (safearray, indices, &element);
4933 VariantClear (&element);
4938 LIBTEST_API int STDCALL
4939 mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr (SAFEARRAY* safearray)
4941 /* Check that the input array is what is expected and change it so the caller can check */
4942 /* correct marshalling back to managed code */
4945 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4946 long i, j, k, failed;
4951 VariantInit (&element);
4953 /* Check that in array is three dimensional and contains the expected values */
4955 dim = SafeArrayGetDim (safearray);
4959 SafeArrayGetLBound (safearray, 1, &lbound1);
4960 SafeArrayGetUBound (safearray, 1, &ubound1);
4962 if ((lbound1 != 0) || (ubound1 != 1))
4965 SafeArrayGetLBound (safearray, 2, &lbound2);
4966 SafeArrayGetUBound (safearray, 2, &ubound2);
4968 if ((lbound2 != 0) || (ubound2 != 1))
4971 SafeArrayGetLBound (safearray, 3, &lbound3);
4972 SafeArrayGetUBound (safearray, 3, &ubound3);
4974 if ((lbound3 != 0) || (ubound3 != 2))
4977 for (i= lbound1; i <= ubound1; i++) {
4979 for (j= lbound2; j <= ubound2; j++) {
4981 for (k= lbound3; k <= ubound3; k++) {
4983 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4985 failed = ((element.vt != VT_BSTR)
4986 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4987 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4988 VariantClear (&element);
4995 /* Change the elements of the array to verify that [out] parameter is marshalled back to the managed side */
5002 SafeArrayPutElement (safearray, indices, &element);
5003 VariantClear (&element);
5010 SafeArrayPutElement (safearray, indices, &element);
5011 VariantClear (&element);
5016 element.vt = VT_BSTR;
5017 element.bstrVal = marshal_bstr_alloc("ABCDEFG");
5018 SafeArrayPutElement (safearray, indices, &element);
5019 VariantClear (&element);
5024 LIBTEST_API int STDCALL
5025 mono_test_marshal_safearray_mixed(
5026 SAFEARRAY *safearray1,
5027 SAFEARRAY **safearray2,
5028 SAFEARRAY *safearray3,
5029 SAFEARRAY **safearray4
5034 /* Initialize out parameters */
5037 /* array1: Check that in array is one dimensional and contains the expected value */
5038 hr = mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (safearray1);
5040 /* array2: Fill in with some values to check on the managed side */
5042 hr = mono_test_marshal_safearray_out_1dim_vt_bstr (safearray2);
5044 /* array3: Check that in array is one dimensional and contains the expected value */
5046 hr = mono_test_marshal_safearray_in_byval_1dim_vt_mixed(safearray3);
5048 /* array4: Check input values and fill in with some values to check on the managed side */
5050 hr = mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr(safearray4);
5057 static int call_managed_res;
5060 call_managed (gpointer arg)
5062 SimpleDelegate del = arg;
5064 call_managed_res = del (42);
5067 LIBTEST_API int STDCALL
5068 mono_test_marshal_thread_attach (SimpleDelegate del)
5076 res = pthread_create (&t, NULL, (gpointer)call_managed, del);
5077 g_assert (res == 0);
5078 pthread_join (t, NULL);
5080 return call_managed_res;
5084 typedef int (STDCALL *Callback) (void);
5086 static Callback callback;
5088 LIBTEST_API void STDCALL
5089 mono_test_marshal_set_callback (Callback cb)
5094 LIBTEST_API int STDCALL
5095 mono_test_marshal_call_callback (void)
5100 LIBTEST_API int STDCALL
5101 mono_test_marshal_lpstr (char *str)
5103 return strcmp ("ABC", str);
5106 LIBTEST_API int STDCALL
5107 mono_test_marshal_lpwstr (gunichar2 *str)
5112 s = g_utf16_to_utf8 (str, -1, NULL, NULL, NULL);
5113 res = strcmp ("ABC", s);
5119 LIBTEST_API char* STDCALL
5120 mono_test_marshal_return_lpstr (void)
5122 char *res = marshal_alloc (4);
5123 strcpy (res, "XYZ");
5128 LIBTEST_API gunichar2* STDCALL
5129 mono_test_marshal_return_lpwstr (void)
5131 gunichar2 *res = marshal_alloc (8);
5132 gunichar2* tmp = g_utf8_to_utf16 ("XYZ", -1, NULL, NULL, NULL);
5134 memcpy (res, tmp, 8);