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
);
56 static char* marshal_strdup (const char *str
)
66 buf
= (char *) CoTaskMemAlloc (len
+ 1);
67 return strcpy (buf
, str
);
69 return g_strdup (str
);
73 static gunichar2
* marshal_bstr_alloc(const gchar
* str
)
76 gunichar2
* ret
= NULL
;
77 gunichar2
* temp
= NULL
;
78 temp
= g_utf8_to_utf16 (str
, -1, NULL
, NULL
, NULL
);
79 ret
= SysAllocString (temp
);
84 int slen
= strlen (str
);
86 /* allocate len + 1 utf16 characters plus 4 byte integer for length*/
87 ret
= g_malloc ((slen
+ 1) * sizeof(gunichar2
) + sizeof(guint32
));
90 temp
= g_utf8_to_utf16 (str
, -1, NULL
, NULL
, NULL
);
91 memcpy (ret
+ sizeof(guint32
), temp
, slen
* sizeof(gunichar2
));
92 * ((guint32
*) ret
) = slen
* sizeof(gunichar2
);
93 ret
[4 + slen
* sizeof(gunichar2
)] = 0;
94 ret
[5 + slen
* sizeof(gunichar2
)] = 0;
96 return (gunichar2
*)(ret
+ 4);
100 LIBTEST_API
int STDCALL
101 mono_cominterop_is_supported (void)
103 #if defined(TARGET_X86) || defined(TARGET_AMD64)
109 LIBTEST_API
unsigned short* STDCALL
110 test_lpwstr_marshal (unsigned short* chars
, long length
)
115 res
= marshal_alloc (2 * (length
+ 1));
117 // printf("test_lpwstr_marshal()\n");
119 while ( i
< length
) {
120 // printf("X|%u|\n", chars[i]);
131 LIBTEST_API
void STDCALL
132 test_lpwstr_marshal_out (unsigned short** chars
)
135 const char abc
[] = "ABC";
136 glong len
= strlen(abc
);
138 *chars
= marshal_alloc (2 * (len
+ 1));
141 (*chars
) [i
] = abc
[i
];
154 LIBTEST_API
int STDCALL
155 mono_union_test_1 (union_test_1_type u1
) {
156 // printf ("Got values %d %d %d\n", u1.b, u1.a, u1.c);
157 return u1
.a
+ u1
.b
+ u1
.c
;
160 LIBTEST_API
int STDCALL
161 mono_return_int (int a
) {
162 // printf ("Got value %d\n", a);
166 LIBTEST_API
float STDCALL
167 mono_test_marshal_pass_return_float (float f
) {
176 LIBTEST_API
int STDCALL
177 mono_return_int_ss (struct ss a
) {
178 // printf ("Got value %d\n", a.i);
182 LIBTEST_API
struct ss STDCALL
183 mono_return_ss (struct ss a
) {
184 // printf ("Got value %d\n", a.i);
194 LIBTEST_API
struct sc1 STDCALL
195 mono_return_sc1 (struct sc1 a
) {
196 // printf ("Got value %d\n", a.c[0]);
207 LIBTEST_API
struct sc3 STDCALL
208 mono_return_sc3 (struct sc3 a
) {
209 // printf ("Got values %d %d %d\n", a.c[0], a.c[1], a.c[2]);
221 LIBTEST_API
struct sc5 STDCALL
222 mono_return_sc5 (struct sc5 a
) {
223 // printf ("Got values %d %d %d %d %d\n", a.c[0], a.c[1], a.c[2], a.c[3], a.c[4]);
238 LIBTEST_API
int STDCALL
239 mono_return_int_su (union su a
) {
240 // printf ("Got value %d\n", a.i1);
244 LIBTEST_API
int STDCALL
245 mono_test_many_int_arguments (int a
, int b
, int c
, int d
, int e
,
246 int f
, int g
, int h
, int i
, int j
);
247 LIBTEST_API
short STDCALL
248 mono_test_many_short_arguments (short a
, short b
, short c
, short d
, short e
,
249 short f
, short g
, short h
, short i
, short j
);
250 LIBTEST_API
char STDCALL
251 mono_test_many_char_arguments (char a
, char b
, char c
, char d
, char e
,
252 char f
, char g
, char h
, char i
, char j
);
254 LIBTEST_API
int STDCALL
255 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
)
257 return a
+ b
+ c
+ d
+ e
+ f
+ g
+ h
+ i
+ j
;
260 LIBTEST_API
short STDCALL
261 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
)
263 return a
+ b
+ c
+ d
+ e
+ f
+ g
+ h
+ i
+ j
;
266 LIBTEST_API
char STDCALL
267 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
)
269 return a
+ b
+ c
+ d
+ e
+ f
+ g
+ h
+ i
+ j
;
272 LIBTEST_API
float STDCALL
273 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
)
275 return a
+ b
+ c
+ d
+ e
+ f
+ g
+ h
+ i
+ j
;
278 LIBTEST_API
double STDCALL
279 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
)
281 return a
+ b
+ c
+ d
+ e
+ f
+ g
+ h
+ i
+ j
;
284 LIBTEST_API
double STDCALL
285 mono_test_split_double_arguments (double a
, double b
, float c
, double d
, double e
)
287 return a
+ b
+ c
+ d
+ e
;
290 LIBTEST_API
int STDCALL
291 mono_test_puts_static (char *s
)
293 // printf ("TEST %s\n", s);
297 typedef int (STDCALL
*SimpleDelegate3
) (int a
, int b
);
299 LIBTEST_API
int STDCALL
300 mono_invoke_delegate (SimpleDelegate3 delegate
)
304 // printf ("start invoke %p\n", delegate);
306 res
= delegate (2, 3);
308 // printf ("end invoke\n");
313 LIBTEST_API
int STDCALL
314 mono_invoke_simple_delegate (SimpleDelegate d
)
319 LIBTEST_API
int STDCALL
320 mono_test_marshal_char (short a1
)
328 LIBTEST_API
void STDCALL
329 mono_test_marshal_char_array (gunichar2
*s
)
331 const char m
[] = "abcdef";
335 s2
= g_utf8_to_utf16 (m
, -1, NULL
, &len
, NULL
);
343 LIBTEST_API
int STDCALL
344 mono_test_empty_pinvoke (int i
)
349 LIBTEST_API
int STDCALL
350 mono_test_marshal_bool_byref (int a
, int *b
, int c
)
359 LIBTEST_API
int STDCALL
360 mono_test_marshal_bool_in_as_I1_U1 (char bTrue
, char bFalse
)
369 LIBTEST_API
int STDCALL
370 mono_test_marshal_bool_out_as_I1_U1 (char* bTrue
, char* bFalse
)
372 if (!bTrue
|| !bFalse
)
381 LIBTEST_API
int STDCALL
382 mono_test_marshal_bool_ref_as_I1_U1 (char* bTrue
, char* bFalse
)
384 if (!bTrue
|| !bFalse
)
398 LIBTEST_API
int STDCALL
399 mono_test_marshal_array (int *a1
)
403 for (i
= 0; i
< 50; i
++)
409 LIBTEST_API
int STDCALL
410 mono_test_marshal_inout_array (int *a1
)
414 for (i
= 0; i
< 50; i
++) {
416 a1
[i
] = 50 - a1
[i
];
422 LIBTEST_API
int /* cdecl */
423 mono_test_marshal_inout_array_cdecl (int *a1
)
425 return mono_test_marshal_inout_array (a1
);
428 LIBTEST_API
int STDCALL
429 mono_test_marshal_out_array (int *a1
)
433 for (i
= 0; i
< 50; i
++) {
440 LIBTEST_API
int STDCALL
441 mono_test_marshal_inout_nonblittable_array (gunichar2
*a1
)
445 for (i
= 0; i
< 10; i
++) {
465 LIBTEST_API simplestruct STDCALL
466 mono_test_return_vtype (int i
)
469 static gunichar2 test2
[] = { 'T', 'E', 'S', 'T', '2', 0 };
480 LIBTEST_API
void STDCALL
481 mono_test_delegate_struct (void)
483 // printf ("TEST\n");
486 typedef char* (STDCALL
*ReturnStringDelegate
) (const char *s
);
488 LIBTEST_API
char * STDCALL
489 mono_test_return_string (ReturnStringDelegate func
)
493 // printf ("mono_test_return_string\n");
498 // printf ("got string: %s\n", res);
499 return marshal_strdup ("12345");
502 typedef int (STDCALL
*RefVTypeDelegate
) (int a
, simplestruct
*ss
, int b
);
504 LIBTEST_API
int STDCALL
505 mono_test_ref_vtype (int a
, simplestruct
*ss
, int b
, RefVTypeDelegate func
)
507 if (a
== 1 && b
== 2 && ss
->a
== 0 && ss
->b
== 1 && ss
->c
== 0 &&
508 !strcmp (ss
->d
, "TEST1")) {
514 return func (a
, ss
, b
);
520 typedef int (STDCALL
*OutVTypeDelegate
) (int a
, simplestruct
*ss
, int b
);
522 LIBTEST_API
int STDCALL
523 mono_test_marshal_out_struct (int a
, simplestruct
*ss
, int b
, OutVTypeDelegate func
)
525 /* Check that the input pointer is ignored */
526 ss
->d
= (gpointer
)0x12345678;
530 if (ss
->a
&& ss
->b
&& ss
->c
&& !strcmp (ss
->d
, "TEST3"))
538 SimpleDelegate func
, func2
, func3
;
541 LIBTEST_API DelegateStruct STDCALL
542 mono_test_marshal_delegate_struct (DelegateStruct ds
)
546 res
.a
= ds
.func (ds
.a
) + ds
.func2 (ds
.a
) + (ds
.func3
== NULL
? 0 : 1);
548 res
.func2
= ds
.func2
;
554 LIBTEST_API
int STDCALL
555 mono_test_marshal_struct (simplestruct ss
)
557 if (ss
.a
== 0 && ss
.b
== 1 && ss
.c
== 0 &&
558 !strcmp (ss
.d
, "TEST"))
564 LIBTEST_API
int STDCALL
565 mono_test_marshal_byref_struct (simplestruct
*ss
, int a
, int b
, int c
, char *d
)
567 gboolean res
= (ss
->a
== a
&& ss
->b
== b
&& ss
->c
== c
&& strcmp (ss
->d
, d
) == 0);
569 marshal_free ((char*)ss
->d
);
574 ss
->d
= marshal_strdup ("DEF");
590 LIBTEST_API
int STDCALL
591 mono_test_marshal_struct2 (simplestruct2 ss
)
593 if (ss
.a
== 0 && ss
.b
== 1 && ss
.c
== 0 &&
594 !strcmp (ss
.d
, "TEST") &&
595 ss
.e
== 99 && ss
.f
== 1.5 && ss
.g
== 42 && ss
.h
== (guint64
)123)
601 /* on HP some of the struct should be on the stack and not in registers */
602 LIBTEST_API
int STDCALL
603 mono_test_marshal_struct2_2 (int i
, int j
, int k
, simplestruct2 ss
)
605 if (i
!= 10 || j
!= 11 || k
!= 12)
607 if (ss
.a
== 0 && ss
.b
== 1 && ss
.c
== 0 &&
608 !strcmp (ss
.d
, "TEST") &&
609 ss
.e
== 99 && ss
.f
== 1.5 && ss
.g
== 42 && ss
.h
== (guint64
)123)
615 LIBTEST_API
int STDCALL
616 mono_test_marshal_lpstruct (simplestruct
*ss
)
618 if (ss
->a
== 0 && ss
->b
== 1 && ss
->c
== 0 &&
619 !strcmp (ss
->d
, "TEST"))
625 LIBTEST_API
int STDCALL
626 mono_test_marshal_lpstruct_blittable (point
*p
)
628 if (p
->x
== 1.0 && p
->y
== 2.0)
634 LIBTEST_API
int STDCALL
635 mono_test_marshal_struct_array (simplestruct2
*ss
)
637 if (! (ss
[0].a
== 0 && ss
[0].b
== 1 && ss
[0].c
== 0 &&
638 !strcmp (ss
[0].d
, "TEST") &&
639 ss
[0].e
== 99 && ss
[0].f
== 1.5 && ss
[0].g
== 42 && ss
[0].h
== (guint64
)123))
642 if (! (ss
[1].a
== 0 && ss
[1].b
== 0 && ss
[1].c
== 0 &&
643 !strcmp (ss
[1].d
, "TEST2") &&
644 ss
[1].e
== 100 && ss
[1].f
== 2.5 && ss
[1].g
== 43 && ss
[1].h
== (guint64
)124))
650 typedef struct long_align_struct
{
656 LIBTEST_API
int STDCALL
657 mono_test_marshal_long_align_struct_array (long_align_struct
*ss
)
659 return ss
[0].a
+ ss
[0].b
+ ss
[0].c
+ ss
[1].a
+ ss
[1].b
+ ss
[1].c
;
662 LIBTEST_API simplestruct2
* STDCALL
663 mono_test_marshal_class (int i
, int j
, int k
, simplestruct2
*ss
, int l
)
670 if (i
!= 10 || j
!= 11 || k
!= 12 || l
!= 14)
672 if (! (ss
->a
== 0 && ss
->b
== 1 && ss
->c
== 0 &&
673 !strcmp (ss
->d
, "TEST") &&
674 ss
->e
== 99 && ss
->f
== 1.5 && ss
->g
== 42 && ss
->h
== (guint64
)123))
677 res
= g_new0 (simplestruct2
, 1);
678 memcpy (res
, ss
, sizeof (simplestruct2
));
679 res
->d
= marshal_strdup ("TEST");
683 LIBTEST_API
int STDCALL
684 mono_test_marshal_byref_class (simplestruct2
**ssp
)
686 simplestruct2
*ss
= *ssp
;
689 if (! (ss
->a
== 0 && ss
->b
== 1 && ss
->c
== 0 &&
690 !strcmp (ss
->d
, "TEST") &&
691 ss
->e
== 99 && ss
->f
== 1.5 && ss
->g
== 42 && ss
->h
== (guint64
)123))
694 res
= g_new0 (simplestruct2
, 1);
695 memcpy (res
, ss
, sizeof (simplestruct2
));
696 res
->d
= marshal_strdup ("TEST-RES");
708 /* Yes, this is correct, we are only trying to determine the value of the stack here */
713 LIBTEST_API
int STDCALL
714 reliable_delegate (int a
)
720 * Checks whether get_sp() works as expected. It doesn't work with gcc-2.95.3 on linux.
723 is_get_sp_reliable (void)
727 reliable_delegate(1);
729 reliable_delegate(1);
734 LIBTEST_API
int STDCALL
735 mono_test_marshal_delegate (SimpleDelegate delegate
)
739 /* Check that the delegate wrapper is stdcall */
744 if (is_get_sp_reliable())
745 g_assert (sp1
== sp2
);
750 static int STDCALL
inc_cb (int i
)
755 LIBTEST_API
int STDCALL
756 mono_test_marshal_out_delegate (SimpleDelegate
*delegate
)
763 LIBTEST_API SimpleDelegate STDCALL
764 mono_test_marshal_return_delegate (SimpleDelegate delegate
)
770 return_plus_one (int i
)
775 LIBTEST_API SimpleDelegate STDCALL
776 mono_test_marshal_return_delegate_2 (void)
778 return return_plus_one
;
781 typedef simplestruct (STDCALL
*SimpleDelegate2
) (simplestruct ss
);
784 is_utf16_equals (gunichar2
*s1
, const char *s2
)
789 s
= g_utf16_to_utf8 (s1
, -1, NULL
, NULL
, NULL
);
790 res
= strcmp (s
, s2
);
796 LIBTEST_API
int STDCALL
797 mono_test_marshal_delegate2 (SimpleDelegate2 delegate
)
799 simplestruct ss
, res
;
805 ss
.d2
= g_utf8_to_utf16 ("TEST2", -1, NULL
, NULL
, NULL
);
808 if (! (res
.a
&& !res
.b
&& res
.c
&& !strcmp (res
.d
, "TEST-RES") && is_utf16_equals (res
.d2
, "TEST2-RES")))
814 typedef simplestruct
* (STDCALL
*SimpleDelegate4
) (simplestruct
*ss
);
816 LIBTEST_API
int STDCALL
817 mono_test_marshal_delegate4 (SimpleDelegate4 delegate
)
828 res
= delegate (&ss
);
832 /* Check return value */
833 if (! (!res
->a
&& res
->b
&& !res
->c
&& !strcmp (res
->d
, "TEST")))
836 /* Check NULL argument and NULL result */
837 res
= delegate (NULL
);
844 typedef int (STDCALL
*SimpleDelegate5
) (simplestruct
**ss
);
846 LIBTEST_API
int STDCALL
847 mono_test_marshal_delegate5 (SimpleDelegate5 delegate
)
860 res
= delegate (&ptr
);
864 if (!(ptr
->a
&& !ptr
->b
&& ptr
->c
&& !strcmp (ptr
->d
, "RES")))
870 LIBTEST_API
int STDCALL
871 mono_test_marshal_delegate6 (SimpleDelegate5 delegate
)
875 res
= delegate (NULL
);
880 typedef int (STDCALL
*SimpleDelegate7
) (simplestruct
**ss
);
882 LIBTEST_API
int STDCALL
883 mono_test_marshal_delegate7 (SimpleDelegate7 delegate
)
888 /* Check that the input pointer is ignored */
889 ptr
= (gpointer
)0x12345678;
891 res
= delegate (&ptr
);
895 if (!(ptr
->a
&& !ptr
->b
&& ptr
->c
&& !strcmp (ptr
->d
, "RES")))
901 typedef int (STDCALL
*InOutByvalClassDelegate
) (simplestruct
*ss
);
903 LIBTEST_API
int STDCALL
904 mono_test_marshal_inout_byval_class_delegate (InOutByvalClassDelegate delegate
)
912 ss
.d
= g_strdup_printf ("%s", "FOO");
914 res
= delegate (&ss
);
918 if (!(ss
.a
&& !ss
.b
&& ss
.c
&& !strcmp (ss
.d
, "RES")))
924 typedef int (STDCALL
*SimpleDelegate8
) (gunichar2
*s
);
926 LIBTEST_API
int STDCALL
927 mono_test_marshal_delegate8 (SimpleDelegate8 delegate
, gunichar2
*s
)
932 typedef int (STDCALL
*return_int_fnt
) (int i
);
933 typedef int (STDCALL
*SimpleDelegate9
) (return_int_fnt d
);
935 LIBTEST_API
int STDCALL
936 mono_test_marshal_delegate9 (SimpleDelegate9 delegate
, gpointer ftn
)
938 return delegate (ftn
);
947 LIBTEST_API
int STDCALL
948 mono_test_marshal_delegate10 (SimpleDelegate9 delegate
)
950 return delegate (return_self
);
953 typedef int (STDCALL
*PrimitiveByrefDelegate
) (int *i
);
955 LIBTEST_API
int STDCALL
956 mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate delegate
)
960 int res
= delegate (&i
);
970 typedef int (STDCALL
*return_int_delegate
) (int i
);
972 typedef return_int_delegate (STDCALL
*ReturnDelegateDelegate
) (void);
974 LIBTEST_API
int STDCALL
975 mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d
)
980 LIBTEST_API
int STDCALL
981 mono_test_marshal_stringbuilder (char *s
, int n
)
983 const char m
[] = "This is my message. Isn't it nice?";
985 if (strcmp (s
, "ABCD") != 0)
992 LIBTEST_API
int STDCALL
993 mono_test_marshal_stringbuilder_default (char *s
, int n
)
995 const char m
[] = "This is my message. Isn't it nice?";
1002 LIBTEST_API
int STDCALL
1003 mono_test_marshal_stringbuilder_unicode (gunichar2
*s
, int n
)
1005 const char m
[] = "This is my message. Isn't it nice?";
1009 s2
= g_utf8_to_utf16 (m
, -1, NULL
, &len
, NULL
);
1011 len
= (len
* 2) + 2;
1014 memcpy (s
, s2
, len
);
1021 LIBTEST_API
void STDCALL
1022 mono_test_marshal_stringbuilder_out (char **s
)
1024 const char m
[] = "This is my message. Isn't it nice?";
1027 str
= marshal_alloc (strlen (m
) + 1);
1028 memcpy (str
, m
, strlen (m
) + 1);
1033 LIBTEST_API
int STDCALL
1034 mono_test_marshal_stringbuilder_out_unicode (gunichar2
**s
)
1036 const char m
[] = "This is my message. Isn't it nice?";
1040 s2
= g_utf8_to_utf16 (m
, -1, NULL
, &len
, NULL
);
1042 len
= (len
* 2) + 2;
1043 *s
= marshal_alloc (len
);
1044 memcpy (*s
, s2
, len
);
1057 LIBTEST_API
int STDCALL
1058 mono_test_marshal_empty_string_array (char **array
)
1060 return (array
== NULL
) ? 0 : 1;
1063 LIBTEST_API
int STDCALL
1064 mono_test_marshal_string_array (char **array
)
1066 if (strcmp (array
[0], "ABC"))
1068 if (strcmp (array
[1], "DEF"))
1071 if (array
[2] != NULL
)
1077 LIBTEST_API
int STDCALL
1078 mono_test_marshal_byref_string_array (char ***array
)
1083 if (strcmp ((*array
) [0], "Alpha"))
1085 if (strcmp ((*array
) [1], "Beta"))
1087 if (strcmp ((*array
) [2], "Gamma"))
1093 LIBTEST_API
int STDCALL
1094 mono_test_marshal_stringbuilder_array (char **array
)
1096 if (strcmp (array
[0], "ABC"))
1098 if (strcmp (array
[1], "DEF"))
1101 strcpy (array
[0], "DEF");
1102 strcpy (array
[1], "ABC");
1107 LIBTEST_API
int STDCALL
1108 mono_test_marshal_unicode_string_array (gunichar2
**array
, char **array2
)
1110 GError
*error
= NULL
;
1113 s
= g_utf16_to_utf8 (array
[0], -1, NULL
, NULL
, &error
);
1114 if (strcmp (s
, "ABC")) {
1121 s
= g_utf16_to_utf8 (array
[1], -1, NULL
, NULL
, &error
);
1122 if (strcmp (s
, "DEF")) {
1129 if (strcmp (array2
[0], "ABC"))
1132 if (strcmp (array2
[1], "DEF"))
1138 /* this does not work on Redhat gcc 2.96 */
1139 LIBTEST_API
int STDCALL
1140 mono_test_empty_struct (int a
, EmptyStruct es
, int b
)
1142 // printf ("mono_test_empty_struct %d %d\n", a, b);
1144 // Intel icc on ia64 passes 'es' in 2 registers
1145 #if defined(__ia64) && defined(__INTEL_COMPILER)
1148 if (a
== 1 && b
== 2)
1158 LIBTEST_API ByValStrStruct
* STDCALL
1159 mono_test_byvalstr_gen (void)
1161 ByValStrStruct
*ret
;
1163 ret
= malloc(sizeof(ByValStrStruct
));
1164 memset(ret
, 'a', sizeof(ByValStrStruct
)-1);
1165 ret
->a
[sizeof(ByValStrStruct
)-1] = 0;
1170 LIBTEST_API
int STDCALL
1171 mono_test_byvalstr_check (ByValStrStruct
* data
, char* correctString
)
1175 ret
= strcmp(data
->a
, correctString
);
1176 // printf ("T1: %s\n", data->a);
1177 // printf ("T2: %s\n", correctString);
1179 /* we need g_free because the allocation was performed by mono_test_byvalstr_gen */
1187 } ByValStrStruct_Unicode
;
1189 LIBTEST_API
int STDCALL
1190 mono_test_byvalstr_check_unicode (ByValStrStruct_Unicode
*ref
, int test
)
1192 if (ref
->flag
!= 0x1234abcd){
1193 printf ("overwritten data");
1197 if (test
== 1 || test
== 3){
1198 if (ref
->a
[0] != '1' ||
1199 ref
->a
[1] != '2' ||
1205 if (ref
->a
[0] != '1' ||
1213 LIBTEST_API
int STDCALL
1214 NameManglingAnsi (char *data
)
1216 return data
[0] + data
[1] + data
[2];
1219 LIBTEST_API
int STDCALL
1220 NameManglingAnsiA (char *data
)
1222 g_assert_not_reached ();
1225 LIBTEST_API
int STDCALL
1226 NameManglingAnsiW (char *data
)
1228 g_assert_not_reached ();
1231 LIBTEST_API
int STDCALL
1232 NameManglingAnsi2A (char *data
)
1234 return data
[0] + data
[1] + data
[2];
1237 LIBTEST_API
int STDCALL
1238 NameManglingAnsi2W (char *data
)
1240 g_assert_not_reached ();
1243 LIBTEST_API
int STDCALL
1244 NameManglingUnicode (char *data
)
1246 g_assert_not_reached ();
1249 LIBTEST_API
int STDCALL
1250 NameManglingUnicodeW (gunichar2
*data
)
1252 return data
[0] + data
[1] + data
[2];
1255 LIBTEST_API
int STDCALL
1256 NameManglingUnicode2 (gunichar2
*data
)
1258 return data
[0] + data
[1] + data
[2];
1261 LIBTEST_API
int STDCALL
1262 NameManglingAutoW (char *data
)
1265 return (data
[0] + data
[1] + data
[2]) == 131 ? 0 : 1;
1267 g_assert_not_reached ();
1271 LIBTEST_API
int STDCALL
1272 NameManglingAuto (char *data
)
1275 return (data
[0] + data
[1] + data
[2]) == 198 ? 0 : 1;
1277 g_assert_not_reached ();
1281 typedef int (STDCALL
*intcharFunc
)(const char*);
1283 LIBTEST_API
void STDCALL
1284 callFunction (intcharFunc f
)
1294 LIBTEST_API
int STDCALL
1295 class_marshal_test0 (SimpleObj
*obj1
)
1297 // printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
1299 if (strcmp(obj1
->str
, "T1"))
1307 LIBTEST_API
int STDCALL
1308 class_marshal_test4 (SimpleObj
*obj1
)
1316 LIBTEST_API
void STDCALL
1317 class_marshal_test1 (SimpleObj
**obj1
)
1319 SimpleObj
*res
= malloc (sizeof (SimpleObj
));
1321 res
->str
= marshal_strdup ("ABC");
1327 LIBTEST_API
int STDCALL
1328 class_marshal_test2 (SimpleObj
**obj1
)
1330 // printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
1332 if (strcmp((*obj1
)->str
, "ABC"))
1334 if ((*obj1
)->i
!= 5)
1340 LIBTEST_API
int STDCALL
1341 string_marshal_test0 (char *str
)
1343 if (strcmp (str
, "TEST0"))
1349 LIBTEST_API
void STDCALL
1350 string_marshal_test1 (const char **str
)
1352 *str
= marshal_strdup ("TEST1");
1355 LIBTEST_API
int STDCALL
1356 string_marshal_test2 (char **str
)
1358 // printf ("string_marshal_test2 %s\n", *str);
1360 if (strcmp (*str
, "TEST1"))
1366 LIBTEST_API
int STDCALL
1367 string_marshal_test3 (char *str
)
1380 LIBTEST_API BlittableClass
* STDCALL
1381 TestBlittableClass (BlittableClass
*vl
)
1383 BlittableClass
*res
;
1385 // printf ("TestBlittableClass %d %d\n", vl->a, vl->b);
1391 res
= g_new0 (BlittableClass
, 1);
1392 memcpy (res
, vl
, sizeof (BlittableClass
));
1394 res
= g_new0 (BlittableClass
, 1);
1402 typedef struct OSVERSIONINFO_STRUCT
1406 } OSVERSIONINFO_STRUCT
;
1408 LIBTEST_API
int STDCALL
1409 MyGetVersionEx (OSVERSIONINFO_STRUCT
*osvi
)
1412 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1417 return osvi
->a
+ osvi
->b
;
1420 LIBTEST_API
int STDCALL
1421 BugGetVersionEx (int a
, int b
, int c
, int d
, int e
, int f
, int g
, int h
, OSVERSIONINFO_STRUCT
*osvi
)
1424 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1429 return osvi
->a
+ osvi
->b
;
1432 LIBTEST_API
int STDCALL
1433 mono_test_marshal_point (point pt
)
1435 // printf("point %g %g\n", pt.x, pt.y);
1436 if (pt
.x
== 1.25 && pt
.y
== 3.5)
1447 LIBTEST_API
int STDCALL
1448 mono_test_marshal_mixed_point (mixed_point pt
)
1450 // printf("mixed point %d %g\n", pt.x, pt.y);
1451 if (pt
.x
== 5 && pt
.y
== 6.75)
1457 LIBTEST_API
int STDCALL
1458 mono_test_marshal_mixed_point_2 (mixed_point
*pt
)
1460 if (pt
->x
!= 5 || pt
->y
!= 6.75)
1469 LIBTEST_API
int STDCALL
1470 marshal_test_ref_bool(int i
, char *b1
, short *b2
, int *b3
)
1473 if (*b1
!= 0 && *b1
!= 1)
1475 if (*b2
!= 0 && *b2
!= -1) /* variant_bool */
1477 if (*b3
!= 0 && *b3
!= 1)
1479 if (i
== ((*b1
<< 2) | (-*b2
<< 1) | *b3
))
1491 short b2
; /* variant_bool */
1495 LIBTEST_API
int STDCALL
1496 marshal_test_bool_struct(struct BoolStruct
*s
)
1499 if (s
->b1
!= 0 && s
->b1
!= 1)
1501 if (s
->b2
!= 0 && s
->b2
!= -1)
1503 if (s
->b3
!= 0 && s
->b3
!= 1)
1505 if (s
->i
== ((s
->b1
<< 2) | (-s
->b2
<< 1) | s
->b3
))
1522 LIBTEST_API
int STDCALL
1523 mono_test_marshal_long_struct (LongStruct
*s
)
1525 return s
->i
+ s
->l
.l
;
1528 LIBTEST_API
void STDCALL
1529 mono_test_last_error (int err
)
1538 LIBTEST_API
int STDCALL
1539 mono_test_asany (void *ptr
, int what
)
1543 return (*(int*)ptr
== 5) ? 0 : 1;
1545 return strcmp (ptr
, "ABC") == 0 ? 0 : 1;
1547 simplestruct2 ss
= *(simplestruct2
*)ptr
;
1549 if (ss
.a
== 0 && ss
.b
== 1 && ss
.c
== 0 &&
1550 !strcmp (ss
.d
, "TEST") &&
1551 ss
.e
== 99 && ss
.f
== 1.5 && ss
.g
== 42 && ss
.h
== (guint64
)123)
1557 GError
*error
= NULL
;
1560 s
= g_utf16_to_utf8 (ptr
, -1, NULL
, NULL
, &error
);
1565 if (!strcmp (s
, "ABC")) {
1575 g_assert_not_reached ();
1589 LIBTEST_API
int STDCALL
1590 mono_test_marshal_asany_in (void* ptr
)
1592 AsAnyStruct
* asAny
= ptr
;
1593 int res
= asAny
->i
+ asAny
->j
+ asAny
->k
;
1598 LIBTEST_API
int STDCALL
1599 mono_test_marshal_asany_inout (void* ptr
)
1601 AsAnyStruct
* asAny
= ptr
;
1602 int res
= asAny
->i
+ asAny
->j
+ asAny
->k
;
1604 marshal_free (asAny
->s
);
1614 LIBTEST_API
int STDCALL
1615 mono_test_marshal_asany_out (void* ptr
)
1617 AsAnyStruct
* asAny
= ptr
;
1618 int res
= asAny
->i
+ asAny
->j
+ asAny
->k
;
1629 * AMD64 marshalling tests.
1632 typedef struct amd64_struct1
{
1639 LIBTEST_API amd64_struct1 STDCALL
1640 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s
)
1650 LIBTEST_API amd64_struct1 STDCALL
1651 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
)
1656 s
.l
+= 1 + i1
+ i2
+ i3
+ i4
+ i5
+ i6
+ i7
+ i8
;
1661 typedef struct amd64_struct2
{
1666 LIBTEST_API amd64_struct2 STDCALL
1667 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s
)
1675 typedef struct amd64_struct3
{
1679 LIBTEST_API amd64_struct3 STDCALL
1680 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s
)
1687 typedef struct amd64_struct4
{
1691 LIBTEST_API amd64_struct4 STDCALL
1692 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s
)
1701 * IA64 marshalling tests.
1703 typedef struct test_struct5
{
1707 LIBTEST_API test_struct5 STDCALL
1708 mono_test_marshal_ia64_pass_return_struct5 (double d1
, double d2
, test_struct5 s
, int i
, double d3
, double d4
)
1710 s
.d1
+= d1
+ d2
+ i
;
1711 s
.d2
+= d3
+ d4
+ i
;
1716 typedef struct test_struct6
{
1720 LIBTEST_API test_struct6 STDCALL
1721 mono_test_marshal_ia64_pass_return_struct6 (double d1
, double d2
, test_struct6 s
, int i
, double d3
, double d4
)
1723 s
.d1
+= d1
+ d2
+ i
;
1729 static guint32 custom_res
[2];
1731 LIBTEST_API
void* STDCALL
1732 mono_test_marshal_pass_return_custom (int i
, guint32
*ptr
, int j
)
1734 /* ptr will be freed by CleanupNative, so make a copy */
1735 custom_res
[0] = 0; /* not allocated by AllocHGlobal */
1736 custom_res
[1] = ptr
[1];
1741 LIBTEST_API
int STDCALL
1742 mono_test_marshal_pass_out_custom (int i
, guint32
**ptr
, int j
)
1745 custom_res
[1] = i
+ j
+ 10;
1752 LIBTEST_API
int STDCALL
1753 mono_test_marshal_pass_inout_custom (int i
, guint32
*ptr
, int j
)
1756 ptr
[1] = i
+ ptr
[1] + j
;
1761 LIBTEST_API
int STDCALL
1762 mono_test_marshal_pass_out_byval_custom (int i
, guint32
*ptr
, int j
)
1764 return ptr
== NULL
? 0 : 1;
1767 LIBTEST_API
int STDCALL
1768 mono_test_marshal_pass_byref_custom (int i
, guint32
**ptr
, int j
)
1775 LIBTEST_API
void* STDCALL
1776 mono_test_marshal_pass_return_custom2 (int i
, guint32
*ptr
, int j
)
1778 g_assert_not_reached ();
1783 LIBTEST_API
void* STDCALL
1784 mono_test_marshal_pass_return_custom_null (int i
, guint32
*ptr
, int j
)
1786 g_assert (ptr
== NULL
);
1791 typedef void *(STDCALL
*PassReturnPtrDelegate
) (void *ptr
);
1793 LIBTEST_API
int STDCALL
1794 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del
)
1808 /* FIXME: Freed with FreeHGlobal */
1816 LIBTEST_API
int STDCALL
1817 mono_test_marshal_pass_return_custom_null_in_delegate (PassReturnPtrDelegate del
)
1819 void *ptr
= del (NULL
);
1821 return (ptr
== NULL
) ? 15 : 0;
1824 typedef void (STDCALL
*CustomOutParamDelegate
) (void **pptr
);
1826 LIBTEST_API
int STDCALL
1827 mono_test_marshal_custom_out_param_delegate (CustomOutParamDelegate del
)
1839 typedef int (STDCALL
*ReturnEnumDelegate
) (int e
);
1841 LIBTEST_API
int STDCALL
1842 mono_test_marshal_return_enum_delegate (ReturnEnumDelegate func
)
1852 typedef BlittableStruct (STDCALL
*SimpleDelegate10
) (BlittableStruct ss
);
1854 LIBTEST_API
int STDCALL
1855 mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 delegate
)
1857 BlittableStruct ss
, res
;
1864 res
= delegate (ss
);
1865 if (! ((res
.a
== -1) && (res
.b
== -2) && (res
.c
== -3) && (res
.d
== -55)))
1871 LIBTEST_API
int STDCALL
1872 mono_test_stdcall_name_mangling (int a
, int b
, int c
)
1878 * PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
1885 typedef SmallStruct1 (STDCALL
*SmallStructDelegate1
) (SmallStruct1 ss
);
1887 LIBTEST_API
int STDCALL
1888 mono_test_marshal_small_struct_delegate1 (SmallStructDelegate1 delegate
)
1890 SmallStruct1 ss
, res
;
1894 res
= delegate (ss
);
1895 if (! (res
.i
== -1))
1905 typedef SmallStruct2 (STDCALL
*SmallStructDelegate2
) (SmallStruct2 ss
);
1907 LIBTEST_API
int STDCALL
1908 mono_test_marshal_small_struct_delegate2 (SmallStructDelegate2 delegate
)
1910 SmallStruct2 ss
, res
;
1915 res
= delegate (ss
);
1916 if (! ((res
.i
== -2) && (res
.j
== -3)))
1927 typedef SmallStruct3 (STDCALL
*SmallStructDelegate3
) (SmallStruct3 ss
);
1929 LIBTEST_API
int STDCALL
1930 mono_test_marshal_small_struct_delegate3 (SmallStructDelegate3 delegate
)
1932 SmallStruct3 ss
, res
;
1937 res
= delegate (ss
);
1938 if (! ((res
.i
== -1) && (res
.j
== -2)))
1948 typedef SmallStruct4 (STDCALL
*SmallStructDelegate4
) (SmallStruct4 ss
);
1950 LIBTEST_API
int STDCALL
1951 mono_test_marshal_small_struct_delegate4 (SmallStructDelegate4 delegate
)
1953 SmallStruct4 ss
, res
;
1957 res
= delegate (ss
);
1958 if (! (res
.i
== -1))
1968 typedef SmallStruct5 (STDCALL
*SmallStructDelegate5
) (SmallStruct5 ss
);
1970 LIBTEST_API
int STDCALL
1971 mono_test_marshal_small_struct_delegate5 (SmallStructDelegate5 delegate
)
1973 SmallStruct5 ss
, res
;
1977 res
= delegate (ss
);
1978 if (! (res
.i
== -5))
1988 typedef SmallStruct6 (STDCALL
*SmallStructDelegate6
) (SmallStruct6 ss
);
1990 LIBTEST_API
int STDCALL
1991 mono_test_marshal_small_struct_delegate6 (SmallStructDelegate6 delegate
)
1993 SmallStruct6 ss
, res
;
1998 res
= delegate (ss
);
1999 if (! ((res
.i
== -1) && (res
.j
== -2)))
2010 typedef SmallStruct7 (STDCALL
*SmallStructDelegate7
) (SmallStruct7 ss
);
2012 LIBTEST_API
int STDCALL
2013 mono_test_marshal_small_struct_delegate7 (SmallStructDelegate7 delegate
)
2015 SmallStruct7 ss
, res
;
2020 res
= delegate (ss
);
2021 if (! ((res
.i
== -1) && (res
.j
== -2)))
2031 typedef SmallStruct8 (STDCALL
*SmallStructDelegate8
) (SmallStruct8 ss
);
2033 LIBTEST_API
int STDCALL
2034 mono_test_marshal_small_struct_delegate8 (SmallStructDelegate8 delegate
)
2036 SmallStruct8 ss
, res
;
2040 res
= delegate (ss
);
2041 if (! ((res
.i
== -1.0)))
2051 typedef SmallStruct9 (STDCALL
*SmallStructDelegate9
) (SmallStruct9 ss
);
2053 LIBTEST_API
int STDCALL
2054 mono_test_marshal_small_struct_delegate9 (SmallStructDelegate9 delegate
)
2056 SmallStruct9 ss
, res
;
2060 res
= delegate (ss
);
2061 if (! ((res
.i
== -1.0)))
2071 typedef SmallStruct10 (STDCALL
*SmallStructDelegate10
) (SmallStruct10 ss
);
2073 LIBTEST_API
int STDCALL
2074 mono_test_marshal_small_struct_delegate10 (SmallStructDelegate10 delegate
)
2076 SmallStruct10 ss
, res
;
2081 res
= delegate (ss
);
2082 if (! ((res
.i
== -1.0) && (res
.j
== -2.0)))
2093 typedef SmallStruct11 (STDCALL
*SmallStructDelegate11
) (SmallStruct11 ss
);
2095 LIBTEST_API
int STDCALL
2096 mono_test_marshal_small_struct_delegate11 (SmallStructDelegate11 delegate
)
2098 SmallStruct11 ss
, res
;
2103 res
= delegate (ss
);
2104 if (! ((res
.i
== -1.0) && (res
.j
== -2)))
2110 typedef int (STDCALL
*ArrayDelegate
) (int i
, char *j
, void *arr
);
2112 LIBTEST_API
int STDCALL
2113 mono_test_marshal_array_delegate (void *arr
, int len
, ArrayDelegate del
)
2115 return del (len
, NULL
, arr
);
2118 typedef int (STDCALL
*ArrayDelegateLong
) (gint64 i
, char *j
, void *arr
);
2120 LIBTEST_API
int STDCALL
2121 mono_test_marshal_array_delegate_long (void *arr
, gint64 len
, ArrayDelegateLong del
)
2123 return del (len
, NULL
, arr
);
2126 LIBTEST_API
int STDCALL
2127 mono_test_marshal_out_array_delegate (int *arr
, int len
, ArrayDelegate del
)
2129 del (len
, NULL
, arr
);
2131 if ((arr
[0] != 1) || (arr
[1] != 2))
2137 typedef gunichar2
* (STDCALL
*UnicodeStringDelegate
) (gunichar2
*message
);
2139 LIBTEST_API
int STDCALL
2140 mono_test_marshal_return_unicode_string_delegate (UnicodeStringDelegate del
)
2142 const char m
[] = "abcdef";
2143 gunichar2
*s2
, *res
;
2146 s2
= g_utf8_to_utf16 (m
, -1, NULL
, &len
, NULL
);
2155 LIBTEST_API
int STDCALL
2156 mono_test_marshal_out_string_array_delegate (char **arr
, int len
, ArrayDelegate del
)
2158 del (len
, NULL
, arr
);
2160 if (!strcmp (arr
[0], "ABC") && !strcmp (arr
[1], "DEF"))
2166 typedef int (*CdeclDelegate
) (int i
, int j
);
2168 LIBTEST_API
int STDCALL
2169 mono_test_marshal_cdecl_delegate (CdeclDelegate del
)
2173 for (i
= 0; i
< 1000; ++i
)
2179 typedef char** (STDCALL
*ReturnStringArrayDelegate
) (int i
);
2181 LIBTEST_API
int STDCALL
2182 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d
)
2190 if (strcmp (arr
[0], "ABC") || strcmp (arr
[1], "DEF"))
2200 typedef int (STDCALL
*ByrefStringDelegate
) (char **s
);
2202 LIBTEST_API
int STDCALL
2203 mono_test_marshal_byref_string_delegate (ByrefStringDelegate d
)
2205 char *s
= (char*)"ABC";
2212 if (!strcmp (s
, "DEF"))
2222 LIBTEST_API
int STDCALL
2223 add_delegate (int i
, int j
)
2228 LIBTEST_API gpointer STDCALL
2229 mono_test_marshal_return_fnptr (void)
2231 return &add_delegate
;
2234 LIBTEST_API
int STDCALL
2237 printf ("codigo %x\n", code
);
2245 LIBTEST_API HandleRef STDCALL
2246 mono_xr_as_handle (int code
)
2250 memset (&ref
, 0, sizeof (ref
));
2262 LIBTEST_API
int STDCALL
2263 mono_safe_handle_struct_ref (HandleStructs
*x
)
2265 printf ("Dingus Ref! \n");
2266 printf ("Values: %d %d %p %p\n", x
->a
, x
->b
, x
->handle1
, x
->handle2
);
2272 if (x
->handle1
!= (void*) 0x7080feed)
2275 if (x
->handle2
!= (void*) 0x1234abcd)
2281 LIBTEST_API
int STDCALL
2282 mono_safe_handle_struct (HandleStructs x
)
2284 printf ("Dingus Standard! \n");
2285 printf ("Values: %d %d %p %p\n", x
.a
, x
.b
, x
.handle1
, x
.handle2
);
2291 if (x
.handle1
!= (void*) 0x7080feed)
2294 if (x
.handle2
!= (void*) 0x1234abcd)
2304 LIBTEST_API
int STDCALL
2305 mono_safe_handle_struct_simple (TrivialHandle x
)
2307 printf ("The value is %p\n", x
.a
);
2308 return ((int)(gsize
)x
.a
) * 2;
2311 LIBTEST_API
int STDCALL
2312 mono_safe_handle_return (void)
2317 LIBTEST_API
void STDCALL
2318 mono_safe_handle_ref (void **handle
)
2321 *handle
= (void *) 0xbad;
2325 *handle
= (void *) 0x800d;
2328 LIBTEST_API
double STDCALL
2329 mono_test_marshal_date_time (double d
, double *d2
)
2400 VT_USERDEFINED
= 29,
2408 VT_STREAMED_OBJECT
= 68,
2409 VT_STORED_OBJECT
= 69,
2410 VT_BLOB_OBJECT
= 70,
2418 void VariantInit(VARIANT
* vt
)
2435 LIBTEST_API
int STDCALL
2436 mono_test_marshal_bstr_in(gunichar2
* bstr
)
2439 gchar
* bstr_utf8
= g_utf16_to_utf8 (bstr
, -1, NULL
, NULL
, NULL
);
2440 result
= strcmp("mono_test_marshal_bstr_in", bstr_utf8
);
2447 LIBTEST_API
int STDCALL
2448 mono_test_marshal_bstr_out(gunichar2
** bstr
)
2450 *bstr
= marshal_bstr_alloc ("mono_test_marshal_bstr_out");
2454 LIBTEST_API
int STDCALL
2455 mono_test_marshal_bstr_in_null(gunichar2
* bstr
)
2462 LIBTEST_API
int STDCALL
2463 mono_test_marshal_bstr_out_null(gunichar2
** bstr
)
2469 LIBTEST_API
int STDCALL
2470 mono_test_marshal_variant_in_sbyte(VARIANT variant
)
2472 if (variant
.vt
== VT_I1
&& variant
.cVal
== 100)
2477 LIBTEST_API
int STDCALL
2478 mono_test_marshal_variant_in_byte(VARIANT variant
)
2480 if (variant
.vt
== VT_UI1
&& variant
.bVal
== 100)
2485 LIBTEST_API
int STDCALL
2486 mono_test_marshal_variant_in_short(VARIANT variant
)
2488 if (variant
.vt
== VT_I2
&& variant
.iVal
== 314)
2493 LIBTEST_API
int STDCALL
2494 mono_test_marshal_variant_in_ushort(VARIANT variant
)
2496 if (variant
.vt
== VT_UI2
&& variant
.uiVal
== 314)
2501 LIBTEST_API
int STDCALL
2502 mono_test_marshal_variant_in_int(VARIANT variant
)
2504 if (variant
.vt
== VT_I4
&& variant
.lVal
== 314)
2509 LIBTEST_API
int STDCALL
2510 mono_test_marshal_variant_in_uint(VARIANT variant
)
2512 if (variant
.vt
== VT_UI4
&& variant
.ulVal
== 314)
2517 LIBTEST_API
int STDCALL
2518 mono_test_marshal_variant_in_long(VARIANT variant
)
2520 if (variant
.vt
== VT_I8
&& variant
.llVal
== 314)
2525 LIBTEST_API
int STDCALL
2526 mono_test_marshal_variant_in_ulong(VARIANT variant
)
2528 if (variant
.vt
== VT_UI8
&& variant
.ullVal
== 314)
2533 LIBTEST_API
int STDCALL
2534 mono_test_marshal_variant_in_float(VARIANT variant
)
2536 if (variant
.vt
== VT_R4
&& (variant
.fltVal
- 3.14)/3.14 < .001)
2541 LIBTEST_API
int STDCALL
2542 mono_test_marshal_variant_in_double(VARIANT variant
)
2544 if (variant
.vt
== VT_R8
&& (variant
.dblVal
- 3.14)/3.14 < .001)
2549 LIBTEST_API
int STDCALL
2550 mono_test_marshal_variant_in_bstr(VARIANT variant
)
2553 gchar
* bstr_utf8
= g_utf16_to_utf8 (variant
.bstrVal
, -1, NULL
, NULL
, NULL
);
2554 result
= strcmp("PI", bstr_utf8
);
2557 if (variant
.vt
== VT_BSTR
&& !result
)
2562 LIBTEST_API
int STDCALL
2563 mono_test_marshal_variant_in_bool_true (VARIANT variant
)
2565 if (variant
.vt
== VT_BOOL
&& variant
.boolVal
== VARIANT_TRUE
)
2570 LIBTEST_API
int STDCALL
2571 mono_test_marshal_variant_in_bool_false (VARIANT variant
)
2573 if (variant
.vt
== VT_BOOL
&& variant
.boolVal
== VARIANT_FALSE
)
2578 LIBTEST_API
int STDCALL
2579 mono_test_marshal_variant_out_sbyte(VARIANT
* variant
)
2581 variant
->vt
= VT_I1
;
2582 variant
->cVal
= 100;
2587 LIBTEST_API
int STDCALL
2588 mono_test_marshal_variant_out_byte(VARIANT
* variant
)
2590 variant
->vt
= VT_UI1
;
2591 variant
->bVal
= 100;
2596 LIBTEST_API
int STDCALL
2597 mono_test_marshal_variant_out_short(VARIANT
* variant
)
2599 variant
->vt
= VT_I2
;
2600 variant
->iVal
= 314;
2605 LIBTEST_API
int STDCALL
2606 mono_test_marshal_variant_out_ushort(VARIANT
* variant
)
2608 variant
->vt
= VT_UI2
;
2609 variant
->uiVal
= 314;
2614 LIBTEST_API
int STDCALL
2615 mono_test_marshal_variant_out_int(VARIANT
* variant
)
2617 variant
->vt
= VT_I4
;
2618 variant
->lVal
= 314;
2623 LIBTEST_API
int STDCALL
2624 mono_test_marshal_variant_out_uint(VARIANT
* variant
)
2626 variant
->vt
= VT_UI4
;
2627 variant
->ulVal
= 314;
2632 LIBTEST_API
int STDCALL
2633 mono_test_marshal_variant_out_long(VARIANT
* variant
)
2635 variant
->vt
= VT_I8
;
2636 variant
->llVal
= 314;
2641 LIBTEST_API
int STDCALL
2642 mono_test_marshal_variant_out_ulong(VARIANT
* variant
)
2644 variant
->vt
= VT_UI8
;
2645 variant
->ullVal
= 314;
2650 LIBTEST_API
int STDCALL
2651 mono_test_marshal_variant_out_float(VARIANT
* variant
)
2653 variant
->vt
= VT_R4
;
2654 variant
->fltVal
= 3.14;
2659 LIBTEST_API
int STDCALL
2660 mono_test_marshal_variant_out_double(VARIANT
* variant
)
2662 variant
->vt
= VT_R8
;
2663 variant
->dblVal
= 3.14;
2668 LIBTEST_API
int STDCALL
2669 mono_test_marshal_variant_out_bstr(VARIANT
* variant
)
2671 variant
->vt
= VT_BSTR
;
2672 variant
->bstrVal
= marshal_bstr_alloc("PI");
2677 LIBTEST_API
int STDCALL
2678 mono_test_marshal_variant_out_bool_true (VARIANT
* variant
)
2680 variant
->vt
= VT_BOOL
;
2681 variant
->boolVal
= VARIANT_TRUE
;
2686 LIBTEST_API
int STDCALL
2687 mono_test_marshal_variant_out_bool_false (VARIANT
* variant
)
2689 variant
->vt
= VT_BOOL
;
2690 variant
->boolVal
= VARIANT_FALSE
;
2695 typedef int (STDCALL
*VarFunc
) (int vt
, VARIANT variant
);
2696 typedef int (STDCALL
*VarRefFunc
) (int vt
, VARIANT
* variant
);
2698 LIBTEST_API
int STDCALL
2699 mono_test_marshal_variant_in_sbyte_unmanaged(VarFunc func
)
2704 return func (VT_I1
, vt
);
2707 LIBTEST_API
int STDCALL
2708 mono_test_marshal_variant_in_byte_unmanaged(VarFunc func
)
2713 return func (VT_UI1
, vt
);
2716 LIBTEST_API
int STDCALL
2717 mono_test_marshal_variant_in_short_unmanaged(VarFunc func
)
2722 return func (VT_I2
, vt
);
2725 LIBTEST_API
int STDCALL
2726 mono_test_marshal_variant_in_ushort_unmanaged(VarFunc func
)
2731 return func (VT_UI2
, vt
);
2734 LIBTEST_API
int STDCALL
2735 mono_test_marshal_variant_in_int_unmanaged(VarFunc func
)
2740 return func (VT_I4
, vt
);
2743 LIBTEST_API
int STDCALL
2744 mono_test_marshal_variant_in_uint_unmanaged(VarFunc func
)
2749 return func (VT_UI4
, vt
);
2752 LIBTEST_API
int STDCALL
2753 mono_test_marshal_variant_in_long_unmanaged(VarFunc func
)
2758 return func (VT_I8
, vt
);
2761 LIBTEST_API
int STDCALL
2762 mono_test_marshal_variant_in_ulong_unmanaged(VarFunc func
)
2767 return func (VT_UI8
, vt
);
2770 LIBTEST_API
int STDCALL
2771 mono_test_marshal_variant_in_float_unmanaged(VarFunc func
)
2776 return func (VT_R4
, vt
);
2779 LIBTEST_API
int STDCALL
2780 mono_test_marshal_variant_in_double_unmanaged(VarFunc func
)
2785 return func (VT_R8
, vt
);
2788 LIBTEST_API
int STDCALL
2789 mono_test_marshal_variant_in_bstr_unmanaged(VarFunc func
)
2793 vt
.bstrVal
= marshal_bstr_alloc("PI");
2794 return func (VT_BSTR
, vt
);
2797 LIBTEST_API
int STDCALL
2798 mono_test_marshal_variant_in_bool_true_unmanaged(VarFunc func
)
2802 vt
.boolVal
= VARIANT_TRUE
;
2803 return func (VT_BOOL
, vt
);
2806 LIBTEST_API
int STDCALL
2807 mono_test_marshal_variant_in_bool_false_unmanaged(VarFunc func
)
2811 vt
.boolVal
= VARIANT_FALSE
;
2812 return func (VT_BOOL
, vt
);
2815 LIBTEST_API
int STDCALL
2816 mono_test_marshal_variant_out_sbyte_unmanaged(VarRefFunc func
)
2821 if (vt
.vt
== VT_I1
&& vt
.cVal
== -100)
2826 LIBTEST_API
int STDCALL
2827 mono_test_marshal_variant_out_byte_unmanaged(VarRefFunc func
)
2832 if (vt
.vt
== VT_UI1
&& vt
.bVal
== 100)
2837 LIBTEST_API
int STDCALL
2838 mono_test_marshal_variant_out_short_unmanaged(VarRefFunc func
)
2843 if (vt
.vt
== VT_I2
&& vt
.iVal
== -100)
2848 LIBTEST_API
int STDCALL
2849 mono_test_marshal_variant_out_ushort_unmanaged(VarRefFunc func
)
2854 if (vt
.vt
== VT_UI2
&& vt
.uiVal
== 100)
2859 LIBTEST_API
int STDCALL
2860 mono_test_marshal_variant_out_int_unmanaged(VarRefFunc func
)
2865 if (vt
.vt
== VT_I4
&& vt
.lVal
== -100)
2870 LIBTEST_API
int STDCALL
2871 mono_test_marshal_variant_out_uint_unmanaged(VarRefFunc func
)
2876 if (vt
.vt
== VT_UI4
&& vt
.ulVal
== 100)
2881 LIBTEST_API
int STDCALL
2882 mono_test_marshal_variant_out_long_unmanaged(VarRefFunc func
)
2887 if (vt
.vt
== VT_I8
&& vt
.llVal
== -100)
2892 LIBTEST_API
int STDCALL
2893 mono_test_marshal_variant_out_ulong_unmanaged(VarRefFunc func
)
2898 if (vt
.vt
== VT_UI8
&& vt
.ullVal
== 100)
2903 LIBTEST_API
int STDCALL
2904 mono_test_marshal_variant_out_float_unmanaged(VarRefFunc func
)
2909 if (vt
.vt
== VT_R4
&& fabs (vt
.fltVal
- 3.14f
) < 1e-10)
2914 LIBTEST_API
int STDCALL
2915 mono_test_marshal_variant_out_double_unmanaged(VarRefFunc func
)
2920 if (vt
.vt
== VT_R8
&& fabs (vt
.dblVal
- 3.14) < 1e-10)
2925 LIBTEST_API
int STDCALL
2926 mono_test_marshal_variant_out_bstr_unmanaged(VarRefFunc func
)
2934 func (VT_BSTR
, &vt
);
2935 bstr_utf8
= g_utf16_to_utf8 (vt
.bstrVal
, -1, NULL
, NULL
, NULL
);
2936 result
= strcmp("PI", bstr_utf8
);
2938 if (vt
.vt
== VT_BSTR
&& !result
)
2943 LIBTEST_API
int STDCALL
2944 mono_test_marshal_variant_out_bool_true_unmanaged(VarRefFunc func
)
2948 func (VT_BOOL
, &vt
);
2949 if (vt
.vt
== VT_BOOL
&& vt
.boolVal
== VARIANT_TRUE
)
2954 LIBTEST_API
int STDCALL
2955 mono_test_marshal_variant_out_bool_false_unmanaged(VarRefFunc func
)
2959 func (VT_BOOL
, &vt
);
2960 if (vt
.vt
== VT_BOOL
&& vt
.boolVal
== VARIANT_TRUE
)
2965 typedef struct MonoComObject MonoComObject
;
2969 int (STDCALL
*QueryInterface
)(MonoComObject
* pUnk
, gpointer riid
, gpointer
* ppv
);
2970 int (STDCALL
*AddRef
)(MonoComObject
* pUnk
);
2971 int (STDCALL
*Release
)(MonoComObject
* pUnk
);
2972 int (STDCALL
*get_ITest
)(MonoComObject
* pUnk
, MonoComObject
* *ppUnk
);
2973 int (STDCALL
*SByteIn
)(MonoComObject
* pUnk
, char a
);
2974 int (STDCALL
*ByteIn
)(MonoComObject
* pUnk
, unsigned char a
);
2975 int (STDCALL
*ShortIn
)(MonoComObject
* pUnk
, short a
);
2976 int (STDCALL
*UShortIn
)(MonoComObject
* pUnk
, unsigned short a
);
2977 int (STDCALL
*IntIn
)(MonoComObject
* pUnk
, int a
);
2978 int (STDCALL
*UIntIn
)(MonoComObject
* pUnk
, unsigned int a
);
2979 int (STDCALL
*LongIn
)(MonoComObject
* pUnk
, gint64 a
);
2980 int (STDCALL
*ULongIn
)(MonoComObject
* pUnk
, guint64 a
);
2981 int (STDCALL
*FloatIn
)(MonoComObject
* pUnk
, float a
);
2982 int (STDCALL
*DoubleIn
)(MonoComObject
* pUnk
, double a
);
2983 int (STDCALL
*ITestIn
)(MonoComObject
* pUnk
, MonoComObject
* pUnk2
);
2984 int (STDCALL
*ITestOut
)(MonoComObject
* pUnk
, MonoComObject
* *ppUnk
);
2987 struct MonoComObject
2993 static GUID IID_ITest
= {0, 0, 0, {0,0,0,0,0,0,0,1}};
2994 static GUID IID_IMonoUnknown
= {0, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
2995 static GUID IID_IMonoDispatch
= {0x00020400, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
2997 LIBTEST_API
int STDCALL
2998 MonoQueryInterface(MonoComObject
* pUnk
, gpointer riid
, gpointer
* ppv
)
3002 if (!memcmp(riid
, &IID_IMonoUnknown
, sizeof(GUID
))) {
3006 else if (!memcmp(riid
, &IID_ITest
, sizeof(GUID
))) {
3010 else if (!memcmp(riid
, &IID_IMonoDispatch
, sizeof(GUID
))) {
3014 return 0x80004002; //E_NOINTERFACE;
3017 LIBTEST_API
int STDCALL
3018 MonoAddRef(MonoComObject
* pUnk
)
3020 return ++(pUnk
->m_ref
);
3023 LIBTEST_API
int STDCALL
3024 MonoRelease(MonoComObject
* pUnk
)
3026 return --(pUnk
->m_ref
);
3029 LIBTEST_API
int STDCALL
3030 SByteIn(MonoComObject
* pUnk
, char a
)
3035 LIBTEST_API
int STDCALL
3036 ByteIn(MonoComObject
* pUnk
, unsigned char a
)
3041 LIBTEST_API
int STDCALL
3042 ShortIn(MonoComObject
* pUnk
, short a
)
3047 LIBTEST_API
int STDCALL
3048 UShortIn(MonoComObject
* pUnk
, unsigned short a
)
3053 LIBTEST_API
int STDCALL
3054 IntIn(MonoComObject
* pUnk
, int a
)
3059 LIBTEST_API
int STDCALL
3060 UIntIn(MonoComObject
* pUnk
, unsigned int a
)
3065 LIBTEST_API
int STDCALL
3066 LongIn(MonoComObject
* pUnk
, gint64 a
)
3071 LIBTEST_API
int STDCALL
3072 ULongIn(MonoComObject
* pUnk
, guint64 a
)
3077 LIBTEST_API
int STDCALL
3078 FloatIn(MonoComObject
* pUnk
, float a
)
3083 LIBTEST_API
int STDCALL
3084 DoubleIn(MonoComObject
* pUnk
, double a
)
3089 LIBTEST_API
int STDCALL
3090 ITestIn(MonoComObject
* pUnk
, MonoComObject
*pUnk2
)
3095 LIBTEST_API
int STDCALL
3096 ITestOut(MonoComObject
* pUnk
, MonoComObject
* *ppUnk
)
3101 LIBTEST_API
int STDCALL
3102 get_ITest(MonoComObject
* pUnk
, MonoComObject
* *ppUnk
)
3107 static void create_com_object (MonoComObject
** pOut
)
3109 *pOut
= g_new0 (MonoComObject
, 1);
3110 (*pOut
)->vtbl
= g_new0 (MonoIUnknown
, 1);
3113 (*pOut
)->vtbl
->QueryInterface
= MonoQueryInterface
;
3114 (*pOut
)->vtbl
->AddRef
= MonoAddRef
;
3115 (*pOut
)->vtbl
->Release
= MonoRelease
;
3116 (*pOut
)->vtbl
->SByteIn
= SByteIn
;
3117 (*pOut
)->vtbl
->ByteIn
= ByteIn
;
3118 (*pOut
)->vtbl
->ShortIn
= ShortIn
;
3119 (*pOut
)->vtbl
->UShortIn
= UShortIn
;
3120 (*pOut
)->vtbl
->IntIn
= IntIn
;
3121 (*pOut
)->vtbl
->UIntIn
= UIntIn
;
3122 (*pOut
)->vtbl
->LongIn
= LongIn
;
3123 (*pOut
)->vtbl
->ULongIn
= ULongIn
;
3124 (*pOut
)->vtbl
->FloatIn
= FloatIn
;
3125 (*pOut
)->vtbl
->DoubleIn
= DoubleIn
;
3126 (*pOut
)->vtbl
->ITestIn
= ITestIn
;
3127 (*pOut
)->vtbl
->ITestOut
= ITestOut
;
3128 (*pOut
)->vtbl
->get_ITest
= get_ITest
;
3131 static MonoComObject
* same_object
= NULL
;
3133 LIBTEST_API
int STDCALL
3134 mono_test_marshal_com_object_create(MonoComObject
* *pUnk
)
3136 create_com_object (pUnk
);
3139 same_object
= *pUnk
;
3144 LIBTEST_API
int STDCALL
3145 mono_test_marshal_com_object_same(MonoComObject
* *pUnk
)
3147 *pUnk
= same_object
;
3152 LIBTEST_API
int STDCALL
3153 mono_test_marshal_com_object_destroy(MonoComObject
*pUnk
)
3155 int ref
= --(pUnk
->m_ref
);
3162 LIBTEST_API
int STDCALL
3163 mono_test_marshal_com_object_ref_count(MonoComObject
*pUnk
)
3168 LIBTEST_API
int STDCALL
3169 mono_test_marshal_ccw_itest (MonoComObject
*pUnk
)
3172 MonoComObject
* pTest
;
3177 hr
= pUnk
->vtbl
->SByteIn (pUnk
, -100);
3180 hr
= pUnk
->vtbl
->ByteIn (pUnk
, 100);
3183 hr
= pUnk
->vtbl
->ShortIn (pUnk
, -100);
3186 hr
= pUnk
->vtbl
->UShortIn (pUnk
, 100);
3189 hr
= pUnk
->vtbl
->IntIn (pUnk
, -100);
3192 hr
= pUnk
->vtbl
->UIntIn (pUnk
, 100);
3195 hr
= pUnk
->vtbl
->LongIn (pUnk
, -100);
3198 hr
= pUnk
->vtbl
->ULongIn (pUnk
, 100);
3201 hr
= pUnk
->vtbl
->FloatIn (pUnk
, 3.14f
);
3204 hr
= pUnk
->vtbl
->DoubleIn (pUnk
, 3.14);
3207 hr
= pUnk
->vtbl
->ITestIn (pUnk
, pUnk
);
3210 hr
= pUnk
->vtbl
->ITestOut (pUnk
, &pTest
);
3218 * mono_method_get_unmanaged_thunk tests
3221 #if defined(__GNUC__) && ((defined(__i386__) && (defined(__linux__) || defined (__APPLE__)) || defined (__FreeBSD__) || defined(__OpenBSD__)) || (defined(__ppc__) && defined(__APPLE__)))
3222 #define ALIGN(size) __attribute__ ((aligned(size)))
3228 /* thunks.cs:TestStruct */
3229 typedef struct _TestStruct
{
3231 double B
ALIGN(8); /* align according to mono's struct layout */
3234 /* Searches for mono symbols in all loaded modules */
3236 lookup_mono_symbol (const char *symbol_name
)
3239 if (g_module_symbol (g_module_open (NULL
, G_MODULE_BIND_LAZY
), symbol_name
, &symbol
))
3245 LIBTEST_API gpointer STDCALL
3246 mono_test_marshal_lookup_symbol (const char *symbol_name
)
3248 return lookup_mono_symbol (symbol_name
);
3252 * test_method_thunk:
3254 * @test_id: the test number
3255 * @test_method_handle: MonoMethod* of the C# test method
3256 * @create_object_method_handle: MonoMethod* of thunks.cs:Test.CreateObject
3258 LIBTEST_API
int STDCALL
3259 test_method_thunk (int test_id
, gpointer test_method_handle
, gpointer create_object_method_handle
)
3261 gpointer (*mono_method_get_unmanaged_thunk
)(gpointer
)
3262 = lookup_mono_symbol ("mono_method_get_unmanaged_thunk");
3264 gpointer (*mono_string_new_wrapper
)(const char *)
3265 = lookup_mono_symbol ("mono_string_new_wrapper");
3267 char* (*mono_string_to_utf8
)(gpointer
)
3268 = lookup_mono_symbol ("mono_string_to_utf8");
3270 gpointer (*mono_object_unbox
)(gpointer
)
3271 = lookup_mono_symbol ("mono_object_unbox");
3273 gpointer test_method
, ex
= NULL
;
3274 gpointer (STDCALL
*CreateObject
)(gpointer
*);
3277 if (!mono_method_get_unmanaged_thunk
)
3280 test_method
= mono_method_get_unmanaged_thunk (test_method_handle
);
3284 CreateObject
= mono_method_get_unmanaged_thunk (create_object_method_handle
);
3292 /* thunks.cs:Test.Test0 */
3293 void (STDCALL
*F
)(gpointer
*) = test_method
;
3299 /* thunks.cs:Test.Test1 */
3300 int (STDCALL
*F
)(gpointer
*) = test_method
;
3307 /* thunks.cs:Test.Test2 */
3308 gpointer (STDCALL
*F
)(gpointer
, gpointer
*) = test_method
;
3309 gpointer str
= mono_string_new_wrapper ("foo");
3310 if (str
!= F (str
, &ex
))
3316 /* thunks.cs:Test.Test3 */
3317 gpointer (STDCALL
*F
)(gpointer
, gpointer
, gpointer
*);
3322 obj
= CreateObject (&ex
);
3323 str
= mono_string_new_wrapper ("bar");
3325 if (str
!= F (obj
, str
, &ex
))
3331 /* thunks.cs:Test.Test4 */
3332 int (STDCALL
*F
)(gpointer
, gpointer
, int, gpointer
*);
3337 obj
= CreateObject (&ex
);
3338 str
= mono_string_new_wrapper ("bar");
3340 if (42 != F (obj
, str
, 42, &ex
))
3347 /* thunks.cs:Test.Test5 */
3348 int (STDCALL
*F
)(gpointer
, gpointer
, int, gpointer
*);
3353 obj
= CreateObject (&ex
);
3354 str
= mono_string_new_wrapper ("bar");
3356 F (obj
, str
, 42, &ex
);
3364 /* thunks.cs:Test.Test6 */
3365 int (STDCALL
*F
)(gpointer
, guint8
, gint16
, gint32
, gint64
, float, double,
3366 gpointer
, gpointer
*);
3368 gpointer str
= mono_string_new_wrapper ("Test6");
3372 obj
= CreateObject (&ex
);
3374 res
= F (obj
, 254, 32700, -245378, 6789600, 3.1415, 3.1415, str
, &ex
);
3385 /* thunks.cs:Test.Test7 */
3386 gint64 (STDCALL
*F
)(gpointer
*) = test_method
;
3387 if (F (&ex
) != G_MAXINT64
)
3393 /* thunks.cs:Test.Test8 */
3394 void (STDCALL
*F
)(guint8
*, gint16
*, gint32
*, gint64
*, float*, double*,
3395 gpointer
*, gpointer
*);
3407 F (&a1
, &a2
, &a3
, &a4
, &a5
, &a6
, &a7
, &ex
);
3415 (fabs (a5
- 3.1415) < 0.001) &&
3416 (fabs (a6
- 3.1415) < 0.001) &&
3417 strcmp (mono_string_to_utf8 (a7
), "Test8") == 0))
3424 /* thunks.cs:Test.Test9 */
3425 void (STDCALL
*F
)(guint8
*, gint16
*, gint32
*, gint64
*, float*, double*,
3426 gpointer
*, gpointer
*);
3438 F (&a1
, &a2
, &a3
, &a4
, &a5
, &a6
, &a7
, &ex
);
3446 /* thunks.cs:Test.Test10 */
3447 void (STDCALL
*F
)(gpointer
*, gpointer
*);
3449 gpointer obj1
, obj2
;
3451 obj1
= obj2
= CreateObject (&ex
);
3468 /* thunks.cs:TestStruct.Test0 */
3469 int (STDCALL
*F
)(gpointer
*, gpointer
*);
3475 obj
= CreateObject (&ex
);
3482 a1
= mono_object_unbox (obj
);
3498 /* check whether the call was really by value */
3499 if (a1
->A
!= 42 || a1
->B
!= 3.1415)
3506 /* thunks.cs:TestStruct.Test1 */
3507 void (STDCALL
*F
)(gpointer
, gpointer
*);
3512 obj
= CreateObject (&ex
);
3519 a1
= mono_object_unbox (obj
);
3532 if (!fabs (a1
->B
- 3.1415) < 0.001)
3539 /* thunks.cs:TestStruct.Test2 */
3540 gpointer (STDCALL
*F
)(gpointer
*);
3554 a1
= mono_object_unbox (obj
);
3559 if (!fabs (a1
->B
- 3.1415) < 0.001)
3566 /* thunks.cs:TestStruct.Test3 */
3567 void (STDCALL
*F
)(gpointer
, gpointer
*);
3572 obj
= CreateObject (&ex
);
3579 a1
= mono_object_unbox (obj
);
3615 LIBTEST_API
int STDCALL
3616 mono_test_Winx64_struct1_in (winx64_struct1 var
)
3629 LIBTEST_API
int STDCALL
3630 mono_test_Winx64_struct2_in (winx64_struct2 var
)
3647 LIBTEST_API
int STDCALL
3648 mono_test_Winx64_struct3_in (winx64_struct3 var
)
3654 if (var
.c
!= 0x1234)
3667 LIBTEST_API
int STDCALL
3668 mono_test_Winx64_struct4_in (winx64_struct4 var
)
3674 if (var
.c
!= 0x1234)
3676 if (var
.d
!= 0x87654321)
3688 LIBTEST_API
int STDCALL
3689 mono_test_Winx64_struct5_in (winx64_struct5 var
)
3707 LIBTEST_API
int STDCALL
3708 mono_test_Winx64_struct6_in (winx64_struct6 var
)
3719 LIBTEST_API
int STDCALL
3720 mono_test_Winx64_structs_in1 (winx64_struct1 var1
,
3721 winx64_struct2 var2
,
3722 winx64_struct3 var3
,
3723 winx64_struct4 var4
)
3737 if (var3
.c
!= 0x1234)
3744 if (var4
.c
!= 0x1234)
3746 if (var4
.d
!= 0x87654321)
3751 LIBTEST_API
int STDCALL
3752 mono_test_Winx64_structs_in2 (winx64_struct1 var1
,
3753 winx64_struct1 var2
,
3754 winx64_struct1 var3
,
3755 winx64_struct1 var4
,
3756 winx64_struct1 var5
)
3772 LIBTEST_API
int STDCALL
3773 mono_test_Winx64_structs_in3 (winx64_struct1 var1
,
3774 winx64_struct5 var2
,
3775 winx64_struct1 var3
,
3776 winx64_struct5 var4
,
3777 winx64_struct1 var5
,
3778 winx64_struct5 var6
)
3813 LIBTEST_API winx64_struct1 STDCALL
3814 mono_test_Winx64_struct1_ret (void)
3821 LIBTEST_API winx64_struct2 STDCALL
3822 mono_test_Winx64_struct2_ret (void)
3830 LIBTEST_API winx64_struct3 STDCALL
3831 mono_test_Winx64_struct3_ret (void)
3840 LIBTEST_API winx64_struct4 STDCALL
3841 mono_test_Winx64_struct4_ret (void)
3851 LIBTEST_API winx64_struct5 STDCALL
3852 mono_test_Winx64_struct5_ret (void)
3861 LIBTEST_API winx64_struct1 STDCALL
3862 mono_test_Winx64_struct1_ret_5_args (char a
, char b
, char c
, char d
, char e
)
3865 ret
.a
= a
+ b
+ c
+ d
+ e
;
3869 LIBTEST_API winx64_struct5 STDCALL
3870 mono_test_Winx64_struct5_ret6_args (char a
, char b
, char c
, char d
, char e
)
3883 } winx64_floatStruct
;
3885 LIBTEST_API
int STDCALL
3886 mono_test_Winx64_floatStruct (winx64_floatStruct a
)
3888 if (a
.a
> 5.6 || a
.a
< 5.4)
3891 if (a
.b
> 9.6 || a
.b
< 9.4)
3900 } winx64_doubleStruct
;
3902 LIBTEST_API
int STDCALL
3903 mono_test_Winx64_doubleStruct (winx64_doubleStruct a
)
3905 if (a
.a
> 5.6 || a
.a
< 5.4)
3911 typedef int (STDCALL
*managed_struct1_delegate
) (winx64_struct1 a
);
3913 LIBTEST_API
int STDCALL
3914 mono_test_managed_Winx64_struct1_in(managed_struct1_delegate func
)
3921 typedef int (STDCALL
*managed_struct5_delegate
) (winx64_struct5 a
);
3923 LIBTEST_API
int STDCALL
3924 mono_test_managed_Winx64_struct5_in(managed_struct5_delegate func
)
3933 typedef int (STDCALL
*managed_struct1_struct5_delegate
) (winx64_struct1 a
, winx64_struct5 b
,
3934 winx64_struct1 c
, winx64_struct5 d
,
3935 winx64_struct1 e
, winx64_struct5 f
);
3937 LIBTEST_API
int STDCALL
3938 mono_test_managed_Winx64_struct1_struct5_in(managed_struct1_struct5_delegate func
)
3940 winx64_struct1 a
, c
, e
;
3941 winx64_struct5 b
, d
, f
;
3943 b
.a
= 2; b
.b
= 3; b
.c
= 4;
3945 d
.a
= 6; d
.b
= 7; d
.c
= 8;
3947 f
.a
= 10; f
.b
= 11; f
.c
= 12;
3949 return func (a
, b
, c
, d
, e
, f
);
3952 typedef winx64_struct1 (STDCALL
*managed_struct1_ret_delegate
) (void);
3954 LIBTEST_API
int STDCALL
3955 mono_test_Winx64_struct1_ret_managed (managed_struct1_ret_delegate func
)
3967 typedef winx64_struct5 (STDCALL
*managed_struct5_ret_delegate
) (void);
3969 LIBTEST_API
int STDCALL
3970 mono_test_Winx64_struct5_ret_managed (managed_struct5_ret_delegate func
)
3986 LIBTEST_API
int STDCALL
3987 mono_test_marshal_bool_in (int arg
, unsigned int expected
, unsigned int bDefaultMarsh
, unsigned int bBoolCustMarsh
,
3988 char bI1CustMarsh
, unsigned char bU1CustMarsh
, short bVBCustMarsh
)
3992 if (bDefaultMarsh
!= expected
)
3996 if (bBoolCustMarsh
!= expected
)
4000 if (bI1CustMarsh
!= expected
)
4004 if (bU1CustMarsh
!= expected
)
4008 if (bVBCustMarsh
!= expected
)
4017 LIBTEST_API
int STDCALL
4018 mono_test_marshal_bool_out (int arg
, unsigned int testVal
, unsigned int* bDefaultMarsh
, unsigned int* bBoolCustMarsh
,
4019 char* bI1CustMarsh
, unsigned char* bU1CustMarsh
, unsigned short* bVBCustMarsh
)
4025 *bDefaultMarsh
= testVal
;
4028 if (!bBoolCustMarsh
)
4030 *bBoolCustMarsh
= testVal
;
4035 *bI1CustMarsh
= (char)testVal
;
4040 *bU1CustMarsh
= (unsigned char)testVal
;
4045 *bVBCustMarsh
= (unsigned short)testVal
;
4053 LIBTEST_API
int STDCALL
4054 mono_test_marshal_bool_ref (int arg
, unsigned int expected
, unsigned int testVal
, unsigned int* bDefaultMarsh
,
4055 unsigned int* bBoolCustMarsh
, char* bI1CustMarsh
, unsigned char* bU1CustMarsh
,
4056 unsigned short* bVBCustMarsh
)
4062 if (*bDefaultMarsh
!= expected
)
4064 *bDefaultMarsh
= testVal
;
4067 if (!bBoolCustMarsh
)
4069 if (*bBoolCustMarsh
!= expected
)
4071 *bBoolCustMarsh
= testVal
;
4076 if (*bI1CustMarsh
!= expected
)
4078 *bI1CustMarsh
= (char)testVal
;
4083 if (*bU1CustMarsh
!= expected
)
4085 *bU1CustMarsh
= (unsigned char)testVal
;
4090 if (*bVBCustMarsh
!= expected
)
4092 *bVBCustMarsh
= (unsigned short)testVal
;
4101 typedef int (STDCALL
*MarshalBoolInDelegate
) (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_in (int arg
, unsigned int expected
, unsigned int testVal
, MarshalBoolInDelegate pfcn
)
4112 return pfcn (arg
, expected
, testVal
, 0, 0, 0, 0);
4114 return pfcn (arg
, expected
, 0, testVal
, 0, 0, 0);
4116 return pfcn (arg
, expected
, 0, 0, testVal
, 0, 0);
4118 return pfcn (arg
, expected
, 0, 0, 0, testVal
, 0);
4120 return pfcn (arg
, expected
, 0, 0, 0, 0, testVal
);
4128 typedef int (STDCALL
*MarshalBoolOutDelegate
) (int arg
, unsigned int expected
, unsigned int* bDefaultMarsh
,
4129 unsigned int* bBoolCustMarsh
, char* bI1CustMarsh
, unsigned char* bU1CustMarsh
, unsigned short* bVBCustMarsh
);
4131 LIBTEST_API
int STDCALL
4132 mono_test_managed_marshal_bool_out (int arg
, unsigned int expected
, unsigned int testVal
, MarshalBoolOutDelegate pfcn
)
4135 unsigned int lDefaultMarsh
, lBoolCustMarsh
;
4136 char lI1CustMarsh
= 0;
4137 unsigned char lU1CustMarsh
= 0;
4138 unsigned short lVBCustMarsh
= 0;
4139 lDefaultMarsh
= lBoolCustMarsh
= 0;
4146 unsigned int ltVal
= 0;
4147 ret
= pfcn (arg
, testVal
, <Val
, &lBoolCustMarsh
, &lI1CustMarsh
, &lU1CustMarsh
, &lVBCustMarsh
);
4149 return 0x0100 + ret
;
4150 if (expected
!= ltVal
)
4155 unsigned int ltVal
= 0;
4156 ret
= pfcn (arg
, testVal
, &lDefaultMarsh
, <Val
, &lI1CustMarsh
, &lU1CustMarsh
, &lVBCustMarsh
);
4158 return 0x0300 + ret
;
4159 if (expected
!= ltVal
)
4165 ret
= pfcn (arg
, testVal
, &lDefaultMarsh
, &lBoolCustMarsh
, <Val
, &lU1CustMarsh
, &lVBCustMarsh
);
4167 return 0x0500 + ret
;
4168 if (expected
!= ltVal
)
4173 unsigned char ltVal
= 0;
4174 ret
= pfcn (arg
, testVal
, &lDefaultMarsh
, &lBoolCustMarsh
, &lI1CustMarsh
, <Val
, &lVBCustMarsh
);
4176 return 0x0700 + ret
;
4177 if (expected
!= ltVal
)
4182 unsigned short ltVal
= 0;
4183 ret
= pfcn (arg
, testVal
, &lDefaultMarsh
, &lBoolCustMarsh
, &lI1CustMarsh
, &lU1CustMarsh
, <Val
);
4185 return 0x0900 + ret
;
4186 if (expected
!= ltVal
)
4197 typedef int (STDCALL
*MarshalBoolRefDelegate
) (int arg
, unsigned int expected
, unsigned int testVal
, unsigned int* bDefaultMarsh
,
4198 unsigned int* bBoolCustMarsh
, char* bI1CustMarsh
, unsigned char* bU1CustMarsh
, unsigned short* bVBCustMarsh
);
4200 LIBTEST_API
int STDCALL
4201 mono_test_managed_marshal_bool_ref (int arg
, unsigned int expected
, unsigned int testVal
, unsigned int outExpected
,
4202 unsigned int outTestVal
, MarshalBoolRefDelegate pfcn
)
4205 unsigned int lDefaultMarsh
, lBoolCustMarsh
;
4206 char lI1CustMarsh
= 0;
4207 unsigned char lU1CustMarsh
= 0;
4208 unsigned short lVBCustMarsh
= 0;
4209 lDefaultMarsh
= lBoolCustMarsh
= 0;
4217 unsigned int ltestVal
= testVal
;
4218 ret
= pfcn (arg
, expected
, outTestVal
, <estVal
, &lBoolCustMarsh
, &lI1CustMarsh
, &lU1CustMarsh
, &lVBCustMarsh
);
4220 return 0x0100 + ret
;
4221 if (outExpected
!= ltestVal
)
4227 unsigned int ltestVal
= testVal
;
4228 ret
= pfcn (arg
, expected
, outTestVal
, &lDefaultMarsh
, <estVal
, &lI1CustMarsh
, &lU1CustMarsh
, &lVBCustMarsh
);
4230 return 0x0300 + ret
;
4231 if (outExpected
!= ltestVal
)
4237 char ltestVal
= testVal
;
4238 ret
= pfcn (arg
, expected
, outTestVal
, &lDefaultMarsh
, &lBoolCustMarsh
, <estVal
, &lU1CustMarsh
, &lVBCustMarsh
);
4240 return 0x0500 + ret
;
4241 if (outExpected
!= ltestVal
)
4247 unsigned char ltestVal
= testVal
;
4248 ret
= pfcn (arg
, expected
, outTestVal
, &lDefaultMarsh
, &lBoolCustMarsh
, &lI1CustMarsh
, <estVal
, &lVBCustMarsh
);
4250 return 0x0700 + ret
;
4251 if (outExpected
!= ltestVal
)
4257 unsigned short ltestVal
= testVal
;
4258 ret
= pfcn (arg
, expected
, outTestVal
, &lDefaultMarsh
, &lBoolCustMarsh
, &lI1CustMarsh
, &lU1CustMarsh
, <estVal
);
4260 return 0x0900 + ret
;
4261 if (outExpected
!= ltestVal
)
4274 LIBTEST_API
int STDCALL
4275 mono_test_marshal_safearray_out_1dim_vt_bstr_empty (SAFEARRAY
** safearray
)
4277 /* Create an empty one-dimensional array of variants */
4279 SAFEARRAYBOUND dimensions
[1];
4281 dimensions
[0].lLbound
= 0;
4282 dimensions
[0].cElements
= 0;
4284 pSA
= SafeArrayCreate (VT_VARIANT
, 1, dimensions
);
4289 LIBTEST_API
int STDCALL
4290 mono_test_marshal_safearray_out_1dim_vt_bstr (SAFEARRAY
** safearray
)
4292 /* Create a one-dimensional array of 10 variants filled with "0" to "9" */
4294 SAFEARRAYBOUND dimensions
[1];
4300 dimensions
[0].lLbound
= 0;
4301 dimensions
[0].cElements
= 10;
4303 pSA
= SafeArrayCreate (VT_VARIANT
, 1, dimensions
);
4304 for (i
= dimensions
[0].lLbound
; i
< (dimensions
[0].cElements
+ dimensions
[0].lLbound
); i
++) {
4306 VariantInit (&vOut
);
4308 _ltoa (i
,buffer
,10);
4309 vOut
.bstrVal
= marshal_bstr_alloc (buffer
);
4311 if ((hr
= SafeArrayPutElement (pSA
, indices
, &vOut
)) != S_OK
) {
4312 VariantClear (&vOut
);
4313 SafeArrayDestroy (pSA
);
4316 VariantClear (&vOut
);
4322 LIBTEST_API
int STDCALL
4323 mono_test_marshal_safearray_out_2dim_vt_i4 (SAFEARRAY
** safearray
)
4325 /* Create a two-dimensional array of 4x3 variants filled with 11, 12, 13, etc. */
4327 SAFEARRAYBOUND dimensions
[2];
4332 dimensions
[0].lLbound
= 0;
4333 dimensions
[0].cElements
= 4;
4334 dimensions
[1].lLbound
= 0;
4335 dimensions
[1].cElements
= 3;
4337 pSA
= SafeArrayCreate(VT_VARIANT
, 2, dimensions
);
4338 for (i
= dimensions
[0].lLbound
; i
< (dimensions
[0].cElements
+ dimensions
[0].lLbound
); i
++) {
4339 for (j
= dimensions
[1].lLbound
; j
< (dimensions
[1].cElements
+ dimensions
[1].lLbound
); j
++) {
4341 VariantInit (&vOut
);
4343 vOut
.lVal
= (i
+1)*10+(j
+1);
4346 if ((hr
= SafeArrayPutElement (pSA
, indices
, &vOut
)) != S_OK
) {
4347 VariantClear (&vOut
);
4348 SafeArrayDestroy (pSA
);
4351 VariantClear (&vOut
); // does a deep destroy of source VARIANT
4358 LIBTEST_API
int STDCALL
4359 mono_test_marshal_safearray_out_4dim_vt_i4 (SAFEARRAY
** safearray
)
4361 /* Create a four-dimensional array of 10x3x6x7 variants filled with their indices */
4362 /* Also use non zero lower bounds */
4364 SAFEARRAYBOUND dimensions
[4];
4369 dimensions
[0].lLbound
= 15;
4370 dimensions
[0].cElements
= 10;
4371 dimensions
[1].lLbound
= 20;
4372 dimensions
[1].cElements
= 3;
4373 dimensions
[2].lLbound
= 5;
4374 dimensions
[2].cElements
= 6;
4375 dimensions
[3].lLbound
= 12;
4376 dimensions
[3].cElements
= 7;
4378 pSA
= SafeArrayCreate (VT_VARIANT
, 4, dimensions
);
4380 SafeArrayAccessData (pSA
, (void **)&pData
);
4382 for (i
= 0; i
< 10*3*6*7; i
++) {
4383 VariantInit(&pData
[i
]);
4384 pData
[i
].vt
= VT_I4
;
4387 SafeArrayUnaccessData (pSA
);
4392 LIBTEST_API
int STDCALL
4393 mono_test_marshal_safearray_in_byval_1dim_empty (SAFEARRAY
* safearray
)
4395 /* Check that array is one dimensional and empty */
4398 long lbound
, ubound
;
4400 dim
= SafeArrayGetDim (safearray
);
4404 SafeArrayGetLBound (safearray
, 1, &lbound
);
4405 SafeArrayGetUBound (safearray
, 1, &ubound
);
4407 if ((lbound
> 0) || (ubound
> 0))
4413 LIBTEST_API
int STDCALL
4414 mono_test_marshal_safearray_in_byval_1dim_vt_i4 (SAFEARRAY
* safearray
)
4416 /* Check that array is one dimensional containing integers from 1 to 10 */
4419 long lbound
, ubound
;
4424 dim
= SafeArrayGetDim (safearray
);
4428 SafeArrayGetLBound (safearray
, 1, &lbound
);
4429 SafeArrayGetUBound (safearray
, 1, &ubound
);
4431 if ((lbound
!= 0) || (ubound
!= 9))
4434 SafeArrayAccessData (safearray
, (void **)&pData
);
4435 for (i
= lbound
; i
<= ubound
; i
++) {
4436 if ((VariantChangeType (&pData
[i
], &pData
[i
], VARIANT_NOUSEROVERRIDE
, VT_I4
) != S_OK
) || (pData
[i
].lVal
!= i
+ 1))
4439 SafeArrayUnaccessData (safearray
);
4444 LIBTEST_API
int STDCALL
4445 mono_test_marshal_safearray_in_byval_1dim_vt_mixed (SAFEARRAY
* safearray
)
4447 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4450 long lbound
, ubound
;
4457 VariantInit (&element
);
4459 dim
= SafeArrayGetDim (safearray
);
4463 SafeArrayGetLBound (safearray
, 1, &lbound
);
4464 SafeArrayGetUBound (safearray
, 1, &ubound
);
4466 if ((lbound
!= 0) || (ubound
!= 12))
4469 SafeArrayAccessData (safearray
, (void **)&pData
);
4470 for (i
= lbound
; i
<= ubound
; i
++) {
4471 if ((i
%2 == 0) && (pData
[i
].vt
!= VT_I4
))
4473 if ((i
%2 == 1) && (pData
[i
].vt
!= VT_BSTR
))
4475 if ((VariantChangeType (&pData
[i
], &pData
[i
], VARIANT_NOUSEROVERRIDE
, VT_I4
) != S_OK
) || (pData
[i
].lVal
!= i
))
4478 SafeArrayUnaccessData (safearray
);
4480 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4485 SafeArrayPutElement (safearray
, indices
, &element
);
4486 VariantClear (&element
);
4491 LIBTEST_API
int STDCALL
4492 mono_test_marshal_safearray_in_byval_2dim_vt_i4 (SAFEARRAY
* safearray
)
4494 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4497 long lbound1
, ubound1
, lbound2
, ubound2
;
4502 VariantInit (&element
);
4504 dim
= SafeArrayGetDim (safearray
);
4508 SafeArrayGetLBound (safearray
, 1, &lbound1
);
4509 SafeArrayGetUBound (safearray
, 1, &ubound1
);
4511 if ((lbound1
!= 0) || (ubound1
!= 1))
4514 SafeArrayGetLBound (safearray
, 2, &lbound2
);
4515 SafeArrayGetUBound (safearray
, 2, &ubound2
);
4517 if ((lbound2
!= 0) || (ubound2
!= 3)) {
4521 for (i
= lbound1
; i
<= ubound1
; i
++) {
4523 for (j
= lbound2
; j
<= ubound2
; j
++) {
4525 if (SafeArrayGetElement (safearray
, indices
, &element
) != S_OK
)
4527 failed
= ((element
.vt
!= VT_I4
) || (element
.lVal
!= 10*(i
+1)+(j
+1)));
4528 VariantClear (&element
);
4534 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4540 SafeArrayPutElement (safearray
, indices
, &element
);
4541 VariantClear (&element
);
4546 LIBTEST_API
int STDCALL
4547 mono_test_marshal_safearray_in_byval_3dim_vt_bstr (SAFEARRAY
* safearray
)
4549 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4552 long lbound1
, ubound1
, lbound2
, ubound2
, lbound3
, ubound3
;
4553 long i
, j
, k
, failed
;
4557 VariantInit (&element
);
4559 dim
= SafeArrayGetDim (safearray
);
4563 SafeArrayGetLBound (safearray
, 1, &lbound1
);
4564 SafeArrayGetUBound (safearray
, 1, &ubound1
);
4566 if ((lbound1
!= 0) || (ubound1
!= 1))
4569 SafeArrayGetLBound (safearray
, 2, &lbound2
);
4570 SafeArrayGetUBound (safearray
, 2, &ubound2
);
4572 if ((lbound2
!= 0) || (ubound2
!= 1))
4575 SafeArrayGetLBound (safearray
, 3, &lbound3
);
4576 SafeArrayGetUBound (safearray
, 3, &ubound3
);
4578 if ((lbound3
!= 0) || (ubound3
!= 2))
4581 for (i
= lbound1
; i
<= ubound1
; i
++) {
4583 for (j
= lbound2
; j
<= ubound2
; j
++) {
4585 for (k
= lbound3
; k
<= ubound3
; k
++) {
4587 if (SafeArrayGetElement (safearray
, indices
, &element
) != S_OK
)
4589 failed
= ((element
.vt
!= VT_BSTR
)
4590 || (VariantChangeType (&element
, &element
, VARIANT_NOUSEROVERRIDE
, VT_I4
) != S_OK
)
4591 || (element
.lVal
!= 100*(i
+1)+10*(j
+1)+(k
+1)));
4592 VariantClear (&element
);
4599 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4604 element
.vt
= VT_BSTR
;
4605 element
.bstrVal
= SysAllocString(L
"Should not be copied");
4606 SafeArrayPutElement (safearray
, indices
, &element
);
4607 VariantClear (&element
);
4612 LIBTEST_API
int STDCALL
4613 mono_test_marshal_safearray_in_byref_3dim_vt_bstr (SAFEARRAY
** safearray
)
4615 return mono_test_marshal_safearray_in_byval_3dim_vt_bstr (*safearray
);
4618 LIBTEST_API
int STDCALL
4619 mono_test_marshal_safearray_in_out_byref_1dim_empty (SAFEARRAY
** safearray
)
4621 /* Check that the input array is what is expected and change it so the caller can check */
4622 /* correct marshalling back to managed code */
4625 long lbound
, ubound
;
4626 SAFEARRAYBOUND dimensions
[1];
4628 wchar_t buffer
[20];
4632 /* Check that in array is one dimensional and empty */
4634 dim
= SafeArrayGetDim (*safearray
);
4639 SafeArrayGetLBound (*safearray
, 1, &lbound
);
4640 SafeArrayGetUBound (*safearray
, 1, &ubound
);
4642 if ((lbound
> 0) || (ubound
> 0)) {
4646 /* Re-dimension the array and return a one-dimensional array of 8 variants filled with "0" to "7" */
4648 dimensions
[0].lLbound
= 0;
4649 dimensions
[0].cElements
= 8;
4651 hr
= SafeArrayRedim (*safearray
, dimensions
);
4655 for (i
= dimensions
[0].lLbound
; i
< (dimensions
[0].lLbound
+ dimensions
[0].cElements
); i
++) {
4657 VariantInit (&vOut
);
4659 _ltow (i
,buffer
,10);
4660 vOut
.bstrVal
= SysAllocString (buffer
);
4662 if ((hr
= SafeArrayPutElement (*safearray
, indices
, &vOut
)) != S_OK
) {
4663 VariantClear (&vOut
);
4664 SafeArrayDestroy (*safearray
);
4667 VariantClear (&vOut
);
4672 LIBTEST_API
int STDCALL
4673 mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr (SAFEARRAY
** safearray
)
4675 /* Check that the input array is what is expected and change it so the caller can check */
4676 /* correct marshalling back to managed code */
4679 long lbound1
, ubound1
, lbound2
, ubound2
, lbound3
, ubound3
;
4680 SAFEARRAYBOUND dimensions
[1];
4681 long i
, j
, k
, failed
;
4682 wchar_t buffer
[20];
4687 VariantInit (&element
);
4689 /* Check that in array is three dimensional and contains the expected values */
4691 dim
= SafeArrayGetDim (*safearray
);
4695 SafeArrayGetLBound (*safearray
, 1, &lbound1
);
4696 SafeArrayGetUBound (*safearray
, 1, &ubound1
);
4698 if ((lbound1
!= 0) || (ubound1
!= 1))
4701 SafeArrayGetLBound (*safearray
, 2, &lbound2
);
4702 SafeArrayGetUBound (*safearray
, 2, &ubound2
);
4704 if ((lbound2
!= 0) || (ubound2
!= 1))
4707 SafeArrayGetLBound (*safearray
, 3, &lbound3
);
4708 SafeArrayGetUBound (*safearray
, 3, &ubound3
);
4710 if ((lbound3
!= 0) || (ubound3
!= 2))
4713 for (i
= lbound1
; i
<= ubound1
; i
++) {
4715 for (j
= lbound2
; j
<= ubound2
; j
++) {
4717 for (k
= lbound3
; k
<= ubound3
; k
++) {
4719 if (SafeArrayGetElement (*safearray
, indices
, &element
) != S_OK
)
4721 failed
= ((element
.vt
!= VT_BSTR
)
4722 || (VariantChangeType (&element
, &element
, VARIANT_NOUSEROVERRIDE
, VT_I4
) != S_OK
)
4723 || (element
.lVal
!= 100*(i
+1)+10*(j
+1)+(k
+1)));
4724 VariantClear (&element
);
4731 hr
= SafeArrayDestroy (*safearray
);
4735 /* Return a new one-dimensional array of 8 variants filled with "0" to "7" */
4737 dimensions
[0].lLbound
= 0;
4738 dimensions
[0].cElements
= 8;
4740 *safearray
= SafeArrayCreate (VT_VARIANT
, 1, dimensions
);
4742 for (i
= dimensions
[0].lLbound
; i
< (dimensions
[0].lLbound
+ dimensions
[0].cElements
); i
++) {
4744 VariantInit (&vOut
);
4746 _ltow (i
,buffer
,10);
4747 vOut
.bstrVal
= SysAllocString (buffer
);
4749 if ((hr
= SafeArrayPutElement (*safearray
, indices
, &vOut
)) != S_OK
) {
4750 VariantClear (&vOut
);
4751 SafeArrayDestroy (*safearray
);
4754 VariantClear (&vOut
);
4759 LIBTEST_API
int STDCALL
4760 mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 (SAFEARRAY
** safearray
)
4762 /* Check that the input array is what is expected and change it so the caller can check */
4763 /* correct marshalling back to managed code */
4766 long lbound1
, ubound1
;
4772 VariantInit (&element
);
4774 /* Check that in array is one dimensional and contains the expected value */
4776 dim
= SafeArrayGetDim (*safearray
);
4780 SafeArrayGetLBound (*safearray
, 1, &lbound1
);
4781 SafeArrayGetUBound (*safearray
, 1, &ubound1
);
4784 if ((lbound1
!= 0) || (ubound1
!= 1))
4788 for (i
= lbound1
; i
<= ubound1
; i
++) {
4790 if (SafeArrayGetElement (*safearray
, indices
, &element
) != S_OK
)
4792 failed
= (element
.vt
!= VT_I4
) || (element
.lVal
!= i
+1);
4793 VariantClear (&element
);
4798 /* Change one of the elements of the array to verify that [out] parameter is marshalled back to the managed side */
4803 SafeArrayPutElement (*safearray
, indices
, &element
);
4804 VariantClear (&element
);
4809 LIBTEST_API
int STDCALL
4810 mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (SAFEARRAY
* safearray
)
4812 /* Check that the input array is what is expected and change it so the caller can check */
4813 /* correct marshalling back to managed code */
4816 long lbound1
, ubound1
;
4817 SAFEARRAYBOUND dimensions
[1];
4823 VariantInit (&element
);
4825 /* Check that in array is one dimensional and contains the expected value */
4827 dim
= SafeArrayGetDim (safearray
);
4831 SafeArrayGetLBound (safearray
, 1, &lbound1
);
4832 SafeArrayGetUBound (safearray
, 1, &ubound1
);
4834 if ((lbound1
!= 0) || (ubound1
!= 0))
4837 for (i
= lbound1
; i
<= ubound1
; i
++) {
4839 if (SafeArrayGetElement (safearray
, indices
, &element
) != S_OK
)
4841 failed
= (element
.vt
!= VT_I4
) || (element
.lVal
!= i
+1);
4842 VariantClear (&element
);
4847 /* Change the array to verify how [out] parameter is marshalled back to the managed side */
4849 /* Redimension the array */
4850 dimensions
[0].lLbound
= lbound1
;
4851 dimensions
[0].cElements
= 2;
4852 hr
= SafeArrayRedim(safearray
, dimensions
);
4856 element
.lVal
= 12345;
4857 SafeArrayPutElement (safearray
, indices
, &element
);
4858 VariantClear (&element
);
4862 element
.lVal
= -12345;
4863 SafeArrayPutElement (safearray
, indices
, &element
);
4864 VariantClear (&element
);
4869 LIBTEST_API
int STDCALL
4870 mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr (SAFEARRAY
* safearray
)
4872 /* Check that the input array is what is expected and change it so the caller can check */
4873 /* correct marshalling back to managed code */
4876 long lbound1
, ubound1
, lbound2
, ubound2
, lbound3
, ubound3
;
4877 long i
, j
, k
, failed
;
4882 VariantInit (&element
);
4884 /* Check that in array is three dimensional and contains the expected values */
4886 dim
= SafeArrayGetDim (safearray
);
4890 SafeArrayGetLBound (safearray
, 1, &lbound1
);
4891 SafeArrayGetUBound (safearray
, 1, &ubound1
);
4893 if ((lbound1
!= 0) || (ubound1
!= 1))
4896 SafeArrayGetLBound (safearray
, 2, &lbound2
);
4897 SafeArrayGetUBound (safearray
, 2, &ubound2
);
4899 if ((lbound2
!= 0) || (ubound2
!= 1))
4902 SafeArrayGetLBound (safearray
, 3, &lbound3
);
4903 SafeArrayGetUBound (safearray
, 3, &ubound3
);
4905 if ((lbound3
!= 0) || (ubound3
!= 2))
4908 for (i
= lbound1
; i
<= ubound1
; i
++) {
4910 for (j
= lbound2
; j
<= ubound2
; j
++) {
4912 for (k
= lbound3
; k
<= ubound3
; k
++) {
4914 if (SafeArrayGetElement (safearray
, indices
, &element
) != S_OK
)
4916 failed
= ((element
.vt
!= VT_BSTR
)
4917 || (VariantChangeType (&element
, &element
, VARIANT_NOUSEROVERRIDE
, VT_I4
) != S_OK
)
4918 || (element
.lVal
!= 100*(i
+1)+10*(j
+1)+(k
+1)));
4919 VariantClear (&element
);
4926 /* Change the elements of the array to verify that [out] parameter is marshalled back to the managed side */
4933 SafeArrayPutElement (safearray
, indices
, &element
);
4934 VariantClear (&element
);
4941 SafeArrayPutElement (safearray
, indices
, &element
);
4942 VariantClear (&element
);
4947 element
.vt
= VT_BSTR
;
4948 element
.bstrVal
= marshal_bstr_alloc("ABCDEFG");
4949 SafeArrayPutElement (safearray
, indices
, &element
);
4950 VariantClear (&element
);
4955 LIBTEST_API
int STDCALL
4956 mono_test_marshal_safearray_mixed(
4957 SAFEARRAY
*safearray1
,
4958 SAFEARRAY
**safearray2
,
4959 SAFEARRAY
*safearray3
,
4960 SAFEARRAY
**safearray4
4965 /* Initialize out parameters */
4968 /* array1: Check that in array is one dimensional and contains the expected value */
4969 hr
= mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (safearray1
);
4971 /* array2: Fill in with some values to check on the managed side */
4973 hr
= mono_test_marshal_safearray_out_1dim_vt_bstr (safearray2
);
4975 /* array3: Check that in array is one dimensional and contains the expected value */
4977 hr
= mono_test_marshal_safearray_in_byval_1dim_vt_mixed(safearray3
);
4979 /* array4: Check input values and fill in with some values to check on the managed side */
4981 hr
= mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr(safearray4
);