17 #define STDCALL __stdcall
23 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
27 extern __declspec(dllimport) void __stdcall CoTaskMemFree(void *ptr);
30 typedef int (STDCALL *SimpleDelegate) (int a);
32 #if defined(WIN32) && defined (_MSC_VER)
33 #define LIBTEST_API __declspec(dllexport)
38 static void marshal_free (void *ptr)
47 static void* marshal_alloc (gsize size)
50 return CoTaskMemAlloc (size);
52 return g_malloc (size);
57 static gunichar2* marshal_bstr_alloc(const gchar* str)
60 gunichar2* ret = NULL;
61 gunichar2* temp = NULL;
62 temp = g_utf8_to_utf16 (str, -1, NULL, NULL, NULL);
63 ret = SysAllocString (temp);
68 int slen = strlen (str);
70 /* allocate len + 1 utf16 characters plus 4 byte integer for length*/
71 ret = g_malloc ((slen + 1) * sizeof(gunichar2) + sizeof(guint32));
74 temp = g_utf8_to_utf16 (str, -1, NULL, NULL, NULL);
75 memcpy (ret + sizeof(guint32), temp, slen * sizeof(gunichar2));
76 * ((guint32 *) ret) = slen * sizeof(gunichar2);
77 ret [4 + slen * sizeof(gunichar2)] = 0;
78 ret [5 + slen * sizeof(gunichar2)] = 0;
80 return (gunichar2*)(ret + 4);
84 LIBTEST_API int STDCALL
85 mono_cominterop_is_supported (void)
87 #if defined(TARGET_X86) || defined(TARGET_AMD64)
93 LIBTEST_API unsigned short* STDCALL
94 test_lpwstr_marshal (unsigned short* chars, long length)
99 res = marshal_alloc (2 * (length + 1));
101 // printf("test_lpwstr_marshal()\n");
103 while ( i < length ) {
104 // printf("X|%u|\n", chars[i]);
115 LIBTEST_API void STDCALL
116 test_lpwstr_marshal_out (unsigned short** chars)
119 const char abc[] = "ABC";
120 glong len = strlen(abc);
122 *chars = marshal_alloc (2 * (len + 1));
125 (*chars) [i] = abc[i];
138 LIBTEST_API int STDCALL
139 mono_union_test_1 (union_test_1_type u1) {
140 // printf ("Got values %d %d %d\n", u1.b, u1.a, u1.c);
141 return u1.a + u1.b + u1.c;
144 LIBTEST_API int STDCALL
145 mono_return_int (int a) {
146 // printf ("Got value %d\n", a);
150 LIBTEST_API float STDCALL
151 mono_test_marshal_pass_return_float (float f) {
160 LIBTEST_API int STDCALL
161 mono_return_int_ss (struct ss a) {
162 // printf ("Got value %d\n", a.i);
166 LIBTEST_API struct ss STDCALL
167 mono_return_ss (struct ss a) {
168 // printf ("Got value %d\n", a.i);
178 LIBTEST_API struct sc1 STDCALL
179 mono_return_sc1 (struct sc1 a) {
180 // printf ("Got value %d\n", a.c[0]);
191 LIBTEST_API struct sc3 STDCALL
192 mono_return_sc3 (struct sc3 a) {
193 // printf ("Got values %d %d %d\n", a.c[0], a.c[1], a.c[2]);
205 LIBTEST_API struct sc5 STDCALL
206 mono_return_sc5 (struct sc5 a) {
207 // printf ("Got values %d %d %d %d %d\n", a.c[0], a.c[1], a.c[2], a.c[3], a.c[4]);
222 LIBTEST_API int STDCALL
223 mono_return_int_su (union su a) {
224 // printf ("Got value %d\n", a.i1);
228 LIBTEST_API int STDCALL
229 mono_test_many_int_arguments (int a, int b, int c, int d, int e,
230 int f, int g, int h, int i, int j);
231 LIBTEST_API short STDCALL
232 mono_test_many_short_arguments (short a, short b, short c, short d, short e,
233 short f, short g, short h, short i, short j);
234 LIBTEST_API char STDCALL
235 mono_test_many_char_arguments (char a, char b, char c, char d, char e,
236 char f, char g, char h, char i, char j);
238 LIBTEST_API int STDCALL
239 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)
241 return a + b + c + d + e + f + g + h + i + j;
244 LIBTEST_API short STDCALL
245 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)
247 return a + b + c + d + e + f + g + h + i + j;
250 LIBTEST_API char STDCALL
251 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)
253 return a + b + c + d + e + f + g + h + i + j;
256 LIBTEST_API float STDCALL
257 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)
259 return a + b + c + d + e + f + g + h + i + j;
262 LIBTEST_API double STDCALL
263 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)
265 return a + b + c + d + e + f + g + h + i + j;
268 LIBTEST_API double STDCALL
269 mono_test_split_double_arguments (double a, double b, float c, double d, double e)
271 return a + b + c + d + e;
274 LIBTEST_API int STDCALL
275 mono_test_puts_static (char *s)
277 // printf ("TEST %s\n", s);
281 typedef int (STDCALL *SimpleDelegate3) (int a, int b);
283 LIBTEST_API int STDCALL
284 mono_invoke_delegate (SimpleDelegate3 delegate)
288 // printf ("start invoke %p\n", delegate);
290 res = delegate (2, 3);
292 // printf ("end invoke\n");
297 LIBTEST_API int STDCALL
298 mono_invoke_simple_delegate (SimpleDelegate d)
303 LIBTEST_API int STDCALL
304 mono_test_marshal_char (short a1)
312 LIBTEST_API void STDCALL
313 mono_test_marshal_char_array (gunichar2 *s)
315 const char m[] = "abcdef";
319 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
327 LIBTEST_API int STDCALL
328 mono_test_empty_pinvoke (int i)
333 LIBTEST_API int STDCALL
334 mono_test_marshal_bool_byref (int a, int *b, int c)
343 LIBTEST_API int STDCALL
344 mono_test_marshal_bool_in_as_I1_U1 (char bTrue, char bFalse)
353 LIBTEST_API int STDCALL
354 mono_test_marshal_bool_out_as_I1_U1 (char* bTrue, char* bFalse)
356 if (!bTrue || !bFalse)
365 LIBTEST_API int STDCALL
366 mono_test_marshal_bool_ref_as_I1_U1 (char* bTrue, char* bFalse)
368 if (!bTrue || !bFalse)
382 LIBTEST_API int STDCALL
383 mono_test_marshal_array (int *a1)
387 for (i = 0; i < 50; i++)
393 LIBTEST_API int STDCALL
394 mono_test_marshal_inout_array (int *a1)
398 for (i = 0; i < 50; i++) {
400 a1 [i] = 50 - a1 [i];
406 LIBTEST_API int STDCALL
407 mono_test_marshal_out_array (int *a1)
411 for (i = 0; i < 50; i++) {
418 LIBTEST_API int STDCALL
419 mono_test_marshal_inout_nonblittable_array (gunichar2 *a1)
423 for (i = 0; i < 10; i++) {
443 LIBTEST_API simplestruct STDCALL
444 mono_test_return_vtype (int i)
447 static gunichar2 test2 [] = { 'T', 'E', 'S', 'T', '2', 0 };
458 LIBTEST_API void STDCALL
459 mono_test_delegate_struct (void)
461 // printf ("TEST\n");
464 typedef char* (STDCALL *ReturnStringDelegate) (const char *s);
466 LIBTEST_API char * STDCALL
467 mono_test_return_string (ReturnStringDelegate func)
471 // printf ("mono_test_return_string\n");
476 // printf ("got string: %s\n", res);
477 return g_strdup ("12345");
480 typedef int (STDCALL *RefVTypeDelegate) (int a, simplestruct *ss, int b);
482 LIBTEST_API int STDCALL
483 mono_test_ref_vtype (int a, simplestruct *ss, int b, RefVTypeDelegate func)
485 if (a == 1 && b == 2 && ss->a == 0 && ss->b == 1 && ss->c == 0 &&
486 !strcmp (ss->d, "TEST1")) {
492 return func (a, ss, b);
498 typedef int (STDCALL *OutVTypeDelegate) (int a, simplestruct *ss, int b);
500 LIBTEST_API int STDCALL
501 mono_test_marshal_out_struct (int a, simplestruct *ss, int b, OutVTypeDelegate func)
503 /* Check that the input pointer is ignored */
504 ss->d = (gpointer)0x12345678;
508 if (ss->a && ss->b && ss->c && !strcmp (ss->d, "TEST3"))
516 SimpleDelegate func, func2, func3;
519 LIBTEST_API DelegateStruct STDCALL
520 mono_test_marshal_delegate_struct (DelegateStruct ds)
524 res.a = ds.func (ds.a) + ds.func2 (ds.a) + (ds.func3 == NULL ? 0 : 1);
526 res.func2 = ds.func2;
532 LIBTEST_API int STDCALL
533 mono_test_marshal_struct (simplestruct ss)
535 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
536 !strcmp (ss.d, "TEST"))
542 LIBTEST_API int STDCALL
543 mono_test_marshal_byref_struct (simplestruct *ss, int a, int b, int c, char *d)
545 gboolean res = (ss->a == a && ss->b == b && ss->c == c && strcmp (ss->d, d) == 0);
547 marshal_free ((char*)ss->d);
552 ss->d = g_strdup ("DEF");
568 LIBTEST_API int STDCALL
569 mono_test_marshal_struct2 (simplestruct2 ss)
571 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
572 !strcmp (ss.d, "TEST") &&
573 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
579 /* on HP some of the struct should be on the stack and not in registers */
580 LIBTEST_API int STDCALL
581 mono_test_marshal_struct2_2 (int i, int j, int k, simplestruct2 ss)
583 if (i != 10 || j != 11 || k != 12)
585 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
586 !strcmp (ss.d, "TEST") &&
587 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
593 LIBTEST_API int STDCALL
594 mono_test_marshal_lpstruct (simplestruct *ss)
596 if (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
597 !strcmp (ss->d, "TEST"))
603 LIBTEST_API int STDCALL
604 mono_test_marshal_lpstruct_blittable (point *p)
606 if (p->x == 1.0 && p->y == 2.0)
612 LIBTEST_API int STDCALL
613 mono_test_marshal_struct_array (simplestruct2 *ss)
615 if (! (ss[0].a == 0 && ss[0].b == 1 && ss[0].c == 0 &&
616 !strcmp (ss[0].d, "TEST") &&
617 ss[0].e == 99 && ss[0].f == 1.5 && ss[0].g == 42 && ss[0].h == (guint64)123))
620 if (! (ss[1].a == 0 && ss[1].b == 0 && ss[1].c == 0 &&
621 !strcmp (ss[1].d, "TEST2") &&
622 ss[1].e == 100 && ss[1].f == 2.5 && ss[1].g == 43 && ss[1].h == (guint64)124))
628 typedef struct long_align_struct {
634 LIBTEST_API int STDCALL
635 mono_test_marshal_long_align_struct_array (long_align_struct *ss)
637 return ss[0].a + ss[0].b + ss[0].c + ss[1].a + ss[1].b + ss[1].c;
640 LIBTEST_API simplestruct2 * STDCALL
641 mono_test_marshal_class (int i, int j, int k, simplestruct2 *ss, int l)
648 if (i != 10 || j != 11 || k != 12 || l != 14)
650 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
651 !strcmp (ss->d, "TEST") &&
652 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
655 res = g_new0 (simplestruct2, 1);
656 memcpy (res, ss, sizeof (simplestruct2));
657 res->d = g_strdup ("TEST");
661 LIBTEST_API int STDCALL
662 mono_test_marshal_byref_class (simplestruct2 **ssp)
664 simplestruct2 *ss = *ssp;
667 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
668 !strcmp (ss->d, "TEST") &&
669 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
672 res = g_new0 (simplestruct2, 1);
673 memcpy (res, ss, sizeof (simplestruct2));
674 res->d = g_strdup ("TEST-RES");
686 /* Yes, this is correct, we are only trying to determine the value of the stack here */
691 LIBTEST_API int STDCALL
692 reliable_delegate (int a)
698 * Checks whether get_sp() works as expected. It doesn't work with gcc-2.95.3 on linux.
701 is_get_sp_reliable (void)
705 reliable_delegate(1);
707 reliable_delegate(1);
712 LIBTEST_API int STDCALL
713 mono_test_marshal_delegate (SimpleDelegate delegate)
717 /* Check that the delegate wrapper is stdcall */
722 if (is_get_sp_reliable())
723 g_assert (sp1 == sp2);
728 static int STDCALL inc_cb (int i)
733 LIBTEST_API int STDCALL
734 mono_test_marshal_out_delegate (SimpleDelegate *delegate)
741 LIBTEST_API SimpleDelegate STDCALL
742 mono_test_marshal_return_delegate (SimpleDelegate delegate)
748 return_plus_one (int i)
753 LIBTEST_API SimpleDelegate STDCALL
754 mono_test_marshal_return_delegate_2 (void)
756 return return_plus_one;
759 typedef simplestruct (STDCALL *SimpleDelegate2) (simplestruct ss);
762 is_utf16_equals (gunichar2 *s1, const char *s2)
767 s = g_utf16_to_utf8 (s1, -1, NULL, NULL, NULL);
768 res = strcmp (s, s2);
774 LIBTEST_API int STDCALL
775 mono_test_marshal_delegate2 (SimpleDelegate2 delegate)
777 simplestruct ss, res;
783 ss.d2 = g_utf8_to_utf16 ("TEST2", -1, NULL, NULL, NULL);
786 if (! (res.a && !res.b && res.c && !strcmp (res.d, "TEST-RES") && is_utf16_equals (res.d2, "TEST2-RES")))
792 typedef simplestruct* (STDCALL *SimpleDelegate4) (simplestruct *ss);
794 LIBTEST_API int STDCALL
795 mono_test_marshal_delegate4 (SimpleDelegate4 delegate)
806 res = delegate (&ss);
810 /* Check return value */
811 if (! (!res->a && res->b && !res->c && !strcmp (res->d, "TEST")))
814 /* Check NULL argument and NULL result */
815 res = delegate (NULL);
822 typedef int (STDCALL *SimpleDelegate5) (simplestruct **ss);
824 LIBTEST_API int STDCALL
825 mono_test_marshal_delegate5 (SimpleDelegate5 delegate)
838 res = delegate (&ptr);
842 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
848 LIBTEST_API int STDCALL
849 mono_test_marshal_delegate6 (SimpleDelegate5 delegate)
853 res = delegate (NULL);
858 typedef int (STDCALL *SimpleDelegate7) (simplestruct **ss);
860 LIBTEST_API int STDCALL
861 mono_test_marshal_delegate7 (SimpleDelegate7 delegate)
866 /* Check that the input pointer is ignored */
867 ptr = (gpointer)0x12345678;
869 res = delegate (&ptr);
873 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
879 typedef int (STDCALL *InOutByvalClassDelegate) (simplestruct *ss);
881 LIBTEST_API int STDCALL
882 mono_test_marshal_inout_byval_class_delegate (InOutByvalClassDelegate delegate)
890 ss.d = g_strdup_printf ("%s", "FOO");
892 res = delegate (&ss);
896 if (!(ss.a && !ss.b && ss.c && !strcmp (ss.d, "RES")))
902 typedef int (STDCALL *SimpleDelegate8) (gunichar2 *s);
904 LIBTEST_API int STDCALL
905 mono_test_marshal_delegate8 (SimpleDelegate8 delegate, gunichar2 *s)
910 typedef int (STDCALL *return_int_fnt) (int i);
911 typedef int (STDCALL *SimpleDelegate9) (return_int_fnt d);
913 LIBTEST_API int STDCALL
914 mono_test_marshal_delegate9 (SimpleDelegate9 delegate, gpointer ftn)
916 return delegate (ftn);
925 LIBTEST_API int STDCALL
926 mono_test_marshal_delegate10 (SimpleDelegate9 delegate)
928 return delegate (return_self);
931 typedef int (STDCALL *PrimitiveByrefDelegate) (int *i);
933 LIBTEST_API int STDCALL
934 mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate delegate)
938 int res = delegate (&i);
948 typedef int (STDCALL *return_int_delegate) (int i);
950 typedef return_int_delegate (STDCALL *ReturnDelegateDelegate) (void);
952 LIBTEST_API int STDCALL
953 mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d)
958 LIBTEST_API int STDCALL
959 mono_test_marshal_stringbuilder (char *s, int n)
961 const char m[] = "This is my message. Isn't it nice?";
963 if (strcmp (s, "ABCD") != 0)
970 LIBTEST_API int STDCALL
971 mono_test_marshal_stringbuilder_default (char *s, int n)
973 const char m[] = "This is my message. Isn't it nice?";
980 LIBTEST_API int STDCALL
981 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
983 const char m[] = "This is my message. Isn't it nice?";
987 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
999 LIBTEST_API void STDCALL
1000 mono_test_marshal_stringbuilder_out (char **s)
1002 const char m[] = "This is my message. Isn't it nice?";
1005 str = g_malloc (strlen (m) + 1);
1006 memcpy (str, m, strlen (m) + 1);
1011 LIBTEST_API int STDCALL
1012 mono_test_marshal_stringbuilder_out_unicode (gunichar2 **s)
1014 const char m[] = "This is my message. Isn't it nice?";
1018 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1020 len = (len * 2) + 2;
1021 *s = g_malloc (len);
1022 memcpy (*s, s2, len);
1035 LIBTEST_API int STDCALL
1036 mono_test_marshal_empty_string_array (char **array)
1038 return (array == NULL) ? 0 : 1;
1041 LIBTEST_API int STDCALL
1042 mono_test_marshal_string_array (char **array)
1044 if (strcmp (array [0], "ABC"))
1046 if (strcmp (array [1], "DEF"))
1049 if (array [2] != NULL)
1055 LIBTEST_API int STDCALL
1056 mono_test_marshal_byref_string_array (char ***array)
1061 if (strcmp ((*array) [0], "Alpha"))
1063 if (strcmp ((*array) [1], "Beta"))
1065 if (strcmp ((*array) [2], "Gamma"))
1071 LIBTEST_API int STDCALL
1072 mono_test_marshal_stringbuilder_array (char **array)
1074 if (strcmp (array [0], "ABC"))
1076 if (strcmp (array [1], "DEF"))
1079 strcpy (array [0], "DEF");
1080 strcpy (array [1], "ABC");
1085 LIBTEST_API int STDCALL
1086 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
1088 GError *error = NULL;
1091 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
1092 if (strcmp (s, "ABC")) {
1099 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
1100 if (strcmp (s, "DEF")) {
1107 if (strcmp (array2 [0], "ABC"))
1110 if (strcmp (array2 [1], "DEF"))
1116 /* this does not work on Redhat gcc 2.96 */
1117 LIBTEST_API int STDCALL
1118 mono_test_empty_struct (int a, EmptyStruct es, int b)
1120 // printf ("mono_test_empty_struct %d %d\n", a, b);
1122 // Intel icc on ia64 passes 'es' in 2 registers
1123 #if defined(__ia64) && defined(__INTEL_COMPILER)
1126 if (a == 1 && b == 2)
1136 LIBTEST_API ByValStrStruct * STDCALL
1137 mono_test_byvalstr_gen (void)
1139 ByValStrStruct *ret;
1141 ret = malloc(sizeof(ByValStrStruct));
1142 memset(ret, 'a', sizeof(ByValStrStruct)-1);
1143 ret->a[sizeof(ByValStrStruct)-1] = 0;
1148 LIBTEST_API int STDCALL
1149 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
1153 ret = strcmp(data->a, correctString);
1154 // printf ("T1: %s\n", data->a);
1155 // printf ("T2: %s\n", correctString);
1157 marshal_free (data);
1164 } ByValStrStruct_Unicode;
1166 LIBTEST_API int STDCALL
1167 mono_test_byvalstr_check_unicode (ByValStrStruct_Unicode *ref, int test)
1169 if (ref->flag != 0x1234abcd){
1170 printf ("overwritten data");
1174 if (test == 1 || test == 3){
1175 if (ref->a [0] != '1' ||
1176 ref->a [1] != '2' ||
1182 if (ref->a [0] != '1' ||
1190 LIBTEST_API int STDCALL
1191 NameManglingAnsi (char *data)
1193 return data [0] + data [1] + data [2];
1196 LIBTEST_API int STDCALL
1197 NameManglingAnsiA (char *data)
1199 g_assert_not_reached ();
1202 LIBTEST_API int STDCALL
1203 NameManglingAnsiW (char *data)
1205 g_assert_not_reached ();
1208 LIBTEST_API int STDCALL
1209 NameManglingAnsi2A (char *data)
1211 return data [0] + data [1] + data [2];
1214 LIBTEST_API int STDCALL
1215 NameManglingAnsi2W (char *data)
1217 g_assert_not_reached ();
1220 LIBTEST_API int STDCALL
1221 NameManglingUnicode (char *data)
1223 g_assert_not_reached ();
1226 LIBTEST_API int STDCALL
1227 NameManglingUnicodeW (gunichar2 *data)
1229 return data [0] + data [1] + data [2];
1232 LIBTEST_API int STDCALL
1233 NameManglingUnicode2 (gunichar2 *data)
1235 return data [0] + data [1] + data [2];
1238 LIBTEST_API int STDCALL
1239 NameManglingAutoW (char *data)
1242 return (data [0] + data [1] + data [2]) == 131 ? 0 : 1;
1244 g_assert_not_reached ();
1248 LIBTEST_API int STDCALL
1249 NameManglingAuto (char *data)
1252 return (data [0] + data [1] + data [2]) == 198 ? 0 : 1;
1254 g_assert_not_reached ();
1258 typedef int (STDCALL *intcharFunc)(const char*);
1260 LIBTEST_API void STDCALL
1261 callFunction (intcharFunc f)
1271 LIBTEST_API int STDCALL
1272 class_marshal_test0 (SimpleObj *obj1)
1274 // printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
1276 if (strcmp(obj1->str, "T1"))
1284 LIBTEST_API int STDCALL
1285 class_marshal_test4 (SimpleObj *obj1)
1293 LIBTEST_API void STDCALL
1294 class_marshal_test1 (SimpleObj **obj1)
1296 SimpleObj *res = malloc (sizeof (SimpleObj));
1298 res->str = g_strdup ("ABC");
1304 LIBTEST_API int STDCALL
1305 class_marshal_test2 (SimpleObj **obj1)
1307 // printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
1309 if (strcmp((*obj1)->str, "ABC"))
1311 if ((*obj1)->i != 5)
1317 LIBTEST_API int STDCALL
1318 string_marshal_test0 (char *str)
1320 if (strcmp (str, "TEST0"))
1326 LIBTEST_API void STDCALL
1327 string_marshal_test1 (const char **str)
1329 *str = g_strdup ("TEST1");
1332 LIBTEST_API int STDCALL
1333 string_marshal_test2 (char **str)
1335 // printf ("string_marshal_test2 %s\n", *str);
1337 if (strcmp (*str, "TEST1"))
1343 LIBTEST_API int STDCALL
1344 string_marshal_test3 (char *str)
1357 LIBTEST_API BlittableClass* STDCALL
1358 TestBlittableClass (BlittableClass *vl)
1360 BlittableClass *res;
1362 // printf ("TestBlittableClass %d %d\n", vl->a, vl->b);
1368 res = g_new0 (BlittableClass, 1);
1369 memcpy (res, vl, sizeof (BlittableClass));
1371 res = g_new0 (BlittableClass, 1);
1379 typedef struct OSVERSIONINFO_STRUCT
1383 } OSVERSIONINFO_STRUCT;
1385 LIBTEST_API int STDCALL
1386 MyGetVersionEx (OSVERSIONINFO_STRUCT *osvi)
1389 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1394 return osvi->a + osvi->b;
1397 LIBTEST_API int STDCALL
1398 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO_STRUCT *osvi)
1401 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1406 return osvi->a + osvi->b;
1409 LIBTEST_API int STDCALL
1410 mono_test_marshal_point (point pt)
1412 // printf("point %g %g\n", pt.x, pt.y);
1413 if (pt.x == 1.25 && pt.y == 3.5)
1424 LIBTEST_API int STDCALL
1425 mono_test_marshal_mixed_point (mixed_point pt)
1427 // printf("mixed point %d %g\n", pt.x, pt.y);
1428 if (pt.x == 5 && pt.y == 6.75)
1434 LIBTEST_API int STDCALL
1435 mono_test_marshal_mixed_point_2 (mixed_point *pt)
1437 if (pt->x != 5 || pt->y != 6.75)
1446 LIBTEST_API int STDCALL
1447 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
1450 if (*b1 != 0 && *b1 != 1)
1452 if (*b2 != 0 && *b2 != -1) /* variant_bool */
1454 if (*b3 != 0 && *b3 != 1)
1456 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
1468 short b2; /* variant_bool */
1472 LIBTEST_API int STDCALL
1473 marshal_test_bool_struct(struct BoolStruct *s)
1476 if (s->b1 != 0 && s->b1 != 1)
1478 if (s->b2 != 0 && s->b2 != -1)
1480 if (s->b3 != 0 && s->b3 != 1)
1482 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1499 LIBTEST_API int STDCALL
1500 mono_test_marshal_long_struct (LongStruct *s)
1502 return s->i + s->l.l;
1505 LIBTEST_API void STDCALL
1506 mono_test_last_error (int err)
1515 LIBTEST_API int STDCALL
1516 mono_test_asany (void *ptr, int what)
1520 return (*(int*)ptr == 5) ? 0 : 1;
1522 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1524 simplestruct2 ss = *(simplestruct2*)ptr;
1526 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1527 !strcmp (ss.d, "TEST") &&
1528 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1534 GError *error = NULL;
1537 s = g_utf16_to_utf8 (ptr, -1, NULL, NULL, &error);
1538 if (!strcmp (s, "ABC")) {
1548 g_assert_not_reached ();
1562 LIBTEST_API int STDCALL
1563 mono_test_marshal_asany_in (void* ptr)
1565 AsAnyStruct* asAny = ptr;
1566 int res = asAny->i + asAny->j + asAny->k;
1571 LIBTEST_API int STDCALL
1572 mono_test_marshal_asany_inout (void* ptr)
1574 AsAnyStruct* asAny = ptr;
1575 int res = asAny->i + asAny->j + asAny->k;
1577 marshal_free (asAny->s);
1587 LIBTEST_API int STDCALL
1588 mono_test_marshal_asany_out (void* ptr)
1590 AsAnyStruct* asAny = ptr;
1591 int res = asAny->i + asAny->j + asAny->k;
1602 * AMD64 marshalling tests.
1605 typedef struct amd64_struct1 {
1612 LIBTEST_API amd64_struct1 STDCALL
1613 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
1623 LIBTEST_API amd64_struct1 STDCALL
1624 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)
1629 s.l += 1 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8;
1634 typedef struct amd64_struct2 {
1639 LIBTEST_API amd64_struct2 STDCALL
1640 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
1648 typedef struct amd64_struct3 {
1652 LIBTEST_API amd64_struct3 STDCALL
1653 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s)
1660 typedef struct amd64_struct4 {
1664 LIBTEST_API amd64_struct4 STDCALL
1665 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s)
1674 * IA64 marshalling tests.
1676 typedef struct test_struct5 {
1680 LIBTEST_API test_struct5 STDCALL
1681 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, test_struct5 s, int i, double d3, double d4)
1683 s.d1 += d1 + d2 + i;
1684 s.d2 += d3 + d4 + i;
1689 typedef struct test_struct6 {
1693 LIBTEST_API test_struct6 STDCALL
1694 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, test_struct6 s, int i, double d3, double d4)
1696 s.d1 += d1 + d2 + i;
1702 static guint32 custom_res [2];
1704 LIBTEST_API void* STDCALL
1705 mono_test_marshal_pass_return_custom (int i, guint32 *ptr, int j)
1707 /* ptr will be freed by CleanupNative, so make a copy */
1708 custom_res [0] = 0; /* not allocated by AllocHGlobal */
1709 custom_res [1] = ptr [1];
1714 LIBTEST_API int STDCALL
1715 mono_test_marshal_pass_out_custom (int i, guint32 **ptr, int j)
1718 custom_res [1] = i + j + 10;
1725 LIBTEST_API int STDCALL
1726 mono_test_marshal_pass_inout_custom (int i, guint32 *ptr, int j)
1729 ptr [1] = i + ptr [1] + j;
1734 LIBTEST_API int STDCALL
1735 mono_test_marshal_pass_out_byval_custom (int i, guint32 *ptr, int j)
1737 return ptr == NULL ? 0 : 1;
1740 LIBTEST_API int STDCALL
1741 mono_test_marshal_pass_byref_custom (int i, guint32 **ptr, int j)
1748 LIBTEST_API void* STDCALL
1749 mono_test_marshal_pass_return_custom2 (int i, guint32 *ptr, int j)
1751 g_assert_not_reached ();
1756 LIBTEST_API void* STDCALL
1757 mono_test_marshal_pass_return_custom_null (int i, guint32 *ptr, int j)
1759 g_assert (ptr == NULL);
1764 typedef void *(STDCALL *PassReturnPtrDelegate) (void *ptr);
1766 LIBTEST_API int STDCALL
1767 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del)
1781 /* FIXME: Freed with FreeHGlobal */
1789 LIBTEST_API int STDCALL
1790 mono_test_marshal_pass_return_custom_null_in_delegate (PassReturnPtrDelegate del)
1792 void *ptr = del (NULL);
1794 return (ptr == NULL) ? 15 : 0;
1797 typedef void (STDCALL *CustomOutParamDelegate) (void **pptr);
1799 LIBTEST_API int STDCALL
1800 mono_test_marshal_custom_out_param_delegate (CustomOutParamDelegate del)
1812 typedef int (STDCALL *ReturnEnumDelegate) (int e);
1814 LIBTEST_API int STDCALL
1815 mono_test_marshal_return_enum_delegate (ReturnEnumDelegate func)
1825 typedef BlittableStruct (STDCALL *SimpleDelegate10) (BlittableStruct ss);
1827 LIBTEST_API int STDCALL
1828 mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 delegate)
1830 BlittableStruct ss, res;
1837 res = delegate (ss);
1838 if (! ((res.a == -1) && (res.b == -2) && (res.c == -3) && (res.d == -55)))
1844 LIBTEST_API int STDCALL
1845 mono_test_stdcall_name_mangling (int a, int b, int c)
1851 * PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
1858 typedef SmallStruct1 (STDCALL *SmallStructDelegate1) (SmallStruct1 ss);
1860 LIBTEST_API int STDCALL
1861 mono_test_marshal_small_struct_delegate1 (SmallStructDelegate1 delegate)
1863 SmallStruct1 ss, res;
1867 res = delegate (ss);
1868 if (! (res.i == -1))
1878 typedef SmallStruct2 (STDCALL *SmallStructDelegate2) (SmallStruct2 ss);
1880 LIBTEST_API int STDCALL
1881 mono_test_marshal_small_struct_delegate2 (SmallStructDelegate2 delegate)
1883 SmallStruct2 ss, res;
1888 res = delegate (ss);
1889 if (! ((res.i == -2) && (res.j == -3)))
1900 typedef SmallStruct3 (STDCALL *SmallStructDelegate3) (SmallStruct3 ss);
1902 LIBTEST_API int STDCALL
1903 mono_test_marshal_small_struct_delegate3 (SmallStructDelegate3 delegate)
1905 SmallStruct3 ss, res;
1910 res = delegate (ss);
1911 if (! ((res.i == -1) && (res.j == -2)))
1921 typedef SmallStruct4 (STDCALL *SmallStructDelegate4) (SmallStruct4 ss);
1923 LIBTEST_API int STDCALL
1924 mono_test_marshal_small_struct_delegate4 (SmallStructDelegate4 delegate)
1926 SmallStruct4 ss, res;
1930 res = delegate (ss);
1931 if (! (res.i == -1))
1941 typedef SmallStruct5 (STDCALL *SmallStructDelegate5) (SmallStruct5 ss);
1943 LIBTEST_API int STDCALL
1944 mono_test_marshal_small_struct_delegate5 (SmallStructDelegate5 delegate)
1946 SmallStruct5 ss, res;
1950 res = delegate (ss);
1951 if (! (res.i == -5))
1961 typedef SmallStruct6 (STDCALL *SmallStructDelegate6) (SmallStruct6 ss);
1963 LIBTEST_API int STDCALL
1964 mono_test_marshal_small_struct_delegate6 (SmallStructDelegate6 delegate)
1966 SmallStruct6 ss, res;
1971 res = delegate (ss);
1972 if (! ((res.i == -1) && (res.j == -2)))
1983 typedef SmallStruct7 (STDCALL *SmallStructDelegate7) (SmallStruct7 ss);
1985 LIBTEST_API int STDCALL
1986 mono_test_marshal_small_struct_delegate7 (SmallStructDelegate7 delegate)
1988 SmallStruct7 ss, res;
1993 res = delegate (ss);
1994 if (! ((res.i == -1) && (res.j == -2)))
2004 typedef SmallStruct8 (STDCALL *SmallStructDelegate8) (SmallStruct8 ss);
2006 LIBTEST_API int STDCALL
2007 mono_test_marshal_small_struct_delegate8 (SmallStructDelegate8 delegate)
2009 SmallStruct8 ss, res;
2013 res = delegate (ss);
2014 if (! ((res.i == -1.0)))
2024 typedef SmallStruct9 (STDCALL *SmallStructDelegate9) (SmallStruct9 ss);
2026 LIBTEST_API int STDCALL
2027 mono_test_marshal_small_struct_delegate9 (SmallStructDelegate9 delegate)
2029 SmallStruct9 ss, res;
2033 res = delegate (ss);
2034 if (! ((res.i == -1.0)))
2044 typedef SmallStruct10 (STDCALL *SmallStructDelegate10) (SmallStruct10 ss);
2046 LIBTEST_API int STDCALL
2047 mono_test_marshal_small_struct_delegate10 (SmallStructDelegate10 delegate)
2049 SmallStruct10 ss, res;
2054 res = delegate (ss);
2055 if (! ((res.i == -1.0) && (res.j == -2.0)))
2066 typedef SmallStruct11 (STDCALL *SmallStructDelegate11) (SmallStruct11 ss);
2068 LIBTEST_API int STDCALL
2069 mono_test_marshal_small_struct_delegate11 (SmallStructDelegate11 delegate)
2071 SmallStruct11 ss, res;
2076 res = delegate (ss);
2077 if (! ((res.i == -1.0) && (res.j == -2)))
2083 typedef int (STDCALL *ArrayDelegate) (int i, char *j, void *arr);
2085 LIBTEST_API int STDCALL
2086 mono_test_marshal_array_delegate (void *arr, int len, ArrayDelegate del)
2088 return del (len, NULL, arr);
2091 typedef int (STDCALL *ArrayDelegateLong) (gint64 i, char *j, void *arr);
2093 LIBTEST_API int STDCALL
2094 mono_test_marshal_array_delegate_long (void *arr, gint64 len, ArrayDelegateLong del)
2096 return del (len, NULL, arr);
2099 LIBTEST_API int STDCALL
2100 mono_test_marshal_out_array_delegate (int *arr, int len, ArrayDelegate del)
2102 del (len, NULL, arr);
2104 if ((arr [0] != 1) || (arr [1] != 2))
2110 typedef gunichar2* (STDCALL *UnicodeStringDelegate) (gunichar2 *message);
2112 LIBTEST_API int STDCALL
2113 mono_test_marshal_return_unicode_string_delegate (UnicodeStringDelegate del)
2115 const char m[] = "abcdef";
2116 gunichar2 *s2, *res;
2119 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
2128 LIBTEST_API int STDCALL
2129 mono_test_marshal_out_string_array_delegate (char **arr, int len, ArrayDelegate del)
2131 del (len, NULL, arr);
2133 if (!strcmp (arr [0], "ABC") && !strcmp (arr [1], "DEF"))
2139 typedef int (*CdeclDelegate) (int i, int j);
2141 LIBTEST_API int STDCALL
2142 mono_test_marshal_cdecl_delegate (CdeclDelegate del)
2146 for (i = 0; i < 1000; ++i)
2152 typedef char** (STDCALL *ReturnStringArrayDelegate) (int i);
2154 LIBTEST_API int STDCALL
2155 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d)
2163 if (strcmp (arr [0], "ABC") || strcmp (arr [1], "DEF"))
2173 typedef int (STDCALL *ByrefStringDelegate) (char **s);
2175 LIBTEST_API int STDCALL
2176 mono_test_marshal_byref_string_delegate (ByrefStringDelegate d)
2178 char *s = (char*)"ABC";
2185 if (!strcmp (s, "DEF"))
2195 LIBTEST_API int STDCALL
2196 add_delegate (int i, int j)
2201 LIBTEST_API gpointer STDCALL
2202 mono_test_marshal_return_fnptr (void)
2204 return &add_delegate;
2207 LIBTEST_API int STDCALL
2210 printf ("codigo %x\n", code);
2218 LIBTEST_API HandleRef STDCALL
2219 mono_xr_as_handle (int code)
2223 memset (&ref, 0, sizeof (ref));
2235 LIBTEST_API int STDCALL
2236 mono_safe_handle_struct_ref (HandleStructs *x)
2238 printf ("Dingus Ref! \n");
2239 printf ("Values: %d %d %p %p\n", x->a, x->b, x->handle1, x->handle2);
2245 if (x->handle1 != (void*) 0x7080feed)
2248 if (x->handle2 != (void*) 0x1234abcd)
2254 LIBTEST_API int STDCALL
2255 mono_safe_handle_struct (HandleStructs x)
2257 printf ("Dingus Standard! \n");
2258 printf ("Values: %d %d %p %p\n", x.a, x.b, x.handle1, x.handle2);
2264 if (x.handle1 != (void*) 0x7080feed)
2267 if (x.handle2 != (void*) 0x1234abcd)
2277 LIBTEST_API int STDCALL
2278 mono_safe_handle_struct_simple (TrivialHandle x)
2280 printf ("The value is %p\n", x.a);
2281 return ((int)(gsize)x.a) * 2;
2284 LIBTEST_API int STDCALL
2285 mono_safe_handle_return (void)
2290 LIBTEST_API void STDCALL
2291 mono_safe_handle_ref (void **handle)
2294 *handle = (void *) 0xbad;
2298 *handle = (void *) 0x800d;
2301 LIBTEST_API double STDCALL
2302 mono_test_marshal_date_time (double d, double *d2)
2373 VT_USERDEFINED = 29,
2381 VT_STREAMED_OBJECT = 68,
2382 VT_STORED_OBJECT = 69,
2383 VT_BLOB_OBJECT = 70,
2391 void VariantInit(VARIANT* vt)
2408 LIBTEST_API int STDCALL
2409 mono_test_marshal_bstr_in(gunichar2* bstr)
2412 gchar* bstr_utf8 = g_utf16_to_utf8 (bstr, -1, NULL, NULL, NULL);
2413 result = strcmp("mono_test_marshal_bstr_in", bstr_utf8);
2420 LIBTEST_API int STDCALL
2421 mono_test_marshal_bstr_out(gunichar2** bstr)
2423 *bstr = marshal_bstr_alloc ("mono_test_marshal_bstr_out");
2427 LIBTEST_API int STDCALL
2428 mono_test_marshal_bstr_in_null(gunichar2* bstr)
2435 LIBTEST_API int STDCALL
2436 mono_test_marshal_bstr_out_null(gunichar2** bstr)
2442 LIBTEST_API int STDCALL
2443 mono_test_marshal_variant_in_sbyte(VARIANT variant)
2445 if (variant.vt == VT_I1 && variant.cVal == 100)
2450 LIBTEST_API int STDCALL
2451 mono_test_marshal_variant_in_byte(VARIANT variant)
2453 if (variant.vt == VT_UI1 && variant.bVal == 100)
2458 LIBTEST_API int STDCALL
2459 mono_test_marshal_variant_in_short(VARIANT variant)
2461 if (variant.vt == VT_I2 && variant.iVal == 314)
2466 LIBTEST_API int STDCALL
2467 mono_test_marshal_variant_in_ushort(VARIANT variant)
2469 if (variant.vt == VT_UI2 && variant.uiVal == 314)
2474 LIBTEST_API int STDCALL
2475 mono_test_marshal_variant_in_int(VARIANT variant)
2477 if (variant.vt == VT_I4 && variant.lVal == 314)
2482 LIBTEST_API int STDCALL
2483 mono_test_marshal_variant_in_uint(VARIANT variant)
2485 if (variant.vt == VT_UI4 && variant.ulVal == 314)
2490 LIBTEST_API int STDCALL
2491 mono_test_marshal_variant_in_long(VARIANT variant)
2493 if (variant.vt == VT_I8 && variant.llVal == 314)
2498 LIBTEST_API int STDCALL
2499 mono_test_marshal_variant_in_ulong(VARIANT variant)
2501 if (variant.vt == VT_UI8 && variant.ullVal == 314)
2506 LIBTEST_API int STDCALL
2507 mono_test_marshal_variant_in_float(VARIANT variant)
2509 if (variant.vt == VT_R4 && (variant.fltVal - 3.14)/3.14 < .001)
2514 LIBTEST_API int STDCALL
2515 mono_test_marshal_variant_in_double(VARIANT variant)
2517 if (variant.vt == VT_R8 && (variant.dblVal - 3.14)/3.14 < .001)
2522 LIBTEST_API int STDCALL
2523 mono_test_marshal_variant_in_bstr(VARIANT variant)
2526 gchar* bstr_utf8 = g_utf16_to_utf8 (variant.bstrVal, -1, NULL, NULL, NULL);
2527 result = strcmp("PI", bstr_utf8);
2530 if (variant.vt == VT_BSTR && !result)
2535 LIBTEST_API int STDCALL
2536 mono_test_marshal_variant_in_bool_true (VARIANT variant)
2538 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_TRUE)
2543 LIBTEST_API int STDCALL
2544 mono_test_marshal_variant_in_bool_false (VARIANT variant)
2546 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_FALSE)
2551 LIBTEST_API int STDCALL
2552 mono_test_marshal_variant_out_sbyte(VARIANT* variant)
2554 variant->vt = VT_I1;
2555 variant->cVal = 100;
2560 LIBTEST_API int STDCALL
2561 mono_test_marshal_variant_out_byte(VARIANT* variant)
2563 variant->vt = VT_UI1;
2564 variant->bVal = 100;
2569 LIBTEST_API int STDCALL
2570 mono_test_marshal_variant_out_short(VARIANT* variant)
2572 variant->vt = VT_I2;
2573 variant->iVal = 314;
2578 LIBTEST_API int STDCALL
2579 mono_test_marshal_variant_out_ushort(VARIANT* variant)
2581 variant->vt = VT_UI2;
2582 variant->uiVal = 314;
2587 LIBTEST_API int STDCALL
2588 mono_test_marshal_variant_out_int(VARIANT* variant)
2590 variant->vt = VT_I4;
2591 variant->lVal = 314;
2596 LIBTEST_API int STDCALL
2597 mono_test_marshal_variant_out_uint(VARIANT* variant)
2599 variant->vt = VT_UI4;
2600 variant->ulVal = 314;
2605 LIBTEST_API int STDCALL
2606 mono_test_marshal_variant_out_long(VARIANT* variant)
2608 variant->vt = VT_I8;
2609 variant->llVal = 314;
2614 LIBTEST_API int STDCALL
2615 mono_test_marshal_variant_out_ulong(VARIANT* variant)
2617 variant->vt = VT_UI8;
2618 variant->ullVal = 314;
2623 LIBTEST_API int STDCALL
2624 mono_test_marshal_variant_out_float(VARIANT* variant)
2626 variant->vt = VT_R4;
2627 variant->fltVal = 3.14;
2632 LIBTEST_API int STDCALL
2633 mono_test_marshal_variant_out_double(VARIANT* variant)
2635 variant->vt = VT_R8;
2636 variant->dblVal = 3.14;
2641 LIBTEST_API int STDCALL
2642 mono_test_marshal_variant_out_bstr(VARIANT* variant)
2644 variant->vt = VT_BSTR;
2645 variant->bstrVal = marshal_bstr_alloc("PI");
2650 LIBTEST_API int STDCALL
2651 mono_test_marshal_variant_out_bool_true (VARIANT* variant)
2653 variant->vt = VT_BOOL;
2654 variant->boolVal = VARIANT_TRUE;
2659 LIBTEST_API int STDCALL
2660 mono_test_marshal_variant_out_bool_false (VARIANT* variant)
2662 variant->vt = VT_BOOL;
2663 variant->boolVal = VARIANT_FALSE;
2668 typedef int (STDCALL *VarFunc) (int vt, VARIANT variant);
2669 typedef int (STDCALL *VarRefFunc) (int vt, VARIANT* variant);
2671 LIBTEST_API int STDCALL
2672 mono_test_marshal_variant_in_sbyte_unmanaged(VarFunc func)
2677 return func (VT_I1, vt);
2680 LIBTEST_API int STDCALL
2681 mono_test_marshal_variant_in_byte_unmanaged(VarFunc func)
2686 return func (VT_UI1, vt);
2689 LIBTEST_API int STDCALL
2690 mono_test_marshal_variant_in_short_unmanaged(VarFunc func)
2695 return func (VT_I2, vt);
2698 LIBTEST_API int STDCALL
2699 mono_test_marshal_variant_in_ushort_unmanaged(VarFunc func)
2704 return func (VT_UI2, vt);
2707 LIBTEST_API int STDCALL
2708 mono_test_marshal_variant_in_int_unmanaged(VarFunc func)
2713 return func (VT_I4, vt);
2716 LIBTEST_API int STDCALL
2717 mono_test_marshal_variant_in_uint_unmanaged(VarFunc func)
2722 return func (VT_UI4, vt);
2725 LIBTEST_API int STDCALL
2726 mono_test_marshal_variant_in_long_unmanaged(VarFunc func)
2731 return func (VT_I8, vt);
2734 LIBTEST_API int STDCALL
2735 mono_test_marshal_variant_in_ulong_unmanaged(VarFunc func)
2740 return func (VT_UI8, vt);
2743 LIBTEST_API int STDCALL
2744 mono_test_marshal_variant_in_float_unmanaged(VarFunc func)
2749 return func (VT_R4, vt);
2752 LIBTEST_API int STDCALL
2753 mono_test_marshal_variant_in_double_unmanaged(VarFunc func)
2758 return func (VT_R8, vt);
2761 LIBTEST_API int STDCALL
2762 mono_test_marshal_variant_in_bstr_unmanaged(VarFunc func)
2766 vt.bstrVal = marshal_bstr_alloc("PI");
2767 return func (VT_BSTR, vt);
2770 LIBTEST_API int STDCALL
2771 mono_test_marshal_variant_in_bool_true_unmanaged(VarFunc func)
2775 vt.boolVal = VARIANT_TRUE;
2776 return func (VT_BOOL, vt);
2779 LIBTEST_API int STDCALL
2780 mono_test_marshal_variant_in_bool_false_unmanaged(VarFunc func)
2784 vt.boolVal = VARIANT_FALSE;
2785 return func (VT_BOOL, vt);
2788 LIBTEST_API int STDCALL
2789 mono_test_marshal_variant_out_sbyte_unmanaged(VarRefFunc func)
2794 if (vt.vt == VT_I1 && vt.cVal == -100)
2799 LIBTEST_API int STDCALL
2800 mono_test_marshal_variant_out_byte_unmanaged(VarRefFunc func)
2805 if (vt.vt == VT_UI1 && vt.bVal == 100)
2810 LIBTEST_API int STDCALL
2811 mono_test_marshal_variant_out_short_unmanaged(VarRefFunc func)
2816 if (vt.vt == VT_I2 && vt.iVal == -100)
2821 LIBTEST_API int STDCALL
2822 mono_test_marshal_variant_out_ushort_unmanaged(VarRefFunc func)
2827 if (vt.vt == VT_UI2 && vt.uiVal == 100)
2832 LIBTEST_API int STDCALL
2833 mono_test_marshal_variant_out_int_unmanaged(VarRefFunc func)
2838 if (vt.vt == VT_I4 && vt.lVal == -100)
2843 LIBTEST_API int STDCALL
2844 mono_test_marshal_variant_out_uint_unmanaged(VarRefFunc func)
2849 if (vt.vt == VT_UI4 && vt.ulVal == 100)
2854 LIBTEST_API int STDCALL
2855 mono_test_marshal_variant_out_long_unmanaged(VarRefFunc func)
2860 if (vt.vt == VT_I8 && vt.llVal == -100)
2865 LIBTEST_API int STDCALL
2866 mono_test_marshal_variant_out_ulong_unmanaged(VarRefFunc func)
2871 if (vt.vt == VT_UI8 && vt.ullVal == 100)
2876 LIBTEST_API int STDCALL
2877 mono_test_marshal_variant_out_float_unmanaged(VarRefFunc func)
2882 if (vt.vt == VT_R4 && fabs (vt.fltVal - 3.14f) < 1e-10)
2887 LIBTEST_API int STDCALL
2888 mono_test_marshal_variant_out_double_unmanaged(VarRefFunc func)
2893 if (vt.vt == VT_R8 && fabs (vt.dblVal - 3.14) < 1e-10)
2898 LIBTEST_API int STDCALL
2899 mono_test_marshal_variant_out_bstr_unmanaged(VarRefFunc func)
2907 func (VT_BSTR, &vt);
2908 bstr_utf8 = g_utf16_to_utf8 (vt.bstrVal, -1, NULL, NULL, NULL);
2909 result = strcmp("PI", bstr_utf8);
2911 if (vt.vt == VT_BSTR && !result)
2916 LIBTEST_API int STDCALL
2917 mono_test_marshal_variant_out_bool_true_unmanaged(VarRefFunc func)
2921 func (VT_BOOL, &vt);
2922 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
2927 LIBTEST_API int STDCALL
2928 mono_test_marshal_variant_out_bool_false_unmanaged(VarRefFunc func)
2932 func (VT_BOOL, &vt);
2933 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
2938 typedef struct MonoComObject MonoComObject;
2942 int (STDCALL *QueryInterface)(MonoComObject* pUnk, gpointer riid, gpointer* ppv);
2943 int (STDCALL *AddRef)(MonoComObject* pUnk);
2944 int (STDCALL *Release)(MonoComObject* pUnk);
2945 int (STDCALL *get_ITest)(MonoComObject* pUnk, MonoComObject* *ppUnk);
2946 int (STDCALL *SByteIn)(MonoComObject* pUnk, char a);
2947 int (STDCALL *ByteIn)(MonoComObject* pUnk, unsigned char a);
2948 int (STDCALL *ShortIn)(MonoComObject* pUnk, short a);
2949 int (STDCALL *UShortIn)(MonoComObject* pUnk, unsigned short a);
2950 int (STDCALL *IntIn)(MonoComObject* pUnk, int a);
2951 int (STDCALL *UIntIn)(MonoComObject* pUnk, unsigned int a);
2952 int (STDCALL *LongIn)(MonoComObject* pUnk, gint64 a);
2953 int (STDCALL *ULongIn)(MonoComObject* pUnk, guint64 a);
2954 int (STDCALL *FloatIn)(MonoComObject* pUnk, float a);
2955 int (STDCALL *DoubleIn)(MonoComObject* pUnk, double a);
2956 int (STDCALL *ITestIn)(MonoComObject* pUnk, MonoComObject* pUnk2);
2957 int (STDCALL *ITestOut)(MonoComObject* pUnk, MonoComObject* *ppUnk);
2960 struct MonoComObject
2966 static GUID IID_ITest = {0, 0, 0, {0,0,0,0,0,0,0,1}};
2967 static GUID IID_IMonoUnknown = {0, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
2968 static GUID IID_IMonoDispatch = {0x00020400, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
2970 LIBTEST_API int STDCALL
2971 MonoQueryInterface(MonoComObject* pUnk, gpointer riid, gpointer* ppv)
2975 if (!memcmp(riid, &IID_IMonoUnknown, sizeof(GUID))) {
2979 else if (!memcmp(riid, &IID_ITest, sizeof(GUID))) {
2983 else if (!memcmp(riid, &IID_IMonoDispatch, sizeof(GUID))) {
2987 return 0x80004002; //E_NOINTERFACE;
2990 LIBTEST_API int STDCALL
2991 MonoAddRef(MonoComObject* pUnk)
2993 return ++(pUnk->m_ref);
2996 LIBTEST_API int STDCALL
2997 MonoRelease(MonoComObject* pUnk)
2999 return --(pUnk->m_ref);
3002 LIBTEST_API int STDCALL
3003 SByteIn(MonoComObject* pUnk, char a)
3008 LIBTEST_API int STDCALL
3009 ByteIn(MonoComObject* pUnk, unsigned char a)
3014 LIBTEST_API int STDCALL
3015 ShortIn(MonoComObject* pUnk, short a)
3020 LIBTEST_API int STDCALL
3021 UShortIn(MonoComObject* pUnk, unsigned short a)
3026 LIBTEST_API int STDCALL
3027 IntIn(MonoComObject* pUnk, int a)
3032 LIBTEST_API int STDCALL
3033 UIntIn(MonoComObject* pUnk, unsigned int a)
3038 LIBTEST_API int STDCALL
3039 LongIn(MonoComObject* pUnk, gint64 a)
3044 LIBTEST_API int STDCALL
3045 ULongIn(MonoComObject* pUnk, guint64 a)
3050 LIBTEST_API int STDCALL
3051 FloatIn(MonoComObject* pUnk, float a)
3056 LIBTEST_API int STDCALL
3057 DoubleIn(MonoComObject* pUnk, double a)
3062 LIBTEST_API int STDCALL
3063 ITestIn(MonoComObject* pUnk, MonoComObject *pUnk2)
3068 LIBTEST_API int STDCALL
3069 ITestOut(MonoComObject* pUnk, MonoComObject* *ppUnk)
3074 LIBTEST_API int STDCALL
3075 get_ITest(MonoComObject* pUnk, MonoComObject* *ppUnk)
3080 static void create_com_object (MonoComObject** pOut)
3082 *pOut = g_new0 (MonoComObject, 1);
3083 (*pOut)->vtbl = g_new0 (MonoIUnknown, 1);
3086 (*pOut)->vtbl->QueryInterface = MonoQueryInterface;
3087 (*pOut)->vtbl->AddRef = MonoAddRef;
3088 (*pOut)->vtbl->Release = MonoRelease;
3089 (*pOut)->vtbl->SByteIn = SByteIn;
3090 (*pOut)->vtbl->ByteIn = ByteIn;
3091 (*pOut)->vtbl->ShortIn = ShortIn;
3092 (*pOut)->vtbl->UShortIn = UShortIn;
3093 (*pOut)->vtbl->IntIn = IntIn;
3094 (*pOut)->vtbl->UIntIn = UIntIn;
3095 (*pOut)->vtbl->LongIn = LongIn;
3096 (*pOut)->vtbl->ULongIn = ULongIn;
3097 (*pOut)->vtbl->FloatIn = FloatIn;
3098 (*pOut)->vtbl->DoubleIn = DoubleIn;
3099 (*pOut)->vtbl->ITestIn = ITestIn;
3100 (*pOut)->vtbl->ITestOut = ITestOut;
3101 (*pOut)->vtbl->get_ITest = get_ITest;
3104 static MonoComObject* same_object = NULL;
3106 LIBTEST_API int STDCALL
3107 mono_test_marshal_com_object_create(MonoComObject* *pUnk)
3109 create_com_object (pUnk);
3112 same_object = *pUnk;
3117 LIBTEST_API int STDCALL
3118 mono_test_marshal_com_object_same(MonoComObject* *pUnk)
3120 *pUnk = same_object;
3125 LIBTEST_API int STDCALL
3126 mono_test_marshal_com_object_destroy(MonoComObject *pUnk)
3128 int ref = --(pUnk->m_ref);
3135 LIBTEST_API int STDCALL
3136 mono_test_marshal_com_object_ref_count(MonoComObject *pUnk)
3141 LIBTEST_API int STDCALL
3142 mono_test_marshal_ccw_itest (MonoComObject *pUnk)
3145 MonoComObject* pTest;
3150 hr = pUnk->vtbl->SByteIn (pUnk, -100);
3153 hr = pUnk->vtbl->ByteIn (pUnk, 100);
3156 hr = pUnk->vtbl->ShortIn (pUnk, -100);
3159 hr = pUnk->vtbl->UShortIn (pUnk, 100);
3162 hr = pUnk->vtbl->IntIn (pUnk, -100);
3165 hr = pUnk->vtbl->UIntIn (pUnk, 100);
3168 hr = pUnk->vtbl->LongIn (pUnk, -100);
3171 hr = pUnk->vtbl->ULongIn (pUnk, 100);
3174 hr = pUnk->vtbl->FloatIn (pUnk, 3.14f);
3177 hr = pUnk->vtbl->DoubleIn (pUnk, 3.14);
3180 hr = pUnk->vtbl->ITestIn (pUnk, pUnk);
3183 hr = pUnk->vtbl->ITestOut (pUnk, &pTest);
3191 * mono_method_get_unmanaged_thunk tests
3194 #if defined(__GNUC__) && ((defined(__i386__) && (defined(__linux__) || defined (__APPLE__)) || defined (__FreeBSD__) || defined(__OpenBSD__)) || (defined(__ppc__) && defined(__APPLE__)))
3195 #define ALIGN(size) __attribute__ ((aligned(size)))
3201 /* thunks.cs:TestStruct */
3202 typedef struct _TestStruct {
3204 double B ALIGN(8); /* align according to mono's struct layout */
3207 /* Searches for mono symbols in all loaded modules */
3209 lookup_mono_symbol (const char *symbol_name)
3212 if (g_module_symbol (g_module_open (NULL, G_MODULE_BIND_LAZY), symbol_name, &symbol))
3219 mono_test_marshal_lookup_symbol (const char *symbol_name)
3221 return lookup_mono_symbol (symbol_name);
3225 * test_method_thunk:
3227 * @test_id: the test number
3228 * @test_method_handle: MonoMethod* of the C# test method
3229 * @create_object_method_handle: MonoMethod* of thunks.cs:Test.CreateObject
3231 LIBTEST_API int STDCALL
3232 test_method_thunk (int test_id, gpointer test_method_handle, gpointer create_object_method_handle)
3234 gpointer (*mono_method_get_unmanaged_thunk)(gpointer)
3235 = lookup_mono_symbol ("mono_method_get_unmanaged_thunk");
3237 gpointer (*mono_string_new_wrapper)(const char *)
3238 = lookup_mono_symbol ("mono_string_new_wrapper");
3240 char* (*mono_string_to_utf8)(gpointer)
3241 = lookup_mono_symbol ("mono_string_to_utf8");
3243 gpointer (*mono_object_unbox)(gpointer)
3244 = lookup_mono_symbol ("mono_object_unbox");
3246 gpointer test_method, ex = NULL;
3247 gpointer (STDCALL *CreateObject)(gpointer*);
3250 if (!mono_method_get_unmanaged_thunk)
3253 test_method = mono_method_get_unmanaged_thunk (test_method_handle);
3257 CreateObject = mono_method_get_unmanaged_thunk (create_object_method_handle);
3265 /* thunks.cs:Test.Test0 */
3266 void (STDCALL *F)(gpointer*) = test_method;
3272 /* thunks.cs:Test.Test1 */
3273 int (STDCALL *F)(gpointer*) = test_method;
3280 /* thunks.cs:Test.Test2 */
3281 gpointer (STDCALL *F)(gpointer, gpointer*) = test_method;
3282 gpointer str = mono_string_new_wrapper ("foo");
3283 if (str != F (str, &ex))
3289 /* thunks.cs:Test.Test3 */
3290 gpointer (STDCALL *F)(gpointer, gpointer, gpointer*);
3295 obj = CreateObject (&ex);
3296 str = mono_string_new_wrapper ("bar");
3298 if (str != F (obj, str, &ex))
3304 /* thunks.cs:Test.Test4 */
3305 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3310 obj = CreateObject (&ex);
3311 str = mono_string_new_wrapper ("bar");
3313 if (42 != F (obj, str, 42, &ex))
3320 /* thunks.cs:Test.Test5 */
3321 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3326 obj = CreateObject (&ex);
3327 str = mono_string_new_wrapper ("bar");
3329 F (obj, str, 42, &ex);
3337 /* thunks.cs:Test.Test6 */
3338 int (STDCALL *F)(gpointer, guint8, gint16, gint32, gint64, float, double,
3339 gpointer, gpointer*);
3341 gpointer str = mono_string_new_wrapper ("Test6");
3345 obj = CreateObject (&ex);
3347 res = F (obj, 254, 32700, -245378, 6789600, 3.1415, 3.1415, str, &ex);
3358 /* thunks.cs:Test.Test7 */
3359 gint64 (STDCALL *F)(gpointer*) = test_method;
3360 if (F (&ex) != G_MAXINT64)
3366 /* thunks.cs:Test.Test8 */
3367 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3368 gpointer*, gpointer*);
3380 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3388 (fabs (a5 - 3.1415) < 0.001) &&
3389 (fabs (a6 - 3.1415) < 0.001) &&
3390 strcmp (mono_string_to_utf8 (a7), "Test8") == 0))
3397 /* thunks.cs:Test.Test9 */
3398 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3399 gpointer*, gpointer*);
3411 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3419 /* thunks.cs:Test.Test10 */
3420 void (STDCALL *F)(gpointer*, gpointer*);
3422 gpointer obj1, obj2;
3424 obj1 = obj2 = CreateObject (&ex);
3441 /* thunks.cs:TestStruct.Test0 */
3442 int (STDCALL *F)(gpointer*, gpointer*);
3448 obj = CreateObject (&ex);
3455 a1 = mono_object_unbox (obj);
3471 /* check whether the call was really by value */
3472 if (a1->A != 42 || a1->B != 3.1415)
3479 /* thunks.cs:TestStruct.Test1 */
3480 void (STDCALL *F)(gpointer, gpointer*);
3485 obj = CreateObject (&ex);
3492 a1 = mono_object_unbox (obj);
3505 if (!fabs (a1->B - 3.1415) < 0.001)
3512 /* thunks.cs:TestStruct.Test2 */
3513 gpointer (STDCALL *F)(gpointer*);
3527 a1 = mono_object_unbox (obj);
3532 if (!fabs (a1->B - 3.1415) < 0.001)
3539 /* thunks.cs:TestStruct.Test3 */
3540 void (STDCALL *F)(gpointer, gpointer*);
3545 obj = CreateObject (&ex);
3552 a1 = mono_object_unbox (obj);
3588 LIBTEST_API int STDCALL
3589 mono_test_Winx64_struct1_in (winx64_struct1 var)
3602 LIBTEST_API int STDCALL
3603 mono_test_Winx64_struct2_in (winx64_struct2 var)
3620 LIBTEST_API int STDCALL
3621 mono_test_Winx64_struct3_in (winx64_struct3 var)
3627 if (var.c != 0x1234)
3640 LIBTEST_API int STDCALL
3641 mono_test_Winx64_struct4_in (winx64_struct4 var)
3647 if (var.c != 0x1234)
3649 if (var.d != 0x87654321)
3661 LIBTEST_API int STDCALL
3662 mono_test_Winx64_struct5_in (winx64_struct5 var)
3680 LIBTEST_API int STDCALL
3681 mono_test_Winx64_struct6_in (winx64_struct6 var)
3692 LIBTEST_API int STDCALL
3693 mono_test_Winx64_structs_in1 (winx64_struct1 var1,
3694 winx64_struct2 var2,
3695 winx64_struct3 var3,
3696 winx64_struct4 var4)
3710 if (var3.c != 0x1234)
3717 if (var4.c != 0x1234)
3719 if (var4.d != 0x87654321)
3724 LIBTEST_API int STDCALL
3725 mono_test_Winx64_structs_in2 (winx64_struct1 var1,
3726 winx64_struct1 var2,
3727 winx64_struct1 var3,
3728 winx64_struct1 var4,
3729 winx64_struct1 var5)
3745 LIBTEST_API int STDCALL
3746 mono_test_Winx64_structs_in3 (winx64_struct1 var1,
3747 winx64_struct5 var2,
3748 winx64_struct1 var3,
3749 winx64_struct5 var4,
3750 winx64_struct1 var5,
3751 winx64_struct5 var6)
3786 LIBTEST_API winx64_struct1 STDCALL
3787 mono_test_Winx64_struct1_ret (void)
3794 LIBTEST_API winx64_struct2 STDCALL
3795 mono_test_Winx64_struct2_ret (void)
3803 LIBTEST_API winx64_struct3 STDCALL
3804 mono_test_Winx64_struct3_ret (void)
3813 LIBTEST_API winx64_struct4 STDCALL
3814 mono_test_Winx64_struct4_ret (void)
3824 LIBTEST_API winx64_struct5 STDCALL
3825 mono_test_Winx64_struct5_ret (void)
3834 LIBTEST_API winx64_struct1 STDCALL
3835 mono_test_Winx64_struct1_ret_5_args (char a, char b, char c, char d, char e)
3838 ret.a = a + b + c + d + e;
3842 LIBTEST_API winx64_struct5 STDCALL
3843 mono_test_Winx64_struct5_ret6_args (char a, char b, char c, char d, char e)
3856 } winx64_floatStruct;
3858 LIBTEST_API int STDCALL
3859 mono_test_Winx64_floatStruct (winx64_floatStruct a)
3861 if (a.a > 5.6 || a.a < 5.4)
3864 if (a.b > 9.6 || a.b < 9.4)
3873 } winx64_doubleStruct;
3875 LIBTEST_API int STDCALL
3876 mono_test_Winx64_doubleStruct (winx64_doubleStruct a)
3878 if (a.a > 5.6 || a.a < 5.4)
3884 typedef int (STDCALL *managed_struct1_delegate) (winx64_struct1 a);
3886 LIBTEST_API int STDCALL
3887 mono_test_managed_Winx64_struct1_in(managed_struct1_delegate func)
3894 typedef int (STDCALL *managed_struct5_delegate) (winx64_struct5 a);
3896 LIBTEST_API int STDCALL
3897 mono_test_managed_Winx64_struct5_in(managed_struct5_delegate func)
3906 typedef int (STDCALL *managed_struct1_struct5_delegate) (winx64_struct1 a, winx64_struct5 b,
3907 winx64_struct1 c, winx64_struct5 d,
3908 winx64_struct1 e, winx64_struct5 f);
3910 LIBTEST_API int STDCALL
3911 mono_test_managed_Winx64_struct1_struct5_in(managed_struct1_struct5_delegate func)
3913 winx64_struct1 a, c, e;
3914 winx64_struct5 b, d, f;
3916 b.a = 2; b.b = 3; b.c = 4;
3918 d.a = 6; d.b = 7; d.c = 8;
3920 f.a = 10; f.b = 11; f.c = 12;
3922 return func (a, b, c, d, e, f);
3925 typedef winx64_struct1 (STDCALL *managed_struct1_ret_delegate) (void);
3927 LIBTEST_API int STDCALL
3928 mono_test_Winx64_struct1_ret_managed (managed_struct1_ret_delegate func)
3940 typedef winx64_struct5 (STDCALL *managed_struct5_ret_delegate) (void);
3942 LIBTEST_API int STDCALL
3943 mono_test_Winx64_struct5_ret_managed (managed_struct5_ret_delegate func)
3959 LIBTEST_API int STDCALL
3960 mono_test_marshal_bool_in (int arg, unsigned int expected, unsigned int bDefaultMarsh, unsigned int bBoolCustMarsh,
3961 char bI1CustMarsh, unsigned char bU1CustMarsh, short bVBCustMarsh)
3965 if (bDefaultMarsh != expected)
3969 if (bBoolCustMarsh != expected)
3973 if (bI1CustMarsh != expected)
3977 if (bU1CustMarsh != expected)
3981 if (bVBCustMarsh != expected)
3990 LIBTEST_API int STDCALL
3991 mono_test_marshal_bool_out (int arg, unsigned int testVal, unsigned int* bDefaultMarsh, unsigned int* bBoolCustMarsh,
3992 char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh)
3998 *bDefaultMarsh = testVal;
4001 if (!bBoolCustMarsh)
4003 *bBoolCustMarsh = testVal;
4008 *bI1CustMarsh = (char)testVal;
4013 *bU1CustMarsh = (unsigned char)testVal;
4018 *bVBCustMarsh = (unsigned short)testVal;
4026 LIBTEST_API int STDCALL
4027 mono_test_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4028 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh,
4029 unsigned short* bVBCustMarsh)
4035 if (*bDefaultMarsh != expected)
4037 *bDefaultMarsh = testVal;
4040 if (!bBoolCustMarsh)
4042 if (*bBoolCustMarsh != expected)
4044 *bBoolCustMarsh = testVal;
4049 if (*bI1CustMarsh != expected)
4051 *bI1CustMarsh = (char)testVal;
4056 if (*bU1CustMarsh != expected)
4058 *bU1CustMarsh = (unsigned char)testVal;
4063 if (*bVBCustMarsh != expected)
4065 *bVBCustMarsh = (unsigned short)testVal;
4074 typedef int (STDCALL *MarshalBoolInDelegate) (int arg, unsigned int expected, unsigned int bDefaultMarsh,
4075 unsigned int bBoolCustMarsh, char bI1CustMarsh, unsigned char bU1CustMarsh, unsigned short bVBCustMarsh);
4077 LIBTEST_API int STDCALL
4078 mono_test_managed_marshal_bool_in (int arg, unsigned int expected, unsigned int testVal, MarshalBoolInDelegate pfcn)
4085 return pfcn (arg, expected, testVal, 0, 0, 0, 0);
4087 return pfcn (arg, expected, 0, testVal, 0, 0, 0);
4089 return pfcn (arg, expected, 0, 0, testVal, 0, 0);
4091 return pfcn (arg, expected, 0, 0, 0, testVal, 0);
4093 return pfcn (arg, expected, 0, 0, 0, 0, testVal);
4101 typedef int (STDCALL *MarshalBoolOutDelegate) (int arg, unsigned int expected, unsigned int* bDefaultMarsh,
4102 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4104 LIBTEST_API int STDCALL
4105 mono_test_managed_marshal_bool_out (int arg, unsigned int expected, unsigned int testVal, MarshalBoolOutDelegate pfcn)
4108 unsigned int lDefaultMarsh, lBoolCustMarsh;
4109 char lI1CustMarsh = 0;
4110 unsigned char lU1CustMarsh = 0;
4111 unsigned short lVBCustMarsh = 0;
4112 lDefaultMarsh = lBoolCustMarsh = 0;
4119 unsigned int ltVal = 0;
4120 ret = pfcn (arg, testVal, <Val, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4122 return 0x0100 + ret;
4123 if (expected != ltVal)
4128 unsigned int ltVal = 0;
4129 ret = pfcn (arg, testVal, &lDefaultMarsh, <Val, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4131 return 0x0300 + ret;
4132 if (expected != ltVal)
4138 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, <Val, &lU1CustMarsh, &lVBCustMarsh);
4140 return 0x0500 + ret;
4141 if (expected != ltVal)
4146 unsigned char ltVal = 0;
4147 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <Val, &lVBCustMarsh);
4149 return 0x0700 + ret;
4150 if (expected != ltVal)
4155 unsigned short ltVal = 0;
4156 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <Val);
4158 return 0x0900 + ret;
4159 if (expected != ltVal)
4170 typedef int (STDCALL *MarshalBoolRefDelegate) (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4171 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4173 LIBTEST_API int STDCALL
4174 mono_test_managed_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int outExpected,
4175 unsigned int outTestVal, MarshalBoolRefDelegate pfcn)
4178 unsigned int lDefaultMarsh, lBoolCustMarsh;
4179 char lI1CustMarsh = 0;
4180 unsigned char lU1CustMarsh = 0;
4181 unsigned short lVBCustMarsh = 0;
4182 lDefaultMarsh = lBoolCustMarsh = 0;
4190 unsigned int ltestVal = testVal;
4191 ret = pfcn (arg, expected, outTestVal, <estVal, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4193 return 0x0100 + ret;
4194 if (outExpected != ltestVal)
4200 unsigned int ltestVal = testVal;
4201 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, <estVal, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4203 return 0x0300 + ret;
4204 if (outExpected != ltestVal)
4210 char ltestVal = testVal;
4211 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, <estVal, &lU1CustMarsh, &lVBCustMarsh);
4213 return 0x0500 + ret;
4214 if (outExpected != ltestVal)
4220 unsigned char ltestVal = testVal;
4221 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <estVal, &lVBCustMarsh);
4223 return 0x0700 + ret;
4224 if (outExpected != ltestVal)
4230 unsigned short ltestVal = testVal;
4231 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <estVal);
4233 return 0x0900 + ret;
4234 if (outExpected != ltestVal)
4247 LIBTEST_API int STDCALL
4248 mono_test_marshal_safearray_out_1dim_vt_bstr_empty (SAFEARRAY** safearray)
4250 /* Create an empty one-dimensional array of variants */
4252 SAFEARRAYBOUND dimensions [1];
4254 dimensions [0].lLbound = 0;
4255 dimensions [0].cElements = 0;
4257 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4262 LIBTEST_API int STDCALL
4263 mono_test_marshal_safearray_out_1dim_vt_bstr (SAFEARRAY** safearray)
4265 /* Create a one-dimensional array of 10 variants filled with "0" to "9" */
4267 SAFEARRAYBOUND dimensions [1];
4273 dimensions [0].lLbound = 0;
4274 dimensions [0].cElements = 10;
4276 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4277 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4279 VariantInit (&vOut);
4281 _ltoa (i,buffer,10);
4282 vOut.bstrVal= marshal_bstr_alloc (buffer);
4284 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4285 VariantClear (&vOut);
4286 SafeArrayDestroy (pSA);
4289 VariantClear (&vOut);
4295 LIBTEST_API int STDCALL
4296 mono_test_marshal_safearray_out_2dim_vt_i4 (SAFEARRAY** safearray)
4298 /* Create a two-dimensional array of 4x3 variants filled with 11, 12, 13, etc. */
4300 SAFEARRAYBOUND dimensions [2];
4305 dimensions [0].lLbound = 0;
4306 dimensions [0].cElements = 4;
4307 dimensions [1].lLbound = 0;
4308 dimensions [1].cElements = 3;
4310 pSA= SafeArrayCreate(VT_VARIANT, 2, dimensions);
4311 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4312 for (j= dimensions [1].lLbound; j< (dimensions [1].cElements + dimensions [1].lLbound); j++) {
4314 VariantInit (&vOut);
4316 vOut.lVal = (i+1)*10+(j+1);
4319 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4320 VariantClear (&vOut);
4321 SafeArrayDestroy (pSA);
4324 VariantClear (&vOut); // does a deep destroy of source VARIANT
4331 LIBTEST_API int STDCALL
4332 mono_test_marshal_safearray_out_4dim_vt_i4 (SAFEARRAY** safearray)
4334 /* Create a four-dimensional array of 10x3x6x7 variants filled with their indices */
4335 /* Also use non zero lower bounds */
4337 SAFEARRAYBOUND dimensions [4];
4342 dimensions [0].lLbound = 15;
4343 dimensions [0].cElements = 10;
4344 dimensions [1].lLbound = 20;
4345 dimensions [1].cElements = 3;
4346 dimensions [2].lLbound = 5;
4347 dimensions [2].cElements = 6;
4348 dimensions [3].lLbound = 12;
4349 dimensions [3].cElements = 7;
4351 pSA= SafeArrayCreate (VT_VARIANT, 4, dimensions);
4353 SafeArrayAccessData (pSA, (void **)&pData);
4355 for (i= 0; i< 10*3*6*7; i++) {
4356 VariantInit(&pData [i]);
4357 pData [i].vt = VT_I4;
4360 SafeArrayUnaccessData (pSA);
4365 LIBTEST_API int STDCALL
4366 mono_test_marshal_safearray_in_byval_1dim_empty (SAFEARRAY* safearray)
4368 /* Check that array is one dimensional and empty */
4371 long lbound, ubound;
4373 dim = SafeArrayGetDim (safearray);
4377 SafeArrayGetLBound (safearray, 1, &lbound);
4378 SafeArrayGetUBound (safearray, 1, &ubound);
4380 if ((lbound > 0) || (ubound > 0))
4386 LIBTEST_API int STDCALL
4387 mono_test_marshal_safearray_in_byval_1dim_vt_i4 (SAFEARRAY* safearray)
4389 /* Check that array is one dimensional containing integers from 1 to 10 */
4392 long lbound, ubound;
4397 dim = SafeArrayGetDim (safearray);
4401 SafeArrayGetLBound (safearray, 1, &lbound);
4402 SafeArrayGetUBound (safearray, 1, &ubound);
4404 if ((lbound != 0) || (ubound != 9))
4407 SafeArrayAccessData (safearray, (void **)&pData);
4408 for (i= lbound; i <= ubound; i++) {
4409 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i + 1))
4412 SafeArrayUnaccessData (safearray);
4417 LIBTEST_API int STDCALL
4418 mono_test_marshal_safearray_in_byval_1dim_vt_mixed (SAFEARRAY* safearray)
4420 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4423 long lbound, ubound;
4430 VariantInit (&element);
4432 dim = SafeArrayGetDim (safearray);
4436 SafeArrayGetLBound (safearray, 1, &lbound);
4437 SafeArrayGetUBound (safearray, 1, &ubound);
4439 if ((lbound != 0) || (ubound != 12))
4442 SafeArrayAccessData (safearray, (void **)&pData);
4443 for (i= lbound; i <= ubound; i++) {
4444 if ((i%2 == 0) && (pData [i].vt != VT_I4))
4446 if ((i%2 == 1) && (pData [i].vt != VT_BSTR))
4448 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i))
4451 SafeArrayUnaccessData (safearray);
4453 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4458 SafeArrayPutElement (safearray, indices, &element);
4459 VariantClear (&element);
4464 LIBTEST_API int STDCALL
4465 mono_test_marshal_safearray_in_byval_2dim_vt_i4 (SAFEARRAY* safearray)
4467 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4470 long lbound1, ubound1, lbound2, ubound2;
4475 VariantInit (&element);
4477 dim = SafeArrayGetDim (safearray);
4481 SafeArrayGetLBound (safearray, 1, &lbound1);
4482 SafeArrayGetUBound (safearray, 1, &ubound1);
4484 if ((lbound1 != 0) || (ubound1 != 1))
4487 SafeArrayGetLBound (safearray, 2, &lbound2);
4488 SafeArrayGetUBound (safearray, 2, &ubound2);
4490 if ((lbound2 != 0) || (ubound2 != 3)) {
4494 for (i= lbound1; i <= ubound1; i++) {
4496 for (j= lbound2; j <= ubound2; j++) {
4498 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4500 failed = ((element.vt != VT_I4) || (element.lVal != 10*(i+1)+(j+1)));
4501 VariantClear (&element);
4507 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4513 SafeArrayPutElement (safearray, indices, &element);
4514 VariantClear (&element);
4519 LIBTEST_API int STDCALL
4520 mono_test_marshal_safearray_in_byval_3dim_vt_bstr (SAFEARRAY* safearray)
4522 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4525 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4526 long i, j, k, failed;
4530 VariantInit (&element);
4532 dim = SafeArrayGetDim (safearray);
4536 SafeArrayGetLBound (safearray, 1, &lbound1);
4537 SafeArrayGetUBound (safearray, 1, &ubound1);
4539 if ((lbound1 != 0) || (ubound1 != 1))
4542 SafeArrayGetLBound (safearray, 2, &lbound2);
4543 SafeArrayGetUBound (safearray, 2, &ubound2);
4545 if ((lbound2 != 0) || (ubound2 != 1))
4548 SafeArrayGetLBound (safearray, 3, &lbound3);
4549 SafeArrayGetUBound (safearray, 3, &ubound3);
4551 if ((lbound3 != 0) || (ubound3 != 2))
4554 for (i= lbound1; i <= ubound1; i++) {
4556 for (j= lbound2; j <= ubound2; j++) {
4558 for (k= lbound3; k <= ubound3; k++) {
4560 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4562 failed = ((element.vt != VT_BSTR)
4563 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4564 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4565 VariantClear (&element);
4572 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4577 element.vt = VT_BSTR;
4578 element.bstrVal = SysAllocString(L"Should not be copied");
4579 SafeArrayPutElement (safearray, indices, &element);
4580 VariantClear (&element);
4585 LIBTEST_API int STDCALL
4586 mono_test_marshal_safearray_in_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4588 return mono_test_marshal_safearray_in_byval_3dim_vt_bstr (*safearray);
4591 LIBTEST_API int STDCALL
4592 mono_test_marshal_safearray_in_out_byref_1dim_empty (SAFEARRAY** safearray)
4594 /* Check that the input array is what is expected and change it so the caller can check */
4595 /* correct marshalling back to managed code */
4598 long lbound, ubound;
4599 SAFEARRAYBOUND dimensions [1];
4601 wchar_t buffer [20];
4605 /* Check that in array is one dimensional and empty */
4607 dim = SafeArrayGetDim (*safearray);
4612 SafeArrayGetLBound (*safearray, 1, &lbound);
4613 SafeArrayGetUBound (*safearray, 1, &ubound);
4615 if ((lbound > 0) || (ubound > 0)) {
4619 /* Re-dimension the array and return a one-dimensional array of 8 variants filled with "0" to "7" */
4621 dimensions [0].lLbound = 0;
4622 dimensions [0].cElements = 8;
4624 hr = SafeArrayRedim (*safearray, dimensions);
4628 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
4630 VariantInit (&vOut);
4632 _ltow (i,buffer,10);
4633 vOut.bstrVal = SysAllocString (buffer);
4635 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
4636 VariantClear (&vOut);
4637 SafeArrayDestroy (*safearray);
4640 VariantClear (&vOut);
4645 LIBTEST_API int STDCALL
4646 mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr (SAFEARRAY** safearray)
4648 /* Check that the input array is what is expected and change it so the caller can check */
4649 /* correct marshalling back to managed code */
4652 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4653 SAFEARRAYBOUND dimensions [1];
4654 long i, j, k, failed;
4655 wchar_t buffer [20];
4660 VariantInit (&element);
4662 /* Check that in array is three dimensional and contains the expected values */
4664 dim = SafeArrayGetDim (*safearray);
4668 SafeArrayGetLBound (*safearray, 1, &lbound1);
4669 SafeArrayGetUBound (*safearray, 1, &ubound1);
4671 if ((lbound1 != 0) || (ubound1 != 1))
4674 SafeArrayGetLBound (*safearray, 2, &lbound2);
4675 SafeArrayGetUBound (*safearray, 2, &ubound2);
4677 if ((lbound2 != 0) || (ubound2 != 1))
4680 SafeArrayGetLBound (*safearray, 3, &lbound3);
4681 SafeArrayGetUBound (*safearray, 3, &ubound3);
4683 if ((lbound3 != 0) || (ubound3 != 2))
4686 for (i= lbound1; i <= ubound1; i++) {
4688 for (j= lbound2; j <= ubound2; j++) {
4690 for (k= lbound3; k <= ubound3; k++) {
4692 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
4694 failed = ((element.vt != VT_BSTR)
4695 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4696 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4697 VariantClear (&element);
4704 hr = SafeArrayDestroy (*safearray);
4708 /* Return a new one-dimensional array of 8 variants filled with "0" to "7" */
4710 dimensions [0].lLbound = 0;
4711 dimensions [0].cElements = 8;
4713 *safearray = SafeArrayCreate (VT_VARIANT, 1, dimensions);
4715 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
4717 VariantInit (&vOut);
4719 _ltow (i,buffer,10);
4720 vOut.bstrVal = SysAllocString (buffer);
4722 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
4723 VariantClear (&vOut);
4724 SafeArrayDestroy (*safearray);
4727 VariantClear (&vOut);
4732 LIBTEST_API int STDCALL
4733 mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 (SAFEARRAY** safearray)
4735 /* Check that the input array is what is expected and change it so the caller can check */
4736 /* correct marshalling back to managed code */
4739 long lbound1, ubound1;
4745 VariantInit (&element);
4747 /* Check that in array is one dimensional and contains the expected value */
4749 dim = SafeArrayGetDim (*safearray);
4753 SafeArrayGetLBound (*safearray, 1, &lbound1);
4754 SafeArrayGetUBound (*safearray, 1, &ubound1);
4757 if ((lbound1 != 0) || (ubound1 != 1))
4761 for (i= lbound1; i <= ubound1; i++) {
4763 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
4765 failed = (element.vt != VT_I4) || (element.lVal != i+1);
4766 VariantClear (&element);
4771 /* Change one of the elements of the array to verify that [out] parameter is marshalled back to the managed side */
4776 SafeArrayPutElement (*safearray, indices, &element);
4777 VariantClear (&element);
4782 LIBTEST_API int STDCALL
4783 mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (SAFEARRAY* safearray)
4785 /* Check that the input array is what is expected and change it so the caller can check */
4786 /* correct marshalling back to managed code */
4789 long lbound1, ubound1;
4790 SAFEARRAYBOUND dimensions [1];
4796 VariantInit (&element);
4798 /* Check that in array is one dimensional and contains the expected value */
4800 dim = SafeArrayGetDim (safearray);
4804 SafeArrayGetLBound (safearray, 1, &lbound1);
4805 SafeArrayGetUBound (safearray, 1, &ubound1);
4807 if ((lbound1 != 0) || (ubound1 != 0))
4810 for (i= lbound1; i <= ubound1; i++) {
4812 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4814 failed = (element.vt != VT_I4) || (element.lVal != i+1);
4815 VariantClear (&element);
4820 /* Change the array to verify how [out] parameter is marshalled back to the managed side */
4822 /* Redimension the array */
4823 dimensions [0].lLbound = lbound1;
4824 dimensions [0].cElements = 2;
4825 hr = SafeArrayRedim(safearray, dimensions);
4829 element.lVal = 12345;
4830 SafeArrayPutElement (safearray, indices, &element);
4831 VariantClear (&element);
4835 element.lVal = -12345;
4836 SafeArrayPutElement (safearray, indices, &element);
4837 VariantClear (&element);
4842 LIBTEST_API int STDCALL
4843 mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr (SAFEARRAY* safearray)
4845 /* Check that the input array is what is expected and change it so the caller can check */
4846 /* correct marshalling back to managed code */
4849 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
4850 long i, j, k, failed;
4855 VariantInit (&element);
4857 /* Check that in array is three dimensional and contains the expected values */
4859 dim = SafeArrayGetDim (safearray);
4863 SafeArrayGetLBound (safearray, 1, &lbound1);
4864 SafeArrayGetUBound (safearray, 1, &ubound1);
4866 if ((lbound1 != 0) || (ubound1 != 1))
4869 SafeArrayGetLBound (safearray, 2, &lbound2);
4870 SafeArrayGetUBound (safearray, 2, &ubound2);
4872 if ((lbound2 != 0) || (ubound2 != 1))
4875 SafeArrayGetLBound (safearray, 3, &lbound3);
4876 SafeArrayGetUBound (safearray, 3, &ubound3);
4878 if ((lbound3 != 0) || (ubound3 != 2))
4881 for (i= lbound1; i <= ubound1; i++) {
4883 for (j= lbound2; j <= ubound2; j++) {
4885 for (k= lbound3; k <= ubound3; k++) {
4887 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4889 failed = ((element.vt != VT_BSTR)
4890 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
4891 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
4892 VariantClear (&element);
4899 /* Change the elements of the array to verify that [out] parameter is marshalled back to the managed side */
4906 SafeArrayPutElement (safearray, indices, &element);
4907 VariantClear (&element);
4914 SafeArrayPutElement (safearray, indices, &element);
4915 VariantClear (&element);
4920 element.vt = VT_BSTR;
4921 element.bstrVal = marshal_bstr_alloc("ABCDEFG");
4922 SafeArrayPutElement (safearray, indices, &element);
4923 VariantClear (&element);
4928 LIBTEST_API int STDCALL
4929 mono_test_marshal_safearray_mixed(
4930 SAFEARRAY *safearray1,
4931 SAFEARRAY **safearray2,
4932 SAFEARRAY *safearray3,
4933 SAFEARRAY **safearray4
4938 /* Initialize out parameters */
4941 /* array1: Check that in array is one dimensional and contains the expected value */
4942 hr = mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (safearray1);
4944 /* array2: Fill in with some values to check on the managed side */
4946 hr = mono_test_marshal_safearray_out_1dim_vt_bstr (safearray2);
4948 /* array3: Check that in array is one dimensional and contains the expected value */
4950 hr = mono_test_marshal_safearray_in_byval_1dim_vt_mixed(safearray3);
4952 /* array4: Check input values and fill in with some values to check on the managed side */
4954 hr = mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr(safearray4);