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)
36 #elif defined(__GNUC__)
37 #define LIBTEST_API __attribute__ ((visibility ("default")))
42 static void marshal_free (void *ptr)
51 static void* marshal_alloc (gsize size)
54 return CoTaskMemAlloc (size);
56 return g_malloc (size);
60 static void* marshal_alloc0 (gsize size)
63 void* ptr = CoTaskMemAlloc (size);
67 return g_malloc0 (size);
71 static char* marshal_strdup (const char *str)
81 buf = (char *) CoTaskMemAlloc (len + 1);
82 return strcpy (buf, str);
84 return g_strdup (str);
88 static gunichar2* marshal_bstr_alloc(const gchar* str)
91 gunichar2* ret = NULL;
92 gunichar2* temp = NULL;
93 temp = g_utf8_to_utf16 (str, -1, NULL, NULL, NULL);
94 ret = SysAllocString (temp);
99 int slen = strlen (str);
101 /* allocate len + 1 utf16 characters plus 4 byte integer for length*/
102 ret = g_malloc ((slen + 1) * sizeof(gunichar2) + sizeof(guint32));
105 temp = g_utf8_to_utf16 (str, -1, NULL, NULL, NULL);
106 memcpy (ret + sizeof(guint32), temp, slen * sizeof(gunichar2));
107 * ((guint32 *) ret) = slen * sizeof(gunichar2);
108 ret [4 + slen * sizeof(gunichar2)] = 0;
109 ret [5 + slen * sizeof(gunichar2)] = 0;
111 return (gunichar2*)(ret + 4);
115 #define marshal_new0(type,size) ((type *) marshal_alloc0 (sizeof (type)* (size)))
117 LIBTEST_API int STDCALL
118 mono_cominterop_is_supported (void)
120 #if defined(TARGET_X86) || defined(TARGET_AMD64)
126 LIBTEST_API unsigned short* STDCALL
127 test_lpwstr_marshal (unsigned short* chars, long length)
132 res = marshal_alloc (2 * (length + 1));
134 // printf("test_lpwstr_marshal()\n");
136 while ( i < length ) {
137 // printf("X|%u|\n", chars[i]);
148 LIBTEST_API void STDCALL
149 test_lpwstr_marshal_out (unsigned short** chars)
152 const char abc[] = "ABC";
153 glong len = strlen(abc);
155 *chars = marshal_alloc (2 * (len + 1));
158 (*chars) [i] = abc[i];
171 LIBTEST_API int STDCALL
172 mono_union_test_1 (union_test_1_type u1) {
173 // printf ("Got values %d %d %d\n", u1.b, u1.a, u1.c);
174 return u1.a + u1.b + u1.c;
177 LIBTEST_API int STDCALL
178 mono_return_int (int a) {
179 // printf ("Got value %d\n", a);
183 LIBTEST_API float STDCALL
184 mono_test_marshal_pass_return_float (float f) {
193 LIBTEST_API int STDCALL
194 mono_return_int_ss (struct ss a) {
195 // printf ("Got value %d\n", a.i);
199 LIBTEST_API struct ss STDCALL
200 mono_return_ss (struct ss a) {
201 // printf ("Got value %d\n", a.i);
211 LIBTEST_API struct sc1 STDCALL
212 mono_return_sc1 (struct sc1 a) {
213 // printf ("Got value %d\n", a.c[0]);
224 LIBTEST_API struct sc3 STDCALL
225 mono_return_sc3 (struct sc3 a) {
226 // printf ("Got values %d %d %d\n", a.c[0], a.c[1], a.c[2]);
238 LIBTEST_API struct sc5 STDCALL
239 mono_return_sc5 (struct sc5 a) {
240 // printf ("Got values %d %d %d %d %d\n", a.c[0], a.c[1], a.c[2], a.c[3], a.c[4]);
255 LIBTEST_API int STDCALL
256 mono_return_int_su (union su a) {
257 // printf ("Got value %d\n", a.i1);
272 LIBTEST_API struct NestedFloat STDCALL
273 mono_return_nested_float (void)
275 struct NestedFloat f;
283 LIBTEST_API int STDCALL
284 mono_test_many_int_arguments (int a, int b, int c, int d, int e,
285 int f, int g, int h, int i, int j);
286 LIBTEST_API short STDCALL
287 mono_test_many_short_arguments (short a, short b, short c, short d, short e,
288 short f, short g, short h, short i, short j);
289 LIBTEST_API char STDCALL
290 mono_test_many_char_arguments (char a, char b, char c, char d, char e,
291 char f, char g, char h, char i, char j);
293 LIBTEST_API int STDCALL
294 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)
296 return a + b + c + d + e + f + g + h + i + j;
299 LIBTEST_API short STDCALL
300 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)
302 return a + b + c + d + e + f + g + h + i + j;
305 LIBTEST_API char STDCALL
306 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)
308 return a + b + c + d + e + f + g + h + i + j;
311 LIBTEST_API float STDCALL
312 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)
314 return a + b + c + d + e + f + g + h + i + j;
317 LIBTEST_API double STDCALL
318 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)
320 return a + b + c + d + e + f + g + h + i + j;
323 LIBTEST_API double STDCALL
324 mono_test_split_double_arguments (double a, double b, float c, double d, double e)
326 return a + b + c + d + e;
329 LIBTEST_API int STDCALL
330 mono_test_puts_static (char *s)
332 // printf ("TEST %s\n", s);
336 typedef int (STDCALL *SimpleDelegate3) (int a, int b);
338 LIBTEST_API int STDCALL
339 mono_invoke_delegate (SimpleDelegate3 delegate)
343 // printf ("start invoke %p\n", delegate);
345 res = delegate (2, 3);
347 // printf ("end invoke\n");
352 LIBTEST_API int STDCALL
353 mono_invoke_simple_delegate (SimpleDelegate d)
358 LIBTEST_API int STDCALL
359 mono_test_marshal_char (short a1)
367 LIBTEST_API void STDCALL
368 mono_test_marshal_char_array (gunichar2 *s)
370 const char m[] = "abcdef";
374 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
382 LIBTEST_API int STDCALL
383 mono_test_marshal_ansi_char_array (char *s)
385 const char m[] = "abcdef";
387 if (strncmp ("qwer", s, 4))
390 memcpy (s, m, sizeof (m));
394 LIBTEST_API int STDCALL
395 mono_test_marshal_unicode_char_array (gunichar2 *s)
397 const char m[] = "abcdef";
398 const char expected[] = "qwer";
402 s1 = g_utf8_to_utf16 (m, -1, NULL, &len1, NULL);
403 s2 = g_utf8_to_utf16 (expected, -1, NULL, &len2, NULL);
407 if (memcmp (s, s2, len2))
410 memcpy (s, s1, len1);
414 LIBTEST_API int STDCALL
415 mono_test_empty_pinvoke (int i)
420 LIBTEST_API int STDCALL
421 mono_test_marshal_bool_byref (int a, int *b, int c)
430 LIBTEST_API int STDCALL
431 mono_test_marshal_bool_in_as_I1_U1 (char bTrue, char bFalse)
440 LIBTEST_API int STDCALL
441 mono_test_marshal_bool_out_as_I1_U1 (char* bTrue, char* bFalse)
443 if (!bTrue || !bFalse)
452 LIBTEST_API int STDCALL
453 mono_test_marshal_bool_ref_as_I1_U1 (char* bTrue, char* bFalse)
455 if (!bTrue || !bFalse)
469 LIBTEST_API int STDCALL
470 mono_test_marshal_array (int *a1)
474 for (i = 0; i < 50; i++)
480 LIBTEST_API int STDCALL
481 mono_test_marshal_inout_array (int *a1)
485 for (i = 0; i < 50; i++) {
487 a1 [i] = 50 - a1 [i];
493 LIBTEST_API int /* cdecl */
494 mono_test_marshal_inout_array_cdecl (int *a1)
496 return mono_test_marshal_inout_array (a1);
499 LIBTEST_API int STDCALL
500 mono_test_marshal_out_array (int *a1)
504 for (i = 0; i < 50; i++) {
511 LIBTEST_API int STDCALL
512 mono_test_marshal_out_byref_array_out_size_param (int **out_arr, int *out_len)
518 arr = marshal_alloc (sizeof (gint32) * len);
519 for (i = 0; i < len; ++i)
527 LIBTEST_API int STDCALL
528 mono_test_marshal_inout_nonblittable_array (gunichar2 *a1)
532 for (i = 0; i < 10; i++) {
552 LIBTEST_API simplestruct STDCALL
553 mono_test_return_vtype (int i)
556 static gunichar2 test2 [] = { 'T', 'E', 'S', 'T', '2', 0 };
567 LIBTEST_API void STDCALL
568 mono_test_delegate_struct (void)
570 // printf ("TEST\n");
573 typedef char* (STDCALL *ReturnStringDelegate) (const char *s);
575 LIBTEST_API char * STDCALL
576 mono_test_return_string (ReturnStringDelegate func)
580 // printf ("mono_test_return_string\n");
585 // printf ("got string: %s\n", res);
586 return marshal_strdup ("12345");
589 typedef int (STDCALL *RefVTypeDelegate) (int a, simplestruct *ss, int b);
591 LIBTEST_API int STDCALL
592 mono_test_ref_vtype (int a, simplestruct *ss, int b, RefVTypeDelegate func)
594 if (a == 1 && b == 2 && ss->a == 0 && ss->b == 1 && ss->c == 0 &&
595 !strcmp (ss->d, "TEST1")) {
601 return func (a, ss, b);
607 typedef int (STDCALL *OutVTypeDelegate) (int a, simplestruct *ss, int b);
609 LIBTEST_API int STDCALL
610 mono_test_marshal_out_struct (int a, simplestruct *ss, int b, OutVTypeDelegate func)
612 /* Check that the input pointer is ignored */
613 ss->d = (gpointer)0x12345678;
617 if (ss->a && ss->b && ss->c && !strcmp (ss->d, "TEST3"))
623 typedef int (STDCALL *InVTypeDelegate) (int a, simplestruct *ss, int b);
625 LIBTEST_API int STDCALL
626 mono_test_marshal_in_struct (int a, simplestruct *ss, int b, InVTypeDelegate func)
631 memcpy (&ss2, ss, sizeof (simplestruct));
633 res = func (a, ss, b);
635 printf ("mono_test_marshal_in_struct () failed: %d\n", res);
639 /* Check that no modifications is made to the struct */
640 if (ss2.a == ss->a && ss2.b == ss->b && ss2.c == ss->c && ss2.d == ss->d)
648 SimpleDelegate func, func2, func3;
651 LIBTEST_API DelegateStruct STDCALL
652 mono_test_marshal_delegate_struct (DelegateStruct ds)
656 res.a = ds.func (ds.a) + ds.func2 (ds.a) + (ds.func3 == NULL ? 0 : 1);
658 res.func2 = ds.func2;
664 LIBTEST_API int STDCALL
665 mono_test_marshal_struct (simplestruct ss)
667 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
668 !strcmp (ss.d, "TEST"))
674 LIBTEST_API int STDCALL
675 mono_test_marshal_byref_struct (simplestruct *ss, int a, int b, int c, char *d)
677 gboolean res = (ss->a == a && ss->b == b && ss->c == c && strcmp (ss->d, d) == 0);
679 marshal_free ((char*)ss->d);
684 ss->d = marshal_strdup ("DEF");
700 LIBTEST_API int STDCALL
701 mono_test_marshal_struct2 (simplestruct2 ss)
703 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
704 !strcmp (ss.d, "TEST") &&
705 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
711 /* on HP some of the struct should be on the stack and not in registers */
712 LIBTEST_API int STDCALL
713 mono_test_marshal_struct2_2 (int i, int j, int k, simplestruct2 ss)
715 if (i != 10 || j != 11 || k != 12)
717 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
718 !strcmp (ss.d, "TEST") &&
719 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
725 LIBTEST_API int STDCALL
726 mono_test_marshal_lpstruct (simplestruct *ss)
728 if (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
729 !strcmp (ss->d, "TEST"))
735 LIBTEST_API int STDCALL
736 mono_test_marshal_lpstruct_blittable (point *p)
738 if (p->x == 1.0 && p->y == 2.0)
744 LIBTEST_API int STDCALL
745 mono_test_marshal_struct_array (simplestruct2 *ss)
747 if (! (ss[0].a == 0 && ss[0].b == 1 && ss[0].c == 0 &&
748 !strcmp (ss[0].d, "TEST") &&
749 ss[0].e == 99 && ss[0].f == 1.5 && ss[0].g == 42 && ss[0].h == (guint64)123))
752 if (! (ss[1].a == 0 && ss[1].b == 0 && ss[1].c == 0 &&
753 !strcmp (ss[1].d, "TEST2") &&
754 ss[1].e == 100 && ss[1].f == 2.5 && ss[1].g == 43 && ss[1].h == (guint64)124))
760 typedef struct long_align_struct {
766 LIBTEST_API int STDCALL
767 mono_test_marshal_long_align_struct_array (long_align_struct *ss)
769 return ss[0].a + ss[0].b + ss[0].c + ss[1].a + ss[1].b + ss[1].c;
772 LIBTEST_API simplestruct2 * STDCALL
773 mono_test_marshal_class (int i, int j, int k, simplestruct2 *ss, int l)
780 if (i != 10 || j != 11 || k != 12 || l != 14)
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");
793 LIBTEST_API int STDCALL
794 mono_test_marshal_byref_class (simplestruct2 **ssp)
796 simplestruct2 *ss = *ssp;
799 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
800 !strcmp (ss->d, "TEST") &&
801 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
804 res = marshal_new0 (simplestruct2, 1);
805 memcpy (res, ss, sizeof (simplestruct2));
806 res->d = marshal_strdup ("TEST-RES");
818 /* Yes, this is correct, we are only trying to determine the value of the stack here */
823 LIBTEST_API int STDCALL
824 reliable_delegate (int a)
830 * Checks whether get_sp() works as expected. It doesn't work with gcc-2.95.3 on linux.
833 is_get_sp_reliable (void)
837 reliable_delegate(1);
839 reliable_delegate(1);
844 LIBTEST_API int STDCALL
845 mono_test_marshal_delegate (SimpleDelegate delegate)
849 /* Check that the delegate wrapper is stdcall */
854 if (is_get_sp_reliable())
855 g_assert (sp1 == sp2);
860 static int STDCALL inc_cb (int i)
865 LIBTEST_API int STDCALL
866 mono_test_marshal_out_delegate (SimpleDelegate *delegate)
873 LIBTEST_API SimpleDelegate STDCALL
874 mono_test_marshal_return_delegate (SimpleDelegate delegate)
880 return_plus_one (int i)
885 LIBTEST_API SimpleDelegate STDCALL
886 mono_test_marshal_return_delegate_2 (void)
888 return return_plus_one;
891 typedef simplestruct (STDCALL *SimpleDelegate2) (simplestruct ss);
894 is_utf16_equals (gunichar2 *s1, const char *s2)
899 s = g_utf16_to_utf8 (s1, -1, NULL, NULL, NULL);
900 res = strcmp (s, s2);
906 LIBTEST_API int STDCALL
907 mono_test_marshal_delegate2 (SimpleDelegate2 delegate)
909 simplestruct ss, res;
915 ss.d2 = g_utf8_to_utf16 ("TEST2", -1, NULL, NULL, NULL);
918 if (! (res.a && !res.b && res.c && !strcmp (res.d, "TEST-RES") && is_utf16_equals (res.d2, "TEST2-RES")))
924 typedef simplestruct* (STDCALL *SimpleDelegate4) (simplestruct *ss);
926 LIBTEST_API int STDCALL
927 mono_test_marshal_delegate4 (SimpleDelegate4 delegate)
938 res = delegate (&ss);
942 /* Check return value */
943 if (! (!res->a && res->b && !res->c && !strcmp (res->d, "TEST")))
946 /* Check NULL argument and NULL result */
947 res = delegate (NULL);
954 typedef int (STDCALL *SimpleDelegate5) (simplestruct **ss);
956 LIBTEST_API int STDCALL
957 mono_test_marshal_delegate5 (SimpleDelegate5 delegate)
970 res = delegate (&ptr);
974 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
980 LIBTEST_API int STDCALL
981 mono_test_marshal_delegate6 (SimpleDelegate5 delegate)
985 res = delegate (NULL);
990 typedef int (STDCALL *SimpleDelegate7) (simplestruct **ss);
992 LIBTEST_API int STDCALL
993 mono_test_marshal_delegate7 (SimpleDelegate7 delegate)
998 /* Check that the input pointer is ignored */
999 ptr = (gpointer)0x12345678;
1001 res = delegate (&ptr);
1005 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
1011 typedef int (STDCALL *InOutByvalClassDelegate) (simplestruct *ss);
1013 LIBTEST_API int STDCALL
1014 mono_test_marshal_inout_byval_class_delegate (InOutByvalClassDelegate delegate)
1022 ss.d = g_strdup_printf ("%s", "FOO");
1024 res = delegate (&ss);
1028 if (!(ss.a && !ss.b && ss.c && !strcmp (ss.d, "RES")))
1034 typedef int (STDCALL *SimpleDelegate8) (gunichar2 *s);
1036 LIBTEST_API int STDCALL
1037 mono_test_marshal_delegate8 (SimpleDelegate8 delegate, gunichar2 *s)
1039 return delegate (s);
1042 typedef int (STDCALL *return_int_fnt) (int i);
1043 typedef int (STDCALL *SimpleDelegate9) (return_int_fnt d);
1045 LIBTEST_API int STDCALL
1046 mono_test_marshal_delegate9 (SimpleDelegate9 delegate, gpointer ftn)
1048 return delegate (ftn);
1057 LIBTEST_API int STDCALL
1058 mono_test_marshal_delegate10 (SimpleDelegate9 delegate)
1060 return delegate (return_self);
1063 typedef int (STDCALL *PrimitiveByrefDelegate) (int *i);
1065 LIBTEST_API int STDCALL
1066 mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate delegate)
1070 int res = delegate (&i);
1080 typedef int (STDCALL *return_int_delegate) (int i);
1082 typedef return_int_delegate (STDCALL *ReturnDelegateDelegate) (void);
1084 LIBTEST_API int STDCALL
1085 mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d)
1090 LIBTEST_API int STDCALL
1091 mono_test_marshal_stringbuilder (char *s, int n)
1093 const char m[] = "This is my message. Isn't it nice?";
1095 if (strcmp (s, "ABCD") != 0)
1102 LIBTEST_API int STDCALL
1103 mono_test_marshal_stringbuilder2 (char *s, int n)
1105 const char m[] = "EFGH";
1112 LIBTEST_API int STDCALL
1113 mono_test_marshal_stringbuilder_default (char *s, int n)
1115 const char m[] = "This is my message. Isn't it nice?";
1122 LIBTEST_API int STDCALL
1123 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
1125 const char m[] = "This is my message. Isn't it nice?";
1129 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1131 len = (len * 2) + 2;
1134 memcpy (s, s2, len);
1141 LIBTEST_API void STDCALL
1142 mono_test_marshal_stringbuilder_out (char **s)
1144 const char m[] = "This is my message. Isn't it nice?";
1147 str = marshal_alloc (strlen (m) + 1);
1148 memcpy (str, m, strlen (m) + 1);
1153 LIBTEST_API int STDCALL
1154 mono_test_marshal_stringbuilder_out_unicode (gunichar2 **s)
1156 const char m[] = "This is my message. Isn't it nice?";
1160 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1162 len = (len * 2) + 2;
1163 *s = marshal_alloc (len);
1164 memcpy (*s, s2, len);
1171 LIBTEST_API int STDCALL
1172 mono_test_marshal_stringbuilder_ref (char **s)
1174 const char m[] = "This is my message. Isn't it nice?";
1177 if (strcmp (*s, "ABC"))
1180 str = marshal_alloc (strlen (m) + 1);
1181 memcpy (str, m, strlen (m) + 1);
1193 LIBTEST_API int STDCALL
1194 mono_test_marshal_empty_string_array (char **array)
1196 return (array == NULL) ? 0 : 1;
1199 LIBTEST_API int STDCALL
1200 mono_test_marshal_string_array (char **array)
1202 if (strcmp (array [0], "ABC"))
1204 if (strcmp (array [1], "DEF"))
1207 if (array [2] != NULL)
1213 LIBTEST_API int STDCALL
1214 mono_test_marshal_byref_string_array (char ***array)
1219 if (strcmp ((*array) [0], "Alpha"))
1221 if (strcmp ((*array) [1], "Beta"))
1223 if (strcmp ((*array) [2], "Gamma"))
1229 LIBTEST_API int STDCALL
1230 mono_test_marshal_stringbuilder_array (char **array)
1232 if (strcmp (array [0], "ABC"))
1234 if (strcmp (array [1], "DEF"))
1237 strcpy (array [0], "DEF");
1238 strcpy (array [1], "ABC");
1243 LIBTEST_API int STDCALL
1244 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
1246 GError *error = NULL;
1249 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
1250 if (strcmp (s, "ABC")) {
1257 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
1258 if (strcmp (s, "DEF")) {
1265 if (strcmp (array2 [0], "ABC"))
1268 if (strcmp (array2 [1], "DEF"))
1274 /* this does not work on Redhat gcc 2.96 */
1275 LIBTEST_API int STDCALL
1276 mono_test_empty_struct (int a, EmptyStruct es, int b)
1278 // printf ("mono_test_empty_struct %d %d\n", a, b);
1280 // Intel icc on ia64 passes 'es' in 2 registers
1281 #if defined(__ia64) && defined(__INTEL_COMPILER)
1284 if (a == 1 && b == 2)
1294 LIBTEST_API ByValStrStruct * STDCALL
1295 mono_test_byvalstr_gen (void)
1297 ByValStrStruct *ret;
1299 ret = malloc(sizeof(ByValStrStruct));
1300 memset(ret, 'a', sizeof(ByValStrStruct)-1);
1301 ret->a[sizeof(ByValStrStruct)-1] = 0;
1306 LIBTEST_API int STDCALL
1307 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
1311 ret = strcmp(data->a, correctString);
1312 // printf ("T1: %s\n", data->a);
1313 // printf ("T2: %s\n", correctString);
1315 /* we need g_free because the allocation was performed by mono_test_byvalstr_gen */
1323 } ByValStrStruct_Unicode;
1325 LIBTEST_API int STDCALL
1326 mono_test_byvalstr_check_unicode (ByValStrStruct_Unicode *ref, int test)
1328 if (ref->flag != 0x1234abcd){
1329 printf ("overwritten data");
1333 if (test == 1 || test == 3){
1334 if (ref->a [0] != '1' ||
1335 ref->a [1] != '2' ||
1341 if (ref->a [0] != '1' ||
1349 LIBTEST_API int STDCALL
1350 NameManglingAnsi (char *data)
1352 return data [0] + data [1] + data [2];
1355 LIBTEST_API int STDCALL
1356 NameManglingAnsiA (char *data)
1358 g_assert_not_reached ();
1361 LIBTEST_API int STDCALL
1362 NameManglingAnsiW (char *data)
1364 g_assert_not_reached ();
1367 LIBTEST_API int STDCALL
1368 NameManglingAnsi2A (char *data)
1370 return data [0] + data [1] + data [2];
1373 LIBTEST_API int STDCALL
1374 NameManglingAnsi2W (char *data)
1376 g_assert_not_reached ();
1379 LIBTEST_API int STDCALL
1380 NameManglingUnicode (char *data)
1382 g_assert_not_reached ();
1385 LIBTEST_API int STDCALL
1386 NameManglingUnicodeW (gunichar2 *data)
1388 return data [0] + data [1] + data [2];
1391 LIBTEST_API int STDCALL
1392 NameManglingUnicode2 (gunichar2 *data)
1394 return data [0] + data [1] + data [2];
1397 LIBTEST_API int STDCALL
1398 NameManglingAutoW (char *data)
1401 return (data [0] + data [1] + data [2]) == 131 ? 0 : 1;
1403 g_assert_not_reached ();
1407 LIBTEST_API int STDCALL
1408 NameManglingAuto (char *data)
1411 return (data [0] + data [1] + data [2]) == 198 ? 0 : 1;
1413 g_assert_not_reached ();
1417 typedef int (STDCALL *intcharFunc)(const char*);
1419 LIBTEST_API void STDCALL
1420 callFunction (intcharFunc f)
1430 LIBTEST_API int STDCALL
1431 class_marshal_test0 (SimpleObj *obj1)
1433 // printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
1435 if (strcmp(obj1->str, "T1"))
1443 LIBTEST_API int STDCALL
1444 class_marshal_test4 (SimpleObj *obj1)
1452 LIBTEST_API void STDCALL
1453 class_marshal_test1 (SimpleObj **obj1)
1455 SimpleObj *res = malloc (sizeof (SimpleObj));
1457 res->str = marshal_strdup ("ABC");
1463 LIBTEST_API int STDCALL
1464 class_marshal_test2 (SimpleObj **obj1)
1466 // printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
1468 if (strcmp((*obj1)->str, "ABC"))
1470 if ((*obj1)->i != 5)
1476 LIBTEST_API int STDCALL
1477 string_marshal_test0 (char *str)
1479 if (strcmp (str, "TEST0"))
1485 LIBTEST_API void STDCALL
1486 string_marshal_test1 (const char **str)
1488 *str = marshal_strdup ("TEST1");
1491 LIBTEST_API int STDCALL
1492 string_marshal_test2 (char **str)
1494 // printf ("string_marshal_test2 %s\n", *str);
1496 if (strcmp (*str, "TEST1"))
1499 *str = marshal_strdup ("TEST2");
1504 LIBTEST_API int STDCALL
1505 string_marshal_test3 (char *str)
1518 LIBTEST_API BlittableClass* STDCALL
1519 TestBlittableClass (BlittableClass *vl)
1521 BlittableClass *res;
1523 // printf ("TestBlittableClass %d %d\n", vl->a, vl->b);
1529 res = marshal_new0 (BlittableClass, 1);
1530 memcpy (res, vl, sizeof (BlittableClass));
1532 res = marshal_new0 (BlittableClass, 1);
1540 typedef struct OSVERSIONINFO_STRUCT
1544 } OSVERSIONINFO_STRUCT;
1546 LIBTEST_API int STDCALL
1547 MyGetVersionEx (OSVERSIONINFO_STRUCT *osvi)
1550 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1555 return osvi->a + osvi->b;
1558 LIBTEST_API int STDCALL
1559 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO_STRUCT *osvi)
1562 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1567 return osvi->a + osvi->b;
1570 LIBTEST_API int STDCALL
1571 mono_test_marshal_point (point pt)
1573 // printf("point %g %g\n", pt.x, pt.y);
1574 if (pt.x == 1.25 && pt.y == 3.5)
1585 LIBTEST_API int STDCALL
1586 mono_test_marshal_mixed_point (mixed_point pt)
1588 // printf("mixed point %d %g\n", pt.x, pt.y);
1589 if (pt.x == 5 && pt.y == 6.75)
1595 LIBTEST_API int STDCALL
1596 mono_test_marshal_mixed_point_2 (mixed_point *pt)
1598 if (pt->x != 5 || pt->y != 6.75)
1607 LIBTEST_API int STDCALL
1608 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
1611 if (*b1 != 0 && *b1 != 1)
1613 if (*b2 != 0 && *b2 != -1) /* variant_bool */
1615 if (*b3 != 0 && *b3 != 1)
1617 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
1629 short b2; /* variant_bool */
1633 LIBTEST_API int STDCALL
1634 marshal_test_bool_struct(struct BoolStruct *s)
1637 if (s->b1 != 0 && s->b1 != 1)
1639 if (s->b2 != 0 && s->b2 != -1)
1641 if (s->b3 != 0 && s->b3 != 1)
1643 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1660 LIBTEST_API int STDCALL
1661 mono_test_marshal_long_struct (LongStruct *s)
1663 return s->i + s->l.l;
1666 LIBTEST_API void STDCALL
1667 mono_test_last_error (int err)
1676 LIBTEST_API int STDCALL
1677 mono_test_asany (void *ptr, int what)
1681 return (*(int*)ptr == 5) ? 0 : 1;
1683 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1685 simplestruct2 ss = *(simplestruct2*)ptr;
1687 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1688 !strcmp (ss.d, "TEST") &&
1689 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1695 GError *error = NULL;
1698 s = g_utf16_to_utf8 (ptr, -1, NULL, NULL, &error);
1703 if (!strcmp (s, "ABC")) {
1713 g_assert_not_reached ();
1727 LIBTEST_API int STDCALL
1728 mono_test_marshal_asany_in (void* ptr)
1730 AsAnyStruct* asAny = ptr;
1731 int res = asAny->i + asAny->j + asAny->k;
1736 LIBTEST_API int STDCALL
1737 mono_test_marshal_asany_inout (void* ptr)
1739 AsAnyStruct* asAny = ptr;
1740 int res = asAny->i + asAny->j + asAny->k;
1742 marshal_free (asAny->s);
1752 LIBTEST_API int STDCALL
1753 mono_test_marshal_asany_out (void* ptr)
1755 AsAnyStruct* asAny = ptr;
1756 int res = asAny->i + asAny->j + asAny->k;
1767 * AMD64 marshalling tests.
1770 typedef struct amd64_struct1 {
1777 LIBTEST_API amd64_struct1 STDCALL
1778 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
1788 LIBTEST_API amd64_struct1 STDCALL
1789 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)
1794 s.l += 1 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8;
1799 typedef struct amd64_struct2 {
1804 LIBTEST_API amd64_struct2 STDCALL
1805 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
1813 typedef struct amd64_struct3 {
1817 LIBTEST_API amd64_struct3 STDCALL
1818 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s)
1825 typedef struct amd64_struct4 {
1829 LIBTEST_API amd64_struct4 STDCALL
1830 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s)
1839 * IA64 marshalling tests.
1841 typedef struct test_struct5 {
1845 LIBTEST_API test_struct5 STDCALL
1846 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, test_struct5 s, int i, double d3, double d4)
1848 s.d1 += d1 + d2 + i;
1849 s.d2 += d3 + d4 + i;
1854 typedef struct test_struct6 {
1858 LIBTEST_API test_struct6 STDCALL
1859 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, test_struct6 s, int i, double d3, double d4)
1861 s.d1 += d1 + d2 + i;
1867 static guint32 custom_res [2];
1869 LIBTEST_API void* STDCALL
1870 mono_test_marshal_pass_return_custom (int i, guint32 *ptr, int j)
1872 /* ptr will be freed by CleanupNative, so make a copy */
1873 custom_res [0] = 0; /* not allocated by AllocHGlobal */
1874 custom_res [1] = ptr [1];
1879 LIBTEST_API int STDCALL
1880 mono_test_marshal_pass_out_custom (int i, guint32 **ptr, int j)
1883 custom_res [1] = i + j + 10;
1890 LIBTEST_API int STDCALL
1891 mono_test_marshal_pass_inout_custom (int i, guint32 *ptr, int j)
1894 ptr [1] = i + ptr [1] + j;
1899 LIBTEST_API int STDCALL
1900 mono_test_marshal_pass_out_byval_custom (int i, guint32 *ptr, int j)
1902 return ptr == NULL ? 0 : 1;
1905 LIBTEST_API int STDCALL
1906 mono_test_marshal_pass_byref_custom (int i, guint32 **ptr, int j)
1913 LIBTEST_API void* STDCALL
1914 mono_test_marshal_pass_return_custom2 (int i, guint32 *ptr, int j)
1916 g_assert_not_reached ();
1921 LIBTEST_API void* STDCALL
1922 mono_test_marshal_pass_return_custom_null (int i, guint32 *ptr, int j)
1924 g_assert (ptr == NULL);
1929 typedef void *(STDCALL *PassReturnPtrDelegate) (void *ptr);
1931 LIBTEST_API int STDCALL
1932 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del)
1946 /* FIXME: Freed with FreeHGlobal */
1954 LIBTEST_API int STDCALL
1955 mono_test_marshal_pass_return_custom_null_in_delegate (PassReturnPtrDelegate del)
1957 void *ptr = del (NULL);
1959 return (ptr == NULL) ? 15 : 0;
1962 typedef void (STDCALL *CustomOutParamDelegate) (void **pptr);
1964 LIBTEST_API int STDCALL
1965 mono_test_marshal_custom_out_param_delegate (CustomOutParamDelegate del)
1977 typedef int (STDCALL *ReturnEnumDelegate) (int e);
1979 LIBTEST_API int STDCALL
1980 mono_test_marshal_return_enum_delegate (ReturnEnumDelegate func)
1990 typedef BlittableStruct (STDCALL *SimpleDelegate10) (BlittableStruct ss);
1992 LIBTEST_API int STDCALL
1993 mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 delegate)
1995 BlittableStruct ss, res;
2002 res = delegate (ss);
2003 if (! ((res.a == -1) && (res.b == -2) && (res.c == -3) && (res.d == -55)))
2009 LIBTEST_API int STDCALL
2010 mono_test_stdcall_name_mangling (int a, int b, int c)
2016 mono_test_stdcall_mismatch_1 (int a, int b, int c)
2021 LIBTEST_API int STDCALL
2022 mono_test_stdcall_mismatch_2 (int a, int b, int c)
2028 * PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
2035 typedef SmallStruct1 (STDCALL *SmallStructDelegate1) (SmallStruct1 ss);
2037 LIBTEST_API int STDCALL
2038 mono_test_marshal_small_struct_delegate1 (SmallStructDelegate1 delegate)
2040 SmallStruct1 ss, res;
2044 res = delegate (ss);
2045 if (! (res.i == -1))
2055 typedef SmallStruct2 (STDCALL *SmallStructDelegate2) (SmallStruct2 ss);
2057 LIBTEST_API int STDCALL
2058 mono_test_marshal_small_struct_delegate2 (SmallStructDelegate2 delegate)
2060 SmallStruct2 ss, res;
2065 res = delegate (ss);
2066 if (! ((res.i == -2) && (res.j == -3)))
2077 typedef SmallStruct3 (STDCALL *SmallStructDelegate3) (SmallStruct3 ss);
2079 LIBTEST_API int STDCALL
2080 mono_test_marshal_small_struct_delegate3 (SmallStructDelegate3 delegate)
2082 SmallStruct3 ss, res;
2087 res = delegate (ss);
2088 if (! ((res.i == -1) && (res.j == -2)))
2098 typedef SmallStruct4 (STDCALL *SmallStructDelegate4) (SmallStruct4 ss);
2100 LIBTEST_API int STDCALL
2101 mono_test_marshal_small_struct_delegate4 (SmallStructDelegate4 delegate)
2103 SmallStruct4 ss, res;
2107 res = delegate (ss);
2108 if (! (res.i == -1))
2118 typedef SmallStruct5 (STDCALL *SmallStructDelegate5) (SmallStruct5 ss);
2120 LIBTEST_API int STDCALL
2121 mono_test_marshal_small_struct_delegate5 (SmallStructDelegate5 delegate)
2123 SmallStruct5 ss, res;
2127 res = delegate (ss);
2128 if (! (res.i == -5))
2138 typedef SmallStruct6 (STDCALL *SmallStructDelegate6) (SmallStruct6 ss);
2140 LIBTEST_API int STDCALL
2141 mono_test_marshal_small_struct_delegate6 (SmallStructDelegate6 delegate)
2143 SmallStruct6 ss, res;
2148 res = delegate (ss);
2149 if (! ((res.i == -1) && (res.j == -2)))
2160 typedef SmallStruct7 (STDCALL *SmallStructDelegate7) (SmallStruct7 ss);
2162 LIBTEST_API int STDCALL
2163 mono_test_marshal_small_struct_delegate7 (SmallStructDelegate7 delegate)
2165 SmallStruct7 ss, res;
2170 res = delegate (ss);
2171 if (! ((res.i == -1) && (res.j == -2)))
2181 typedef SmallStruct8 (STDCALL *SmallStructDelegate8) (SmallStruct8 ss);
2183 LIBTEST_API int STDCALL
2184 mono_test_marshal_small_struct_delegate8 (SmallStructDelegate8 delegate)
2186 SmallStruct8 ss, res;
2190 res = delegate (ss);
2191 if (! ((res.i == -1.0)))
2201 typedef SmallStruct9 (STDCALL *SmallStructDelegate9) (SmallStruct9 ss);
2203 LIBTEST_API int STDCALL
2204 mono_test_marshal_small_struct_delegate9 (SmallStructDelegate9 delegate)
2206 SmallStruct9 ss, res;
2210 res = delegate (ss);
2211 if (! ((res.i == -1.0)))
2221 typedef SmallStruct10 (STDCALL *SmallStructDelegate10) (SmallStruct10 ss);
2223 LIBTEST_API int STDCALL
2224 mono_test_marshal_small_struct_delegate10 (SmallStructDelegate10 delegate)
2226 SmallStruct10 ss, res;
2231 res = delegate (ss);
2232 if (! ((res.i == -1.0) && (res.j == -2.0)))
2243 typedef SmallStruct11 (STDCALL *SmallStructDelegate11) (SmallStruct11 ss);
2245 LIBTEST_API int STDCALL
2246 mono_test_marshal_small_struct_delegate11 (SmallStructDelegate11 delegate)
2248 SmallStruct11 ss, res;
2253 res = delegate (ss);
2254 if (! ((res.i == -1.0) && (res.j == -2)))
2260 typedef int (STDCALL *ArrayDelegate) (int i, char *j, void *arr);
2262 LIBTEST_API int STDCALL
2263 mono_test_marshal_array_delegate (void *arr, int len, ArrayDelegate del)
2265 return del (len, NULL, arr);
2268 typedef int (STDCALL *ArrayDelegateLong) (gint64 i, char *j, void *arr);
2270 LIBTEST_API int STDCALL
2271 mono_test_marshal_array_delegate_long (void *arr, gint64 len, ArrayDelegateLong del)
2273 return del (len, NULL, arr);
2276 LIBTEST_API int STDCALL
2277 mono_test_marshal_out_array_delegate (int *arr, int len, ArrayDelegate del)
2279 del (len, NULL, arr);
2281 if ((arr [0] != 1) || (arr [1] != 2))
2287 typedef gunichar2* (STDCALL *UnicodeStringDelegate) (gunichar2 *message);
2289 LIBTEST_API int STDCALL
2290 mono_test_marshal_return_unicode_string_delegate (UnicodeStringDelegate del)
2292 const char m[] = "abcdef";
2293 gunichar2 *s2, *res;
2296 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
2305 LIBTEST_API int STDCALL
2306 mono_test_marshal_out_string_array_delegate (char **arr, int len, ArrayDelegate del)
2308 del (len, NULL, arr);
2310 if (!strcmp (arr [0], "ABC") && !strcmp (arr [1], "DEF"))
2316 typedef int (*CdeclDelegate) (int i, int j);
2318 LIBTEST_API int STDCALL
2319 mono_test_marshal_cdecl_delegate (CdeclDelegate del)
2323 for (i = 0; i < 1000; ++i)
2329 typedef char** (STDCALL *ReturnStringArrayDelegate) (int i);
2331 LIBTEST_API int STDCALL
2332 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d)
2340 if (strcmp (arr [0], "ABC") || strcmp (arr [1], "DEF"))
2350 typedef int (STDCALL *ByrefStringDelegate) (char **s);
2352 LIBTEST_API int STDCALL
2353 mono_test_marshal_byref_string_delegate (ByrefStringDelegate d)
2355 char *s = (char*)"ABC";
2362 if (!strcmp (s, "DEF"))
2372 LIBTEST_API int STDCALL
2373 add_delegate (int i, int j)
2378 LIBTEST_API gpointer STDCALL
2379 mono_test_marshal_return_fnptr (void)
2381 return &add_delegate;
2384 LIBTEST_API int STDCALL
2387 printf ("codigo %x\n", code);
2395 LIBTEST_API HandleRef STDCALL
2396 mono_xr_as_handle (int code)
2400 memset (&ref, 0, sizeof (ref));
2412 LIBTEST_API int STDCALL
2413 mono_safe_handle_struct_ref (HandleStructs *x)
2415 printf ("Dingus Ref! \n");
2416 printf ("Values: %d %d %p %p\n", x->a, x->b, x->handle1, x->handle2);
2422 if (x->handle1 != (void*) 0x7080feed)
2425 if (x->handle2 != (void*) 0x1234abcd)
2431 LIBTEST_API int STDCALL
2432 mono_safe_handle_struct (HandleStructs x)
2434 printf ("Dingus Standard! \n");
2435 printf ("Values: %d %d %p %p\n", x.a, x.b, x.handle1, x.handle2);
2441 if (x.handle1 != (void*) 0x7080feed)
2444 if (x.handle2 != (void*) 0x1234abcd)
2454 LIBTEST_API int STDCALL
2455 mono_safe_handle_struct_simple (TrivialHandle x)
2457 printf ("The value is %p\n", x.a);
2458 return ((int)(gsize)x.a) * 2;
2461 LIBTEST_API int STDCALL
2462 mono_safe_handle_return (void)
2467 LIBTEST_API void STDCALL
2468 mono_safe_handle_ref (void **handle)
2471 *handle = (void *) 0xbad;
2475 *handle = (void *) 0x800d;
2478 LIBTEST_API double STDCALL
2479 mono_test_marshal_date_time (double d, double *d2)
2551 VT_USERDEFINED = 29,
2559 VT_STREAMED_OBJECT = 68,
2560 VT_STORED_OBJECT = 69,
2561 VT_BLOB_OBJECT = 70,
2569 void VariantInit(VARIANT* vt)
2586 LIBTEST_API int STDCALL
2587 mono_test_marshal_bstr_in(gunichar2* bstr)
2590 gchar* bstr_utf8 = g_utf16_to_utf8 (bstr, -1, NULL, NULL, NULL);
2591 result = strcmp("mono_test_marshal_bstr_in", bstr_utf8);
2598 LIBTEST_API int STDCALL
2599 mono_test_marshal_bstr_out(gunichar2** bstr)
2601 *bstr = marshal_bstr_alloc ("mono_test_marshal_bstr_out");
2605 LIBTEST_API int STDCALL
2606 mono_test_marshal_bstr_in_null(gunichar2* bstr)
2613 LIBTEST_API int STDCALL
2614 mono_test_marshal_bstr_out_null(gunichar2** bstr)
2620 LIBTEST_API int STDCALL
2621 mono_test_marshal_variant_in_sbyte(VARIANT variant)
2623 if (variant.vt == VT_I1 && variant.cVal == 100)
2628 LIBTEST_API int STDCALL
2629 mono_test_marshal_variant_in_byte(VARIANT variant)
2631 if (variant.vt == VT_UI1 && variant.bVal == 100)
2636 LIBTEST_API int STDCALL
2637 mono_test_marshal_variant_in_short(VARIANT variant)
2639 if (variant.vt == VT_I2 && variant.iVal == 314)
2644 LIBTEST_API int STDCALL
2645 mono_test_marshal_variant_in_ushort(VARIANT variant)
2647 if (variant.vt == VT_UI2 && variant.uiVal == 314)
2652 LIBTEST_API int STDCALL
2653 mono_test_marshal_variant_in_int(VARIANT variant)
2655 if (variant.vt == VT_I4 && variant.lVal == 314)
2660 LIBTEST_API int STDCALL
2661 mono_test_marshal_variant_in_uint(VARIANT variant)
2663 if (variant.vt == VT_UI4 && variant.ulVal == 314)
2668 LIBTEST_API int STDCALL
2669 mono_test_marshal_variant_in_long(VARIANT variant)
2671 if (variant.vt == VT_I8 && variant.llVal == 314)
2676 LIBTEST_API int STDCALL
2677 mono_test_marshal_variant_in_ulong(VARIANT variant)
2679 if (variant.vt == VT_UI8 && variant.ullVal == 314)
2684 LIBTEST_API int STDCALL
2685 mono_test_marshal_variant_in_float(VARIANT variant)
2687 if (variant.vt == VT_R4 && (variant.fltVal - 3.14)/3.14 < .001)
2692 LIBTEST_API int STDCALL
2693 mono_test_marshal_variant_in_double(VARIANT variant)
2695 if (variant.vt == VT_R8 && (variant.dblVal - 3.14)/3.14 < .001)
2700 LIBTEST_API int STDCALL
2701 mono_test_marshal_variant_in_bstr(VARIANT variant)
2704 gchar* bstr_utf8 = g_utf16_to_utf8 (variant.bstrVal, -1, NULL, NULL, NULL);
2705 result = strcmp("PI", bstr_utf8);
2708 if (variant.vt == VT_BSTR && !result)
2713 LIBTEST_API int STDCALL
2714 mono_test_marshal_variant_in_bool_true (VARIANT variant)
2716 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_TRUE)
2721 LIBTEST_API int STDCALL
2722 mono_test_marshal_variant_in_bool_false (VARIANT variant)
2724 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_FALSE)
2729 LIBTEST_API int STDCALL
2730 mono_test_marshal_variant_out_sbyte(VARIANT* variant)
2732 variant->vt = VT_I1;
2733 variant->cVal = 100;
2738 LIBTEST_API int STDCALL
2739 mono_test_marshal_variant_out_sbyte_byref(VARIANT* variant)
2741 variant->vt = VT_I1|VT_BYREF;
2742 variant->byref = marshal_alloc(1);
2743 *((gint8*)variant->byref) = 100;
2748 LIBTEST_API int STDCALL
2749 mono_test_marshal_variant_out_byte(VARIANT* variant)
2751 variant->vt = VT_UI1;
2752 variant->bVal = 100;
2757 LIBTEST_API int STDCALL
2758 mono_test_marshal_variant_out_byte_byref(VARIANT* variant)
2760 variant->vt = VT_UI1|VT_BYREF;
2761 variant->byref = marshal_alloc(1);
2762 *((gint8*)variant->byref) = 100;
2767 LIBTEST_API int STDCALL
2768 mono_test_marshal_variant_out_short(VARIANT* variant)
2770 variant->vt = VT_I2;
2771 variant->iVal = 314;
2776 LIBTEST_API int STDCALL
2777 mono_test_marshal_variant_out_short_byref(VARIANT* variant)
2779 variant->vt = VT_I2|VT_BYREF;
2780 variant->byref = marshal_alloc(2);
2781 *((gint16*)variant->byref) = 314;
2786 LIBTEST_API int STDCALL
2787 mono_test_marshal_variant_out_ushort(VARIANT* variant)
2789 variant->vt = VT_UI2;
2790 variant->uiVal = 314;
2795 LIBTEST_API int STDCALL
2796 mono_test_marshal_variant_out_ushort_byref(VARIANT* variant)
2798 variant->vt = VT_UI2|VT_BYREF;
2799 variant->byref = marshal_alloc(2);
2800 *((guint16*)variant->byref) = 314;
2805 LIBTEST_API int STDCALL
2806 mono_test_marshal_variant_out_int(VARIANT* variant)
2808 variant->vt = VT_I4;
2809 variant->lVal = 314;
2814 LIBTEST_API int STDCALL
2815 mono_test_marshal_variant_out_int_byref(VARIANT* variant)
2817 variant->vt = VT_I4|VT_BYREF;
2818 variant->byref = marshal_alloc(4);
2819 *((gint32*)variant->byref) = 314;
2824 LIBTEST_API int STDCALL
2825 mono_test_marshal_variant_out_uint(VARIANT* variant)
2827 variant->vt = VT_UI4;
2828 variant->ulVal = 314;
2833 LIBTEST_API int STDCALL
2834 mono_test_marshal_variant_out_uint_byref(VARIANT* variant)
2836 variant->vt = VT_UI4|VT_BYREF;
2837 variant->byref = marshal_alloc(4);
2838 *((guint32*)variant->byref) = 314;
2843 LIBTEST_API int STDCALL
2844 mono_test_marshal_variant_out_long(VARIANT* variant)
2846 variant->vt = VT_I8;
2847 variant->llVal = 314;
2852 LIBTEST_API int STDCALL
2853 mono_test_marshal_variant_out_long_byref(VARIANT* variant)
2855 variant->vt = VT_I8|VT_BYREF;
2856 variant->byref = marshal_alloc(8);
2857 *((gint64*)variant->byref) = 314;
2862 LIBTEST_API int STDCALL
2863 mono_test_marshal_variant_out_ulong(VARIANT* variant)
2865 variant->vt = VT_UI8;
2866 variant->ullVal = 314;
2871 LIBTEST_API int STDCALL
2872 mono_test_marshal_variant_out_ulong_byref(VARIANT* variant)
2874 variant->vt = VT_UI8|VT_BYREF;
2875 variant->byref = marshal_alloc(8);
2876 *((guint64*)variant->byref) = 314;
2881 LIBTEST_API int STDCALL
2882 mono_test_marshal_variant_out_float(VARIANT* variant)
2884 variant->vt = VT_R4;
2885 variant->fltVal = 3.14;
2890 LIBTEST_API int STDCALL
2891 mono_test_marshal_variant_out_float_byref(VARIANT* variant)
2893 variant->vt = VT_R4|VT_BYREF;
2894 variant->byref = marshal_alloc(4);
2895 *((float*)variant->byref) = 3.14;
2900 LIBTEST_API int STDCALL
2901 mono_test_marshal_variant_out_double(VARIANT* variant)
2903 variant->vt = VT_R8;
2904 variant->dblVal = 3.14;
2909 LIBTEST_API int STDCALL
2910 mono_test_marshal_variant_out_double_byref(VARIANT* variant)
2912 variant->vt = VT_R8|VT_BYREF;
2913 variant->byref = marshal_alloc(8);
2914 *((double*)variant->byref) = 3.14;
2919 LIBTEST_API int STDCALL
2920 mono_test_marshal_variant_out_bstr(VARIANT* variant)
2922 variant->vt = VT_BSTR;
2923 variant->bstrVal = marshal_bstr_alloc("PI");
2928 LIBTEST_API int STDCALL
2929 mono_test_marshal_variant_out_bstr_byref(VARIANT* variant)
2931 variant->vt = VT_BSTR|VT_BYREF;
2932 variant->byref = marshal_alloc(sizeof(gpointer));
2933 *((gunichar**)variant->byref) = (gunichar*)marshal_bstr_alloc("PI");
2938 LIBTEST_API int STDCALL
2939 mono_test_marshal_variant_out_bool_true (VARIANT* variant)
2941 variant->vt = VT_BOOL;
2942 variant->boolVal = VARIANT_TRUE;
2947 LIBTEST_API int STDCALL
2948 mono_test_marshal_variant_out_bool_true_byref (VARIANT* variant)
2950 variant->vt = VT_BOOL|VT_BYREF;
2951 variant->byref = marshal_alloc(2);
2952 *((gint16*)variant->byref) = VARIANT_TRUE;
2957 LIBTEST_API int STDCALL
2958 mono_test_marshal_variant_out_bool_false (VARIANT* variant)
2960 variant->vt = VT_BOOL;
2961 variant->boolVal = VARIANT_FALSE;
2966 LIBTEST_API int STDCALL
2967 mono_test_marshal_variant_out_bool_false_byref (VARIANT* variant)
2969 variant->vt = VT_BOOL|VT_BYREF;
2970 variant->byref = marshal_alloc(2);
2971 *((gint16*)variant->byref) = VARIANT_FALSE;
2976 typedef int (STDCALL *VarFunc) (int vt, VARIANT variant);
2977 typedef int (STDCALL *VarRefFunc) (int vt, VARIANT* variant);
2979 LIBTEST_API int STDCALL
2980 mono_test_marshal_variant_in_sbyte_unmanaged(VarFunc func)
2985 return func (VT_I1, vt);
2988 LIBTEST_API int STDCALL
2989 mono_test_marshal_variant_in_byte_unmanaged(VarFunc func)
2994 return func (VT_UI1, vt);
2997 LIBTEST_API int STDCALL
2998 mono_test_marshal_variant_in_short_unmanaged(VarFunc func)
3003 return func (VT_I2, vt);
3006 LIBTEST_API int STDCALL
3007 mono_test_marshal_variant_in_ushort_unmanaged(VarFunc func)
3012 return func (VT_UI2, vt);
3015 LIBTEST_API int STDCALL
3016 mono_test_marshal_variant_in_int_unmanaged(VarFunc func)
3021 return func (VT_I4, vt);
3024 LIBTEST_API int STDCALL
3025 mono_test_marshal_variant_in_uint_unmanaged(VarFunc func)
3030 return func (VT_UI4, vt);
3033 LIBTEST_API int STDCALL
3034 mono_test_marshal_variant_in_long_unmanaged(VarFunc func)
3039 return func (VT_I8, vt);
3042 LIBTEST_API int STDCALL
3043 mono_test_marshal_variant_in_ulong_unmanaged(VarFunc func)
3048 return func (VT_UI8, vt);
3051 LIBTEST_API int STDCALL
3052 mono_test_marshal_variant_in_float_unmanaged(VarFunc func)
3057 return func (VT_R4, vt);
3060 LIBTEST_API int STDCALL
3061 mono_test_marshal_variant_in_double_unmanaged(VarFunc func)
3066 return func (VT_R8, vt);
3069 LIBTEST_API int STDCALL
3070 mono_test_marshal_variant_in_bstr_unmanaged(VarFunc func)
3074 vt.bstrVal = marshal_bstr_alloc("PI");
3075 return func (VT_BSTR, vt);
3078 LIBTEST_API int STDCALL
3079 mono_test_marshal_variant_in_bool_true_unmanaged(VarFunc func)
3083 vt.boolVal = VARIANT_TRUE;
3084 return func (VT_BOOL, vt);
3087 LIBTEST_API int STDCALL
3088 mono_test_marshal_variant_in_bool_false_unmanaged(VarFunc func)
3092 vt.boolVal = VARIANT_FALSE;
3093 return func (VT_BOOL, vt);
3096 LIBTEST_API int STDCALL
3097 mono_test_marshal_variant_out_sbyte_unmanaged(VarRefFunc func)
3102 if (vt.vt == VT_I1 && vt.cVal == -100)
3107 LIBTEST_API int STDCALL
3108 mono_test_marshal_variant_out_byte_unmanaged(VarRefFunc func)
3113 if (vt.vt == VT_UI1 && vt.bVal == 100)
3118 LIBTEST_API int STDCALL
3119 mono_test_marshal_variant_out_short_unmanaged(VarRefFunc func)
3124 if (vt.vt == VT_I2 && vt.iVal == -100)
3129 LIBTEST_API int STDCALL
3130 mono_test_marshal_variant_out_ushort_unmanaged(VarRefFunc func)
3135 if (vt.vt == VT_UI2 && vt.uiVal == 100)
3140 LIBTEST_API int STDCALL
3141 mono_test_marshal_variant_out_int_unmanaged(VarRefFunc func)
3146 if (vt.vt == VT_I4 && vt.lVal == -100)
3151 LIBTEST_API int STDCALL
3152 mono_test_marshal_variant_out_uint_unmanaged(VarRefFunc func)
3157 if (vt.vt == VT_UI4 && vt.ulVal == 100)
3162 LIBTEST_API int STDCALL
3163 mono_test_marshal_variant_out_long_unmanaged(VarRefFunc func)
3168 if (vt.vt == VT_I8 && vt.llVal == -100)
3173 LIBTEST_API int STDCALL
3174 mono_test_marshal_variant_out_ulong_unmanaged(VarRefFunc func)
3179 if (vt.vt == VT_UI8 && vt.ullVal == 100)
3184 LIBTEST_API int STDCALL
3185 mono_test_marshal_variant_out_float_unmanaged(VarRefFunc func)
3190 if (vt.vt == VT_R4 && fabs (vt.fltVal - 3.14f) < 1e-10)
3195 LIBTEST_API int STDCALL
3196 mono_test_marshal_variant_out_double_unmanaged(VarRefFunc func)
3201 if (vt.vt == VT_R8 && fabs (vt.dblVal - 3.14) < 1e-10)
3206 LIBTEST_API int STDCALL
3207 mono_test_marshal_variant_out_bstr_unmanaged(VarRefFunc func)
3215 func (VT_BSTR, &vt);
3216 bstr_utf8 = g_utf16_to_utf8 (vt.bstrVal, -1, NULL, NULL, NULL);
3217 result = strcmp("PI", bstr_utf8);
3219 if (vt.vt == VT_BSTR && !result)
3224 LIBTEST_API int STDCALL
3225 mono_test_marshal_variant_out_bool_true_unmanaged(VarRefFunc func)
3229 func (VT_BOOL, &vt);
3230 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3235 LIBTEST_API int STDCALL
3236 mono_test_marshal_variant_out_bool_false_unmanaged(VarRefFunc func)
3240 func (VT_BOOL, &vt);
3241 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3246 typedef struct MonoComObject MonoComObject;
3250 int (STDCALL *QueryInterface)(MonoComObject* pUnk, gpointer riid, gpointer* ppv);
3251 int (STDCALL *AddRef)(MonoComObject* pUnk);
3252 int (STDCALL *Release)(MonoComObject* pUnk);
3253 int (STDCALL *get_ITest)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3254 int (STDCALL *SByteIn)(MonoComObject* pUnk, char a);
3255 int (STDCALL *ByteIn)(MonoComObject* pUnk, unsigned char a);
3256 int (STDCALL *ShortIn)(MonoComObject* pUnk, short a);
3257 int (STDCALL *UShortIn)(MonoComObject* pUnk, unsigned short a);
3258 int (STDCALL *IntIn)(MonoComObject* pUnk, int a);
3259 int (STDCALL *UIntIn)(MonoComObject* pUnk, unsigned int a);
3260 int (STDCALL *LongIn)(MonoComObject* pUnk, gint64 a);
3261 int (STDCALL *ULongIn)(MonoComObject* pUnk, guint64 a);
3262 int (STDCALL *FloatIn)(MonoComObject* pUnk, float a);
3263 int (STDCALL *DoubleIn)(MonoComObject* pUnk, double a);
3264 int (STDCALL *ITestIn)(MonoComObject* pUnk, MonoComObject* pUnk2);
3265 int (STDCALL *ITestOut)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3268 struct MonoComObject
3274 static GUID IID_ITest = {0, 0, 0, {0,0,0,0,0,0,0,1}};
3275 static GUID IID_IMonoUnknown = {0, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3276 static GUID IID_IMonoDispatch = {0x00020400, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3278 LIBTEST_API int STDCALL
3279 MonoQueryInterface(MonoComObject* pUnk, gpointer riid, gpointer* ppv)
3283 if (!memcmp(riid, &IID_IMonoUnknown, sizeof(GUID))) {
3287 else if (!memcmp(riid, &IID_ITest, sizeof(GUID))) {
3291 else if (!memcmp(riid, &IID_IMonoDispatch, sizeof(GUID))) {
3295 return 0x80004002; //E_NOINTERFACE;
3298 LIBTEST_API int STDCALL
3299 MonoAddRef(MonoComObject* pUnk)
3301 return ++(pUnk->m_ref);
3304 LIBTEST_API int STDCALL
3305 MonoRelease(MonoComObject* pUnk)
3307 return --(pUnk->m_ref);
3310 LIBTEST_API int STDCALL
3311 SByteIn(MonoComObject* pUnk, char a)
3316 LIBTEST_API int STDCALL
3317 ByteIn(MonoComObject* pUnk, unsigned char a)
3322 LIBTEST_API int STDCALL
3323 ShortIn(MonoComObject* pUnk, short a)
3328 LIBTEST_API int STDCALL
3329 UShortIn(MonoComObject* pUnk, unsigned short a)
3334 LIBTEST_API int STDCALL
3335 IntIn(MonoComObject* pUnk, int a)
3340 LIBTEST_API int STDCALL
3341 UIntIn(MonoComObject* pUnk, unsigned int a)
3346 LIBTEST_API int STDCALL
3347 LongIn(MonoComObject* pUnk, gint64 a)
3352 LIBTEST_API int STDCALL
3353 ULongIn(MonoComObject* pUnk, guint64 a)
3358 LIBTEST_API int STDCALL
3359 FloatIn(MonoComObject* pUnk, float a)
3364 LIBTEST_API int STDCALL
3365 DoubleIn(MonoComObject* pUnk, double a)
3370 LIBTEST_API int STDCALL
3371 ITestIn(MonoComObject* pUnk, MonoComObject *pUnk2)
3376 LIBTEST_API int STDCALL
3377 ITestOut(MonoComObject* pUnk, MonoComObject* *ppUnk)
3382 static void create_com_object (MonoComObject** pOut);
3384 LIBTEST_API int STDCALL
3385 get_ITest(MonoComObject* pUnk, MonoComObject* *ppUnk)
3387 create_com_object (ppUnk);
3391 static void create_com_object (MonoComObject** pOut)
3393 *pOut = marshal_new0 (MonoComObject, 1);
3394 (*pOut)->vtbl = marshal_new0 (MonoIUnknown, 1);
3397 (*pOut)->vtbl->QueryInterface = MonoQueryInterface;
3398 (*pOut)->vtbl->AddRef = MonoAddRef;
3399 (*pOut)->vtbl->Release = MonoRelease;
3400 (*pOut)->vtbl->SByteIn = SByteIn;
3401 (*pOut)->vtbl->ByteIn = ByteIn;
3402 (*pOut)->vtbl->ShortIn = ShortIn;
3403 (*pOut)->vtbl->UShortIn = UShortIn;
3404 (*pOut)->vtbl->IntIn = IntIn;
3405 (*pOut)->vtbl->UIntIn = UIntIn;
3406 (*pOut)->vtbl->LongIn = LongIn;
3407 (*pOut)->vtbl->ULongIn = ULongIn;
3408 (*pOut)->vtbl->FloatIn = FloatIn;
3409 (*pOut)->vtbl->DoubleIn = DoubleIn;
3410 (*pOut)->vtbl->ITestIn = ITestIn;
3411 (*pOut)->vtbl->ITestOut = ITestOut;
3412 (*pOut)->vtbl->get_ITest = get_ITest;
3415 static MonoComObject* same_object = NULL;
3417 LIBTEST_API int STDCALL
3418 mono_test_marshal_com_object_create(MonoComObject* *pUnk)
3420 create_com_object (pUnk);
3423 same_object = *pUnk;
3428 LIBTEST_API int STDCALL
3429 mono_test_marshal_com_object_same(MonoComObject* *pUnk)
3431 *pUnk = same_object;
3436 LIBTEST_API int STDCALL
3437 mono_test_marshal_com_object_destroy(MonoComObject *pUnk)
3439 int ref = --(pUnk->m_ref);
3446 LIBTEST_API int STDCALL
3447 mono_test_marshal_com_object_ref_count(MonoComObject *pUnk)
3452 LIBTEST_API int STDCALL
3453 mono_test_marshal_ccw_itest (MonoComObject *pUnk)
3456 MonoComObject* pTest;
3461 hr = pUnk->vtbl->SByteIn (pUnk, -100);
3464 hr = pUnk->vtbl->ByteIn (pUnk, 100);
3467 hr = pUnk->vtbl->ShortIn (pUnk, -100);
3470 hr = pUnk->vtbl->UShortIn (pUnk, 100);
3473 hr = pUnk->vtbl->IntIn (pUnk, -100);
3476 hr = pUnk->vtbl->UIntIn (pUnk, 100);
3479 hr = pUnk->vtbl->LongIn (pUnk, -100);
3482 hr = pUnk->vtbl->ULongIn (pUnk, 100);
3485 hr = pUnk->vtbl->FloatIn (pUnk, 3.14f);
3488 hr = pUnk->vtbl->DoubleIn (pUnk, 3.14);
3491 hr = pUnk->vtbl->ITestIn (pUnk, pUnk);
3494 hr = pUnk->vtbl->ITestOut (pUnk, &pTest);
3502 * mono_method_get_unmanaged_thunk tests
3505 #if defined(__GNUC__) && ((defined(__i386__) && (defined(__linux__) || defined (__APPLE__)) || defined (__FreeBSD__) || defined(__OpenBSD__)) || (defined(__ppc__) && defined(__APPLE__)))
3506 #define ALIGN(size) __attribute__ ((aligned(size)))
3512 /* thunks.cs:TestStruct */
3513 typedef struct _TestStruct {
3518 /* Searches for mono symbols in all loaded modules */
3520 lookup_mono_symbol (const char *symbol_name)
3523 if (g_module_symbol (g_module_open (NULL, G_MODULE_BIND_LAZY), symbol_name, &symbol))
3529 LIBTEST_API gpointer STDCALL
3530 mono_test_marshal_lookup_symbol (const char *symbol_name)
3532 return lookup_mono_symbol (symbol_name);
3536 * test_method_thunk:
3538 * @test_id: the test number
3539 * @test_method_handle: MonoMethod* of the C# test method
3540 * @create_object_method_handle: MonoMethod* of thunks.cs:Test.CreateObject
3542 LIBTEST_API int STDCALL
3543 test_method_thunk (int test_id, gpointer test_method_handle, gpointer create_object_method_handle)
3545 gpointer (*mono_method_get_unmanaged_thunk)(gpointer)
3546 = lookup_mono_symbol ("mono_method_get_unmanaged_thunk");
3548 gpointer (*mono_string_new_wrapper)(const char *)
3549 = lookup_mono_symbol ("mono_string_new_wrapper");
3551 char* (*mono_string_to_utf8)(gpointer)
3552 = lookup_mono_symbol ("mono_string_to_utf8");
3554 gpointer (*mono_object_unbox)(gpointer)
3555 = lookup_mono_symbol ("mono_object_unbox");
3557 gpointer test_method, ex = NULL;
3558 gpointer (STDCALL *CreateObject)(gpointer*);
3560 if (!mono_method_get_unmanaged_thunk)
3563 test_method = mono_method_get_unmanaged_thunk (test_method_handle);
3567 CreateObject = mono_method_get_unmanaged_thunk (create_object_method_handle);
3575 /* thunks.cs:Test.Test0 */
3576 void (STDCALL *F)(gpointer*) = test_method;
3582 /* thunks.cs:Test.Test1 */
3583 int (STDCALL *F)(gpointer*) = test_method;
3590 /* thunks.cs:Test.Test2 */
3591 gpointer (STDCALL *F)(gpointer, gpointer*) = test_method;
3592 gpointer str = mono_string_new_wrapper ("foo");
3593 if (str != F (str, &ex))
3599 /* thunks.cs:Test.Test3 */
3600 gpointer (STDCALL *F)(gpointer, gpointer, gpointer*);
3605 obj = CreateObject (&ex);
3606 str = mono_string_new_wrapper ("bar");
3608 if (str != F (obj, str, &ex))
3614 /* thunks.cs:Test.Test4 */
3615 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3620 obj = CreateObject (&ex);
3621 str = mono_string_new_wrapper ("bar");
3623 if (42 != F (obj, str, 42, &ex))
3630 /* thunks.cs:Test.Test5 */
3631 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3636 obj = CreateObject (&ex);
3637 str = mono_string_new_wrapper ("bar");
3639 F (obj, str, 42, &ex);
3647 /* thunks.cs:Test.Test6 */
3648 int (STDCALL *F)(gpointer, guint8, gint16, gint32, gint64, float, double,
3649 gpointer, gpointer*);
3651 gpointer str = mono_string_new_wrapper ("Test6");
3655 obj = CreateObject (&ex);
3657 res = F (obj, 254, 32700, -245378, 6789600, 3.1415, 3.1415, str, &ex);
3668 /* thunks.cs:Test.Test7 */
3669 gint64 (STDCALL *F)(gpointer*) = test_method;
3670 if (F (&ex) != G_MAXINT64)
3676 /* thunks.cs:Test.Test8 */
3677 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3678 gpointer*, gpointer*);
3690 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3698 (fabs (a5 - 3.1415) < 0.001) &&
3699 (fabs (a6 - 3.1415) < 0.001) &&
3700 strcmp (mono_string_to_utf8 (a7), "Test8") == 0))
3707 /* thunks.cs:Test.Test9 */
3708 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3709 gpointer*, gpointer*);
3721 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3729 /* thunks.cs:Test.Test10 */
3730 void (STDCALL *F)(gpointer*, gpointer*);
3732 gpointer obj1, obj2;
3734 obj1 = obj2 = CreateObject (&ex);
3751 /* thunks.cs:TestStruct.Test0 */
3752 int (STDCALL *F)(gpointer*, gpointer*);
3758 obj = CreateObject (&ex);
3765 a1 = mono_object_unbox (obj);
3781 /* check whether the call was really by value */
3782 if (a1->A != 42 || a1->B != 3.1415)
3789 /* thunks.cs:TestStruct.Test1 */
3790 void (STDCALL *F)(gpointer, gpointer*);
3795 obj = CreateObject (&ex);
3802 a1 = mono_object_unbox (obj);
3815 if (!fabs (a1->B - 3.1415) < 0.001)
3822 /* thunks.cs:TestStruct.Test2 */
3823 gpointer (STDCALL *F)(gpointer*);
3837 a1 = mono_object_unbox (obj);
3842 if (!fabs (a1->B - 3.1415) < 0.001)
3849 /* thunks.cs:TestStruct.Test3 */
3850 void (STDCALL *F)(gpointer, gpointer*);
3855 obj = CreateObject (&ex);
3862 a1 = mono_object_unbox (obj);
3898 LIBTEST_API int STDCALL
3899 mono_test_Winx64_struct1_in (winx64_struct1 var)
3912 LIBTEST_API int STDCALL
3913 mono_test_Winx64_struct2_in (winx64_struct2 var)
3930 LIBTEST_API int STDCALL
3931 mono_test_Winx64_struct3_in (winx64_struct3 var)
3937 if (var.c != 0x1234)
3950 LIBTEST_API int STDCALL
3951 mono_test_Winx64_struct4_in (winx64_struct4 var)
3957 if (var.c != 0x1234)
3959 if (var.d != 0x87654321)
3971 LIBTEST_API int STDCALL
3972 mono_test_Winx64_struct5_in (winx64_struct5 var)
3990 LIBTEST_API int STDCALL
3991 mono_test_Winx64_struct6_in (winx64_struct6 var)
4002 LIBTEST_API int STDCALL
4003 mono_test_Winx64_structs_in1 (winx64_struct1 var1,
4004 winx64_struct2 var2,
4005 winx64_struct3 var3,
4006 winx64_struct4 var4)
4020 if (var3.c != 0x1234)
4027 if (var4.c != 0x1234)
4029 if (var4.d != 0x87654321)
4034 LIBTEST_API int STDCALL
4035 mono_test_Winx64_structs_in2 (winx64_struct1 var1,
4036 winx64_struct1 var2,
4037 winx64_struct1 var3,
4038 winx64_struct1 var4,
4039 winx64_struct1 var5)
4055 LIBTEST_API int STDCALL
4056 mono_test_Winx64_structs_in3 (winx64_struct1 var1,
4057 winx64_struct5 var2,
4058 winx64_struct1 var3,
4059 winx64_struct5 var4,
4060 winx64_struct1 var5,
4061 winx64_struct5 var6)
4096 LIBTEST_API winx64_struct1 STDCALL
4097 mono_test_Winx64_struct1_ret (void)
4104 LIBTEST_API winx64_struct2 STDCALL
4105 mono_test_Winx64_struct2_ret (void)
4113 LIBTEST_API winx64_struct3 STDCALL
4114 mono_test_Winx64_struct3_ret (void)
4123 LIBTEST_API winx64_struct4 STDCALL
4124 mono_test_Winx64_struct4_ret (void)
4134 LIBTEST_API winx64_struct5 STDCALL
4135 mono_test_Winx64_struct5_ret (void)
4144 LIBTEST_API winx64_struct1 STDCALL
4145 mono_test_Winx64_struct1_ret_5_args (char a, char b, char c, char d, char e)
4148 ret.a = a + b + c + d + e;
4152 LIBTEST_API winx64_struct5 STDCALL
4153 mono_test_Winx64_struct5_ret6_args (char a, char b, char c, char d, char e)
4166 } winx64_floatStruct;
4168 LIBTEST_API int STDCALL
4169 mono_test_Winx64_floatStruct (winx64_floatStruct a)
4171 if (a.a > 5.6 || a.a < 5.4)
4174 if (a.b > 9.6 || a.b < 9.4)
4183 } winx64_doubleStruct;
4185 LIBTEST_API int STDCALL
4186 mono_test_Winx64_doubleStruct (winx64_doubleStruct a)
4188 if (a.a > 5.6 || a.a < 5.4)
4194 typedef int (STDCALL *managed_struct1_delegate) (winx64_struct1 a);
4196 LIBTEST_API int STDCALL
4197 mono_test_managed_Winx64_struct1_in(managed_struct1_delegate func)
4204 typedef int (STDCALL *managed_struct5_delegate) (winx64_struct5 a);
4206 LIBTEST_API int STDCALL
4207 mono_test_managed_Winx64_struct5_in(managed_struct5_delegate func)
4216 typedef int (STDCALL *managed_struct1_struct5_delegate) (winx64_struct1 a, winx64_struct5 b,
4217 winx64_struct1 c, winx64_struct5 d,
4218 winx64_struct1 e, winx64_struct5 f);
4220 LIBTEST_API int STDCALL
4221 mono_test_managed_Winx64_struct1_struct5_in(managed_struct1_struct5_delegate func)
4223 winx64_struct1 a, c, e;
4224 winx64_struct5 b, d, f;
4226 b.a = 2; b.b = 3; b.c = 4;
4228 d.a = 6; d.b = 7; d.c = 8;
4230 f.a = 10; f.b = 11; f.c = 12;
4232 return func (a, b, c, d, e, f);
4235 typedef winx64_struct1 (STDCALL *managed_struct1_ret_delegate) (void);
4237 LIBTEST_API int STDCALL
4238 mono_test_Winx64_struct1_ret_managed (managed_struct1_ret_delegate func)
4250 typedef winx64_struct5 (STDCALL *managed_struct5_ret_delegate) (void);
4252 LIBTEST_API int STDCALL
4253 mono_test_Winx64_struct5_ret_managed (managed_struct5_ret_delegate func)
4269 LIBTEST_API int STDCALL
4270 mono_test_marshal_bool_in (int arg, unsigned int expected, unsigned int bDefaultMarsh, unsigned int bBoolCustMarsh,
4271 char bI1CustMarsh, unsigned char bU1CustMarsh, short bVBCustMarsh)
4275 if (bDefaultMarsh != expected)
4279 if (bBoolCustMarsh != expected)
4283 if (bI1CustMarsh != expected)
4287 if (bU1CustMarsh != expected)
4291 if (bVBCustMarsh != expected)
4300 LIBTEST_API int STDCALL
4301 mono_test_marshal_bool_out (int arg, unsigned int testVal, unsigned int* bDefaultMarsh, unsigned int* bBoolCustMarsh,
4302 char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh)
4308 *bDefaultMarsh = testVal;
4311 if (!bBoolCustMarsh)
4313 *bBoolCustMarsh = testVal;
4318 *bI1CustMarsh = (char)testVal;
4323 *bU1CustMarsh = (unsigned char)testVal;
4328 *bVBCustMarsh = (unsigned short)testVal;
4336 LIBTEST_API int STDCALL
4337 mono_test_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4338 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh,
4339 unsigned short* bVBCustMarsh)
4345 if (*bDefaultMarsh != expected)
4347 *bDefaultMarsh = testVal;
4350 if (!bBoolCustMarsh)
4352 if (*bBoolCustMarsh != expected)
4354 *bBoolCustMarsh = testVal;
4359 if (*bI1CustMarsh != expected)
4361 *bI1CustMarsh = (char)testVal;
4366 if (*bU1CustMarsh != expected)
4368 *bU1CustMarsh = (unsigned char)testVal;
4373 if (*bVBCustMarsh != expected)
4375 *bVBCustMarsh = (unsigned short)testVal;
4384 typedef int (STDCALL *MarshalBoolInDelegate) (int arg, unsigned int expected, unsigned int bDefaultMarsh,
4385 unsigned int bBoolCustMarsh, char bI1CustMarsh, unsigned char bU1CustMarsh, unsigned short bVBCustMarsh);
4387 LIBTEST_API int STDCALL
4388 mono_test_managed_marshal_bool_in (int arg, unsigned int expected, unsigned int testVal, MarshalBoolInDelegate pfcn)
4395 return pfcn (arg, expected, testVal, 0, 0, 0, 0);
4397 return pfcn (arg, expected, 0, testVal, 0, 0, 0);
4399 return pfcn (arg, expected, 0, 0, testVal, 0, 0);
4401 return pfcn (arg, expected, 0, 0, 0, testVal, 0);
4403 return pfcn (arg, expected, 0, 0, 0, 0, testVal);
4411 typedef int (STDCALL *MarshalBoolOutDelegate) (int arg, unsigned int expected, unsigned int* bDefaultMarsh,
4412 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4414 LIBTEST_API int STDCALL
4415 mono_test_managed_marshal_bool_out (int arg, unsigned int expected, unsigned int testVal, MarshalBoolOutDelegate pfcn)
4418 unsigned int lDefaultMarsh, lBoolCustMarsh;
4419 char lI1CustMarsh = 0;
4420 unsigned char lU1CustMarsh = 0;
4421 unsigned short lVBCustMarsh = 0;
4422 lDefaultMarsh = lBoolCustMarsh = 0;
4429 unsigned int ltVal = 0;
4430 ret = pfcn (arg, testVal, <Val, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4432 return 0x0100 + ret;
4433 if (expected != ltVal)
4438 unsigned int ltVal = 0;
4439 ret = pfcn (arg, testVal, &lDefaultMarsh, <Val, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4441 return 0x0300 + ret;
4442 if (expected != ltVal)
4448 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, <Val, &lU1CustMarsh, &lVBCustMarsh);
4450 return 0x0500 + ret;
4451 if (expected != ltVal)
4456 unsigned char ltVal = 0;
4457 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <Val, &lVBCustMarsh);
4459 return 0x0700 + ret;
4460 if (expected != ltVal)
4465 unsigned short ltVal = 0;
4466 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <Val);
4468 return 0x0900 + ret;
4469 if (expected != ltVal)
4480 typedef int (STDCALL *MarshalBoolRefDelegate) (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4481 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4483 LIBTEST_API int STDCALL
4484 mono_test_managed_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int outExpected,
4485 unsigned int outTestVal, MarshalBoolRefDelegate pfcn)
4488 unsigned int lDefaultMarsh, lBoolCustMarsh;
4489 char lI1CustMarsh = 0;
4490 unsigned char lU1CustMarsh = 0;
4491 unsigned short lVBCustMarsh = 0;
4492 lDefaultMarsh = lBoolCustMarsh = 0;
4500 unsigned int ltestVal = testVal;
4501 ret = pfcn (arg, expected, outTestVal, <estVal, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4503 return 0x0100 + ret;
4504 if (outExpected != ltestVal)
4510 unsigned int ltestVal = testVal;
4511 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, <estVal, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4513 return 0x0300 + ret;
4514 if (outExpected != ltestVal)
4520 char ltestVal = testVal;
4521 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, <estVal, &lU1CustMarsh, &lVBCustMarsh);
4523 return 0x0500 + ret;
4524 if (outExpected != ltestVal)
4530 unsigned char ltestVal = testVal;
4531 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <estVal, &lVBCustMarsh);
4533 return 0x0700 + ret;
4534 if (outExpected != ltestVal)
4540 unsigned short ltestVal = testVal;
4541 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <estVal);
4543 return 0x0900 + ret;
4544 if (outExpected != ltestVal)
4557 LIBTEST_API int STDCALL
4558 mono_test_marshal_safearray_out_1dim_vt_bstr_empty (SAFEARRAY** safearray)
4560 /* Create an empty one-dimensional array of variants */
4562 SAFEARRAYBOUND dimensions [1];
4564 dimensions [0].lLbound = 0;
4565 dimensions [0].cElements = 0;
4567 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4572 LIBTEST_API int STDCALL
4573 mono_test_marshal_safearray_out_1dim_vt_bstr (SAFEARRAY** safearray)
4575 /* Create a one-dimensional array of 10 variants filled with "0" to "9" */
4577 SAFEARRAYBOUND dimensions [1];
4583 dimensions [0].lLbound = 0;
4584 dimensions [0].cElements = 10;
4586 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4587 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4589 VariantInit (&vOut);
4591 _ltoa (i,buffer,10);
4592 vOut.bstrVal= marshal_bstr_alloc (buffer);
4594 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4595 VariantClear (&vOut);
4596 SafeArrayDestroy (pSA);
4599 VariantClear (&vOut);
4605 LIBTEST_API int STDCALL
4606 mono_test_marshal_safearray_out_2dim_vt_i4 (SAFEARRAY** safearray)
4608 /* Create a two-dimensional array of 4x3 variants filled with 11, 12, 13, etc. */
4610 SAFEARRAYBOUND dimensions [2];
4615 dimensions [0].lLbound = 0;
4616 dimensions [0].cElements = 4;
4617 dimensions [1].lLbound = 0;
4618 dimensions [1].cElements = 3;
4620 pSA= SafeArrayCreate(VT_VARIANT, 2, dimensions);
4621 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4622 for (j= dimensions [1].lLbound; j< (dimensions [1].cElements + dimensions [1].lLbound); j++) {
4624 VariantInit (&vOut);
4626 vOut.lVal = (i+1)*10+(j+1);
4629 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4630 VariantClear (&vOut);
4631 SafeArrayDestroy (pSA);
4634 VariantClear (&vOut); // does a deep destroy of source VARIANT
4641 LIBTEST_API int STDCALL
4642 mono_test_marshal_safearray_out_4dim_vt_i4 (SAFEARRAY** safearray)
4644 /* Create a four-dimensional array of 10x3x6x7 variants filled with their indices */
4645 /* Also use non zero lower bounds */
4647 SAFEARRAYBOUND dimensions [4];
4652 dimensions [0].lLbound = 15;
4653 dimensions [0].cElements = 10;
4654 dimensions [1].lLbound = 20;
4655 dimensions [1].cElements = 3;
4656 dimensions [2].lLbound = 5;
4657 dimensions [2].cElements = 6;
4658 dimensions [3].lLbound = 12;
4659 dimensions [3].cElements = 7;
4661 pSA= SafeArrayCreate (VT_VARIANT, 4, dimensions);
4663 SafeArrayAccessData (pSA, (void **)&pData);
4665 for (i= 0; i< 10*3*6*7; i++) {
4666 VariantInit(&pData [i]);
4667 pData [i].vt = VT_I4;
4670 SafeArrayUnaccessData (pSA);
4675 LIBTEST_API int STDCALL
4676 mono_test_marshal_safearray_in_byval_1dim_empty (SAFEARRAY* safearray)
4678 /* Check that array is one dimensional and empty */
4681 long lbound, ubound;
4683 dim = SafeArrayGetDim (safearray);
4687 SafeArrayGetLBound (safearray, 1, &lbound);
4688 SafeArrayGetUBound (safearray, 1, &ubound);
4690 if ((lbound > 0) || (ubound > 0))
4696 LIBTEST_API int STDCALL
4697 mono_test_marshal_safearray_in_byval_1dim_vt_i4 (SAFEARRAY* safearray)
4699 /* Check that array is one dimensional containing integers from 1 to 10 */
4702 long lbound, ubound;
4707 dim = SafeArrayGetDim (safearray);
4711 SafeArrayGetLBound (safearray, 1, &lbound);
4712 SafeArrayGetUBound (safearray, 1, &ubound);
4714 if ((lbound != 0) || (ubound != 9))
4717 SafeArrayAccessData (safearray, (void **)&pData);
4718 for (i= lbound; i <= ubound; i++) {
4719 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i + 1))
4722 SafeArrayUnaccessData (safearray);
4727 LIBTEST_API int STDCALL
4728 mono_test_marshal_safearray_in_byval_1dim_vt_mixed (SAFEARRAY* safearray)
4730 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4733 long lbound, ubound;
4740 VariantInit (&element);
4742 dim = SafeArrayGetDim (safearray);
4746 SafeArrayGetLBound (safearray, 1, &lbound);
4747 SafeArrayGetUBound (safearray, 1, &ubound);
4749 if ((lbound != 0) || (ubound != 12))
4752 SafeArrayAccessData (safearray, (void **)&pData);
4753 for (i= lbound; i <= ubound; i++) {
4754 if ((i%2 == 0) && (pData [i].vt != VT_I4))
4756 if ((i%2 == 1) && (pData [i].vt != VT_BSTR))
4758 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i))
4761 SafeArrayUnaccessData (safearray);
4763 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4768 SafeArrayPutElement (safearray, indices, &element);
4769 VariantClear (&element);
4774 LIBTEST_API int STDCALL
4775 mono_test_marshal_safearray_in_byval_2dim_vt_i4 (SAFEARRAY* safearray)
4777 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4780 long lbound1, ubound1, lbound2, ubound2;
4785 VariantInit (&element);
4787 dim = SafeArrayGetDim (safearray);
4791 SafeArrayGetLBound (safearray, 1, &lbound1);
4792 SafeArrayGetUBound (safearray, 1, &ubound1);
4794 if ((lbound1 != 0) || (ubound1 != 1))
4797 SafeArrayGetLBound (safearray, 2, &lbound2);
4798 SafeArrayGetUBound (safearray, 2, &ubound2);
4800 if ((lbound2 != 0) || (ubound2 != 3)) {
4804 for (i= lbound1; i <= ubound1; i++) {
4806 for (j= lbound2; j <= ubound2; j++) {
4808 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4810 failed = ((element.vt != VT_I4) || (element.lVal != 10*(i+1)+(j+1)));
4811 VariantClear (&element);
4817 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4823 SafeArrayPutElement (safearray, indices, &element);
4824 VariantClear (&element);
4829 LIBTEST_API int STDCALL
4830 mono_test_marshal_safearray_in_byval_3dim_vt_bstr (SAFEARRAY* safearray)
4832 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4835 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4836 long i, j, k, failed;
4840 VariantInit (&element);
4842 dim = SafeArrayGetDim (safearray);
4846 SafeArrayGetLBound (safearray, 1, &lbound1);
4847 SafeArrayGetUBound (safearray, 1, &ubound1);
4849 if ((lbound1 != 0) || (ubound1 != 1))
4852 SafeArrayGetLBound (safearray, 2, &lbound2);
4853 SafeArrayGetUBound (safearray, 2, &ubound2);
4855 if ((lbound2 != 0) || (ubound2 != 1))
4858 SafeArrayGetLBound (safearray, 3, &lbound3);
4859 SafeArrayGetUBound (safearray, 3, &ubound3);
4861 if ((lbound3 != 0) || (ubound3 != 2))
4864 for (i= lbound1; i <= ubound1; i++) {
4866 for (j= lbound2; j <= ubound2; j++) {
4868 for (k= lbound3; k <= ubound3; k++) {
4870 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4872 failed = ((element.vt != VT_BSTR)
4873 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4874 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4875 VariantClear (&element);
4882 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4887 element.vt = VT_BSTR;
4888 element.bstrVal = SysAllocString(L"Should not be copied");
4889 SafeArrayPutElement (safearray, indices, &element);
4890 VariantClear (&element);
4895 LIBTEST_API int STDCALL
4896 mono_test_marshal_safearray_in_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4898 return mono_test_marshal_safearray_in_byval_3dim_vt_bstr (*safearray);
4901 LIBTEST_API int STDCALL
4902 mono_test_marshal_safearray_in_out_byref_1dim_empty (SAFEARRAY** safearray)
4904 /* Check that the input array is what is expected and change it so the caller can check */
4905 /* correct marshalling back to managed code */
4908 long lbound, ubound;
4909 SAFEARRAYBOUND dimensions [1];
4911 wchar_t buffer [20];
4915 /* Check that in array is one dimensional and empty */
4917 dim = SafeArrayGetDim (*safearray);
4922 SafeArrayGetLBound (*safearray, 1, &lbound);
4923 SafeArrayGetUBound (*safearray, 1, &ubound);
4925 if ((lbound > 0) || (ubound > 0)) {
4929 /* Re-dimension the array and return a one-dimensional array of 8 variants filled with "0" to "7" */
4931 dimensions [0].lLbound = 0;
4932 dimensions [0].cElements = 8;
4934 hr = SafeArrayRedim (*safearray, dimensions);
4938 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
4940 VariantInit (&vOut);
4942 _ltow (i,buffer,10);
4943 vOut.bstrVal = SysAllocString (buffer);
4945 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
4946 VariantClear (&vOut);
4947 SafeArrayDestroy (*safearray);
4950 VariantClear (&vOut);
4955 LIBTEST_API int STDCALL
4956 mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4958 /* Check that the input array is what is expected and change it so the caller can check */
4959 /* correct marshalling back to managed code */
4962 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4963 SAFEARRAYBOUND dimensions [1];
4964 long i, j, k, failed;
4965 wchar_t buffer [20];
4970 VariantInit (&element);
4972 /* Check that in array is three dimensional and contains the expected values */
4974 dim = SafeArrayGetDim (*safearray);
4978 SafeArrayGetLBound (*safearray, 1, &lbound1);
4979 SafeArrayGetUBound (*safearray, 1, &ubound1);
4981 if ((lbound1 != 0) || (ubound1 != 1))
4984 SafeArrayGetLBound (*safearray, 2, &lbound2);
4985 SafeArrayGetUBound (*safearray, 2, &ubound2);
4987 if ((lbound2 != 0) || (ubound2 != 1))
4990 SafeArrayGetLBound (*safearray, 3, &lbound3);
4991 SafeArrayGetUBound (*safearray, 3, &ubound3);
4993 if ((lbound3 != 0) || (ubound3 != 2))
4996 for (i= lbound1; i <= ubound1; i++) {
4998 for (j= lbound2; j <= ubound2; j++) {
5000 for (k= lbound3; k <= ubound3; k++) {
5002 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
5004 failed = ((element.vt != VT_BSTR)
5005 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
5006 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
5007 VariantClear (&element);
5014 hr = SafeArrayDestroy (*safearray);
5018 /* Return a new one-dimensional array of 8 variants filled with "0" to "7" */
5020 dimensions [0].lLbound = 0;
5021 dimensions [0].cElements = 8;
5023 *safearray = SafeArrayCreate (VT_VARIANT, 1, dimensions);
5025 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
5027 VariantInit (&vOut);
5029 _ltow (i,buffer,10);
5030 vOut.bstrVal = SysAllocString (buffer);
5032 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
5033 VariantClear (&vOut);
5034 SafeArrayDestroy (*safearray);
5037 VariantClear (&vOut);
5042 LIBTEST_API int STDCALL
5043 mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 (SAFEARRAY** safearray)
5045 /* Check that the input array is what is expected and change it so the caller can check */
5046 /* correct marshalling back to managed code */
5049 long lbound1, ubound1;
5055 VariantInit (&element);
5057 /* Check that in array is one dimensional and contains the expected value */
5059 dim = SafeArrayGetDim (*safearray);
5063 SafeArrayGetLBound (*safearray, 1, &lbound1);
5064 SafeArrayGetUBound (*safearray, 1, &ubound1);
5067 if ((lbound1 != 0) || (ubound1 != 1))
5071 for (i= lbound1; i <= ubound1; i++) {
5073 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
5075 failed = (element.vt != VT_I4) || (element.lVal != i+1);
5076 VariantClear (&element);
5081 /* Change one of the elements of the array to verify that [out] parameter is marshalled back to the managed side */
5086 SafeArrayPutElement (*safearray, indices, &element);
5087 VariantClear (&element);
5092 LIBTEST_API int STDCALL
5093 mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (SAFEARRAY* safearray)
5095 /* Check that the input array is what is expected and change it so the caller can check */
5096 /* correct marshalling back to managed code */
5099 long lbound1, ubound1;
5100 SAFEARRAYBOUND dimensions [1];
5106 VariantInit (&element);
5108 /* Check that in array is one dimensional and contains the expected value */
5110 dim = SafeArrayGetDim (safearray);
5114 SafeArrayGetLBound (safearray, 1, &lbound1);
5115 SafeArrayGetUBound (safearray, 1, &ubound1);
5117 if ((lbound1 != 0) || (ubound1 != 0))
5120 for (i= lbound1; i <= ubound1; i++) {
5122 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
5124 failed = (element.vt != VT_I4) || (element.lVal != i+1);
5125 VariantClear (&element);
5130 /* Change the array to verify how [out] parameter is marshalled back to the managed side */
5132 /* Redimension the array */
5133 dimensions [0].lLbound = lbound1;
5134 dimensions [0].cElements = 2;
5135 hr = SafeArrayRedim(safearray, dimensions);
5139 element.lVal = 12345;
5140 SafeArrayPutElement (safearray, indices, &element);
5141 VariantClear (&element);
5145 element.lVal = -12345;
5146 SafeArrayPutElement (safearray, indices, &element);
5147 VariantClear (&element);
5152 LIBTEST_API int STDCALL
5153 mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr (SAFEARRAY* safearray)
5155 /* Check that the input array is what is expected and change it so the caller can check */
5156 /* correct marshalling back to managed code */
5159 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
5160 long i, j, k, failed;
5165 VariantInit (&element);
5167 /* Check that in array is three dimensional and contains the expected values */
5169 dim = SafeArrayGetDim (safearray);
5173 SafeArrayGetLBound (safearray, 1, &lbound1);
5174 SafeArrayGetUBound (safearray, 1, &ubound1);
5176 if ((lbound1 != 0) || (ubound1 != 1))
5179 SafeArrayGetLBound (safearray, 2, &lbound2);
5180 SafeArrayGetUBound (safearray, 2, &ubound2);
5182 if ((lbound2 != 0) || (ubound2 != 1))
5185 SafeArrayGetLBound (safearray, 3, &lbound3);
5186 SafeArrayGetUBound (safearray, 3, &ubound3);
5188 if ((lbound3 != 0) || (ubound3 != 2))
5191 for (i= lbound1; i <= ubound1; i++) {
5193 for (j= lbound2; j <= ubound2; j++) {
5195 for (k= lbound3; k <= ubound3; k++) {
5197 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
5199 failed = ((element.vt != VT_BSTR)
5200 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
5201 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
5202 VariantClear (&element);
5209 /* Change the elements of the array to verify that [out] parameter is marshalled back to the managed side */
5216 SafeArrayPutElement (safearray, indices, &element);
5217 VariantClear (&element);
5224 SafeArrayPutElement (safearray, indices, &element);
5225 VariantClear (&element);
5230 element.vt = VT_BSTR;
5231 element.bstrVal = marshal_bstr_alloc("ABCDEFG");
5232 SafeArrayPutElement (safearray, indices, &element);
5233 VariantClear (&element);
5238 LIBTEST_API int STDCALL
5239 mono_test_marshal_safearray_mixed(
5240 SAFEARRAY *safearray1,
5241 SAFEARRAY **safearray2,
5242 SAFEARRAY *safearray3,
5243 SAFEARRAY **safearray4
5248 /* Initialize out parameters */
5251 /* array1: Check that in array is one dimensional and contains the expected value */
5252 hr = mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (safearray1);
5254 /* array2: Fill in with some values to check on the managed side */
5256 hr = mono_test_marshal_safearray_out_1dim_vt_bstr (safearray2);
5258 /* array3: Check that in array is one dimensional and contains the expected value */
5260 hr = mono_test_marshal_safearray_in_byval_1dim_vt_mixed(safearray3);
5262 /* array4: Check input values and fill in with some values to check on the managed side */
5264 hr = mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr(safearray4);
5271 static int call_managed_res;
5274 call_managed (gpointer arg)
5276 SimpleDelegate del = arg;
5278 call_managed_res = del (42);
5281 LIBTEST_API int STDCALL
5282 mono_test_marshal_thread_attach (SimpleDelegate del)
5290 res = pthread_create (&t, NULL, (gpointer)call_managed, del);
5291 g_assert (res == 0);
5292 pthread_join (t, NULL);
5294 return call_managed_res;
5298 typedef int (STDCALL *Callback) (void);
5300 static Callback callback;
5302 LIBTEST_API void STDCALL
5303 mono_test_marshal_set_callback (Callback cb)
5308 LIBTEST_API int STDCALL
5309 mono_test_marshal_call_callback (void)
5314 LIBTEST_API int STDCALL
5315 mono_test_marshal_lpstr (char *str)
5317 return strcmp ("ABC", str);
5320 LIBTEST_API int STDCALL
5321 mono_test_marshal_lpwstr (gunichar2 *str)
5326 s = g_utf16_to_utf8 (str, -1, NULL, NULL, NULL);
5327 res = strcmp ("ABC", s);
5333 LIBTEST_API char* STDCALL
5334 mono_test_marshal_return_lpstr (void)
5336 char *res = marshal_alloc (4);
5337 strcpy (res, "XYZ");
5342 LIBTEST_API gunichar2* STDCALL
5343 mono_test_marshal_return_lpwstr (void)
5345 gunichar2 *res = marshal_alloc (8);
5346 gunichar2* tmp = g_utf8_to_utf16 ("XYZ", -1, NULL, NULL, NULL);
5348 memcpy (res, tmp, 8);
5356 } SingleDoubleStruct;
5358 LIBTEST_API SingleDoubleStruct STDCALL
5359 mono_test_marshal_return_single_double_struct (void)
5361 SingleDoubleStruct res;
5371 LIBTEST_API int STDCALL
5372 mono_test_has_thiscall (void)
5378 _mono_test_native_thiscall1 (int arg)
5384 _mono_test_native_thiscall2 (int arg, int arg2)
5386 return arg + (arg2^1);
5390 _mono_test_native_thiscall3 (int arg, int arg2, int arg3)
5392 return arg + (arg2^1) + (arg3^2);
5395 #elif defined(__GNUC__)
5397 LIBTEST_API int STDCALL
5398 mono_test_has_thiscall (void)
5403 #define def_asm_fn(name) \
5405 "\t.globl _" #name "\n" \
5407 "\t.globl __" #name "\n" \
5412 def_asm_fn(mono_test_native_thiscall1)
5413 "\tmovl %ecx,%eax\n"
5416 def_asm_fn(mono_test_native_thiscall2)
5417 "\tmovl %ecx,%eax\n"
5418 "\tmovl 4(%esp),%ecx\n"
5420 "\taddl %ecx,%eax\n"
5423 def_asm_fn(mono_test_native_thiscall3)
5424 "\tmovl %ecx,%eax\n"
5425 "\tmovl 4(%esp),%ecx\n"
5427 "\taddl %ecx,%eax\n"
5428 "\tmovl 8(%esp),%ecx\n"
5430 "\taddl %ecx,%eax\n"
5437 LIBTEST_API int STDCALL
5438 mono_test_has_thiscall (void)