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 ()
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);
1005 LIBTEST_API int STDCALL
1006 mono_test_marshal_empty_string_array (char **array)
1008 return (array == NULL) ? 0 : 1;
1011 LIBTEST_API int STDCALL
1012 mono_test_marshal_string_array (char **array)
1014 if (strcmp (array [0], "ABC"))
1016 if (strcmp (array [1], "DEF"))
1019 if (array [2] != NULL)
1025 LIBTEST_API int STDCALL
1026 mono_test_marshal_byref_string_array (char ***array)
1031 if (strcmp ((*array) [0], "Alpha"))
1033 if (strcmp ((*array) [1], "Beta"))
1035 if (strcmp ((*array) [2], "Gamma"))
1041 LIBTEST_API int STDCALL
1042 mono_test_marshal_stringbuilder_array (char **array)
1044 if (strcmp (array [0], "ABC"))
1046 if (strcmp (array [1], "DEF"))
1049 strcpy (array [0], "DEF");
1050 strcpy (array [1], "ABC");
1055 LIBTEST_API int STDCALL
1056 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
1058 GError *error = NULL;
1061 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
1062 if (strcmp (s, "ABC")) {
1069 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
1070 if (strcmp (s, "DEF")) {
1077 if (strcmp (array2 [0], "ABC"))
1080 if (strcmp (array2 [1], "DEF"))
1086 /* this does not work on Redhat gcc 2.96 */
1087 LIBTEST_API int STDCALL
1088 mono_test_empty_struct (int a, EmptyStruct es, int b)
1090 // printf ("mono_test_empty_struct %d %d\n", a, b);
1092 // Intel icc on ia64 passes 'es' in 2 registers
1093 #if defined(__ia64) && defined(__INTEL_COMPILER)
1096 if (a == 1 && b == 2)
1106 LIBTEST_API ByValStrStruct * STDCALL
1107 mono_test_byvalstr_gen (void)
1109 ByValStrStruct *ret;
1111 ret = malloc(sizeof(ByValStrStruct));
1112 memset(ret, 'a', sizeof(ByValStrStruct)-1);
1113 ret->a[sizeof(ByValStrStruct)-1] = 0;
1118 LIBTEST_API int STDCALL
1119 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
1123 ret = strcmp(data->a, correctString);
1124 // printf ("T1: %s\n", data->a);
1125 // printf ("T2: %s\n", correctString);
1127 marshal_free (data);
1134 } ByValStrStruct_Unicode;
1136 LIBTEST_API int STDCALL
1137 mono_test_byvalstr_check_unicode (ByValStrStruct_Unicode *ref, int test)
1139 if (ref->flag != 0x1234abcd){
1140 printf ("overwritten data");
1144 if (test == 1 || test == 3){
1145 if (ref->a [0] != '1' ||
1146 ref->a [1] != '2' ||
1152 if (ref->a [0] != '1' ||
1160 LIBTEST_API int STDCALL
1161 NameManglingAnsi (char *data)
1163 return data [0] + data [1] + data [2];
1166 LIBTEST_API int STDCALL
1167 NameManglingAnsiA (char *data)
1169 g_assert_not_reached ();
1172 LIBTEST_API int STDCALL
1173 NameManglingAnsiW (char *data)
1175 g_assert_not_reached ();
1178 LIBTEST_API int STDCALL
1179 NameManglingAnsi2A (char *data)
1181 return data [0] + data [1] + data [2];
1184 LIBTEST_API int STDCALL
1185 NameManglingAnsi2W (char *data)
1187 g_assert_not_reached ();
1190 LIBTEST_API int STDCALL
1191 NameManglingUnicode (char *data)
1193 g_assert_not_reached ();
1196 LIBTEST_API int STDCALL
1197 NameManglingUnicodeW (gunichar2 *data)
1199 return data [0] + data [1] + data [2];
1202 LIBTEST_API int STDCALL
1203 NameManglingUnicode2 (gunichar2 *data)
1205 return data [0] + data [1] + data [2];
1208 LIBTEST_API int STDCALL
1209 NameManglingAutoW (char *data)
1212 return (data [0] + data [1] + data [2]) == 131 ? 0 : 1;
1214 g_assert_not_reached ();
1218 LIBTEST_API int STDCALL
1219 NameManglingAuto (char *data)
1222 return (data [0] + data [1] + data [2]) == 198 ? 0 : 1;
1224 g_assert_not_reached ();
1228 typedef int (STDCALL *intcharFunc)(const char*);
1230 LIBTEST_API void STDCALL
1231 callFunction (intcharFunc f)
1241 LIBTEST_API int STDCALL
1242 class_marshal_test0 (SimpleObj *obj1)
1244 // printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
1246 if (strcmp(obj1->str, "T1"))
1254 LIBTEST_API int STDCALL
1255 class_marshal_test4 (SimpleObj *obj1)
1263 LIBTEST_API void STDCALL
1264 class_marshal_test1 (SimpleObj **obj1)
1266 SimpleObj *res = malloc (sizeof (SimpleObj));
1268 res->str = g_strdup ("ABC");
1274 LIBTEST_API int STDCALL
1275 class_marshal_test2 (SimpleObj **obj1)
1277 // printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
1279 if (strcmp((*obj1)->str, "ABC"))
1281 if ((*obj1)->i != 5)
1287 LIBTEST_API int STDCALL
1288 string_marshal_test0 (char *str)
1290 if (strcmp (str, "TEST0"))
1296 LIBTEST_API void STDCALL
1297 string_marshal_test1 (const char **str)
1299 *str = g_strdup ("TEST1");
1302 LIBTEST_API int STDCALL
1303 string_marshal_test2 (char **str)
1305 // printf ("string_marshal_test2 %s\n", *str);
1307 if (strcmp (*str, "TEST1"))
1313 LIBTEST_API int STDCALL
1314 string_marshal_test3 (char *str)
1327 LIBTEST_API BlittableClass* STDCALL
1328 TestBlittableClass (BlittableClass *vl)
1330 BlittableClass *res;
1332 // printf ("TestBlittableClass %d %d\n", vl->a, vl->b);
1338 res = g_new0 (BlittableClass, 1);
1339 memcpy (res, vl, sizeof (BlittableClass));
1341 res = g_new0 (BlittableClass, 1);
1349 typedef struct OSVERSIONINFO_STRUCT
1353 } OSVERSIONINFO_STRUCT;
1355 LIBTEST_API int STDCALL
1356 MyGetVersionEx (OSVERSIONINFO_STRUCT *osvi)
1359 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1364 return osvi->a + osvi->b;
1367 LIBTEST_API int STDCALL
1368 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO_STRUCT *osvi)
1371 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1376 return osvi->a + osvi->b;
1379 LIBTEST_API int STDCALL
1380 mono_test_marshal_point (point pt)
1382 // printf("point %g %g\n", pt.x, pt.y);
1383 if (pt.x == 1.25 && pt.y == 3.5)
1394 LIBTEST_API int STDCALL
1395 mono_test_marshal_mixed_point (mixed_point pt)
1397 // printf("mixed point %d %g\n", pt.x, pt.y);
1398 if (pt.x == 5 && pt.y == 6.75)
1404 LIBTEST_API int STDCALL
1405 mono_test_marshal_mixed_point_2 (mixed_point *pt)
1407 if (pt->x != 5 || pt->y != 6.75)
1416 LIBTEST_API int STDCALL
1417 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
1420 if (*b1 != 0 && *b1 != 1)
1422 if (*b2 != 0 && *b2 != -1) /* variant_bool */
1424 if (*b3 != 0 && *b3 != 1)
1426 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
1438 short b2; /* variant_bool */
1442 LIBTEST_API int STDCALL
1443 marshal_test_bool_struct(struct BoolStruct *s)
1446 if (s->b1 != 0 && s->b1 != 1)
1448 if (s->b2 != 0 && s->b2 != -1)
1450 if (s->b3 != 0 && s->b3 != 1)
1452 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1469 LIBTEST_API int STDCALL
1470 mono_test_marshal_long_struct (LongStruct *s)
1472 return s->i + s->l.l;
1475 LIBTEST_API void STDCALL
1476 mono_test_last_error (int err)
1485 LIBTEST_API int STDCALL
1486 mono_test_asany (void *ptr, int what)
1490 return (*(int*)ptr == 5) ? 0 : 1;
1492 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1494 simplestruct2 ss = *(simplestruct2*)ptr;
1496 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1497 !strcmp (ss.d, "TEST") &&
1498 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1504 GError *error = NULL;
1507 s = g_utf16_to_utf8 (ptr, -1, NULL, NULL, &error);
1508 if (!strcmp (s, "ABC")) {
1518 g_assert_not_reached ();
1532 LIBTEST_API int STDCALL
1533 mono_test_marshal_asany_in (void* ptr)
1535 AsAnyStruct* asAny = ptr;
1536 int res = asAny->i + asAny->j + asAny->k;
1541 LIBTEST_API int STDCALL
1542 mono_test_marshal_asany_inout (void* ptr)
1544 AsAnyStruct* asAny = ptr;
1545 int res = asAny->i + asAny->j + asAny->k;
1547 marshal_free (asAny->s);
1557 LIBTEST_API int STDCALL
1558 mono_test_marshal_asany_out (void* ptr)
1560 AsAnyStruct* asAny = ptr;
1561 int res = asAny->i + asAny->j + asAny->k;
1572 * AMD64 marshalling tests.
1575 typedef struct amd64_struct1 {
1582 LIBTEST_API amd64_struct1 STDCALL
1583 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
1593 LIBTEST_API amd64_struct1 STDCALL
1594 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)
1599 s.l += 1 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8;
1604 typedef struct amd64_struct2 {
1609 LIBTEST_API amd64_struct2 STDCALL
1610 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
1618 typedef struct amd64_struct3 {
1622 LIBTEST_API amd64_struct3 STDCALL
1623 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s)
1630 typedef struct amd64_struct4 {
1634 LIBTEST_API amd64_struct4 STDCALL
1635 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s)
1644 * IA64 marshalling tests.
1646 typedef struct test_struct5 {
1650 LIBTEST_API test_struct5 STDCALL
1651 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, test_struct5 s, int i, double d3, double d4)
1653 s.d1 += d1 + d2 + i;
1654 s.d2 += d3 + d4 + i;
1659 typedef struct test_struct6 {
1663 LIBTEST_API test_struct6 STDCALL
1664 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, test_struct6 s, int i, double d3, double d4)
1666 s.d1 += d1 + d2 + i;
1672 static guint32 custom_res [2];
1674 LIBTEST_API void* STDCALL
1675 mono_test_marshal_pass_return_custom (int i, guint32 *ptr, int j)
1677 /* ptr will be freed by CleanupNative, so make a copy */
1678 custom_res [0] = 0; /* not allocated by AllocHGlobal */
1679 custom_res [1] = ptr [1];
1684 LIBTEST_API int STDCALL
1685 mono_test_marshal_pass_out_custom (int i, guint32 **ptr, int j)
1688 custom_res [1] = i + j + 10;
1695 LIBTEST_API int STDCALL
1696 mono_test_marshal_pass_inout_custom (int i, guint32 *ptr, int j)
1699 ptr [1] = i + ptr [1] + j;
1704 LIBTEST_API int STDCALL
1705 mono_test_marshal_pass_out_byval_custom (int i, guint32 *ptr, int j)
1707 return ptr == NULL ? 0 : 1;
1710 LIBTEST_API int STDCALL
1711 mono_test_marshal_pass_byref_custom (int i, guint32 **ptr, int j)
1718 LIBTEST_API void* STDCALL
1719 mono_test_marshal_pass_return_custom2 (int i, guint32 *ptr, int j)
1721 g_assert_not_reached ();
1726 LIBTEST_API void* STDCALL
1727 mono_test_marshal_pass_return_custom_null (int i, guint32 *ptr, int j)
1729 g_assert (ptr == NULL);
1734 typedef void *(STDCALL *PassReturnPtrDelegate) (void *ptr);
1736 LIBTEST_API int STDCALL
1737 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del)
1751 /* FIXME: Freed with FreeHGlobal */
1759 LIBTEST_API int STDCALL
1760 mono_test_marshal_pass_return_custom_null_in_delegate (PassReturnPtrDelegate del)
1762 void *ptr = del (NULL);
1764 return (ptr == NULL) ? 15 : 0;
1767 typedef void (STDCALL *CustomOutParamDelegate) (void **pptr);
1769 LIBTEST_API int STDCALL
1770 mono_test_marshal_custom_out_param_delegate (CustomOutParamDelegate del)
1782 typedef int (STDCALL *ReturnEnumDelegate) (int e);
1784 LIBTEST_API int STDCALL
1785 mono_test_marshal_return_enum_delegate (ReturnEnumDelegate func)
1795 typedef BlittableStruct (STDCALL *SimpleDelegate10) (BlittableStruct ss);
1797 LIBTEST_API int STDCALL
1798 mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 delegate)
1800 BlittableStruct ss, res;
1807 res = delegate (ss);
1808 if (! ((res.a == -1) && (res.b == -2) && (res.c == -3) && (res.d == -55)))
1814 LIBTEST_API int STDCALL
1815 mono_test_stdcall_name_mangling (int a, int b, int c)
1821 * PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
1828 typedef SmallStruct1 (STDCALL *SmallStructDelegate1) (SmallStruct1 ss);
1830 LIBTEST_API int STDCALL
1831 mono_test_marshal_small_struct_delegate1 (SmallStructDelegate1 delegate)
1833 SmallStruct1 ss, res;
1837 res = delegate (ss);
1838 if (! (res.i == -1))
1848 typedef SmallStruct2 (STDCALL *SmallStructDelegate2) (SmallStruct2 ss);
1850 LIBTEST_API int STDCALL
1851 mono_test_marshal_small_struct_delegate2 (SmallStructDelegate2 delegate)
1853 SmallStruct2 ss, res;
1858 res = delegate (ss);
1859 if (! ((res.i == -2) && (res.j == -3)))
1870 typedef SmallStruct3 (STDCALL *SmallStructDelegate3) (SmallStruct3 ss);
1872 LIBTEST_API int STDCALL
1873 mono_test_marshal_small_struct_delegate3 (SmallStructDelegate3 delegate)
1875 SmallStruct3 ss, res;
1880 res = delegate (ss);
1881 if (! ((res.i == -1) && (res.j == -2)))
1891 typedef SmallStruct4 (STDCALL *SmallStructDelegate4) (SmallStruct4 ss);
1893 LIBTEST_API int STDCALL
1894 mono_test_marshal_small_struct_delegate4 (SmallStructDelegate4 delegate)
1896 SmallStruct4 ss, res;
1900 res = delegate (ss);
1901 if (! (res.i == -1))
1911 typedef SmallStruct5 (STDCALL *SmallStructDelegate5) (SmallStruct5 ss);
1913 LIBTEST_API int STDCALL
1914 mono_test_marshal_small_struct_delegate5 (SmallStructDelegate5 delegate)
1916 SmallStruct5 ss, res;
1920 res = delegate (ss);
1921 if (! (res.i == -5))
1931 typedef SmallStruct6 (STDCALL *SmallStructDelegate6) (SmallStruct6 ss);
1933 LIBTEST_API int STDCALL
1934 mono_test_marshal_small_struct_delegate6 (SmallStructDelegate6 delegate)
1936 SmallStruct6 ss, res;
1941 res = delegate (ss);
1942 if (! ((res.i == -1) && (res.j == -2)))
1953 typedef SmallStruct7 (STDCALL *SmallStructDelegate7) (SmallStruct7 ss);
1955 LIBTEST_API int STDCALL
1956 mono_test_marshal_small_struct_delegate7 (SmallStructDelegate7 delegate)
1958 SmallStruct7 ss, res;
1963 res = delegate (ss);
1964 if (! ((res.i == -1) && (res.j == -2)))
1974 typedef SmallStruct8 (STDCALL *SmallStructDelegate8) (SmallStruct8 ss);
1976 LIBTEST_API int STDCALL
1977 mono_test_marshal_small_struct_delegate8 (SmallStructDelegate8 delegate)
1979 SmallStruct8 ss, res;
1983 res = delegate (ss);
1984 if (! ((res.i == -1.0)))
1994 typedef SmallStruct9 (STDCALL *SmallStructDelegate9) (SmallStruct9 ss);
1996 LIBTEST_API int STDCALL
1997 mono_test_marshal_small_struct_delegate9 (SmallStructDelegate9 delegate)
1999 SmallStruct9 ss, res;
2003 res = delegate (ss);
2004 if (! ((res.i == -1.0)))
2014 typedef SmallStruct10 (STDCALL *SmallStructDelegate10) (SmallStruct10 ss);
2016 LIBTEST_API int STDCALL
2017 mono_test_marshal_small_struct_delegate10 (SmallStructDelegate10 delegate)
2019 SmallStruct10 ss, res;
2024 res = delegate (ss);
2025 if (! ((res.i == -1.0) && (res.j == -2.0)))
2036 typedef SmallStruct11 (STDCALL *SmallStructDelegate11) (SmallStruct11 ss);
2038 LIBTEST_API int STDCALL
2039 mono_test_marshal_small_struct_delegate11 (SmallStructDelegate11 delegate)
2041 SmallStruct11 ss, res;
2046 res = delegate (ss);
2047 if (! ((res.i == -1.0) && (res.j == -2)))
2053 typedef int (STDCALL *ArrayDelegate) (int i, char *j, void *arr);
2055 LIBTEST_API int STDCALL
2056 mono_test_marshal_array_delegate (void *arr, int len, ArrayDelegate del)
2058 return del (len, NULL, arr);
2061 typedef int (STDCALL *ArrayDelegateLong) (gint64 i, char *j, void *arr);
2063 LIBTEST_API int STDCALL
2064 mono_test_marshal_array_delegate_long (void *arr, gint64 len, ArrayDelegateLong del)
2066 return del (len, NULL, arr);
2069 LIBTEST_API int STDCALL
2070 mono_test_marshal_out_array_delegate (int *arr, int len, ArrayDelegate del)
2072 del (len, NULL, arr);
2074 if ((arr [0] != 1) || (arr [1] != 2))
2080 typedef gunichar2* (STDCALL *UnicodeStringDelegate) (gunichar2 *message);
2082 LIBTEST_API int STDCALL
2083 mono_test_marshal_return_unicode_string_delegate (UnicodeStringDelegate del)
2085 const char m[] = "abcdef";
2086 gunichar2 *s2, *res;
2089 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
2098 LIBTEST_API int STDCALL
2099 mono_test_marshal_out_string_array_delegate (char **arr, int len, ArrayDelegate del)
2101 del (len, NULL, arr);
2103 if (!strcmp (arr [0], "ABC") && !strcmp (arr [1], "DEF"))
2109 typedef int (*CdeclDelegate) (int i, int j);
2111 LIBTEST_API int STDCALL
2112 mono_test_marshal_cdecl_delegate (CdeclDelegate del)
2116 for (i = 0; i < 1000; ++i)
2122 typedef char** (STDCALL *ReturnStringArrayDelegate) (int i);
2124 LIBTEST_API int STDCALL
2125 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d)
2133 if (strcmp (arr [0], "ABC") || strcmp (arr [1], "DEF"))
2143 typedef int (STDCALL *ByrefStringDelegate) (char **s);
2145 LIBTEST_API int STDCALL
2146 mono_test_marshal_byref_string_delegate (ByrefStringDelegate d)
2148 char *s = (char*)"ABC";
2155 if (!strcmp (s, "DEF"))
2165 LIBTEST_API int STDCALL
2166 add_delegate (int i, int j)
2171 LIBTEST_API gpointer STDCALL
2172 mono_test_marshal_return_fnptr (void)
2174 return &add_delegate;
2177 LIBTEST_API int STDCALL
2180 printf ("codigo %x\n", code);
2188 LIBTEST_API HandleRef STDCALL
2189 mono_xr_as_handle (int code)
2193 memset (&ref, 0, sizeof (ref));
2205 LIBTEST_API int STDCALL
2206 mono_safe_handle_struct_ref (HandleStructs *x)
2208 printf ("Dingus Ref! \n");
2209 printf ("Values: %d %d %p %p\n", x->a, x->b, x->handle1, x->handle2);
2215 if (x->handle1 != (void*) 0x7080feed)
2218 if (x->handle2 != (void*) 0x1234abcd)
2224 LIBTEST_API int STDCALL
2225 mono_safe_handle_struct (HandleStructs x)
2227 printf ("Dingus Standard! \n");
2228 printf ("Values: %d %d %p %p\n", x.a, x.b, x.handle1, x.handle2);
2234 if (x.handle1 != (void*) 0x7080feed)
2237 if (x.handle2 != (void*) 0x1234abcd)
2247 LIBTEST_API int STDCALL
2248 mono_safe_handle_struct_simple (TrivialHandle x)
2250 printf ("The value is %p\n", x.a);
2251 return ((int)(gsize)x.a) * 2;
2254 LIBTEST_API int STDCALL
2255 mono_safe_handle_return (void)
2260 LIBTEST_API void STDCALL
2261 mono_safe_handle_ref (void **handle)
2264 *handle = (void *) 0xbad;
2268 *handle = (void *) 0x800d;
2335 VT_USERDEFINED = 29,
2343 VT_STREAMED_OBJECT = 68,
2344 VT_STORED_OBJECT = 69,
2345 VT_BLOB_OBJECT = 70,
2353 void VariantInit(VARIANT* vt)
2370 LIBTEST_API int STDCALL
2371 mono_test_marshal_bstr_in(gunichar2* bstr)
2374 gchar* bstr_utf8 = g_utf16_to_utf8 (bstr, -1, NULL, NULL, NULL);
2375 result = strcmp("mono_test_marshal_bstr_in", bstr_utf8);
2382 LIBTEST_API int STDCALL
2383 mono_test_marshal_bstr_out(gunichar2** bstr)
2385 *bstr = marshal_bstr_alloc ("mono_test_marshal_bstr_out");
2389 LIBTEST_API int STDCALL
2390 mono_test_marshal_bstr_in_null(gunichar2* bstr)
2397 LIBTEST_API int STDCALL
2398 mono_test_marshal_bstr_out_null(gunichar2** bstr)
2404 LIBTEST_API int STDCALL
2405 mono_test_marshal_variant_in_sbyte(VARIANT variant)
2407 if (variant.vt == VT_I1 && variant.cVal == 100)
2412 LIBTEST_API int STDCALL
2413 mono_test_marshal_variant_in_byte(VARIANT variant)
2415 if (variant.vt == VT_UI1 && variant.bVal == 100)
2420 LIBTEST_API int STDCALL
2421 mono_test_marshal_variant_in_short(VARIANT variant)
2423 if (variant.vt == VT_I2 && variant.iVal == 314)
2428 LIBTEST_API int STDCALL
2429 mono_test_marshal_variant_in_ushort(VARIANT variant)
2431 if (variant.vt == VT_UI2 && variant.uiVal == 314)
2436 LIBTEST_API int STDCALL
2437 mono_test_marshal_variant_in_int(VARIANT variant)
2439 if (variant.vt == VT_I4 && variant.lVal == 314)
2444 LIBTEST_API int STDCALL
2445 mono_test_marshal_variant_in_uint(VARIANT variant)
2447 if (variant.vt == VT_UI4 && variant.ulVal == 314)
2452 LIBTEST_API int STDCALL
2453 mono_test_marshal_variant_in_long(VARIANT variant)
2455 if (variant.vt == VT_I8 && variant.llVal == 314)
2460 LIBTEST_API int STDCALL
2461 mono_test_marshal_variant_in_ulong(VARIANT variant)
2463 if (variant.vt == VT_UI8 && variant.ullVal == 314)
2468 LIBTEST_API int STDCALL
2469 mono_test_marshal_variant_in_float(VARIANT variant)
2471 if (variant.vt == VT_R4 && (variant.fltVal - 3.14)/3.14 < .001)
2476 LIBTEST_API int STDCALL
2477 mono_test_marshal_variant_in_double(VARIANT variant)
2479 if (variant.vt == VT_R8 && (variant.dblVal - 3.14)/3.14 < .001)
2484 LIBTEST_API int STDCALL
2485 mono_test_marshal_variant_in_bstr(VARIANT variant)
2488 gchar* bstr_utf8 = g_utf16_to_utf8 (variant.bstrVal, -1, NULL, NULL, NULL);
2489 result = strcmp("PI", bstr_utf8);
2492 if (variant.vt == VT_BSTR && !result)
2497 LIBTEST_API int STDCALL
2498 mono_test_marshal_variant_in_bool_true (VARIANT variant)
2500 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_TRUE)
2505 LIBTEST_API int STDCALL
2506 mono_test_marshal_variant_in_bool_false (VARIANT variant)
2508 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_FALSE)
2513 LIBTEST_API int STDCALL
2514 mono_test_marshal_variant_out_sbyte(VARIANT* variant)
2516 variant->vt = VT_I1;
2517 variant->cVal = 100;
2522 LIBTEST_API int STDCALL
2523 mono_test_marshal_variant_out_byte(VARIANT* variant)
2525 variant->vt = VT_UI1;
2526 variant->bVal = 100;
2531 LIBTEST_API int STDCALL
2532 mono_test_marshal_variant_out_short(VARIANT* variant)
2534 variant->vt = VT_I2;
2535 variant->iVal = 314;
2540 LIBTEST_API int STDCALL
2541 mono_test_marshal_variant_out_ushort(VARIANT* variant)
2543 variant->vt = VT_UI2;
2544 variant->uiVal = 314;
2549 LIBTEST_API int STDCALL
2550 mono_test_marshal_variant_out_int(VARIANT* variant)
2552 variant->vt = VT_I4;
2553 variant->lVal = 314;
2558 LIBTEST_API int STDCALL
2559 mono_test_marshal_variant_out_uint(VARIANT* variant)
2561 variant->vt = VT_UI4;
2562 variant->ulVal = 314;
2567 LIBTEST_API int STDCALL
2568 mono_test_marshal_variant_out_long(VARIANT* variant)
2570 variant->vt = VT_I8;
2571 variant->llVal = 314;
2576 LIBTEST_API int STDCALL
2577 mono_test_marshal_variant_out_ulong(VARIANT* variant)
2579 variant->vt = VT_UI8;
2580 variant->ullVal = 314;
2585 LIBTEST_API int STDCALL
2586 mono_test_marshal_variant_out_float(VARIANT* variant)
2588 variant->vt = VT_R4;
2589 variant->fltVal = 3.14;
2594 LIBTEST_API int STDCALL
2595 mono_test_marshal_variant_out_double(VARIANT* variant)
2597 variant->vt = VT_R8;
2598 variant->dblVal = 3.14;
2603 LIBTEST_API int STDCALL
2604 mono_test_marshal_variant_out_bstr(VARIANT* variant)
2606 variant->vt = VT_BSTR;
2607 variant->bstrVal = marshal_bstr_alloc("PI");
2612 LIBTEST_API int STDCALL
2613 mono_test_marshal_variant_out_bool_true (VARIANT* variant)
2615 variant->vt = VT_BOOL;
2616 variant->boolVal = VARIANT_TRUE;
2621 LIBTEST_API int STDCALL
2622 mono_test_marshal_variant_out_bool_false (VARIANT* variant)
2624 variant->vt = VT_BOOL;
2625 variant->boolVal = VARIANT_FALSE;
2630 typedef int (STDCALL *VarFunc) (int vt, VARIANT variant);
2631 typedef int (STDCALL *VarRefFunc) (int vt, VARIANT* variant);
2633 LIBTEST_API int STDCALL
2634 mono_test_marshal_variant_in_sbyte_unmanaged(VarFunc func)
2639 return func (VT_I1, vt);
2642 LIBTEST_API int STDCALL
2643 mono_test_marshal_variant_in_byte_unmanaged(VarFunc func)
2648 return func (VT_UI1, vt);
2651 LIBTEST_API int STDCALL
2652 mono_test_marshal_variant_in_short_unmanaged(VarFunc func)
2657 return func (VT_I2, vt);
2660 LIBTEST_API int STDCALL
2661 mono_test_marshal_variant_in_ushort_unmanaged(VarFunc func)
2666 return func (VT_UI2, vt);
2669 LIBTEST_API int STDCALL
2670 mono_test_marshal_variant_in_int_unmanaged(VarFunc func)
2675 return func (VT_I4, vt);
2678 LIBTEST_API int STDCALL
2679 mono_test_marshal_variant_in_uint_unmanaged(VarFunc func)
2684 return func (VT_UI4, vt);
2687 LIBTEST_API int STDCALL
2688 mono_test_marshal_variant_in_long_unmanaged(VarFunc func)
2693 return func (VT_I8, vt);
2696 LIBTEST_API int STDCALL
2697 mono_test_marshal_variant_in_ulong_unmanaged(VarFunc func)
2702 return func (VT_UI8, vt);
2705 LIBTEST_API int STDCALL
2706 mono_test_marshal_variant_in_float_unmanaged(VarFunc func)
2711 return func (VT_R4, vt);
2714 LIBTEST_API int STDCALL
2715 mono_test_marshal_variant_in_double_unmanaged(VarFunc func)
2720 return func (VT_R8, vt);
2723 LIBTEST_API int STDCALL
2724 mono_test_marshal_variant_in_bstr_unmanaged(VarFunc func)
2728 vt.bstrVal = marshal_bstr_alloc("PI");
2729 return func (VT_BSTR, vt);
2732 LIBTEST_API int STDCALL
2733 mono_test_marshal_variant_in_bool_true_unmanaged(VarFunc func)
2737 vt.boolVal = VARIANT_TRUE;
2738 return func (VT_BOOL, vt);
2741 LIBTEST_API int STDCALL
2742 mono_test_marshal_variant_in_bool_false_unmanaged(VarFunc func)
2746 vt.boolVal = VARIANT_FALSE;
2747 return func (VT_BOOL, vt);
2750 LIBTEST_API int STDCALL
2751 mono_test_marshal_variant_out_sbyte_unmanaged(VarRefFunc func)
2756 if (vt.vt == VT_I1 && vt.cVal == -100)
2761 LIBTEST_API int STDCALL
2762 mono_test_marshal_variant_out_byte_unmanaged(VarRefFunc func)
2767 if (vt.vt == VT_UI1 && vt.bVal == 100)
2772 LIBTEST_API int STDCALL
2773 mono_test_marshal_variant_out_short_unmanaged(VarRefFunc func)
2778 if (vt.vt == VT_I2 && vt.iVal == -100)
2783 LIBTEST_API int STDCALL
2784 mono_test_marshal_variant_out_ushort_unmanaged(VarRefFunc func)
2789 if (vt.vt == VT_UI2 && vt.uiVal == 100)
2794 LIBTEST_API int STDCALL
2795 mono_test_marshal_variant_out_int_unmanaged(VarRefFunc func)
2800 if (vt.vt == VT_I4 && vt.lVal == -100)
2805 LIBTEST_API int STDCALL
2806 mono_test_marshal_variant_out_uint_unmanaged(VarRefFunc func)
2811 if (vt.vt == VT_UI4 && vt.ulVal == 100)
2816 LIBTEST_API int STDCALL
2817 mono_test_marshal_variant_out_long_unmanaged(VarRefFunc func)
2822 if (vt.vt == VT_I8 && vt.llVal == -100)
2827 LIBTEST_API int STDCALL
2828 mono_test_marshal_variant_out_ulong_unmanaged(VarRefFunc func)
2833 if (vt.vt == VT_UI8 && vt.ullVal == 100)
2838 LIBTEST_API int STDCALL
2839 mono_test_marshal_variant_out_float_unmanaged(VarRefFunc func)
2844 if (vt.vt == VT_R4 && fabs (vt.fltVal - 3.14f) < 1e-10)
2849 LIBTEST_API int STDCALL
2850 mono_test_marshal_variant_out_double_unmanaged(VarRefFunc func)
2855 if (vt.vt == VT_R8 && fabs (vt.dblVal - 3.14) < 1e-10)
2860 LIBTEST_API int STDCALL
2861 mono_test_marshal_variant_out_bstr_unmanaged(VarRefFunc func)
2869 func (VT_BSTR, &vt);
2870 bstr_utf8 = g_utf16_to_utf8 (vt.bstrVal, -1, NULL, NULL, NULL);
2871 result = strcmp("PI", bstr_utf8);
2873 if (vt.vt == VT_BSTR && !result)
2878 LIBTEST_API int STDCALL
2879 mono_test_marshal_variant_out_bool_true_unmanaged(VarRefFunc func)
2883 func (VT_BOOL, &vt);
2884 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
2889 LIBTEST_API int STDCALL
2890 mono_test_marshal_variant_out_bool_false_unmanaged(VarRefFunc func)
2894 func (VT_BOOL, &vt);
2895 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
2900 typedef struct MonoComObject MonoComObject;
2904 int (STDCALL *QueryInterface)(MonoComObject* pUnk, gpointer riid, gpointer* ppv);
2905 int (STDCALL *AddRef)(MonoComObject* pUnk);
2906 int (STDCALL *Release)(MonoComObject* pUnk);
2907 int (STDCALL *get_ITest)(MonoComObject* pUnk, MonoComObject* *ppUnk);
2908 int (STDCALL *SByteIn)(MonoComObject* pUnk, char a);
2909 int (STDCALL *ByteIn)(MonoComObject* pUnk, unsigned char a);
2910 int (STDCALL *ShortIn)(MonoComObject* pUnk, short a);
2911 int (STDCALL *UShortIn)(MonoComObject* pUnk, unsigned short a);
2912 int (STDCALL *IntIn)(MonoComObject* pUnk, int a);
2913 int (STDCALL *UIntIn)(MonoComObject* pUnk, unsigned int a);
2914 int (STDCALL *LongIn)(MonoComObject* pUnk, gint64 a);
2915 int (STDCALL *ULongIn)(MonoComObject* pUnk, guint64 a);
2916 int (STDCALL *FloatIn)(MonoComObject* pUnk, float a);
2917 int (STDCALL *DoubleIn)(MonoComObject* pUnk, double a);
2918 int (STDCALL *ITestIn)(MonoComObject* pUnk, MonoComObject* pUnk2);
2919 int (STDCALL *ITestOut)(MonoComObject* pUnk, MonoComObject* *ppUnk);
2922 struct MonoComObject
2928 static GUID IID_ITest = {0, 0, 0, {0,0,0,0,0,0,0,1}};
2929 static GUID IID_IMonoUnknown = {0, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
2930 static GUID IID_IMonoDispatch = {0x00020400, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
2932 LIBTEST_API int STDCALL
2933 MonoQueryInterface(MonoComObject* pUnk, gpointer riid, gpointer* ppv)
2937 if (!memcmp(riid, &IID_IMonoUnknown, sizeof(GUID))) {
2941 else if (!memcmp(riid, &IID_ITest, sizeof(GUID))) {
2945 else if (!memcmp(riid, &IID_IMonoDispatch, sizeof(GUID))) {
2949 return 0x80004002; //E_NOINTERFACE;
2952 LIBTEST_API int STDCALL
2953 MonoAddRef(MonoComObject* pUnk)
2955 return ++(pUnk->m_ref);
2958 LIBTEST_API int STDCALL
2959 MonoRelease(MonoComObject* pUnk)
2961 return --(pUnk->m_ref);
2964 LIBTEST_API int STDCALL
2965 SByteIn(MonoComObject* pUnk, char a)
2970 LIBTEST_API int STDCALL
2971 ByteIn(MonoComObject* pUnk, unsigned char a)
2976 LIBTEST_API int STDCALL
2977 ShortIn(MonoComObject* pUnk, short a)
2982 LIBTEST_API int STDCALL
2983 UShortIn(MonoComObject* pUnk, unsigned short a)
2988 LIBTEST_API int STDCALL
2989 IntIn(MonoComObject* pUnk, int a)
2994 LIBTEST_API int STDCALL
2995 UIntIn(MonoComObject* pUnk, unsigned int a)
3000 LIBTEST_API int STDCALL
3001 LongIn(MonoComObject* pUnk, gint64 a)
3006 LIBTEST_API int STDCALL
3007 ULongIn(MonoComObject* pUnk, guint64 a)
3012 LIBTEST_API int STDCALL
3013 FloatIn(MonoComObject* pUnk, float a)
3018 LIBTEST_API int STDCALL
3019 DoubleIn(MonoComObject* pUnk, double a)
3024 LIBTEST_API int STDCALL
3025 ITestIn(MonoComObject* pUnk, MonoComObject *pUnk2)
3030 LIBTEST_API int STDCALL
3031 ITestOut(MonoComObject* pUnk, MonoComObject* *ppUnk)
3036 LIBTEST_API int STDCALL
3037 get_ITest(MonoComObject* pUnk, MonoComObject* *ppUnk)
3042 static void create_com_object (MonoComObject** pOut)
3044 *pOut = g_new0 (MonoComObject, 1);
3045 (*pOut)->vtbl = g_new0 (MonoIUnknown, 1);
3048 (*pOut)->vtbl->QueryInterface = MonoQueryInterface;
3049 (*pOut)->vtbl->AddRef = MonoAddRef;
3050 (*pOut)->vtbl->Release = MonoRelease;
3051 (*pOut)->vtbl->SByteIn = SByteIn;
3052 (*pOut)->vtbl->ByteIn = ByteIn;
3053 (*pOut)->vtbl->ShortIn = ShortIn;
3054 (*pOut)->vtbl->UShortIn = UShortIn;
3055 (*pOut)->vtbl->IntIn = IntIn;
3056 (*pOut)->vtbl->UIntIn = UIntIn;
3057 (*pOut)->vtbl->LongIn = LongIn;
3058 (*pOut)->vtbl->ULongIn = ULongIn;
3059 (*pOut)->vtbl->FloatIn = FloatIn;
3060 (*pOut)->vtbl->DoubleIn = DoubleIn;
3061 (*pOut)->vtbl->ITestIn = ITestIn;
3062 (*pOut)->vtbl->ITestOut = ITestOut;
3063 (*pOut)->vtbl->get_ITest = get_ITest;
3066 static MonoComObject* same_object = NULL;
3068 LIBTEST_API int STDCALL
3069 mono_test_marshal_com_object_create(MonoComObject* *pUnk)
3071 create_com_object (pUnk);
3074 same_object = *pUnk;
3079 LIBTEST_API int STDCALL
3080 mono_test_marshal_com_object_same(MonoComObject* *pUnk)
3082 *pUnk = same_object;
3087 LIBTEST_API int STDCALL
3088 mono_test_marshal_com_object_destroy(MonoComObject *pUnk)
3090 int ref = --(pUnk->m_ref);
3097 LIBTEST_API int STDCALL
3098 mono_test_marshal_com_object_ref_count(MonoComObject *pUnk)
3103 LIBTEST_API int STDCALL
3104 mono_test_marshal_ccw_itest (MonoComObject *pUnk)
3107 MonoComObject* pTest;
3112 hr = pUnk->vtbl->SByteIn (pUnk, -100);
3115 hr = pUnk->vtbl->ByteIn (pUnk, 100);
3118 hr = pUnk->vtbl->ShortIn (pUnk, -100);
3121 hr = pUnk->vtbl->UShortIn (pUnk, 100);
3124 hr = pUnk->vtbl->IntIn (pUnk, -100);
3127 hr = pUnk->vtbl->UIntIn (pUnk, 100);
3130 hr = pUnk->vtbl->LongIn (pUnk, -100);
3133 hr = pUnk->vtbl->ULongIn (pUnk, 100);
3136 hr = pUnk->vtbl->FloatIn (pUnk, 3.14f);
3139 hr = pUnk->vtbl->DoubleIn (pUnk, 3.14);
3142 hr = pUnk->vtbl->ITestIn (pUnk, pUnk);
3145 hr = pUnk->vtbl->ITestOut (pUnk, &pTest);
3153 * mono_method_get_unmanaged_thunk tests
3156 #if defined(__GNUC__) && ((defined(__i386__) && (defined(__linux__) || defined (__APPLE__)) || defined (__FreeBSD__)) || (defined(__ppc__) && defined(__APPLE__)))
3157 #define ALIGN(size) __attribute__ ((aligned(size)))
3163 /* thunks.cs:TestStruct */
3164 typedef struct _TestStruct {
3166 double B ALIGN(8); /* align according to mono's struct layout */
3169 /* Searches for mono symbols in all loaded modules */
3171 lookup_mono_symbol (const char *symbol_name)
3174 if (g_module_symbol (g_module_open (NULL, G_MODULE_BIND_LAZY), symbol_name, &symbol))
3181 * test_method_thunk:
3183 * @test_id: the test number
3184 * @test_method_handle: MonoMethod* of the C# test method
3185 * @create_object_method_handle: MonoMethod* of thunks.cs:Test.CreateObject
3187 LIBTEST_API int STDCALL
3188 test_method_thunk (int test_id, gpointer test_method_handle, gpointer create_object_method_handle)
3190 gpointer (*mono_method_get_unmanaged_thunk)(gpointer)
3191 = lookup_mono_symbol ("mono_method_get_unmanaged_thunk");
3193 gpointer (*mono_string_new_wrapper)(const char *)
3194 = lookup_mono_symbol ("mono_string_new_wrapper");
3196 char* (*mono_string_to_utf8)(gpointer)
3197 = lookup_mono_symbol ("mono_string_to_utf8");
3199 gpointer (*mono_object_unbox)(gpointer)
3200 = lookup_mono_symbol ("mono_object_unbox");
3202 gpointer test_method, ex = NULL;
3203 gpointer (STDCALL *CreateObject)(gpointer*);
3206 if (!mono_method_get_unmanaged_thunk)
3209 test_method = mono_method_get_unmanaged_thunk (test_method_handle);
3213 CreateObject = mono_method_get_unmanaged_thunk (create_object_method_handle);
3221 /* thunks.cs:Test.Test0 */
3222 void (STDCALL *F)(gpointer*) = test_method;
3228 /* thunks.cs:Test.Test1 */
3229 int (STDCALL *F)(gpointer*) = test_method;
3236 /* thunks.cs:Test.Test2 */
3237 gpointer (STDCALL *F)(gpointer, gpointer*) = test_method;
3238 gpointer str = mono_string_new_wrapper ("foo");
3239 if (str != F (str, &ex))
3245 /* thunks.cs:Test.Test3 */
3246 gpointer (STDCALL *F)(gpointer, gpointer, gpointer*);
3251 obj = CreateObject (&ex);
3252 str = mono_string_new_wrapper ("bar");
3254 if (str != F (obj, str, &ex))
3260 /* thunks.cs:Test.Test4 */
3261 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3266 obj = CreateObject (&ex);
3267 str = mono_string_new_wrapper ("bar");
3269 if (42 != F (obj, str, 42, &ex))
3276 /* thunks.cs:Test.Test5 */
3277 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3282 obj = CreateObject (&ex);
3283 str = mono_string_new_wrapper ("bar");
3285 F (obj, str, 42, &ex);
3293 /* thunks.cs:Test.Test6 */
3294 int (STDCALL *F)(gpointer, guint8, gint16, gint32, gint64, float, double,
3295 gpointer, gpointer*);
3297 gpointer str = mono_string_new_wrapper ("Test6");
3301 obj = CreateObject (&ex);
3303 res = F (obj, 254, 32700, -245378, 6789600, 3.1415, 3.1415, str, &ex);
3314 /* thunks.cs:Test.Test7 */
3315 gint64 (STDCALL *F)(gpointer*) = test_method;
3316 if (F (&ex) != G_MAXINT64)
3322 /* thunks.cs:Test.Test8 */
3323 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3324 gpointer*, gpointer*);
3336 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3344 (fabs (a5 - 3.1415) < 0.001) &&
3345 (fabs (a6 - 3.1415) < 0.001) &&
3346 strcmp (mono_string_to_utf8 (a7), "Test8") == 0))
3353 /* thunks.cs:Test.Test9 */
3354 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3355 gpointer*, gpointer*);
3367 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3375 /* thunks.cs:Test.Test10 */
3376 void (STDCALL *F)(gpointer*, gpointer*);
3378 gpointer obj1, obj2;
3380 obj1 = obj2 = CreateObject (&ex);
3397 /* thunks.cs:TestStruct.Test0 */
3398 int (STDCALL *F)(gpointer*, gpointer*);
3404 obj = CreateObject (&ex);
3411 a1 = mono_object_unbox (obj);
3427 /* check whether the call was really by value */
3428 if (a1->A != 42 || a1->B != 3.1415)
3435 /* thunks.cs:TestStruct.Test1 */
3436 void (STDCALL *F)(gpointer, gpointer*);
3441 obj = CreateObject (&ex);
3448 a1 = mono_object_unbox (obj);
3461 if (!fabs (a1->B - 3.1415) < 0.001)
3468 /* thunks.cs:TestStruct.Test2 */
3469 gpointer (STDCALL *F)(gpointer*);
3483 a1 = mono_object_unbox (obj);
3488 if (!fabs (a1->B - 3.1415) < 0.001)
3495 /* thunks.cs:TestStruct.Test3 */
3496 void (STDCALL *F)(gpointer, gpointer*);
3501 obj = CreateObject (&ex);
3508 a1 = mono_object_unbox (obj);
3544 LIBTEST_API int STDCALL
3545 mono_test_Winx64_struct1_in (winx64_struct1 var)
3558 LIBTEST_API int STDCALL
3559 mono_test_Winx64_struct2_in (winx64_struct2 var)
3576 LIBTEST_API int STDCALL
3577 mono_test_Winx64_struct3_in (winx64_struct3 var)
3583 if (var.c != 0x1234)
3596 LIBTEST_API int STDCALL
3597 mono_test_Winx64_struct4_in (winx64_struct4 var)
3603 if (var.c != 0x1234)
3605 if (var.d != 0x87654321)
3617 LIBTEST_API int STDCALL
3618 mono_test_Winx64_struct5_in (winx64_struct5 var)
3636 LIBTEST_API int STDCALL
3637 mono_test_Winx64_struct6_in (winx64_struct6 var)
3648 LIBTEST_API int STDCALL
3649 mono_test_Winx64_structs_in1 (winx64_struct1 var1,
3650 winx64_struct2 var2,
3651 winx64_struct3 var3,
3652 winx64_struct4 var4)
3666 if (var3.c != 0x1234)
3673 if (var4.c != 0x1234)
3675 if (var4.d != 0x87654321)
3680 LIBTEST_API int STDCALL
3681 mono_test_Winx64_structs_in2 (winx64_struct1 var1,
3682 winx64_struct1 var2,
3683 winx64_struct1 var3,
3684 winx64_struct1 var4,
3685 winx64_struct1 var5)
3701 LIBTEST_API int STDCALL
3702 mono_test_Winx64_structs_in3 (winx64_struct1 var1,
3703 winx64_struct5 var2,
3704 winx64_struct1 var3,
3705 winx64_struct5 var4,
3706 winx64_struct1 var5,
3707 winx64_struct5 var6)
3742 LIBTEST_API winx64_struct1 STDCALL
3743 mono_test_Winx64_struct1_ret (void)
3750 LIBTEST_API winx64_struct2 STDCALL
3751 mono_test_Winx64_struct2_ret (void)
3759 LIBTEST_API winx64_struct3 STDCALL
3760 mono_test_Winx64_struct3_ret (void)
3769 LIBTEST_API winx64_struct4 STDCALL
3770 mono_test_Winx64_struct4_ret (void)
3780 LIBTEST_API winx64_struct5 STDCALL
3781 mono_test_Winx64_struct5_ret (void)
3790 LIBTEST_API winx64_struct1 STDCALL
3791 mono_test_Winx64_struct1_ret_5_args (char a, char b, char c, char d, char e)
3794 ret.a = a + b + c + d + e;
3798 LIBTEST_API winx64_struct5 STDCALL
3799 mono_test_Winx64_struct5_ret6_args (char a, char b, char c, char d, char e)
3812 } winx64_floatStruct;
3814 LIBTEST_API int STDCALL
3815 mono_test_Winx64_floatStruct (winx64_floatStruct a)
3817 if (a.a > 5.6 || a.a < 5.4)
3820 if (a.b > 9.6 || a.b < 9.4)
3829 } winx64_doubleStruct;
3831 LIBTEST_API int STDCALL
3832 mono_test_Winx64_doubleStruct (winx64_doubleStruct a)
3834 if (a.a > 5.6 || a.a < 5.4)
3840 typedef int (STDCALL *managed_struct1_delegate) (winx64_struct1 a);
3842 LIBTEST_API int STDCALL
3843 mono_test_managed_Winx64_struct1_in(managed_struct1_delegate func)
3850 typedef int (STDCALL *managed_struct5_delegate) (winx64_struct5 a);
3852 LIBTEST_API int STDCALL
3853 mono_test_managed_Winx64_struct5_in(managed_struct5_delegate func)
3862 typedef int (STDCALL *managed_struct1_struct5_delegate) (winx64_struct1 a, winx64_struct5 b,
3863 winx64_struct1 c, winx64_struct5 d,
3864 winx64_struct1 e, winx64_struct5 f);
3866 LIBTEST_API int STDCALL
3867 mono_test_managed_Winx64_struct1_struct5_in(managed_struct1_struct5_delegate func)
3869 winx64_struct1 a, c, e;
3870 winx64_struct5 b, d, f;
3872 b.a = 2; b.b = 3; b.c = 4;
3874 d.a = 6; d.b = 7; d.c = 8;
3876 f.a = 10; f.b = 11; f.c = 12;
3878 return func (a, b, c, d, e, f);
3881 typedef winx64_struct1 (STDCALL *managed_struct1_ret_delegate) (void);
3883 LIBTEST_API int STDCALL
3884 mono_test_Winx64_struct1_ret_managed (managed_struct1_ret_delegate func)
3896 typedef winx64_struct5 (STDCALL *managed_struct5_ret_delegate) (void);
3898 LIBTEST_API int STDCALL
3899 mono_test_Winx64_struct5_ret_managed (managed_struct5_ret_delegate func)
3915 LIBTEST_API int STDCALL
3916 mono_test_marshal_bool_in (int arg, unsigned int expected, unsigned int bDefaultMarsh, unsigned int bBoolCustMarsh,
3917 char bI1CustMarsh, unsigned char bU1CustMarsh, unsigned short bVBCustMarsh)
3921 if (bDefaultMarsh != expected)
3925 if (bBoolCustMarsh != expected)
3929 if (bI1CustMarsh != expected)
3933 if (bU1CustMarsh != expected)
3937 if (bVBCustMarsh != expected)
3946 LIBTEST_API int STDCALL
3947 mono_test_marshal_bool_out (int arg, unsigned int testVal, unsigned int* bDefaultMarsh, unsigned int* bBoolCustMarsh,
3948 char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh)
3954 *bDefaultMarsh = testVal;
3957 if (!bBoolCustMarsh)
3959 *bBoolCustMarsh = testVal;
3964 *bI1CustMarsh = (char)testVal;
3969 *bU1CustMarsh = (unsigned char)testVal;
3974 *bVBCustMarsh = (unsigned short)testVal;
3982 LIBTEST_API int STDCALL
3983 mono_test_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
3984 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh,
3985 unsigned short* bVBCustMarsh)
3991 if (*bDefaultMarsh != expected)
3993 *bDefaultMarsh = testVal;
3996 if (!bBoolCustMarsh)
3998 if (*bBoolCustMarsh != expected)
4000 *bBoolCustMarsh = testVal;
4005 if (*bI1CustMarsh != expected)
4007 *bI1CustMarsh = (char)testVal;
4012 if (*bU1CustMarsh != expected)
4014 *bU1CustMarsh = (unsigned char)testVal;
4019 if (*bVBCustMarsh != expected)
4021 *bVBCustMarsh = (unsigned short)testVal;
4030 typedef int (STDCALL *MarshalBoolInDelegate) (int arg, unsigned int expected, unsigned int bDefaultMarsh,
4031 unsigned int bBoolCustMarsh, char bI1CustMarsh, unsigned char bU1CustMarsh, unsigned short bVBCustMarsh);
4033 LIBTEST_API int STDCALL
4034 mono_test_managed_marshal_bool_in (int arg, unsigned int expected, unsigned int testVal, MarshalBoolInDelegate pfcn)
4041 return pfcn (arg, expected, testVal, 0, 0, 0, 0);
4043 return pfcn (arg, expected, 0, testVal, 0, 0, 0);
4045 return pfcn (arg, expected, 0, 0, testVal, 0, 0);
4047 return pfcn (arg, expected, 0, 0, 0, testVal, 0);
4049 return pfcn (arg, expected, 0, 0, 0, 0, testVal);
4057 typedef int (STDCALL *MarshalBoolOutDelegate) (int arg, unsigned int expected, unsigned int* bDefaultMarsh,
4058 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4060 LIBTEST_API int STDCALL
4061 mono_test_managed_marshal_bool_out (int arg, unsigned int expected, unsigned int testVal, MarshalBoolOutDelegate pfcn)
4064 unsigned int lDefaultMarsh, lBoolCustMarsh;
4065 char lI1CustMarsh = 0;
4066 unsigned char lU1CustMarsh = 0;
4067 unsigned short lVBCustMarsh = 0;
4068 lDefaultMarsh = lBoolCustMarsh = 0;
4075 unsigned int ltVal = 0;
4076 ret = pfcn (arg, testVal, <Val, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4078 return 0x0100 + ret;
4079 if (expected != ltVal)
4084 unsigned int ltVal = 0;
4085 ret = pfcn (arg, testVal, &lDefaultMarsh, <Val, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4087 return 0x0300 + ret;
4088 if (expected != ltVal)
4094 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, <Val, &lU1CustMarsh, &lVBCustMarsh);
4096 return 0x0500 + ret;
4097 if (expected != ltVal)
4102 unsigned char ltVal = 0;
4103 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <Val, &lVBCustMarsh);
4105 return 0x0700 + ret;
4106 if (expected != ltVal)
4111 unsigned short ltVal = 0;
4112 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <Val);
4114 return 0x0900 + ret;
4115 if (expected != ltVal)
4126 typedef int (STDCALL *MarshalBoolRefDelegate) (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4127 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4129 LIBTEST_API int STDCALL
4130 mono_test_managed_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int outExpected,
4131 unsigned int outTestVal, MarshalBoolRefDelegate pfcn)
4134 unsigned int lDefaultMarsh, lBoolCustMarsh;
4135 char lI1CustMarsh = 0;
4136 unsigned char lU1CustMarsh = 0;
4137 unsigned short lVBCustMarsh = 0;
4138 lDefaultMarsh = lBoolCustMarsh = 0;
4146 unsigned int ltestVal = testVal;
4147 ret = pfcn (arg, expected, outTestVal, <estVal, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4149 return 0x0100 + ret;
4150 if (outExpected != ltestVal)
4156 unsigned int ltestVal = testVal;
4157 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, <estVal, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4159 return 0x0300 + ret;
4160 if (outExpected != ltestVal)
4166 char ltestVal = testVal;
4167 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, <estVal, &lU1CustMarsh, &lVBCustMarsh);
4169 return 0x0500 + ret;
4170 if (outExpected != ltestVal)
4176 unsigned char ltestVal = testVal;
4177 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, <estVal, &lVBCustMarsh);
4179 return 0x0700 + ret;
4180 if (outExpected != ltestVal)
4186 unsigned short ltestVal = testVal;
4187 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, <estVal);
4189 return 0x0900 + ret;
4190 if (outExpected != ltestVal)
4203 LIBTEST_API int STDCALL
4204 mono_test_marshal_variant_out_safearray_1dim_vt_bstr_empty (SAFEARRAY** safearray)
4206 /* Create an empty one-dimensional array of variants */
4208 SAFEARRAYBOUND dimensions [1];
4210 dimensions [0].lLbound = 0;
4211 dimensions [0].cElements = 0;
4213 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4218 LIBTEST_API int STDCALL
4219 mono_test_marshal_variant_out_safearray_1dim_vt_bstr (SAFEARRAY** safearray)
4221 /* Create a one-dimensional array of 10 variants filled with "0" to "9" */
4223 SAFEARRAYBOUND dimensions [1];
4229 dimensions [0].lLbound = 0;
4230 dimensions [0].cElements = 10;
4232 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4233 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4235 VariantInit (&vOut);
4237 _ltoa (i,buffer,10);
4238 vOut.bstrVal= marshal_bstr_alloc (buffer);
4240 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4241 VariantClear (&vOut);
4242 SafeArrayDestroy (pSA);
4245 VariantClear (&vOut);
4251 LIBTEST_API int STDCALL
4252 mono_test_marshal_variant_out_safearray_2dim_vt_int (SAFEARRAY** safearray)
4254 /* Create a two-dimensional array of 4x3 variants filled with 11, 12, 13, etc. */
4256 SAFEARRAYBOUND dimensions [2];
4261 dimensions [0].lLbound = 0;
4262 dimensions [0].cElements = 4;
4263 dimensions [1].lLbound = 0;
4264 dimensions [1].cElements = 3;
4266 pSA= SafeArrayCreate(VT_VARIANT, 2, dimensions);
4267 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4268 for (j= dimensions [1].lLbound; j< (dimensions [1].cElements + dimensions [1].lLbound); j++) {
4270 VariantInit (&vOut);
4272 vOut.intVal = (i+1)*10+(j+1);
4275 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4276 VariantClear (&vOut);
4277 SafeArrayDestroy (pSA);
4280 VariantClear (&vOut); // does a deep destroy of source VARIANT
4287 LIBTEST_API int STDCALL
4288 mono_test_marshal_variant_out_safearray_4dim_vt_int (SAFEARRAY** safearray)
4290 /* Create a four-dimensional array of 10x3x6x7 variants filled with their indices */
4291 /* Also use non zero lower bounds */
4293 SAFEARRAYBOUND dimensions [4];
4298 dimensions [0].lLbound = 15;
4299 dimensions [0].cElements = 10;
4300 dimensions [1].lLbound = 20;
4301 dimensions [1].cElements = 3;
4302 dimensions [2].lLbound = 5;
4303 dimensions [2].cElements = 6;
4304 dimensions [3].lLbound = 12;
4305 dimensions [3].cElements = 7;
4307 pSA= SafeArrayCreate (VT_VARIANT, 4, dimensions);
4309 SafeArrayAccessData (pSA, (void **)&pData);
4311 for (i= 0; i< 10*3*6*7; i++) {
4312 VariantInit(&pData [i]);
4313 pData [i].vt = VT_I4;
4314 pData [i].intVal = i;
4316 SafeArrayUnaccessData(pSA);