13 #define STDCALL __stdcall
19 extern __declspec(dllimport
) __stdcall
void CoTaskMemFree(void *ptr
);
22 typedef int (STDCALL
*SimpleDelegate
) (int a
);
24 static void marshal_free (void *ptr
)
33 STDCALL
unsigned short*
34 test_lpwstr_marshal (unsigned short* chars
, long length
)
39 res
= malloc (2 * (length
+ 1));
41 // printf("test_lpwstr_marshal()\n");
43 while ( i
< length
) {
44 // printf("X|%u|\n", chars[i]);
61 mono_union_test_1 (union_test_1_type u1
) {
62 // printf ("Got values %d %d %d\n", u1.b, u1.a, u1.c);
63 return u1
.a
+ u1
.b
+ u1
.c
;
67 mono_return_int (int a
) {
68 // printf ("Got value %d\n", a);
78 mono_return_int_ss (struct ss a
) {
79 // printf ("Got value %d\n", a.i);
84 mono_return_ss (struct ss a
) {
85 // printf ("Got value %d\n", a.i);
96 mono_return_sc1 (struct sc1 a
) {
97 // printf ("Got value %d\n", a.c[0]);
109 mono_return_sc3 (struct sc3 a
) {
110 // printf ("Got values %d %d %d\n", a.c[0], a.c[1], a.c[2]);
123 mono_return_sc5 (struct sc5 a
) {
124 // printf ("Got values %d %d %d %d %d\n", a.c[0], a.c[1], a.c[2], a.c[3], a.c[4]);
140 mono_return_int_su (union su a
) {
141 // printf ("Got value %d\n", a.i1);
146 mono_test_many_int_arguments (int a
, int b
, int c
, int d
, int e
,
147 int f
, int g
, int h
, int i
, int j
);
149 mono_test_many_short_arguments (short a
, short b
, short c
, short d
, short e
,
150 short f
, short g
, short h
, short i
, short j
);
152 mono_test_many_char_arguments (char a
, char b
, char c
, char d
, char e
,
153 char f
, char g
, char h
, char i
, char j
);
156 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
)
158 return a
+ b
+ c
+ d
+ e
+ f
+ g
+ h
+ i
+ j
;
162 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
)
164 return a
+ b
+ c
+ d
+ e
+ f
+ g
+ h
+ i
+ j
;
168 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
)
170 return a
+ b
+ c
+ d
+ e
+ f
+ g
+ h
+ i
+ j
;
174 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
)
176 return a
+ b
+ c
+ d
+ e
+ f
+ g
+ h
+ i
+ j
;
180 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
)
182 return a
+ b
+ c
+ d
+ e
+ f
+ g
+ h
+ i
+ j
;
186 mono_test_split_double_arguments (double a
, double b
, float c
, double d
, double e
)
188 return a
+ b
+ c
+ d
+ e
;
192 mono_test_puts_static (char *s
)
194 // printf ("TEST %s\n", s);
198 typedef int (STDCALL
*SimpleDelegate3
) (int a
, int b
);
201 mono_invoke_delegate (SimpleDelegate3 delegate
)
205 // printf ("start invoke %p\n", delegate);
207 res
= delegate (2, 3);
209 // printf ("end invoke\n");
215 mono_test_marshal_char (short a1
)
224 mono_test_marshal_char_array (gunichar2
*s
)
226 const char m
[] = "abcdef";
230 s2
= g_utf8_to_utf16 (m
, -1, NULL
, &len
, NULL
);
239 mono_test_empty_pinvoke (int i
)
245 mono_test_marshal_bool_byref (int a
, int *b
, int c
)
255 mono_test_marshal_array (int *a1
)
259 for (i
= 0; i
< 50; i
++)
266 mono_test_marshal_inout_array (int *a1
)
270 for (i
= 0; i
< 50; i
++) {
272 a1
[i
] = 50 - a1
[i
];
279 mono_test_marshal_out_array (int *a1
)
283 for (i
= 0; i
< 50; i
++) {
291 mono_test_marshal_inout_nonblittable_array (gunichar2
*a1
)
295 for (i
= 0; i
< 10; i
++) {
316 mono_test_return_vtype (int i
)
319 static gunichar2 test2
[] = { 'T', 'E', 'S', 'T', '2', 0 };
331 mono_test_delegate_struct (void)
333 // printf ("TEST\n");
336 typedef char* (STDCALL
*ReturnStringDelegate
) (const char *s
);
339 mono_test_return_string (ReturnStringDelegate func
)
343 // printf ("mono_test_return_string\n");
348 // printf ("got string: %s\n", res);
349 return g_strdup ("12345");
352 typedef int (STDCALL
*RefVTypeDelegate
) (int a
, simplestruct
*ss
, int b
);
355 mono_test_ref_vtype (int a
, simplestruct
*ss
, int b
, RefVTypeDelegate func
)
357 if (a
== 1 && b
== 2 && ss
->a
== 0 && ss
->b
== 1 && ss
->c
== 0 &&
358 !strcmp (ss
->d
, "TEST1")) {
364 return func (a
, ss
, b
);
370 typedef int (STDCALL
*OutVTypeDelegate
) (int a
, simplestruct
*ss
, int b
);
373 mono_test_marshal_out_struct (int a
, simplestruct
*ss
, int b
, OutVTypeDelegate func
)
375 /* Check that the input pointer is ignored */
376 ss
->d
= (gpointer
)0x12345678;
380 if (ss
->a
&& ss
->b
&& ss
->c
&& !strcmp (ss
->d
, "TEST3"))
388 SimpleDelegate func
, func2
;
391 STDCALL DelegateStruct
392 mono_test_marshal_delegate_struct (DelegateStruct ds
)
396 res
.a
= ds
.func (ds
.a
) + ds
.func2 (ds
.a
);
398 res
.func2
= ds
.func2
;
404 mono_test_marshal_struct (simplestruct ss
)
406 if (ss
.a
== 0 && ss
.b
== 1 && ss
.c
== 0 &&
407 !strcmp (ss
.d
, "TEST"))
414 mono_test_marshal_byref_struct (simplestruct
*ss
, int a
, int b
, int c
, char *d
)
416 gboolean res
= (ss
->a
== a
&& ss
->b
== b
&& ss
->c
== c
&& strcmp (ss
->d
, d
) == 0);
421 ss
->d
= g_strdup ("DEF");
438 mono_test_marshal_struct2 (simplestruct2 ss
)
440 if (ss
.a
== 0 && ss
.b
== 1 && ss
.c
== 0 &&
441 !strcmp (ss
.d
, "TEST") &&
442 ss
.e
== 99 && ss
.f
== 1.5 && ss
.g
== 42 && ss
.h
== (guint64
)123)
448 /* on HP some of the struct should be on the stack and not in registers */
450 mono_test_marshal_struct2_2 (int i
, int j
, int k
, simplestruct2 ss
)
452 if (i
!= 10 || j
!= 11 || k
!= 12)
454 if (ss
.a
== 0 && ss
.b
== 1 && ss
.c
== 0 &&
455 !strcmp (ss
.d
, "TEST") &&
456 ss
.e
== 99 && ss
.f
== 1.5 && ss
.g
== 42 && ss
.h
== (guint64
)123)
463 mono_test_marshal_lpstruct (simplestruct
*ss
)
465 if (ss
->a
== 0 && ss
->b
== 1 && ss
->c
== 0 &&
466 !strcmp (ss
->d
, "TEST"))
473 mono_test_marshal_lpstruct_blittable (point
*p
)
475 if (p
->x
== 1.0 && p
->y
== 2.0)
482 mono_test_marshal_struct_array (simplestruct2
*ss
)
484 if (! (ss
[0].a
== 0 && ss
[0].b
== 1 && ss
[0].c
== 0 &&
485 !strcmp (ss
[0].d
, "TEST") &&
486 ss
[0].e
== 99 && ss
[0].f
== 1.5 && ss
[0].g
== 42 && ss
[0].h
== (guint64
)123))
489 if (! (ss
[1].a
== 0 && ss
[1].b
== 0 && ss
[1].c
== 0 &&
490 !strcmp (ss
[1].d
, "TEST2") &&
491 ss
[1].e
== 100 && ss
[1].f
== 2.5 && ss
[1].g
== 43 && ss
[1].h
== (guint64
)124))
497 typedef struct long_align_struct
{
504 mono_test_marshal_long_align_struct_array (long_align_struct
*ss
)
506 return ss
[0].a
+ ss
[0].b
+ ss
[0].c
+ ss
[1].a
+ ss
[1].b
+ ss
[1].c
;
509 STDCALL simplestruct2
*
510 mono_test_marshal_class (int i
, int j
, int k
, simplestruct2
*ss
, int l
)
517 if (i
!= 10 || j
!= 11 || k
!= 12 || l
!= 14)
519 if (! (ss
->a
== 0 && ss
->b
== 1 && ss
->c
== 0 &&
520 !strcmp (ss
->d
, "TEST") &&
521 ss
->e
== 99 && ss
->f
== 1.5 && ss
->g
== 42 && ss
->h
== (guint64
)123))
524 res
= g_new0 (simplestruct2
, 1);
525 memcpy (res
, ss
, sizeof (simplestruct2
));
526 res
->d
= g_strdup ("TEST");
531 mono_test_marshal_byref_class (simplestruct2
**ssp
)
533 simplestruct2
*ss
= *ssp
;
536 if (! (ss
->a
== 0 && ss
->b
== 1 && ss
->c
== 0 &&
537 !strcmp (ss
->d
, "TEST") &&
538 ss
->e
== 99 && ss
->f
== 1.5 && ss
->g
== 42 && ss
->h
== (guint64
)123))
541 res
= g_new0 (simplestruct2
, 1);
542 memcpy (res
, ss
, sizeof (simplestruct2
));
543 res
->d
= g_strdup ("TEST-RES");
555 /* Yes, this is correct, we are only trying to determine the value of the stack here */
561 reliable_delegate (int a
)
567 * Checks whether get_sp() works as expected. It doesn't work with gcc-2.95.3 on linux.
570 is_get_sp_reliable (void)
574 reliable_delegate(1);
576 reliable_delegate(1);
582 mono_test_marshal_delegate (SimpleDelegate delegate
)
586 /* Check that the delegate wrapper is stdcall */
591 if (is_get_sp_reliable())
592 g_assert (sp1
== sp2
);
597 STDCALL SimpleDelegate
598 mono_test_marshal_return_delegate (SimpleDelegate delegate
)
604 return_plus_one (int i
)
609 STDCALL SimpleDelegate
610 mono_test_marshal_return_delegate_2 ()
612 return return_plus_one
;
615 typedef simplestruct (STDCALL
*SimpleDelegate2
) (simplestruct ss
);
618 is_utf16_equals (gunichar2
*s1
, const char *s2
)
623 s
= g_utf16_to_utf8 (s1
, -1, NULL
, NULL
, NULL
);
624 res
= strcmp (s
, s2
);
631 mono_test_marshal_delegate2 (SimpleDelegate2 delegate
)
633 simplestruct ss
, res
;
639 ss
.d2
= g_utf8_to_utf16 ("TEST2", -1, NULL
, NULL
, NULL
);
642 if (! (res
.a
&& !res
.b
&& res
.c
&& !strcmp (res
.d
, "TEST-RES") && is_utf16_equals (res
.d2
, "TEST2-RES")))
648 typedef simplestruct
* (STDCALL
*SimpleDelegate4
) (simplestruct
*ss
);
651 mono_test_marshal_delegate4 (SimpleDelegate4 delegate
)
662 res
= delegate (&ss
);
666 /* Check return value */
667 if (! (!res
->a
&& res
->b
&& !res
->c
&& !strcmp (res
->d
, "TEST")))
670 /* Check NULL argument and NULL result */
671 res
= delegate (NULL
);
678 typedef int (STDCALL
*SimpleDelegate5
) (simplestruct
**ss
);
681 mono_test_marshal_delegate5 (SimpleDelegate5 delegate
)
694 res
= delegate (&ptr
);
698 if (!(ptr
->a
&& !ptr
->b
&& ptr
->c
&& !strcmp (ptr
->d
, "RES")))
705 mono_test_marshal_delegate6 (SimpleDelegate5 delegate
)
709 res
= delegate (NULL
);
714 typedef int (STDCALL
*SimpleDelegate7
) (simplestruct
**ss
);
717 mono_test_marshal_delegate7 (SimpleDelegate7 delegate
)
722 /* Check that the input pointer is ignored */
723 ptr
= (gpointer
)0x12345678;
725 res
= delegate (&ptr
);
729 if (!(ptr
->a
&& !ptr
->b
&& ptr
->c
&& !strcmp (ptr
->d
, "RES")))
735 typedef int (STDCALL
*SimpleDelegate8
) (gunichar2
*s
);
738 mono_test_marshal_delegate8 (SimpleDelegate8 delegate
, gunichar2
*s
)
743 typedef int (STDCALL
*return_int_fnt
) (int i
);
744 typedef int (STDCALL
*SimpleDelegate9
) (return_int_fnt d
);
747 mono_test_marshal_delegate9 (SimpleDelegate9 delegate
, gpointer ftn
)
749 return delegate (ftn
);
759 mono_test_marshal_delegate10 (SimpleDelegate9 delegate
)
761 return delegate (return_self
);
764 typedef int (STDCALL
*PrimitiveByrefDelegate
) (int *i
);
767 mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate delegate
)
771 int res
= delegate (&i
);
781 typedef int (STDCALL
*return_int_delegate
) (int i
);
783 typedef return_int_delegate (STDCALL
*ReturnDelegateDelegate
) (void);
786 mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d
)
792 mono_test_marshal_stringbuilder (char *s
, int n
)
794 const char m
[] = "This is my message. Isn't it nice?";
796 if (strcmp (s
, "ABCD") != 0)
803 mono_test_marshal_stringbuilder_unicode (gunichar2
*s
, int n
)
805 const char m
[] = "This is my message. Isn't it nice?";
809 s2
= g_utf8_to_utf16 (m
, -1, NULL
, &len
, NULL
);
828 mono_test_marshal_empty_string_array (char **array
)
830 return (array
== NULL
) ? 0 : 1;
834 mono_test_marshal_string_array (char **array
)
836 if (strcmp (array
[0], "ABC"))
838 if (strcmp (array
[1], "DEF"))
841 if (array
[2] != NULL
)
848 mono_test_marshal_byref_string_array (char ***array
)
853 if (strcmp ((*array
) [0], "Alpha"))
855 if (strcmp ((*array
) [1], "Beta"))
857 if (strcmp ((*array
) [2], "Gamma"))
864 mono_test_marshal_stringbuilder_array (char **array
)
866 if (strcmp (array
[0], "ABC"))
868 if (strcmp (array
[1], "DEF"))
871 strcpy (array
[0], "DEF");
872 strcpy (array
[1], "ABC");
878 mono_test_marshal_unicode_string_array (gunichar2
**array
, char **array2
)
880 GError
*error
= NULL
;
883 s
= g_utf16_to_utf8 (array
[0], -1, NULL
, NULL
, &error
);
884 if (strcmp (s
, "ABC")) {
891 s
= g_utf16_to_utf8 (array
[1], -1, NULL
, NULL
, &error
);
892 if (strcmp (s
, "DEF")) {
899 if (strcmp (array2
[0], "ABC"))
902 if (strcmp (array2
[1], "DEF"))
908 /* this does not work on Redhat gcc 2.96 */
910 mono_test_empty_struct (int a
, EmptyStruct es
, int b
)
912 // printf ("mono_test_empty_struct %d %d\n", a, b);
914 // Intel icc on ia64 passes 'es' in 2 registers
915 #if defined(__ia64) && defined(__INTEL_COMPILER)
918 if (a
== 1 && b
== 2)
928 STDCALL ByValStrStruct
*
929 mono_test_byvalstr_gen (void)
933 ret
= malloc(sizeof(ByValStrStruct
));
934 memset(ret
, 'a', sizeof(ByValStrStruct
)-1);
935 ret
->a
[sizeof(ByValStrStruct
)-1] = 0;
941 mono_test_byvalstr_check (ByValStrStruct
* data
, char* correctString
)
945 ret
= strcmp(data
->a
, correctString
);
946 // printf ("T1: %s\n", data->a);
947 // printf ("T2: %s\n", correctString);
954 NameManglingAnsi (char *data
)
956 return data
[0] + data
[1] + data
[2];
960 NameManglingAnsiA (char *data
)
962 g_assert_not_reached ();
966 NameManglingAnsiW (char *data
)
968 g_assert_not_reached ();
972 NameManglingAnsi2A (char *data
)
974 return data
[0] + data
[1] + data
[2];
978 NameManglingAnsi2W (char *data
)
980 g_assert_not_reached ();
984 NameManglingUnicode (char *data
)
986 g_assert_not_reached ();
990 NameManglingUnicodeW (gunichar2
*data
)
992 return data
[0] + data
[1] + data
[2];
996 NameManglingUnicode2 (gunichar2
*data
)
998 return data
[0] + data
[1] + data
[2];
1002 NameManglingAutoW (char *data
)
1005 return (data
[0] + data
[1] + data
[2]) == 131 ? 0 : 1;
1007 g_assert_not_reached ();
1012 NameManglingAuto (char *data
)
1015 return (data
[0] + data
[1] + data
[2]) == 198 ? 0 : 1;
1017 g_assert_not_reached ();
1021 typedef int (STDCALL
*intcharFunc
)(const char*);
1024 callFunction (intcharFunc f
)
1035 class_marshal_test0 (SimpleObj
*obj1
)
1037 // printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
1039 if (strcmp(obj1
->str
, "T1"))
1048 class_marshal_test4 (SimpleObj
*obj1
)
1057 class_marshal_test1 (SimpleObj
**obj1
)
1059 SimpleObj
*res
= malloc (sizeof (SimpleObj
));
1061 res
->str
= g_strdup ("ABC");
1068 class_marshal_test2 (SimpleObj
**obj1
)
1070 // printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
1072 if (strcmp((*obj1
)->str
, "ABC"))
1074 if ((*obj1
)->i
!= 5)
1081 string_marshal_test0 (char *str
)
1083 if (strcmp (str
, "TEST0"))
1090 string_marshal_test1 (const char **str
)
1096 string_marshal_test2 (char **str
)
1098 // printf ("string_marshal_test2 %s\n", *str);
1100 if (strcmp (*str
, "TEST1"))
1107 string_marshal_test3 (char *str
)
1121 TestVectorList (VectorList
*vl
)
1125 // printf ("TestVectorList %d %d\n", vl->a, vl->b);
1130 res
= g_new0 (VectorList
, 1);
1131 memcpy (res
, vl
, sizeof (VectorList
));
1136 typedef struct OSVERSIONINFO_STRUCT
1140 } OSVERSIONINFO_STRUCT
;
1143 MyGetVersionEx (OSVERSIONINFO_STRUCT
*osvi
)
1146 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1151 return osvi
->a
+ osvi
->b
;
1155 BugGetVersionEx (int a
, int b
, int c
, int d
, int e
, int f
, int g
, int h
, OSVERSIONINFO_STRUCT
*osvi
)
1158 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1163 return osvi
->a
+ osvi
->b
;
1167 mono_test_marshal_point (point pt
)
1169 // printf("point %g %g\n", pt.x, pt.y);
1170 if (pt
.x
== 1.25 && pt
.y
== 3.5)
1182 mono_test_marshal_mixed_point (mixed_point pt
)
1184 // printf("mixed point %d %g\n", pt.x, pt.y);
1185 if (pt
.x
== 5 && pt
.y
== 6.75)
1192 mono_test_marshal_mixed_point_2 (mixed_point
*pt
)
1194 if (pt
->x
!= 5 || pt
->y
!= 6.75)
1204 marshal_test_ref_bool(int i
, char *b1
, short *b2
, int *b3
)
1207 if (*b1
!= 0 && *b1
!= 1)
1209 if (*b2
!= 0 && *b2
!= -1) /* variant_bool */
1211 if (*b3
!= 0 && *b3
!= 1)
1213 if (i
== ((*b1
<< 2) | (-*b2
<< 1) | *b3
))
1225 short b2
; /* variant_bool */
1230 marshal_test_bool_struct(struct BoolStruct
*s
)
1233 if (s
->b1
!= 0 && s
->b1
!= 1)
1235 if (s
->b2
!= 0 && s
->b2
!= -1)
1237 if (s
->b3
!= 0 && s
->b3
!= 1)
1239 if (s
->i
== ((s
->b1
<< 2) | (-s
->b2
<< 1) | s
->b3
))
1248 mono_test_last_error (int err
)
1258 mono_test_asany (void *ptr
, int what
)
1262 return (*(int*)ptr
== 5) ? 0 : 1;
1264 return strcmp (ptr
, "ABC") == 0 ? 0 : 1;
1266 simplestruct2 ss
= *(simplestruct2
*)ptr
;
1268 if (ss
.a
== 0 && ss
.b
== 1 && ss
.c
== 0 &&
1269 !strcmp (ss
.d
, "TEST") &&
1270 ss
.e
== 99 && ss
.f
== 1.5 && ss
.g
== 42 && ss
.h
== (guint64
)123)
1276 GError
*error
= NULL
;
1279 s
= g_utf16_to_utf8 (ptr
, -1, NULL
, NULL
, &error
);
1280 if (!strcmp (s
, "ABC")) {
1290 g_assert_not_reached ();
1305 mono_test_marshal_asany_inout (void* ptr
)
1307 AsAnyStruct
* asAny
= ptr
;
1308 int res
= asAny
->i
+ asAny
->j
+ asAny
->k
;
1319 * AMD64 marshalling tests.
1322 typedef struct amd64_struct1
{
1329 STDCALL amd64_struct1
1330 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s
)
1340 typedef struct amd64_struct2
{
1345 STDCALL amd64_struct2
1346 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s
)
1354 typedef struct amd64_struct3
{
1358 STDCALL amd64_struct3
1359 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s
)
1366 typedef struct amd64_struct4
{
1370 STDCALL amd64_struct4
1371 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s
)
1380 * IA64 marshalling tests.
1382 typedef struct test_struct5
{
1386 STDCALL test_struct5
1387 mono_test_marshal_ia64_pass_return_struct5 (double d1
, double d2
, test_struct5 s
, double d3
, double d4
)
1395 typedef struct test_struct6
{
1399 STDCALL test_struct6
1400 mono_test_marshal_ia64_pass_return_struct6 (double d1
, double d2
, test_struct6 s
, double d3
, double d4
)
1408 static guint32 custom_res
[2];
1411 mono_test_marshal_pass_return_custom (int i
, guint32
*ptr
, int j
)
1413 /* ptr will be freed by CleanupNative, so make a copy */
1414 custom_res
[0] = 0; /* not allocated by AllocHGlobal */
1415 custom_res
[1] = ptr
[1];
1421 mono_test_marshal_pass_out_custom (int i
, guint32
**ptr
, int j
)
1424 custom_res
[1] = i
+ j
+ 10;
1432 mono_test_marshal_pass_byref_custom (int i
, guint32
**ptr
, int j
)
1440 mono_test_marshal_pass_return_custom2 (int i
, guint32
*ptr
, int j
)
1442 g_assert_not_reached ();
1448 mono_test_marshal_pass_return_custom_null (int i
, guint32
*ptr
, int j
)
1450 g_assert (ptr
== NULL
);
1455 typedef void *(STDCALL
*PassReturnPtrDelegate
) (void *ptr
);
1458 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del
)
1472 /* FIXME: Freed with FreeHGlobal */
1481 mono_test_marshal_pass_return_custom_null_in_delegate (PassReturnPtrDelegate del
)
1483 void *ptr
= del (NULL
);
1485 return (ptr
== NULL
) ? 15 : 0;
1488 typedef int (STDCALL
*ReturnEnumDelegate
) (int e
);
1491 mono_test_marshal_return_enum_delegate (ReturnEnumDelegate func
)
1501 typedef BlittableStruct (STDCALL
*SimpleDelegate10
) (BlittableStruct ss
);
1504 mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 delegate
)
1506 BlittableStruct ss
, res
;
1513 res
= delegate (ss
);
1514 if (! ((res
.a
== -1) && (res
.b
== -2) && (res
.c
== -3) && (res
.d
== -55)))
1521 mono_test_stdcall_name_mangling (int a
, int b
, int c
)
1527 * PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
1534 typedef SmallStruct1 (STDCALL
*SmallStructDelegate1
) (SmallStruct1 ss
);
1537 mono_test_marshal_small_struct_delegate1 (SmallStructDelegate1 delegate
)
1539 SmallStruct1 ss
, res
;
1543 res
= delegate (ss
);
1544 if (! (res
.i
== -1))
1554 typedef SmallStruct2 (STDCALL
*SmallStructDelegate2
) (SmallStruct2 ss
);
1557 mono_test_marshal_small_struct_delegate2 (SmallStructDelegate2 delegate
)
1559 SmallStruct2 ss
, res
;
1564 res
= delegate (ss
);
1565 if (! ((res
.i
== -2) && (res
.j
== -3)))
1576 typedef SmallStruct3 (STDCALL
*SmallStructDelegate3
) (SmallStruct3 ss
);
1579 mono_test_marshal_small_struct_delegate3 (SmallStructDelegate3 delegate
)
1581 SmallStruct3 ss
, res
;
1586 res
= delegate (ss
);
1587 if (! ((res
.i
== -1) && (res
.j
== -2)))
1597 typedef SmallStruct4 (STDCALL
*SmallStructDelegate4
) (SmallStruct4 ss
);
1600 mono_test_marshal_small_struct_delegate4 (SmallStructDelegate4 delegate
)
1602 SmallStruct4 ss
, res
;
1606 res
= delegate (ss
);
1607 if (! (res
.i
== -1))
1617 typedef SmallStruct5 (STDCALL
*SmallStructDelegate5
) (SmallStruct5 ss
);
1620 mono_test_marshal_small_struct_delegate5 (SmallStructDelegate5 delegate
)
1622 SmallStruct5 ss
, res
;
1626 res
= delegate (ss
);
1627 if (! (res
.i
== -5))
1637 typedef SmallStruct6 (STDCALL
*SmallStructDelegate6
) (SmallStruct6 ss
);
1640 mono_test_marshal_small_struct_delegate6 (SmallStructDelegate6 delegate
)
1642 SmallStruct6 ss
, res
;
1647 res
= delegate (ss
);
1648 if (! ((res
.i
== -1) && (res
.j
== -2)))
1659 typedef SmallStruct7 (STDCALL
*SmallStructDelegate7
) (SmallStruct7 ss
);
1662 mono_test_marshal_small_struct_delegate7 (SmallStructDelegate7 delegate
)
1664 SmallStruct7 ss
, res
;
1669 res
= delegate (ss
);
1670 if (! ((res
.i
== -1) && (res
.j
== -2)))
1680 typedef SmallStruct8 (STDCALL
*SmallStructDelegate8
) (SmallStruct8 ss
);
1683 mono_test_marshal_small_struct_delegate8 (SmallStructDelegate8 delegate
)
1685 SmallStruct8 ss
, res
;
1689 res
= delegate (ss
);
1690 if (! ((res
.i
== -1.0)))
1700 typedef SmallStruct9 (STDCALL
*SmallStructDelegate9
) (SmallStruct9 ss
);
1703 mono_test_marshal_small_struct_delegate9 (SmallStructDelegate9 delegate
)
1705 SmallStruct9 ss
, res
;
1709 res
= delegate (ss
);
1710 if (! ((res
.i
== -1.0)))
1720 typedef SmallStruct10 (STDCALL
*SmallStructDelegate10
) (SmallStruct10 ss
);
1723 mono_test_marshal_small_struct_delegate10 (SmallStructDelegate10 delegate
)
1725 SmallStruct10 ss
, res
;
1730 res
= delegate (ss
);
1731 if (! ((res
.i
== -1.0) && (res
.j
== -2.0)))
1742 typedef SmallStruct11 (STDCALL
*SmallStructDelegate11
) (SmallStruct11 ss
);
1745 mono_test_marshal_small_struct_delegate11 (SmallStructDelegate11 delegate
)
1747 SmallStruct11 ss
, res
;
1752 res
= delegate (ss
);
1753 if (! ((res
.i
== -1.0) && (res
.j
== -2)))
1759 typedef int (STDCALL
*ArrayDelegate
) (int i
, char *j
, void *arr
);
1762 mono_test_marshal_array_delegate (void *arr
, int len
, ArrayDelegate del
)
1764 return del (len
, NULL
, arr
);
1768 mono_test_marshal_out_array_delegate (int *arr
, int len
, ArrayDelegate del
)
1770 del (len
, NULL
, arr
);
1772 if ((arr
[0] != 1) || (arr
[1] != 2))
1779 mono_test_marshal_out_string_array_delegate (char **arr
, int len
, ArrayDelegate del
)
1781 del (len
, NULL
, arr
);
1783 if (!strcmp (arr
[0], "ABC") && !strcmp (arr
[1], "DEF"))
1789 typedef int (*CdeclDelegate
) (int i
, int j
);
1792 mono_test_marshal_cdecl_delegate (CdeclDelegate del
)
1796 for (i
= 0; i
< 1000; ++i
)
1802 typedef char** (*ReturnStringArrayDelegate
) (int i
);
1805 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d
)
1813 if (strcmp (arr
[0], "ABC") || strcmp (arr
[1], "DEF"))
1824 add_delegate (int i
, int j
)
1830 mono_test_marshal_return_fnptr (void)
1832 return &add_delegate
;
1842 mono_test_marshal_bstr_in(BSTR bstr
)
1844 if (!wcscmp(bstr
, L
"mono_test_marshal_bstr_in"))
1850 mono_test_marshal_bstr_out(BSTR
* bstr
)
1852 *bstr
= SysAllocString(L
"mono_test_marshal_bstr_out");
1857 mono_test_marshal_variant_in_sbyte(VARIANT variant
)
1859 if (variant
.vt
== VT_I1
&& variant
.cVal
== 100)
1865 mono_test_marshal_variant_in_byte(VARIANT variant
)
1867 if (variant
.vt
== VT_UI1
&& variant
.bVal
== 100)
1873 mono_test_marshal_variant_in_short(VARIANT variant
)
1875 if (variant
.vt
== VT_I2
&& variant
.iVal
== 314)
1881 mono_test_marshal_variant_in_ushort(VARIANT variant
)
1883 if (variant
.vt
== VT_UI2
&& variant
.uiVal
== 314)
1889 mono_test_marshal_variant_in_int(VARIANT variant
)
1891 if (variant
.vt
== VT_I4
&& variant
.lVal
== 314)
1897 mono_test_marshal_variant_in_uint(VARIANT variant
)
1899 if (variant
.vt
== VT_UI4
&& variant
.ulVal
== 314)
1905 mono_test_marshal_variant_in_long(VARIANT variant
)
1907 if (variant
.vt
== VT_I8
&& variant
.llVal
== 314)
1913 mono_test_marshal_variant_in_ulong(VARIANT variant
)
1915 if (variant
.vt
== VT_UI8
&& variant
.ullVal
== 314)
1921 mono_test_marshal_variant_in_float(VARIANT variant
)
1923 if (variant
.vt
== VT_R4
&& (variant
.fltVal
- 3.14)/3.14 < .001)
1929 mono_test_marshal_variant_in_double(VARIANT variant
)
1931 if (variant
.vt
== VT_R8
&& (variant
.dblVal
- 3.14)/3.14 < .001)
1937 mono_test_marshal_variant_in_bstr(VARIANT variant
)
1939 if (variant
.vt
== VT_BSTR
&& !wcscmp(variant
.bstrVal
, L
"PI"))
1945 mono_test_marshal_variant_out_sbyte(VARIANT
* variant
)
1947 variant
->vt
= VT_I1
;
1948 variant
->cVal
= 100;
1954 mono_test_marshal_variant_out_byte(VARIANT
* variant
)
1956 variant
->vt
= VT_UI1
;
1957 variant
->bVal
= 100;
1963 mono_test_marshal_variant_out_short(VARIANT
* variant
)
1965 variant
->vt
= VT_I2
;
1966 variant
->iVal
= 314;
1972 mono_test_marshal_variant_out_ushort(VARIANT
* variant
)
1974 variant
->vt
= VT_UI2
;
1975 variant
->uiVal
= 314;
1981 mono_test_marshal_variant_out_int(VARIANT
* variant
)
1983 variant
->vt
= VT_I4
;
1984 variant
->lVal
= 314;
1990 mono_test_marshal_variant_out_uint(VARIANT
* variant
)
1992 variant
->vt
= VT_UI4
;
1993 variant
->ulVal
= 314;
1999 mono_test_marshal_variant_out_long(VARIANT
* variant
)
2001 variant
->vt
= VT_I8
;
2002 variant
->llVal
= 314;
2008 mono_test_marshal_variant_out_ulong(VARIANT
* variant
)
2010 variant
->vt
= VT_UI8
;
2011 variant
->ullVal
= 314;
2017 mono_test_marshal_variant_out_float(VARIANT
* variant
)
2019 variant
->vt
= VT_R4
;
2020 variant
->fltVal
= 3.14;
2026 mono_test_marshal_variant_out_double(VARIANT
* variant
)
2028 variant
->vt
= VT_R8
;
2029 variant
->dblVal
= 3.14;
2035 mono_test_marshal_variant_out_bstr(VARIANT
* variant
)
2037 variant
->vt
= VT_BSTR
;
2038 variant
->bstrVal
= SysAllocString(L
"PI");
2048 #define COM_STDCALL __stdcall
2050 #define COM_STDCALL __attribute__((stdcall))
2053 typedef struct MonoComObject MonoComObject
;
2057 int (COM_STDCALL
*QueryInterface
)(MonoComObject
* pUnk
, gpointer riid
, gpointer
* ppv
);
2058 int (COM_STDCALL
*AddRef
)(MonoComObject
* pUnk
);
2059 int (COM_STDCALL
*Release
)(MonoComObject
* pUnk
);
2060 int (COM_STDCALL
*Add
)(MonoComObject
* pUnk
, int a
, int b
, int* c
);
2061 int (COM_STDCALL
*Subtract
)(MonoComObject
* pUnk
, int a
, int b
, int* c
);
2064 struct MonoComObject
2070 int COM_STDCALL
MonoQueryInterface(MonoComObject
* pUnk
, gpointer riid
, gpointer
* ppv
)
2076 int COM_STDCALL
MonoAddRef(MonoComObject
* pUnk
)
2078 return ++(pUnk
->m_ref
);
2081 int COM_STDCALL
MonoRelease(MonoComObject
* pUnk
)
2083 return --(pUnk
->m_ref
);
2086 int COM_STDCALL
Add(MonoComObject
* pUnk
, int a
, int b
, int* c
)
2092 int COM_STDCALL
Subtract(MonoComObject
* pUnk
, int a
, int b
, int* c
)
2099 mono_test_marshal_com_object_create(MonoComObject
* *pUnk
)
2101 *pUnk
= g_new0 (MonoComObject
, 1);
2102 (*pUnk
)->vtbl
= g_new0 (MonoIUnknown
, 1);
2105 (*pUnk
)->vtbl
->QueryInterface
= MonoQueryInterface
;
2106 (*pUnk
)->vtbl
->AddRef
= MonoAddRef
;
2107 (*pUnk
)->vtbl
->Release
= MonoRelease
;
2108 (*pUnk
)->vtbl
->Add
= Add
;
2109 (*pUnk
)->vtbl
->Subtract
= Subtract
;
2116 mono_test_marshal_com_object_destroy(MonoComObject
*pUnk
)
2118 int ref
= --(pUnk
->m_ref
);
2126 mono_test_marshal_com_object_ref_count(MonoComObject
*pUnk
)