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)
987 typedef int (STDCALL *SimpleDelegate7) (simplestruct **ss);
989 LIBTEST_API int STDCALL
990 mono_test_marshal_delegate7 (SimpleDelegate7 delegate)
995 /* Check that the input pointer is ignored */
996 ptr = (gpointer)0x12345678;
998 res = delegate (&ptr);
1002 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
1008 typedef int (STDCALL *InOutByvalClassDelegate) (simplestruct *ss);
1010 LIBTEST_API int STDCALL
1011 mono_test_marshal_inout_byval_class_delegate (InOutByvalClassDelegate delegate)
1019 ss.d = g_strdup_printf ("%s", "FOO");
1021 res = delegate (&ss);
1025 if (!(ss.a && !ss.b && ss.c && !strcmp (ss.d, "RES")))
1031 typedef int (STDCALL *SimpleDelegate8) (gunichar2 *s);
1033 LIBTEST_API int STDCALL
1034 mono_test_marshal_delegate8 (SimpleDelegate8 delegate, gunichar2 *s)
1036 return delegate (s);
1039 typedef int (STDCALL *return_int_fnt) (int i);
1040 typedef int (STDCALL *SimpleDelegate9) (return_int_fnt d);
1042 LIBTEST_API int STDCALL
1043 mono_test_marshal_delegate9 (SimpleDelegate9 delegate, gpointer ftn)
1045 return delegate (ftn);
1054 LIBTEST_API int STDCALL
1055 mono_test_marshal_delegate10 (SimpleDelegate9 delegate)
1057 return delegate (return_self);
1060 typedef int (STDCALL *PrimitiveByrefDelegate) (int *i);
1062 LIBTEST_API int STDCALL
1063 mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate delegate)
1067 int res = delegate (&i);
1077 typedef int (STDCALL *return_int_delegate) (int i);
1079 typedef return_int_delegate (STDCALL *ReturnDelegateDelegate) (void);
1081 LIBTEST_API int STDCALL
1082 mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d)
1087 LIBTEST_API int STDCALL
1088 mono_test_marshal_stringbuilder (char *s, int n)
1090 const char m[] = "This is my message. Isn't it nice?";
1092 if (strcmp (s, "ABCD") != 0)
1099 LIBTEST_API int STDCALL
1100 mono_test_marshal_stringbuilder_append (char *s, int length)
1102 const char out_sentinel[] = "CSHARP_";
1103 const char out_len = strlen (out_sentinel);
1105 for (int i=0; i < length; i++) {
1106 s [i] = out_sentinel [i % out_len];
1115 LIBTEST_API int STDCALL
1116 mono_test_marshal_stringbuilder_default (char *s, int n)
1118 const char m[] = "This is my message. Isn't it nice?";
1125 LIBTEST_API int STDCALL
1126 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
1128 const char m[] = "This is my message. Isn't it nice?";
1132 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1134 len = (len * 2) + 2;
1137 memcpy (s, s2, len);
1144 LIBTEST_API void STDCALL
1145 mono_test_marshal_stringbuilder_out (char **s)
1147 const char m[] = "This is my message. Isn't it nice?";
1150 str = marshal_alloc (strlen (m) + 1);
1151 memcpy (str, m, strlen (m) + 1);
1156 LIBTEST_API int STDCALL
1157 mono_test_marshal_stringbuilder_out_unicode (gunichar2 **s)
1159 const char m[] = "This is my message. Isn't it nice?";
1163 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1165 len = (len * 2) + 2;
1166 *s = marshal_alloc (len);
1167 memcpy (*s, s2, len);
1174 LIBTEST_API int STDCALL
1175 mono_test_marshal_stringbuilder_ref (char **s)
1177 const char m[] = "This is my message. Isn't it nice?";
1180 if (strcmp (*s, "ABC"))
1183 str = marshal_alloc (strlen (m) + 1);
1184 memcpy (str, m, strlen (m) + 1);
1196 LIBTEST_API int STDCALL
1197 mono_test_marshal_empty_string_array (char **array)
1199 return (array == NULL) ? 0 : 1;
1202 LIBTEST_API int STDCALL
1203 mono_test_marshal_string_array (char **array)
1205 if (strcmp (array [0], "ABC"))
1207 if (strcmp (array [1], "DEF"))
1210 if (array [2] != NULL)
1216 LIBTEST_API int STDCALL
1217 mono_test_marshal_byref_string_array (char ***array)
1222 if (strcmp ((*array) [0], "Alpha"))
1224 if (strcmp ((*array) [1], "Beta"))
1226 if (strcmp ((*array) [2], "Gamma"))
1232 LIBTEST_API int STDCALL
1233 mono_test_marshal_stringbuilder_array (char **array)
1235 if (strcmp (array [0], "ABC"))
1237 if (strcmp (array [1], "DEF"))
1240 strcpy (array [0], "DEF");
1241 strcpy (array [1], "ABC");
1246 LIBTEST_API int STDCALL
1247 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
1249 GError *error = NULL;
1252 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
1253 if (strcmp (s, "ABC")) {
1260 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
1261 if (strcmp (s, "DEF")) {
1268 if (strcmp (array2 [0], "ABC"))
1271 if (strcmp (array2 [1], "DEF"))
1277 /* this does not work on Redhat gcc 2.96 */
1278 LIBTEST_API int STDCALL
1279 mono_test_empty_struct (int a, EmptyStruct es, int b)
1281 // printf ("mono_test_empty_struct %d %d\n", a, b);
1283 // Intel icc on ia64 passes 'es' in 2 registers
1284 #if defined(__ia64) && defined(__INTEL_COMPILER)
1287 if (a == 1 && b == 2)
1297 LIBTEST_API ByValStrStruct * STDCALL
1298 mono_test_byvalstr_gen (void)
1300 ByValStrStruct *ret;
1302 ret = malloc(sizeof(ByValStrStruct));
1303 memset(ret, 'a', sizeof(ByValStrStruct)-1);
1304 ret->a[sizeof(ByValStrStruct)-1] = 0;
1309 LIBTEST_API int STDCALL
1310 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
1314 ret = strcmp(data->a, correctString);
1315 // printf ("T1: %s\n", data->a);
1316 // printf ("T2: %s\n", correctString);
1318 /* we need g_free because the allocation was performed by mono_test_byvalstr_gen */
1326 } ByValStrStruct_Unicode;
1328 LIBTEST_API int STDCALL
1329 mono_test_byvalstr_check_unicode (ByValStrStruct_Unicode *ref, int test)
1331 if (ref->flag != 0x1234abcd){
1332 printf ("overwritten data");
1336 if (test == 1 || test == 3){
1337 if (ref->a [0] != '1' ||
1338 ref->a [1] != '2' ||
1344 if (ref->a [0] != '1' ||
1352 LIBTEST_API int STDCALL
1353 NameManglingAnsi (char *data)
1355 return data [0] + data [1] + data [2];
1358 LIBTEST_API int STDCALL
1359 NameManglingAnsiA (char *data)
1361 g_assert_not_reached ();
1364 LIBTEST_API int STDCALL
1365 NameManglingAnsiW (char *data)
1367 g_assert_not_reached ();
1370 LIBTEST_API int STDCALL
1371 NameManglingAnsi2A (char *data)
1373 return data [0] + data [1] + data [2];
1376 LIBTEST_API int STDCALL
1377 NameManglingAnsi2W (char *data)
1379 g_assert_not_reached ();
1382 LIBTEST_API int STDCALL
1383 NameManglingUnicode (char *data)
1385 g_assert_not_reached ();
1388 LIBTEST_API int STDCALL
1389 NameManglingUnicodeW (gunichar2 *data)
1391 return data [0] + data [1] + data [2];
1394 LIBTEST_API int STDCALL
1395 NameManglingUnicode2 (gunichar2 *data)
1397 return data [0] + data [1] + data [2];
1400 LIBTEST_API int STDCALL
1401 NameManglingAutoW (char *data)
1404 return (data [0] + data [1] + data [2]) == 131 ? 0 : 1;
1406 g_assert_not_reached ();
1410 LIBTEST_API int STDCALL
1411 NameManglingAuto (char *data)
1414 return (data [0] + data [1] + data [2]) == 198 ? 0 : 1;
1416 g_assert_not_reached ();
1420 typedef int (STDCALL *intcharFunc)(const char*);
1422 LIBTEST_API void STDCALL
1423 callFunction (intcharFunc f)
1433 LIBTEST_API int STDCALL
1434 class_marshal_test0 (SimpleObj *obj1)
1436 // printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
1438 if (strcmp(obj1->str, "T1"))
1446 LIBTEST_API int STDCALL
1447 class_marshal_test4 (SimpleObj *obj1)
1455 LIBTEST_API void STDCALL
1456 class_marshal_test1 (SimpleObj **obj1)
1458 SimpleObj *res = malloc (sizeof (SimpleObj));
1460 res->str = marshal_strdup ("ABC");
1466 LIBTEST_API int STDCALL
1467 class_marshal_test2 (SimpleObj **obj1)
1469 // printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
1471 if (strcmp((*obj1)->str, "ABC"))
1473 if ((*obj1)->i != 5)
1479 LIBTEST_API int STDCALL
1480 string_marshal_test0 (char *str)
1482 if (strcmp (str, "TEST0"))
1488 LIBTEST_API void STDCALL
1489 string_marshal_test1 (const char **str)
1491 *str = marshal_strdup ("TEST1");
1494 LIBTEST_API int STDCALL
1495 string_marshal_test2 (char **str)
1497 // printf ("string_marshal_test2 %s\n", *str);
1499 if (strcmp (*str, "TEST1"))
1502 *str = marshal_strdup ("TEST2");
1507 LIBTEST_API int STDCALL
1508 string_marshal_test3 (char *str)
1521 LIBTEST_API BlittableClass* STDCALL
1522 TestBlittableClass (BlittableClass *vl)
1524 BlittableClass *res;
1526 // printf ("TestBlittableClass %d %d\n", vl->a, vl->b);
1532 res = marshal_new0 (BlittableClass, 1);
1533 memcpy (res, vl, sizeof (BlittableClass));
1535 res = marshal_new0 (BlittableClass, 1);
1543 typedef struct OSVERSIONINFO_STRUCT
1547 } OSVERSIONINFO_STRUCT;
1549 LIBTEST_API int STDCALL
1550 MyGetVersionEx (OSVERSIONINFO_STRUCT *osvi)
1553 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1558 return osvi->a + osvi->b;
1561 LIBTEST_API int STDCALL
1562 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO_STRUCT *osvi)
1565 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1570 return osvi->a + osvi->b;
1573 LIBTEST_API int STDCALL
1574 mono_test_marshal_point (point pt)
1576 // printf("point %g %g\n", pt.x, pt.y);
1577 if (pt.x == 1.25 && pt.y == 3.5)
1588 LIBTEST_API int STDCALL
1589 mono_test_marshal_mixed_point (mixed_point pt)
1591 // printf("mixed point %d %g\n", pt.x, pt.y);
1592 if (pt.x == 5 && pt.y == 6.75)
1598 LIBTEST_API int STDCALL
1599 mono_test_marshal_mixed_point_2 (mixed_point *pt)
1601 if (pt->x != 5 || pt->y != 6.75)
1610 LIBTEST_API int STDCALL
1611 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
1614 if (*b1 != 0 && *b1 != 1)
1616 if (*b2 != 0 && *b2 != -1) /* variant_bool */
1618 if (*b3 != 0 && *b3 != 1)
1620 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
1632 short b2; /* variant_bool */
1636 LIBTEST_API int STDCALL
1637 marshal_test_bool_struct(struct BoolStruct *s)
1640 if (s->b1 != 0 && s->b1 != 1)
1642 if (s->b2 != 0 && s->b2 != -1)
1644 if (s->b3 != 0 && s->b3 != 1)
1646 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1663 LIBTEST_API int STDCALL
1664 mono_test_marshal_long_struct (LongStruct *s)
1666 return s->i + s->l.l;
1669 LIBTEST_API void STDCALL
1670 mono_test_last_error (int err)
1679 LIBTEST_API int STDCALL
1680 mono_test_asany (void *ptr, int what)
1684 return (*(int*)ptr == 5) ? 0 : 1;
1686 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1688 simplestruct2 ss = *(simplestruct2*)ptr;
1690 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1691 !strcmp (ss.d, "TEST") &&
1692 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1698 GError *error = NULL;
1701 s = g_utf16_to_utf8 (ptr, -1, NULL, NULL, &error);
1706 if (!strcmp (s, "ABC")) {
1716 g_assert_not_reached ();
1730 LIBTEST_API int STDCALL
1731 mono_test_marshal_asany_in (void* ptr)
1733 AsAnyStruct* asAny = ptr;
1734 int res = asAny->i + asAny->j + asAny->k;
1739 LIBTEST_API int STDCALL
1740 mono_test_marshal_asany_inout (void* ptr)
1742 AsAnyStruct* asAny = ptr;
1743 int res = asAny->i + asAny->j + asAny->k;
1745 marshal_free (asAny->s);
1755 LIBTEST_API int STDCALL
1756 mono_test_marshal_asany_out (void* ptr)
1758 AsAnyStruct* asAny = ptr;
1759 int res = asAny->i + asAny->j + asAny->k;
1770 * AMD64 marshalling tests.
1773 typedef struct amd64_struct1 {
1780 LIBTEST_API amd64_struct1 STDCALL
1781 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
1791 LIBTEST_API amd64_struct1 STDCALL
1792 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)
1797 s.l += 1 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8;
1802 typedef struct amd64_struct2 {
1807 LIBTEST_API amd64_struct2 STDCALL
1808 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
1816 typedef struct amd64_struct3 {
1820 LIBTEST_API amd64_struct3 STDCALL
1821 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s)
1828 typedef struct amd64_struct4 {
1832 LIBTEST_API amd64_struct4 STDCALL
1833 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s)
1842 * IA64 marshalling tests.
1844 typedef struct test_struct5 {
1848 LIBTEST_API test_struct5 STDCALL
1849 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, test_struct5 s, int i, double d3, double d4)
1851 s.d1 += d1 + d2 + i;
1852 s.d2 += d3 + d4 + i;
1857 typedef struct test_struct6 {
1861 LIBTEST_API test_struct6 STDCALL
1862 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, test_struct6 s, int i, double d3, double d4)
1864 s.d1 += d1 + d2 + i;
1870 static guint32 custom_res [2];
1872 LIBTEST_API void* STDCALL
1873 mono_test_marshal_pass_return_custom (int i, guint32 *ptr, int j)
1875 /* ptr will be freed by CleanupNative, so make a copy */
1876 custom_res [0] = 0; /* not allocated by AllocHGlobal */
1877 custom_res [1] = ptr [1];
1882 LIBTEST_API int STDCALL
1883 mono_test_marshal_pass_out_custom (int i, guint32 **ptr, int j)
1886 custom_res [1] = i + j + 10;
1893 LIBTEST_API int STDCALL
1894 mono_test_marshal_pass_inout_custom (int i, guint32 *ptr, int j)
1897 ptr [1] = i + ptr [1] + j;
1902 LIBTEST_API int STDCALL
1903 mono_test_marshal_pass_out_byval_custom (int i, guint32 *ptr, int j)
1905 return ptr == NULL ? 0 : 1;
1908 LIBTEST_API int STDCALL
1909 mono_test_marshal_pass_byref_custom (int i, guint32 **ptr, int j)
1916 LIBTEST_API void* STDCALL
1917 mono_test_marshal_pass_return_custom2 (int i, guint32 *ptr, int j)
1919 g_assert_not_reached ();
1924 LIBTEST_API void* STDCALL
1925 mono_test_marshal_pass_return_custom_null (int i, guint32 *ptr, int j)
1927 g_assert (ptr == NULL);
1932 typedef void *(STDCALL *PassReturnPtrDelegate) (void *ptr);
1934 LIBTEST_API int STDCALL
1935 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del)
1949 /* FIXME: Freed with FreeHGlobal */
1957 LIBTEST_API int STDCALL
1958 mono_test_marshal_pass_return_custom_null_in_delegate (PassReturnPtrDelegate del)
1960 void *ptr = del (NULL);
1962 return (ptr == NULL) ? 15 : 0;
1965 typedef void (STDCALL *CustomOutParamDelegate) (void **pptr);
1967 LIBTEST_API int STDCALL
1968 mono_test_marshal_custom_out_param_delegate (CustomOutParamDelegate del)
1980 typedef int (STDCALL *ReturnEnumDelegate) (int e);
1982 LIBTEST_API int STDCALL
1983 mono_test_marshal_return_enum_delegate (ReturnEnumDelegate func)
1993 typedef BlittableStruct (STDCALL *SimpleDelegate10) (BlittableStruct ss);
1995 LIBTEST_API int STDCALL
1996 mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 delegate)
1998 BlittableStruct ss, res;
2005 res = delegate (ss);
2006 if (! ((res.a == -1) && (res.b == -2) && (res.c == -3) && (res.d == -55)))
2012 LIBTEST_API int STDCALL
2013 mono_test_stdcall_name_mangling (int a, int b, int c)
2019 mono_test_stdcall_mismatch_1 (int a, int b, int c)
2024 LIBTEST_API int STDCALL
2025 mono_test_stdcall_mismatch_2 (int a, int b, int c)
2031 * PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
2038 typedef SmallStruct1 (STDCALL *SmallStructDelegate1) (SmallStruct1 ss);
2040 LIBTEST_API int STDCALL
2041 mono_test_marshal_small_struct_delegate1 (SmallStructDelegate1 delegate)
2043 SmallStruct1 ss, res;
2047 res = delegate (ss);
2048 if (! (res.i == -1))
2058 typedef SmallStruct2 (STDCALL *SmallStructDelegate2) (SmallStruct2 ss);
2060 LIBTEST_API int STDCALL
2061 mono_test_marshal_small_struct_delegate2 (SmallStructDelegate2 delegate)
2063 SmallStruct2 ss, res;
2068 res = delegate (ss);
2069 if (! ((res.i == -2) && (res.j == -3)))
2080 typedef SmallStruct3 (STDCALL *SmallStructDelegate3) (SmallStruct3 ss);
2082 LIBTEST_API int STDCALL
2083 mono_test_marshal_small_struct_delegate3 (SmallStructDelegate3 delegate)
2085 SmallStruct3 ss, res;
2090 res = delegate (ss);
2091 if (! ((res.i == -1) && (res.j == -2)))
2101 typedef SmallStruct4 (STDCALL *SmallStructDelegate4) (SmallStruct4 ss);
2103 LIBTEST_API int STDCALL
2104 mono_test_marshal_small_struct_delegate4 (SmallStructDelegate4 delegate)
2106 SmallStruct4 ss, res;
2110 res = delegate (ss);
2111 if (! (res.i == -1))
2121 typedef SmallStruct5 (STDCALL *SmallStructDelegate5) (SmallStruct5 ss);
2123 LIBTEST_API int STDCALL
2124 mono_test_marshal_small_struct_delegate5 (SmallStructDelegate5 delegate)
2126 SmallStruct5 ss, res;
2130 res = delegate (ss);
2131 if (! (res.i == -5))
2141 typedef SmallStruct6 (STDCALL *SmallStructDelegate6) (SmallStruct6 ss);
2143 LIBTEST_API int STDCALL
2144 mono_test_marshal_small_struct_delegate6 (SmallStructDelegate6 delegate)
2146 SmallStruct6 ss, res;
2151 res = delegate (ss);
2152 if (! ((res.i == -1) && (res.j == -2)))
2163 typedef SmallStruct7 (STDCALL *SmallStructDelegate7) (SmallStruct7 ss);
2165 LIBTEST_API int STDCALL
2166 mono_test_marshal_small_struct_delegate7 (SmallStructDelegate7 delegate)
2168 SmallStruct7 ss, res;
2173 res = delegate (ss);
2174 if (! ((res.i == -1) && (res.j == -2)))
2184 typedef SmallStruct8 (STDCALL *SmallStructDelegate8) (SmallStruct8 ss);
2186 LIBTEST_API int STDCALL
2187 mono_test_marshal_small_struct_delegate8 (SmallStructDelegate8 delegate)
2189 SmallStruct8 ss, res;
2193 res = delegate (ss);
2194 if (! ((res.i == -1.0)))
2204 typedef SmallStruct9 (STDCALL *SmallStructDelegate9) (SmallStruct9 ss);
2206 LIBTEST_API int STDCALL
2207 mono_test_marshal_small_struct_delegate9 (SmallStructDelegate9 delegate)
2209 SmallStruct9 ss, res;
2213 res = delegate (ss);
2214 if (! ((res.i == -1.0)))
2224 typedef SmallStruct10 (STDCALL *SmallStructDelegate10) (SmallStruct10 ss);
2226 LIBTEST_API int STDCALL
2227 mono_test_marshal_small_struct_delegate10 (SmallStructDelegate10 delegate)
2229 SmallStruct10 ss, res;
2234 res = delegate (ss);
2235 if (! ((res.i == -1.0) && (res.j == -2.0)))
2246 typedef SmallStruct11 (STDCALL *SmallStructDelegate11) (SmallStruct11 ss);
2248 LIBTEST_API int STDCALL
2249 mono_test_marshal_small_struct_delegate11 (SmallStructDelegate11 delegate)
2251 SmallStruct11 ss, res;
2256 res = delegate (ss);
2257 if (! ((res.i == -1.0) && (res.j == -2)))
2263 typedef int (STDCALL *ArrayDelegate) (int i, char *j, void *arr);
2265 LIBTEST_API int STDCALL
2266 mono_test_marshal_array_delegate (void *arr, int len, ArrayDelegate del)
2268 return del (len, NULL, arr);
2271 typedef int (STDCALL *ArrayDelegateLong) (gint64 i, char *j, void *arr);
2273 LIBTEST_API int STDCALL
2274 mono_test_marshal_array_delegate_long (void *arr, gint64 len, ArrayDelegateLong del)
2276 return del (len, NULL, arr);
2279 LIBTEST_API int STDCALL
2280 mono_test_marshal_out_array_delegate (int *arr, int len, ArrayDelegate del)
2282 del (len, NULL, arr);
2284 if ((arr [0] != 1) || (arr [1] != 2))
2290 typedef gunichar2* (STDCALL *UnicodeStringDelegate) (gunichar2 *message);
2292 LIBTEST_API int STDCALL
2293 mono_test_marshal_return_unicode_string_delegate (UnicodeStringDelegate del)
2295 const char m[] = "abcdef";
2296 gunichar2 *s2, *res;
2299 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
2308 LIBTEST_API int STDCALL
2309 mono_test_marshal_out_string_array_delegate (char **arr, int len, ArrayDelegate del)
2311 del (len, NULL, arr);
2313 if (!strcmp (arr [0], "ABC") && !strcmp (arr [1], "DEF"))
2319 typedef int (*CdeclDelegate) (int i, int j);
2321 LIBTEST_API int STDCALL
2322 mono_test_marshal_cdecl_delegate (CdeclDelegate del)
2326 for (i = 0; i < 1000; ++i)
2332 typedef char** (STDCALL *ReturnStringArrayDelegate) (int i);
2334 LIBTEST_API int STDCALL
2335 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d)
2343 if (strcmp (arr [0], "ABC") || strcmp (arr [1], "DEF"))
2353 typedef int (STDCALL *ByrefStringDelegate) (char **s);
2355 LIBTEST_API int STDCALL
2356 mono_test_marshal_byref_string_delegate (ByrefStringDelegate d)
2358 char *s = (char*)"ABC";
2365 if (!strcmp (s, "DEF"))
2375 LIBTEST_API int STDCALL
2376 add_delegate (int i, int j)
2381 LIBTEST_API gpointer STDCALL
2382 mono_test_marshal_return_fnptr (void)
2384 return &add_delegate;
2387 LIBTEST_API int STDCALL
2390 printf ("codigo %x\n", code);
2398 LIBTEST_API HandleRef STDCALL
2399 mono_xr_as_handle (int code)
2403 memset (&ref, 0, sizeof (ref));
2415 LIBTEST_API int STDCALL
2416 mono_safe_handle_struct_ref (HandleStructs *x)
2418 printf ("Dingus Ref! \n");
2419 printf ("Values: %d %d %p %p\n", x->a, x->b, x->handle1, x->handle2);
2425 if (x->handle1 != (void*) 0x7080feed)
2428 if (x->handle2 != (void*) 0x1234abcd)
2434 LIBTEST_API int STDCALL
2435 mono_safe_handle_struct (HandleStructs x)
2437 printf ("Dingus Standard! \n");
2438 printf ("Values: %d %d %p %p\n", x.a, x.b, x.handle1, x.handle2);
2444 if (x.handle1 != (void*) 0x7080feed)
2447 if (x.handle2 != (void*) 0x1234abcd)
2457 LIBTEST_API int STDCALL
2458 mono_safe_handle_struct_simple (TrivialHandle x)
2460 printf ("The value is %p\n", x.a);
2461 return ((int)(gsize)x.a) * 2;
2464 LIBTEST_API int STDCALL
2465 mono_safe_handle_return (void)
2470 LIBTEST_API void STDCALL
2471 mono_safe_handle_ref (void **handle)
2474 *handle = (void *) 0xbad;
2478 *handle = (void *) 0x800d;
2481 LIBTEST_API double STDCALL
2482 mono_test_marshal_date_time (double d, double *d2)
2554 VT_USERDEFINED = 29,
2562 VT_STREAMED_OBJECT = 68,
2563 VT_STORED_OBJECT = 69,
2564 VT_BLOB_OBJECT = 70,
2572 void VariantInit(VARIANT* vt)
2589 LIBTEST_API int STDCALL
2590 mono_test_marshal_bstr_in(gunichar2* bstr)
2593 gchar* bstr_utf8 = g_utf16_to_utf8 (bstr, -1, NULL, NULL, NULL);
2594 result = strcmp("mono_test_marshal_bstr_in", bstr_utf8);
2601 LIBTEST_API int STDCALL
2602 mono_test_marshal_bstr_out(gunichar2** bstr)
2604 *bstr = marshal_bstr_alloc ("mono_test_marshal_bstr_out");
2608 LIBTEST_API int STDCALL
2609 mono_test_marshal_bstr_in_null(gunichar2* bstr)
2616 LIBTEST_API int STDCALL
2617 mono_test_marshal_bstr_out_null(gunichar2** bstr)
2623 LIBTEST_API int STDCALL
2624 mono_test_marshal_variant_in_sbyte(VARIANT variant)
2626 if (variant.vt == VT_I1 && variant.cVal == 100)
2631 LIBTEST_API int STDCALL
2632 mono_test_marshal_variant_in_byte(VARIANT variant)
2634 if (variant.vt == VT_UI1 && variant.bVal == 100)
2639 LIBTEST_API int STDCALL
2640 mono_test_marshal_variant_in_short(VARIANT variant)
2642 if (variant.vt == VT_I2 && variant.iVal == 314)
2647 LIBTEST_API int STDCALL
2648 mono_test_marshal_variant_in_ushort(VARIANT variant)
2650 if (variant.vt == VT_UI2 && variant.uiVal == 314)
2655 LIBTEST_API int STDCALL
2656 mono_test_marshal_variant_in_int(VARIANT variant)
2658 if (variant.vt == VT_I4 && variant.lVal == 314)
2663 LIBTEST_API int STDCALL
2664 mono_test_marshal_variant_in_uint(VARIANT variant)
2666 if (variant.vt == VT_UI4 && variant.ulVal == 314)
2671 LIBTEST_API int STDCALL
2672 mono_test_marshal_variant_in_long(VARIANT variant)
2674 if (variant.vt == VT_I8 && variant.llVal == 314)
2679 LIBTEST_API int STDCALL
2680 mono_test_marshal_variant_in_ulong(VARIANT variant)
2682 if (variant.vt == VT_UI8 && variant.ullVal == 314)
2687 LIBTEST_API int STDCALL
2688 mono_test_marshal_variant_in_float(VARIANT variant)
2690 if (variant.vt == VT_R4 && (variant.fltVal - 3.14)/3.14 < .001)
2695 LIBTEST_API int STDCALL
2696 mono_test_marshal_variant_in_double(VARIANT variant)
2698 if (variant.vt == VT_R8 && (variant.dblVal - 3.14)/3.14 < .001)
2703 LIBTEST_API int STDCALL
2704 mono_test_marshal_variant_in_bstr(VARIANT variant)
2707 gchar* bstr_utf8 = g_utf16_to_utf8 (variant.bstrVal, -1, NULL, NULL, NULL);
2708 result = strcmp("PI", bstr_utf8);
2711 if (variant.vt == VT_BSTR && !result)
2716 LIBTEST_API int STDCALL
2717 mono_test_marshal_variant_in_bool_true (VARIANT variant)
2719 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_TRUE)
2724 LIBTEST_API int STDCALL
2725 mono_test_marshal_variant_in_bool_false (VARIANT variant)
2727 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_FALSE)
2732 LIBTEST_API int STDCALL
2733 mono_test_marshal_variant_out_sbyte(VARIANT* variant)
2735 variant->vt = VT_I1;
2736 variant->cVal = 100;
2741 LIBTEST_API int STDCALL
2742 mono_test_marshal_variant_out_sbyte_byref(VARIANT* variant)
2744 variant->vt = VT_I1|VT_BYREF;
2745 variant->byref = marshal_alloc(1);
2746 *((gint8*)variant->byref) = 100;
2751 LIBTEST_API int STDCALL
2752 mono_test_marshal_variant_out_byte(VARIANT* variant)
2754 variant->vt = VT_UI1;
2755 variant->bVal = 100;
2760 LIBTEST_API int STDCALL
2761 mono_test_marshal_variant_out_byte_byref(VARIANT* variant)
2763 variant->vt = VT_UI1|VT_BYREF;
2764 variant->byref = marshal_alloc(1);
2765 *((gint8*)variant->byref) = 100;
2770 LIBTEST_API int STDCALL
2771 mono_test_marshal_variant_out_short(VARIANT* variant)
2773 variant->vt = VT_I2;
2774 variant->iVal = 314;
2779 LIBTEST_API int STDCALL
2780 mono_test_marshal_variant_out_short_byref(VARIANT* variant)
2782 variant->vt = VT_I2|VT_BYREF;
2783 variant->byref = marshal_alloc(2);
2784 *((gint16*)variant->byref) = 314;
2789 LIBTEST_API int STDCALL
2790 mono_test_marshal_variant_out_ushort(VARIANT* variant)
2792 variant->vt = VT_UI2;
2793 variant->uiVal = 314;
2798 LIBTEST_API int STDCALL
2799 mono_test_marshal_variant_out_ushort_byref(VARIANT* variant)
2801 variant->vt = VT_UI2|VT_BYREF;
2802 variant->byref = marshal_alloc(2);
2803 *((guint16*)variant->byref) = 314;
2808 LIBTEST_API int STDCALL
2809 mono_test_marshal_variant_out_int(VARIANT* variant)
2811 variant->vt = VT_I4;
2812 variant->lVal = 314;
2817 LIBTEST_API int STDCALL
2818 mono_test_marshal_variant_out_int_byref(VARIANT* variant)
2820 variant->vt = VT_I4|VT_BYREF;
2821 variant->byref = marshal_alloc(4);
2822 *((gint32*)variant->byref) = 314;
2827 LIBTEST_API int STDCALL
2828 mono_test_marshal_variant_out_uint(VARIANT* variant)
2830 variant->vt = VT_UI4;
2831 variant->ulVal = 314;
2836 LIBTEST_API int STDCALL
2837 mono_test_marshal_variant_out_uint_byref(VARIANT* variant)
2839 variant->vt = VT_UI4|VT_BYREF;
2840 variant->byref = marshal_alloc(4);
2841 *((guint32*)variant->byref) = 314;
2846 LIBTEST_API int STDCALL
2847 mono_test_marshal_variant_out_long(VARIANT* variant)
2849 variant->vt = VT_I8;
2850 variant->llVal = 314;
2855 LIBTEST_API int STDCALL
2856 mono_test_marshal_variant_out_long_byref(VARIANT* variant)
2858 variant->vt = VT_I8|VT_BYREF;
2859 variant->byref = marshal_alloc(8);
2860 *((gint64*)variant->byref) = 314;
2865 LIBTEST_API int STDCALL
2866 mono_test_marshal_variant_out_ulong(VARIANT* variant)
2868 variant->vt = VT_UI8;
2869 variant->ullVal = 314;
2874 LIBTEST_API int STDCALL
2875 mono_test_marshal_variant_out_ulong_byref(VARIANT* variant)
2877 variant->vt = VT_UI8|VT_BYREF;
2878 variant->byref = marshal_alloc(8);
2879 *((guint64*)variant->byref) = 314;
2884 LIBTEST_API int STDCALL
2885 mono_test_marshal_variant_out_float(VARIANT* variant)
2887 variant->vt = VT_R4;
2888 variant->fltVal = 3.14;
2893 LIBTEST_API int STDCALL
2894 mono_test_marshal_variant_out_float_byref(VARIANT* variant)
2896 variant->vt = VT_R4|VT_BYREF;
2897 variant->byref = marshal_alloc(4);
2898 *((float*)variant->byref) = 3.14;
2903 LIBTEST_API int STDCALL
2904 mono_test_marshal_variant_out_double(VARIANT* variant)
2906 variant->vt = VT_R8;
2907 variant->dblVal = 3.14;
2912 LIBTEST_API int STDCALL
2913 mono_test_marshal_variant_out_double_byref(VARIANT* variant)
2915 variant->vt = VT_R8|VT_BYREF;
2916 variant->byref = marshal_alloc(8);
2917 *((double*)variant->byref) = 3.14;
2922 LIBTEST_API int STDCALL
2923 mono_test_marshal_variant_out_bstr(VARIANT* variant)
2925 variant->vt = VT_BSTR;
2926 variant->bstrVal = marshal_bstr_alloc("PI");
2931 LIBTEST_API int STDCALL
2932 mono_test_marshal_variant_out_bstr_byref(VARIANT* variant)
2934 variant->vt = VT_BSTR|VT_BYREF;
2935 variant->byref = marshal_alloc(sizeof(gpointer));
2936 *((gunichar**)variant->byref) = (gunichar*)marshal_bstr_alloc("PI");
2941 LIBTEST_API int STDCALL
2942 mono_test_marshal_variant_out_bool_true (VARIANT* variant)
2944 variant->vt = VT_BOOL;
2945 variant->boolVal = VARIANT_TRUE;
2950 LIBTEST_API int STDCALL
2951 mono_test_marshal_variant_out_bool_true_byref (VARIANT* variant)
2953 variant->vt = VT_BOOL|VT_BYREF;
2954 variant->byref = marshal_alloc(2);
2955 *((gint16*)variant->byref) = VARIANT_TRUE;
2960 LIBTEST_API int STDCALL
2961 mono_test_marshal_variant_out_bool_false (VARIANT* variant)
2963 variant->vt = VT_BOOL;
2964 variant->boolVal = VARIANT_FALSE;
2969 LIBTEST_API int STDCALL
2970 mono_test_marshal_variant_out_bool_false_byref (VARIANT* variant)
2972 variant->vt = VT_BOOL|VT_BYREF;
2973 variant->byref = marshal_alloc(2);
2974 *((gint16*)variant->byref) = VARIANT_FALSE;
2979 typedef int (STDCALL *VarFunc) (int vt, VARIANT variant);
2980 typedef int (STDCALL *VarRefFunc) (int vt, VARIANT* variant);
2982 LIBTEST_API int STDCALL
2983 mono_test_marshal_variant_in_sbyte_unmanaged(VarFunc func)
2988 return func (VT_I1, vt);
2991 LIBTEST_API int STDCALL
2992 mono_test_marshal_variant_in_byte_unmanaged(VarFunc func)
2997 return func (VT_UI1, vt);
3000 LIBTEST_API int STDCALL
3001 mono_test_marshal_variant_in_short_unmanaged(VarFunc func)
3006 return func (VT_I2, vt);
3009 LIBTEST_API int STDCALL
3010 mono_test_marshal_variant_in_ushort_unmanaged(VarFunc func)
3015 return func (VT_UI2, vt);
3018 LIBTEST_API int STDCALL
3019 mono_test_marshal_variant_in_int_unmanaged(VarFunc func)
3024 return func (VT_I4, vt);
3027 LIBTEST_API int STDCALL
3028 mono_test_marshal_variant_in_uint_unmanaged(VarFunc func)
3033 return func (VT_UI4, vt);
3036 LIBTEST_API int STDCALL
3037 mono_test_marshal_variant_in_long_unmanaged(VarFunc func)
3042 return func (VT_I8, vt);
3045 LIBTEST_API int STDCALL
3046 mono_test_marshal_variant_in_ulong_unmanaged(VarFunc func)
3051 return func (VT_UI8, vt);
3054 LIBTEST_API int STDCALL
3055 mono_test_marshal_variant_in_float_unmanaged(VarFunc func)
3060 return func (VT_R4, vt);
3063 LIBTEST_API int STDCALL
3064 mono_test_marshal_variant_in_double_unmanaged(VarFunc func)
3069 return func (VT_R8, vt);
3072 LIBTEST_API int STDCALL
3073 mono_test_marshal_variant_in_bstr_unmanaged(VarFunc func)
3077 vt.bstrVal = marshal_bstr_alloc("PI");
3078 return func (VT_BSTR, vt);
3081 LIBTEST_API int STDCALL
3082 mono_test_marshal_variant_in_bool_true_unmanaged(VarFunc func)
3086 vt.boolVal = VARIANT_TRUE;
3087 return func (VT_BOOL, vt);
3090 LIBTEST_API int STDCALL
3091 mono_test_marshal_variant_in_bool_false_unmanaged(VarFunc func)
3095 vt.boolVal = VARIANT_FALSE;
3096 return func (VT_BOOL, vt);
3099 LIBTEST_API int STDCALL
3100 mono_test_marshal_variant_out_sbyte_unmanaged(VarRefFunc func)
3105 if (vt.vt == VT_I1 && vt.cVal == -100)
3110 LIBTEST_API int STDCALL
3111 mono_test_marshal_variant_out_byte_unmanaged(VarRefFunc func)
3116 if (vt.vt == VT_UI1 && vt.bVal == 100)
3121 LIBTEST_API int STDCALL
3122 mono_test_marshal_variant_out_short_unmanaged(VarRefFunc func)
3127 if (vt.vt == VT_I2 && vt.iVal == -100)
3132 LIBTEST_API int STDCALL
3133 mono_test_marshal_variant_out_ushort_unmanaged(VarRefFunc func)
3138 if (vt.vt == VT_UI2 && vt.uiVal == 100)
3143 LIBTEST_API int STDCALL
3144 mono_test_marshal_variant_out_int_unmanaged(VarRefFunc func)
3149 if (vt.vt == VT_I4 && vt.lVal == -100)
3154 LIBTEST_API int STDCALL
3155 mono_test_marshal_variant_out_uint_unmanaged(VarRefFunc func)
3160 if (vt.vt == VT_UI4 && vt.ulVal == 100)
3165 LIBTEST_API int STDCALL
3166 mono_test_marshal_variant_out_long_unmanaged(VarRefFunc func)
3171 if (vt.vt == VT_I8 && vt.llVal == -100)
3176 LIBTEST_API int STDCALL
3177 mono_test_marshal_variant_out_ulong_unmanaged(VarRefFunc func)
3182 if (vt.vt == VT_UI8 && vt.ullVal == 100)
3187 LIBTEST_API int STDCALL
3188 mono_test_marshal_variant_out_float_unmanaged(VarRefFunc func)
3193 if (vt.vt == VT_R4 && fabs (vt.fltVal - 3.14f) < 1e-10)
3198 LIBTEST_API int STDCALL
3199 mono_test_marshal_variant_out_double_unmanaged(VarRefFunc func)
3204 if (vt.vt == VT_R8 && fabs (vt.dblVal - 3.14) < 1e-10)
3209 LIBTEST_API int STDCALL
3210 mono_test_marshal_variant_out_bstr_unmanaged(VarRefFunc func)
3218 func (VT_BSTR, &vt);
3219 bstr_utf8 = g_utf16_to_utf8 (vt.bstrVal, -1, NULL, NULL, NULL);
3220 result = strcmp("PI", bstr_utf8);
3222 if (vt.vt == VT_BSTR && !result)
3227 LIBTEST_API int STDCALL
3228 mono_test_marshal_variant_out_bool_true_unmanaged(VarRefFunc func)
3232 func (VT_BOOL, &vt);
3233 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3238 LIBTEST_API int STDCALL
3239 mono_test_marshal_variant_out_bool_false_unmanaged(VarRefFunc func)
3243 func (VT_BOOL, &vt);
3244 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3249 typedef struct MonoComObject MonoComObject;
3253 int (STDCALL *QueryInterface)(MonoComObject* pUnk, gpointer riid, gpointer* ppv);
3254 int (STDCALL *AddRef)(MonoComObject* pUnk);
3255 int (STDCALL *Release)(MonoComObject* pUnk);
3256 int (STDCALL *get_ITest)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3257 int (STDCALL *SByteIn)(MonoComObject* pUnk, char a);
3258 int (STDCALL *ByteIn)(MonoComObject* pUnk, unsigned char a);
3259 int (STDCALL *ShortIn)(MonoComObject* pUnk, short a);
3260 int (STDCALL *UShortIn)(MonoComObject* pUnk, unsigned short a);
3261 int (STDCALL *IntIn)(MonoComObject* pUnk, int a);
3262 int (STDCALL *UIntIn)(MonoComObject* pUnk, unsigned int a);
3263 int (STDCALL *LongIn)(MonoComObject* pUnk, gint64 a);
3264 int (STDCALL *ULongIn)(MonoComObject* pUnk, guint64 a);
3265 int (STDCALL *FloatIn)(MonoComObject* pUnk, float a);
3266 int (STDCALL *DoubleIn)(MonoComObject* pUnk, double a);
3267 int (STDCALL *ITestIn)(MonoComObject* pUnk, MonoComObject* pUnk2);
3268 int (STDCALL *ITestOut)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3271 struct MonoComObject
3277 static GUID IID_ITest = {0, 0, 0, {0,0,0,0,0,0,0,1}};
3278 static GUID IID_IMonoUnknown = {0, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3279 static GUID IID_IMonoDispatch = {0x00020400, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3281 LIBTEST_API int STDCALL
3282 MonoQueryInterface(MonoComObject* pUnk, gpointer riid, gpointer* ppv)
3286 if (!memcmp(riid, &IID_IMonoUnknown, sizeof(GUID))) {
3290 else if (!memcmp(riid, &IID_ITest, sizeof(GUID))) {
3294 else if (!memcmp(riid, &IID_IMonoDispatch, sizeof(GUID))) {
3298 return 0x80004002; //E_NOINTERFACE;
3301 LIBTEST_API int STDCALL
3302 MonoAddRef(MonoComObject* pUnk)
3304 return ++(pUnk->m_ref);
3307 LIBTEST_API int STDCALL
3308 MonoRelease(MonoComObject* pUnk)
3310 return --(pUnk->m_ref);
3313 LIBTEST_API int STDCALL
3314 SByteIn(MonoComObject* pUnk, char a)
3319 LIBTEST_API int STDCALL
3320 ByteIn(MonoComObject* pUnk, unsigned char a)
3325 LIBTEST_API int STDCALL
3326 ShortIn(MonoComObject* pUnk, short a)
3331 LIBTEST_API int STDCALL
3332 UShortIn(MonoComObject* pUnk, unsigned short a)
3337 LIBTEST_API int STDCALL
3338 IntIn(MonoComObject* pUnk, int a)
3343 LIBTEST_API int STDCALL
3344 UIntIn(MonoComObject* pUnk, unsigned int a)
3349 LIBTEST_API int STDCALL
3350 LongIn(MonoComObject* pUnk, gint64 a)
3355 LIBTEST_API int STDCALL
3356 ULongIn(MonoComObject* pUnk, guint64 a)
3361 LIBTEST_API int STDCALL
3362 FloatIn(MonoComObject* pUnk, float a)
3367 LIBTEST_API int STDCALL
3368 DoubleIn(MonoComObject* pUnk, double a)
3373 LIBTEST_API int STDCALL
3374 ITestIn(MonoComObject* pUnk, MonoComObject *pUnk2)
3379 LIBTEST_API int STDCALL
3380 ITestOut(MonoComObject* pUnk, MonoComObject* *ppUnk)
3385 static void create_com_object (MonoComObject** pOut);
3387 LIBTEST_API int STDCALL
3388 get_ITest(MonoComObject* pUnk, MonoComObject* *ppUnk)
3390 create_com_object (ppUnk);
3394 static void create_com_object (MonoComObject** pOut)
3396 *pOut = marshal_new0 (MonoComObject, 1);
3397 (*pOut)->vtbl = marshal_new0 (MonoIUnknown, 1);
3400 (*pOut)->vtbl->QueryInterface = MonoQueryInterface;
3401 (*pOut)->vtbl->AddRef = MonoAddRef;
3402 (*pOut)->vtbl->Release = MonoRelease;
3403 (*pOut)->vtbl->SByteIn = SByteIn;
3404 (*pOut)->vtbl->ByteIn = ByteIn;
3405 (*pOut)->vtbl->ShortIn = ShortIn;
3406 (*pOut)->vtbl->UShortIn = UShortIn;
3407 (*pOut)->vtbl->IntIn = IntIn;
3408 (*pOut)->vtbl->UIntIn = UIntIn;
3409 (*pOut)->vtbl->LongIn = LongIn;
3410 (*pOut)->vtbl->ULongIn = ULongIn;
3411 (*pOut)->vtbl->FloatIn = FloatIn;
3412 (*pOut)->vtbl->DoubleIn = DoubleIn;
3413 (*pOut)->vtbl->ITestIn = ITestIn;
3414 (*pOut)->vtbl->ITestOut = ITestOut;
3415 (*pOut)->vtbl->get_ITest = get_ITest;
3418 static MonoComObject* same_object = NULL;
3420 LIBTEST_API int STDCALL
3421 mono_test_marshal_com_object_create(MonoComObject* *pUnk)
3423 create_com_object (pUnk);
3426 same_object = *pUnk;
3431 LIBTEST_API int STDCALL
3432 mono_test_marshal_com_object_same(MonoComObject* *pUnk)
3434 *pUnk = same_object;
3439 LIBTEST_API int STDCALL
3440 mono_test_marshal_com_object_destroy(MonoComObject *pUnk)
3442 int ref = --(pUnk->m_ref);
3449 LIBTEST_API int STDCALL
3450 mono_test_marshal_com_object_ref_count(MonoComObject *pUnk)
3455 LIBTEST_API int STDCALL
3456 mono_test_marshal_ccw_itest (MonoComObject *pUnk)
3459 MonoComObject* pTest;
3464 hr = pUnk->vtbl->SByteIn (pUnk, -100);
3467 hr = pUnk->vtbl->ByteIn (pUnk, 100);
3470 hr = pUnk->vtbl->ShortIn (pUnk, -100);
3473 hr = pUnk->vtbl->UShortIn (pUnk, 100);
3476 hr = pUnk->vtbl->IntIn (pUnk, -100);
3479 hr = pUnk->vtbl->UIntIn (pUnk, 100);
3482 hr = pUnk->vtbl->LongIn (pUnk, -100);
3485 hr = pUnk->vtbl->ULongIn (pUnk, 100);
3488 hr = pUnk->vtbl->FloatIn (pUnk, 3.14f);
3491 hr = pUnk->vtbl->DoubleIn (pUnk, 3.14);
3494 hr = pUnk->vtbl->ITestIn (pUnk, pUnk);
3497 hr = pUnk->vtbl->ITestOut (pUnk, &pTest);
3505 * mono_method_get_unmanaged_thunk tests
3508 #if defined(__GNUC__) && ((defined(__i386__) && (defined(__linux__) || defined (__APPLE__)) || defined (__FreeBSD__) || defined(__OpenBSD__)) || (defined(__ppc__) && defined(__APPLE__)))
3509 #define ALIGN(size) __attribute__ ((aligned(size)))
3515 /* thunks.cs:TestStruct */
3516 typedef struct _TestStruct {
3521 /* Searches for mono symbols in all loaded modules */
3523 lookup_mono_symbol (const char *symbol_name)
3526 if (g_module_symbol (g_module_open (NULL, G_MODULE_BIND_LAZY), symbol_name, &symbol))
3532 LIBTEST_API gpointer STDCALL
3533 mono_test_marshal_lookup_symbol (const char *symbol_name)
3535 return lookup_mono_symbol (symbol_name);
3539 * test_method_thunk:
3541 * @test_id: the test number
3542 * @test_method_handle: MonoMethod* of the C# test method
3543 * @create_object_method_handle: MonoMethod* of thunks.cs:Test.CreateObject
3545 LIBTEST_API int STDCALL
3546 test_method_thunk (int test_id, gpointer test_method_handle, gpointer create_object_method_handle)
3548 gpointer (*mono_method_get_unmanaged_thunk)(gpointer)
3549 = lookup_mono_symbol ("mono_method_get_unmanaged_thunk");
3551 gpointer (*mono_string_new_wrapper)(const char *)
3552 = lookup_mono_symbol ("mono_string_new_wrapper");
3554 char* (*mono_string_to_utf8)(gpointer)
3555 = lookup_mono_symbol ("mono_string_to_utf8");
3557 gpointer (*mono_object_unbox)(gpointer)
3558 = lookup_mono_symbol ("mono_object_unbox");
3560 gpointer test_method, ex = NULL;
3561 gpointer (STDCALL *CreateObject)(gpointer*);
3563 if (!mono_method_get_unmanaged_thunk)
3566 test_method = mono_method_get_unmanaged_thunk (test_method_handle);
3570 CreateObject = mono_method_get_unmanaged_thunk (create_object_method_handle);
3578 /* thunks.cs:Test.Test0 */
3579 void (STDCALL *F)(gpointer*) = test_method;
3585 /* thunks.cs:Test.Test1 */
3586 int (STDCALL *F)(gpointer*) = test_method;
3593 /* thunks.cs:Test.Test2 */
3594 gpointer (STDCALL *F)(gpointer, gpointer*) = test_method;
3595 gpointer str = mono_string_new_wrapper ("foo");
3596 if (str != F (str, &ex))
3602 /* thunks.cs:Test.Test3 */
3603 gpointer (STDCALL *F)(gpointer, gpointer, gpointer*);
3608 obj = CreateObject (&ex);
3609 str = mono_string_new_wrapper ("bar");
3611 if (str != F (obj, str, &ex))
3617 /* thunks.cs:Test.Test4 */
3618 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3623 obj = CreateObject (&ex);
3624 str = mono_string_new_wrapper ("bar");
3626 if (42 != F (obj, str, 42, &ex))
3633 /* thunks.cs:Test.Test5 */
3634 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3639 obj = CreateObject (&ex);
3640 str = mono_string_new_wrapper ("bar");
3642 F (obj, str, 42, &ex);
3650 /* thunks.cs:Test.Test6 */
3651 int (STDCALL *F)(gpointer, guint8, gint16, gint32, gint64, float, double,
3652 gpointer, gpointer*);
3654 gpointer str = mono_string_new_wrapper ("Test6");
3658 obj = CreateObject (&ex);
3660 res = F (obj, 254, 32700, -245378, 6789600, 3.1415, 3.1415, str, &ex);
3671 /* thunks.cs:Test.Test7 */
3672 gint64 (STDCALL *F)(gpointer*) = test_method;
3673 if (F (&ex) != G_MAXINT64)
3679 /* thunks.cs:Test.Test8 */
3680 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3681 gpointer*, gpointer*);
3693 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3701 (fabs (a5 - 3.1415) < 0.001) &&
3702 (fabs (a6 - 3.1415) < 0.001) &&
3703 strcmp (mono_string_to_utf8 (a7), "Test8") == 0))
3710 /* thunks.cs:Test.Test9 */
3711 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3712 gpointer*, gpointer*);
3724 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3732 /* thunks.cs:Test.Test10 */
3733 void (STDCALL *F)(gpointer*, gpointer*);
3735 gpointer obj1, obj2;
3737 obj1 = obj2 = CreateObject (&ex);
3754 /* thunks.cs:TestStruct.Test0 */
3755 int (STDCALL *F)(gpointer*, gpointer*);
3761 obj = CreateObject (&ex);
3768 a1 = mono_object_unbox (obj);
3784 /* check whether the call was really by value */
3785 if (a1->A != 42 || a1->B != 3.1415)
3792 /* thunks.cs:TestStruct.Test1 */
3793 void (STDCALL *F)(gpointer, gpointer*);
3798 obj = CreateObject (&ex);
3805 a1 = mono_object_unbox (obj);
3818 if (!fabs (a1->B - 3.1415) < 0.001)
3825 /* thunks.cs:TestStruct.Test2 */
3826 gpointer (STDCALL *F)(gpointer*);
3840 a1 = mono_object_unbox (obj);
3845 if (!fabs (a1->B - 3.1415) < 0.001)
3852 /* thunks.cs:TestStruct.Test3 */
3853 void (STDCALL *F)(gpointer, gpointer*);
3858 obj = CreateObject (&ex);
3865 a1 = mono_object_unbox (obj);
3901 LIBTEST_API int STDCALL
3902 mono_test_Winx64_struct1_in (winx64_struct1 var)
3915 LIBTEST_API int STDCALL
3916 mono_test_Winx64_struct2_in (winx64_struct2 var)
3933 LIBTEST_API int STDCALL
3934 mono_test_Winx64_struct3_in (winx64_struct3 var)
3940 if (var.c != 0x1234)
3953 LIBTEST_API int STDCALL
3954 mono_test_Winx64_struct4_in (winx64_struct4 var)
3960 if (var.c != 0x1234)
3962 if (var.d != 0x87654321)
3974 LIBTEST_API int STDCALL
3975 mono_test_Winx64_struct5_in (winx64_struct5 var)
3993 LIBTEST_API int STDCALL
3994 mono_test_Winx64_struct6_in (winx64_struct6 var)
4005 LIBTEST_API int STDCALL
4006 mono_test_Winx64_structs_in1 (winx64_struct1 var1,
4007 winx64_struct2 var2,
4008 winx64_struct3 var3,
4009 winx64_struct4 var4)
4023 if (var3.c != 0x1234)
4030 if (var4.c != 0x1234)
4032 if (var4.d != 0x87654321)
4037 LIBTEST_API int STDCALL
4038 mono_test_Winx64_structs_in2 (winx64_struct1 var1,
4039 winx64_struct1 var2,
4040 winx64_struct1 var3,
4041 winx64_struct1 var4,
4042 winx64_struct1 var5)
4058 LIBTEST_API int STDCALL
4059 mono_test_Winx64_structs_in3 (winx64_struct1 var1,
4060 winx64_struct5 var2,
4061 winx64_struct1 var3,
4062 winx64_struct5 var4,
4063 winx64_struct1 var5,
4064 winx64_struct5 var6)
4099 LIBTEST_API winx64_struct1 STDCALL
4100 mono_test_Winx64_struct1_ret (void)
4107 LIBTEST_API winx64_struct2 STDCALL
4108 mono_test_Winx64_struct2_ret (void)
4116 LIBTEST_API winx64_struct3 STDCALL
4117 mono_test_Winx64_struct3_ret (void)
4126 LIBTEST_API winx64_struct4 STDCALL
4127 mono_test_Winx64_struct4_ret (void)
4137 LIBTEST_API winx64_struct5 STDCALL
4138 mono_test_Winx64_struct5_ret (void)
4147 LIBTEST_API winx64_struct1 STDCALL
4148 mono_test_Winx64_struct1_ret_5_args (char a, char b, char c, char d, char e)
4151 ret.a = a + b + c + d + e;
4155 LIBTEST_API winx64_struct5 STDCALL
4156 mono_test_Winx64_struct5_ret6_args (char a, char b, char c, char d, char e)
4169 } winx64_floatStruct;
4171 LIBTEST_API int STDCALL
4172 mono_test_Winx64_floatStruct (winx64_floatStruct a)
4174 if (a.a > 5.6 || a.a < 5.4)
4177 if (a.b > 9.6 || a.b < 9.4)
4186 } winx64_doubleStruct;
4188 LIBTEST_API int STDCALL
4189 mono_test_Winx64_doubleStruct (winx64_doubleStruct a)
4191 if (a.a > 5.6 || a.a < 5.4)
4197 typedef int (STDCALL *managed_struct1_delegate) (winx64_struct1 a);
4199 LIBTEST_API int STDCALL
4200 mono_test_managed_Winx64_struct1_in(managed_struct1_delegate func)
4207 typedef int (STDCALL *managed_struct5_delegate) (winx64_struct5 a);
4209 LIBTEST_API int STDCALL
4210 mono_test_managed_Winx64_struct5_in(managed_struct5_delegate func)
4219 typedef int (STDCALL *managed_struct1_struct5_delegate) (winx64_struct1 a, winx64_struct5 b,
4220 winx64_struct1 c, winx64_struct5 d,
4221 winx64_struct1 e, winx64_struct5 f);
4223 LIBTEST_API int STDCALL
4224 mono_test_managed_Winx64_struct1_struct5_in(managed_struct1_struct5_delegate func)
4226 winx64_struct1 a, c, e;
4227 winx64_struct5 b, d, f;
4229 b.a = 2; b.b = 3; b.c = 4;
4231 d.a = 6; d.b = 7; d.c = 8;
4233 f.a = 10; f.b = 11; f.c = 12;
4235 return func (a, b, c, d, e, f);
4238 typedef winx64_struct1 (STDCALL *managed_struct1_ret_delegate) (void);
4240 LIBTEST_API int STDCALL
4241 mono_test_Winx64_struct1_ret_managed (managed_struct1_ret_delegate func)
4253 typedef winx64_struct5 (STDCALL *managed_struct5_ret_delegate) (void);
4255 LIBTEST_API int STDCALL
4256 mono_test_Winx64_struct5_ret_managed (managed_struct5_ret_delegate func)
4272 LIBTEST_API int STDCALL
4273 mono_test_marshal_bool_in (int arg, unsigned int expected, unsigned int bDefaultMarsh, unsigned int bBoolCustMarsh,
4274 char bI1CustMarsh, unsigned char bU1CustMarsh, short bVBCustMarsh)
4278 if (bDefaultMarsh != expected)
4282 if (bBoolCustMarsh != expected)
4286 if (bI1CustMarsh != expected)
4290 if (bU1CustMarsh != expected)
4294 if (bVBCustMarsh != expected)
4303 LIBTEST_API int STDCALL
4304 mono_test_marshal_bool_out (int arg, unsigned int testVal, unsigned int* bDefaultMarsh, unsigned int* bBoolCustMarsh,
4305 char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh)
4311 *bDefaultMarsh = testVal;
4314 if (!bBoolCustMarsh)
4316 *bBoolCustMarsh = testVal;
4321 *bI1CustMarsh = (char)testVal;
4326 *bU1CustMarsh = (unsigned char)testVal;
4331 *bVBCustMarsh = (unsigned short)testVal;
4339 LIBTEST_API int STDCALL
4340 mono_test_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4341 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh,
4342 unsigned short* bVBCustMarsh)
4348 if (*bDefaultMarsh != expected)
4350 *bDefaultMarsh = testVal;
4353 if (!bBoolCustMarsh)
4355 if (*bBoolCustMarsh != expected)
4357 *bBoolCustMarsh = testVal;
4362 if (*bI1CustMarsh != expected)
4364 *bI1CustMarsh = (char)testVal;
4369 if (*bU1CustMarsh != expected)
4371 *bU1CustMarsh = (unsigned char)testVal;
4376 if (*bVBCustMarsh != expected)
4378 *bVBCustMarsh = (unsigned short)testVal;
4387 typedef int (STDCALL *MarshalBoolInDelegate) (int arg, unsigned int expected, unsigned int bDefaultMarsh,
4388 unsigned int bBoolCustMarsh, char bI1CustMarsh, unsigned char bU1CustMarsh, unsigned short bVBCustMarsh);
4390 LIBTEST_API int STDCALL
4391 mono_test_managed_marshal_bool_in (int arg, unsigned int expected, unsigned int testVal, MarshalBoolInDelegate pfcn)
4398 return pfcn (arg, expected, testVal, 0, 0, 0, 0);
4400 return pfcn (arg, expected, 0, testVal, 0, 0, 0);
4402 return pfcn (arg, expected, 0, 0, testVal, 0, 0);
4404 return pfcn (arg, expected, 0, 0, 0, testVal, 0);
4406 return pfcn (arg, expected, 0, 0, 0, 0, testVal);
4414 typedef int (STDCALL *MarshalBoolOutDelegate) (int arg, unsigned int expected, unsigned int* bDefaultMarsh,
4415 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4417 LIBTEST_API int STDCALL
4418 mono_test_managed_marshal_bool_out (int arg, unsigned int expected, unsigned int testVal, MarshalBoolOutDelegate pfcn)
4421 unsigned int lDefaultMarsh, lBoolCustMarsh;
4422 char lI1CustMarsh = 0;
4423 unsigned char lU1CustMarsh = 0;
4424 unsigned short lVBCustMarsh = 0;
4425 lDefaultMarsh = lBoolCustMarsh = 0;
4432 unsigned int ltVal = 0;
4433 ret = pfcn (arg, testVal, <Val, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4435 return 0x0100 + ret;
4436 if (expected != ltVal)
4441 unsigned int ltVal = 0;
4442 ret = pfcn (arg, testVal, &lDefaultMarsh, <Val, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4444 return 0x0300 + ret;
4445 if (expected != ltVal)
4451 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, <Val, &lU1CustMarsh, &lVBCustMarsh);
4453 return 0x0500 + ret;
4454 if (expected != ltVal)
4459 unsigned char ltVal = 0;
4460 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <Val, &lVBCustMarsh);
4462 return 0x0700 + ret;
4463 if (expected != ltVal)
4468 unsigned short ltVal = 0;
4469 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <Val);
4471 return 0x0900 + ret;
4472 if (expected != ltVal)
4483 typedef int (STDCALL *MarshalBoolRefDelegate) (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4484 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4486 LIBTEST_API int STDCALL
4487 mono_test_managed_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int outExpected,
4488 unsigned int outTestVal, MarshalBoolRefDelegate pfcn)
4491 unsigned int lDefaultMarsh, lBoolCustMarsh;
4492 char lI1CustMarsh = 0;
4493 unsigned char lU1CustMarsh = 0;
4494 unsigned short lVBCustMarsh = 0;
4495 lDefaultMarsh = lBoolCustMarsh = 0;
4503 unsigned int ltestVal = testVal;
4504 ret = pfcn (arg, expected, outTestVal, <estVal, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4506 return 0x0100 + ret;
4507 if (outExpected != ltestVal)
4513 unsigned int ltestVal = testVal;
4514 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, <estVal, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4516 return 0x0300 + ret;
4517 if (outExpected != ltestVal)
4523 char ltestVal = testVal;
4524 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, <estVal, &lU1CustMarsh, &lVBCustMarsh);
4526 return 0x0500 + ret;
4527 if (outExpected != ltestVal)
4533 unsigned char ltestVal = testVal;
4534 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <estVal, &lVBCustMarsh);
4536 return 0x0700 + ret;
4537 if (outExpected != ltestVal)
4543 unsigned short ltestVal = testVal;
4544 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <estVal);
4546 return 0x0900 + ret;
4547 if (outExpected != ltestVal)
4560 LIBTEST_API int STDCALL
4561 mono_test_marshal_safearray_out_1dim_vt_bstr_empty (SAFEARRAY** safearray)
4563 /* Create an empty one-dimensional array of variants */
4565 SAFEARRAYBOUND dimensions [1];
4567 dimensions [0].lLbound = 0;
4568 dimensions [0].cElements = 0;
4570 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4575 LIBTEST_API int STDCALL
4576 mono_test_marshal_safearray_out_1dim_vt_bstr (SAFEARRAY** safearray)
4578 /* Create a one-dimensional array of 10 variants filled with "0" to "9" */
4580 SAFEARRAYBOUND dimensions [1];
4586 dimensions [0].lLbound = 0;
4587 dimensions [0].cElements = 10;
4589 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4590 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4592 VariantInit (&vOut);
4594 _ltoa (i,buffer,10);
4595 vOut.bstrVal= marshal_bstr_alloc (buffer);
4597 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4598 VariantClear (&vOut);
4599 SafeArrayDestroy (pSA);
4602 VariantClear (&vOut);
4608 LIBTEST_API int STDCALL
4609 mono_test_marshal_safearray_out_2dim_vt_i4 (SAFEARRAY** safearray)
4611 /* Create a two-dimensional array of 4x3 variants filled with 11, 12, 13, etc. */
4613 SAFEARRAYBOUND dimensions [2];
4618 dimensions [0].lLbound = 0;
4619 dimensions [0].cElements = 4;
4620 dimensions [1].lLbound = 0;
4621 dimensions [1].cElements = 3;
4623 pSA= SafeArrayCreate(VT_VARIANT, 2, dimensions);
4624 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4625 for (j= dimensions [1].lLbound; j< (dimensions [1].cElements + dimensions [1].lLbound); j++) {
4627 VariantInit (&vOut);
4629 vOut.lVal = (i+1)*10+(j+1);
4632 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4633 VariantClear (&vOut);
4634 SafeArrayDestroy (pSA);
4637 VariantClear (&vOut); // does a deep destroy of source VARIANT
4644 LIBTEST_API int STDCALL
4645 mono_test_marshal_safearray_out_4dim_vt_i4 (SAFEARRAY** safearray)
4647 /* Create a four-dimensional array of 10x3x6x7 variants filled with their indices */
4648 /* Also use non zero lower bounds */
4650 SAFEARRAYBOUND dimensions [4];
4655 dimensions [0].lLbound = 15;
4656 dimensions [0].cElements = 10;
4657 dimensions [1].lLbound = 20;
4658 dimensions [1].cElements = 3;
4659 dimensions [2].lLbound = 5;
4660 dimensions [2].cElements = 6;
4661 dimensions [3].lLbound = 12;
4662 dimensions [3].cElements = 7;
4664 pSA= SafeArrayCreate (VT_VARIANT, 4, dimensions);
4666 SafeArrayAccessData (pSA, (void **)&pData);
4668 for (i= 0; i< 10*3*6*7; i++) {
4669 VariantInit(&pData [i]);
4670 pData [i].vt = VT_I4;
4673 SafeArrayUnaccessData (pSA);
4678 LIBTEST_API int STDCALL
4679 mono_test_marshal_safearray_in_byval_1dim_empty (SAFEARRAY* safearray)
4681 /* Check that array is one dimensional and empty */
4684 long lbound, ubound;
4686 dim = SafeArrayGetDim (safearray);
4690 SafeArrayGetLBound (safearray, 1, &lbound);
4691 SafeArrayGetUBound (safearray, 1, &ubound);
4693 if ((lbound > 0) || (ubound > 0))
4699 LIBTEST_API int STDCALL
4700 mono_test_marshal_safearray_in_byval_1dim_vt_i4 (SAFEARRAY* safearray)
4702 /* Check that array is one dimensional containing integers from 1 to 10 */
4705 long lbound, ubound;
4710 dim = SafeArrayGetDim (safearray);
4714 SafeArrayGetLBound (safearray, 1, &lbound);
4715 SafeArrayGetUBound (safearray, 1, &ubound);
4717 if ((lbound != 0) || (ubound != 9))
4720 SafeArrayAccessData (safearray, (void **)&pData);
4721 for (i= lbound; i <= ubound; i++) {
4722 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i + 1))
4725 SafeArrayUnaccessData (safearray);
4730 LIBTEST_API int STDCALL
4731 mono_test_marshal_safearray_in_byval_1dim_vt_mixed (SAFEARRAY* safearray)
4733 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4736 long lbound, ubound;
4743 VariantInit (&element);
4745 dim = SafeArrayGetDim (safearray);
4749 SafeArrayGetLBound (safearray, 1, &lbound);
4750 SafeArrayGetUBound (safearray, 1, &ubound);
4752 if ((lbound != 0) || (ubound != 12))
4755 SafeArrayAccessData (safearray, (void **)&pData);
4756 for (i= lbound; i <= ubound; i++) {
4757 if ((i%2 == 0) && (pData [i].vt != VT_I4))
4759 if ((i%2 == 1) && (pData [i].vt != VT_BSTR))
4761 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i))
4764 SafeArrayUnaccessData (safearray);
4766 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4771 SafeArrayPutElement (safearray, indices, &element);
4772 VariantClear (&element);
4777 LIBTEST_API int STDCALL
4778 mono_test_marshal_safearray_in_byval_2dim_vt_i4 (SAFEARRAY* safearray)
4780 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4783 long lbound1, ubound1, lbound2, ubound2;
4788 VariantInit (&element);
4790 dim = SafeArrayGetDim (safearray);
4794 SafeArrayGetLBound (safearray, 1, &lbound1);
4795 SafeArrayGetUBound (safearray, 1, &ubound1);
4797 if ((lbound1 != 0) || (ubound1 != 1))
4800 SafeArrayGetLBound (safearray, 2, &lbound2);
4801 SafeArrayGetUBound (safearray, 2, &ubound2);
4803 if ((lbound2 != 0) || (ubound2 != 3)) {
4807 for (i= lbound1; i <= ubound1; i++) {
4809 for (j= lbound2; j <= ubound2; j++) {
4811 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4813 failed = ((element.vt != VT_I4) || (element.lVal != 10*(i+1)+(j+1)));
4814 VariantClear (&element);
4820 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4826 SafeArrayPutElement (safearray, indices, &element);
4827 VariantClear (&element);
4832 LIBTEST_API int STDCALL
4833 mono_test_marshal_safearray_in_byval_3dim_vt_bstr (SAFEARRAY* safearray)
4835 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4838 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4839 long i, j, k, failed;
4843 VariantInit (&element);
4845 dim = SafeArrayGetDim (safearray);
4849 SafeArrayGetLBound (safearray, 1, &lbound1);
4850 SafeArrayGetUBound (safearray, 1, &ubound1);
4852 if ((lbound1 != 0) || (ubound1 != 1))
4855 SafeArrayGetLBound (safearray, 2, &lbound2);
4856 SafeArrayGetUBound (safearray, 2, &ubound2);
4858 if ((lbound2 != 0) || (ubound2 != 1))
4861 SafeArrayGetLBound (safearray, 3, &lbound3);
4862 SafeArrayGetUBound (safearray, 3, &ubound3);
4864 if ((lbound3 != 0) || (ubound3 != 2))
4867 for (i= lbound1; i <= ubound1; i++) {
4869 for (j= lbound2; j <= ubound2; j++) {
4871 for (k= lbound3; k <= ubound3; k++) {
4873 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4875 failed = ((element.vt != VT_BSTR)
4876 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4877 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4878 VariantClear (&element);
4885 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4890 element.vt = VT_BSTR;
4891 element.bstrVal = SysAllocString(L"Should not be copied");
4892 SafeArrayPutElement (safearray, indices, &element);
4893 VariantClear (&element);
4898 LIBTEST_API int STDCALL
4899 mono_test_marshal_safearray_in_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4901 return mono_test_marshal_safearray_in_byval_3dim_vt_bstr (*safearray);
4904 LIBTEST_API int STDCALL
4905 mono_test_marshal_safearray_in_out_byref_1dim_empty (SAFEARRAY** safearray)
4907 /* Check that the input array is what is expected and change it so the caller can check */
4908 /* correct marshalling back to managed code */
4911 long lbound, ubound;
4912 SAFEARRAYBOUND dimensions [1];
4914 wchar_t buffer [20];
4918 /* Check that in array is one dimensional and empty */
4920 dim = SafeArrayGetDim (*safearray);
4925 SafeArrayGetLBound (*safearray, 1, &lbound);
4926 SafeArrayGetUBound (*safearray, 1, &ubound);
4928 if ((lbound > 0) || (ubound > 0)) {
4932 /* Re-dimension the array and return a one-dimensional array of 8 variants filled with "0" to "7" */
4934 dimensions [0].lLbound = 0;
4935 dimensions [0].cElements = 8;
4937 hr = SafeArrayRedim (*safearray, dimensions);
4941 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
4943 VariantInit (&vOut);
4945 _ltow (i,buffer,10);
4946 vOut.bstrVal = SysAllocString (buffer);
4948 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
4949 VariantClear (&vOut);
4950 SafeArrayDestroy (*safearray);
4953 VariantClear (&vOut);
4958 LIBTEST_API int STDCALL
4959 mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4961 /* Check that the input array is what is expected and change it so the caller can check */
4962 /* correct marshalling back to managed code */
4965 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4966 SAFEARRAYBOUND dimensions [1];
4967 long i, j, k, failed;
4968 wchar_t buffer [20];
4973 VariantInit (&element);
4975 /* Check that in array is three dimensional and contains the expected values */
4977 dim = SafeArrayGetDim (*safearray);
4981 SafeArrayGetLBound (*safearray, 1, &lbound1);
4982 SafeArrayGetUBound (*safearray, 1, &ubound1);
4984 if ((lbound1 != 0) || (ubound1 != 1))
4987 SafeArrayGetLBound (*safearray, 2, &lbound2);
4988 SafeArrayGetUBound (*safearray, 2, &ubound2);
4990 if ((lbound2 != 0) || (ubound2 != 1))
4993 SafeArrayGetLBound (*safearray, 3, &lbound3);
4994 SafeArrayGetUBound (*safearray, 3, &ubound3);
4996 if ((lbound3 != 0) || (ubound3 != 2))
4999 for (i= lbound1; i <= ubound1; i++) {
5001 for (j= lbound2; j <= ubound2; j++) {
5003 for (k= lbound3; k <= ubound3; k++) {
5005 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
5007 failed = ((element.vt != VT_BSTR)
5008 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
5009 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
5010 VariantClear (&element);
5017 hr = SafeArrayDestroy (*safearray);
5021 /* Return a new one-dimensional array of 8 variants filled with "0" to "7" */
5023 dimensions [0].lLbound = 0;
5024 dimensions [0].cElements = 8;
5026 *safearray = SafeArrayCreate (VT_VARIANT, 1, dimensions);
5028 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
5030 VariantInit (&vOut);
5032 _ltow (i,buffer,10);
5033 vOut.bstrVal = SysAllocString (buffer);
5035 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
5036 VariantClear (&vOut);
5037 SafeArrayDestroy (*safearray);
5040 VariantClear (&vOut);
5045 LIBTEST_API int STDCALL
5046 mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 (SAFEARRAY** safearray)
5048 /* Check that the input array is what is expected and change it so the caller can check */
5049 /* correct marshalling back to managed code */
5052 long lbound1, ubound1;
5058 VariantInit (&element);
5060 /* Check that in array is one dimensional and contains the expected value */
5062 dim = SafeArrayGetDim (*safearray);
5066 SafeArrayGetLBound (*safearray, 1, &lbound1);
5067 SafeArrayGetUBound (*safearray, 1, &ubound1);
5070 if ((lbound1 != 0) || (ubound1 != 1))
5074 for (i= lbound1; i <= ubound1; i++) {
5076 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
5078 failed = (element.vt != VT_I4) || (element.lVal != i+1);
5079 VariantClear (&element);
5084 /* Change one of the elements of the array to verify that [out] parameter is marshalled back to the managed side */
5089 SafeArrayPutElement (*safearray, indices, &element);
5090 VariantClear (&element);
5095 LIBTEST_API int STDCALL
5096 mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (SAFEARRAY* safearray)
5098 /* Check that the input array is what is expected and change it so the caller can check */
5099 /* correct marshalling back to managed code */
5102 long lbound1, ubound1;
5103 SAFEARRAYBOUND dimensions [1];
5109 VariantInit (&element);
5111 /* Check that in array is one dimensional and contains the expected value */
5113 dim = SafeArrayGetDim (safearray);
5117 SafeArrayGetLBound (safearray, 1, &lbound1);
5118 SafeArrayGetUBound (safearray, 1, &ubound1);
5120 if ((lbound1 != 0) || (ubound1 != 0))
5123 for (i= lbound1; i <= ubound1; i++) {
5125 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
5127 failed = (element.vt != VT_I4) || (element.lVal != i+1);
5128 VariantClear (&element);
5133 /* Change the array to verify how [out] parameter is marshalled back to the managed side */
5135 /* Redimension the array */
5136 dimensions [0].lLbound = lbound1;
5137 dimensions [0].cElements = 2;
5138 hr = SafeArrayRedim(safearray, dimensions);
5142 element.lVal = 12345;
5143 SafeArrayPutElement (safearray, indices, &element);
5144 VariantClear (&element);
5148 element.lVal = -12345;
5149 SafeArrayPutElement (safearray, indices, &element);
5150 VariantClear (&element);
5155 LIBTEST_API int STDCALL
5156 mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr (SAFEARRAY* safearray)
5158 /* Check that the input array is what is expected and change it so the caller can check */
5159 /* correct marshalling back to managed code */
5162 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
5163 long i, j, k, failed;
5168 VariantInit (&element);
5170 /* Check that in array is three dimensional and contains the expected values */
5172 dim = SafeArrayGetDim (safearray);
5176 SafeArrayGetLBound (safearray, 1, &lbound1);
5177 SafeArrayGetUBound (safearray, 1, &ubound1);
5179 if ((lbound1 != 0) || (ubound1 != 1))
5182 SafeArrayGetLBound (safearray, 2, &lbound2);
5183 SafeArrayGetUBound (safearray, 2, &ubound2);
5185 if ((lbound2 != 0) || (ubound2 != 1))
5188 SafeArrayGetLBound (safearray, 3, &lbound3);
5189 SafeArrayGetUBound (safearray, 3, &ubound3);
5191 if ((lbound3 != 0) || (ubound3 != 2))
5194 for (i= lbound1; i <= ubound1; i++) {
5196 for (j= lbound2; j <= ubound2; j++) {
5198 for (k= lbound3; k <= ubound3; k++) {
5200 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
5202 failed = ((element.vt != VT_BSTR)
5203 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
5204 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
5205 VariantClear (&element);
5212 /* Change the elements of the array to verify that [out] parameter is marshalled back to the managed side */
5219 SafeArrayPutElement (safearray, indices, &element);
5220 VariantClear (&element);
5227 SafeArrayPutElement (safearray, indices, &element);
5228 VariantClear (&element);
5233 element.vt = VT_BSTR;
5234 element.bstrVal = marshal_bstr_alloc("ABCDEFG");
5235 SafeArrayPutElement (safearray, indices, &element);
5236 VariantClear (&element);
5241 LIBTEST_API int STDCALL
5242 mono_test_marshal_safearray_mixed(
5243 SAFEARRAY *safearray1,
5244 SAFEARRAY **safearray2,
5245 SAFEARRAY *safearray3,
5246 SAFEARRAY **safearray4
5251 /* Initialize out parameters */
5254 /* array1: Check that in array is one dimensional and contains the expected value */
5255 hr = mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (safearray1);
5257 /* array2: Fill in with some values to check on the managed side */
5259 hr = mono_test_marshal_safearray_out_1dim_vt_bstr (safearray2);
5261 /* array3: Check that in array is one dimensional and contains the expected value */
5263 hr = mono_test_marshal_safearray_in_byval_1dim_vt_mixed(safearray3);
5265 /* array4: Check input values and fill in with some values to check on the managed side */
5267 hr = mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr(safearray4);
5274 static int call_managed_res;
5277 call_managed (gpointer arg)
5279 SimpleDelegate del = arg;
5281 call_managed_res = del (42);
5284 LIBTEST_API int STDCALL
5285 mono_test_marshal_thread_attach (SimpleDelegate del)
5293 res = pthread_create (&t, NULL, (gpointer)call_managed, del);
5294 g_assert (res == 0);
5295 pthread_join (t, NULL);
5297 return call_managed_res;
5301 typedef int (STDCALL *Callback) (void);
5303 static Callback callback;
5305 LIBTEST_API void STDCALL
5306 mono_test_marshal_set_callback (Callback cb)
5311 LIBTEST_API int STDCALL
5312 mono_test_marshal_call_callback (void)
5317 LIBTEST_API int STDCALL
5318 mono_test_marshal_lpstr (char *str)
5320 return strcmp ("ABC", str);
5323 LIBTEST_API int STDCALL
5324 mono_test_marshal_lpwstr (gunichar2 *str)
5329 s = g_utf16_to_utf8 (str, -1, NULL, NULL, NULL);
5330 res = strcmp ("ABC", s);
5336 LIBTEST_API char* STDCALL
5337 mono_test_marshal_return_lpstr (void)
5339 char *res = marshal_alloc (4);
5340 strcpy (res, "XYZ");
5345 LIBTEST_API gunichar2* STDCALL
5346 mono_test_marshal_return_lpwstr (void)
5348 gunichar2 *res = marshal_alloc (8);
5349 gunichar2* tmp = g_utf8_to_utf16 ("XYZ", -1, NULL, NULL, NULL);
5351 memcpy (res, tmp, 8);
5359 } SingleDoubleStruct;
5361 LIBTEST_API SingleDoubleStruct STDCALL
5362 mono_test_marshal_return_single_double_struct (void)
5364 SingleDoubleStruct res;
5374 LIBTEST_API int STDCALL
5375 mono_test_has_thiscall (void)
5381 _mono_test_native_thiscall1 (int arg)
5387 _mono_test_native_thiscall2 (int arg, int arg2)
5389 return arg + (arg2^1);
5393 _mono_test_native_thiscall3 (int arg, int arg2, int arg3)
5395 return arg + (arg2^1) + (arg3^2);
5398 #elif defined(__GNUC__)
5400 LIBTEST_API int STDCALL
5401 mono_test_has_thiscall (void)
5406 #define def_asm_fn(name) \
5408 "\t.globl _" #name "\n" \
5410 "\t.globl __" #name "\n" \
5415 def_asm_fn(mono_test_native_thiscall1)
5416 "\tmovl %ecx,%eax\n"
5419 def_asm_fn(mono_test_native_thiscall2)
5420 "\tmovl %ecx,%eax\n"
5421 "\tmovl 4(%esp),%ecx\n"
5423 "\taddl %ecx,%eax\n"
5426 def_asm_fn(mono_test_native_thiscall3)
5427 "\tmovl %ecx,%eax\n"
5428 "\tmovl 4(%esp),%ecx\n"
5430 "\taddl %ecx,%eax\n"
5431 "\tmovl 8(%esp),%ecx\n"
5433 "\taddl %ecx,%eax\n"
5440 LIBTEST_API int STDCALL
5441 mono_test_has_thiscall (void)