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);
415 LIBTEST_API int STDCALL
416 mono_test_empty_pinvoke (int i)
421 LIBTEST_API int STDCALL
422 mono_test_marshal_bool_byref (int a, int *b, int c)
431 LIBTEST_API int STDCALL
432 mono_test_marshal_bool_in_as_I1_U1 (char bTrue, char bFalse)
441 LIBTEST_API int STDCALL
442 mono_test_marshal_bool_out_as_I1_U1 (char* bTrue, char* bFalse)
444 if (!bTrue || !bFalse)
453 LIBTEST_API int STDCALL
454 mono_test_marshal_bool_ref_as_I1_U1 (char* bTrue, char* bFalse)
456 if (!bTrue || !bFalse)
470 LIBTEST_API int STDCALL
471 mono_test_marshal_array (int *a1)
475 for (i = 0; i < 50; i++)
481 LIBTEST_API int STDCALL
482 mono_test_marshal_inout_array (int *a1)
486 for (i = 0; i < 50; i++) {
488 a1 [i] = 50 - a1 [i];
494 LIBTEST_API int /* cdecl */
495 mono_test_marshal_inout_array_cdecl (int *a1)
497 return mono_test_marshal_inout_array (a1);
500 LIBTEST_API int STDCALL
501 mono_test_marshal_out_array (int *a1)
505 for (i = 0; i < 50; i++) {
512 LIBTEST_API int STDCALL
513 mono_test_marshal_inout_nonblittable_array (gunichar2 *a1)
517 for (i = 0; i < 10; i++) {
537 LIBTEST_API simplestruct STDCALL
538 mono_test_return_vtype (int i)
541 static gunichar2 test2 [] = { 'T', 'E', 'S', 'T', '2', 0 };
552 LIBTEST_API void STDCALL
553 mono_test_delegate_struct (void)
555 // printf ("TEST\n");
558 typedef char* (STDCALL *ReturnStringDelegate) (const char *s);
560 LIBTEST_API char * STDCALL
561 mono_test_return_string (ReturnStringDelegate func)
565 // printf ("mono_test_return_string\n");
570 // printf ("got string: %s\n", res);
571 return marshal_strdup ("12345");
574 typedef int (STDCALL *RefVTypeDelegate) (int a, simplestruct *ss, int b);
576 LIBTEST_API int STDCALL
577 mono_test_ref_vtype (int a, simplestruct *ss, int b, RefVTypeDelegate func)
579 if (a == 1 && b == 2 && ss->a == 0 && ss->b == 1 && ss->c == 0 &&
580 !strcmp (ss->d, "TEST1")) {
586 return func (a, ss, b);
592 typedef int (STDCALL *OutVTypeDelegate) (int a, simplestruct *ss, int b);
594 LIBTEST_API int STDCALL
595 mono_test_marshal_out_struct (int a, simplestruct *ss, int b, OutVTypeDelegate func)
597 /* Check that the input pointer is ignored */
598 ss->d = (gpointer)0x12345678;
602 if (ss->a && ss->b && ss->c && !strcmp (ss->d, "TEST3"))
608 typedef int (STDCALL *InVTypeDelegate) (int a, simplestruct *ss, int b);
610 LIBTEST_API int STDCALL
611 mono_test_marshal_in_struct (int a, simplestruct *ss, int b, InVTypeDelegate func)
616 memcpy (&ss2, ss, sizeof (simplestruct));
618 res = func (a, ss, b);
620 printf ("mono_test_marshal_in_struct () failed: %d\n", res);
624 /* Check that no modifications is made to the struct */
625 if (ss2.a == ss->a && ss2.b == ss->b && ss2.c == ss->c && ss2.d == ss->d)
633 SimpleDelegate func, func2, func3;
636 LIBTEST_API DelegateStruct STDCALL
637 mono_test_marshal_delegate_struct (DelegateStruct ds)
641 res.a = ds.func (ds.a) + ds.func2 (ds.a) + (ds.func3 == NULL ? 0 : 1);
643 res.func2 = ds.func2;
649 LIBTEST_API int STDCALL
650 mono_test_marshal_struct (simplestruct ss)
652 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
653 !strcmp (ss.d, "TEST"))
659 LIBTEST_API int STDCALL
660 mono_test_marshal_byref_struct (simplestruct *ss, int a, int b, int c, char *d)
662 gboolean res = (ss->a == a && ss->b == b && ss->c == c && strcmp (ss->d, d) == 0);
664 marshal_free ((char*)ss->d);
669 ss->d = marshal_strdup ("DEF");
685 LIBTEST_API int STDCALL
686 mono_test_marshal_struct2 (simplestruct2 ss)
688 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
689 !strcmp (ss.d, "TEST") &&
690 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
696 /* on HP some of the struct should be on the stack and not in registers */
697 LIBTEST_API int STDCALL
698 mono_test_marshal_struct2_2 (int i, int j, int k, simplestruct2 ss)
700 if (i != 10 || j != 11 || k != 12)
702 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
703 !strcmp (ss.d, "TEST") &&
704 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
710 LIBTEST_API int STDCALL
711 mono_test_marshal_lpstruct (simplestruct *ss)
713 if (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
714 !strcmp (ss->d, "TEST"))
720 LIBTEST_API int STDCALL
721 mono_test_marshal_lpstruct_blittable (point *p)
723 if (p->x == 1.0 && p->y == 2.0)
729 LIBTEST_API int STDCALL
730 mono_test_marshal_struct_array (simplestruct2 *ss)
732 if (! (ss[0].a == 0 && ss[0].b == 1 && ss[0].c == 0 &&
733 !strcmp (ss[0].d, "TEST") &&
734 ss[0].e == 99 && ss[0].f == 1.5 && ss[0].g == 42 && ss[0].h == (guint64)123))
737 if (! (ss[1].a == 0 && ss[1].b == 0 && ss[1].c == 0 &&
738 !strcmp (ss[1].d, "TEST2") &&
739 ss[1].e == 100 && ss[1].f == 2.5 && ss[1].g == 43 && ss[1].h == (guint64)124))
745 typedef struct long_align_struct {
751 LIBTEST_API int STDCALL
752 mono_test_marshal_long_align_struct_array (long_align_struct *ss)
754 return ss[0].a + ss[0].b + ss[0].c + ss[1].a + ss[1].b + ss[1].c;
757 LIBTEST_API simplestruct2 * STDCALL
758 mono_test_marshal_class (int i, int j, int k, simplestruct2 *ss, int l)
765 if (i != 10 || j != 11 || k != 12 || l != 14)
767 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
768 !strcmp (ss->d, "TEST") &&
769 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
772 res = marshal_new0 (simplestruct2, 1);
773 memcpy (res, ss, sizeof (simplestruct2));
774 res->d = marshal_strdup ("TEST");
778 LIBTEST_API int STDCALL
779 mono_test_marshal_byref_class (simplestruct2 **ssp)
781 simplestruct2 *ss = *ssp;
784 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
785 !strcmp (ss->d, "TEST") &&
786 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
789 res = marshal_new0 (simplestruct2, 1);
790 memcpy (res, ss, sizeof (simplestruct2));
791 res->d = marshal_strdup ("TEST-RES");
803 /* Yes, this is correct, we are only trying to determine the value of the stack here */
808 LIBTEST_API int STDCALL
809 reliable_delegate (int a)
815 * Checks whether get_sp() works as expected. It doesn't work with gcc-2.95.3 on linux.
818 is_get_sp_reliable (void)
822 reliable_delegate(1);
824 reliable_delegate(1);
829 LIBTEST_API int STDCALL
830 mono_test_marshal_delegate (SimpleDelegate delegate)
834 /* Check that the delegate wrapper is stdcall */
839 if (is_get_sp_reliable())
840 g_assert (sp1 == sp2);
845 static int STDCALL inc_cb (int i)
850 LIBTEST_API int STDCALL
851 mono_test_marshal_out_delegate (SimpleDelegate *delegate)
858 LIBTEST_API SimpleDelegate STDCALL
859 mono_test_marshal_return_delegate (SimpleDelegate delegate)
865 return_plus_one (int i)
870 LIBTEST_API SimpleDelegate STDCALL
871 mono_test_marshal_return_delegate_2 (void)
873 return return_plus_one;
876 typedef simplestruct (STDCALL *SimpleDelegate2) (simplestruct ss);
879 is_utf16_equals (gunichar2 *s1, const char *s2)
884 s = g_utf16_to_utf8 (s1, -1, NULL, NULL, NULL);
885 res = strcmp (s, s2);
891 LIBTEST_API int STDCALL
892 mono_test_marshal_delegate2 (SimpleDelegate2 delegate)
894 simplestruct ss, res;
900 ss.d2 = g_utf8_to_utf16 ("TEST2", -1, NULL, NULL, NULL);
903 if (! (res.a && !res.b && res.c && !strcmp (res.d, "TEST-RES") && is_utf16_equals (res.d2, "TEST2-RES")))
909 typedef simplestruct* (STDCALL *SimpleDelegate4) (simplestruct *ss);
911 LIBTEST_API int STDCALL
912 mono_test_marshal_delegate4 (SimpleDelegate4 delegate)
923 res = delegate (&ss);
927 /* Check return value */
928 if (! (!res->a && res->b && !res->c && !strcmp (res->d, "TEST")))
931 /* Check NULL argument and NULL result */
932 res = delegate (NULL);
939 typedef int (STDCALL *SimpleDelegate5) (simplestruct **ss);
941 LIBTEST_API int STDCALL
942 mono_test_marshal_delegate5 (SimpleDelegate5 delegate)
955 res = delegate (&ptr);
959 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
965 LIBTEST_API int STDCALL
966 mono_test_marshal_delegate6 (SimpleDelegate5 delegate)
970 res = delegate (NULL);
975 typedef int (STDCALL *SimpleDelegate7) (simplestruct **ss);
977 LIBTEST_API int STDCALL
978 mono_test_marshal_delegate7 (SimpleDelegate7 delegate)
983 /* Check that the input pointer is ignored */
984 ptr = (gpointer)0x12345678;
986 res = delegate (&ptr);
990 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
996 typedef int (STDCALL *InOutByvalClassDelegate) (simplestruct *ss);
998 LIBTEST_API int STDCALL
999 mono_test_marshal_inout_byval_class_delegate (InOutByvalClassDelegate delegate)
1007 ss.d = g_strdup_printf ("%s", "FOO");
1009 res = delegate (&ss);
1013 if (!(ss.a && !ss.b && ss.c && !strcmp (ss.d, "RES")))
1019 typedef int (STDCALL *SimpleDelegate8) (gunichar2 *s);
1021 LIBTEST_API int STDCALL
1022 mono_test_marshal_delegate8 (SimpleDelegate8 delegate, gunichar2 *s)
1024 return delegate (s);
1027 typedef int (STDCALL *return_int_fnt) (int i);
1028 typedef int (STDCALL *SimpleDelegate9) (return_int_fnt d);
1030 LIBTEST_API int STDCALL
1031 mono_test_marshal_delegate9 (SimpleDelegate9 delegate, gpointer ftn)
1033 return delegate (ftn);
1042 LIBTEST_API int STDCALL
1043 mono_test_marshal_delegate10 (SimpleDelegate9 delegate)
1045 return delegate (return_self);
1048 typedef int (STDCALL *PrimitiveByrefDelegate) (int *i);
1050 LIBTEST_API int STDCALL
1051 mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate delegate)
1055 int res = delegate (&i);
1065 typedef int (STDCALL *return_int_delegate) (int i);
1067 typedef return_int_delegate (STDCALL *ReturnDelegateDelegate) (void);
1069 LIBTEST_API int STDCALL
1070 mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d)
1075 LIBTEST_API int STDCALL
1076 mono_test_marshal_stringbuilder (char *s, int n)
1078 const char m[] = "This is my message. Isn't it nice?";
1080 if (strcmp (s, "ABCD") != 0)
1087 LIBTEST_API int STDCALL
1088 mono_test_marshal_stringbuilder2 (char *s, int n)
1090 const char m[] = "EFGH";
1097 LIBTEST_API int STDCALL
1098 mono_test_marshal_stringbuilder_default (char *s, int n)
1100 const char m[] = "This is my message. Isn't it nice?";
1107 LIBTEST_API int STDCALL
1108 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
1110 const char m[] = "This is my message. Isn't it nice?";
1114 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1116 len = (len * 2) + 2;
1119 memcpy (s, s2, len);
1126 LIBTEST_API void STDCALL
1127 mono_test_marshal_stringbuilder_out (char **s)
1129 const char m[] = "This is my message. Isn't it nice?";
1132 str = marshal_alloc (strlen (m) + 1);
1133 memcpy (str, m, strlen (m) + 1);
1138 LIBTEST_API int STDCALL
1139 mono_test_marshal_stringbuilder_out_unicode (gunichar2 **s)
1141 const char m[] = "This is my message. Isn't it nice?";
1145 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1147 len = (len * 2) + 2;
1148 *s = marshal_alloc (len);
1149 memcpy (*s, s2, len);
1156 LIBTEST_API int STDCALL
1157 mono_test_marshal_stringbuilder_ref (char **s)
1159 const char m[] = "This is my message. Isn't it nice?";
1162 if (strcmp (*s, "ABC"))
1165 str = marshal_alloc (strlen (m) + 1);
1166 memcpy (str, m, strlen (m) + 1);
1178 LIBTEST_API int STDCALL
1179 mono_test_marshal_empty_string_array (char **array)
1181 return (array == NULL) ? 0 : 1;
1184 LIBTEST_API int STDCALL
1185 mono_test_marshal_string_array (char **array)
1187 if (strcmp (array [0], "ABC"))
1189 if (strcmp (array [1], "DEF"))
1192 if (array [2] != NULL)
1198 LIBTEST_API int STDCALL
1199 mono_test_marshal_byref_string_array (char ***array)
1204 if (strcmp ((*array) [0], "Alpha"))
1206 if (strcmp ((*array) [1], "Beta"))
1208 if (strcmp ((*array) [2], "Gamma"))
1214 LIBTEST_API int STDCALL
1215 mono_test_marshal_stringbuilder_array (char **array)
1217 if (strcmp (array [0], "ABC"))
1219 if (strcmp (array [1], "DEF"))
1222 strcpy (array [0], "DEF");
1223 strcpy (array [1], "ABC");
1228 LIBTEST_API int STDCALL
1229 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
1231 GError *error = NULL;
1234 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
1235 if (strcmp (s, "ABC")) {
1242 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
1243 if (strcmp (s, "DEF")) {
1250 if (strcmp (array2 [0], "ABC"))
1253 if (strcmp (array2 [1], "DEF"))
1259 /* this does not work on Redhat gcc 2.96 */
1260 LIBTEST_API int STDCALL
1261 mono_test_empty_struct (int a, EmptyStruct es, int b)
1263 // printf ("mono_test_empty_struct %d %d\n", a, b);
1265 // Intel icc on ia64 passes 'es' in 2 registers
1266 #if defined(__ia64) && defined(__INTEL_COMPILER)
1269 if (a == 1 && b == 2)
1279 LIBTEST_API ByValStrStruct * STDCALL
1280 mono_test_byvalstr_gen (void)
1282 ByValStrStruct *ret;
1284 ret = malloc(sizeof(ByValStrStruct));
1285 memset(ret, 'a', sizeof(ByValStrStruct)-1);
1286 ret->a[sizeof(ByValStrStruct)-1] = 0;
1291 LIBTEST_API int STDCALL
1292 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
1296 ret = strcmp(data->a, correctString);
1297 // printf ("T1: %s\n", data->a);
1298 // printf ("T2: %s\n", correctString);
1300 /* we need g_free because the allocation was performed by mono_test_byvalstr_gen */
1308 } ByValStrStruct_Unicode;
1310 LIBTEST_API int STDCALL
1311 mono_test_byvalstr_check_unicode (ByValStrStruct_Unicode *ref, int test)
1313 if (ref->flag != 0x1234abcd){
1314 printf ("overwritten data");
1318 if (test == 1 || test == 3){
1319 if (ref->a [0] != '1' ||
1320 ref->a [1] != '2' ||
1326 if (ref->a [0] != '1' ||
1334 LIBTEST_API int STDCALL
1335 NameManglingAnsi (char *data)
1337 return data [0] + data [1] + data [2];
1340 LIBTEST_API int STDCALL
1341 NameManglingAnsiA (char *data)
1343 g_assert_not_reached ();
1346 LIBTEST_API int STDCALL
1347 NameManglingAnsiW (char *data)
1349 g_assert_not_reached ();
1352 LIBTEST_API int STDCALL
1353 NameManglingAnsi2A (char *data)
1355 return data [0] + data [1] + data [2];
1358 LIBTEST_API int STDCALL
1359 NameManglingAnsi2W (char *data)
1361 g_assert_not_reached ();
1364 LIBTEST_API int STDCALL
1365 NameManglingUnicode (char *data)
1367 g_assert_not_reached ();
1370 LIBTEST_API int STDCALL
1371 NameManglingUnicodeW (gunichar2 *data)
1373 return data [0] + data [1] + data [2];
1376 LIBTEST_API int STDCALL
1377 NameManglingUnicode2 (gunichar2 *data)
1379 return data [0] + data [1] + data [2];
1382 LIBTEST_API int STDCALL
1383 NameManglingAutoW (char *data)
1386 return (data [0] + data [1] + data [2]) == 131 ? 0 : 1;
1388 g_assert_not_reached ();
1392 LIBTEST_API int STDCALL
1393 NameManglingAuto (char *data)
1396 return (data [0] + data [1] + data [2]) == 198 ? 0 : 1;
1398 g_assert_not_reached ();
1402 typedef int (STDCALL *intcharFunc)(const char*);
1404 LIBTEST_API void STDCALL
1405 callFunction (intcharFunc f)
1415 LIBTEST_API int STDCALL
1416 class_marshal_test0 (SimpleObj *obj1)
1418 // printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
1420 if (strcmp(obj1->str, "T1"))
1428 LIBTEST_API int STDCALL
1429 class_marshal_test4 (SimpleObj *obj1)
1437 LIBTEST_API void STDCALL
1438 class_marshal_test1 (SimpleObj **obj1)
1440 SimpleObj *res = malloc (sizeof (SimpleObj));
1442 res->str = marshal_strdup ("ABC");
1448 LIBTEST_API int STDCALL
1449 class_marshal_test2 (SimpleObj **obj1)
1451 // printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
1453 if (strcmp((*obj1)->str, "ABC"))
1455 if ((*obj1)->i != 5)
1461 LIBTEST_API int STDCALL
1462 string_marshal_test0 (char *str)
1464 if (strcmp (str, "TEST0"))
1470 LIBTEST_API void STDCALL
1471 string_marshal_test1 (const char **str)
1473 *str = marshal_strdup ("TEST1");
1476 LIBTEST_API int STDCALL
1477 string_marshal_test2 (char **str)
1479 // printf ("string_marshal_test2 %s\n", *str);
1481 if (strcmp (*str, "TEST1"))
1484 *str = marshal_strdup ("TEST2");
1489 LIBTEST_API int STDCALL
1490 string_marshal_test3 (char *str)
1503 LIBTEST_API BlittableClass* STDCALL
1504 TestBlittableClass (BlittableClass *vl)
1506 BlittableClass *res;
1508 // printf ("TestBlittableClass %d %d\n", vl->a, vl->b);
1514 res = marshal_new0 (BlittableClass, 1);
1515 memcpy (res, vl, sizeof (BlittableClass));
1517 res = marshal_new0 (BlittableClass, 1);
1525 typedef struct OSVERSIONINFO_STRUCT
1529 } OSVERSIONINFO_STRUCT;
1531 LIBTEST_API int STDCALL
1532 MyGetVersionEx (OSVERSIONINFO_STRUCT *osvi)
1535 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1540 return osvi->a + osvi->b;
1543 LIBTEST_API int STDCALL
1544 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO_STRUCT *osvi)
1547 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1552 return osvi->a + osvi->b;
1555 LIBTEST_API int STDCALL
1556 mono_test_marshal_point (point pt)
1558 // printf("point %g %g\n", pt.x, pt.y);
1559 if (pt.x == 1.25 && pt.y == 3.5)
1570 LIBTEST_API int STDCALL
1571 mono_test_marshal_mixed_point (mixed_point pt)
1573 // printf("mixed point %d %g\n", pt.x, pt.y);
1574 if (pt.x == 5 && pt.y == 6.75)
1580 LIBTEST_API int STDCALL
1581 mono_test_marshal_mixed_point_2 (mixed_point *pt)
1583 if (pt->x != 5 || pt->y != 6.75)
1592 LIBTEST_API int STDCALL
1593 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
1596 if (*b1 != 0 && *b1 != 1)
1598 if (*b2 != 0 && *b2 != -1) /* variant_bool */
1600 if (*b3 != 0 && *b3 != 1)
1602 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
1614 short b2; /* variant_bool */
1618 LIBTEST_API int STDCALL
1619 marshal_test_bool_struct(struct BoolStruct *s)
1622 if (s->b1 != 0 && s->b1 != 1)
1624 if (s->b2 != 0 && s->b2 != -1)
1626 if (s->b3 != 0 && s->b3 != 1)
1628 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1645 LIBTEST_API int STDCALL
1646 mono_test_marshal_long_struct (LongStruct *s)
1648 return s->i + s->l.l;
1651 LIBTEST_API void STDCALL
1652 mono_test_last_error (int err)
1661 LIBTEST_API int STDCALL
1662 mono_test_asany (void *ptr, int what)
1666 return (*(int*)ptr == 5) ? 0 : 1;
1668 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1670 simplestruct2 ss = *(simplestruct2*)ptr;
1672 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1673 !strcmp (ss.d, "TEST") &&
1674 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1680 GError *error = NULL;
1683 s = g_utf16_to_utf8 (ptr, -1, NULL, NULL, &error);
1688 if (!strcmp (s, "ABC")) {
1698 g_assert_not_reached ();
1712 LIBTEST_API int STDCALL
1713 mono_test_marshal_asany_in (void* ptr)
1715 AsAnyStruct* asAny = ptr;
1716 int res = asAny->i + asAny->j + asAny->k;
1721 LIBTEST_API int STDCALL
1722 mono_test_marshal_asany_inout (void* ptr)
1724 AsAnyStruct* asAny = ptr;
1725 int res = asAny->i + asAny->j + asAny->k;
1727 marshal_free (asAny->s);
1737 LIBTEST_API int STDCALL
1738 mono_test_marshal_asany_out (void* ptr)
1740 AsAnyStruct* asAny = ptr;
1741 int res = asAny->i + asAny->j + asAny->k;
1752 * AMD64 marshalling tests.
1755 typedef struct amd64_struct1 {
1762 LIBTEST_API amd64_struct1 STDCALL
1763 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
1773 LIBTEST_API amd64_struct1 STDCALL
1774 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)
1779 s.l += 1 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8;
1784 typedef struct amd64_struct2 {
1789 LIBTEST_API amd64_struct2 STDCALL
1790 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
1798 typedef struct amd64_struct3 {
1802 LIBTEST_API amd64_struct3 STDCALL
1803 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s)
1810 typedef struct amd64_struct4 {
1814 LIBTEST_API amd64_struct4 STDCALL
1815 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s)
1824 * IA64 marshalling tests.
1826 typedef struct test_struct5 {
1830 LIBTEST_API test_struct5 STDCALL
1831 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, test_struct5 s, int i, double d3, double d4)
1833 s.d1 += d1 + d2 + i;
1834 s.d2 += d3 + d4 + i;
1839 typedef struct test_struct6 {
1843 LIBTEST_API test_struct6 STDCALL
1844 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, test_struct6 s, int i, double d3, double d4)
1846 s.d1 += d1 + d2 + i;
1852 static guint32 custom_res [2];
1854 LIBTEST_API void* STDCALL
1855 mono_test_marshal_pass_return_custom (int i, guint32 *ptr, int j)
1857 /* ptr will be freed by CleanupNative, so make a copy */
1858 custom_res [0] = 0; /* not allocated by AllocHGlobal */
1859 custom_res [1] = ptr [1];
1864 LIBTEST_API int STDCALL
1865 mono_test_marshal_pass_out_custom (int i, guint32 **ptr, int j)
1868 custom_res [1] = i + j + 10;
1875 LIBTEST_API int STDCALL
1876 mono_test_marshal_pass_inout_custom (int i, guint32 *ptr, int j)
1879 ptr [1] = i + ptr [1] + j;
1884 LIBTEST_API int STDCALL
1885 mono_test_marshal_pass_out_byval_custom (int i, guint32 *ptr, int j)
1887 return ptr == NULL ? 0 : 1;
1890 LIBTEST_API int STDCALL
1891 mono_test_marshal_pass_byref_custom (int i, guint32 **ptr, int j)
1898 LIBTEST_API void* STDCALL
1899 mono_test_marshal_pass_return_custom2 (int i, guint32 *ptr, int j)
1901 g_assert_not_reached ();
1906 LIBTEST_API void* STDCALL
1907 mono_test_marshal_pass_return_custom_null (int i, guint32 *ptr, int j)
1909 g_assert (ptr == NULL);
1914 typedef void *(STDCALL *PassReturnPtrDelegate) (void *ptr);
1916 LIBTEST_API int STDCALL
1917 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del)
1931 /* FIXME: Freed with FreeHGlobal */
1939 LIBTEST_API int STDCALL
1940 mono_test_marshal_pass_return_custom_null_in_delegate (PassReturnPtrDelegate del)
1942 void *ptr = del (NULL);
1944 return (ptr == NULL) ? 15 : 0;
1947 typedef void (STDCALL *CustomOutParamDelegate) (void **pptr);
1949 LIBTEST_API int STDCALL
1950 mono_test_marshal_custom_out_param_delegate (CustomOutParamDelegate del)
1962 typedef int (STDCALL *ReturnEnumDelegate) (int e);
1964 LIBTEST_API int STDCALL
1965 mono_test_marshal_return_enum_delegate (ReturnEnumDelegate func)
1975 typedef BlittableStruct (STDCALL *SimpleDelegate10) (BlittableStruct ss);
1977 LIBTEST_API int STDCALL
1978 mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 delegate)
1980 BlittableStruct ss, res;
1987 res = delegate (ss);
1988 if (! ((res.a == -1) && (res.b == -2) && (res.c == -3) && (res.d == -55)))
1994 LIBTEST_API int STDCALL
1995 mono_test_stdcall_name_mangling (int a, int b, int c)
2001 mono_test_stdcall_mismatch_1 (int a, int b, int c)
2006 LIBTEST_API int STDCALL
2007 mono_test_stdcall_mismatch_2 (int a, int b, int c)
2013 * PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
2020 typedef SmallStruct1 (STDCALL *SmallStructDelegate1) (SmallStruct1 ss);
2022 LIBTEST_API int STDCALL
2023 mono_test_marshal_small_struct_delegate1 (SmallStructDelegate1 delegate)
2025 SmallStruct1 ss, res;
2029 res = delegate (ss);
2030 if (! (res.i == -1))
2040 typedef SmallStruct2 (STDCALL *SmallStructDelegate2) (SmallStruct2 ss);
2042 LIBTEST_API int STDCALL
2043 mono_test_marshal_small_struct_delegate2 (SmallStructDelegate2 delegate)
2045 SmallStruct2 ss, res;
2050 res = delegate (ss);
2051 if (! ((res.i == -2) && (res.j == -3)))
2062 typedef SmallStruct3 (STDCALL *SmallStructDelegate3) (SmallStruct3 ss);
2064 LIBTEST_API int STDCALL
2065 mono_test_marshal_small_struct_delegate3 (SmallStructDelegate3 delegate)
2067 SmallStruct3 ss, res;
2072 res = delegate (ss);
2073 if (! ((res.i == -1) && (res.j == -2)))
2083 typedef SmallStruct4 (STDCALL *SmallStructDelegate4) (SmallStruct4 ss);
2085 LIBTEST_API int STDCALL
2086 mono_test_marshal_small_struct_delegate4 (SmallStructDelegate4 delegate)
2088 SmallStruct4 ss, res;
2092 res = delegate (ss);
2093 if (! (res.i == -1))
2103 typedef SmallStruct5 (STDCALL *SmallStructDelegate5) (SmallStruct5 ss);
2105 LIBTEST_API int STDCALL
2106 mono_test_marshal_small_struct_delegate5 (SmallStructDelegate5 delegate)
2108 SmallStruct5 ss, res;
2112 res = delegate (ss);
2113 if (! (res.i == -5))
2123 typedef SmallStruct6 (STDCALL *SmallStructDelegate6) (SmallStruct6 ss);
2125 LIBTEST_API int STDCALL
2126 mono_test_marshal_small_struct_delegate6 (SmallStructDelegate6 delegate)
2128 SmallStruct6 ss, res;
2133 res = delegate (ss);
2134 if (! ((res.i == -1) && (res.j == -2)))
2145 typedef SmallStruct7 (STDCALL *SmallStructDelegate7) (SmallStruct7 ss);
2147 LIBTEST_API int STDCALL
2148 mono_test_marshal_small_struct_delegate7 (SmallStructDelegate7 delegate)
2150 SmallStruct7 ss, res;
2155 res = delegate (ss);
2156 if (! ((res.i == -1) && (res.j == -2)))
2166 typedef SmallStruct8 (STDCALL *SmallStructDelegate8) (SmallStruct8 ss);
2168 LIBTEST_API int STDCALL
2169 mono_test_marshal_small_struct_delegate8 (SmallStructDelegate8 delegate)
2171 SmallStruct8 ss, res;
2175 res = delegate (ss);
2176 if (! ((res.i == -1.0)))
2186 typedef SmallStruct9 (STDCALL *SmallStructDelegate9) (SmallStruct9 ss);
2188 LIBTEST_API int STDCALL
2189 mono_test_marshal_small_struct_delegate9 (SmallStructDelegate9 delegate)
2191 SmallStruct9 ss, res;
2195 res = delegate (ss);
2196 if (! ((res.i == -1.0)))
2206 typedef SmallStruct10 (STDCALL *SmallStructDelegate10) (SmallStruct10 ss);
2208 LIBTEST_API int STDCALL
2209 mono_test_marshal_small_struct_delegate10 (SmallStructDelegate10 delegate)
2211 SmallStruct10 ss, res;
2216 res = delegate (ss);
2217 if (! ((res.i == -1.0) && (res.j == -2.0)))
2228 typedef SmallStruct11 (STDCALL *SmallStructDelegate11) (SmallStruct11 ss);
2230 LIBTEST_API int STDCALL
2231 mono_test_marshal_small_struct_delegate11 (SmallStructDelegate11 delegate)
2233 SmallStruct11 ss, res;
2238 res = delegate (ss);
2239 if (! ((res.i == -1.0) && (res.j == -2)))
2245 typedef int (STDCALL *ArrayDelegate) (int i, char *j, void *arr);
2247 LIBTEST_API int STDCALL
2248 mono_test_marshal_array_delegate (void *arr, int len, ArrayDelegate del)
2250 return del (len, NULL, arr);
2253 typedef int (STDCALL *ArrayDelegateLong) (gint64 i, char *j, void *arr);
2255 LIBTEST_API int STDCALL
2256 mono_test_marshal_array_delegate_long (void *arr, gint64 len, ArrayDelegateLong del)
2258 return del (len, NULL, arr);
2261 LIBTEST_API int STDCALL
2262 mono_test_marshal_out_array_delegate (int *arr, int len, ArrayDelegate del)
2264 del (len, NULL, arr);
2266 if ((arr [0] != 1) || (arr [1] != 2))
2272 typedef gunichar2* (STDCALL *UnicodeStringDelegate) (gunichar2 *message);
2274 LIBTEST_API int STDCALL
2275 mono_test_marshal_return_unicode_string_delegate (UnicodeStringDelegate del)
2277 const char m[] = "abcdef";
2278 gunichar2 *s2, *res;
2281 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
2290 LIBTEST_API int STDCALL
2291 mono_test_marshal_out_string_array_delegate (char **arr, int len, ArrayDelegate del)
2293 del (len, NULL, arr);
2295 if (!strcmp (arr [0], "ABC") && !strcmp (arr [1], "DEF"))
2301 typedef int (*CdeclDelegate) (int i, int j);
2303 LIBTEST_API int STDCALL
2304 mono_test_marshal_cdecl_delegate (CdeclDelegate del)
2308 for (i = 0; i < 1000; ++i)
2314 typedef char** (STDCALL *ReturnStringArrayDelegate) (int i);
2316 LIBTEST_API int STDCALL
2317 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d)
2325 if (strcmp (arr [0], "ABC") || strcmp (arr [1], "DEF"))
2335 typedef int (STDCALL *ByrefStringDelegate) (char **s);
2337 LIBTEST_API int STDCALL
2338 mono_test_marshal_byref_string_delegate (ByrefStringDelegate d)
2340 char *s = (char*)"ABC";
2347 if (!strcmp (s, "DEF"))
2357 LIBTEST_API int STDCALL
2358 add_delegate (int i, int j)
2363 LIBTEST_API gpointer STDCALL
2364 mono_test_marshal_return_fnptr (void)
2366 return &add_delegate;
2369 LIBTEST_API int STDCALL
2372 printf ("codigo %x\n", code);
2380 LIBTEST_API HandleRef STDCALL
2381 mono_xr_as_handle (int code)
2385 memset (&ref, 0, sizeof (ref));
2397 LIBTEST_API int STDCALL
2398 mono_safe_handle_struct_ref (HandleStructs *x)
2400 printf ("Dingus Ref! \n");
2401 printf ("Values: %d %d %p %p\n", x->a, x->b, x->handle1, x->handle2);
2407 if (x->handle1 != (void*) 0x7080feed)
2410 if (x->handle2 != (void*) 0x1234abcd)
2416 LIBTEST_API int STDCALL
2417 mono_safe_handle_struct (HandleStructs x)
2419 printf ("Dingus Standard! \n");
2420 printf ("Values: %d %d %p %p\n", x.a, x.b, x.handle1, x.handle2);
2426 if (x.handle1 != (void*) 0x7080feed)
2429 if (x.handle2 != (void*) 0x1234abcd)
2439 LIBTEST_API int STDCALL
2440 mono_safe_handle_struct_simple (TrivialHandle x)
2442 printf ("The value is %p\n", x.a);
2443 return ((int)(gsize)x.a) * 2;
2446 LIBTEST_API int STDCALL
2447 mono_safe_handle_return (void)
2452 LIBTEST_API void STDCALL
2453 mono_safe_handle_ref (void **handle)
2456 *handle = (void *) 0xbad;
2460 *handle = (void *) 0x800d;
2463 LIBTEST_API double STDCALL
2464 mono_test_marshal_date_time (double d, double *d2)
2536 VT_USERDEFINED = 29,
2544 VT_STREAMED_OBJECT = 68,
2545 VT_STORED_OBJECT = 69,
2546 VT_BLOB_OBJECT = 70,
2554 void VariantInit(VARIANT* vt)
2571 LIBTEST_API int STDCALL
2572 mono_test_marshal_bstr_in(gunichar2* bstr)
2575 gchar* bstr_utf8 = g_utf16_to_utf8 (bstr, -1, NULL, NULL, NULL);
2576 result = strcmp("mono_test_marshal_bstr_in", bstr_utf8);
2583 LIBTEST_API int STDCALL
2584 mono_test_marshal_bstr_out(gunichar2** bstr)
2586 *bstr = marshal_bstr_alloc ("mono_test_marshal_bstr_out");
2590 LIBTEST_API int STDCALL
2591 mono_test_marshal_bstr_in_null(gunichar2* bstr)
2598 LIBTEST_API int STDCALL
2599 mono_test_marshal_bstr_out_null(gunichar2** bstr)
2605 LIBTEST_API int STDCALL
2606 mono_test_marshal_variant_in_sbyte(VARIANT variant)
2608 if (variant.vt == VT_I1 && variant.cVal == 100)
2613 LIBTEST_API int STDCALL
2614 mono_test_marshal_variant_in_byte(VARIANT variant)
2616 if (variant.vt == VT_UI1 && variant.bVal == 100)
2621 LIBTEST_API int STDCALL
2622 mono_test_marshal_variant_in_short(VARIANT variant)
2624 if (variant.vt == VT_I2 && variant.iVal == 314)
2629 LIBTEST_API int STDCALL
2630 mono_test_marshal_variant_in_ushort(VARIANT variant)
2632 if (variant.vt == VT_UI2 && variant.uiVal == 314)
2637 LIBTEST_API int STDCALL
2638 mono_test_marshal_variant_in_int(VARIANT variant)
2640 if (variant.vt == VT_I4 && variant.lVal == 314)
2645 LIBTEST_API int STDCALL
2646 mono_test_marshal_variant_in_uint(VARIANT variant)
2648 if (variant.vt == VT_UI4 && variant.ulVal == 314)
2653 LIBTEST_API int STDCALL
2654 mono_test_marshal_variant_in_long(VARIANT variant)
2656 if (variant.vt == VT_I8 && variant.llVal == 314)
2661 LIBTEST_API int STDCALL
2662 mono_test_marshal_variant_in_ulong(VARIANT variant)
2664 if (variant.vt == VT_UI8 && variant.ullVal == 314)
2669 LIBTEST_API int STDCALL
2670 mono_test_marshal_variant_in_float(VARIANT variant)
2672 if (variant.vt == VT_R4 && (variant.fltVal - 3.14)/3.14 < .001)
2677 LIBTEST_API int STDCALL
2678 mono_test_marshal_variant_in_double(VARIANT variant)
2680 if (variant.vt == VT_R8 && (variant.dblVal - 3.14)/3.14 < .001)
2685 LIBTEST_API int STDCALL
2686 mono_test_marshal_variant_in_bstr(VARIANT variant)
2689 gchar* bstr_utf8 = g_utf16_to_utf8 (variant.bstrVal, -1, NULL, NULL, NULL);
2690 result = strcmp("PI", bstr_utf8);
2693 if (variant.vt == VT_BSTR && !result)
2698 LIBTEST_API int STDCALL
2699 mono_test_marshal_variant_in_bool_true (VARIANT variant)
2701 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_TRUE)
2706 LIBTEST_API int STDCALL
2707 mono_test_marshal_variant_in_bool_false (VARIANT variant)
2709 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_FALSE)
2714 LIBTEST_API int STDCALL
2715 mono_test_marshal_variant_out_sbyte(VARIANT* variant)
2717 variant->vt = VT_I1;
2718 variant->cVal = 100;
2723 LIBTEST_API int STDCALL
2724 mono_test_marshal_variant_out_sbyte_byref(VARIANT* variant)
2726 variant->vt = VT_I1|VT_BYREF;
2727 variant->byref = marshal_alloc(1);
2728 *((gint8*)variant->byref) = 100;
2733 LIBTEST_API int STDCALL
2734 mono_test_marshal_variant_out_byte(VARIANT* variant)
2736 variant->vt = VT_UI1;
2737 variant->bVal = 100;
2742 LIBTEST_API int STDCALL
2743 mono_test_marshal_variant_out_byte_byref(VARIANT* variant)
2745 variant->vt = VT_UI1|VT_BYREF;
2746 variant->byref = marshal_alloc(1);
2747 *((gint8*)variant->byref) = 100;
2752 LIBTEST_API int STDCALL
2753 mono_test_marshal_variant_out_short(VARIANT* variant)
2755 variant->vt = VT_I2;
2756 variant->iVal = 314;
2761 LIBTEST_API int STDCALL
2762 mono_test_marshal_variant_out_short_byref(VARIANT* variant)
2764 variant->vt = VT_I2|VT_BYREF;
2765 variant->byref = marshal_alloc(2);
2766 *((gint16*)variant->byref) = 314;
2771 LIBTEST_API int STDCALL
2772 mono_test_marshal_variant_out_ushort(VARIANT* variant)
2774 variant->vt = VT_UI2;
2775 variant->uiVal = 314;
2780 LIBTEST_API int STDCALL
2781 mono_test_marshal_variant_out_ushort_byref(VARIANT* variant)
2783 variant->vt = VT_UI2|VT_BYREF;
2784 variant->byref = marshal_alloc(2);
2785 *((guint16*)variant->byref) = 314;
2790 LIBTEST_API int STDCALL
2791 mono_test_marshal_variant_out_int(VARIANT* variant)
2793 variant->vt = VT_I4;
2794 variant->lVal = 314;
2799 LIBTEST_API int STDCALL
2800 mono_test_marshal_variant_out_int_byref(VARIANT* variant)
2802 variant->vt = VT_I4|VT_BYREF;
2803 variant->byref = marshal_alloc(4);
2804 *((gint32*)variant->byref) = 314;
2809 LIBTEST_API int STDCALL
2810 mono_test_marshal_variant_out_uint(VARIANT* variant)
2812 variant->vt = VT_UI4;
2813 variant->ulVal = 314;
2818 LIBTEST_API int STDCALL
2819 mono_test_marshal_variant_out_uint_byref(VARIANT* variant)
2821 variant->vt = VT_UI4|VT_BYREF;
2822 variant->byref = marshal_alloc(4);
2823 *((guint32*)variant->byref) = 314;
2828 LIBTEST_API int STDCALL
2829 mono_test_marshal_variant_out_long(VARIANT* variant)
2831 variant->vt = VT_I8;
2832 variant->llVal = 314;
2837 LIBTEST_API int STDCALL
2838 mono_test_marshal_variant_out_long_byref(VARIANT* variant)
2840 variant->vt = VT_I8|VT_BYREF;
2841 variant->byref = marshal_alloc(8);
2842 *((gint64*)variant->byref) = 314;
2847 LIBTEST_API int STDCALL
2848 mono_test_marshal_variant_out_ulong(VARIANT* variant)
2850 variant->vt = VT_UI8;
2851 variant->ullVal = 314;
2856 LIBTEST_API int STDCALL
2857 mono_test_marshal_variant_out_ulong_byref(VARIANT* variant)
2859 variant->vt = VT_UI8|VT_BYREF;
2860 variant->byref = marshal_alloc(8);
2861 *((guint64*)variant->byref) = 314;
2866 LIBTEST_API int STDCALL
2867 mono_test_marshal_variant_out_float(VARIANT* variant)
2869 variant->vt = VT_R4;
2870 variant->fltVal = 3.14;
2875 LIBTEST_API int STDCALL
2876 mono_test_marshal_variant_out_float_byref(VARIANT* variant)
2878 variant->vt = VT_R4|VT_BYREF;
2879 variant->byref = marshal_alloc(4);
2880 *((float*)variant->byref) = 3.14;
2885 LIBTEST_API int STDCALL
2886 mono_test_marshal_variant_out_double(VARIANT* variant)
2888 variant->vt = VT_R8;
2889 variant->dblVal = 3.14;
2894 LIBTEST_API int STDCALL
2895 mono_test_marshal_variant_out_double_byref(VARIANT* variant)
2897 variant->vt = VT_R8|VT_BYREF;
2898 variant->byref = marshal_alloc(8);
2899 *((double*)variant->byref) = 3.14;
2904 LIBTEST_API int STDCALL
2905 mono_test_marshal_variant_out_bstr(VARIANT* variant)
2907 variant->vt = VT_BSTR;
2908 variant->bstrVal = marshal_bstr_alloc("PI");
2913 LIBTEST_API int STDCALL
2914 mono_test_marshal_variant_out_bstr_byref(VARIANT* variant)
2916 variant->vt = VT_BSTR|VT_BYREF;
2917 variant->byref = marshal_alloc(sizeof(gpointer));
2918 *((gunichar**)variant->byref) = (gunichar*)marshal_bstr_alloc("PI");
2923 LIBTEST_API int STDCALL
2924 mono_test_marshal_variant_out_bool_true (VARIANT* variant)
2926 variant->vt = VT_BOOL;
2927 variant->boolVal = VARIANT_TRUE;
2932 LIBTEST_API int STDCALL
2933 mono_test_marshal_variant_out_bool_true_byref (VARIANT* variant)
2935 variant->vt = VT_BOOL|VT_BYREF;
2936 variant->byref = marshal_alloc(2);
2937 *((gint16*)variant->byref) = VARIANT_TRUE;
2942 LIBTEST_API int STDCALL
2943 mono_test_marshal_variant_out_bool_false (VARIANT* variant)
2945 variant->vt = VT_BOOL;
2946 variant->boolVal = VARIANT_FALSE;
2951 LIBTEST_API int STDCALL
2952 mono_test_marshal_variant_out_bool_false_byref (VARIANT* variant)
2954 variant->vt = VT_BOOL|VT_BYREF;
2955 variant->byref = marshal_alloc(2);
2956 *((gint16*)variant->byref) = VARIANT_FALSE;
2961 typedef int (STDCALL *VarFunc) (int vt, VARIANT variant);
2962 typedef int (STDCALL *VarRefFunc) (int vt, VARIANT* variant);
2964 LIBTEST_API int STDCALL
2965 mono_test_marshal_variant_in_sbyte_unmanaged(VarFunc func)
2970 return func (VT_I1, vt);
2973 LIBTEST_API int STDCALL
2974 mono_test_marshal_variant_in_byte_unmanaged(VarFunc func)
2979 return func (VT_UI1, vt);
2982 LIBTEST_API int STDCALL
2983 mono_test_marshal_variant_in_short_unmanaged(VarFunc func)
2988 return func (VT_I2, vt);
2991 LIBTEST_API int STDCALL
2992 mono_test_marshal_variant_in_ushort_unmanaged(VarFunc func)
2997 return func (VT_UI2, vt);
3000 LIBTEST_API int STDCALL
3001 mono_test_marshal_variant_in_int_unmanaged(VarFunc func)
3006 return func (VT_I4, vt);
3009 LIBTEST_API int STDCALL
3010 mono_test_marshal_variant_in_uint_unmanaged(VarFunc func)
3015 return func (VT_UI4, vt);
3018 LIBTEST_API int STDCALL
3019 mono_test_marshal_variant_in_long_unmanaged(VarFunc func)
3024 return func (VT_I8, vt);
3027 LIBTEST_API int STDCALL
3028 mono_test_marshal_variant_in_ulong_unmanaged(VarFunc func)
3033 return func (VT_UI8, vt);
3036 LIBTEST_API int STDCALL
3037 mono_test_marshal_variant_in_float_unmanaged(VarFunc func)
3042 return func (VT_R4, vt);
3045 LIBTEST_API int STDCALL
3046 mono_test_marshal_variant_in_double_unmanaged(VarFunc func)
3051 return func (VT_R8, vt);
3054 LIBTEST_API int STDCALL
3055 mono_test_marshal_variant_in_bstr_unmanaged(VarFunc func)
3059 vt.bstrVal = marshal_bstr_alloc("PI");
3060 return func (VT_BSTR, vt);
3063 LIBTEST_API int STDCALL
3064 mono_test_marshal_variant_in_bool_true_unmanaged(VarFunc func)
3068 vt.boolVal = VARIANT_TRUE;
3069 return func (VT_BOOL, vt);
3072 LIBTEST_API int STDCALL
3073 mono_test_marshal_variant_in_bool_false_unmanaged(VarFunc func)
3077 vt.boolVal = VARIANT_FALSE;
3078 return func (VT_BOOL, vt);
3081 LIBTEST_API int STDCALL
3082 mono_test_marshal_variant_out_sbyte_unmanaged(VarRefFunc func)
3087 if (vt.vt == VT_I1 && vt.cVal == -100)
3092 LIBTEST_API int STDCALL
3093 mono_test_marshal_variant_out_byte_unmanaged(VarRefFunc func)
3098 if (vt.vt == VT_UI1 && vt.bVal == 100)
3103 LIBTEST_API int STDCALL
3104 mono_test_marshal_variant_out_short_unmanaged(VarRefFunc func)
3109 if (vt.vt == VT_I2 && vt.iVal == -100)
3114 LIBTEST_API int STDCALL
3115 mono_test_marshal_variant_out_ushort_unmanaged(VarRefFunc func)
3120 if (vt.vt == VT_UI2 && vt.uiVal == 100)
3125 LIBTEST_API int STDCALL
3126 mono_test_marshal_variant_out_int_unmanaged(VarRefFunc func)
3131 if (vt.vt == VT_I4 && vt.lVal == -100)
3136 LIBTEST_API int STDCALL
3137 mono_test_marshal_variant_out_uint_unmanaged(VarRefFunc func)
3142 if (vt.vt == VT_UI4 && vt.ulVal == 100)
3147 LIBTEST_API int STDCALL
3148 mono_test_marshal_variant_out_long_unmanaged(VarRefFunc func)
3153 if (vt.vt == VT_I8 && vt.llVal == -100)
3158 LIBTEST_API int STDCALL
3159 mono_test_marshal_variant_out_ulong_unmanaged(VarRefFunc func)
3164 if (vt.vt == VT_UI8 && vt.ullVal == 100)
3169 LIBTEST_API int STDCALL
3170 mono_test_marshal_variant_out_float_unmanaged(VarRefFunc func)
3175 if (vt.vt == VT_R4 && fabs (vt.fltVal - 3.14f) < 1e-10)
3180 LIBTEST_API int STDCALL
3181 mono_test_marshal_variant_out_double_unmanaged(VarRefFunc func)
3186 if (vt.vt == VT_R8 && fabs (vt.dblVal - 3.14) < 1e-10)
3191 LIBTEST_API int STDCALL
3192 mono_test_marshal_variant_out_bstr_unmanaged(VarRefFunc func)
3200 func (VT_BSTR, &vt);
3201 bstr_utf8 = g_utf16_to_utf8 (vt.bstrVal, -1, NULL, NULL, NULL);
3202 result = strcmp("PI", bstr_utf8);
3204 if (vt.vt == VT_BSTR && !result)
3209 LIBTEST_API int STDCALL
3210 mono_test_marshal_variant_out_bool_true_unmanaged(VarRefFunc func)
3214 func (VT_BOOL, &vt);
3215 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3220 LIBTEST_API int STDCALL
3221 mono_test_marshal_variant_out_bool_false_unmanaged(VarRefFunc func)
3225 func (VT_BOOL, &vt);
3226 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3231 typedef struct MonoComObject MonoComObject;
3235 int (STDCALL *QueryInterface)(MonoComObject* pUnk, gpointer riid, gpointer* ppv);
3236 int (STDCALL *AddRef)(MonoComObject* pUnk);
3237 int (STDCALL *Release)(MonoComObject* pUnk);
3238 int (STDCALL *get_ITest)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3239 int (STDCALL *SByteIn)(MonoComObject* pUnk, char a);
3240 int (STDCALL *ByteIn)(MonoComObject* pUnk, unsigned char a);
3241 int (STDCALL *ShortIn)(MonoComObject* pUnk, short a);
3242 int (STDCALL *UShortIn)(MonoComObject* pUnk, unsigned short a);
3243 int (STDCALL *IntIn)(MonoComObject* pUnk, int a);
3244 int (STDCALL *UIntIn)(MonoComObject* pUnk, unsigned int a);
3245 int (STDCALL *LongIn)(MonoComObject* pUnk, gint64 a);
3246 int (STDCALL *ULongIn)(MonoComObject* pUnk, guint64 a);
3247 int (STDCALL *FloatIn)(MonoComObject* pUnk, float a);
3248 int (STDCALL *DoubleIn)(MonoComObject* pUnk, double a);
3249 int (STDCALL *ITestIn)(MonoComObject* pUnk, MonoComObject* pUnk2);
3250 int (STDCALL *ITestOut)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3253 struct MonoComObject
3259 static GUID IID_ITest = {0, 0, 0, {0,0,0,0,0,0,0,1}};
3260 static GUID IID_IMonoUnknown = {0, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3261 static GUID IID_IMonoDispatch = {0x00020400, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3263 LIBTEST_API int STDCALL
3264 MonoQueryInterface(MonoComObject* pUnk, gpointer riid, gpointer* ppv)
3268 if (!memcmp(riid, &IID_IMonoUnknown, sizeof(GUID))) {
3272 else if (!memcmp(riid, &IID_ITest, sizeof(GUID))) {
3276 else if (!memcmp(riid, &IID_IMonoDispatch, sizeof(GUID))) {
3280 return 0x80004002; //E_NOINTERFACE;
3283 LIBTEST_API int STDCALL
3284 MonoAddRef(MonoComObject* pUnk)
3286 return ++(pUnk->m_ref);
3289 LIBTEST_API int STDCALL
3290 MonoRelease(MonoComObject* pUnk)
3292 return --(pUnk->m_ref);
3295 LIBTEST_API int STDCALL
3296 SByteIn(MonoComObject* pUnk, char a)
3301 LIBTEST_API int STDCALL
3302 ByteIn(MonoComObject* pUnk, unsigned char a)
3307 LIBTEST_API int STDCALL
3308 ShortIn(MonoComObject* pUnk, short a)
3313 LIBTEST_API int STDCALL
3314 UShortIn(MonoComObject* pUnk, unsigned short a)
3319 LIBTEST_API int STDCALL
3320 IntIn(MonoComObject* pUnk, int a)
3325 LIBTEST_API int STDCALL
3326 UIntIn(MonoComObject* pUnk, unsigned int a)
3331 LIBTEST_API int STDCALL
3332 LongIn(MonoComObject* pUnk, gint64 a)
3337 LIBTEST_API int STDCALL
3338 ULongIn(MonoComObject* pUnk, guint64 a)
3343 LIBTEST_API int STDCALL
3344 FloatIn(MonoComObject* pUnk, float a)
3349 LIBTEST_API int STDCALL
3350 DoubleIn(MonoComObject* pUnk, double a)
3355 LIBTEST_API int STDCALL
3356 ITestIn(MonoComObject* pUnk, MonoComObject *pUnk2)
3361 LIBTEST_API int STDCALL
3362 ITestOut(MonoComObject* pUnk, MonoComObject* *ppUnk)
3367 static void create_com_object (MonoComObject** pOut);
3369 LIBTEST_API int STDCALL
3370 get_ITest(MonoComObject* pUnk, MonoComObject* *ppUnk)
3372 create_com_object (ppUnk);
3376 static void create_com_object (MonoComObject** pOut)
3378 *pOut = marshal_new0 (MonoComObject, 1);
3379 (*pOut)->vtbl = marshal_new0 (MonoIUnknown, 1);
3382 (*pOut)->vtbl->QueryInterface = MonoQueryInterface;
3383 (*pOut)->vtbl->AddRef = MonoAddRef;
3384 (*pOut)->vtbl->Release = MonoRelease;
3385 (*pOut)->vtbl->SByteIn = SByteIn;
3386 (*pOut)->vtbl->ByteIn = ByteIn;
3387 (*pOut)->vtbl->ShortIn = ShortIn;
3388 (*pOut)->vtbl->UShortIn = UShortIn;
3389 (*pOut)->vtbl->IntIn = IntIn;
3390 (*pOut)->vtbl->UIntIn = UIntIn;
3391 (*pOut)->vtbl->LongIn = LongIn;
3392 (*pOut)->vtbl->ULongIn = ULongIn;
3393 (*pOut)->vtbl->FloatIn = FloatIn;
3394 (*pOut)->vtbl->DoubleIn = DoubleIn;
3395 (*pOut)->vtbl->ITestIn = ITestIn;
3396 (*pOut)->vtbl->ITestOut = ITestOut;
3397 (*pOut)->vtbl->get_ITest = get_ITest;
3400 static MonoComObject* same_object = NULL;
3402 LIBTEST_API int STDCALL
3403 mono_test_marshal_com_object_create(MonoComObject* *pUnk)
3405 create_com_object (pUnk);
3408 same_object = *pUnk;
3413 LIBTEST_API int STDCALL
3414 mono_test_marshal_com_object_same(MonoComObject* *pUnk)
3416 *pUnk = same_object;
3421 LIBTEST_API int STDCALL
3422 mono_test_marshal_com_object_destroy(MonoComObject *pUnk)
3424 int ref = --(pUnk->m_ref);
3431 LIBTEST_API int STDCALL
3432 mono_test_marshal_com_object_ref_count(MonoComObject *pUnk)
3437 LIBTEST_API int STDCALL
3438 mono_test_marshal_ccw_itest (MonoComObject *pUnk)
3441 MonoComObject* pTest;
3446 hr = pUnk->vtbl->SByteIn (pUnk, -100);
3449 hr = pUnk->vtbl->ByteIn (pUnk, 100);
3452 hr = pUnk->vtbl->ShortIn (pUnk, -100);
3455 hr = pUnk->vtbl->UShortIn (pUnk, 100);
3458 hr = pUnk->vtbl->IntIn (pUnk, -100);
3461 hr = pUnk->vtbl->UIntIn (pUnk, 100);
3464 hr = pUnk->vtbl->LongIn (pUnk, -100);
3467 hr = pUnk->vtbl->ULongIn (pUnk, 100);
3470 hr = pUnk->vtbl->FloatIn (pUnk, 3.14f);
3473 hr = pUnk->vtbl->DoubleIn (pUnk, 3.14);
3476 hr = pUnk->vtbl->ITestIn (pUnk, pUnk);
3479 hr = pUnk->vtbl->ITestOut (pUnk, &pTest);
3487 * mono_method_get_unmanaged_thunk tests
3490 #if defined(__GNUC__) && ((defined(__i386__) && (defined(__linux__) || defined (__APPLE__)) || defined (__FreeBSD__) || defined(__OpenBSD__)) || (defined(__ppc__) && defined(__APPLE__)))
3491 #define ALIGN(size) __attribute__ ((aligned(size)))
3497 /* thunks.cs:TestStruct */
3498 typedef struct _TestStruct {
3503 /* Searches for mono symbols in all loaded modules */
3505 lookup_mono_symbol (const char *symbol_name)
3508 if (g_module_symbol (g_module_open (NULL, G_MODULE_BIND_LAZY), symbol_name, &symbol))
3514 LIBTEST_API gpointer STDCALL
3515 mono_test_marshal_lookup_symbol (const char *symbol_name)
3517 return lookup_mono_symbol (symbol_name);
3521 * test_method_thunk:
3523 * @test_id: the test number
3524 * @test_method_handle: MonoMethod* of the C# test method
3525 * @create_object_method_handle: MonoMethod* of thunks.cs:Test.CreateObject
3527 LIBTEST_API int STDCALL
3528 test_method_thunk (int test_id, gpointer test_method_handle, gpointer create_object_method_handle)
3530 gpointer (*mono_method_get_unmanaged_thunk)(gpointer)
3531 = lookup_mono_symbol ("mono_method_get_unmanaged_thunk");
3533 gpointer (*mono_string_new_wrapper)(const char *)
3534 = lookup_mono_symbol ("mono_string_new_wrapper");
3536 char* (*mono_string_to_utf8)(gpointer)
3537 = lookup_mono_symbol ("mono_string_to_utf8");
3539 gpointer (*mono_object_unbox)(gpointer)
3540 = lookup_mono_symbol ("mono_object_unbox");
3542 gpointer test_method, ex = NULL;
3543 gpointer (STDCALL *CreateObject)(gpointer*);
3545 if (!mono_method_get_unmanaged_thunk)
3548 test_method = mono_method_get_unmanaged_thunk (test_method_handle);
3552 CreateObject = mono_method_get_unmanaged_thunk (create_object_method_handle);
3560 /* thunks.cs:Test.Test0 */
3561 void (STDCALL *F)(gpointer*) = test_method;
3567 /* thunks.cs:Test.Test1 */
3568 int (STDCALL *F)(gpointer*) = test_method;
3575 /* thunks.cs:Test.Test2 */
3576 gpointer (STDCALL *F)(gpointer, gpointer*) = test_method;
3577 gpointer str = mono_string_new_wrapper ("foo");
3578 if (str != F (str, &ex))
3584 /* thunks.cs:Test.Test3 */
3585 gpointer (STDCALL *F)(gpointer, gpointer, gpointer*);
3590 obj = CreateObject (&ex);
3591 str = mono_string_new_wrapper ("bar");
3593 if (str != F (obj, str, &ex))
3599 /* thunks.cs:Test.Test4 */
3600 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3605 obj = CreateObject (&ex);
3606 str = mono_string_new_wrapper ("bar");
3608 if (42 != F (obj, str, 42, &ex))
3615 /* thunks.cs:Test.Test5 */
3616 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3621 obj = CreateObject (&ex);
3622 str = mono_string_new_wrapper ("bar");
3624 F (obj, str, 42, &ex);
3632 /* thunks.cs:Test.Test6 */
3633 int (STDCALL *F)(gpointer, guint8, gint16, gint32, gint64, float, double,
3634 gpointer, gpointer*);
3636 gpointer str = mono_string_new_wrapper ("Test6");
3640 obj = CreateObject (&ex);
3642 res = F (obj, 254, 32700, -245378, 6789600, 3.1415, 3.1415, str, &ex);
3653 /* thunks.cs:Test.Test7 */
3654 gint64 (STDCALL *F)(gpointer*) = test_method;
3655 if (F (&ex) != G_MAXINT64)
3661 /* thunks.cs:Test.Test8 */
3662 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3663 gpointer*, gpointer*);
3675 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3683 (fabs (a5 - 3.1415) < 0.001) &&
3684 (fabs (a6 - 3.1415) < 0.001) &&
3685 strcmp (mono_string_to_utf8 (a7), "Test8") == 0))
3692 /* thunks.cs:Test.Test9 */
3693 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3694 gpointer*, gpointer*);
3706 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3714 /* thunks.cs:Test.Test10 */
3715 void (STDCALL *F)(gpointer*, gpointer*);
3717 gpointer obj1, obj2;
3719 obj1 = obj2 = CreateObject (&ex);
3736 /* thunks.cs:TestStruct.Test0 */
3737 int (STDCALL *F)(gpointer*, gpointer*);
3743 obj = CreateObject (&ex);
3750 a1 = mono_object_unbox (obj);
3766 /* check whether the call was really by value */
3767 if (a1->A != 42 || a1->B != 3.1415)
3774 /* thunks.cs:TestStruct.Test1 */
3775 void (STDCALL *F)(gpointer, gpointer*);
3780 obj = CreateObject (&ex);
3787 a1 = mono_object_unbox (obj);
3800 if (!fabs (a1->B - 3.1415) < 0.001)
3807 /* thunks.cs:TestStruct.Test2 */
3808 gpointer (STDCALL *F)(gpointer*);
3822 a1 = mono_object_unbox (obj);
3827 if (!fabs (a1->B - 3.1415) < 0.001)
3834 /* thunks.cs:TestStruct.Test3 */
3835 void (STDCALL *F)(gpointer, gpointer*);
3840 obj = CreateObject (&ex);
3847 a1 = mono_object_unbox (obj);
3883 LIBTEST_API int STDCALL
3884 mono_test_Winx64_struct1_in (winx64_struct1 var)
3897 LIBTEST_API int STDCALL
3898 mono_test_Winx64_struct2_in (winx64_struct2 var)
3915 LIBTEST_API int STDCALL
3916 mono_test_Winx64_struct3_in (winx64_struct3 var)
3922 if (var.c != 0x1234)
3935 LIBTEST_API int STDCALL
3936 mono_test_Winx64_struct4_in (winx64_struct4 var)
3942 if (var.c != 0x1234)
3944 if (var.d != 0x87654321)
3956 LIBTEST_API int STDCALL
3957 mono_test_Winx64_struct5_in (winx64_struct5 var)
3975 LIBTEST_API int STDCALL
3976 mono_test_Winx64_struct6_in (winx64_struct6 var)
3987 LIBTEST_API int STDCALL
3988 mono_test_Winx64_structs_in1 (winx64_struct1 var1,
3989 winx64_struct2 var2,
3990 winx64_struct3 var3,
3991 winx64_struct4 var4)
4005 if (var3.c != 0x1234)
4012 if (var4.c != 0x1234)
4014 if (var4.d != 0x87654321)
4019 LIBTEST_API int STDCALL
4020 mono_test_Winx64_structs_in2 (winx64_struct1 var1,
4021 winx64_struct1 var2,
4022 winx64_struct1 var3,
4023 winx64_struct1 var4,
4024 winx64_struct1 var5)
4040 LIBTEST_API int STDCALL
4041 mono_test_Winx64_structs_in3 (winx64_struct1 var1,
4042 winx64_struct5 var2,
4043 winx64_struct1 var3,
4044 winx64_struct5 var4,
4045 winx64_struct1 var5,
4046 winx64_struct5 var6)
4081 LIBTEST_API winx64_struct1 STDCALL
4082 mono_test_Winx64_struct1_ret (void)
4089 LIBTEST_API winx64_struct2 STDCALL
4090 mono_test_Winx64_struct2_ret (void)
4098 LIBTEST_API winx64_struct3 STDCALL
4099 mono_test_Winx64_struct3_ret (void)
4108 LIBTEST_API winx64_struct4 STDCALL
4109 mono_test_Winx64_struct4_ret (void)
4119 LIBTEST_API winx64_struct5 STDCALL
4120 mono_test_Winx64_struct5_ret (void)
4129 LIBTEST_API winx64_struct1 STDCALL
4130 mono_test_Winx64_struct1_ret_5_args (char a, char b, char c, char d, char e)
4133 ret.a = a + b + c + d + e;
4137 LIBTEST_API winx64_struct5 STDCALL
4138 mono_test_Winx64_struct5_ret6_args (char a, char b, char c, char d, char e)
4151 } winx64_floatStruct;
4153 LIBTEST_API int STDCALL
4154 mono_test_Winx64_floatStruct (winx64_floatStruct a)
4156 if (a.a > 5.6 || a.a < 5.4)
4159 if (a.b > 9.6 || a.b < 9.4)
4168 } winx64_doubleStruct;
4170 LIBTEST_API int STDCALL
4171 mono_test_Winx64_doubleStruct (winx64_doubleStruct a)
4173 if (a.a > 5.6 || a.a < 5.4)
4179 typedef int (STDCALL *managed_struct1_delegate) (winx64_struct1 a);
4181 LIBTEST_API int STDCALL
4182 mono_test_managed_Winx64_struct1_in(managed_struct1_delegate func)
4189 typedef int (STDCALL *managed_struct5_delegate) (winx64_struct5 a);
4191 LIBTEST_API int STDCALL
4192 mono_test_managed_Winx64_struct5_in(managed_struct5_delegate func)
4201 typedef int (STDCALL *managed_struct1_struct5_delegate) (winx64_struct1 a, winx64_struct5 b,
4202 winx64_struct1 c, winx64_struct5 d,
4203 winx64_struct1 e, winx64_struct5 f);
4205 LIBTEST_API int STDCALL
4206 mono_test_managed_Winx64_struct1_struct5_in(managed_struct1_struct5_delegate func)
4208 winx64_struct1 a, c, e;
4209 winx64_struct5 b, d, f;
4211 b.a = 2; b.b = 3; b.c = 4;
4213 d.a = 6; d.b = 7; d.c = 8;
4215 f.a = 10; f.b = 11; f.c = 12;
4217 return func (a, b, c, d, e, f);
4220 typedef winx64_struct1 (STDCALL *managed_struct1_ret_delegate) (void);
4222 LIBTEST_API int STDCALL
4223 mono_test_Winx64_struct1_ret_managed (managed_struct1_ret_delegate func)
4235 typedef winx64_struct5 (STDCALL *managed_struct5_ret_delegate) (void);
4237 LIBTEST_API int STDCALL
4238 mono_test_Winx64_struct5_ret_managed (managed_struct5_ret_delegate func)
4254 LIBTEST_API int STDCALL
4255 mono_test_marshal_bool_in (int arg, unsigned int expected, unsigned int bDefaultMarsh, unsigned int bBoolCustMarsh,
4256 char bI1CustMarsh, unsigned char bU1CustMarsh, short bVBCustMarsh)
4260 if (bDefaultMarsh != expected)
4264 if (bBoolCustMarsh != expected)
4268 if (bI1CustMarsh != expected)
4272 if (bU1CustMarsh != expected)
4276 if (bVBCustMarsh != expected)
4285 LIBTEST_API int STDCALL
4286 mono_test_marshal_bool_out (int arg, unsigned int testVal, unsigned int* bDefaultMarsh, unsigned int* bBoolCustMarsh,
4287 char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh)
4293 *bDefaultMarsh = testVal;
4296 if (!bBoolCustMarsh)
4298 *bBoolCustMarsh = testVal;
4303 *bI1CustMarsh = (char)testVal;
4308 *bU1CustMarsh = (unsigned char)testVal;
4313 *bVBCustMarsh = (unsigned short)testVal;
4321 LIBTEST_API int STDCALL
4322 mono_test_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4323 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh,
4324 unsigned short* bVBCustMarsh)
4330 if (*bDefaultMarsh != expected)
4332 *bDefaultMarsh = testVal;
4335 if (!bBoolCustMarsh)
4337 if (*bBoolCustMarsh != expected)
4339 *bBoolCustMarsh = testVal;
4344 if (*bI1CustMarsh != expected)
4346 *bI1CustMarsh = (char)testVal;
4351 if (*bU1CustMarsh != expected)
4353 *bU1CustMarsh = (unsigned char)testVal;
4358 if (*bVBCustMarsh != expected)
4360 *bVBCustMarsh = (unsigned short)testVal;
4369 typedef int (STDCALL *MarshalBoolInDelegate) (int arg, unsigned int expected, unsigned int bDefaultMarsh,
4370 unsigned int bBoolCustMarsh, char bI1CustMarsh, unsigned char bU1CustMarsh, unsigned short bVBCustMarsh);
4372 LIBTEST_API int STDCALL
4373 mono_test_managed_marshal_bool_in (int arg, unsigned int expected, unsigned int testVal, MarshalBoolInDelegate pfcn)
4380 return pfcn (arg, expected, testVal, 0, 0, 0, 0);
4382 return pfcn (arg, expected, 0, testVal, 0, 0, 0);
4384 return pfcn (arg, expected, 0, 0, testVal, 0, 0);
4386 return pfcn (arg, expected, 0, 0, 0, testVal, 0);
4388 return pfcn (arg, expected, 0, 0, 0, 0, testVal);
4396 typedef int (STDCALL *MarshalBoolOutDelegate) (int arg, unsigned int expected, unsigned int* bDefaultMarsh,
4397 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4399 LIBTEST_API int STDCALL
4400 mono_test_managed_marshal_bool_out (int arg, unsigned int expected, unsigned int testVal, MarshalBoolOutDelegate pfcn)
4403 unsigned int lDefaultMarsh, lBoolCustMarsh;
4404 char lI1CustMarsh = 0;
4405 unsigned char lU1CustMarsh = 0;
4406 unsigned short lVBCustMarsh = 0;
4407 lDefaultMarsh = lBoolCustMarsh = 0;
4414 unsigned int ltVal = 0;
4415 ret = pfcn (arg, testVal, <Val, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4417 return 0x0100 + ret;
4418 if (expected != ltVal)
4423 unsigned int ltVal = 0;
4424 ret = pfcn (arg, testVal, &lDefaultMarsh, <Val, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4426 return 0x0300 + ret;
4427 if (expected != ltVal)
4433 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, <Val, &lU1CustMarsh, &lVBCustMarsh);
4435 return 0x0500 + ret;
4436 if (expected != ltVal)
4441 unsigned char ltVal = 0;
4442 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <Val, &lVBCustMarsh);
4444 return 0x0700 + ret;
4445 if (expected != ltVal)
4450 unsigned short ltVal = 0;
4451 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <Val);
4453 return 0x0900 + ret;
4454 if (expected != ltVal)
4465 typedef int (STDCALL *MarshalBoolRefDelegate) (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4466 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4468 LIBTEST_API int STDCALL
4469 mono_test_managed_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int outExpected,
4470 unsigned int outTestVal, MarshalBoolRefDelegate pfcn)
4473 unsigned int lDefaultMarsh, lBoolCustMarsh;
4474 char lI1CustMarsh = 0;
4475 unsigned char lU1CustMarsh = 0;
4476 unsigned short lVBCustMarsh = 0;
4477 lDefaultMarsh = lBoolCustMarsh = 0;
4485 unsigned int ltestVal = testVal;
4486 ret = pfcn (arg, expected, outTestVal, <estVal, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4488 return 0x0100 + ret;
4489 if (outExpected != ltestVal)
4495 unsigned int ltestVal = testVal;
4496 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, <estVal, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4498 return 0x0300 + ret;
4499 if (outExpected != ltestVal)
4505 char ltestVal = testVal;
4506 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, <estVal, &lU1CustMarsh, &lVBCustMarsh);
4508 return 0x0500 + ret;
4509 if (outExpected != ltestVal)
4515 unsigned char ltestVal = testVal;
4516 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <estVal, &lVBCustMarsh);
4518 return 0x0700 + ret;
4519 if (outExpected != ltestVal)
4525 unsigned short ltestVal = testVal;
4526 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <estVal);
4528 return 0x0900 + ret;
4529 if (outExpected != ltestVal)
4542 LIBTEST_API int STDCALL
4543 mono_test_marshal_safearray_out_1dim_vt_bstr_empty (SAFEARRAY** safearray)
4545 /* Create an empty one-dimensional array of variants */
4547 SAFEARRAYBOUND dimensions [1];
4549 dimensions [0].lLbound = 0;
4550 dimensions [0].cElements = 0;
4552 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4557 LIBTEST_API int STDCALL
4558 mono_test_marshal_safearray_out_1dim_vt_bstr (SAFEARRAY** safearray)
4560 /* Create a one-dimensional array of 10 variants filled with "0" to "9" */
4562 SAFEARRAYBOUND dimensions [1];
4568 dimensions [0].lLbound = 0;
4569 dimensions [0].cElements = 10;
4571 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4572 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4574 VariantInit (&vOut);
4576 _ltoa (i,buffer,10);
4577 vOut.bstrVal= marshal_bstr_alloc (buffer);
4579 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4580 VariantClear (&vOut);
4581 SafeArrayDestroy (pSA);
4584 VariantClear (&vOut);
4590 LIBTEST_API int STDCALL
4591 mono_test_marshal_safearray_out_2dim_vt_i4 (SAFEARRAY** safearray)
4593 /* Create a two-dimensional array of 4x3 variants filled with 11, 12, 13, etc. */
4595 SAFEARRAYBOUND dimensions [2];
4600 dimensions [0].lLbound = 0;
4601 dimensions [0].cElements = 4;
4602 dimensions [1].lLbound = 0;
4603 dimensions [1].cElements = 3;
4605 pSA= SafeArrayCreate(VT_VARIANT, 2, dimensions);
4606 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4607 for (j= dimensions [1].lLbound; j< (dimensions [1].cElements + dimensions [1].lLbound); j++) {
4609 VariantInit (&vOut);
4611 vOut.lVal = (i+1)*10+(j+1);
4614 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4615 VariantClear (&vOut);
4616 SafeArrayDestroy (pSA);
4619 VariantClear (&vOut); // does a deep destroy of source VARIANT
4626 LIBTEST_API int STDCALL
4627 mono_test_marshal_safearray_out_4dim_vt_i4 (SAFEARRAY** safearray)
4629 /* Create a four-dimensional array of 10x3x6x7 variants filled with their indices */
4630 /* Also use non zero lower bounds */
4632 SAFEARRAYBOUND dimensions [4];
4637 dimensions [0].lLbound = 15;
4638 dimensions [0].cElements = 10;
4639 dimensions [1].lLbound = 20;
4640 dimensions [1].cElements = 3;
4641 dimensions [2].lLbound = 5;
4642 dimensions [2].cElements = 6;
4643 dimensions [3].lLbound = 12;
4644 dimensions [3].cElements = 7;
4646 pSA= SafeArrayCreate (VT_VARIANT, 4, dimensions);
4648 SafeArrayAccessData (pSA, (void **)&pData);
4650 for (i= 0; i< 10*3*6*7; i++) {
4651 VariantInit(&pData [i]);
4652 pData [i].vt = VT_I4;
4655 SafeArrayUnaccessData (pSA);
4660 LIBTEST_API int STDCALL
4661 mono_test_marshal_safearray_in_byval_1dim_empty (SAFEARRAY* safearray)
4663 /* Check that array is one dimensional and empty */
4666 long lbound, ubound;
4668 dim = SafeArrayGetDim (safearray);
4672 SafeArrayGetLBound (safearray, 1, &lbound);
4673 SafeArrayGetUBound (safearray, 1, &ubound);
4675 if ((lbound > 0) || (ubound > 0))
4681 LIBTEST_API int STDCALL
4682 mono_test_marshal_safearray_in_byval_1dim_vt_i4 (SAFEARRAY* safearray)
4684 /* Check that array is one dimensional containing integers from 1 to 10 */
4687 long lbound, ubound;
4692 dim = SafeArrayGetDim (safearray);
4696 SafeArrayGetLBound (safearray, 1, &lbound);
4697 SafeArrayGetUBound (safearray, 1, &ubound);
4699 if ((lbound != 0) || (ubound != 9))
4702 SafeArrayAccessData (safearray, (void **)&pData);
4703 for (i= lbound; i <= ubound; i++) {
4704 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i + 1))
4707 SafeArrayUnaccessData (safearray);
4712 LIBTEST_API int STDCALL
4713 mono_test_marshal_safearray_in_byval_1dim_vt_mixed (SAFEARRAY* safearray)
4715 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4718 long lbound, ubound;
4725 VariantInit (&element);
4727 dim = SafeArrayGetDim (safearray);
4731 SafeArrayGetLBound (safearray, 1, &lbound);
4732 SafeArrayGetUBound (safearray, 1, &ubound);
4734 if ((lbound != 0) || (ubound != 12))
4737 SafeArrayAccessData (safearray, (void **)&pData);
4738 for (i= lbound; i <= ubound; i++) {
4739 if ((i%2 == 0) && (pData [i].vt != VT_I4))
4741 if ((i%2 == 1) && (pData [i].vt != VT_BSTR))
4743 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i))
4746 SafeArrayUnaccessData (safearray);
4748 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4753 SafeArrayPutElement (safearray, indices, &element);
4754 VariantClear (&element);
4759 LIBTEST_API int STDCALL
4760 mono_test_marshal_safearray_in_byval_2dim_vt_i4 (SAFEARRAY* safearray)
4762 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4765 long lbound1, ubound1, lbound2, ubound2;
4770 VariantInit (&element);
4772 dim = SafeArrayGetDim (safearray);
4776 SafeArrayGetLBound (safearray, 1, &lbound1);
4777 SafeArrayGetUBound (safearray, 1, &ubound1);
4779 if ((lbound1 != 0) || (ubound1 != 1))
4782 SafeArrayGetLBound (safearray, 2, &lbound2);
4783 SafeArrayGetUBound (safearray, 2, &ubound2);
4785 if ((lbound2 != 0) || (ubound2 != 3)) {
4789 for (i= lbound1; i <= ubound1; i++) {
4791 for (j= lbound2; j <= ubound2; j++) {
4793 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4795 failed = ((element.vt != VT_I4) || (element.lVal != 10*(i+1)+(j+1)));
4796 VariantClear (&element);
4802 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4808 SafeArrayPutElement (safearray, indices, &element);
4809 VariantClear (&element);
4814 LIBTEST_API int STDCALL
4815 mono_test_marshal_safearray_in_byval_3dim_vt_bstr (SAFEARRAY* safearray)
4817 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4820 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4821 long i, j, k, failed;
4825 VariantInit (&element);
4827 dim = SafeArrayGetDim (safearray);
4831 SafeArrayGetLBound (safearray, 1, &lbound1);
4832 SafeArrayGetUBound (safearray, 1, &ubound1);
4834 if ((lbound1 != 0) || (ubound1 != 1))
4837 SafeArrayGetLBound (safearray, 2, &lbound2);
4838 SafeArrayGetUBound (safearray, 2, &ubound2);
4840 if ((lbound2 != 0) || (ubound2 != 1))
4843 SafeArrayGetLBound (safearray, 3, &lbound3);
4844 SafeArrayGetUBound (safearray, 3, &ubound3);
4846 if ((lbound3 != 0) || (ubound3 != 2))
4849 for (i= lbound1; i <= ubound1; i++) {
4851 for (j= lbound2; j <= ubound2; j++) {
4853 for (k= lbound3; k <= ubound3; k++) {
4855 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4857 failed = ((element.vt != VT_BSTR)
4858 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4859 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4860 VariantClear (&element);
4867 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4872 element.vt = VT_BSTR;
4873 element.bstrVal = SysAllocString(L"Should not be copied");
4874 SafeArrayPutElement (safearray, indices, &element);
4875 VariantClear (&element);
4880 LIBTEST_API int STDCALL
4881 mono_test_marshal_safearray_in_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4883 return mono_test_marshal_safearray_in_byval_3dim_vt_bstr (*safearray);
4886 LIBTEST_API int STDCALL
4887 mono_test_marshal_safearray_in_out_byref_1dim_empty (SAFEARRAY** safearray)
4889 /* Check that the input array is what is expected and change it so the caller can check */
4890 /* correct marshalling back to managed code */
4893 long lbound, ubound;
4894 SAFEARRAYBOUND dimensions [1];
4896 wchar_t buffer [20];
4900 /* Check that in array is one dimensional and empty */
4902 dim = SafeArrayGetDim (*safearray);
4907 SafeArrayGetLBound (*safearray, 1, &lbound);
4908 SafeArrayGetUBound (*safearray, 1, &ubound);
4910 if ((lbound > 0) || (ubound > 0)) {
4914 /* Re-dimension the array and return a one-dimensional array of 8 variants filled with "0" to "7" */
4916 dimensions [0].lLbound = 0;
4917 dimensions [0].cElements = 8;
4919 hr = SafeArrayRedim (*safearray, dimensions);
4923 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
4925 VariantInit (&vOut);
4927 _ltow (i,buffer,10);
4928 vOut.bstrVal = SysAllocString (buffer);
4930 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
4931 VariantClear (&vOut);
4932 SafeArrayDestroy (*safearray);
4935 VariantClear (&vOut);
4940 LIBTEST_API int STDCALL
4941 mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4943 /* Check that the input array is what is expected and change it so the caller can check */
4944 /* correct marshalling back to managed code */
4947 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4948 SAFEARRAYBOUND dimensions [1];
4949 long i, j, k, failed;
4950 wchar_t buffer [20];
4955 VariantInit (&element);
4957 /* Check that in array is three dimensional and contains the expected values */
4959 dim = SafeArrayGetDim (*safearray);
4963 SafeArrayGetLBound (*safearray, 1, &lbound1);
4964 SafeArrayGetUBound (*safearray, 1, &ubound1);
4966 if ((lbound1 != 0) || (ubound1 != 1))
4969 SafeArrayGetLBound (*safearray, 2, &lbound2);
4970 SafeArrayGetUBound (*safearray, 2, &ubound2);
4972 if ((lbound2 != 0) || (ubound2 != 1))
4975 SafeArrayGetLBound (*safearray, 3, &lbound3);
4976 SafeArrayGetUBound (*safearray, 3, &ubound3);
4978 if ((lbound3 != 0) || (ubound3 != 2))
4981 for (i= lbound1; i <= ubound1; i++) {
4983 for (j= lbound2; j <= ubound2; j++) {
4985 for (k= lbound3; k <= ubound3; k++) {
4987 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
4989 failed = ((element.vt != VT_BSTR)
4990 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4991 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4992 VariantClear (&element);
4999 hr = SafeArrayDestroy (*safearray);
5003 /* Return a new one-dimensional array of 8 variants filled with "0" to "7" */
5005 dimensions [0].lLbound = 0;
5006 dimensions [0].cElements = 8;
5008 *safearray = SafeArrayCreate (VT_VARIANT, 1, dimensions);
5010 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
5012 VariantInit (&vOut);
5014 _ltow (i,buffer,10);
5015 vOut.bstrVal = SysAllocString (buffer);
5017 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
5018 VariantClear (&vOut);
5019 SafeArrayDestroy (*safearray);
5022 VariantClear (&vOut);
5027 LIBTEST_API int STDCALL
5028 mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 (SAFEARRAY** safearray)
5030 /* Check that the input array is what is expected and change it so the caller can check */
5031 /* correct marshalling back to managed code */
5034 long lbound1, ubound1;
5040 VariantInit (&element);
5042 /* Check that in array is one dimensional and contains the expected value */
5044 dim = SafeArrayGetDim (*safearray);
5048 SafeArrayGetLBound (*safearray, 1, &lbound1);
5049 SafeArrayGetUBound (*safearray, 1, &ubound1);
5052 if ((lbound1 != 0) || (ubound1 != 1))
5056 for (i= lbound1; i <= ubound1; i++) {
5058 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
5060 failed = (element.vt != VT_I4) || (element.lVal != i+1);
5061 VariantClear (&element);
5066 /* Change one of the elements of the array to verify that [out] parameter is marshalled back to the managed side */
5071 SafeArrayPutElement (*safearray, indices, &element);
5072 VariantClear (&element);
5077 LIBTEST_API int STDCALL
5078 mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (SAFEARRAY* safearray)
5080 /* Check that the input array is what is expected and change it so the caller can check */
5081 /* correct marshalling back to managed code */
5084 long lbound1, ubound1;
5085 SAFEARRAYBOUND dimensions [1];
5091 VariantInit (&element);
5093 /* Check that in array is one dimensional and contains the expected value */
5095 dim = SafeArrayGetDim (safearray);
5099 SafeArrayGetLBound (safearray, 1, &lbound1);
5100 SafeArrayGetUBound (safearray, 1, &ubound1);
5102 if ((lbound1 != 0) || (ubound1 != 0))
5105 for (i= lbound1; i <= ubound1; i++) {
5107 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
5109 failed = (element.vt != VT_I4) || (element.lVal != i+1);
5110 VariantClear (&element);
5115 /* Change the array to verify how [out] parameter is marshalled back to the managed side */
5117 /* Redimension the array */
5118 dimensions [0].lLbound = lbound1;
5119 dimensions [0].cElements = 2;
5120 hr = SafeArrayRedim(safearray, dimensions);
5124 element.lVal = 12345;
5125 SafeArrayPutElement (safearray, indices, &element);
5126 VariantClear (&element);
5130 element.lVal = -12345;
5131 SafeArrayPutElement (safearray, indices, &element);
5132 VariantClear (&element);
5137 LIBTEST_API int STDCALL
5138 mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr (SAFEARRAY* safearray)
5140 /* Check that the input array is what is expected and change it so the caller can check */
5141 /* correct marshalling back to managed code */
5144 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
5145 long i, j, k, failed;
5150 VariantInit (&element);
5152 /* Check that in array is three dimensional and contains the expected values */
5154 dim = SafeArrayGetDim (safearray);
5158 SafeArrayGetLBound (safearray, 1, &lbound1);
5159 SafeArrayGetUBound (safearray, 1, &ubound1);
5161 if ((lbound1 != 0) || (ubound1 != 1))
5164 SafeArrayGetLBound (safearray, 2, &lbound2);
5165 SafeArrayGetUBound (safearray, 2, &ubound2);
5167 if ((lbound2 != 0) || (ubound2 != 1))
5170 SafeArrayGetLBound (safearray, 3, &lbound3);
5171 SafeArrayGetUBound (safearray, 3, &ubound3);
5173 if ((lbound3 != 0) || (ubound3 != 2))
5176 for (i= lbound1; i <= ubound1; i++) {
5178 for (j= lbound2; j <= ubound2; j++) {
5180 for (k= lbound3; k <= ubound3; k++) {
5182 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
5184 failed = ((element.vt != VT_BSTR)
5185 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
5186 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
5187 VariantClear (&element);
5194 /* Change the elements of the array to verify that [out] parameter is marshalled back to the managed side */
5201 SafeArrayPutElement (safearray, indices, &element);
5202 VariantClear (&element);
5209 SafeArrayPutElement (safearray, indices, &element);
5210 VariantClear (&element);
5215 element.vt = VT_BSTR;
5216 element.bstrVal = marshal_bstr_alloc("ABCDEFG");
5217 SafeArrayPutElement (safearray, indices, &element);
5218 VariantClear (&element);
5223 LIBTEST_API int STDCALL
5224 mono_test_marshal_safearray_mixed(
5225 SAFEARRAY *safearray1,
5226 SAFEARRAY **safearray2,
5227 SAFEARRAY *safearray3,
5228 SAFEARRAY **safearray4
5233 /* Initialize out parameters */
5236 /* array1: Check that in array is one dimensional and contains the expected value */
5237 hr = mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (safearray1);
5239 /* array2: Fill in with some values to check on the managed side */
5241 hr = mono_test_marshal_safearray_out_1dim_vt_bstr (safearray2);
5243 /* array3: Check that in array is one dimensional and contains the expected value */
5245 hr = mono_test_marshal_safearray_in_byval_1dim_vt_mixed(safearray3);
5247 /* array4: Check input values and fill in with some values to check on the managed side */
5249 hr = mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr(safearray4);
5256 static int call_managed_res;
5259 call_managed (gpointer arg)
5261 SimpleDelegate del = arg;
5263 call_managed_res = del (42);
5266 LIBTEST_API int STDCALL
5267 mono_test_marshal_thread_attach (SimpleDelegate del)
5275 res = pthread_create (&t, NULL, (gpointer)call_managed, del);
5276 g_assert (res == 0);
5277 pthread_join (t, NULL);
5279 return call_managed_res;
5283 typedef int (STDCALL *Callback) (void);
5285 static Callback callback;
5287 LIBTEST_API void STDCALL
5288 mono_test_marshal_set_callback (Callback cb)
5293 LIBTEST_API int STDCALL
5294 mono_test_marshal_call_callback (void)
5299 LIBTEST_API int STDCALL
5300 mono_test_marshal_lpstr (char *str)
5302 return strcmp ("ABC", str);
5305 LIBTEST_API int STDCALL
5306 mono_test_marshal_lpwstr (gunichar2 *str)
5311 s = g_utf16_to_utf8 (str, -1, NULL, NULL, NULL);
5312 res = strcmp ("ABC", s);
5318 LIBTEST_API char* STDCALL
5319 mono_test_marshal_return_lpstr (void)
5321 char *res = marshal_alloc (4);
5322 strcpy (res, "XYZ");
5327 LIBTEST_API gunichar2* STDCALL
5328 mono_test_marshal_return_lpwstr (void)
5330 gunichar2 *res = marshal_alloc (8);
5331 gunichar2* tmp = g_utf8_to_utf16 ("XYZ", -1, NULL, NULL, NULL);
5333 memcpy (res, tmp, 8);
5341 } SingleDoubleStruct;
5343 LIBTEST_API SingleDoubleStruct STDCALL
5344 mono_test_marshal_return_single_double_struct (void)
5346 SingleDoubleStruct res;
5356 LIBTEST_API int STDCALL
5357 mono_test_has_thiscall (void)
5363 _mono_test_native_thiscall1 (int arg)
5369 _mono_test_native_thiscall2 (int arg, int arg2)
5371 return arg + (arg2^1);
5375 _mono_test_native_thiscall3 (int arg, int arg2, int arg3)
5377 return arg + (arg2^1) + (arg3^2);
5380 #elif defined(__GNUC__)
5382 LIBTEST_API int STDCALL
5383 mono_test_has_thiscall (void)
5388 #define def_asm_fn(name) \
5390 "\t.globl _" #name "\n" \
5392 "\t.globl __" #name "\n" \
5397 def_asm_fn(mono_test_native_thiscall1)
5398 "\tmovl %ecx,%eax\n"
5401 def_asm_fn(mono_test_native_thiscall2)
5402 "\tmovl %ecx,%eax\n"
5403 "\tmovl 4(%esp),%ecx\n"
5405 "\taddl %ecx,%eax\n"
5408 def_asm_fn(mono_test_native_thiscall3)
5409 "\tmovl %ecx,%eax\n"
5410 "\tmovl 4(%esp),%ecx\n"
5412 "\taddl %ecx,%eax\n"
5413 "\tmovl 8(%esp),%ecx\n"
5415 "\taddl %ecx,%eax\n"
5422 LIBTEST_API int STDCALL
5423 mono_test_has_thiscall (void)