Bump corefx
[mono-project.git] / mono / tests / libtest.c
blob4517eda2f74f64ddc41f8e2453372f4b17e5fd12
1 #include <config.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <glib.h>
6 #include <gmodule.h>
7 #include <errno.h>
8 #include <time.h>
9 #include <math.h>
11 #ifdef WIN32
12 #include <windows.h>
13 #include "initguid.h"
14 #else
15 #include <pthread.h>
16 #endif
18 #ifdef WIN32
19 #define STDCALL __stdcall
20 #else
21 #define STDCALL
22 #endif
24 #ifdef __GNUC__
25 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
26 #endif
28 #ifdef WIN32
29 extern __declspec(dllimport) void __stdcall CoTaskMemFree(void *ptr);
30 #endif
32 typedef int (STDCALL *SimpleDelegate) (int a);
34 #if defined(WIN32) && defined (_MSC_VER)
35 #define LIBTEST_API __declspec(dllexport)
36 #elif defined(__GNUC__)
37 #define LIBTEST_API __attribute__ ((__visibility__ ("default")))
38 #else
39 #define LIBTEST_API
40 #endif
42 static void marshal_free (void *ptr)
44 #ifdef WIN32
45 CoTaskMemFree (ptr);
46 #else
47 g_free (ptr);
48 #endif
51 static void* marshal_alloc (gsize size)
53 #ifdef WIN32
54 return CoTaskMemAlloc (size);
55 #else
56 return g_malloc (size);
57 #endif
60 static void* marshal_alloc0 (gsize size)
62 #ifdef WIN32
63 void* ptr = CoTaskMemAlloc (size);
64 memset(ptr, 0, size);
65 return ptr;
66 #else
67 return g_malloc0 (size);
68 #endif
71 static char* marshal_strdup (const char *str)
73 #ifdef WIN32
74 int len;
75 char *buf;
77 if (!str)
78 return NULL;
80 len = strlen (str);
81 buf = (char *) CoTaskMemAlloc (len + 1);
82 return strcpy (buf, str);
83 #else
84 return g_strdup (str);
85 #endif
88 static gunichar2* marshal_bstr_alloc(const gchar* str)
90 #ifdef WIN32
91 gunichar2* ret = NULL;
92 gunichar2* temp = NULL;
93 temp = g_utf8_to_utf16 (str, -1, NULL, NULL, NULL);
94 ret = SysAllocString (temp);
95 g_free (temp);
96 return ret;
97 #else
98 gchar* ret = NULL;
99 int slen = strlen (str);
100 gunichar2* temp;
101 /* allocate len + 1 utf16 characters plus 4 byte integer for length*/
102 ret = (gchar *)g_malloc ((slen + 1) * sizeof(gunichar2) + sizeof(guint32));
103 if (ret == NULL)
104 return NULL;
105 temp = g_utf8_to_utf16 (str, -1, NULL, NULL, NULL);
106 memcpy (ret + sizeof(guint32), temp, slen * sizeof(gunichar2));
107 * ((guint32 *) ret) = slen * sizeof(gunichar2);
108 ret [4 + slen * sizeof(gunichar2)] = 0;
109 ret [5 + slen * sizeof(gunichar2)] = 0;
111 return (gunichar2*)(ret + 4);
112 #endif
115 #define marshal_new0(type,size) ((type *) marshal_alloc0 (sizeof (type)* (size)))
117 LIBTEST_API int STDCALL
118 mono_cominterop_is_supported (void)
120 #if defined(TARGET_X86) || defined(TARGET_AMD64)
121 return 1;
122 #endif
123 return 0;
126 LIBTEST_API unsigned short* STDCALL
127 test_lpwstr_marshal (unsigned short* chars, long length)
129 int i = 0;
130 unsigned short *res;
132 res = (unsigned short *)marshal_alloc (2 * (length + 1));
134 // printf("test_lpwstr_marshal()\n");
136 while ( i < length ) {
137 // printf("X|%u|\n", chars[i]);
138 res [i] = chars[i];
139 i++;
142 res [i] = 0;
144 return res;
148 LIBTEST_API void STDCALL
149 test_lpwstr_marshal_out (unsigned short** chars)
151 int i = 0;
152 const char abc[] = "ABC";
153 glong len = strlen(abc);
155 *chars = (unsigned short *)marshal_alloc (2 * (len + 1));
157 while ( i < len ) {
158 (*chars) [i] = abc[i];
159 i++;
162 (*chars) [i] = 0;
165 typedef struct {
166 int b;
167 int a;
168 int c;
169 } union_test_1_type;
171 LIBTEST_API int STDCALL
172 mono_union_test_1 (union_test_1_type u1) {
173 // printf ("Got values %d %d %d\n", u1.b, u1.a, u1.c);
174 return u1.a + u1.b + u1.c;
177 LIBTEST_API int STDCALL
178 mono_return_int (int a) {
179 // printf ("Got value %d\n", a);
180 return a;
183 LIBTEST_API float STDCALL
184 mono_test_marshal_pass_return_float (float f) {
185 return f + 1.0;
188 struct ss
190 int i;
193 LIBTEST_API int STDCALL
194 mono_return_int_ss (struct ss a) {
195 // printf ("Got value %d\n", a.i);
196 return a.i;
199 LIBTEST_API struct ss STDCALL
200 mono_return_ss (struct ss a) {
201 // printf ("Got value %d\n", a.i);
202 a.i++;
203 return a;
206 struct sc1
208 char c[1];
211 LIBTEST_API struct sc1 STDCALL
212 mono_return_sc1 (struct sc1 a) {
213 // printf ("Got value %d\n", a.c[0]);
214 a.c[0]++;
215 return a;
219 struct sc3
221 char c[3];
224 LIBTEST_API struct sc3 STDCALL
225 mono_return_sc3 (struct sc3 a) {
226 // printf ("Got values %d %d %d\n", a.c[0], a.c[1], a.c[2]);
227 a.c[0]++;
228 a.c[1] += 2;
229 a.c[2] += 3;
230 return a;
233 struct sc5
235 char c[5];
238 LIBTEST_API struct sc5 STDCALL
239 mono_return_sc5 (struct sc5 a) {
240 // printf ("Got values %d %d %d %d %d\n", a.c[0], a.c[1], a.c[2], a.c[3], a.c[4]);
241 a.c[0]++;
242 a.c[1] += 2;
243 a.c[2] += 3;
244 a.c[3] += 4;
245 a.c[4] += 5;
246 return a;
249 union su
251 int i1;
252 int i2;
255 LIBTEST_API int STDCALL
256 mono_return_int_su (union su a) {
257 // printf ("Got value %d\n", a.i1);
258 return a.i1;
261 struct FI {
262 float f1;
263 float f2;
264 float f3;
267 struct NestedFloat {
268 struct FI fi;
269 float f4;
272 LIBTEST_API struct NestedFloat STDCALL
273 mono_return_nested_float (void)
275 struct NestedFloat f;
276 f.fi.f1 = 1.0;
277 f.fi.f2 = 2.0;
278 f.fi.f3 = 3.0;
279 f.f4 = 4.0;
280 return f;
283 LIBTEST_API int STDCALL
284 mono_test_many_int_arguments (int a, int b, int c, int d, int e,
285 int f, int g, int h, int i, int j);
286 LIBTEST_API short STDCALL
287 mono_test_many_short_arguments (short a, short b, short c, short d, short e,
288 short f, short g, short h, short i, short j);
289 LIBTEST_API char STDCALL
290 mono_test_many_char_arguments (char a, char b, char c, char d, char e,
291 char f, char g, char h, char i, char j);
293 LIBTEST_API int STDCALL
294 mono_test_many_int_arguments (int a, int b, int c, int d, int e, int f, int g, int h, int i, int j)
296 return a + b + c + d + e + f + g + h + i + j;
299 LIBTEST_API short STDCALL
300 mono_test_many_short_arguments (short a, short b, short c, short d, short e, short f, short g, short h, short i, short j)
302 return a + b + c + d + e + f + g + h + i + j;
305 LIBTEST_API char STDCALL
306 mono_test_many_byte_arguments (char a, char b, char c, char d, char e, char f, char g, char h, char i, char j)
308 return a + b + c + d + e + f + g + h + i + j;
311 LIBTEST_API float STDCALL
312 mono_test_many_float_arguments (float a, float b, float c, float d, float e, float f, float g, float h, float i, float j)
314 return a + b + c + d + e + f + g + h + i + j;
317 LIBTEST_API double STDCALL
318 mono_test_many_double_arguments (double a, double b, double c, double d, double e, double f, double g, double h, double i, double j)
320 return a + b + c + d + e + f + g + h + i + j;
323 LIBTEST_API double STDCALL
324 mono_test_split_double_arguments (double a, double b, float c, double d, double e)
326 return a + b + c + d + e;
329 LIBTEST_API int STDCALL
330 mono_test_puts_static (char *s)
332 // printf ("TEST %s\n", s);
333 return 1;
336 typedef int (STDCALL *SimpleDelegate3) (int a, int b);
338 LIBTEST_API int STDCALL
339 mono_invoke_delegate (SimpleDelegate3 delegate)
341 int res;
343 // printf ("start invoke %p\n", delegate);
345 res = delegate (2, 3);
347 // printf ("end invoke\n");
349 return res;
352 LIBTEST_API int STDCALL
353 mono_invoke_simple_delegate (SimpleDelegate d)
355 return d (4);
358 LIBTEST_API int STDCALL
359 mono_test_marshal_char (short a1)
361 if (a1 == 'a')
362 return 0;
364 return 1;
367 LIBTEST_API void STDCALL
368 mono_test_marshal_char_array (gunichar2 *s)
370 const char m[] = "abcdef";
371 gunichar2* s2;
372 glong len;
374 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
376 len = (len * 2) + 2;
377 memcpy (s, s2, len);
379 g_free (s2);
382 LIBTEST_API int STDCALL
383 mono_test_marshal_ansi_char_array (char *s)
385 const char m[] = "abcdef";
387 if (strncmp ("qwer", s, 4))
388 return 1;
390 memcpy (s, m, sizeof (m));
391 return 0;
394 LIBTEST_API int STDCALL
395 mono_test_marshal_unicode_char_array (gunichar2 *s)
397 const char m[] = "abcdef";
398 const char expected[] = "qwer";
399 gunichar2 *s1, *s2;
400 glong len1, len2;
402 s1 = g_utf8_to_utf16 (m, -1, NULL, &len1, NULL);
403 s2 = g_utf8_to_utf16 (expected, -1, NULL, &len2, NULL);
404 len1 = (len1 * 2);
405 len2 = (len2 * 2);
407 if (memcmp (s, s2, len2))
408 return 1;
410 memcpy (s, s1, len1);
411 return 0;
414 LIBTEST_API int STDCALL
415 mono_test_empty_pinvoke (int i)
417 return i;
420 LIBTEST_API int STDCALL
421 mono_test_marshal_bool_byref (int a, int *b, int c)
423 int res = *b;
425 *b = 1;
427 return res;
430 LIBTEST_API int STDCALL
431 mono_test_marshal_bool_in_as_I1_U1 (char bTrue, char bFalse)
433 if (!bTrue)
434 return 1;
435 if (bFalse)
436 return 2;
437 return 0;
440 LIBTEST_API int STDCALL
441 mono_test_marshal_bool_out_as_I1_U1 (char* bTrue, char* bFalse)
443 if (!bTrue || !bFalse)
444 return 3;
446 *bTrue = 1;
447 *bFalse = 0;
449 return 0;
452 LIBTEST_API int STDCALL
453 mono_test_marshal_bool_ref_as_I1_U1 (char* bTrue, char* bFalse)
455 if (!bTrue || !bFalse)
456 return 4;
458 if (!(*bTrue))
459 return 5;
460 if (*bFalse)
461 return 6;
463 *bFalse = 1;
464 *bTrue = 0;
466 return 0;
469 LIBTEST_API int STDCALL
470 mono_test_marshal_array (int *a1)
472 int i, sum = 0;
474 for (i = 0; i < 50; i++)
475 sum += a1 [i];
477 return sum;
480 LIBTEST_API int STDCALL
481 mono_test_marshal_inout_array (int *a1)
483 int i, sum = 0;
485 for (i = 0; i < 50; i++) {
486 sum += a1 [i];
487 a1 [i] = 50 - a1 [i];
490 return sum;
493 LIBTEST_API int /* cdecl */
494 mono_test_marshal_inout_array_cdecl (int *a1)
496 return mono_test_marshal_inout_array (a1);
499 LIBTEST_API int STDCALL
500 mono_test_marshal_out_array (int *a1)
502 int i;
504 for (i = 0; i < 50; i++) {
505 a1 [i] = i;
508 return 0;
511 LIBTEST_API int STDCALL
512 mono_test_marshal_out_byref_array_out_size_param (int **out_arr, int *out_len)
514 int *arr;
515 int i, len;
517 len = 4;
518 arr = (gint32 *)marshal_alloc (sizeof (gint32) * len);
519 for (i = 0; i < len; ++i)
520 arr [i] = i;
521 *out_arr = arr;
522 *out_len = len;
524 return 0;
527 LIBTEST_API int STDCALL
528 mono_test_marshal_out_lparray_out_size_param (int *arr, int *out_len)
530 int i, len;
532 len = 4;
533 for (i = 0; i < len; ++i)
534 arr [i] = i;
535 *out_len = len;
537 return 0;
540 LIBTEST_API int STDCALL
541 mono_test_marshal_inout_nonblittable_array (gunichar2 *a1)
543 int i, sum = 0;
545 for (i = 0; i < 10; i++) {
546 a1 [i] = 'F';
549 return sum;
552 typedef struct {
553 int a;
554 int b;
555 int c;
556 const char *d;
557 gunichar2 *d2;
558 } simplestruct;
560 typedef struct {
561 double x;
562 double y;
563 } point;
565 LIBTEST_API simplestruct STDCALL
566 mono_test_return_vtype (int i)
568 simplestruct res;
569 static gunichar2 test2 [] = { 'T', 'E', 'S', 'T', '2', 0 };
571 res.a = 0;
572 res.b = 1;
573 res.c = 0;
574 res.d = "TEST";
575 res.d2 = test2;
577 return res;
580 LIBTEST_API void STDCALL
581 mono_test_delegate_struct (void)
583 // printf ("TEST\n");
586 typedef char* (STDCALL *ReturnStringDelegate) (const char *s);
588 LIBTEST_API char * STDCALL
589 mono_test_return_string (ReturnStringDelegate func)
591 char *res;
593 // printf ("mono_test_return_string\n");
595 res = func ("TEST");
596 marshal_free (res);
598 // printf ("got string: %s\n", res);
599 return marshal_strdup ("12345");
602 typedef int (STDCALL *RefVTypeDelegate) (int a, simplestruct *ss, int b);
604 LIBTEST_API int STDCALL
605 mono_test_ref_vtype (int a, simplestruct *ss, int b, RefVTypeDelegate func)
607 if (a == 1 && b == 2 && ss->a == 0 && ss->b == 1 && ss->c == 0 &&
608 !strcmp (ss->d, "TEST1")) {
609 ss->a = 1;
610 ss->b = 0;
611 ss->c = 1;
612 ss->d = "TEST2";
614 return func (a, ss, b);
617 return 1;
620 typedef int (STDCALL *OutVTypeDelegate) (int a, simplestruct *ss, int b);
622 LIBTEST_API int STDCALL
623 mono_test_marshal_out_struct (int a, simplestruct *ss, int b, OutVTypeDelegate func)
625 /* Check that the input pointer is ignored */
626 ss->d = (const char *)0x12345678;
628 func (a, ss, b);
630 if (ss->a && ss->b && ss->c && !strcmp (ss->d, "TEST3"))
631 return 0;
632 else
633 return 1;
636 typedef int (STDCALL *InVTypeDelegate) (int a, simplestruct *ss, int b);
638 LIBTEST_API int STDCALL
639 mono_test_marshal_in_struct (int a, simplestruct *ss, int b, InVTypeDelegate func)
641 simplestruct ss2;
642 int res;
644 memcpy (&ss2, ss, sizeof (simplestruct));
646 res = func (a, ss, b);
647 if (res) {
648 printf ("mono_test_marshal_in_struct () failed: %d\n", res);
649 return 1;
652 /* Check that no modifications is made to the struct */
653 if (ss2.a == ss->a && ss2.b == ss->b && ss2.c == ss->c && ss2.d == ss->d)
654 return 0;
655 else
656 return 1;
659 typedef struct {
660 int a;
661 SimpleDelegate func, func2, func3;
662 } DelegateStruct;
664 LIBTEST_API DelegateStruct STDCALL
665 mono_test_marshal_delegate_struct (DelegateStruct ds)
667 DelegateStruct res;
669 res.a = ds.func (ds.a) + ds.func2 (ds.a) + (ds.func3 == NULL ? 0 : 1);
670 res.func = ds.func;
671 res.func2 = ds.func2;
672 res.func3 = NULL;
674 return res;
677 LIBTEST_API int STDCALL
678 mono_test_marshal_struct (simplestruct ss)
680 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
681 !strcmp (ss.d, "TEST"))
682 return 0;
684 return 1;
687 LIBTEST_API int STDCALL
688 mono_test_marshal_byref_struct (simplestruct *ss, int a, int b, int c, char *d)
690 gboolean res = (ss->a == a && ss->b == b && ss->c == c && strcmp (ss->d, d) == 0);
692 marshal_free ((char*)ss->d);
694 ss->a = !ss->a;
695 ss->b = !ss->b;
696 ss->c = !ss->c;
697 ss->d = marshal_strdup ("DEF");
699 return res ? 0 : 1;
702 typedef struct {
703 int a;
704 int b;
705 int c;
706 char *d;
707 unsigned char e;
708 double f;
709 unsigned char g;
710 guint64 h;
711 } simplestruct2;
713 LIBTEST_API int STDCALL
714 mono_test_marshal_struct2 (simplestruct2 ss)
716 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
717 !strcmp (ss.d, "TEST") &&
718 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
719 return 0;
721 return 1;
724 /* on HP some of the struct should be on the stack and not in registers */
725 LIBTEST_API int STDCALL
726 mono_test_marshal_struct2_2 (int i, int j, int k, simplestruct2 ss)
728 if (i != 10 || j != 11 || k != 12)
729 return 1;
730 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
731 !strcmp (ss.d, "TEST") &&
732 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
733 return 0;
735 return 1;
738 LIBTEST_API int STDCALL
739 mono_test_marshal_lpstruct (simplestruct *ss)
741 if (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
742 !strcmp (ss->d, "TEST"))
743 return 0;
745 return 1;
748 LIBTEST_API int STDCALL
749 mono_test_marshal_lpstruct_blittable (point *p)
751 if (p->x == 1.0 && p->y == 2.0)
752 return 0;
753 else
754 return 1;
757 LIBTEST_API int STDCALL
758 mono_test_marshal_struct_array (simplestruct2 *ss)
760 if (! (ss[0].a == 0 && ss[0].b == 1 && ss[0].c == 0 &&
761 !strcmp (ss[0].d, "TEST") &&
762 ss[0].e == 99 && ss[0].f == 1.5 && ss[0].g == 42 && ss[0].h == (guint64)123))
763 return 1;
765 if (! (ss[1].a == 0 && ss[1].b == 0 && ss[1].c == 0 &&
766 !strcmp (ss[1].d, "TEST2") &&
767 ss[1].e == 100 && ss[1].f == 2.5 && ss[1].g == 43 && ss[1].h == (guint64)124))
768 return 1;
770 return 0;
773 typedef struct long_align_struct {
774 gint32 a;
775 gint64 b;
776 gint64 c;
777 } long_align_struct;
779 LIBTEST_API int STDCALL
780 mono_test_marshal_long_align_struct_array (long_align_struct *ss)
782 return ss[0].a + ss[0].b + ss[0].c + ss[1].a + ss[1].b + ss[1].c;
785 LIBTEST_API simplestruct2 * STDCALL
786 mono_test_marshal_class (int i, int j, int k, simplestruct2 *ss, int l)
788 simplestruct2 *res;
790 if (!ss)
791 return NULL;
793 if (i != 10 || j != 11 || k != 12 || l != 14)
794 return NULL;
795 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
796 !strcmp (ss->d, "TEST") &&
797 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
798 return NULL;
800 res = marshal_new0 (simplestruct2, 1);
801 memcpy (res, ss, sizeof (simplestruct2));
802 res->d = marshal_strdup ("TEST");
803 return res;
806 LIBTEST_API int STDCALL
807 mono_test_marshal_byref_class (simplestruct2 **ssp)
809 simplestruct2 *ss = *ssp;
810 simplestruct2 *res;
812 if (! (ss->a == 0 && ss->b == 1 && ss->c == 0 &&
813 !strcmp (ss->d, "TEST") &&
814 ss->e == 99 && ss->f == 1.5 && ss->g == 42 && ss->h == (guint64)123))
815 return 1;
817 res = marshal_new0 (simplestruct2, 1);
818 memcpy (res, ss, sizeof (simplestruct2));
819 res->d = marshal_strdup ("TEST-RES");
821 *ssp = res;
822 return 0;
825 static void *
826 get_sp (void)
828 int i;
829 void *p;
831 /* Yes, this is correct, we are only trying to determine the value of the stack here */
832 p = &i;
833 return p;
836 LIBTEST_API int STDCALL
837 reliable_delegate (int a)
839 return a;
843 * Checks whether get_sp() works as expected. It doesn't work with gcc-2.95.3 on linux.
845 static gboolean
846 is_get_sp_reliable (void)
848 void *sp1, *sp2;
850 reliable_delegate(1);
851 sp1 = get_sp();
852 reliable_delegate(1);
853 sp2 = get_sp();
854 return sp1 == sp2;
857 LIBTEST_API int STDCALL
858 mono_test_marshal_delegate (SimpleDelegate delegate)
860 void *sp1, *sp2;
862 /* Check that the delegate wrapper is stdcall */
863 delegate (2);
864 sp1 = get_sp ();
865 delegate (2);
866 sp2 = get_sp ();
867 if (is_get_sp_reliable())
868 g_assert (sp1 == sp2);
870 return delegate (2);
873 static int STDCALL inc_cb (int i)
875 return i + 1;
878 LIBTEST_API int STDCALL
879 mono_test_marshal_out_delegate (SimpleDelegate *delegate)
881 *delegate = inc_cb;
883 return 0;
886 LIBTEST_API SimpleDelegate STDCALL
887 mono_test_marshal_return_delegate (SimpleDelegate delegate)
889 return delegate;
892 typedef int (STDCALL *DelegateByrefDelegate) (void *);
894 LIBTEST_API int STDCALL
895 mono_test_marshal_delegate_ref_delegate (DelegateByrefDelegate del)
897 int (STDCALL *ptr) (int i);
899 del (&ptr);
901 return ptr (54);
904 static int STDCALL
905 return_plus_one (int i)
907 return i + 1;
910 LIBTEST_API SimpleDelegate STDCALL
911 mono_test_marshal_return_delegate_2 (void)
913 return return_plus_one;
916 typedef simplestruct (STDCALL *SimpleDelegate2) (simplestruct ss);
918 static gboolean
919 is_utf16_equals (gunichar2 *s1, const char *s2)
921 char *s;
922 int res;
924 s = g_utf16_to_utf8 (s1, -1, NULL, NULL, NULL);
925 res = strcmp (s, s2);
926 g_free (s);
928 return res == 0;
931 LIBTEST_API int STDCALL
932 mono_test_marshal_delegate2 (SimpleDelegate2 delegate)
934 simplestruct ss, res;
936 ss.a = 0;
937 ss.b = 1;
938 ss.c = 0;
939 ss.d = "TEST";
940 ss.d2 = g_utf8_to_utf16 ("TEST2", -1, NULL, NULL, NULL);
942 res = delegate (ss);
943 if (! (res.a && !res.b && res.c && !strcmp (res.d, "TEST-RES") && is_utf16_equals (res.d2, "TEST2-RES")))
944 return 1;
946 return 0;
949 typedef simplestruct* (STDCALL *SimpleDelegate4) (simplestruct *ss);
951 LIBTEST_API int STDCALL
952 mono_test_marshal_delegate4 (SimpleDelegate4 delegate)
954 simplestruct ss;
955 simplestruct *res;
957 ss.a = 0;
958 ss.b = 1;
959 ss.c = 0;
960 ss.d = "TEST";
962 /* Check argument */
963 res = delegate (&ss);
964 if (!res)
965 return 1;
967 /* Check return value */
968 if (! (!res->a && res->b && !res->c && !strcmp (res->d, "TEST")))
969 return 2;
971 /* Check NULL argument and NULL result */
972 res = delegate (NULL);
973 if (res)
974 return 3;
976 return 0;
979 typedef int (STDCALL *SimpleDelegate5) (simplestruct **ss);
981 LIBTEST_API int STDCALL
982 mono_test_marshal_delegate5 (SimpleDelegate5 delegate)
984 simplestruct ss;
985 int res;
986 simplestruct *ptr;
988 ss.a = 0;
989 ss.b = 1;
990 ss.c = 0;
991 ss.d = "TEST";
993 ptr = &ss;
995 res = delegate (&ptr);
996 if (res != 0)
997 return 1;
999 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
1000 return 2;
1002 return 0;
1005 LIBTEST_API int STDCALL
1006 mono_test_marshal_delegate6 (SimpleDelegate5 delegate)
1008 delegate (NULL);
1009 return 0;
1012 typedef int (STDCALL *SimpleDelegate7) (simplestruct **ss);
1014 LIBTEST_API int STDCALL
1015 mono_test_marshal_delegate7 (SimpleDelegate7 delegate)
1017 int res;
1018 simplestruct *ptr;
1020 /* Check that the input pointer is ignored */
1021 ptr = (simplestruct *)0x12345678;
1023 res = delegate (&ptr);
1024 if (res != 0)
1025 return 1;
1027 if (!(ptr->a && !ptr->b && ptr->c && !strcmp (ptr->d, "RES")))
1028 return 2;
1030 return 0;
1033 typedef int (STDCALL *InOutByvalClassDelegate) (simplestruct *ss);
1035 LIBTEST_API int STDCALL
1036 mono_test_marshal_inout_byval_class_delegate (InOutByvalClassDelegate delegate)
1038 int res;
1039 simplestruct ss;
1041 ss.a = FALSE;
1042 ss.b = TRUE;
1043 ss.c = FALSE;
1044 ss.d = g_strdup_printf ("%s", "FOO");
1046 res = delegate (&ss);
1047 if (res != 0)
1048 return 1;
1050 if (!(ss.a && !ss.b && ss.c && !strcmp (ss.d, "RES")))
1051 return 2;
1053 return 0;
1056 typedef int (STDCALL *SimpleDelegate8) (gunichar2 *s);
1058 LIBTEST_API int STDCALL
1059 mono_test_marshal_delegate8 (SimpleDelegate8 delegate, gunichar2 *s)
1061 return delegate (s);
1064 typedef int (STDCALL *return_int_fnt) (int i);
1065 typedef int (STDCALL *SimpleDelegate9) (return_int_fnt d);
1067 LIBTEST_API int STDCALL
1068 mono_test_marshal_delegate9 (SimpleDelegate9 delegate, gpointer ftn)
1070 return delegate ((return_int_fnt)ftn);
1073 static int STDCALL
1074 return_self (int i)
1076 return i;
1079 LIBTEST_API int STDCALL
1080 mono_test_marshal_delegate10 (SimpleDelegate9 delegate)
1082 return delegate (return_self);
1085 typedef int (STDCALL *PrimitiveByrefDelegate) (int *i);
1087 LIBTEST_API int STDCALL
1088 mono_test_marshal_primitive_byref_delegate (PrimitiveByrefDelegate delegate)
1090 int i = 1;
1092 int res = delegate (&i);
1093 if (res != 0)
1094 return res;
1096 if (i != 2)
1097 return 2;
1099 return 0;
1102 typedef int (STDCALL *return_int_delegate) (int i);
1104 typedef return_int_delegate (STDCALL *ReturnDelegateDelegate) (void);
1106 LIBTEST_API int STDCALL
1107 mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d)
1109 return (d ()) (55);
1112 typedef int (STDCALL *VirtualDelegate) (int);
1114 LIBTEST_API int STDCALL
1115 mono_test_marshal_virtual_delegate (VirtualDelegate del)
1117 return del (42);
1120 typedef char* (STDCALL *IcallDelegate) (const char *);
1121 LIBTEST_API int STDCALL
1122 mono_test_marshal_icall_delegate (IcallDelegate del)
1124 char *res = del ("ABC");
1125 return strcmp (res, "ABC") == 0 ? 0 : 1;
1128 LIBTEST_API int STDCALL
1129 mono_test_marshal_stringbuilder (char *s, int n)
1131 const char m[] = "This is my message. Isn't it nice?";
1133 if (strcmp (s, "ABCD") != 0)
1134 return 1;
1135 memcpy(s, m, n);
1136 s [n] = '\0';
1137 return 0;
1140 LIBTEST_API int STDCALL
1141 mono_test_marshal_stringbuilder_append (char *s, int length)
1143 const char out_sentinel[] = "CSHARP_";
1144 const char out_len = strlen (out_sentinel);
1146 for (int i=0; i < length; i++) {
1147 s [i] = out_sentinel [i % out_len];
1150 s [length] = '\0';
1153 return 0;
1156 LIBTEST_API int STDCALL
1157 mono_test_marshal_stringbuilder_default (char *s, int n)
1159 const char m[] = "This is my message. Isn't it nice?";
1161 memcpy(s, m, n);
1162 s [n] = '\0';
1163 return 0;
1166 LIBTEST_API int STDCALL
1167 mono_test_marshal_stringbuilder_unicode (gunichar2 *s, int n)
1169 const char m[] = "This is my message. Isn't it nice?";
1170 gunichar2* s2;
1171 glong len;
1173 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1175 len = (len * 2) + 2;
1176 if (len > (n * 2))
1177 len = n * 2;
1178 memcpy (s, s2, len);
1180 g_free (s2);
1182 return 0;
1185 LIBTEST_API void STDCALL
1186 mono_test_marshal_stringbuilder_out (char **s)
1188 const char m[] = "This is my message. Isn't it nice?";
1189 char *str;
1191 str = (char *)marshal_alloc (strlen (m) + 1);
1192 memcpy (str, m, strlen (m) + 1);
1194 *s = str;
1197 LIBTEST_API int STDCALL
1198 mono_test_marshal_stringbuilder_out_unicode (gunichar2 **s)
1200 const char m[] = "This is my message. Isn't it nice?";
1201 gunichar2 *s2;
1202 glong len;
1204 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
1206 len = (len * 2) + 2;
1207 *s = (gunichar2 *)marshal_alloc (len);
1208 memcpy (*s, s2, len);
1210 g_free (s2);
1212 return 0;
1215 LIBTEST_API int STDCALL
1216 mono_test_marshal_stringbuilder_ref (char **s)
1218 const char m[] = "This is my message. Isn't it nice?";
1219 char *str;
1221 if (strcmp (*s, "ABC"))
1222 return 1;
1224 str = (char *)marshal_alloc (strlen (m) + 1);
1225 memcpy (str, m, strlen (m) + 1);
1227 *s = str;
1228 return 0;
1231 #ifdef __GNUC__
1232 #pragma GCC diagnostic push
1233 #pragma GCC diagnostic ignored "-Wc++-compat"
1234 #endif
1237 * Standard C and C++ doesn't allow empty structs, empty structs will always have a size of 1 byte.
1238 * GCC have an extension to allow empty structs, https://gcc.gnu.org/onlinedocs/gcc/Empty-Structures.html.
1239 * This cause a little dilemma since runtime build using none GCC compiler will not be compatible with
1240 * GCC build C libraries and the other way around. On platforms where empty structs has size of 1 byte
1241 * it must be represented in call and cannot be dropped. On Windows x64 structs will always be represented in the call
1242 * meaning that an empty struct must have a representation in the callee in order to correctly follow the ABI used by the
1243 * C/C++ standard and the runtime.
1245 typedef struct {
1246 #if !defined(__GNUC__) || defined(TARGET_WIN32)
1247 char a;
1248 #endif
1249 } EmptyStruct;
1251 #ifdef __GNUC__
1252 #pragma GCC diagnostic pop
1253 #endif
1255 LIBTEST_API int STDCALL
1256 mono_test_marshal_empty_string_array (char **array)
1258 return (array == NULL) ? 0 : 1;
1261 LIBTEST_API int STDCALL
1262 mono_test_marshal_string_array (char **array)
1264 if (strcmp (array [0], "ABC"))
1265 return 1;
1266 if (strcmp (array [1], "DEF"))
1267 return 2;
1269 if (array [2] != NULL)
1270 return 3;
1272 return 0;
1275 LIBTEST_API int STDCALL
1276 mono_test_marshal_byref_string_array (char ***array)
1278 if (*array == NULL)
1279 return 0;
1281 if (strcmp ((*array) [0], "Alpha"))
1282 return 2;
1283 if (strcmp ((*array) [1], "Beta"))
1284 return 2;
1285 if (strcmp ((*array) [2], "Gamma"))
1286 return 2;
1288 return 1;
1291 LIBTEST_API int STDCALL
1292 mono_test_marshal_stringbuilder_array (char **array)
1294 if (strcmp (array [0], "ABC"))
1295 return 1;
1296 if (strcmp (array [1], "DEF"))
1297 return 2;
1299 strcpy (array [0], "DEF");
1300 strcpy (array [1], "ABC");
1302 return 0;
1305 LIBTEST_API int STDCALL
1306 mono_test_marshal_unicode_string_array (gunichar2 **array, char **array2)
1308 GError *error = NULL;
1309 char *s;
1311 s = g_utf16_to_utf8 (array [0], -1, NULL, NULL, &error);
1312 if (strcmp (s, "ABC")) {
1313 g_free (s);
1314 return 1;
1316 else
1317 g_free (s);
1319 s = g_utf16_to_utf8 (array [1], -1, NULL, NULL, &error);
1320 if (strcmp (s, "DEF")) {
1321 g_free (s);
1322 return 2;
1324 else
1325 g_free (s);
1327 if (strcmp (array2 [0], "ABC"))
1328 return 3;
1330 if (strcmp (array2 [1], "DEF"))
1331 return 4;
1333 return 0;
1336 /* this does not work on Redhat gcc 2.96 */
1337 LIBTEST_API int STDCALL
1338 mono_test_empty_struct (int a, EmptyStruct es, int b)
1340 // printf ("mono_test_empty_struct %d %d\n", a, b);
1342 // Intel icc on ia64 passes 'es' in 2 registers
1343 #if defined(__ia64) && defined(__INTEL_COMPILER)
1344 return 0;
1345 #else
1346 if (a == 1 && b == 2)
1347 return 0;
1348 return 1;
1349 #endif
1352 LIBTEST_API EmptyStruct STDCALL
1353 mono_test_return_empty_struct (int a)
1355 EmptyStruct s;
1357 memset (&s, 0, sizeof (s));
1359 g_assert (a == 42);
1361 return s;
1364 typedef struct {
1365 char a[100];
1366 } ByValStrStruct;
1368 LIBTEST_API ByValStrStruct * STDCALL
1369 mono_test_byvalstr_gen (void)
1371 ByValStrStruct *ret;
1373 ret = (ByValStrStruct *)malloc (sizeof (ByValStrStruct));
1374 memset(ret, 'a', sizeof(ByValStrStruct)-1);
1375 ret->a[sizeof(ByValStrStruct)-1] = 0;
1377 return ret;
1380 LIBTEST_API int STDCALL
1381 mono_test_byvalstr_check (ByValStrStruct* data, char* correctString)
1383 int ret;
1385 ret = strcmp(data->a, correctString);
1386 // printf ("T1: %s\n", data->a);
1387 // printf ("T2: %s\n", correctString);
1389 /* we need g_free because the allocation was performed by mono_test_byvalstr_gen */
1390 g_free (data);
1391 return (ret != 0);
1394 typedef struct {
1395 guint16 a[4];
1396 int flag;
1397 } ByValStrStruct_Unicode;
1399 LIBTEST_API int STDCALL
1400 mono_test_byvalstr_check_unicode (ByValStrStruct_Unicode *ref, int test)
1402 if (ref->flag != 0x1234abcd){
1403 printf ("overwritten data");
1404 return 1;
1407 if (test == 1 || test == 3){
1408 if (ref->a [0] != '1' ||
1409 ref->a [1] != '2' ||
1410 ref->a [2] != '3')
1411 return 1;
1412 return 0;
1414 if (test == 2){
1415 if (ref->a [0] != '1' ||
1416 ref->a [1] != '2')
1417 return 1;
1418 return 0;
1420 return 10;
1423 LIBTEST_API int STDCALL
1424 NameManglingAnsi (char *data)
1426 return data [0] + data [1] + data [2];
1429 LIBTEST_API int STDCALL
1430 NameManglingAnsiA (char *data)
1432 g_assert_not_reached ();
1435 LIBTEST_API int STDCALL
1436 NameManglingAnsiW (char *data)
1438 g_assert_not_reached ();
1441 LIBTEST_API int STDCALL
1442 NameManglingAnsi2A (char *data)
1444 return data [0] + data [1] + data [2];
1447 LIBTEST_API int STDCALL
1448 NameManglingAnsi2W (char *data)
1450 g_assert_not_reached ();
1453 LIBTEST_API int STDCALL
1454 NameManglingUnicode (char *data)
1456 g_assert_not_reached ();
1459 LIBTEST_API int STDCALL
1460 NameManglingUnicodeW (gunichar2 *data)
1462 return data [0] + data [1] + data [2];
1465 LIBTEST_API int STDCALL
1466 NameManglingUnicode2 (gunichar2 *data)
1468 return data [0] + data [1] + data [2];
1471 LIBTEST_API int STDCALL
1472 NameManglingAutoW (char *data)
1474 #ifdef WIN32
1475 return (data [0] + data [1] + data [2]) == 131 ? 0 : 1;
1476 #else
1477 g_assert_not_reached ();
1478 #endif
1481 LIBTEST_API int STDCALL
1482 NameManglingAuto (char *data)
1484 #ifndef WIN32
1485 return (data [0] + data [1] + data [2]) == 198 ? 0 : 1;
1486 #else
1487 g_assert_not_reached ();
1488 #endif
1491 typedef int (STDCALL *intcharFunc)(const char*);
1493 LIBTEST_API void STDCALL
1494 callFunction (intcharFunc f)
1496 f ("ABC");
1499 typedef struct {
1500 const char* str;
1501 int i;
1502 } SimpleObj;
1504 LIBTEST_API int STDCALL
1505 class_marshal_test0 (SimpleObj *obj1)
1507 // printf ("class_marshal_test0 %s %d\n", obj1->str, obj1->i);
1509 if (strcmp(obj1->str, "T1"))
1510 return -1;
1511 if (obj1->i != 4)
1512 return -2;
1514 return 0;
1517 LIBTEST_API int STDCALL
1518 class_marshal_test4 (SimpleObj *obj1)
1520 if (obj1)
1521 return -1;
1523 return 0;
1526 LIBTEST_API void STDCALL
1527 class_marshal_test1 (SimpleObj **obj1)
1529 SimpleObj *res = (SimpleObj *)malloc (sizeof (SimpleObj));
1531 res->str = marshal_strdup ("ABC");
1532 res->i = 5;
1534 *obj1 = res;
1537 LIBTEST_API int STDCALL
1538 class_marshal_test2 (SimpleObj **obj1)
1540 // printf ("class_marshal_test2 %s %d\n", (*obj1)->str, (*obj1)->i);
1542 if (strcmp((*obj1)->str, "ABC"))
1543 return -1;
1544 if ((*obj1)->i != 5)
1545 return -2;
1547 return 0;
1550 LIBTEST_API int STDCALL
1551 string_marshal_test0 (char *str)
1553 if (strcmp (str, "TEST0"))
1554 return -1;
1556 return 0;
1559 LIBTEST_API void STDCALL
1560 string_marshal_test1 (const char **str)
1562 *str = marshal_strdup ("TEST1");
1565 LIBTEST_API int STDCALL
1566 string_marshal_test2 (char **str)
1568 // printf ("string_marshal_test2 %s\n", *str);
1570 if (strcmp (*str, "TEST1"))
1571 return -1;
1573 *str = marshal_strdup ("TEST2");
1575 return 0;
1578 LIBTEST_API int STDCALL
1579 string_marshal_test3 (char *str)
1581 if (str)
1582 return -1;
1584 return 0;
1587 typedef struct {
1588 int a;
1589 int b;
1590 } BlittableClass;
1592 LIBTEST_API BlittableClass* STDCALL
1593 TestBlittableClass (BlittableClass *vl)
1595 BlittableClass *res;
1597 // printf ("TestBlittableClass %d %d\n", vl->a, vl->b);
1599 if (vl) {
1600 vl->a++;
1601 vl->b++;
1603 res = marshal_new0 (BlittableClass, 1);
1604 memcpy (res, vl, sizeof (BlittableClass));
1605 } else {
1606 res = marshal_new0 (BlittableClass, 1);
1607 res->a = 42;
1608 res->b = 43;
1611 return res;
1614 typedef struct OSVERSIONINFO_STRUCT
1616 int a;
1617 int b;
1618 } OSVERSIONINFO_STRUCT;
1620 LIBTEST_API int STDCALL
1621 MyGetVersionEx (OSVERSIONINFO_STRUCT *osvi)
1624 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1626 osvi->a += 1;
1627 osvi->b += 1;
1629 return osvi->a + osvi->b;
1632 LIBTEST_API int STDCALL
1633 BugGetVersionEx (int a, int b, int c, int d, int e, int f, int g, int h, OSVERSIONINFO_STRUCT *osvi)
1636 // printf ("GOT %d %d\n", osvi->a, osvi->b);
1638 osvi->a += 1;
1639 osvi->b += 1;
1641 return osvi->a + osvi->b;
1644 LIBTEST_API int STDCALL
1645 mono_test_marshal_point (point pt)
1647 // printf("point %g %g\n", pt.x, pt.y);
1648 if (pt.x == 1.25 && pt.y == 3.5)
1649 return 0;
1651 return 1;
1654 typedef struct {
1655 int x;
1656 double y;
1657 } mixed_point;
1659 LIBTEST_API int STDCALL
1660 mono_test_marshal_mixed_point (mixed_point pt)
1662 // printf("mixed point %d %g\n", pt.x, pt.y);
1663 if (pt.x == 5 && pt.y == 6.75)
1664 return 0;
1666 return 1;
1669 LIBTEST_API int STDCALL
1670 mono_test_marshal_mixed_point_2 (mixed_point *pt)
1672 if (pt->x != 5 || pt->y != 6.75)
1673 return 1;
1675 pt->x = 10;
1676 pt->y = 12.35;
1678 return 0;
1681 LIBTEST_API int STDCALL
1682 marshal_test_ref_bool(int i, char *b1, short *b2, int *b3)
1684 int res = 1;
1685 if (*b1 != 0 && *b1 != 1)
1686 return 1;
1687 if (*b2 != 0 && *b2 != -1) /* variant_bool */
1688 return 1;
1689 if (*b3 != 0 && *b3 != 1)
1690 return 1;
1691 if (i == ((*b1 << 2) | (-*b2 << 1) | *b3))
1692 res = 0;
1693 *b1 = !*b1;
1694 *b2 = ~*b2;
1695 *b3 = !*b3;
1696 return res;
1699 struct BoolStruct
1701 int i;
1702 char b1;
1703 short b2; /* variant_bool */
1704 int b3;
1707 LIBTEST_API int STDCALL
1708 marshal_test_bool_struct(struct BoolStruct *s)
1710 int res = 1;
1711 if (s->b1 != 0 && s->b1 != 1)
1712 return 1;
1713 if (s->b2 != 0 && s->b2 != -1)
1714 return 1;
1715 if (s->b3 != 0 && s->b3 != 1)
1716 return 1;
1717 if (s->i == ((s->b1 << 2) | (-s->b2 << 1) | s->b3))
1718 res = 0;
1719 s->b1 = !s->b1;
1720 s->b2 = ~s->b2;
1721 s->b3 = !s->b3;
1722 return res;
1725 typedef struct {
1726 gint64 l;
1727 } LongStruct2;
1729 typedef struct {
1730 int i;
1731 LongStruct2 l;
1732 } LongStruct;
1734 LIBTEST_API int STDCALL
1735 mono_test_marshal_long_struct (LongStruct *s)
1737 return s->i + s->l.l;
1740 LIBTEST_API void STDCALL
1741 mono_test_last_error (int err)
1743 #ifdef WIN32
1744 SetLastError (err);
1745 #else
1746 errno = err;
1747 #endif
1750 LIBTEST_API int STDCALL
1751 mono_test_asany (void *ptr, int what)
1753 switch (what) {
1754 case 1:
1755 return (*(int*)ptr == 5) ? 0 : 1;
1756 case 2:
1757 return strcmp (ptr, "ABC") == 0 ? 0 : 1;
1758 case 3: {
1759 simplestruct2 ss = *(simplestruct2*)ptr;
1761 if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
1762 !strcmp (ss.d, "TEST") &&
1763 ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
1764 return 0;
1765 else
1766 return 1;
1768 case 4: {
1769 GError *error = NULL;
1770 char *s;
1772 s = g_utf16_to_utf8 ((const gunichar2 *)ptr, -1, NULL, NULL, &error);
1774 if (!s)
1775 return 1;
1777 if (!strcmp (s, "ABC")) {
1778 g_free (s);
1779 return 0;
1781 else {
1782 g_free (s);
1783 return 1;
1786 default:
1787 g_assert_not_reached ();
1790 return 1;
1793 typedef struct
1795 int i;
1796 int j;
1797 int k;
1798 char *s;
1799 } AsAnyStruct;
1801 LIBTEST_API int STDCALL
1802 mono_test_marshal_asany_in (void* ptr)
1804 AsAnyStruct *asAny = (AsAnyStruct *)ptr;
1805 int res = asAny->i + asAny->j + asAny->k;
1807 return res;
1810 LIBTEST_API int STDCALL
1811 mono_test_marshal_asany_inout (void* ptr)
1813 AsAnyStruct *asAny = (AsAnyStruct *)ptr;
1814 int res = asAny->i + asAny->j + asAny->k;
1816 marshal_free (asAny->s);
1818 asAny->i = 10;
1819 asAny->j = 20;
1820 asAny->k = 30;
1821 asAny->s = 0;
1823 return res;
1826 LIBTEST_API int STDCALL
1827 mono_test_marshal_asany_out (void* ptr)
1829 AsAnyStruct *asAny = (AsAnyStruct *)ptr;
1830 int res = asAny->i + asAny->j + asAny->k;
1832 asAny->i = 10;
1833 asAny->j = 20;
1834 asAny->k = 30;
1835 asAny->s = 0;
1837 return res;
1841 * AMD64 marshalling tests.
1844 typedef struct amd64_struct1 {
1845 int i;
1846 int j;
1847 int k;
1848 int l;
1849 } amd64_struct1;
1851 LIBTEST_API amd64_struct1 STDCALL
1852 mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
1854 s.i ++;
1855 s.j ++;
1856 s.k ++;
1857 s.l ++;
1859 return s;
1862 LIBTEST_API amd64_struct1 STDCALL
1863 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)
1865 s.i ++;
1866 s.j ++;
1867 s.k ++;
1868 s.l += 1 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8;
1870 return s;
1873 typedef struct amd64_struct2 {
1874 int i;
1875 int j;
1876 } amd64_struct2;
1878 LIBTEST_API amd64_struct2 STDCALL
1879 mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
1881 s.i ++;
1882 s.j ++;
1884 return s;
1887 typedef struct amd64_struct3 {
1888 int i;
1889 } amd64_struct3;
1891 LIBTEST_API amd64_struct3 STDCALL
1892 mono_test_marshal_amd64_pass_return_struct3 (amd64_struct3 s)
1894 s.i ++;
1896 return s;
1899 typedef struct amd64_struct4 {
1900 double d1, d2;
1901 } amd64_struct4;
1903 LIBTEST_API amd64_struct4 STDCALL
1904 mono_test_marshal_amd64_pass_return_struct4 (amd64_struct4 s)
1906 s.d1 ++;
1907 s.d2 ++;
1909 return s;
1913 * IA64 marshalling tests.
1915 typedef struct test_struct5 {
1916 float d1, d2;
1917 } test_struct5;
1919 LIBTEST_API test_struct5 STDCALL
1920 mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, test_struct5 s, int i, double d3, double d4)
1922 s.d1 += d1 + d2 + i;
1923 s.d2 += d3 + d4 + i;
1925 return s;
1928 typedef struct test_struct6 {
1929 double d1, d2;
1930 } test_struct6;
1932 LIBTEST_API test_struct6 STDCALL
1933 mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, test_struct6 s, int i, double d3, double d4)
1935 s.d1 += d1 + d2 + i;
1936 s.d2 += d3 + d4;
1938 return s;
1941 static guint32 custom_res [2];
1943 LIBTEST_API void* STDCALL
1944 mono_test_marshal_pass_return_custom (int i, guint32 *ptr, int j)
1946 /* ptr will be freed by CleanupNative, so make a copy */
1947 custom_res [0] = 0; /* not allocated by AllocHGlobal */
1948 custom_res [1] = ptr [1];
1950 return &custom_res;
1953 LIBTEST_API int STDCALL
1954 mono_test_marshal_pass_out_custom (int i, guint32 **ptr, int j)
1956 custom_res [0] = 0;
1957 custom_res [1] = i + j + 10;
1959 *ptr = custom_res;
1961 return 0;
1964 LIBTEST_API int STDCALL
1965 mono_test_marshal_pass_inout_custom (int i, guint32 *ptr, int j)
1967 ptr [0] = 0;
1968 ptr [1] = i + ptr [1] + j;
1970 return 0;
1973 LIBTEST_API int STDCALL
1974 mono_test_marshal_pass_out_byval_custom (int i, guint32 *ptr, int j)
1976 return ptr == NULL ? 0 : 1;
1979 LIBTEST_API int STDCALL
1980 mono_test_marshal_pass_byref_custom (int i, guint32 **ptr, int j)
1982 (*ptr)[1] += i + j;
1984 return 0;
1987 LIBTEST_API void* STDCALL
1988 mono_test_marshal_pass_return_custom2 (int i, guint32 *ptr, int j)
1990 g_assert_not_reached ();
1992 return NULL;
1995 LIBTEST_API void* STDCALL
1996 mono_test_marshal_pass_return_custom_null (int i, guint32 *ptr, int j)
1998 g_assert (ptr == NULL);
2000 return NULL;
2003 typedef void *(STDCALL *PassReturnPtrDelegate) (void *ptr);
2005 LIBTEST_API int STDCALL
2006 mono_test_marshal_pass_return_custom_in_delegate (PassReturnPtrDelegate del)
2008 guint32 buf [2];
2009 guint32 res;
2010 guint32 *ptr;
2012 buf [0] = 0;
2013 buf [1] = 10;
2015 ptr = (guint32 *)del (&buf);
2017 res = ptr [1];
2019 #ifdef WIN32
2020 /* FIXME: Freed with FreeHGlobal */
2021 #else
2022 g_free (ptr);
2023 #endif
2025 return res;
2028 LIBTEST_API int STDCALL
2029 mono_test_marshal_pass_return_custom_null_in_delegate (PassReturnPtrDelegate del)
2031 void *ptr = del (NULL);
2033 return (ptr == NULL) ? 15 : 0;
2036 typedef void (STDCALL *CustomOutParamDelegate) (void **pptr);
2038 LIBTEST_API int STDCALL
2039 mono_test_marshal_custom_out_param_delegate (CustomOutParamDelegate del)
2041 void* pptr = del;
2043 del (&pptr);
2045 if(pptr != NULL)
2046 return 1;
2048 return 0;
2051 typedef int (STDCALL *ReturnEnumDelegate) (int e);
2053 LIBTEST_API int STDCALL
2054 mono_test_marshal_return_enum_delegate (ReturnEnumDelegate func)
2056 return func (1);
2059 typedef struct {
2060 int a, b, c;
2061 gint64 d;
2062 } BlittableStruct;
2064 typedef BlittableStruct (STDCALL *SimpleDelegate10) (BlittableStruct ss);
2066 LIBTEST_API int STDCALL
2067 mono_test_marshal_blittable_struct_delegate (SimpleDelegate10 delegate)
2069 BlittableStruct ss, res;
2071 ss.a = 1;
2072 ss.b = 2;
2073 ss.c = 3;
2074 ss.d = 55;
2076 res = delegate (ss);
2077 if (! ((res.a == -1) && (res.b == -2) && (res.c == -3) && (res.d == -55)))
2078 return 1;
2080 return 0;
2083 LIBTEST_API int STDCALL
2084 mono_test_stdcall_name_mangling (int a, int b, int c)
2086 return a + b + c;
2089 LIBTEST_API int
2090 mono_test_stdcall_mismatch_1 (int a, int b, int c)
2092 return a + b + c;
2095 LIBTEST_API int STDCALL
2096 mono_test_stdcall_mismatch_2 (int a, int b, int c)
2098 return a + b + c;
2102 * PASSING AND RETURNING SMALL STRUCTURES FROM DELEGATES TESTS
2105 typedef struct {
2106 int i;
2107 } SmallStruct1;
2109 typedef SmallStruct1 (STDCALL *SmallStructDelegate1) (SmallStruct1 ss);
2111 LIBTEST_API int STDCALL
2112 mono_test_marshal_small_struct_delegate1 (SmallStructDelegate1 delegate)
2114 SmallStruct1 ss, res;
2116 ss.i = 1;
2118 res = delegate (ss);
2119 if (! (res.i == -1))
2120 return 1;
2122 return 0;
2125 typedef struct {
2126 gint16 i, j;
2127 } SmallStruct2;
2129 typedef SmallStruct2 (STDCALL *SmallStructDelegate2) (SmallStruct2 ss);
2131 LIBTEST_API int STDCALL
2132 mono_test_marshal_small_struct_delegate2 (SmallStructDelegate2 delegate)
2134 SmallStruct2 ss, res;
2136 ss.i = 2;
2137 ss.j = 3;
2139 res = delegate (ss);
2140 if (! ((res.i == -2) && (res.j == -3)))
2141 return 1;
2143 return 0;
2146 typedef struct {
2147 gint16 i;
2148 gint8 j;
2149 } SmallStruct3;
2151 typedef SmallStruct3 (STDCALL *SmallStructDelegate3) (SmallStruct3 ss);
2153 LIBTEST_API int STDCALL
2154 mono_test_marshal_small_struct_delegate3 (SmallStructDelegate3 delegate)
2156 SmallStruct3 ss, res;
2158 ss.i = 1;
2159 ss.j = 2;
2161 res = delegate (ss);
2162 if (! ((res.i == -1) && (res.j == -2)))
2163 return 1;
2165 return 0;
2168 typedef struct {
2169 gint16 i;
2170 } SmallStruct4;
2172 typedef SmallStruct4 (STDCALL *SmallStructDelegate4) (SmallStruct4 ss);
2174 LIBTEST_API int STDCALL
2175 mono_test_marshal_small_struct_delegate4 (SmallStructDelegate4 delegate)
2177 SmallStruct4 ss, res;
2179 ss.i = 1;
2181 res = delegate (ss);
2182 if (! (res.i == -1))
2183 return 1;
2185 return 0;
2188 typedef struct {
2189 gint64 i;
2190 } SmallStruct5;
2192 typedef SmallStruct5 (STDCALL *SmallStructDelegate5) (SmallStruct5 ss);
2194 LIBTEST_API int STDCALL
2195 mono_test_marshal_small_struct_delegate5 (SmallStructDelegate5 delegate)
2197 SmallStruct5 ss, res;
2199 ss.i = 5;
2201 res = delegate (ss);
2202 if (! (res.i == -5))
2203 return 1;
2205 return 0;
2208 typedef struct {
2209 int i, j;
2210 } SmallStruct6;
2212 typedef SmallStruct6 (STDCALL *SmallStructDelegate6) (SmallStruct6 ss);
2214 LIBTEST_API int STDCALL
2215 mono_test_marshal_small_struct_delegate6 (SmallStructDelegate6 delegate)
2217 SmallStruct6 ss, res;
2219 ss.i = 1;
2220 ss.j = 2;
2222 res = delegate (ss);
2223 if (! ((res.i == -1) && (res.j == -2)))
2224 return 1;
2226 return 0;
2229 typedef struct {
2230 int i;
2231 gint16 j;
2232 } SmallStruct7;
2234 typedef SmallStruct7 (STDCALL *SmallStructDelegate7) (SmallStruct7 ss);
2236 LIBTEST_API int STDCALL
2237 mono_test_marshal_small_struct_delegate7 (SmallStructDelegate7 delegate)
2239 SmallStruct7 ss, res;
2241 ss.i = 1;
2242 ss.j = 2;
2244 res = delegate (ss);
2245 if (! ((res.i == -1) && (res.j == -2)))
2246 return 1;
2248 return 0;
2251 typedef struct {
2252 float i;
2253 } SmallStruct8;
2255 typedef SmallStruct8 (STDCALL *SmallStructDelegate8) (SmallStruct8 ss);
2257 LIBTEST_API int STDCALL
2258 mono_test_marshal_small_struct_delegate8 (SmallStructDelegate8 delegate)
2260 SmallStruct8 ss, res;
2262 ss.i = 1.0;
2264 res = delegate (ss);
2265 if (! ((res.i == -1.0)))
2266 return 1;
2268 return 0;
2271 typedef struct {
2272 double i;
2273 } SmallStruct9;
2275 typedef SmallStruct9 (STDCALL *SmallStructDelegate9) (SmallStruct9 ss);
2277 LIBTEST_API int STDCALL
2278 mono_test_marshal_small_struct_delegate9 (SmallStructDelegate9 delegate)
2280 SmallStruct9 ss, res;
2282 ss.i = 1.0;
2284 res = delegate (ss);
2285 if (! ((res.i == -1.0)))
2286 return 1;
2288 return 0;
2291 typedef struct {
2292 float i, j;
2293 } SmallStruct10;
2295 typedef SmallStruct10 (STDCALL *SmallStructDelegate10) (SmallStruct10 ss);
2297 LIBTEST_API int STDCALL
2298 mono_test_marshal_small_struct_delegate10 (SmallStructDelegate10 delegate)
2300 SmallStruct10 ss, res;
2302 ss.i = 1.0;
2303 ss.j = 2.0;
2305 res = delegate (ss);
2306 if (! ((res.i == -1.0) && (res.j == -2.0)))
2307 return 1;
2309 return 0;
2312 typedef struct {
2313 float i;
2314 int j;
2315 } SmallStruct11;
2317 typedef SmallStruct11 (STDCALL *SmallStructDelegate11) (SmallStruct11 ss);
2319 LIBTEST_API int STDCALL
2320 mono_test_marshal_small_struct_delegate11 (SmallStructDelegate11 delegate)
2322 SmallStruct11 ss, res;
2324 ss.i = 1.0;
2325 ss.j = 2;
2327 res = delegate (ss);
2328 if (! ((res.i == -1.0) && (res.j == -2)))
2329 return 1;
2331 return 0;
2334 typedef int (STDCALL *ArrayDelegate) (int i, char *j, void *arr);
2336 LIBTEST_API int STDCALL
2337 mono_test_marshal_array_delegate (void *arr, int len, ArrayDelegate del)
2339 return del (len, NULL, arr);
2342 typedef int (STDCALL *ArrayDelegateLong) (gint64 i, char *j, void *arr);
2344 LIBTEST_API int STDCALL
2345 mono_test_marshal_array_delegate_long (void *arr, gint64 len, ArrayDelegateLong del)
2347 return del (len, NULL, arr);
2350 LIBTEST_API int STDCALL
2351 mono_test_marshal_out_array_delegate (int *arr, int len, ArrayDelegate del)
2353 del (len, NULL, arr);
2355 if ((arr [0] != 1) || (arr [1] != 2))
2356 return 1;
2357 else
2358 return 0;
2361 typedef gunichar2* (STDCALL *UnicodeStringDelegate) (gunichar2 *message);
2363 LIBTEST_API int STDCALL
2364 mono_test_marshal_return_unicode_string_delegate (UnicodeStringDelegate del)
2366 const char m[] = "abcdef";
2367 gunichar2 *s2, *res;
2368 glong len;
2370 s2 = g_utf8_to_utf16 (m, -1, NULL, &len, NULL);
2372 res = del (s2);
2374 marshal_free (res);
2376 return 0;
2379 LIBTEST_API int STDCALL
2380 mono_test_marshal_out_string_array_delegate (char **arr, int len, ArrayDelegate del)
2382 del (len, NULL, arr);
2384 if (!strcmp (arr [0], "ABC") && !strcmp (arr [1], "DEF"))
2385 return 0;
2386 else
2387 return 1;
2390 typedef int (*CdeclDelegate) (int i, int j);
2392 LIBTEST_API int STDCALL
2393 mono_test_marshal_cdecl_delegate (CdeclDelegate del)
2395 int i;
2397 for (i = 0; i < 1000; ++i)
2398 del (1, 2);
2400 return 0;
2403 typedef char** (STDCALL *ReturnStringArrayDelegate) (int i);
2405 LIBTEST_API int STDCALL
2406 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d)
2408 char **arr = d (2);
2409 int res;
2411 if (arr == NULL)
2412 return 3;
2414 if (strcmp (arr [0], "ABC") || strcmp (arr [1], "DEF"))
2415 res = 1;
2416 else
2417 res = 0;
2419 marshal_free (arr);
2421 return res;
2424 typedef int (STDCALL *ByrefStringDelegate) (char **s);
2426 LIBTEST_API int STDCALL
2427 mono_test_marshal_byref_string_delegate (ByrefStringDelegate d)
2429 char *s = (char*)"ABC";
2430 int res;
2432 res = d (&s);
2433 if (res != 0)
2434 return res;
2436 if (!strcmp (s, "DEF"))
2437 res = 0;
2438 else
2439 res = 2;
2441 marshal_free (s);
2443 return res;
2446 LIBTEST_API int STDCALL
2447 add_delegate (int i, int j)
2449 return i + j;
2452 LIBTEST_API gpointer STDCALL
2453 mono_test_marshal_return_fnptr (void)
2455 return &add_delegate;
2458 LIBTEST_API int STDCALL
2459 mono_xr (int code)
2461 printf ("codigo %x\n", code);
2462 return code + 1234;
2465 typedef struct {
2466 int handle;
2467 } HandleRef;
2469 LIBTEST_API HandleRef STDCALL
2470 mono_xr_as_handle (int code)
2472 HandleRef ref;
2474 memset (&ref, 0, sizeof (ref));
2476 return ref;
2479 typedef struct {
2480 int a;
2481 void *handle1;
2482 void *handle2;
2483 int b;
2484 } HandleStructs;
2486 LIBTEST_API int STDCALL
2487 mono_safe_handle_struct_ref (HandleStructs *x)
2489 printf ("Dingus Ref! \n");
2490 printf ("Values: %d %d %p %p\n", x->a, x->b, x->handle1, x->handle2);
2491 if (x->a != 1234)
2492 return 1;
2493 if (x->b != 8743)
2494 return 2;
2496 if (x->handle1 != (void*) 0x7080feed)
2497 return 3;
2499 if (x->handle2 != (void*) 0x1234abcd)
2500 return 4;
2502 return 0xf00d;
2505 LIBTEST_API int STDCALL
2506 mono_safe_handle_struct (HandleStructs x)
2508 printf ("Dingus Standard! \n");
2509 printf ("Values: %d %d %p %p\n", x.a, x.b, x.handle1, x.handle2);
2510 if (x.a != 1234)
2511 return 1;
2512 if (x.b != 8743)
2513 return 2;
2515 if (x.handle1 != (void*) 0x7080feed)
2516 return 3;
2518 if (x.handle2 != (void*) 0x1234abcd)
2519 return 4;
2521 return 0xf00f;
2524 typedef struct {
2525 void *a;
2526 } TrivialHandle;
2528 LIBTEST_API int STDCALL
2529 mono_safe_handle_struct_simple (TrivialHandle x)
2531 printf ("The value is %p\n", x.a);
2532 return ((int)(gsize)x.a) * 2;
2535 LIBTEST_API int STDCALL
2536 mono_safe_handle_return (void)
2538 return 0x1000f00d;
2541 LIBTEST_API void STDCALL
2542 mono_safe_handle_ref (void **handle)
2544 if (*handle != 0){
2545 *handle = (void *) 0xbad;
2546 return;
2549 *handle = (void *) 0x800d;
2552 LIBTEST_API double STDCALL
2553 mono_test_marshal_date_time (double d, double *d2)
2555 *d2 = d;
2556 return d;
2560 * COM INTEROP TESTS
2563 #ifndef WIN32
2565 typedef struct {
2566 guint16 vt;
2567 guint16 wReserved1;
2568 guint16 wReserved2;
2569 guint16 wReserved3;
2570 union {
2571 gint64 llVal;
2572 gint32 lVal;
2573 guint8 bVal;
2574 gint16 iVal;
2575 float fltVal;
2576 double dblVal;
2577 gint16 boolVal;
2578 gunichar2* bstrVal;
2579 gint8 cVal;
2580 guint16 uiVal;
2581 guint32 ulVal;
2582 guint64 ullVal;
2583 gpointer byref;
2584 struct {
2585 gpointer pvRecord;
2586 gpointer pRecInfo;
2589 } VARIANT;
2591 typedef enum {
2592 VARIANT_TRUE = -1,
2593 VARIANT_FALSE = 0
2594 } VariantBool;
2596 typedef enum {
2597 VT_EMPTY = 0,
2598 VT_NULL = 1,
2599 VT_I2 = 2,
2600 VT_I4 = 3,
2601 VT_R4 = 4,
2602 VT_R8 = 5,
2603 VT_CY = 6,
2604 VT_DATE = 7,
2605 VT_BSTR = 8,
2606 VT_DISPATCH = 9,
2607 VT_ERROR = 10,
2608 VT_BOOL = 11,
2609 VT_VARIANT = 12,
2610 VT_UNKNOWN = 13,
2611 VT_DECIMAL = 14,
2612 VT_I1 = 16,
2613 VT_UI1 = 17,
2614 VT_UI2 = 18,
2615 VT_UI4 = 19,
2616 VT_I8 = 20,
2617 VT_UI8 = 21,
2618 VT_INT = 22,
2619 VT_UINT = 23,
2620 VT_VOID = 24,
2621 VT_HRESULT = 25,
2622 VT_PTR = 26,
2623 VT_SAFEARRAY = 27,
2624 VT_CARRAY = 28,
2625 VT_USERDEFINED = 29,
2626 VT_LPSTR = 30,
2627 VT_LPWSTR = 31,
2628 VT_RECORD = 36,
2629 VT_FILETIME = 64,
2630 VT_BLOB = 65,
2631 VT_STREAM = 66,
2632 VT_STORAGE = 67,
2633 VT_STREAMED_OBJECT = 68,
2634 VT_STORED_OBJECT = 69,
2635 VT_BLOB_OBJECT = 70,
2636 VT_CF = 71,
2637 VT_CLSID = 72,
2638 VT_VECTOR = 4096,
2639 VT_ARRAY = 8192,
2640 VT_BYREF = 16384
2641 } VarEnum;
2643 void VariantInit(VARIANT* vt)
2645 vt->vt = VT_EMPTY;
2648 typedef struct
2650 guint32 a;
2651 guint16 b;
2652 guint16 c;
2653 guint8 d[8];
2654 } GUID;
2656 #define S_OK 0
2658 #endif
2660 LIBTEST_API int STDCALL
2661 mono_test_marshal_bstr_in(gunichar2* bstr)
2663 gint32 result = 0;
2664 gchar* bstr_utf8 = g_utf16_to_utf8 (bstr, -1, NULL, NULL, NULL);
2665 result = strcmp("mono_test_marshal_bstr_in", bstr_utf8);
2666 g_free(bstr_utf8);
2667 if (result == 0)
2668 return 0;
2669 return 1;
2672 LIBTEST_API int STDCALL
2673 mono_test_marshal_bstr_out(gunichar2** bstr)
2675 *bstr = marshal_bstr_alloc ("mono_test_marshal_bstr_out");
2676 return 0;
2679 LIBTEST_API int STDCALL
2680 mono_test_marshal_bstr_in_null(gunichar2* bstr)
2682 if (!bstr)
2683 return 0;
2684 return 1;
2687 LIBTEST_API int STDCALL
2688 mono_test_marshal_bstr_out_null(gunichar2** bstr)
2690 *bstr = NULL;
2691 return 0;
2694 LIBTEST_API int STDCALL
2695 mono_test_marshal_variant_in_sbyte(VARIANT variant)
2697 if (variant.vt == VT_I1 && variant.cVal == 100)
2698 return 0;
2699 return 1;
2702 LIBTEST_API int STDCALL
2703 mono_test_marshal_variant_in_byte(VARIANT variant)
2705 if (variant.vt == VT_UI1 && variant.bVal == 100)
2706 return 0;
2707 return 1;
2710 LIBTEST_API int STDCALL
2711 mono_test_marshal_variant_in_short(VARIANT variant)
2713 if (variant.vt == VT_I2 && variant.iVal == 314)
2714 return 0;
2715 return 1;
2718 LIBTEST_API int STDCALL
2719 mono_test_marshal_variant_in_ushort(VARIANT variant)
2721 if (variant.vt == VT_UI2 && variant.uiVal == 314)
2722 return 0;
2723 return 1;
2726 LIBTEST_API int STDCALL
2727 mono_test_marshal_variant_in_int(VARIANT variant)
2729 if (variant.vt == VT_I4 && variant.lVal == 314)
2730 return 0;
2731 return 1;
2734 LIBTEST_API int STDCALL
2735 mono_test_marshal_variant_in_uint(VARIANT variant)
2737 if (variant.vt == VT_UI4 && variant.ulVal == 314)
2738 return 0;
2739 return 1;
2742 LIBTEST_API int STDCALL
2743 mono_test_marshal_variant_in_long(VARIANT variant)
2745 if (variant.vt == VT_I8 && variant.llVal == 314)
2746 return 0;
2747 return 1;
2750 LIBTEST_API int STDCALL
2751 mono_test_marshal_variant_in_ulong(VARIANT variant)
2753 if (variant.vt == VT_UI8 && variant.ullVal == 314)
2754 return 0;
2755 return 1;
2758 LIBTEST_API int STDCALL
2759 mono_test_marshal_variant_in_float(VARIANT variant)
2761 if (variant.vt == VT_R4 && (variant.fltVal - 3.14)/3.14 < .001)
2762 return 0;
2763 return 1;
2766 LIBTEST_API int STDCALL
2767 mono_test_marshal_variant_in_double(VARIANT variant)
2769 if (variant.vt == VT_R8 && (variant.dblVal - 3.14)/3.14 < .001)
2770 return 0;
2771 return 1;
2774 LIBTEST_API int STDCALL
2775 mono_test_marshal_variant_in_bstr(VARIANT variant)
2777 gint32 result = 0;
2778 gchar* bstr_utf8 = g_utf16_to_utf8 (variant.bstrVal, -1, NULL, NULL, NULL);
2779 result = strcmp("PI", bstr_utf8);
2780 g_free(bstr_utf8);
2782 if (variant.vt == VT_BSTR && !result)
2783 return 0;
2784 return 1;
2787 LIBTEST_API int STDCALL
2788 mono_test_marshal_variant_in_bool_true (VARIANT variant)
2790 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_TRUE)
2791 return 0;
2792 return 1;
2795 LIBTEST_API int STDCALL
2796 mono_test_marshal_variant_in_bool_false (VARIANT variant)
2798 if (variant.vt == VT_BOOL && variant.boolVal == VARIANT_FALSE)
2799 return 0;
2800 return 1;
2803 LIBTEST_API int STDCALL
2804 mono_test_marshal_variant_out_sbyte(VARIANT* variant)
2806 variant->vt = VT_I1;
2807 variant->cVal = 100;
2809 return 0;
2812 LIBTEST_API int STDCALL
2813 mono_test_marshal_variant_out_sbyte_byref(VARIANT* variant)
2815 variant->vt = VT_I1|VT_BYREF;
2816 variant->byref = marshal_alloc(1);
2817 *((gint8*)variant->byref) = 100;
2819 return 0;
2822 LIBTEST_API int STDCALL
2823 mono_test_marshal_variant_out_byte(VARIANT* variant)
2825 variant->vt = VT_UI1;
2826 variant->bVal = 100;
2828 return 0;
2831 LIBTEST_API int STDCALL
2832 mono_test_marshal_variant_out_byte_byref(VARIANT* variant)
2834 variant->vt = VT_UI1|VT_BYREF;
2835 variant->byref = marshal_alloc(1);
2836 *((gint8*)variant->byref) = 100;
2838 return 0;
2841 LIBTEST_API int STDCALL
2842 mono_test_marshal_variant_out_short(VARIANT* variant)
2844 variant->vt = VT_I2;
2845 variant->iVal = 314;
2847 return 0;
2850 LIBTEST_API int STDCALL
2851 mono_test_marshal_variant_out_short_byref(VARIANT* variant)
2853 variant->vt = VT_I2|VT_BYREF;
2854 variant->byref = marshal_alloc(2);
2855 *((gint16*)variant->byref) = 314;
2857 return 0;
2860 LIBTEST_API int STDCALL
2861 mono_test_marshal_variant_out_ushort(VARIANT* variant)
2863 variant->vt = VT_UI2;
2864 variant->uiVal = 314;
2866 return 0;
2869 LIBTEST_API int STDCALL
2870 mono_test_marshal_variant_out_ushort_byref(VARIANT* variant)
2872 variant->vt = VT_UI2|VT_BYREF;
2873 variant->byref = marshal_alloc(2);
2874 *((guint16*)variant->byref) = 314;
2876 return 0;
2879 LIBTEST_API int STDCALL
2880 mono_test_marshal_variant_out_int(VARIANT* variant)
2882 variant->vt = VT_I4;
2883 variant->lVal = 314;
2885 return 0;
2888 LIBTEST_API int STDCALL
2889 mono_test_marshal_variant_out_int_byref(VARIANT* variant)
2891 variant->vt = VT_I4|VT_BYREF;
2892 variant->byref = marshal_alloc(4);
2893 *((gint32*)variant->byref) = 314;
2895 return 0;
2898 LIBTEST_API int STDCALL
2899 mono_test_marshal_variant_out_uint(VARIANT* variant)
2901 variant->vt = VT_UI4;
2902 variant->ulVal = 314;
2904 return 0;
2907 LIBTEST_API int STDCALL
2908 mono_test_marshal_variant_out_uint_byref(VARIANT* variant)
2910 variant->vt = VT_UI4|VT_BYREF;
2911 variant->byref = marshal_alloc(4);
2912 *((guint32*)variant->byref) = 314;
2914 return 0;
2917 LIBTEST_API int STDCALL
2918 mono_test_marshal_variant_out_long(VARIANT* variant)
2920 variant->vt = VT_I8;
2921 variant->llVal = 314;
2923 return 0;
2926 LIBTEST_API int STDCALL
2927 mono_test_marshal_variant_out_long_byref(VARIANT* variant)
2929 variant->vt = VT_I8|VT_BYREF;
2930 variant->byref = marshal_alloc(8);
2931 *((gint64*)variant->byref) = 314;
2933 return 0;
2936 LIBTEST_API int STDCALL
2937 mono_test_marshal_variant_out_ulong(VARIANT* variant)
2939 variant->vt = VT_UI8;
2940 variant->ullVal = 314;
2942 return 0;
2945 LIBTEST_API int STDCALL
2946 mono_test_marshal_variant_out_ulong_byref(VARIANT* variant)
2948 variant->vt = VT_UI8|VT_BYREF;
2949 variant->byref = marshal_alloc(8);
2950 *((guint64*)variant->byref) = 314;
2952 return 0;
2955 LIBTEST_API int STDCALL
2956 mono_test_marshal_variant_out_float(VARIANT* variant)
2958 variant->vt = VT_R4;
2959 variant->fltVal = 3.14;
2961 return 0;
2964 LIBTEST_API int STDCALL
2965 mono_test_marshal_variant_out_float_byref(VARIANT* variant)
2967 variant->vt = VT_R4|VT_BYREF;
2968 variant->byref = marshal_alloc(4);
2969 *((float*)variant->byref) = 3.14;
2971 return 0;
2974 LIBTEST_API int STDCALL
2975 mono_test_marshal_variant_out_double(VARIANT* variant)
2977 variant->vt = VT_R8;
2978 variant->dblVal = 3.14;
2980 return 0;
2983 LIBTEST_API int STDCALL
2984 mono_test_marshal_variant_out_double_byref(VARIANT* variant)
2986 variant->vt = VT_R8|VT_BYREF;
2987 variant->byref = marshal_alloc(8);
2988 *((double*)variant->byref) = 3.14;
2990 return 0;
2993 LIBTEST_API int STDCALL
2994 mono_test_marshal_variant_out_bstr(VARIANT* variant)
2996 variant->vt = VT_BSTR;
2997 variant->bstrVal = marshal_bstr_alloc("PI");
2999 return 0;
3002 LIBTEST_API int STDCALL
3003 mono_test_marshal_variant_out_bstr_byref(VARIANT* variant)
3005 variant->vt = VT_BSTR|VT_BYREF;
3006 variant->byref = marshal_alloc(sizeof(gpointer));
3007 *((gunichar**)variant->byref) = (gunichar*)marshal_bstr_alloc("PI");
3009 return 0;
3012 LIBTEST_API int STDCALL
3013 mono_test_marshal_variant_out_bool_true (VARIANT* variant)
3015 variant->vt = VT_BOOL;
3016 variant->boolVal = VARIANT_TRUE;
3018 return 0;
3021 LIBTEST_API int STDCALL
3022 mono_test_marshal_variant_out_bool_true_byref (VARIANT* variant)
3024 variant->vt = VT_BOOL|VT_BYREF;
3025 variant->byref = marshal_alloc(2);
3026 *((gint16*)variant->byref) = VARIANT_TRUE;
3028 return 0;
3031 LIBTEST_API int STDCALL
3032 mono_test_marshal_variant_out_bool_false (VARIANT* variant)
3034 variant->vt = VT_BOOL;
3035 variant->boolVal = VARIANT_FALSE;
3037 return 0;
3040 LIBTEST_API int STDCALL
3041 mono_test_marshal_variant_out_bool_false_byref (VARIANT* variant)
3043 variant->vt = VT_BOOL|VT_BYREF;
3044 variant->byref = marshal_alloc(2);
3045 *((gint16*)variant->byref) = VARIANT_FALSE;
3047 return 0;
3050 typedef int (STDCALL *VarFunc) (int vt, VARIANT variant);
3051 typedef int (STDCALL *VarRefFunc) (int vt, VARIANT* variant);
3053 LIBTEST_API int STDCALL
3054 mono_test_marshal_variant_in_sbyte_unmanaged(VarFunc func)
3056 VARIANT vt;
3057 vt.vt = VT_I1;
3058 vt.cVal = -100;
3059 return func (VT_I1, vt);
3062 LIBTEST_API int STDCALL
3063 mono_test_marshal_variant_in_byte_unmanaged(VarFunc func)
3065 VARIANT vt;
3066 vt.vt = VT_UI1;
3067 vt.bVal = 100;
3068 return func (VT_UI1, vt);
3071 LIBTEST_API int STDCALL
3072 mono_test_marshal_variant_in_short_unmanaged(VarFunc func)
3074 VARIANT vt;
3075 vt.vt = VT_I2;
3076 vt.iVal = -100;
3077 return func (VT_I2, vt);
3080 LIBTEST_API int STDCALL
3081 mono_test_marshal_variant_in_ushort_unmanaged(VarFunc func)
3083 VARIANT vt;
3084 vt.vt = VT_UI2;
3085 vt.uiVal = 100;
3086 return func (VT_UI2, vt);
3089 LIBTEST_API int STDCALL
3090 mono_test_marshal_variant_in_int_unmanaged(VarFunc func)
3092 VARIANT vt;
3093 vt.vt = VT_I4;
3094 vt.lVal = -100;
3095 return func (VT_I4, vt);
3098 LIBTEST_API int STDCALL
3099 mono_test_marshal_variant_in_uint_unmanaged(VarFunc func)
3101 VARIANT vt;
3102 vt.vt = VT_UI4;
3103 vt.ulVal = 100;
3104 return func (VT_UI4, vt);
3107 LIBTEST_API int STDCALL
3108 mono_test_marshal_variant_in_long_unmanaged(VarFunc func)
3110 VARIANT vt;
3111 vt.vt = VT_I8;
3112 vt.llVal = -100;
3113 return func (VT_I8, vt);
3116 LIBTEST_API int STDCALL
3117 mono_test_marshal_variant_in_ulong_unmanaged(VarFunc func)
3119 VARIANT vt;
3120 vt.vt = VT_UI8;
3121 vt.ullVal = 100;
3122 return func (VT_UI8, vt);
3125 LIBTEST_API int STDCALL
3126 mono_test_marshal_variant_in_float_unmanaged(VarFunc func)
3128 VARIANT vt;
3129 vt.vt = VT_R4;
3130 vt.fltVal = 3.14;
3131 return func (VT_R4, vt);
3134 LIBTEST_API int STDCALL
3135 mono_test_marshal_variant_in_double_unmanaged(VarFunc func)
3137 VARIANT vt;
3138 vt.vt = VT_R8;
3139 vt.dblVal = 3.14;
3140 return func (VT_R8, vt);
3143 LIBTEST_API int STDCALL
3144 mono_test_marshal_variant_in_bstr_unmanaged(VarFunc func)
3146 VARIANT vt;
3147 vt.vt = VT_BSTR;
3148 vt.bstrVal = marshal_bstr_alloc("PI");
3149 return func (VT_BSTR, vt);
3152 LIBTEST_API int STDCALL
3153 mono_test_marshal_variant_in_bool_true_unmanaged(VarFunc func)
3155 VARIANT vt;
3156 vt.vt = VT_BOOL;
3157 vt.boolVal = VARIANT_TRUE;
3158 return func (VT_BOOL, vt);
3161 LIBTEST_API int STDCALL
3162 mono_test_marshal_variant_in_bool_false_unmanaged(VarFunc func)
3164 VARIANT vt;
3165 vt.vt = VT_BOOL;
3166 vt.boolVal = VARIANT_FALSE;
3167 return func (VT_BOOL, vt);
3170 LIBTEST_API int STDCALL
3171 mono_test_marshal_variant_out_sbyte_unmanaged(VarRefFunc func)
3173 VARIANT vt;
3174 VariantInit (&vt);
3175 func (VT_I1, &vt);
3176 if (vt.vt == VT_I1 && vt.cVal == -100)
3177 return 0;
3178 return 1;
3181 LIBTEST_API int STDCALL
3182 mono_test_marshal_variant_out_byte_unmanaged(VarRefFunc func)
3184 VARIANT vt;
3185 VariantInit (&vt);
3186 func (VT_UI1, &vt);
3187 if (vt.vt == VT_UI1 && vt.bVal == 100)
3188 return 0;
3189 return 1;
3192 LIBTEST_API int STDCALL
3193 mono_test_marshal_variant_out_short_unmanaged(VarRefFunc func)
3195 VARIANT vt;
3196 VariantInit (&vt);
3197 func (VT_I2, &vt);
3198 if (vt.vt == VT_I2 && vt.iVal == -100)
3199 return 0;
3200 return 1;
3203 LIBTEST_API int STDCALL
3204 mono_test_marshal_variant_out_ushort_unmanaged(VarRefFunc func)
3206 VARIANT vt;
3207 VariantInit (&vt);
3208 func (VT_UI2, &vt);
3209 if (vt.vt == VT_UI2 && vt.uiVal == 100)
3210 return 0;
3211 return 1;
3214 LIBTEST_API int STDCALL
3215 mono_test_marshal_variant_out_int_unmanaged(VarRefFunc func)
3217 VARIANT vt;
3218 VariantInit (&vt);
3219 func (VT_I4, &vt);
3220 if (vt.vt == VT_I4 && vt.lVal == -100)
3221 return 0;
3222 return 1;
3225 LIBTEST_API int STDCALL
3226 mono_test_marshal_variant_out_uint_unmanaged(VarRefFunc func)
3228 VARIANT vt;
3229 VariantInit (&vt);
3230 func (VT_UI4, &vt);
3231 if (vt.vt == VT_UI4 && vt.ulVal == 100)
3232 return 0;
3233 return 1;
3236 LIBTEST_API int STDCALL
3237 mono_test_marshal_variant_out_long_unmanaged(VarRefFunc func)
3239 VARIANT vt;
3240 VariantInit (&vt);
3241 func (VT_I8, &vt);
3242 if (vt.vt == VT_I8 && vt.llVal == -100)
3243 return 0;
3244 return 1;
3247 LIBTEST_API int STDCALL
3248 mono_test_marshal_variant_out_ulong_unmanaged(VarRefFunc func)
3250 VARIANT vt;
3251 VariantInit (&vt);
3252 func (VT_UI8, &vt);
3253 if (vt.vt == VT_UI8 && vt.ullVal == 100)
3254 return 0;
3255 return 1;
3258 LIBTEST_API int STDCALL
3259 mono_test_marshal_variant_out_float_unmanaged(VarRefFunc func)
3261 VARIANT vt;
3262 VariantInit (&vt);
3263 func (VT_R4, &vt);
3264 if (vt.vt == VT_R4 && fabs (vt.fltVal - 3.14f) < 1e-10)
3265 return 0;
3266 return 1;
3269 LIBTEST_API int STDCALL
3270 mono_test_marshal_variant_out_double_unmanaged(VarRefFunc func)
3272 VARIANT vt;
3273 VariantInit (&vt);
3274 func (VT_R8, &vt);
3275 if (vt.vt == VT_R8 && fabs (vt.dblVal - 3.14) < 1e-10)
3276 return 0;
3277 return 1;
3280 LIBTEST_API int STDCALL
3281 mono_test_marshal_variant_out_bstr_unmanaged(VarRefFunc func)
3283 VARIANT vt;
3284 gchar* bstr_utf8;
3285 gint32 result = 0;
3288 VariantInit (&vt);
3289 func (VT_BSTR, &vt);
3290 bstr_utf8 = g_utf16_to_utf8 (vt.bstrVal, -1, NULL, NULL, NULL);
3291 result = strcmp("PI", bstr_utf8);
3292 g_free(bstr_utf8);
3293 if (vt.vt == VT_BSTR && !result)
3294 return 0;
3295 return 1;
3298 LIBTEST_API int STDCALL
3299 mono_test_marshal_variant_out_bool_true_unmanaged(VarRefFunc func)
3301 VARIANT vt;
3302 VariantInit (&vt);
3303 func (VT_BOOL, &vt);
3304 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3305 return 0;
3306 return 1;
3309 LIBTEST_API int STDCALL
3310 mono_test_marshal_variant_out_bool_false_unmanaged(VarRefFunc func)
3312 VARIANT vt;
3313 VariantInit (&vt);
3314 func (VT_BOOL, &vt);
3315 if (vt.vt == VT_BOOL && vt.boolVal == VARIANT_TRUE)
3316 return 0;
3317 return 1;
3320 typedef struct MonoComObject MonoComObject;
3322 typedef struct
3324 int (STDCALL *QueryInterface)(MonoComObject* pUnk, gpointer riid, gpointer* ppv);
3325 int (STDCALL *AddRef)(MonoComObject* pUnk);
3326 int (STDCALL *Release)(MonoComObject* pUnk);
3327 int (STDCALL *get_ITest)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3328 int (STDCALL *SByteIn)(MonoComObject* pUnk, char a);
3329 int (STDCALL *ByteIn)(MonoComObject* pUnk, unsigned char a);
3330 int (STDCALL *ShortIn)(MonoComObject* pUnk, short a);
3331 int (STDCALL *UShortIn)(MonoComObject* pUnk, unsigned short a);
3332 int (STDCALL *IntIn)(MonoComObject* pUnk, int a);
3333 int (STDCALL *UIntIn)(MonoComObject* pUnk, unsigned int a);
3334 int (STDCALL *LongIn)(MonoComObject* pUnk, gint64 a);
3335 int (STDCALL *ULongIn)(MonoComObject* pUnk, guint64 a);
3336 int (STDCALL *FloatIn)(MonoComObject* pUnk, float a);
3337 int (STDCALL *DoubleIn)(MonoComObject* pUnk, double a);
3338 int (STDCALL *ITestIn)(MonoComObject* pUnk, MonoComObject* pUnk2);
3339 int (STDCALL *ITestOut)(MonoComObject* pUnk, MonoComObject* *ppUnk);
3340 } MonoIUnknown;
3342 struct MonoComObject
3344 MonoIUnknown* vtbl;
3345 int m_ref;
3348 static GUID IID_ITest = {0, 0, 0, {0,0,0,0,0,0,0,1}};
3349 static GUID IID_IMonoUnknown = {0, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3350 static GUID IID_IMonoDispatch = {0x00020400, 0, 0, {0xc0,0,0,0,0,0,0,0x46}};
3352 LIBTEST_API int STDCALL
3353 MonoQueryInterface(MonoComObject* pUnk, gpointer riid, gpointer* ppv)
3356 *ppv = NULL;
3357 if (!memcmp(riid, &IID_IMonoUnknown, sizeof(GUID))) {
3358 *ppv = pUnk;
3359 return S_OK;
3361 else if (!memcmp(riid, &IID_ITest, sizeof(GUID))) {
3362 *ppv = pUnk;
3363 return S_OK;
3365 else if (!memcmp(riid, &IID_IMonoDispatch, sizeof(GUID))) {
3366 *ppv = pUnk;
3367 return S_OK;
3369 return 0x80004002; //E_NOINTERFACE;
3372 LIBTEST_API int STDCALL
3373 MonoAddRef(MonoComObject* pUnk)
3375 return ++(pUnk->m_ref);
3378 LIBTEST_API int STDCALL
3379 MonoRelease(MonoComObject* pUnk)
3381 return --(pUnk->m_ref);
3384 LIBTEST_API int STDCALL
3385 SByteIn(MonoComObject* pUnk, char a)
3387 return S_OK;
3390 LIBTEST_API int STDCALL
3391 ByteIn(MonoComObject* pUnk, unsigned char a)
3393 return S_OK;
3396 LIBTEST_API int STDCALL
3397 ShortIn(MonoComObject* pUnk, short a)
3399 return S_OK;
3402 LIBTEST_API int STDCALL
3403 UShortIn(MonoComObject* pUnk, unsigned short a)
3405 return S_OK;
3408 LIBTEST_API int STDCALL
3409 IntIn(MonoComObject* pUnk, int a)
3411 return S_OK;
3414 LIBTEST_API int STDCALL
3415 UIntIn(MonoComObject* pUnk, unsigned int a)
3417 return S_OK;
3420 LIBTEST_API int STDCALL
3421 LongIn(MonoComObject* pUnk, gint64 a)
3423 return S_OK;
3426 LIBTEST_API int STDCALL
3427 ULongIn(MonoComObject* pUnk, guint64 a)
3429 return S_OK;
3432 LIBTEST_API int STDCALL
3433 FloatIn(MonoComObject* pUnk, float a)
3435 return S_OK;
3438 LIBTEST_API int STDCALL
3439 DoubleIn(MonoComObject* pUnk, double a)
3441 return S_OK;
3444 LIBTEST_API int STDCALL
3445 ITestIn(MonoComObject* pUnk, MonoComObject *pUnk2)
3447 return S_OK;
3450 LIBTEST_API int STDCALL
3451 ITestOut(MonoComObject* pUnk, MonoComObject* *ppUnk)
3453 return S_OK;
3456 static void create_com_object (MonoComObject** pOut);
3458 LIBTEST_API int STDCALL
3459 get_ITest(MonoComObject* pUnk, MonoComObject* *ppUnk)
3461 create_com_object (ppUnk);
3462 return S_OK;
3465 static void create_com_object (MonoComObject** pOut)
3467 *pOut = marshal_new0 (MonoComObject, 1);
3468 (*pOut)->vtbl = marshal_new0 (MonoIUnknown, 1);
3470 (*pOut)->m_ref = 1;
3471 (*pOut)->vtbl->QueryInterface = MonoQueryInterface;
3472 (*pOut)->vtbl->AddRef = MonoAddRef;
3473 (*pOut)->vtbl->Release = MonoRelease;
3474 (*pOut)->vtbl->SByteIn = SByteIn;
3475 (*pOut)->vtbl->ByteIn = ByteIn;
3476 (*pOut)->vtbl->ShortIn = ShortIn;
3477 (*pOut)->vtbl->UShortIn = UShortIn;
3478 (*pOut)->vtbl->IntIn = IntIn;
3479 (*pOut)->vtbl->UIntIn = UIntIn;
3480 (*pOut)->vtbl->LongIn = LongIn;
3481 (*pOut)->vtbl->ULongIn = ULongIn;
3482 (*pOut)->vtbl->FloatIn = FloatIn;
3483 (*pOut)->vtbl->DoubleIn = DoubleIn;
3484 (*pOut)->vtbl->ITestIn = ITestIn;
3485 (*pOut)->vtbl->ITestOut = ITestOut;
3486 (*pOut)->vtbl->get_ITest = get_ITest;
3489 static MonoComObject* same_object = NULL;
3491 LIBTEST_API int STDCALL
3492 mono_test_marshal_com_object_create(MonoComObject* *pUnk)
3494 create_com_object (pUnk);
3496 if (!same_object)
3497 same_object = *pUnk;
3499 return 0;
3502 LIBTEST_API int STDCALL
3503 mono_test_marshal_com_object_same(MonoComObject* *pUnk)
3505 *pUnk = same_object;
3507 return 0;
3510 LIBTEST_API int STDCALL
3511 mono_test_marshal_com_object_destroy(MonoComObject *pUnk)
3513 int ref = --(pUnk->m_ref);
3514 g_free(pUnk->vtbl);
3515 g_free(pUnk);
3517 return ref;
3520 LIBTEST_API int STDCALL
3521 mono_test_marshal_com_object_ref_count(MonoComObject *pUnk)
3523 return pUnk->m_ref;
3526 LIBTEST_API int STDCALL
3527 mono_test_marshal_ccw_itest (MonoComObject *pUnk)
3529 int hr = 0;
3530 MonoComObject* pTest;
3532 if (!pUnk)
3533 return 1;
3535 hr = pUnk->vtbl->SByteIn (pUnk, -100);
3536 if (hr != 0)
3537 return 2;
3538 hr = pUnk->vtbl->ByteIn (pUnk, 100);
3539 if (hr != 0)
3540 return 3;
3541 hr = pUnk->vtbl->ShortIn (pUnk, -100);
3542 if (hr != 0)
3543 return 4;
3544 hr = pUnk->vtbl->UShortIn (pUnk, 100);
3545 if (hr != 0)
3546 return 5;
3547 hr = pUnk->vtbl->IntIn (pUnk, -100);
3548 if (hr != 0)
3549 return 6;
3550 hr = pUnk->vtbl->UIntIn (pUnk, 100);
3551 if (hr != 0)
3552 return 7;
3553 hr = pUnk->vtbl->LongIn (pUnk, -100);
3554 if (hr != 0)
3555 return 8;
3556 hr = pUnk->vtbl->ULongIn (pUnk, 100);
3557 if (hr != 0)
3558 return 9;
3559 hr = pUnk->vtbl->FloatIn (pUnk, 3.14f);
3560 if (hr != 0)
3561 return 10;
3562 hr = pUnk->vtbl->DoubleIn (pUnk, 3.14);
3563 if (hr != 0)
3564 return 11;
3565 hr = pUnk->vtbl->ITestIn (pUnk, pUnk);
3566 if (hr != 0)
3567 return 12;
3568 hr = pUnk->vtbl->ITestOut (pUnk, &pTest);
3569 if (hr != 0)
3570 return 13;
3572 return 0;
3576 * mono_method_get_unmanaged_thunk tests
3579 #if defined(__GNUC__) && ((defined(__i386__) && (defined(__linux__) || defined (__APPLE__)) || defined (__FreeBSD__) || defined(__OpenBSD__)) || (defined(__ppc__) && defined(__APPLE__)))
3580 #define ALIGN(size) __attribute__ ((__aligned__(size)))
3581 #else
3582 #define ALIGN(size)
3583 #endif
3586 /* thunks.cs:TestStruct */
3587 typedef struct _TestStruct {
3588 int A;
3589 double B;
3590 } TestStruct;
3592 /* Searches for mono symbols in all loaded modules */
3593 static gpointer
3594 lookup_mono_symbol (const char *symbol_name)
3596 gpointer symbol;
3597 if (g_module_symbol (g_module_open (NULL, G_MODULE_BIND_LAZY), symbol_name, &symbol))
3598 return symbol;
3599 else
3600 return NULL;
3603 LIBTEST_API gpointer STDCALL
3604 mono_test_marshal_lookup_symbol (const char *symbol_name)
3606 return lookup_mono_symbol (symbol_name);
3609 #define MONO_BEGIN_EFRAME { void *__dummy; void *__region_cookie = mono_threads_enter_gc_unsafe_region ? mono_threads_enter_gc_unsafe_region (&__dummy) : NULL;
3610 #define MONO_END_EFRAME if (mono_threads_exit_gc_unsafe_region) mono_threads_exit_gc_unsafe_region (__region_cookie, &__dummy); }
3613 * test_method_thunk:
3615 * @test_id: the test number
3616 * @test_method_handle: MonoMethod* of the C# test method
3617 * @create_object_method_handle: MonoMethod* of thunks.cs:Test.CreateObject
3619 LIBTEST_API int STDCALL
3620 test_method_thunk (int test_id, gpointer test_method_handle, gpointer create_object_method_handle)
3622 int ret = 0;
3624 gpointer (*mono_method_get_unmanaged_thunk)(gpointer)
3625 = (gpointer (*)(gpointer))lookup_mono_symbol ("mono_method_get_unmanaged_thunk");
3627 gpointer (*mono_string_new_wrapper)(const char *)
3628 = (gpointer (*)(const char *))lookup_mono_symbol ("mono_string_new_wrapper");
3630 char *(*mono_string_to_utf8)(gpointer)
3631 = (char *(*)(gpointer))lookup_mono_symbol ("mono_string_to_utf8");
3633 gpointer (*mono_object_unbox)(gpointer)
3634 = (gpointer (*)(gpointer))lookup_mono_symbol ("mono_object_unbox");
3636 gpointer (*mono_threads_enter_gc_unsafe_region) (gpointer)
3637 = (gpointer (*)(gpointer))lookup_mono_symbol ("mono_threads_enter_gc_unsafe_region");
3639 void (*mono_threads_exit_gc_unsafe_region) (gpointer, gpointer)
3640 = (void (*)(gpointer, gpointer))lookup_mono_symbol ("mono_threads_exit_gc_unsafe_region");
3644 gpointer test_method, ex = NULL;
3645 gpointer (STDCALL *CreateObject)(gpointer*);
3647 MONO_BEGIN_EFRAME;
3649 if (!mono_method_get_unmanaged_thunk) {
3650 ret = 1;
3651 goto done;
3654 test_method = mono_method_get_unmanaged_thunk (test_method_handle);
3655 if (!test_method) {
3656 ret = 2;
3657 goto done;
3660 CreateObject = (gpointer (STDCALL *)(gpointer *))mono_method_get_unmanaged_thunk (create_object_method_handle);
3661 if (!CreateObject) {
3662 ret = 3;
3663 goto done;
3667 switch (test_id) {
3669 case 0: {
3670 /* thunks.cs:Test.Test0 */
3671 void (STDCALL *F)(gpointer *) = (void (STDCALL *)(gpointer *))test_method;
3672 F (&ex);
3673 break;
3676 case 1: {
3677 /* thunks.cs:Test.Test1 */
3678 int (STDCALL *F)(gpointer *) = (int (STDCALL *)(gpointer *))test_method;
3679 if (F (&ex) != 42) {
3680 ret = 4;
3681 goto done;
3683 break;
3686 case 2: {
3687 /* thunks.cs:Test.Test2 */
3688 gpointer (STDCALL *F)(gpointer, gpointer*) = (gpointer (STDCALL *)(gpointer, gpointer *))test_method;
3689 gpointer str = mono_string_new_wrapper ("foo");
3690 if (str != F (str, &ex)) {
3691 ret = 4;
3692 goto done;
3694 break;
3697 case 3: {
3698 /* thunks.cs:Test.Test3 */
3699 gpointer (STDCALL *F)(gpointer, gpointer, gpointer*);
3700 gpointer obj;
3701 gpointer str;
3703 F = (gpointer (STDCALL *)(gpointer, gpointer, gpointer *))test_method;
3704 obj = CreateObject (&ex);
3705 str = mono_string_new_wrapper ("bar");
3707 if (str != F (obj, str, &ex)) {
3708 ret = 4;
3709 goto done;
3711 break;
3714 case 4: {
3715 /* thunks.cs:Test.Test4 */
3716 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3717 gpointer obj;
3718 gpointer str;
3720 F = (int (STDCALL *)(gpointer, gpointer, int, gpointer *))test_method;
3721 obj = CreateObject (&ex);
3722 str = mono_string_new_wrapper ("bar");
3724 if (42 != F (obj, str, 42, &ex)) {
3725 ret = 4;
3726 goto done;
3729 break;
3732 case 5: {
3733 /* thunks.cs:Test.Test5 */
3734 int (STDCALL *F)(gpointer, gpointer, int, gpointer*);
3735 gpointer obj;
3736 gpointer str;
3738 F = (int (STDCALL *)(gpointer, gpointer, int, gpointer *))test_method;
3739 obj = CreateObject (&ex);
3740 str = mono_string_new_wrapper ("bar");
3742 F (obj, str, 42, &ex);
3743 if (!ex) {
3744 ret = 4;
3745 goto done;
3748 break;
3751 case 6: {
3752 /* thunks.cs:Test.Test6 */
3753 int (STDCALL *F)(gpointer, guint8, gint16, gint32, gint64, float, double,
3754 gpointer, gpointer*);
3755 gpointer obj;
3756 gpointer str = mono_string_new_wrapper ("Test6");
3757 int res;
3759 F = (int (STDCALL *)(gpointer, guint8, gint16, gint32, gint64, float, double, gpointer, gpointer *))test_method;
3760 obj = CreateObject (&ex);
3762 res = F (obj, 254, 32700, -245378, 6789600, 3.1415, 3.1415, str, &ex);
3763 if (ex) {
3764 ret = 4;
3765 goto done;
3768 if (!res) {
3769 ret = 5;
3770 goto done;
3773 break;
3776 case 7: {
3777 /* thunks.cs:Test.Test7 */
3778 gint64 (STDCALL *F)(gpointer*) = (gint64 (STDCALL *)(gpointer *))test_method;
3779 if (F (&ex) != G_MAXINT64) {
3780 ret = 4;
3781 goto done;
3783 break;
3786 case 8: {
3787 /* thunks.cs:Test.Test8 */
3788 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3789 gpointer*, gpointer*);
3791 guint8 a1;
3792 gint16 a2;
3793 gint32 a3;
3794 gint64 a4;
3795 float a5;
3796 double a6;
3797 gpointer a7;
3799 F = (void (STDCALL *)(guint8 *, gint16 *, gint32 *, gint64 *, float *, double *,
3800 gpointer *, gpointer *))test_method;
3802 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3803 if (ex) {
3804 ret = 4;
3805 goto done;
3808 if (!(a1 == 254 &&
3809 a2 == 32700 &&
3810 a3 == -245378 &&
3811 a4 == 6789600 &&
3812 (fabs (a5 - 3.1415) < 0.001) &&
3813 (fabs (a6 - 3.1415) < 0.001) &&
3814 strcmp (mono_string_to_utf8 (a7), "Test8") == 0)){
3815 ret = 5;
3816 goto done;
3819 break;
3822 case 9: {
3823 /* thunks.cs:Test.Test9 */
3824 void (STDCALL *F)(guint8*, gint16*, gint32*, gint64*, float*, double*,
3825 gpointer*, gpointer*);
3827 guint8 a1;
3828 gint16 a2;
3829 gint32 a3;
3830 gint64 a4;
3831 float a5;
3832 double a6;
3833 gpointer a7;
3835 F = (void (STDCALL *)(guint8 *, gint16 *, gint32 *, gint64 *, float *, double *,
3836 gpointer *, gpointer *))test_method;
3838 F (&a1, &a2, &a3, &a4, &a5, &a6, &a7, &ex);
3839 if (!ex) {
3840 ret = 4;
3841 goto done;
3844 break;
3847 case 10: {
3848 /* thunks.cs:Test.Test10 */
3849 void (STDCALL *F)(gpointer*, gpointer*);
3851 gpointer obj1, obj2;
3853 obj1 = obj2 = CreateObject (&ex);
3854 if (ex) {
3855 ret = 4;
3856 goto done;
3859 F = (void (STDCALL *)(gpointer *, gpointer *))test_method;
3861 F (&obj1, &ex);
3862 if (ex) {
3863 ret = 5;
3864 goto done;
3867 if (obj1 == obj2) {
3868 ret = 6;
3869 goto done;
3872 break;
3875 case 100: {
3876 /* thunks.cs:TestStruct.Test0 */
3877 int (STDCALL *F)(gpointer*, gpointer*);
3879 gpointer obj;
3880 TestStruct *a1;
3881 int res;
3883 obj = CreateObject (&ex);
3884 if (ex) {
3885 ret = 4;
3886 goto done;
3889 if (!obj) {
3890 ret = 5;
3891 goto done;
3894 a1 = (TestStruct *)mono_object_unbox (obj);
3895 if (!a1) {
3896 ret = 6;
3897 goto done;
3900 a1->A = 42;
3901 a1->B = 3.1415;
3903 F = (int (STDCALL *)(gpointer *, gpointer *))test_method;
3905 res = F ((gpointer *)obj, &ex);
3906 if (ex) {
3907 ret = 7;
3908 goto done;
3911 if (!res) {
3912 ret = 8;
3913 goto done;
3916 /* check whether the call was really by value */
3917 if (a1->A != 42 || a1->B != 3.1415) {
3918 ret = 9;
3919 goto done;
3922 break;
3925 case 101: {
3926 /* thunks.cs:TestStruct.Test1 */
3927 void (STDCALL *F)(gpointer, gpointer*);
3929 TestStruct *a1;
3930 gpointer obj;
3932 obj = CreateObject (&ex);
3933 if (ex) {
3934 ret = 4;
3935 goto done;
3938 if (!obj) {
3939 ret = 5;
3940 goto done;
3943 a1 = (TestStruct *)mono_object_unbox (obj);
3944 if (!a1) {
3945 ret = 6;
3946 goto done;
3949 F = (void (STDCALL *)(gpointer, gpointer *))test_method;
3951 F (obj, &ex);
3952 if (ex) {
3953 ret = 7;
3954 goto done;
3957 if (a1->A != 42) {
3958 ret = 8;
3959 goto done;
3962 if (!(fabs (a1->B - 3.1415) < 0.001)) {
3963 ret = 9;
3964 goto done;
3967 break;
3970 case 102: {
3971 /* thunks.cs:TestStruct.Test2 */
3972 gpointer (STDCALL *F)(gpointer*);
3974 TestStruct *a1;
3975 gpointer obj;
3977 F = (gpointer (STDCALL *)(gpointer *))test_method;
3979 obj = F (&ex);
3980 if (ex) {
3981 ret = 4;
3982 goto done;
3985 if (!obj) {
3986 ret = 5;
3987 goto done;
3990 a1 = (TestStruct *)mono_object_unbox (obj);
3992 if (a1->A != 42) {
3993 ret = 5;
3994 goto done;
3997 if (!(fabs (a1->B - 3.1415) < 0.001)) {
3998 ret = 6;
3999 goto done;
4002 break;
4005 case 103: {
4006 /* thunks.cs:TestStruct.Test3 */
4007 void (STDCALL *F)(gpointer, gpointer*);
4009 TestStruct *a1;
4010 gpointer obj;
4012 obj = CreateObject (&ex);
4013 if (ex) {
4014 ret = 4;
4015 goto done;
4018 if (!obj) {
4019 ret = 5;
4020 goto done;
4023 a1 = (TestStruct *)mono_object_unbox (obj);
4025 if (!a1) {
4026 ret = 6;
4027 goto done;
4030 a1->A = 42;
4031 a1->B = 3.1415;
4033 F = (void (STDCALL *)(gpointer, gpointer *))test_method;
4035 F (obj, &ex);
4036 if (ex) {
4037 ret = 4;
4038 goto done;
4041 if (a1->A != 1) {
4042 ret = 5;
4043 goto done;
4046 if (a1->B != 17) {
4047 ret = 6;
4048 goto done;
4051 break;
4054 default:
4055 ret = 9;
4058 done:
4059 MONO_END_EFRAME;
4061 return ret;
4064 typedef struct
4066 char a;
4067 } winx64_struct1;
4069 LIBTEST_API int STDCALL
4070 mono_test_Winx64_struct1_in (winx64_struct1 var)
4072 if (var.a != 123)
4073 return 1;
4074 return 0;
4077 typedef struct
4079 char a;
4080 char b;
4081 } winx64_struct2;
4083 LIBTEST_API int STDCALL
4084 mono_test_Winx64_struct2_in (winx64_struct2 var)
4086 if (var.a != 4)
4087 return 1;
4088 if (var.b != 5)
4089 return 2;
4090 return 0;
4094 typedef struct
4096 char a;
4097 char b;
4098 short c;
4099 } winx64_struct3;
4101 LIBTEST_API int STDCALL
4102 mono_test_Winx64_struct3_in (winx64_struct3 var)
4104 if (var.a != 4)
4105 return 1;
4106 if (var.b != 5)
4107 return 2;
4108 if (var.c != 0x1234)
4109 return 3;
4110 return 0;
4113 typedef struct
4115 char a;
4116 char b;
4117 short c;
4118 unsigned int d;
4119 } winx64_struct4;
4121 LIBTEST_API int STDCALL
4122 mono_test_Winx64_struct4_in (winx64_struct4 var)
4124 if (var.a != 4)
4125 return 1;
4126 if (var.b != 5)
4127 return 2;
4128 if (var.c != 0x1234)
4129 return 3;
4130 if (var.d != 0x87654321)
4131 return 4;
4132 return 0;
4135 typedef struct
4137 char a;
4138 char b;
4139 char c;
4140 } winx64_struct5;
4142 LIBTEST_API int STDCALL
4143 mono_test_Winx64_struct5_in (winx64_struct5 var)
4145 if (var.a != 4)
4146 return 1;
4147 if (var.b != 5)
4148 return 2;
4149 if (var.c != 6)
4150 return 3;
4151 return 0;
4154 typedef struct
4156 winx64_struct1 a;
4157 short b;
4158 char c;
4159 } winx64_struct6;
4161 LIBTEST_API int STDCALL
4162 mono_test_Winx64_struct6_in (winx64_struct6 var)
4164 if (var.a.a != 4)
4165 return 1;
4166 if (var.b != 5)
4167 return 2;
4168 if (var.c != 6)
4169 return 3;
4170 return 0;
4173 LIBTEST_API int STDCALL
4174 mono_test_Winx64_structs_in1 (winx64_struct1 var1,
4175 winx64_struct2 var2,
4176 winx64_struct3 var3,
4177 winx64_struct4 var4)
4179 if (var1.a != 123)
4180 return 1;
4182 if (var2.a != 4)
4183 return 2;
4184 if (var2.b != 5)
4185 return 3;
4187 if (var3.a != 4)
4188 return 4;
4189 if (var3.b != 5)
4190 return 2;
4191 if (var3.c != 0x1234)
4192 return 5;
4194 if (var4.a != 4)
4195 return 6;
4196 if (var4.b != 5)
4197 return 7;
4198 if (var4.c != 0x1234)
4199 return 8;
4200 if (var4.d != 0x87654321)
4201 return 9;
4202 return 0;
4205 LIBTEST_API int STDCALL
4206 mono_test_Winx64_structs_in2 (winx64_struct1 var1,
4207 winx64_struct1 var2,
4208 winx64_struct1 var3,
4209 winx64_struct1 var4,
4210 winx64_struct1 var5)
4212 if (var1.a != 1)
4213 return 1;
4214 if (var2.a != 2)
4215 return 2;
4216 if (var3.a != 3)
4217 return 3;
4218 if (var4.a != 4)
4219 return 4;
4220 if (var5.a != 5)
4221 return 5;
4223 return 0;
4226 LIBTEST_API int STDCALL
4227 mono_test_Winx64_structs_in3 (winx64_struct1 var1,
4228 winx64_struct5 var2,
4229 winx64_struct1 var3,
4230 winx64_struct5 var4,
4231 winx64_struct1 var5,
4232 winx64_struct5 var6)
4234 if (var1.a != 1)
4235 return 1;
4237 if (var2.a != 2)
4238 return 2;
4239 if (var2.b != 3)
4240 return 2;
4241 if (var2.c != 4)
4242 return 4;
4244 if (var3.a != 5)
4245 return 5;
4247 if (var4.a != 6)
4248 return 6;
4249 if (var4.b != 7)
4250 return 7;
4251 if (var4.c != 8)
4252 return 8;
4254 if (var5.a != 9)
4255 return 9;
4257 if (var6.a != 10)
4258 return 10;
4259 if (var6.b != 11)
4260 return 11;
4261 if (var6.c != 12)
4262 return 12;
4264 return 0;
4267 LIBTEST_API winx64_struct1 STDCALL
4268 mono_test_Winx64_struct1_ret (void)
4270 winx64_struct1 ret;
4271 ret.a = 123;
4272 return ret;
4275 LIBTEST_API winx64_struct2 STDCALL
4276 mono_test_Winx64_struct2_ret (void)
4278 winx64_struct2 ret;
4279 ret.a = 4;
4280 ret.b = 5;
4281 return ret;
4284 LIBTEST_API winx64_struct3 STDCALL
4285 mono_test_Winx64_struct3_ret (void)
4287 winx64_struct3 ret;
4288 ret.a = 4;
4289 ret.b = 5;
4290 ret.c = 0x1234;
4291 return ret;
4294 LIBTEST_API winx64_struct4 STDCALL
4295 mono_test_Winx64_struct4_ret (void)
4297 winx64_struct4 ret;
4298 ret.a = 4;
4299 ret.b = 5;
4300 ret.c = 0x1234;
4301 ret.d = 0x87654321;
4302 return ret;
4305 LIBTEST_API winx64_struct5 STDCALL
4306 mono_test_Winx64_struct5_ret (void)
4308 winx64_struct5 ret;
4309 ret.a = 4;
4310 ret.b = 5;
4311 ret.c = 6;
4312 return ret;
4315 LIBTEST_API winx64_struct1 STDCALL
4316 mono_test_Winx64_struct1_ret_5_args (char a, char b, char c, char d, char e)
4318 winx64_struct1 ret;
4319 ret.a = a + b + c + d + e;
4320 return ret;
4323 LIBTEST_API winx64_struct5 STDCALL
4324 mono_test_Winx64_struct5_ret6_args (char a, char b, char c, char d, char e)
4326 winx64_struct5 ret;
4327 ret.a = a + b;
4328 ret.b = c + d;
4329 ret.c = e;
4330 return ret;
4333 typedef struct
4335 float a;
4336 float b;
4337 } winx64_floatStruct;
4339 LIBTEST_API int STDCALL
4340 mono_test_Winx64_floatStruct (winx64_floatStruct a)
4342 if (a.a > 5.6 || a.a < 5.4)
4343 return 1;
4345 if (a.b > 9.6 || a.b < 9.4)
4346 return 2;
4348 return 0;
4351 typedef struct
4353 double a;
4354 } winx64_doubleStruct;
4356 LIBTEST_API int STDCALL
4357 mono_test_Winx64_doubleStruct (winx64_doubleStruct a)
4359 if (a.a > 5.6 || a.a < 5.4)
4360 return 1;
4362 return 0;
4365 typedef int (STDCALL *managed_struct1_delegate) (winx64_struct1 a);
4367 LIBTEST_API int STDCALL
4368 mono_test_managed_Winx64_struct1_in(managed_struct1_delegate func)
4370 winx64_struct1 val;
4371 val.a = 5;
4372 return func (val);
4375 typedef int (STDCALL *managed_struct5_delegate) (winx64_struct5 a);
4377 LIBTEST_API int STDCALL
4378 mono_test_managed_Winx64_struct5_in(managed_struct5_delegate func)
4380 winx64_struct5 val;
4381 val.a = 5;
4382 val.b = 0x10;
4383 val.c = 0x99;
4384 return func (val);
4387 typedef int (STDCALL *managed_struct1_struct5_delegate) (winx64_struct1 a, winx64_struct5 b,
4388 winx64_struct1 c, winx64_struct5 d,
4389 winx64_struct1 e, winx64_struct5 f);
4391 LIBTEST_API int STDCALL
4392 mono_test_managed_Winx64_struct1_struct5_in(managed_struct1_struct5_delegate func)
4394 winx64_struct1 a, c, e;
4395 winx64_struct5 b, d, f;
4396 a.a = 1;
4397 b.a = 2; b.b = 3; b.c = 4;
4398 c.a = 5;
4399 d.a = 6; d.b = 7; d.c = 8;
4400 e.a = 9;
4401 f.a = 10; f.b = 11; f.c = 12;
4403 return func (a, b, c, d, e, f);
4406 typedef winx64_struct1 (STDCALL *managed_struct1_ret_delegate) (void);
4408 LIBTEST_API int STDCALL
4409 mono_test_Winx64_struct1_ret_managed (managed_struct1_ret_delegate func)
4411 winx64_struct1 ret;
4413 ret = func ();
4415 if (ret.a != 0x45)
4416 return 1;
4418 return 0;
4421 typedef winx64_struct5 (STDCALL *managed_struct5_ret_delegate) (void);
4423 LIBTEST_API int STDCALL
4424 mono_test_Winx64_struct5_ret_managed (managed_struct5_ret_delegate func)
4426 winx64_struct5 ret;
4428 ret = func ();
4430 if (ret.a != 0x12)
4431 return 1;
4432 if (ret.b != 0x34)
4433 return 2;
4434 if (ret.c != 0x56)
4435 return 3;
4437 return 0;
4440 LIBTEST_API int STDCALL
4441 mono_test_marshal_bool_in (int arg, unsigned int expected, unsigned int bDefaultMarsh, unsigned int bBoolCustMarsh,
4442 char bI1CustMarsh, unsigned char bU1CustMarsh, short bVBCustMarsh)
4444 switch (arg) {
4445 case 1:
4446 if (bDefaultMarsh != expected)
4447 return 1;
4448 break;
4449 case 2:
4450 if (bBoolCustMarsh != expected)
4451 return 2;
4452 break;
4453 case 3:
4454 if (bI1CustMarsh != expected)
4455 return 3;
4456 break;
4457 case 4:
4458 if (bU1CustMarsh != expected)
4459 return 4;
4460 break;
4461 case 5:
4462 if (bVBCustMarsh != expected)
4463 return 5;
4464 break;
4465 default:
4466 return 999;
4468 return 0;
4471 LIBTEST_API int STDCALL
4472 mono_test_marshal_bool_out (int arg, unsigned int testVal, unsigned int* bDefaultMarsh, unsigned int* bBoolCustMarsh,
4473 char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh)
4475 switch (arg) {
4476 case 1:
4477 if (!bDefaultMarsh)
4478 return 1;
4479 *bDefaultMarsh = testVal;
4480 break;
4481 case 2:
4482 if (!bBoolCustMarsh)
4483 return 2;
4484 *bBoolCustMarsh = testVal;
4485 break;
4486 case 3:
4487 if (!bI1CustMarsh)
4488 return 3;
4489 *bI1CustMarsh = (char)testVal;
4490 break;
4491 case 4:
4492 if (!bU1CustMarsh)
4493 return 4;
4494 *bU1CustMarsh = (unsigned char)testVal;
4495 break;
4496 case 5:
4497 if (!bVBCustMarsh)
4498 return 5;
4499 *bVBCustMarsh = (unsigned short)testVal;
4500 break;
4501 default:
4502 return 999;
4504 return 0;
4507 LIBTEST_API int STDCALL
4508 mono_test_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4509 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh,
4510 unsigned short* bVBCustMarsh)
4512 switch (arg) {
4513 case 1:
4514 if (!bDefaultMarsh)
4515 return 1;
4516 if (*bDefaultMarsh != expected)
4517 return 2;
4518 *bDefaultMarsh = testVal;
4519 break;
4520 case 2:
4521 if (!bBoolCustMarsh)
4522 return 3;
4523 if (*bBoolCustMarsh != expected)
4524 return 4;
4525 *bBoolCustMarsh = testVal;
4526 break;
4527 case 3:
4528 if (!bI1CustMarsh)
4529 return 5;
4530 if (*bI1CustMarsh != expected)
4531 return 6;
4532 *bI1CustMarsh = (char)testVal;
4533 break;
4534 case 4:
4535 if (!bU1CustMarsh)
4536 return 7;
4537 if (*bU1CustMarsh != expected)
4538 return 8;
4539 *bU1CustMarsh = (unsigned char)testVal;
4540 break;
4541 case 5:
4542 if (!bVBCustMarsh)
4543 return 9;
4544 if (*bVBCustMarsh != expected)
4545 return 10;
4546 *bVBCustMarsh = (unsigned short)testVal;
4547 break;
4548 default:
4549 return 999;
4551 return 0;
4555 typedef int (STDCALL *MarshalBoolInDelegate) (int arg, unsigned int expected, unsigned int bDefaultMarsh,
4556 unsigned int bBoolCustMarsh, char bI1CustMarsh, unsigned char bU1CustMarsh, unsigned short bVBCustMarsh);
4558 LIBTEST_API int STDCALL
4559 mono_test_managed_marshal_bool_in (int arg, unsigned int expected, unsigned int testVal, MarshalBoolInDelegate pfcn)
4561 if (!pfcn)
4562 return 0x9900;
4564 switch (arg) {
4565 case 1:
4566 return pfcn (arg, expected, testVal, 0, 0, 0, 0);
4567 case 2:
4568 return pfcn (arg, expected, 0, testVal, 0, 0, 0);
4569 case 3:
4570 return pfcn (arg, expected, 0, 0, testVal, 0, 0);
4571 case 4:
4572 return pfcn (arg, expected, 0, 0, 0, testVal, 0);
4573 case 5:
4574 return pfcn (arg, expected, 0, 0, 0, 0, testVal);
4575 default:
4576 return 0x9800;
4579 return 0;
4582 typedef int (STDCALL *MarshalBoolOutDelegate) (int arg, unsigned int expected, unsigned int* bDefaultMarsh,
4583 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4585 LIBTEST_API int STDCALL
4586 mono_test_managed_marshal_bool_out (int arg, unsigned int expected, unsigned int testVal, MarshalBoolOutDelegate pfcn)
4588 int ret;
4589 unsigned int lDefaultMarsh, lBoolCustMarsh;
4590 char lI1CustMarsh = 0;
4591 unsigned char lU1CustMarsh = 0;
4592 unsigned short lVBCustMarsh = 0;
4593 lDefaultMarsh = lBoolCustMarsh = 0;
4595 if (!pfcn)
4596 return 0x9900;
4598 switch (arg) {
4599 case 1: {
4600 unsigned int ltVal = 0;
4601 ret = pfcn (arg, testVal, &ltVal, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4602 if (ret)
4603 return 0x0100 + ret;
4604 if (expected != ltVal)
4605 return 0x0200;
4606 break;
4608 case 2: {
4609 unsigned int ltVal = 0;
4610 ret = pfcn (arg, testVal, &lDefaultMarsh, &ltVal, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4611 if (ret)
4612 return 0x0300 + ret;
4613 if (expected != ltVal)
4614 return 0x0400;
4615 break;
4617 case 3: {
4618 char ltVal = 0;
4619 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &ltVal, &lU1CustMarsh, &lVBCustMarsh);
4620 if (ret)
4621 return 0x0500 + ret;
4622 if (expected != ltVal)
4623 return 0x0600;
4624 break;
4626 case 4: {
4627 unsigned char ltVal = 0;
4628 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &ltVal, &lVBCustMarsh);
4629 if (ret)
4630 return 0x0700 + ret;
4631 if (expected != ltVal)
4632 return 0x0800;
4633 break;
4635 case 5: {
4636 unsigned short ltVal = 0;
4637 ret = pfcn (arg, testVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &ltVal);
4638 if (ret)
4639 return 0x0900 + ret;
4640 if (expected != ltVal)
4641 return 0x1000;
4642 break;
4644 default:
4645 return 0x9800;
4648 return 0;
4651 typedef int (STDCALL *MarshalBoolRefDelegate) (int arg, unsigned int expected, unsigned int testVal, unsigned int* bDefaultMarsh,
4652 unsigned int* bBoolCustMarsh, char* bI1CustMarsh, unsigned char* bU1CustMarsh, unsigned short* bVBCustMarsh);
4654 LIBTEST_API int STDCALL
4655 mono_test_managed_marshal_bool_ref (int arg, unsigned int expected, unsigned int testVal, unsigned int outExpected,
4656 unsigned int outTestVal, MarshalBoolRefDelegate pfcn)
4658 int ret;
4659 unsigned int lDefaultMarsh, lBoolCustMarsh;
4660 char lI1CustMarsh = 0;
4661 unsigned char lU1CustMarsh = 0;
4662 unsigned short lVBCustMarsh = 0;
4663 lDefaultMarsh = lBoolCustMarsh = 0;
4665 if (!pfcn)
4666 return 0x9900;
4668 switch (arg) {
4669 case 1:
4671 unsigned int ltestVal = testVal;
4672 ret = pfcn (arg, expected, outTestVal, &ltestVal, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4673 if (ret)
4674 return 0x0100 + ret;
4675 if (outExpected != ltestVal)
4676 return 0x0200;
4677 break;
4679 case 2:
4681 unsigned int ltestVal = testVal;
4682 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &ltestVal, &lI1CustMarsh, &lU1CustMarsh, &lVBCustMarsh);
4683 if (ret)
4684 return 0x0300 + ret;
4685 if (outExpected != ltestVal)
4686 return 0x0400;
4687 break;
4689 case 3:
4691 char ltestVal = testVal;
4692 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &ltestVal, &lU1CustMarsh, &lVBCustMarsh);
4693 if (ret)
4694 return 0x0500 + ret;
4695 if (outExpected != ltestVal)
4696 return 0x0600;
4697 break;
4699 case 4:
4701 unsigned char ltestVal = testVal;
4702 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &ltestVal, &lVBCustMarsh);
4703 if (ret)
4704 return 0x0700 + ret;
4705 if (outExpected != ltestVal)
4706 return 0x0800;
4707 break;
4709 case 5:
4711 unsigned short ltestVal = testVal;
4712 ret = pfcn (arg, expected, outTestVal, &lDefaultMarsh, &lBoolCustMarsh, &lI1CustMarsh, &lU1CustMarsh, &ltestVal);
4713 if (ret)
4714 return 0x0900 + ret;
4715 if (outExpected != ltestVal)
4716 return 0x1000;
4717 break;
4719 default:
4720 return 0x9800;
4723 return 0;
4726 #ifdef WIN32
4728 LIBTEST_API int STDCALL
4729 mono_test_marshal_safearray_out_1dim_vt_bstr_empty (SAFEARRAY** safearray)
4731 /* Create an empty one-dimensional array of variants */
4732 SAFEARRAY *pSA;
4733 SAFEARRAYBOUND dimensions [1];
4735 dimensions [0].lLbound = 0;
4736 dimensions [0].cElements = 0;
4738 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4739 *safearray = pSA;
4740 return S_OK;
4743 LIBTEST_API int STDCALL
4744 mono_test_marshal_safearray_out_1dim_vt_bstr (SAFEARRAY** safearray)
4746 /* Create a one-dimensional array of 10 variants filled with "0" to "9" */
4747 SAFEARRAY *pSA;
4748 SAFEARRAYBOUND dimensions [1];
4749 long i;
4750 gchar buffer [20];
4751 HRESULT hr = S_OK;
4752 long indices [1];
4754 dimensions [0].lLbound = 0;
4755 dimensions [0].cElements = 10;
4757 pSA= SafeArrayCreate (VT_VARIANT, 1, dimensions);
4758 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4759 VARIANT vOut;
4760 VariantInit (&vOut);
4761 vOut.vt = VT_BSTR;
4762 _ltoa (i,buffer,10);
4763 vOut.bstrVal= marshal_bstr_alloc (buffer);
4764 indices [0] = i;
4765 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4766 VariantClear (&vOut);
4767 SafeArrayDestroy (pSA);
4768 return hr;
4770 VariantClear (&vOut);
4772 *safearray = pSA;
4773 return hr;
4776 LIBTEST_API int STDCALL
4777 mono_test_marshal_safearray_out_2dim_vt_i4 (SAFEARRAY** safearray)
4779 /* Create a two-dimensional array of 4x3 variants filled with 11, 12, 13, etc. */
4780 SAFEARRAY *pSA;
4781 SAFEARRAYBOUND dimensions [2];
4782 long i, j;
4783 HRESULT hr = S_OK;
4784 long indices [2];
4786 dimensions [0].lLbound = 0;
4787 dimensions [0].cElements = 4;
4788 dimensions [1].lLbound = 0;
4789 dimensions [1].cElements = 3;
4791 pSA= SafeArrayCreate(VT_VARIANT, 2, dimensions);
4792 for (i= dimensions [0].lLbound; i< (dimensions [0].cElements + dimensions [0].lLbound); i++) {
4793 for (j= dimensions [1].lLbound; j< (dimensions [1].cElements + dimensions [1].lLbound); j++) {
4794 VARIANT vOut;
4795 VariantInit (&vOut);
4796 vOut.vt = VT_I4;
4797 vOut.lVal = (i+1)*10+(j+1);
4798 indices [0] = i;
4799 indices [1] = j;
4800 if ((hr = SafeArrayPutElement (pSA, indices, &vOut)) != S_OK) {
4801 VariantClear (&vOut);
4802 SafeArrayDestroy (pSA);
4803 return hr;
4805 VariantClear (&vOut); // does a deep destroy of source VARIANT
4808 *safearray = pSA;
4809 return hr;
4812 LIBTEST_API int STDCALL
4813 mono_test_marshal_safearray_out_4dim_vt_i4 (SAFEARRAY** safearray)
4815 /* Create a four-dimensional array of 10x3x6x7 variants filled with their indices */
4816 /* Also use non zero lower bounds */
4817 SAFEARRAY *pSA;
4818 SAFEARRAYBOUND dimensions [4];
4819 long i;
4820 HRESULT hr = S_OK;
4821 VARIANT *pData;
4823 dimensions [0].lLbound = 15;
4824 dimensions [0].cElements = 10;
4825 dimensions [1].lLbound = 20;
4826 dimensions [1].cElements = 3;
4827 dimensions [2].lLbound = 5;
4828 dimensions [2].cElements = 6;
4829 dimensions [3].lLbound = 12;
4830 dimensions [3].cElements = 7;
4832 pSA= SafeArrayCreate (VT_VARIANT, 4, dimensions);
4834 SafeArrayAccessData (pSA, (void **)&pData);
4836 for (i= 0; i< 10*3*6*7; i++) {
4837 VariantInit(&pData [i]);
4838 pData [i].vt = VT_I4;
4839 pData [i].lVal = i;
4841 SafeArrayUnaccessData (pSA);
4842 *safearray = pSA;
4843 return hr;
4846 LIBTEST_API int STDCALL
4847 mono_test_marshal_safearray_in_byval_1dim_empty (SAFEARRAY* safearray)
4849 /* Check that array is one dimensional and empty */
4851 UINT dim;
4852 long lbound, ubound;
4854 dim = SafeArrayGetDim (safearray);
4855 if (dim != 1)
4856 return 1;
4858 SafeArrayGetLBound (safearray, 1, &lbound);
4859 SafeArrayGetUBound (safearray, 1, &ubound);
4861 if ((lbound > 0) || (ubound > 0))
4862 return 1;
4864 return 0;
4867 LIBTEST_API int STDCALL
4868 mono_test_marshal_safearray_in_byval_1dim_vt_i4 (SAFEARRAY* safearray)
4870 /* Check that array is one dimensional containing integers from 1 to 10 */
4872 UINT dim;
4873 long lbound, ubound;
4874 VARIANT *pData;
4875 long i;
4876 int result=0;
4878 dim = SafeArrayGetDim (safearray);
4879 if (dim != 1)
4880 return 1;
4882 SafeArrayGetLBound (safearray, 1, &lbound);
4883 SafeArrayGetUBound (safearray, 1, &ubound);
4885 if ((lbound != 0) || (ubound != 9))
4886 return 1;
4888 SafeArrayAccessData (safearray, (void **)&pData);
4889 for (i= lbound; i <= ubound; i++) {
4890 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i + 1))
4891 result = 1;
4893 SafeArrayUnaccessData (safearray);
4895 return result;
4898 LIBTEST_API int STDCALL
4899 mono_test_marshal_safearray_in_byval_1dim_vt_mixed (SAFEARRAY* safearray)
4901 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4903 UINT dim;
4904 long lbound, ubound;
4905 VARIANT *pData;
4906 long i;
4907 long indices [1];
4908 VARIANT element;
4909 int result=0;
4911 VariantInit (&element);
4913 dim = SafeArrayGetDim (safearray);
4914 if (dim != 1)
4915 return 1;
4917 SafeArrayGetLBound (safearray, 1, &lbound);
4918 SafeArrayGetUBound (safearray, 1, &ubound);
4920 if ((lbound != 0) || (ubound != 12))
4921 return 1;
4923 SafeArrayAccessData (safearray, (void **)&pData);
4924 for (i= lbound; i <= ubound; i++) {
4925 if ((i%2 == 0) && (pData [i].vt != VT_I4))
4926 result = 1;
4927 if ((i%2 == 1) && (pData [i].vt != VT_BSTR))
4928 result = 1;
4929 if ((VariantChangeType (&pData [i], &pData [i], VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK) || (pData [i].lVal != i))
4930 result = 1;
4932 SafeArrayUnaccessData (safearray);
4934 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4936 indices [0] = 0;
4937 element.vt = VT_I4;
4938 element.lVal = 333;
4939 SafeArrayPutElement (safearray, indices, &element);
4940 VariantClear (&element);
4942 return result;
4945 LIBTEST_API int STDCALL
4946 mono_test_marshal_safearray_in_byval_2dim_vt_i4 (SAFEARRAY* safearray)
4948 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
4950 UINT dim;
4951 long lbound1, ubound1, lbound2, ubound2;
4952 long i, j, failed;
4953 long indices [2];
4954 VARIANT element;
4956 VariantInit (&element);
4958 dim = SafeArrayGetDim (safearray);
4959 if (dim != 2)
4960 return 1;
4962 SafeArrayGetLBound (safearray, 1, &lbound1);
4963 SafeArrayGetUBound (safearray, 1, &ubound1);
4965 if ((lbound1 != 0) || (ubound1 != 1))
4966 return 1;
4968 SafeArrayGetLBound (safearray, 2, &lbound2);
4969 SafeArrayGetUBound (safearray, 2, &ubound2);
4971 if ((lbound2 != 0) || (ubound2 != 3)) {
4972 return 1;
4975 for (i= lbound1; i <= ubound1; i++) {
4976 indices [0] = i;
4977 for (j= lbound2; j <= ubound2; j++) {
4978 indices [1] = j;
4979 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
4980 return 1;
4981 failed = ((element.vt != VT_I4) || (element.lVal != 10*(i+1)+(j+1)));
4982 VariantClear (&element);
4983 if (failed)
4984 return 1;
4988 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
4990 indices [0] = 0;
4991 indices [1] = 0;
4992 element.vt = VT_I4;
4993 element.lVal = 333;
4994 SafeArrayPutElement (safearray, indices, &element);
4995 VariantClear (&element);
4997 return 0;
5000 LIBTEST_API int STDCALL
5001 mono_test_marshal_safearray_in_byval_3dim_vt_bstr (SAFEARRAY* safearray)
5003 /* Check that array is one dimensional containing integers mixed with strings from 0 to 12 */
5005 UINT dim;
5006 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
5007 long i, j, k, failed;
5008 long indices [3];
5009 VARIANT element;
5011 VariantInit (&element);
5013 dim = SafeArrayGetDim (safearray);
5014 if (dim != 3)
5015 return 1;
5017 SafeArrayGetLBound (safearray, 1, &lbound1);
5018 SafeArrayGetUBound (safearray, 1, &ubound1);
5020 if ((lbound1 != 0) || (ubound1 != 1))
5021 return 1;
5023 SafeArrayGetLBound (safearray, 2, &lbound2);
5024 SafeArrayGetUBound (safearray, 2, &ubound2);
5026 if ((lbound2 != 0) || (ubound2 != 1))
5027 return 1;
5029 SafeArrayGetLBound (safearray, 3, &lbound3);
5030 SafeArrayGetUBound (safearray, 3, &ubound3);
5032 if ((lbound3 != 0) || (ubound3 != 2))
5033 return 1;
5035 for (i= lbound1; i <= ubound1; i++) {
5036 indices [0] = i;
5037 for (j= lbound2; j <= ubound2; j++) {
5038 indices [1] = j;
5039 for (k= lbound3; k <= ubound3; k++) {
5040 indices [2] = k;
5041 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
5042 return 1;
5043 failed = ((element.vt != VT_BSTR)
5044 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
5045 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
5046 VariantClear (&element);
5047 if (failed)
5048 return 1;
5053 /* Change the first element of the array to verify that [in] parameters are not marshalled back to the managed side */
5055 indices [0] = 0;
5056 indices [1] = 0;
5057 indices [2] = 0;
5058 element.vt = VT_BSTR;
5059 element.bstrVal = SysAllocString(L"Should not be copied");
5060 SafeArrayPutElement (safearray, indices, &element);
5061 VariantClear (&element);
5063 return 0;
5066 LIBTEST_API int STDCALL
5067 mono_test_marshal_safearray_in_byref_3dim_vt_bstr (SAFEARRAY** safearray)
5069 return mono_test_marshal_safearray_in_byval_3dim_vt_bstr (*safearray);
5072 LIBTEST_API int STDCALL
5073 mono_test_marshal_safearray_in_out_byref_1dim_empty (SAFEARRAY** safearray)
5075 /* Check that the input array is what is expected and change it so the caller can check */
5076 /* correct marshalling back to managed code */
5078 UINT dim;
5079 long lbound, ubound;
5080 SAFEARRAYBOUND dimensions [1];
5081 long i;
5082 wchar_t buffer [20];
5083 HRESULT hr = S_OK;
5084 long indices [1];
5086 /* Check that in array is one dimensional and empty */
5088 dim = SafeArrayGetDim (*safearray);
5089 if (dim != 1) {
5090 return 1;
5093 SafeArrayGetLBound (*safearray, 1, &lbound);
5094 SafeArrayGetUBound (*safearray, 1, &ubound);
5096 if ((lbound > 0) || (ubound > 0)) {
5097 return 1;
5100 /* Re-dimension the array and return a one-dimensional array of 8 variants filled with "0" to "7" */
5102 dimensions [0].lLbound = 0;
5103 dimensions [0].cElements = 8;
5105 hr = SafeArrayRedim (*safearray, dimensions);
5106 if (hr != S_OK)
5107 return 1;
5109 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
5110 VARIANT vOut;
5111 VariantInit (&vOut);
5112 vOut.vt = VT_BSTR;
5113 _ltow (i,buffer,10);
5114 vOut.bstrVal = SysAllocString (buffer);
5115 indices [0] = i;
5116 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
5117 VariantClear (&vOut);
5118 SafeArrayDestroy (*safearray);
5119 return hr;
5121 VariantClear (&vOut);
5123 return hr;
5126 LIBTEST_API int STDCALL
5127 mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr (SAFEARRAY** safearray)
5129 /* Check that the input array is what is expected and change it so the caller can check */
5130 /* correct marshalling back to managed code */
5132 UINT dim;
5133 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
5134 SAFEARRAYBOUND dimensions [1];
5135 long i, j, k, failed;
5136 wchar_t buffer [20];
5137 HRESULT hr = S_OK;
5138 long indices [3];
5139 VARIANT element;
5141 VariantInit (&element);
5143 /* Check that in array is three dimensional and contains the expected values */
5145 dim = SafeArrayGetDim (*safearray);
5146 if (dim != 3)
5147 return 1;
5149 SafeArrayGetLBound (*safearray, 1, &lbound1);
5150 SafeArrayGetUBound (*safearray, 1, &ubound1);
5152 if ((lbound1 != 0) || (ubound1 != 1))
5153 return 1;
5155 SafeArrayGetLBound (*safearray, 2, &lbound2);
5156 SafeArrayGetUBound (*safearray, 2, &ubound2);
5158 if ((lbound2 != 0) || (ubound2 != 1))
5159 return 1;
5161 SafeArrayGetLBound (*safearray, 3, &lbound3);
5162 SafeArrayGetUBound (*safearray, 3, &ubound3);
5164 if ((lbound3 != 0) || (ubound3 != 2))
5165 return 1;
5167 for (i= lbound1; i <= ubound1; i++) {
5168 indices [0] = i;
5169 for (j= lbound2; j <= ubound2; j++) {
5170 indices [1] = j;
5171 for (k= lbound3; k <= ubound3; k++) {
5172 indices [2] = k;
5173 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
5174 return 1;
5175 failed = ((element.vt != VT_BSTR)
5176 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
5177 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
5178 VariantClear (&element);
5179 if (failed)
5180 return 1;
5185 hr = SafeArrayDestroy (*safearray);
5186 if (hr != S_OK)
5187 return 1;
5189 /* Return a new one-dimensional array of 8 variants filled with "0" to "7" */
5191 dimensions [0].lLbound = 0;
5192 dimensions [0].cElements = 8;
5194 *safearray = SafeArrayCreate (VT_VARIANT, 1, dimensions);
5196 for (i= dimensions [0].lLbound; i< (dimensions [0].lLbound + dimensions [0].cElements); i++) {
5197 VARIANT vOut;
5198 VariantInit (&vOut);
5199 vOut.vt = VT_BSTR;
5200 _ltow (i,buffer,10);
5201 vOut.bstrVal = SysAllocString (buffer);
5202 indices [0] = i;
5203 if ((hr = SafeArrayPutElement (*safearray, indices, &vOut)) != S_OK) {
5204 VariantClear (&vOut);
5205 SafeArrayDestroy (*safearray);
5206 return hr;
5208 VariantClear (&vOut);
5210 return hr;
5213 LIBTEST_API int STDCALL
5214 mono_test_marshal_safearray_in_out_byref_1dim_vt_i4 (SAFEARRAY** safearray)
5216 /* Check that the input array is what is expected and change it so the caller can check */
5217 /* correct marshalling back to managed code */
5219 UINT dim;
5220 long lbound1, ubound1;
5221 long i, failed;
5222 HRESULT hr = S_OK;
5223 long indices [1];
5224 VARIANT element;
5226 VariantInit (&element);
5228 /* Check that in array is one dimensional and contains the expected value */
5230 dim = SafeArrayGetDim (*safearray);
5231 if (dim != 1)
5232 return 1;
5234 SafeArrayGetLBound (*safearray, 1, &lbound1);
5235 SafeArrayGetUBound (*safearray, 1, &ubound1);
5237 ubound1 = 1;
5238 if ((lbound1 != 0) || (ubound1 != 1))
5239 return 1;
5240 ubound1 = 0;
5242 for (i= lbound1; i <= ubound1; i++) {
5243 indices [0] = i;
5244 if (SafeArrayGetElement (*safearray, indices, &element) != S_OK)
5245 return 1;
5246 failed = (element.vt != VT_I4) || (element.lVal != i+1);
5247 VariantClear (&element);
5248 if (failed)
5249 return 1;
5252 /* Change one of the elements of the array to verify that [out] parameter is marshalled back to the managed side */
5254 indices [0] = 0;
5255 element.vt = VT_I4;
5256 element.lVal = -1;
5257 SafeArrayPutElement (*safearray, indices, &element);
5258 VariantClear (&element);
5260 return hr;
5263 LIBTEST_API int STDCALL
5264 mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (SAFEARRAY* safearray)
5266 /* Check that the input array is what is expected and change it so the caller can check */
5267 /* correct marshalling back to managed code */
5269 UINT dim;
5270 long lbound1, ubound1;
5271 SAFEARRAYBOUND dimensions [1];
5272 long i, failed;
5273 HRESULT hr = S_OK;
5274 long indices [1];
5275 VARIANT element;
5277 VariantInit (&element);
5279 /* Check that in array is one dimensional and contains the expected value */
5281 dim = SafeArrayGetDim (safearray);
5282 if (dim != 1)
5283 return 1;
5285 SafeArrayGetLBound (safearray, 1, &lbound1);
5286 SafeArrayGetUBound (safearray, 1, &ubound1);
5288 if ((lbound1 != 0) || (ubound1 != 0))
5289 return 1;
5291 for (i= lbound1; i <= ubound1; i++) {
5292 indices [0] = i;
5293 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
5294 return 1;
5295 failed = (element.vt != VT_I4) || (element.lVal != i+1);
5296 VariantClear (&element);
5297 if (failed)
5298 return 1;
5301 /* Change the array to verify how [out] parameter is marshalled back to the managed side */
5303 /* Redimension the array */
5304 dimensions [0].lLbound = lbound1;
5305 dimensions [0].cElements = 2;
5306 hr = SafeArrayRedim(safearray, dimensions);
5308 indices [0] = 0;
5309 element.vt = VT_I4;
5310 element.lVal = 12345;
5311 SafeArrayPutElement (safearray, indices, &element);
5312 VariantClear (&element);
5314 indices [0] = 1;
5315 element.vt = VT_I4;
5316 element.lVal = -12345;
5317 SafeArrayPutElement (safearray, indices, &element);
5318 VariantClear (&element);
5320 return hr;
5323 LIBTEST_API int STDCALL
5324 mono_test_marshal_safearray_in_out_byval_3dim_vt_bstr (SAFEARRAY* safearray)
5326 /* Check that the input array is what is expected and change it so the caller can check */
5327 /* correct marshalling back to managed code */
5329 UINT dim;
5330 long lbound1, ubound1, lbound2, ubound2, lbound3, ubound3;
5331 long i, j, k, failed;
5332 HRESULT hr = S_OK;
5333 long indices [3];
5334 VARIANT element;
5336 VariantInit (&element);
5338 /* Check that in array is three dimensional and contains the expected values */
5340 dim = SafeArrayGetDim (safearray);
5341 if (dim != 3)
5342 return 1;
5344 SafeArrayGetLBound (safearray, 1, &lbound1);
5345 SafeArrayGetUBound (safearray, 1, &ubound1);
5347 if ((lbound1 != 0) || (ubound1 != 1))
5348 return 1;
5350 SafeArrayGetLBound (safearray, 2, &lbound2);
5351 SafeArrayGetUBound (safearray, 2, &ubound2);
5353 if ((lbound2 != 0) || (ubound2 != 1))
5354 return 1;
5356 SafeArrayGetLBound (safearray, 3, &lbound3);
5357 SafeArrayGetUBound (safearray, 3, &ubound3);
5359 if ((lbound3 != 0) || (ubound3 != 2))
5360 return 1;
5362 for (i= lbound1; i <= ubound1; i++) {
5363 indices [0] = i;
5364 for (j= lbound2; j <= ubound2; j++) {
5365 indices [1] = j;
5366 for (k= lbound3; k <= ubound3; k++) {
5367 indices [2] = k;
5368 if (SafeArrayGetElement (safearray, indices, &element) != S_OK)
5369 return 1;
5370 failed = ((element.vt != VT_BSTR)
5371 || (VariantChangeType (&element, &element, VARIANT_NOUSEROVERRIDE, VT_I4) != S_OK)
5372 || (element.lVal != 100*(i+1)+10*(j+1)+(k+1)));
5373 VariantClear (&element);
5374 if (failed)
5375 return 1;
5380 /* Change the elements of the array to verify that [out] parameter is marshalled back to the managed side */
5382 indices [0] = 1;
5383 indices [1] = 1;
5384 indices [2] = 2;
5385 element.vt = VT_I4;
5386 element.lVal = 333;
5387 SafeArrayPutElement (safearray, indices, &element);
5388 VariantClear (&element);
5390 indices [0] = 1;
5391 indices [1] = 1;
5392 indices [2] = 1;
5393 element.vt = VT_I4;
5394 element.lVal = 111;
5395 SafeArrayPutElement (safearray, indices, &element);
5396 VariantClear (&element);
5398 indices [0] = 0;
5399 indices [1] = 1;
5400 indices [2] = 0;
5401 element.vt = VT_BSTR;
5402 element.bstrVal = marshal_bstr_alloc("ABCDEFG");
5403 SafeArrayPutElement (safearray, indices, &element);
5404 VariantClear (&element);
5406 return hr;
5409 LIBTEST_API int STDCALL
5410 mono_test_marshal_safearray_mixed(
5411 SAFEARRAY *safearray1,
5412 SAFEARRAY **safearray2,
5413 SAFEARRAY *safearray3,
5414 SAFEARRAY **safearray4
5417 HRESULT hr = S_OK;
5419 /* Initialize out parameters */
5420 *safearray2 = NULL;
5422 /* array1: Check that in array is one dimensional and contains the expected value */
5423 hr = mono_test_marshal_safearray_in_out_byval_1dim_vt_i4 (safearray1);
5425 /* array2: Fill in with some values to check on the managed side */
5426 if (hr == S_OK)
5427 hr = mono_test_marshal_safearray_out_1dim_vt_bstr (safearray2);
5429 /* array3: Check that in array is one dimensional and contains the expected value */
5430 if (hr == S_OK)
5431 hr = mono_test_marshal_safearray_in_byval_1dim_vt_mixed(safearray3);
5433 /* array4: Check input values and fill in with some values to check on the managed side */
5434 if (hr == S_OK)
5435 hr = mono_test_marshal_safearray_in_out_byref_3dim_vt_bstr(safearray4);
5437 return hr;
5440 #endif
5442 static int call_managed_res;
5444 static void
5445 call_managed (gpointer arg)
5447 SimpleDelegate del = (SimpleDelegate)arg;
5449 call_managed_res = del (42);
5452 LIBTEST_API int STDCALL
5453 mono_test_marshal_thread_attach (SimpleDelegate del)
5455 #ifdef WIN32
5456 return 43;
5457 #else
5458 int res;
5459 pthread_t t;
5461 res = pthread_create (&t, NULL, (gpointer (*)(gpointer))call_managed, del);
5462 g_assert (res == 0);
5463 pthread_join (t, NULL);
5465 return call_managed_res;
5466 #endif
5469 typedef int (STDCALL *Callback) (void);
5471 static Callback callback;
5473 LIBTEST_API void STDCALL
5474 mono_test_marshal_set_callback (Callback cb)
5476 callback = cb;
5479 LIBTEST_API int STDCALL
5480 mono_test_marshal_call_callback (void)
5482 return callback ();
5485 LIBTEST_API int STDCALL
5486 mono_test_marshal_lpstr (char *str)
5488 return strcmp ("ABC", str);
5491 LIBTEST_API int STDCALL
5492 mono_test_marshal_lpwstr (gunichar2 *str)
5494 char *s;
5495 int res;
5497 s = g_utf16_to_utf8 (str, -1, NULL, NULL, NULL);
5498 res = strcmp ("ABC", s);
5499 g_free (s);
5501 return res;
5504 LIBTEST_API char* STDCALL
5505 mono_test_marshal_return_lpstr (void)
5507 char *res = (char *)marshal_alloc (4);
5508 strcpy (res, "XYZ");
5509 return res;
5513 LIBTEST_API gunichar2* STDCALL
5514 mono_test_marshal_return_lpwstr (void)
5516 gunichar2 *res = (gunichar2 *)marshal_alloc (8);
5517 gunichar2* tmp = g_utf8_to_utf16 ("XYZ", -1, NULL, NULL, NULL);
5519 memcpy (res, tmp, 8);
5520 g_free (tmp);
5522 return res;
5525 typedef struct {
5526 double d;
5527 } SingleDoubleStruct;
5529 LIBTEST_API SingleDoubleStruct STDCALL
5530 mono_test_marshal_return_single_double_struct (void)
5532 SingleDoubleStruct res;
5534 res.d = 3.0;
5536 return res;
5540 #ifndef TARGET_X86
5542 LIBTEST_API int STDCALL
5543 mono_test_has_thiscall (void)
5545 return 1;
5548 LIBTEST_API int
5549 _mono_test_native_thiscall1 (int arg)
5551 return arg;
5554 LIBTEST_API int
5555 _mono_test_native_thiscall2 (int arg, int arg2)
5557 return arg + (arg2^1);
5560 LIBTEST_API int
5561 _mono_test_native_thiscall3 (int arg, int arg2, int arg3)
5563 return arg + (arg2^1) + (arg3^2);
5566 #elif defined(__GNUC__)
5568 LIBTEST_API int STDCALL
5569 mono_test_has_thiscall (void)
5571 return 1;
5574 #define def_asm_fn(name) \
5575 "\t.align 4\n" \
5576 "\t.globl _" #name "\n" \
5577 "_" #name ":\n" \
5578 "\t.globl __" #name "\n" \
5579 "__" #name ":\n"
5581 asm(".text\n"
5583 def_asm_fn(mono_test_native_thiscall1)
5584 "\tmovl %ecx,%eax\n"
5585 "\tret\n"
5587 def_asm_fn(mono_test_native_thiscall2)
5588 "\tmovl %ecx,%eax\n"
5589 "\tmovl 4(%esp),%ecx\n"
5590 "\txorl $1,%ecx\n"
5591 "\taddl %ecx,%eax\n"
5592 "\tret $4\n"
5594 def_asm_fn(mono_test_native_thiscall3)
5595 "\tmovl %ecx,%eax\n"
5596 "\tmovl 4(%esp),%ecx\n"
5597 "\txorl $1,%ecx\n"
5598 "\taddl %ecx,%eax\n"
5599 "\tmovl 8(%esp),%ecx\n"
5600 "\txorl $2,%ecx\n"
5601 "\taddl %ecx,%eax\n"
5602 "\tret $8\n"
5606 #else
5608 LIBTEST_API int STDCALL
5609 mono_test_has_thiscall (void)
5611 return 0;
5614 #endif
5617 typedef struct {
5618 char f1;
5619 } sbyte1;
5621 LIBTEST_API sbyte1 STDCALL
5622 mono_return_sbyte1 (sbyte1 s1, int addend) {
5623 if (s1.f1 != 1) {
5624 fprintf(stderr, "mono_return_sbyte1 s1.f1: got %d but expected %d\n", s1.f1, 1);
5626 s1.f1+=addend;
5627 return s1;
5630 typedef struct {
5631 char f1,f2;
5632 } sbyte2;
5634 LIBTEST_API sbyte2 STDCALL
5635 mono_return_sbyte2 (sbyte2 s2, int addend) {
5636 if (s2.f1 != 1) {
5637 fprintf(stderr, "mono_return_sbyte2 s2.f1: got %d but expected %d\n", s2.f1, 1);
5639 if (s2.f2 != 2) {
5640 fprintf(stderr, "mono_return_sbyte2 s2.f2: got %d but expected %d\n", s2.f2, 2);
5642 s2.f1+=addend; s2.f2+=addend;
5643 return s2;
5646 typedef struct {
5647 char f1,f2,f3;
5648 } sbyte3;
5650 LIBTEST_API sbyte3 STDCALL
5651 mono_return_sbyte3 (sbyte3 s3, int addend) {
5652 if (s3.f1 != 1) {
5653 fprintf(stderr, "mono_return_sbyte3 s3.f1: got %d but expected %d\n", s3.f1, 1);
5655 if (s3.f2 != 2) {
5656 fprintf(stderr, "mono_return_sbyte3 s3.f2: got %d but expected %d\n", s3.f2, 2);
5658 if (s3.f3 != 3) {
5659 fprintf(stderr, "mono_return_sbyte3 s3.f3: got %d but expected %d\n", s3.f3, 3);
5661 s3.f1+=addend; s3.f2+=addend; s3.f3+=addend;
5662 return s3;
5665 typedef struct {
5666 char f1,f2,f3,f4;
5667 } sbyte4;
5669 LIBTEST_API sbyte4 STDCALL
5670 mono_return_sbyte4 (sbyte4 s4, int addend) {
5671 if (s4.f1 != 1) {
5672 fprintf(stderr, "mono_return_sbyte4 s4.f1: got %d but expected %d\n", s4.f1, 1);
5674 if (s4.f2 != 2) {
5675 fprintf(stderr, "mono_return_sbyte4 s4.f2: got %d but expected %d\n", s4.f2, 2);
5677 if (s4.f3 != 3) {
5678 fprintf(stderr, "mono_return_sbyte4 s4.f3: got %d but expected %d\n", s4.f3, 3);
5680 if (s4.f4 != 4) {
5681 fprintf(stderr, "mono_return_sbyte4 s4.f4: got %d but expected %d\n", s4.f4, 4);
5683 s4.f1+=addend; s4.f2+=addend; s4.f3+=addend; s4.f4+=addend;
5684 return s4;
5687 typedef struct {
5688 char f1,f2,f3,f4,f5;
5689 } sbyte5;
5691 LIBTEST_API sbyte5 STDCALL
5692 mono_return_sbyte5 (sbyte5 s5, int addend) {
5693 if (s5.f1 != 1) {
5694 fprintf(stderr, "mono_return_sbyte5 s5.f1: got %d but expected %d\n", s5.f1, 1);
5696 if (s5.f2 != 2) {
5697 fprintf(stderr, "mono_return_sbyte5 s5.f2: got %d but expected %d\n", s5.f2, 2);
5699 if (s5.f3 != 3) {
5700 fprintf(stderr, "mono_return_sbyte5 s5.f3: got %d but expected %d\n", s5.f3, 3);
5702 if (s5.f4 != 4) {
5703 fprintf(stderr, "mono_return_sbyte5 s5.f4: got %d but expected %d\n", s5.f4, 4);
5705 if (s5.f5 != 5) {
5706 fprintf(stderr, "mono_return_sbyte5 s5.f5: got %d but expected %d\n", s5.f5, 5);
5708 s5.f1+=addend; s5.f2+=addend; s5.f3+=addend; s5.f4+=addend; s5.f5+=addend;
5709 return s5;
5712 typedef struct {
5713 char f1,f2,f3,f4,f5,f6;
5714 } sbyte6;
5716 LIBTEST_API sbyte6 STDCALL
5717 mono_return_sbyte6 (sbyte6 s6, int addend) {
5718 if (s6.f1 != 1) {
5719 fprintf(stderr, "mono_return_sbyte6 s6.f1: got %d but expected %d\n", s6.f1, 1);
5721 if (s6.f2 != 2) {
5722 fprintf(stderr, "mono_return_sbyte6 s6.f2: got %d but expected %d\n", s6.f2, 2);
5724 if (s6.f3 != 3) {
5725 fprintf(stderr, "mono_return_sbyte6 s6.f3: got %d but expected %d\n", s6.f3, 3);
5727 if (s6.f4 != 4) {
5728 fprintf(stderr, "mono_return_sbyte6 s6.f4: got %d but expected %d\n", s6.f4, 4);
5730 if (s6.f5 != 5) {
5731 fprintf(stderr, "mono_return_sbyte6 s6.f5: got %d but expected %d\n", s6.f5, 5);
5733 if (s6.f6 != 6) {
5734 fprintf(stderr, "mono_return_sbyte6 s6.f6: got %d but expected %d\n", s6.f6, 6);
5736 s6.f1+=addend; s6.f2+=addend; s6.f3+=addend; s6.f4+=addend; s6.f5+=addend; s6.f6+=addend;
5737 return s6;
5740 typedef struct {
5741 char f1,f2,f3,f4,f5,f6,f7;
5742 } sbyte7;
5744 LIBTEST_API sbyte7 STDCALL
5745 mono_return_sbyte7 (sbyte7 s7, int addend) {
5746 if (s7.f1 != 1) {
5747 fprintf(stderr, "mono_return_sbyte7 s7.f1: got %d but expected %d\n", s7.f1, 1);
5749 if (s7.f2 != 2) {
5750 fprintf(stderr, "mono_return_sbyte7 s7.f2: got %d but expected %d\n", s7.f2, 2);
5752 if (s7.f3 != 3) {
5753 fprintf(stderr, "mono_return_sbyte7 s7.f3: got %d but expected %d\n", s7.f3, 3);
5755 if (s7.f4 != 4) {
5756 fprintf(stderr, "mono_return_sbyte7 s7.f4: got %d but expected %d\n", s7.f4, 4);
5758 if (s7.f5 != 5) {
5759 fprintf(stderr, "mono_return_sbyte7 s7.f5: got %d but expected %d\n", s7.f5, 5);
5761 if (s7.f6 != 6) {
5762 fprintf(stderr, "mono_return_sbyte7 s7.f6: got %d but expected %d\n", s7.f6, 6);
5764 if (s7.f7 != 7) {
5765 fprintf(stderr, "mono_return_sbyte7 s7.f7: got %d but expected %d\n", s7.f7, 7);
5767 s7.f1+=addend; s7.f2+=addend; s7.f3+=addend; s7.f4+=addend; s7.f5+=addend; s7.f6+=addend; s7.f7+=addend;
5768 return s7;
5771 typedef struct {
5772 char f1,f2,f3,f4,f5,f6,f7,f8;
5773 } sbyte8;
5775 LIBTEST_API sbyte8 STDCALL
5776 mono_return_sbyte8 (sbyte8 s8, int addend) {
5777 if (s8.f1 != 1) {
5778 fprintf(stderr, "mono_return_sbyte8 s8.f1: got %d but expected %d\n", s8.f1, 1);
5780 if (s8.f2 != 2) {
5781 fprintf(stderr, "mono_return_sbyte8 s8.f2: got %d but expected %d\n", s8.f2, 2);
5783 if (s8.f3 != 3) {
5784 fprintf(stderr, "mono_return_sbyte8 s8.f3: got %d but expected %d\n", s8.f3, 3);
5786 if (s8.f4 != 4) {
5787 fprintf(stderr, "mono_return_sbyte8 s8.f4: got %d but expected %d\n", s8.f4, 4);
5789 if (s8.f5 != 5) {
5790 fprintf(stderr, "mono_return_sbyte8 s8.f5: got %d but expected %d\n", s8.f5, 5);
5792 if (s8.f6 != 6) {
5793 fprintf(stderr, "mono_return_sbyte8 s8.f6: got %d but expected %d\n", s8.f6, 6);
5795 if (s8.f7 != 7) {
5796 fprintf(stderr, "mono_return_sbyte8 s8.f7: got %d but expected %d\n", s8.f7, 7);
5798 if (s8.f8 != 8) {
5799 fprintf(stderr, "mono_return_sbyte8 s8.f8: got %d but expected %d\n", s8.f8, 8);
5801 s8.f1+=addend; s8.f2+=addend; s8.f3+=addend; s8.f4+=addend; s8.f5+=addend; s8.f6+=addend; s8.f7+=addend; s8.f8+=addend;
5802 return s8;
5805 typedef struct {
5806 char f1,f2,f3,f4,f5,f6,f7,f8,f9;
5807 } sbyte9;
5809 LIBTEST_API sbyte9 STDCALL
5810 mono_return_sbyte9 (sbyte9 s9, int addend) {
5811 if (s9.f1 != 1) {
5812 fprintf(stderr, "mono_return_sbyte9 s9.f1: got %d but expected %d\n", s9.f1, 1);
5814 if (s9.f2 != 2) {
5815 fprintf(stderr, "mono_return_sbyte9 s9.f2: got %d but expected %d\n", s9.f2, 2);
5817 if (s9.f3 != 3) {
5818 fprintf(stderr, "mono_return_sbyte9 s9.f3: got %d but expected %d\n", s9.f3, 3);
5820 if (s9.f4 != 4) {
5821 fprintf(stderr, "mono_return_sbyte9 s9.f4: got %d but expected %d\n", s9.f4, 4);
5823 if (s9.f5 != 5) {
5824 fprintf(stderr, "mono_return_sbyte9 s9.f5: got %d but expected %d\n", s9.f5, 5);
5826 if (s9.f6 != 6) {
5827 fprintf(stderr, "mono_return_sbyte9 s9.f6: got %d but expected %d\n", s9.f6, 6);
5829 if (s9.f7 != 7) {
5830 fprintf(stderr, "mono_return_sbyte9 s9.f7: got %d but expected %d\n", s9.f7, 7);
5832 if (s9.f8 != 8) {
5833 fprintf(stderr, "mono_return_sbyte9 s9.f8: got %d but expected %d\n", s9.f8, 8);
5835 if (s9.f9 != 9) {
5836 fprintf(stderr, "mono_return_sbyte9 s9.f9: got %d but expected %d\n", s9.f9, 9);
5838 s9.f1+=addend; s9.f2+=addend; s9.f3+=addend; s9.f4+=addend; s9.f5+=addend; s9.f6+=addend; s9.f7+=addend; s9.f8+=addend; s9.f9+=addend;
5839 return s9;
5842 typedef struct {
5843 char f1,f2,f3,f4,f5,f6,f7,f8,f9,f10;
5844 } sbyte10;
5846 LIBTEST_API sbyte10 STDCALL
5847 mono_return_sbyte10 (sbyte10 s10, int addend) {
5848 if (s10.f1 != 1) {
5849 fprintf(stderr, "mono_return_sbyte10 s10.f1: got %d but expected %d\n", s10.f1, 1);
5851 if (s10.f2 != 2) {
5852 fprintf(stderr, "mono_return_sbyte10 s10.f2: got %d but expected %d\n", s10.f2, 2);
5854 if (s10.f3 != 3) {
5855 fprintf(stderr, "mono_return_sbyte10 s10.f3: got %d but expected %d\n", s10.f3, 3);
5857 if (s10.f4 != 4) {
5858 fprintf(stderr, "mono_return_sbyte10 s10.f4: got %d but expected %d\n", s10.f4, 4);
5860 if (s10.f5 != 5) {
5861 fprintf(stderr, "mono_return_sbyte10 s10.f5: got %d but expected %d\n", s10.f5, 5);
5863 if (s10.f6 != 6) {
5864 fprintf(stderr, "mono_return_sbyte10 s10.f6: got %d but expected %d\n", s10.f6, 6);
5866 if (s10.f7 != 7) {
5867 fprintf(stderr, "mono_return_sbyte10 s10.f7: got %d but expected %d\n", s10.f7, 7);
5869 if (s10.f8 != 8) {
5870 fprintf(stderr, "mono_return_sbyte10 s10.f8: got %d but expected %d\n", s10.f8, 8);
5872 if (s10.f9 != 9) {
5873 fprintf(stderr, "mono_return_sbyte10 s10.f9: got %d but expected %d\n", s10.f9, 9);
5875 if (s10.f10 != 10) {
5876 fprintf(stderr, "mono_return_sbyte10 s10.f10: got %d but expected %d\n", s10.f10, 10);
5878 s10.f1+=addend; s10.f2+=addend; s10.f3+=addend; s10.f4+=addend; s10.f5+=addend; s10.f6+=addend; s10.f7+=addend; s10.f8+=addend; s10.f9+=addend; s10.f10+=addend;
5879 return s10;
5882 typedef struct {
5883 char f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11;
5884 } sbyte11;
5886 LIBTEST_API sbyte11 STDCALL
5887 mono_return_sbyte11 (sbyte11 s11, int addend) {
5888 if (s11.f1 != 1) {
5889 fprintf(stderr, "mono_return_sbyte11 s11.f1: got %d but expected %d\n", s11.f1, 1);
5891 if (s11.f2 != 2) {
5892 fprintf(stderr, "mono_return_sbyte11 s11.f2: got %d but expected %d\n", s11.f2, 2);
5894 if (s11.f3 != 3) {
5895 fprintf(stderr, "mono_return_sbyte11 s11.f3: got %d but expected %d\n", s11.f3, 3);
5897 if (s11.f4 != 4) {
5898 fprintf(stderr, "mono_return_sbyte11 s11.f4: got %d but expected %d\n", s11.f4, 4);
5900 if (s11.f5 != 5) {
5901 fprintf(stderr, "mono_return_sbyte11 s11.f5: got %d but expected %d\n", s11.f5, 5);
5903 if (s11.f6 != 6) {
5904 fprintf(stderr, "mono_return_sbyte11 s11.f6: got %d but expected %d\n", s11.f6, 6);
5906 if (s11.f7 != 7) {
5907 fprintf(stderr, "mono_return_sbyte11 s11.f7: got %d but expected %d\n", s11.f7, 7);
5909 if (s11.f8 != 8) {
5910 fprintf(stderr, "mono_return_sbyte11 s11.f8: got %d but expected %d\n", s11.f8, 8);
5912 if (s11.f9 != 9) {
5913 fprintf(stderr, "mono_return_sbyte11 s11.f9: got %d but expected %d\n", s11.f9, 9);
5915 if (s11.f10 != 10) {
5916 fprintf(stderr, "mono_return_sbyte11 s11.f10: got %d but expected %d\n", s11.f10, 10);
5918 if (s11.f11 != 11) {
5919 fprintf(stderr, "mono_return_sbyte11 s11.f11: got %d but expected %d\n", s11.f11, 11);
5921 s11.f1+=addend; s11.f2+=addend; s11.f3+=addend; s11.f4+=addend; s11.f5+=addend; s11.f6+=addend; s11.f7+=addend; s11.f8+=addend; s11.f9+=addend; s11.f10+=addend; s11.f11+=addend;
5922 return s11;
5925 typedef struct {
5926 char f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12;
5927 } sbyte12;
5929 LIBTEST_API sbyte12 STDCALL
5930 mono_return_sbyte12 (sbyte12 s12, int addend) {
5931 if (s12.f1 != 1) {
5932 fprintf(stderr, "mono_return_sbyte12 s12.f1: got %d but expected %d\n", s12.f1, 1);
5934 if (s12.f2 != 2) {
5935 fprintf(stderr, "mono_return_sbyte12 s12.f2: got %d but expected %d\n", s12.f2, 2);
5937 if (s12.f3 != 3) {
5938 fprintf(stderr, "mono_return_sbyte12 s12.f3: got %d but expected %d\n", s12.f3, 3);
5940 if (s12.f4 != 4) {
5941 fprintf(stderr, "mono_return_sbyte12 s12.f4: got %d but expected %d\n", s12.f4, 4);
5943 if (s12.f5 != 5) {
5944 fprintf(stderr, "mono_return_sbyte12 s12.f5: got %d but expected %d\n", s12.f5, 5);
5946 if (s12.f6 != 6) {
5947 fprintf(stderr, "mono_return_sbyte12 s12.f6: got %d but expected %d\n", s12.f6, 6);
5949 if (s12.f7 != 7) {
5950 fprintf(stderr, "mono_return_sbyte12 s12.f7: got %d but expected %d\n", s12.f7, 7);
5952 if (s12.f8 != 8) {
5953 fprintf(stderr, "mono_return_sbyte12 s12.f8: got %d but expected %d\n", s12.f8, 8);
5955 if (s12.f9 != 9) {
5956 fprintf(stderr, "mono_return_sbyte12 s12.f9: got %d but expected %d\n", s12.f9, 9);
5958 if (s12.f10 != 10) {
5959 fprintf(stderr, "mono_return_sbyte12 s12.f10: got %d but expected %d\n", s12.f10, 10);
5961 if (s12.f11 != 11) {
5962 fprintf(stderr, "mono_return_sbyte12 s12.f11: got %d but expected %d\n", s12.f11, 11);
5964 if (s12.f12 != 12) {
5965 fprintf(stderr, "mono_return_sbyte12 s12.f12: got %d but expected %d\n", s12.f12, 12);
5967 s12.f1+=addend; s12.f2+=addend; s12.f3+=addend; s12.f4+=addend; s12.f5+=addend; s12.f6+=addend; s12.f7+=addend; s12.f8+=addend; s12.f9+=addend; s12.f10+=addend; s12.f11+=addend; s12.f12+=addend;
5968 return s12;
5971 typedef struct {
5972 char f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13;
5973 } sbyte13;
5975 LIBTEST_API sbyte13 STDCALL
5976 mono_return_sbyte13 (sbyte13 s13, int addend) {
5977 if (s13.f1 != 1) {
5978 fprintf(stderr, "mono_return_sbyte13 s13.f1: got %d but expected %d\n", s13.f1, 1);
5980 if (s13.f2 != 2) {
5981 fprintf(stderr, "mono_return_sbyte13 s13.f2: got %d but expected %d\n", s13.f2, 2);
5983 if (s13.f3 != 3) {
5984 fprintf(stderr, "mono_return_sbyte13 s13.f3: got %d but expected %d\n", s13.f3, 3);
5986 if (s13.f4 != 4) {
5987 fprintf(stderr, "mono_return_sbyte13 s13.f4: got %d but expected %d\n", s13.f4, 4);
5989 if (s13.f5 != 5) {
5990 fprintf(stderr, "mono_return_sbyte13 s13.f5: got %d but expected %d\n", s13.f5, 5);
5992 if (s13.f6 != 6) {
5993 fprintf(stderr, "mono_return_sbyte13 s13.f6: got %d but expected %d\n", s13.f6, 6);
5995 if (s13.f7 != 7) {
5996 fprintf(stderr, "mono_return_sbyte13 s13.f7: got %d but expected %d\n", s13.f7, 7);
5998 if (s13.f8 != 8) {
5999 fprintf(stderr, "mono_return_sbyte13 s13.f8: got %d but expected %d\n", s13.f8, 8);
6001 if (s13.f9 != 9) {
6002 fprintf(stderr, "mono_return_sbyte13 s13.f9: got %d but expected %d\n", s13.f9, 9);
6004 if (s13.f10 != 10) {
6005 fprintf(stderr, "mono_return_sbyte13 s13.f10: got %d but expected %d\n", s13.f10, 10);
6007 if (s13.f11 != 11) {
6008 fprintf(stderr, "mono_return_sbyte13 s13.f11: got %d but expected %d\n", s13.f11, 11);
6010 if (s13.f12 != 12) {
6011 fprintf(stderr, "mono_return_sbyte13 s13.f12: got %d but expected %d\n", s13.f12, 12);
6013 if (s13.f13 != 13) {
6014 fprintf(stderr, "mono_return_sbyte13 s13.f13: got %d but expected %d\n", s13.f13, 13);
6016 s13.f1+=addend; s13.f2+=addend; s13.f3+=addend; s13.f4+=addend; s13.f5+=addend; s13.f6+=addend; s13.f7+=addend; s13.f8+=addend; s13.f9+=addend; s13.f10+=addend; s13.f11+=addend; s13.f12+=addend; s13.f13+=addend;
6017 return s13;
6020 typedef struct {
6021 char f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14;
6022 } sbyte14;
6024 LIBTEST_API sbyte14 STDCALL
6025 mono_return_sbyte14 (sbyte14 s14, int addend) {
6026 if (s14.f1 != 1) {
6027 fprintf(stderr, "mono_return_sbyte14 s14.f1: got %d but expected %d\n", s14.f1, 1);
6029 if (s14.f2 != 2) {
6030 fprintf(stderr, "mono_return_sbyte14 s14.f2: got %d but expected %d\n", s14.f2, 2);
6032 if (s14.f3 != 3) {
6033 fprintf(stderr, "mono_return_sbyte14 s14.f3: got %d but expected %d\n", s14.f3, 3);
6035 if (s14.f4 != 4) {
6036 fprintf(stderr, "mono_return_sbyte14 s14.f4: got %d but expected %d\n", s14.f4, 4);
6038 if (s14.f5 != 5) {
6039 fprintf(stderr, "mono_return_sbyte14 s14.f5: got %d but expected %d\n", s14.f5, 5);
6041 if (s14.f6 != 6) {
6042 fprintf(stderr, "mono_return_sbyte14 s14.f6: got %d but expected %d\n", s14.f6, 6);
6044 if (s14.f7 != 7) {
6045 fprintf(stderr, "mono_return_sbyte14 s14.f7: got %d but expected %d\n", s14.f7, 7);
6047 if (s14.f8 != 8) {
6048 fprintf(stderr, "mono_return_sbyte14 s14.f8: got %d but expected %d\n", s14.f8, 8);
6050 if (s14.f9 != 9) {
6051 fprintf(stderr, "mono_return_sbyte14 s14.f9: got %d but expected %d\n", s14.f9, 9);
6053 if (s14.f10 != 10) {
6054 fprintf(stderr, "mono_return_sbyte14 s14.f10: got %d but expected %d\n", s14.f10, 10);
6056 if (s14.f11 != 11) {
6057 fprintf(stderr, "mono_return_sbyte14 s14.f11: got %d but expected %d\n", s14.f11, 11);
6059 if (s14.f12 != 12) {
6060 fprintf(stderr, "mono_return_sbyte14 s14.f12: got %d but expected %d\n", s14.f12, 12);
6062 if (s14.f13 != 13) {
6063 fprintf(stderr, "mono_return_sbyte14 s14.f13: got %d but expected %d\n", s14.f13, 13);
6065 if (s14.f14 != 14) {
6066 fprintf(stderr, "mono_return_sbyte14 s14.f14: got %d but expected %d\n", s14.f14, 14);
6068 s14.f1+=addend; s14.f2+=addend; s14.f3+=addend; s14.f4+=addend; s14.f5+=addend; s14.f6+=addend; s14.f7+=addend; s14.f8+=addend; s14.f9+=addend; s14.f10+=addend; s14.f11+=addend; s14.f12+=addend; s14.f13+=addend; s14.f14+=addend;
6069 return s14;
6072 typedef struct {
6073 char f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15;
6074 } sbyte15;
6076 LIBTEST_API sbyte15 STDCALL
6077 mono_return_sbyte15 (sbyte15 s15, int addend) {
6078 if (s15.f1 != 1) {
6079 fprintf(stderr, "mono_return_sbyte15 s15.f1: got %d but expected %d\n", s15.f1, 1);
6081 if (s15.f2 != 2) {
6082 fprintf(stderr, "mono_return_sbyte15 s15.f2: got %d but expected %d\n", s15.f2, 2);
6084 if (s15.f3 != 3) {
6085 fprintf(stderr, "mono_return_sbyte15 s15.f3: got %d but expected %d\n", s15.f3, 3);
6087 if (s15.f4 != 4) {
6088 fprintf(stderr, "mono_return_sbyte15 s15.f4: got %d but expected %d\n", s15.f4, 4);
6090 if (s15.f5 != 5) {
6091 fprintf(stderr, "mono_return_sbyte15 s15.f5: got %d but expected %d\n", s15.f5, 5);
6093 if (s15.f6 != 6) {
6094 fprintf(stderr, "mono_return_sbyte15 s15.f6: got %d but expected %d\n", s15.f6, 6);
6096 if (s15.f7 != 7) {
6097 fprintf(stderr, "mono_return_sbyte15 s15.f7: got %d but expected %d\n", s15.f7, 7);
6099 if (s15.f8 != 8) {
6100 fprintf(stderr, "mono_return_sbyte15 s15.f8: got %d but expected %d\n", s15.f8, 8);
6102 if (s15.f9 != 9) {
6103 fprintf(stderr, "mono_return_sbyte15 s15.f9: got %d but expected %d\n", s15.f9, 9);
6105 if (s15.f10 != 10) {
6106 fprintf(stderr, "mono_return_sbyte15 s15.f10: got %d but expected %d\n", s15.f10, 10);
6108 if (s15.f11 != 11) {
6109 fprintf(stderr, "mono_return_sbyte15 s15.f11: got %d but expected %d\n", s15.f11, 11);
6111 if (s15.f12 != 12) {
6112 fprintf(stderr, "mono_return_sbyte15 s15.f12: got %d but expected %d\n", s15.f12, 12);
6114 if (s15.f13 != 13) {
6115 fprintf(stderr, "mono_return_sbyte15 s15.f13: got %d but expected %d\n", s15.f13, 13);
6117 if (s15.f14 != 14) {
6118 fprintf(stderr, "mono_return_sbyte15 s15.f14: got %d but expected %d\n", s15.f14, 14);
6120 if (s15.f15 != 15) {
6121 fprintf(stderr, "mono_return_sbyte15 s15.f15: got %d but expected %d\n", s15.f15, 15);
6123 s15.f1+=addend; s15.f2+=addend; s15.f3+=addend; s15.f4+=addend; s15.f5+=addend; s15.f6+=addend; s15.f7+=addend; s15.f8+=addend; s15.f9+=addend; s15.f10+=addend; s15.f11+=addend; s15.f12+=addend; s15.f13+=addend; s15.f14+=addend; s15.f15+=addend;
6124 return s15;
6127 typedef struct {
6128 char f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16;
6129 } sbyte16;
6131 LIBTEST_API sbyte16 STDCALL
6132 mono_return_sbyte16 (sbyte16 s16, int addend) {
6133 if (s16.f1 != 1) {
6134 fprintf(stderr, "mono_return_sbyte16 s16.f1: got %d but expected %d\n", s16.f1, 1);
6136 if (s16.f2 != 2) {
6137 fprintf(stderr, "mono_return_sbyte16 s16.f2: got %d but expected %d\n", s16.f2, 2);
6139 if (s16.f3 != 3) {
6140 fprintf(stderr, "mono_return_sbyte16 s16.f3: got %d but expected %d\n", s16.f3, 3);
6142 if (s16.f4 != 4) {
6143 fprintf(stderr, "mono_return_sbyte16 s16.f4: got %d but expected %d\n", s16.f4, 4);
6145 if (s16.f5 != 5) {
6146 fprintf(stderr, "mono_return_sbyte16 s16.f5: got %d but expected %d\n", s16.f5, 5);
6148 if (s16.f6 != 6) {
6149 fprintf(stderr, "mono_return_sbyte16 s16.f6: got %d but expected %d\n", s16.f6, 6);
6151 if (s16.f7 != 7) {
6152 fprintf(stderr, "mono_return_sbyte16 s16.f7: got %d but expected %d\n", s16.f7, 7);
6154 if (s16.f8 != 8) {
6155 fprintf(stderr, "mono_return_sbyte16 s16.f8: got %d but expected %d\n", s16.f8, 8);
6157 if (s16.f9 != 9) {
6158 fprintf(stderr, "mono_return_sbyte16 s16.f9: got %d but expected %d\n", s16.f9, 9);
6160 if (s16.f10 != 10) {
6161 fprintf(stderr, "mono_return_sbyte16 s16.f10: got %d but expected %d\n", s16.f10, 10);
6163 if (s16.f11 != 11) {
6164 fprintf(stderr, "mono_return_sbyte16 s16.f11: got %d but expected %d\n", s16.f11, 11);
6166 if (s16.f12 != 12) {
6167 fprintf(stderr, "mono_return_sbyte16 s16.f12: got %d but expected %d\n", s16.f12, 12);
6169 if (s16.f13 != 13) {
6170 fprintf(stderr, "mono_return_sbyte16 s16.f13: got %d but expected %d\n", s16.f13, 13);
6172 if (s16.f14 != 14) {
6173 fprintf(stderr, "mono_return_sbyte16 s16.f14: got %d but expected %d\n", s16.f14, 14);
6175 if (s16.f15 != 15) {
6176 fprintf(stderr, "mono_return_sbyte16 s16.f15: got %d but expected %d\n", s16.f15, 15);
6178 if (s16.f16 != 16) {
6179 fprintf(stderr, "mono_return_sbyte16 s16.f16: got %d but expected %d\n", s16.f16, 16);
6181 s16.f1+=addend; s16.f2+=addend; s16.f3+=addend; s16.f4+=addend; s16.f5+=addend; s16.f6+=addend; s16.f7+=addend; s16.f8+=addend; s16.f9+=addend; s16.f10+=addend; s16.f11+=addend; s16.f12+=addend; s16.f13+=addend; s16.f14+=addend; s16.f15+=addend; s16.f16+=addend;
6182 return s16;
6185 typedef struct {
6186 char f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17;
6187 } sbyte17;
6189 LIBTEST_API sbyte17 STDCALL
6190 mono_return_sbyte17 (sbyte17 s17, int addend) {
6191 if (s17.f1 != 1) {
6192 fprintf(stderr, "mono_return_sbyte17 s17.f1: got %d but expected %d\n", s17.f1, 1);
6194 if (s17.f2 != 2) {
6195 fprintf(stderr, "mono_return_sbyte17 s17.f2: got %d but expected %d\n", s17.f2, 2);
6197 if (s17.f3 != 3) {
6198 fprintf(stderr, "mono_return_sbyte17 s17.f3: got %d but expected %d\n", s17.f3, 3);
6200 if (s17.f4 != 4) {
6201 fprintf(stderr, "mono_return_sbyte17 s17.f4: got %d but expected %d\n", s17.f4, 4);
6203 if (s17.f5 != 5) {
6204 fprintf(stderr, "mono_return_sbyte17 s17.f5: got %d but expected %d\n", s17.f5, 5);
6206 if (s17.f6 != 6) {
6207 fprintf(stderr, "mono_return_sbyte17 s17.f6: got %d but expected %d\n", s17.f6, 6);
6209 if (s17.f7 != 7) {
6210 fprintf(stderr, "mono_return_sbyte17 s17.f7: got %d but expected %d\n", s17.f7, 7);
6212 if (s17.f8 != 8) {
6213 fprintf(stderr, "mono_return_sbyte17 s17.f8: got %d but expected %d\n", s17.f8, 8);
6215 if (s17.f9 != 9) {
6216 fprintf(stderr, "mono_return_sbyte17 s17.f9: got %d but expected %d\n", s17.f9, 9);
6218 if (s17.f10 != 10) {
6219 fprintf(stderr, "mono_return_sbyte17 s17.f10: got %d but expected %d\n", s17.f10, 10);
6221 if (s17.f11 != 11) {
6222 fprintf(stderr, "mono_return_sbyte17 s17.f11: got %d but expected %d\n", s17.f11, 11);
6224 if (s17.f12 != 12) {
6225 fprintf(stderr, "mono_return_sbyte17 s17.f12: got %d but expected %d\n", s17.f12, 12);
6227 if (s17.f13 != 13) {
6228 fprintf(stderr, "mono_return_sbyte17 s17.f13: got %d but expected %d\n", s17.f13, 13);
6230 if (s17.f14 != 14) {
6231 fprintf(stderr, "mono_return_sbyte17 s17.f14: got %d but expected %d\n", s17.f14, 14);
6233 if (s17.f15 != 15) {
6234 fprintf(stderr, "mono_return_sbyte17 s17.f15: got %d but expected %d\n", s17.f15, 15);
6236 if (s17.f16 != 16) {
6237 fprintf(stderr, "mono_return_sbyte17 s17.f16: got %d but expected %d\n", s17.f16, 16);
6239 if (s17.f17 != 17) {
6240 fprintf(stderr, "mono_return_sbyte17 s17.f17: got %d but expected %d\n", s17.f17, 17);
6242 s17.f1+=addend; s17.f2+=addend; s17.f3+=addend; s17.f4+=addend; s17.f5+=addend; s17.f6+=addend; s17.f7+=addend; s17.f8+=addend; s17.f9+=addend; s17.f10+=addend; s17.f11+=addend; s17.f12+=addend; s17.f13+=addend; s17.f14+=addend; s17.f15+=addend; s17.f16+=addend; s17.f17+=addend;
6243 return s17;
6246 typedef struct {
6247 struct {
6248 char f1;
6249 } nested1;
6250 char f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15;
6251 struct {
6252 char f16;
6253 } nested2;
6254 } sbyte16_nested;
6256 LIBTEST_API sbyte16_nested STDCALL
6257 mono_return_sbyte16_nested (sbyte16_nested sn16, int addend) {
6258 if (sn16.nested1.f1 != 1) {
6259 fprintf(stderr, "mono_return_sbyte16_nested sn16.nested1.f1: got %d but expected %d\n", sn16.nested1.f1, 1);
6261 if (sn16.f2 != 2) {
6262 fprintf(stderr, "mono_return_sbyte16_nested sn16.f2: got %d but expected %d\n", sn16.f2, 2);
6264 if (sn16.f3 != 3) {
6265 fprintf(stderr, "mono_return_sbyte16_nested sn16.f3: got %d but expected %d\n", sn16.f3, 3);
6267 if (sn16.f4 != 4) {
6268 fprintf(stderr, "mono_return_sbyte16_nested sn16.f4: got %d but expected %d\n", sn16.f4, 4);
6270 if (sn16.f5 != 5) {
6271 fprintf(stderr, "mono_return_sbyte16_nested sn16.f5: got %d but expected %d\n", sn16.f5, 5);
6273 if (sn16.f6 != 6) {
6274 fprintf(stderr, "mono_return_sbyte16_nested sn16.f6: got %d but expected %d\n", sn16.f6, 6);
6276 if (sn16.f7 != 7) {
6277 fprintf(stderr, "mono_return_sbyte16_nested sn16.f7: got %d but expected %d\n", sn16.f7, 7);
6279 if (sn16.f8 != 8) {
6280 fprintf(stderr, "mono_return_sbyte16_nested sn16.f8: got %d but expected %d\n", sn16.f8, 8);
6282 if (sn16.f9 != 9) {
6283 fprintf(stderr, "mono_return_sbyte16_nested sn16.f9: got %d but expected %d\n", sn16.f9, 9);
6285 if (sn16.f10 != 10) {
6286 fprintf(stderr, "mono_return_sbyte16_nested sn16.f10: got %d but expected %d\n", sn16.f10, 10);
6288 if (sn16.f11 != 11) {
6289 fprintf(stderr, "mono_return_sbyte16_nested sn16.f11: got %d but expected %d\n", sn16.f11, 11);
6291 if (sn16.f12 != 12) {
6292 fprintf(stderr, "mono_return_sbyte16_nested sn16.f12: got %d but expected %d\n", sn16.f12, 12);
6294 if (sn16.f13 != 13) {
6295 fprintf(stderr, "mono_return_sbyte16_nested sn16.f13: got %d but expected %d\n", sn16.f13, 13);
6297 if (sn16.f14 != 14) {
6298 fprintf(stderr, "mono_return_sbyte16_nested sn16.f14: got %d but expected %d\n", sn16.f14, 14);
6300 if (sn16.f15 != 15) {
6301 fprintf(stderr, "mono_return_sbyte16_nested sn16.f15: got %d but expected %d\n", sn16.f15, 15);
6303 if (sn16.nested2.f16 != 16) {
6304 fprintf(stderr, "mono_return_sbyte16_nested sn16.nested2.f16: got %d but expected %d\n", sn16.nested2.f16, 16);
6306 sn16.nested1.f1+=addend; sn16.f2+=addend; sn16.f3+=addend; sn16.f4+=addend; sn16.f5+=addend; sn16.f6+=addend; sn16.f7+=addend; sn16.f8+=addend; sn16.f9+=addend; sn16.f10+=addend; sn16.f11+=addend; sn16.f12+=addend; sn16.f13+=addend; sn16.f14+=addend; sn16.f15+=addend; sn16.nested2.f16+=addend;
6307 return sn16;
6311 typedef struct {
6312 short f1;
6313 } short1;
6315 LIBTEST_API short1 STDCALL
6316 mono_return_short1 (short1 s1, int addend) {
6317 if (s1.f1 != 1) {
6318 fprintf(stderr, "mono_return_short1 s1.f1: got %d but expected %d\n", s1.f1, 1);
6320 s1.f1+=addend;
6321 return s1;
6324 typedef struct {
6325 short f1,f2;
6326 } short2;
6328 LIBTEST_API short2 STDCALL
6329 mono_return_short2 (short2 s2, int addend) {
6330 if (s2.f1 != 1) {
6331 fprintf(stderr, "mono_return_short2 s2.f1: got %d but expected %d\n", s2.f1, 1);
6333 if (s2.f2 != 2) {
6334 fprintf(stderr, "mono_return_short2 s2.f2: got %d but expected %d\n", s2.f2, 2);
6336 s2.f1+=addend; s2.f2+=addend;
6337 return s2;
6340 typedef struct {
6341 short f1,f2,f3;
6342 } short3;
6344 LIBTEST_API short3 STDCALL
6345 mono_return_short3 (short3 s3, int addend) {
6346 if (s3.f1 != 1) {
6347 fprintf(stderr, "mono_return_short3 s3.f1: got %d but expected %d\n", s3.f1, 1);
6349 if (s3.f2 != 2) {
6350 fprintf(stderr, "mono_return_short3 s3.f2: got %d but expected %d\n", s3.f2, 2);
6352 if (s3.f3 != 3) {
6353 fprintf(stderr, "mono_return_short3 s3.f3: got %d but expected %d\n", s3.f3, 3);
6355 s3.f1+=addend; s3.f2+=addend; s3.f3+=addend;
6356 return s3;
6359 typedef struct {
6360 short f1,f2,f3,f4;
6361 } short4;
6363 LIBTEST_API short4 STDCALL
6364 mono_return_short4 (short4 s4, int addend) {
6365 if (s4.f1 != 1) {
6366 fprintf(stderr, "mono_return_short4 s4.f1: got %d but expected %d\n", s4.f1, 1);
6368 if (s4.f2 != 2) {
6369 fprintf(stderr, "mono_return_short4 s4.f2: got %d but expected %d\n", s4.f2, 2);
6371 if (s4.f3 != 3) {
6372 fprintf(stderr, "mono_return_short4 s4.f3: got %d but expected %d\n", s4.f3, 3);
6374 if (s4.f4 != 4) {
6375 fprintf(stderr, "mono_return_short4 s4.f4: got %d but expected %d\n", s4.f4, 4);
6377 s4.f1+=addend; s4.f2+=addend; s4.f3+=addend; s4.f4+=addend;
6378 return s4;
6381 typedef struct {
6382 short f1,f2,f3,f4,f5;
6383 } short5;
6385 LIBTEST_API short5 STDCALL
6386 mono_return_short5 (short5 s5, int addend) {
6387 if (s5.f1 != 1) {
6388 fprintf(stderr, "mono_return_short5 s5.f1: got %d but expected %d\n", s5.f1, 1);
6390 if (s5.f2 != 2) {
6391 fprintf(stderr, "mono_return_short5 s5.f2: got %d but expected %d\n", s5.f2, 2);
6393 if (s5.f3 != 3) {
6394 fprintf(stderr, "mono_return_short5 s5.f3: got %d but expected %d\n", s5.f3, 3);
6396 if (s5.f4 != 4) {
6397 fprintf(stderr, "mono_return_short5 s5.f4: got %d but expected %d\n", s5.f4, 4);
6399 if (s5.f5 != 5) {
6400 fprintf(stderr, "mono_return_short5 s5.f5: got %d but expected %d\n", s5.f5, 5);
6402 s5.f1+=addend; s5.f2+=addend; s5.f3+=addend; s5.f4+=addend; s5.f5+=addend;
6403 return s5;
6406 typedef struct {
6407 short f1,f2,f3,f4,f5,f6;
6408 } short6;
6410 LIBTEST_API short6 STDCALL
6411 mono_return_short6 (short6 s6, int addend) {
6412 if (s6.f1 != 1) {
6413 fprintf(stderr, "mono_return_short6 s6.f1: got %d but expected %d\n", s6.f1, 1);
6415 if (s6.f2 != 2) {
6416 fprintf(stderr, "mono_return_short6 s6.f2: got %d but expected %d\n", s6.f2, 2);
6418 if (s6.f3 != 3) {
6419 fprintf(stderr, "mono_return_short6 s6.f3: got %d but expected %d\n", s6.f3, 3);
6421 if (s6.f4 != 4) {
6422 fprintf(stderr, "mono_return_short6 s6.f4: got %d but expected %d\n", s6.f4, 4);
6424 if (s6.f5 != 5) {
6425 fprintf(stderr, "mono_return_short6 s6.f5: got %d but expected %d\n", s6.f5, 5);
6427 if (s6.f6 != 6) {
6428 fprintf(stderr, "mono_return_short6 s6.f6: got %d but expected %d\n", s6.f6, 6);
6430 s6.f1+=addend; s6.f2+=addend; s6.f3+=addend; s6.f4+=addend; s6.f5+=addend; s6.f6+=addend;
6431 return s6;
6434 typedef struct {
6435 short f1,f2,f3,f4,f5,f6,f7;
6436 } short7;
6438 LIBTEST_API short7 STDCALL
6439 mono_return_short7 (short7 s7, int addend) {
6440 if (s7.f1 != 1) {
6441 fprintf(stderr, "mono_return_short7 s7.f1: got %d but expected %d\n", s7.f1, 1);
6443 if (s7.f2 != 2) {
6444 fprintf(stderr, "mono_return_short7 s7.f2: got %d but expected %d\n", s7.f2, 2);
6446 if (s7.f3 != 3) {
6447 fprintf(stderr, "mono_return_short7 s7.f3: got %d but expected %d\n", s7.f3, 3);
6449 if (s7.f4 != 4) {
6450 fprintf(stderr, "mono_return_short7 s7.f4: got %d but expected %d\n", s7.f4, 4);
6452 if (s7.f5 != 5) {
6453 fprintf(stderr, "mono_return_short7 s7.f5: got %d but expected %d\n", s7.f5, 5);
6455 if (s7.f6 != 6) {
6456 fprintf(stderr, "mono_return_short7 s7.f6: got %d but expected %d\n", s7.f6, 6);
6458 if (s7.f7 != 7) {
6459 fprintf(stderr, "mono_return_short7 s7.f7: got %d but expected %d\n", s7.f7, 7);
6461 s7.f1+=addend; s7.f2+=addend; s7.f3+=addend; s7.f4+=addend; s7.f5+=addend; s7.f6+=addend; s7.f7+=addend;
6462 return s7;
6465 typedef struct {
6466 short f1,f2,f3,f4,f5,f6,f7,f8;
6467 } short8;
6469 LIBTEST_API short8 STDCALL
6470 mono_return_short8 (short8 s8, int addend) {
6471 if (s8.f1 != 1) {
6472 fprintf(stderr, "mono_return_short8 s8.f1: got %d but expected %d\n", s8.f1, 1);
6474 if (s8.f2 != 2) {
6475 fprintf(stderr, "mono_return_short8 s8.f2: got %d but expected %d\n", s8.f2, 2);
6477 if (s8.f3 != 3) {
6478 fprintf(stderr, "mono_return_short8 s8.f3: got %d but expected %d\n", s8.f3, 3);
6480 if (s8.f4 != 4) {
6481 fprintf(stderr, "mono_return_short8 s8.f4: got %d but expected %d\n", s8.f4, 4);
6483 if (s8.f5 != 5) {
6484 fprintf(stderr, "mono_return_short8 s8.f5: got %d but expected %d\n", s8.f5, 5);
6486 if (s8.f6 != 6) {
6487 fprintf(stderr, "mono_return_short8 s8.f6: got %d but expected %d\n", s8.f6, 6);
6489 if (s8.f7 != 7) {
6490 fprintf(stderr, "mono_return_short8 s8.f7: got %d but expected %d\n", s8.f7, 7);
6492 if (s8.f8 != 8) {
6493 fprintf(stderr, "mono_return_short8 s8.f8: got %d but expected %d\n", s8.f8, 8);
6495 s8.f1+=addend; s8.f2+=addend; s8.f3+=addend; s8.f4+=addend; s8.f5+=addend; s8.f6+=addend; s8.f7+=addend; s8.f8+=addend;
6496 return s8;
6499 typedef struct {
6500 short f1,f2,f3,f4,f5,f6,f7,f8,f9;
6501 } short9;
6503 LIBTEST_API short9 STDCALL
6504 mono_return_short9 (short9 s9, int addend) {
6505 if (s9.f1 != 1) {
6506 fprintf(stderr, "mono_return_short9 s9.f1: got %d but expected %d\n", s9.f1, 1);
6508 if (s9.f2 != 2) {
6509 fprintf(stderr, "mono_return_short9 s9.f2: got %d but expected %d\n", s9.f2, 2);
6511 if (s9.f3 != 3) {
6512 fprintf(stderr, "mono_return_short9 s9.f3: got %d but expected %d\n", s9.f3, 3);
6514 if (s9.f4 != 4) {
6515 fprintf(stderr, "mono_return_short9 s9.f4: got %d but expected %d\n", s9.f4, 4);
6517 if (s9.f5 != 5) {
6518 fprintf(stderr, "mono_return_short9 s9.f5: got %d but expected %d\n", s9.f5, 5);
6520 if (s9.f6 != 6) {
6521 fprintf(stderr, "mono_return_short9 s9.f6: got %d but expected %d\n", s9.f6, 6);
6523 if (s9.f7 != 7) {
6524 fprintf(stderr, "mono_return_short9 s9.f7: got %d but expected %d\n", s9.f7, 7);
6526 if (s9.f8 != 8) {
6527 fprintf(stderr, "mono_return_short9 s9.f8: got %d but expected %d\n", s9.f8, 8);
6529 if (s9.f9 != 9) {
6530 fprintf(stderr, "mono_return_short9 s9.f9: got %d but expected %d\n", s9.f9, 9);
6532 s9.f1+=addend; s9.f2+=addend; s9.f3+=addend; s9.f4+=addend; s9.f5+=addend; s9.f6+=addend; s9.f7+=addend; s9.f8+=addend; s9.f9+=addend;
6533 return s9;
6536 typedef struct {
6537 struct {
6538 short f1;
6539 } nested1;
6540 short f2,f3,f4,f5,f6,f7;
6541 struct {
6542 short f8;
6543 } nested2;
6544 } short8_nested;
6546 LIBTEST_API short8_nested STDCALL
6547 mono_return_short8_nested (short8_nested sn8, int addend) {
6548 if (sn8.nested1.f1 != 1) {
6549 fprintf(stderr, "mono_return_short8_nested sn8.nested1.f1: got %d but expected %d\n", sn8.nested1.f1, 1);
6551 if (sn8.f2 != 2) {
6552 fprintf(stderr, "mono_return_short8_nested sn8.f2: got %d but expected %d\n", sn8.f2, 2);
6554 if (sn8.f3 != 3) {
6555 fprintf(stderr, "mono_return_short8_nested sn8.f3: got %d but expected %d\n", sn8.f3, 3);
6557 if (sn8.f4 != 4) {
6558 fprintf(stderr, "mono_return_short8_nested sn8.f4: got %d but expected %d\n", sn8.f4, 4);
6560 if (sn8.f5 != 5) {
6561 fprintf(stderr, "mono_return_short8_nested sn8.f5: got %d but expected %d\n", sn8.f5, 5);
6563 if (sn8.f6 != 6) {
6564 fprintf(stderr, "mono_return_short8_nested sn8.f6: got %d but expected %d\n", sn8.f6, 6);
6566 if (sn8.f7 != 7) {
6567 fprintf(stderr, "mono_return_short8_nested sn8.f7: got %d but expected %d\n", sn8.f7, 7);
6569 if (sn8.nested2.f8 != 8) {
6570 fprintf(stderr, "mono_return_short8_nested sn8.nested2.f8: got %d but expected %d\n", sn8.nested2.f8, 8);
6572 sn8.nested1.f1+=addend; sn8.f2+=addend; sn8.f3+=addend; sn8.f4+=addend; sn8.f5+=addend; sn8.f6+=addend; sn8.f7+=addend; sn8.nested2.f8+=addend;
6573 return sn8;
6577 typedef struct {
6578 int f1;
6579 } int1;
6581 LIBTEST_API int1 STDCALL
6582 mono_return_int1 (int1 s1, int addend) {
6583 if (s1.f1 != 1) {
6584 fprintf(stderr, "mono_return_int1 s1.f1: got %d but expected %d\n", s1.f1, 1);
6586 s1.f1+=addend;
6587 return s1;
6590 typedef struct {
6591 int f1,f2;
6592 } int2;
6594 LIBTEST_API int2 STDCALL
6595 mono_return_int2 (int2 s2, int addend) {
6596 if (s2.f1 != 1) {
6597 fprintf(stderr, "mono_return_int2 s2.f1: got %d but expected %d\n", s2.f1, 1);
6599 if (s2.f2 != 2) {
6600 fprintf(stderr, "mono_return_int2 s2.f2: got %d but expected %d\n", s2.f2, 2);
6602 s2.f1+=addend; s2.f2+=addend;
6603 return s2;
6606 typedef struct {
6607 int f1,f2,f3;
6608 } int3;
6610 LIBTEST_API int3 STDCALL
6611 mono_return_int3 (int3 s3, int addend) {
6612 if (s3.f1 != 1) {
6613 fprintf(stderr, "mono_return_int3 s3.f1: got %d but expected %d\n", s3.f1, 1);
6615 if (s3.f2 != 2) {
6616 fprintf(stderr, "mono_return_int3 s3.f2: got %d but expected %d\n", s3.f2, 2);
6618 if (s3.f3 != 3) {
6619 fprintf(stderr, "mono_return_int3 s3.f3: got %d but expected %d\n", s3.f3, 3);
6621 s3.f1+=addend; s3.f2+=addend; s3.f3+=addend;
6622 return s3;
6625 typedef struct {
6626 int f1,f2,f3,f4;
6627 } int4;
6629 LIBTEST_API int4 STDCALL
6630 mono_return_int4 (int4 s4, int addend) {
6631 if (s4.f1 != 1) {
6632 fprintf(stderr, "mono_return_int4 s4.f1: got %d but expected %d\n", s4.f1, 1);
6634 if (s4.f2 != 2) {
6635 fprintf(stderr, "mono_return_int4 s4.f2: got %d but expected %d\n", s4.f2, 2);
6637 if (s4.f3 != 3) {
6638 fprintf(stderr, "mono_return_int4 s4.f3: got %d but expected %d\n", s4.f3, 3);
6640 if (s4.f4 != 4) {
6641 fprintf(stderr, "mono_return_int4 s4.f4: got %d but expected %d\n", s4.f4, 4);
6643 s4.f1+=addend; s4.f2+=addend; s4.f3+=addend; s4.f4+=addend;
6644 return s4;
6647 typedef struct {
6648 int f1,f2,f3,f4,f5;
6649 } int5;
6651 LIBTEST_API int5 STDCALL
6652 mono_return_int5 (int5 s5, int addend) {
6653 if (s5.f1 != 1) {
6654 fprintf(stderr, "mono_return_int5 s5.f1: got %d but expected %d\n", s5.f1, 1);
6656 if (s5.f2 != 2) {
6657 fprintf(stderr, "mono_return_int5 s5.f2: got %d but expected %d\n", s5.f2, 2);
6659 if (s5.f3 != 3) {
6660 fprintf(stderr, "mono_return_int5 s5.f3: got %d but expected %d\n", s5.f3, 3);
6662 if (s5.f4 != 4) {
6663 fprintf(stderr, "mono_return_int5 s5.f4: got %d but expected %d\n", s5.f4, 4);
6665 if (s5.f5 != 5) {
6666 fprintf(stderr, "mono_return_int5 s5.f5: got %d but expected %d\n", s5.f5, 5);
6668 s5.f1+=addend; s5.f2+=addend; s5.f3+=addend; s5.f4+=addend; s5.f5+=addend;
6669 return s5;
6672 typedef struct {
6673 struct {
6674 int f1;
6675 } nested1;
6676 int f2,f3;
6677 struct {
6678 int f4;
6679 } nested2;
6680 } int4_nested;
6682 LIBTEST_API int4_nested STDCALL
6683 mono_return_int4_nested (int4_nested sn4, int addend) {
6684 if (sn4.nested1.f1 != 1) {
6685 fprintf(stderr, "mono_return_int4_nested sn4.nested1.f1: got %d but expected %d\n", sn4.nested1.f1, 1);
6687 if (sn4.f2 != 2) {
6688 fprintf(stderr, "mono_return_int4_nested sn4.f2: got %d but expected %d\n", sn4.f2, 2);
6690 if (sn4.f3 != 3) {
6691 fprintf(stderr, "mono_return_int4_nested sn4.f3: got %d but expected %d\n", sn4.f3, 3);
6693 if (sn4.nested2.f4 != 4) {
6694 fprintf(stderr, "mono_return_int4_nested sn4.nested2.f4: got %d but expected %d\n", sn4.nested2.f4, 4);
6696 sn4.nested1.f1+=addend; sn4.f2+=addend; sn4.f3+=addend; sn4.nested2.f4+=addend;
6697 return sn4;
6700 typedef struct {
6701 float f1;
6702 } float1;
6704 LIBTEST_API float1 STDCALL
6705 mono_return_float1 (float1 s1, int addend) {
6706 if (s1.f1 != 1) {
6707 fprintf(stderr, "mono_return_float1 s1.f1: got %f but expected %d\n", s1.f1, 1);
6709 s1.f1+=addend;
6710 return s1;
6713 typedef struct {
6714 float f1,f2;
6715 } float2;
6717 LIBTEST_API float2 STDCALL
6718 mono_return_float2 (float2 s2, int addend) {
6719 if (s2.f1 != 1) {
6720 fprintf(stderr, "mono_return_float2 s2.f1: got %f but expected %d\n", s2.f1, 1);
6722 if (s2.f2 != 2) {
6723 fprintf(stderr, "mono_return_float2 s2.f2: got %f but expected %d\n", s2.f2, 2);
6725 s2.f1+=addend; s2.f2+=addend;
6726 return s2;
6729 typedef struct {
6730 float f1,f2,f3;
6731 } float3;
6733 LIBTEST_API float3 STDCALL
6734 mono_return_float3 (float3 s3, int addend) {
6735 if (s3.f1 != 1) {
6736 fprintf(stderr, "mono_return_float3 s3.f1: got %f but expected %d\n", s3.f1, 1);
6738 if (s3.f2 != 2) {
6739 fprintf(stderr, "mono_return_float3 s3.f2: got %f but expected %d\n", s3.f2, 2);
6741 if (s3.f3 != 3) {
6742 fprintf(stderr, "mono_return_float3 s3.f3: got %f but expected %d\n", s3.f3, 3);
6744 s3.f1+=addend; s3.f2+=addend; s3.f3+=addend;
6745 return s3;
6748 typedef struct {
6749 float f1,f2,f3,f4;
6750 } float4;
6752 LIBTEST_API float4 STDCALL
6753 mono_return_float4 (float4 s4, int addend) {
6754 if (s4.f1 != 1) {
6755 fprintf(stderr, "mono_return_float4 s4.f1: got %f but expected %d\n", s4.f1, 1);
6757 if (s4.f2 != 2) {
6758 fprintf(stderr, "mono_return_float4 s4.f2: got %f but expected %d\n", s4.f2, 2);
6760 if (s4.f3 != 3) {
6761 fprintf(stderr, "mono_return_float4 s4.f3: got %f but expected %d\n", s4.f3, 3);
6763 if (s4.f4 != 4) {
6764 fprintf(stderr, "mono_return_float4 s4.f4: got %f but expected %d\n", s4.f4, 4);
6766 s4.f1+=addend; s4.f2+=addend; s4.f3+=addend; s4.f4+=addend;
6767 return s4;
6770 typedef struct {
6771 float f1,f2,f3,f4,f5;
6772 } float5;
6774 LIBTEST_API float5 STDCALL
6775 mono_return_float5 (float5 s5, int addend) {
6776 if (s5.f1 != 1) {
6777 fprintf(stderr, "mono_return_float5 s5.f1: got %f but expected %d\n", s5.f1, 1);
6779 if (s5.f2 != 2) {
6780 fprintf(stderr, "mono_return_float5 s5.f2: got %f but expected %d\n", s5.f2, 2);
6782 if (s5.f3 != 3) {
6783 fprintf(stderr, "mono_return_float5 s5.f3: got %f but expected %d\n", s5.f3, 3);
6785 if (s5.f4 != 4) {
6786 fprintf(stderr, "mono_return_float5 s5.f4: got %f but expected %d\n", s5.f4, 4);
6788 if (s5.f5 != 5) {
6789 fprintf(stderr, "mono_return_float5 s5.f5: got %f but expected %d\n", s5.f5, 5);
6791 s5.f1+=addend; s5.f2+=addend; s5.f3+=addend; s5.f4+=addend; s5.f5+=addend;
6792 return s5;
6795 typedef struct {
6796 float f1,f2,f3,f4,f5,f6;
6797 } float6;
6799 LIBTEST_API float6 STDCALL
6800 mono_return_float6 (float6 s6, int addend) {
6801 if (s6.f1 != 1) {
6802 fprintf(stderr, "mono_return_float6 s6.f1: got %f but expected %d\n", s6.f1, 1);
6804 if (s6.f2 != 2) {
6805 fprintf(stderr, "mono_return_float6 s6.f2: got %f but expected %d\n", s6.f2, 2);
6807 if (s6.f3 != 3) {
6808 fprintf(stderr, "mono_return_float6 s6.f3: got %f but expected %d\n", s6.f3, 3);
6810 if (s6.f4 != 4) {
6811 fprintf(stderr, "mono_return_float6 s6.f4: got %f but expected %d\n", s6.f4, 4);
6813 if (s6.f5 != 5) {
6814 fprintf(stderr, "mono_return_float6 s6.f5: got %f but expected %d\n", s6.f5, 5);
6816 if (s6.f6 != 6) {
6817 fprintf(stderr, "mono_return_float6 s6.f6: got %f but expected %d\n", s6.f6, 6);
6819 s6.f1+=addend; s6.f2+=addend; s6.f3+=addend; s6.f4+=addend; s6.f5+=addend; s6.f6+=addend;
6820 return s6;
6823 typedef struct {
6824 float f1,f2,f3,f4,f5,f6,f7;
6825 } float7;
6827 LIBTEST_API float7 STDCALL
6828 mono_return_float7 (float7 s7, int addend) {
6829 if (s7.f1 != 1) {
6830 fprintf(stderr, "mono_return_float7 s7.f1: got %f but expected %d\n", s7.f1, 1);
6832 if (s7.f2 != 2) {
6833 fprintf(stderr, "mono_return_float7 s7.f2: got %f but expected %d\n", s7.f2, 2);
6835 if (s7.f3 != 3) {
6836 fprintf(stderr, "mono_return_float7 s7.f3: got %f but expected %d\n", s7.f3, 3);
6838 if (s7.f4 != 4) {
6839 fprintf(stderr, "mono_return_float7 s7.f4: got %f but expected %d\n", s7.f4, 4);
6841 if (s7.f5 != 5) {
6842 fprintf(stderr, "mono_return_float7 s7.f5: got %f but expected %d\n", s7.f5, 5);
6844 if (s7.f6 != 6) {
6845 fprintf(stderr, "mono_return_float7 s7.f6: got %f but expected %d\n", s7.f6, 6);
6847 if (s7.f7 != 7) {
6848 fprintf(stderr, "mono_return_float7 s7.f7: got %f but expected %d\n", s7.f7, 7);
6850 s7.f1+=addend; s7.f2+=addend; s7.f3+=addend; s7.f4+=addend; s7.f5+=addend; s7.f6+=addend; s7.f7+=addend;
6851 return s7;
6854 typedef struct {
6855 float f1,f2,f3,f4,f5,f6,f7,f8;
6856 } float8;
6858 LIBTEST_API float8 STDCALL
6859 mono_return_float8 (float8 s8, int addend) {
6860 if (s8.f1 != 1) {
6861 fprintf(stderr, "mono_return_float8 s8.f1: got %f but expected %d\n", s8.f1, 1);
6863 if (s8.f2 != 2) {
6864 fprintf(stderr, "mono_return_float8 s8.f2: got %f but expected %d\n", s8.f2, 2);
6866 if (s8.f3 != 3) {
6867 fprintf(stderr, "mono_return_float8 s8.f3: got %f but expected %d\n", s8.f3, 3);
6869 if (s8.f4 != 4) {
6870 fprintf(stderr, "mono_return_float8 s8.f4: got %f but expected %d\n", s8.f4, 4);
6872 if (s8.f5 != 5) {
6873 fprintf(stderr, "mono_return_float8 s8.f5: got %f but expected %d\n", s8.f5, 5);
6875 if (s8.f6 != 6) {
6876 fprintf(stderr, "mono_return_float8 s8.f6: got %f but expected %d\n", s8.f6, 6);
6878 if (s8.f7 != 7) {
6879 fprintf(stderr, "mono_return_float8 s8.f7: got %f but expected %d\n", s8.f7, 7);
6881 if (s8.f8 != 8) {
6882 fprintf(stderr, "mono_return_float8 s8.f8: got %f but expected %d\n", s8.f8, 8);
6884 s8.f1+=addend; s8.f2+=addend; s8.f3+=addend; s8.f4+=addend; s8.f5+=addend; s8.f6+=addend; s8.f7+=addend; s8.f8+=addend;
6885 return s8;
6888 typedef struct {
6889 float f1,f2,f3,f4,f5,f6,f7,f8,f9;
6890 } float9;
6892 LIBTEST_API float9 STDCALL
6893 mono_return_float9 (float9 s9, int addend) {
6894 if (s9.f1 != 1) {
6895 fprintf(stderr, "mono_return_float9 s9.f1: got %f but expected %d\n", s9.f1, 1);
6897 if (s9.f2 != 2) {
6898 fprintf(stderr, "mono_return_float9 s9.f2: got %f but expected %d\n", s9.f2, 2);
6900 if (s9.f3 != 3) {
6901 fprintf(stderr, "mono_return_float9 s9.f3: got %f but expected %d\n", s9.f3, 3);
6903 if (s9.f4 != 4) {
6904 fprintf(stderr, "mono_return_float9 s9.f4: got %f but expected %d\n", s9.f4, 4);
6906 if (s9.f5 != 5) {
6907 fprintf(stderr, "mono_return_float9 s9.f5: got %f but expected %d\n", s9.f5, 5);
6909 if (s9.f6 != 6) {
6910 fprintf(stderr, "mono_return_float9 s9.f6: got %f but expected %d\n", s9.f6, 6);
6912 if (s9.f7 != 7) {
6913 fprintf(stderr, "mono_return_float9 s9.f7: got %f but expected %d\n", s9.f7, 7);
6915 if (s9.f8 != 8) {
6916 fprintf(stderr, "mono_return_float9 s9.f8: got %f but expected %d\n", s9.f8, 8);
6918 if (s9.f9 != 9) {
6919 fprintf(stderr, "mono_return_float9 s9.f9: got %f but expected %d\n", s9.f9, 9);
6921 s9.f1+=addend; s9.f2+=addend; s9.f3+=addend; s9.f4+=addend; s9.f5+=addend; s9.f6+=addend; s9.f7+=addend; s9.f8+=addend; s9.f9+=addend;
6922 return s9;
6925 typedef struct {
6926 struct {
6927 float f1;
6928 } nested1;
6929 float f2,f3;
6930 struct {
6931 float f4;
6932 } nested2;
6933 } float4_nested;
6935 LIBTEST_API float4_nested STDCALL
6936 mono_return_float4_nested (float4_nested sn4, int addend) {
6937 if (sn4.nested1.f1 != 1) {
6938 fprintf(stderr, "mono_return_float4_nested sn4.nested1.f1: got %f but expected %d\n", sn4.nested1.f1, 1);
6940 if (sn4.f2 != 2) {
6941 fprintf(stderr, "mono_return_float4_nested sn4.f2: got %f but expected %d\n", sn4.f2, 2);
6943 if (sn4.f3 != 3) {
6944 fprintf(stderr, "mono_return_float4_nested sn4.f3: got %f but expected %d\n", sn4.f3, 3);
6946 if (sn4.nested2.f4 != 4) {
6947 fprintf(stderr, "mono_return_float4_nested sn4.nested2.f4: got %f but expected %d\n", sn4.nested2.f4, 4);
6949 sn4.nested1.f1+=addend; sn4.f2+=addend; sn4.f3+=addend; sn4.nested2.f4+=addend;
6950 return sn4;
6953 typedef struct {
6954 double f1;
6955 } double1;
6957 LIBTEST_API double1 STDCALL
6958 mono_return_double1 (double1 s1, int addend) {
6959 if (s1.f1 != 1) {
6960 fprintf(stderr, "mono_return_double1 s1.f1: got %f but expected %d\n", s1.f1, 1);
6962 s1.f1+=addend;
6963 return s1;
6966 typedef struct {
6967 double f1,f2;
6968 } double2;
6970 LIBTEST_API double2 STDCALL
6971 mono_return_double2 (double2 s2, int addend) {
6972 if (s2.f1 != 1) {
6973 fprintf(stderr, "mono_return_double2 s2.f1: got %f but expected %d\n", s2.f1, 1);
6975 if (s2.f2 != 2) {
6976 fprintf(stderr, "mono_return_double2 s2.f2: got %f but expected %d\n", s2.f2, 2);
6978 s2.f1+=addend; s2.f2+=addend;
6979 return s2;
6982 typedef struct {
6983 double f1,f2,f3;
6984 } double3;
6986 LIBTEST_API double3 STDCALL
6987 mono_return_double3 (double3 s3, int addend) {
6988 if (s3.f1 != 1) {
6989 fprintf(stderr, "mono_return_double3 s3.f1: got %f but expected %d\n", s3.f1, 1);
6991 if (s3.f2 != 2) {
6992 fprintf(stderr, "mono_return_double3 s3.f2: got %f but expected %d\n", s3.f2, 2);
6994 if (s3.f3 != 3) {
6995 fprintf(stderr, "mono_return_double3 s3.f3: got %f but expected %d\n", s3.f3, 3);
6997 s3.f1+=addend; s3.f2+=addend; s3.f3+=addend;
6998 return s3;
7001 typedef struct {
7002 double f1,f2,f3,f4;
7003 } double4;
7005 LIBTEST_API double4 STDCALL
7006 mono_return_double4 (double4 s4, int addend) {
7007 if (s4.f1 != 1) {
7008 fprintf(stderr, "mono_return_double4 s4.f1: got %f but expected %d\n", s4.f1, 1);
7010 if (s4.f2 != 2) {
7011 fprintf(stderr, "mono_return_double4 s4.f2: got %f but expected %d\n", s4.f2, 2);
7013 if (s4.f3 != 3) {
7014 fprintf(stderr, "mono_return_double4 s4.f3: got %f but expected %d\n", s4.f3, 3);
7016 if (s4.f4 != 4) {
7017 fprintf(stderr, "mono_return_double4 s4.f4: got %f but expected %d\n", s4.f4, 4);
7019 s4.f1+=addend; s4.f2+=addend; s4.f3+=addend; s4.f4+=addend;
7020 return s4;
7023 typedef struct {
7024 double f1,f2,f3,f4,f5;
7025 } double5;
7027 LIBTEST_API double5 STDCALL
7028 mono_return_double5 (double5 s5, int addend) {
7029 if (s5.f1 != 1) {
7030 fprintf(stderr, "mono_return_double5 s5.f1: got %f but expected %d\n", s5.f1, 1);
7032 if (s5.f2 != 2) {
7033 fprintf(stderr, "mono_return_double5 s5.f2: got %f but expected %d\n", s5.f2, 2);
7035 if (s5.f3 != 3) {
7036 fprintf(stderr, "mono_return_double5 s5.f3: got %f but expected %d\n", s5.f3, 3);
7038 if (s5.f4 != 4) {
7039 fprintf(stderr, "mono_return_double5 s5.f4: got %f but expected %d\n", s5.f4, 4);
7041 if (s5.f5 != 5) {
7042 fprintf(stderr, "mono_return_double5 s5.f5: got %f but expected %d\n", s5.f5, 5);
7044 s5.f1+=addend; s5.f2+=addend; s5.f3+=addend; s5.f4+=addend; s5.f5+=addend;
7045 return s5;
7048 typedef struct {
7049 double f1,f2,f3,f4,f5,f6;
7050 } double6;
7052 LIBTEST_API double6 STDCALL
7053 mono_return_double6 (double6 s6, int addend) {
7054 if (s6.f1 != 1) {
7055 fprintf(stderr, "mono_return_double6 s6.f1: got %f but expected %d\n", s6.f1, 1);
7057 if (s6.f2 != 2) {
7058 fprintf(stderr, "mono_return_double6 s6.f2: got %f but expected %d\n", s6.f2, 2);
7060 if (s6.f3 != 3) {
7061 fprintf(stderr, "mono_return_double6 s6.f3: got %f but expected %d\n", s6.f3, 3);
7063 if (s6.f4 != 4) {
7064 fprintf(stderr, "mono_return_double6 s6.f4: got %f but expected %d\n", s6.f4, 4);
7066 if (s6.f5 != 5) {
7067 fprintf(stderr, "mono_return_double6 s6.f5: got %f but expected %d\n", s6.f5, 5);
7069 if (s6.f6 != 6) {
7070 fprintf(stderr, "mono_return_double6 s6.f6: got %f but expected %d\n", s6.f6, 6);
7072 s6.f1+=addend; s6.f2+=addend; s6.f3+=addend; s6.f4+=addend; s6.f5+=addend; s6.f6+=addend;
7073 return s6;
7076 typedef struct {
7077 double f1,f2,f3,f4,f5,f6,f7;
7078 } double7;
7080 LIBTEST_API double7 STDCALL
7081 mono_return_double7 (double7 s7, int addend) {
7082 if (s7.f1 != 1) {
7083 fprintf(stderr, "mono_return_double7 s7.f1: got %f but expected %d\n", s7.f1, 1);
7085 if (s7.f2 != 2) {
7086 fprintf(stderr, "mono_return_double7 s7.f2: got %f but expected %d\n", s7.f2, 2);
7088 if (s7.f3 != 3) {
7089 fprintf(stderr, "mono_return_double7 s7.f3: got %f but expected %d\n", s7.f3, 3);
7091 if (s7.f4 != 4) {
7092 fprintf(stderr, "mono_return_double7 s7.f4: got %f but expected %d\n", s7.f4, 4);
7094 if (s7.f5 != 5) {
7095 fprintf(stderr, "mono_return_double7 s7.f5: got %f but expected %d\n", s7.f5, 5);
7097 if (s7.f6 != 6) {
7098 fprintf(stderr, "mono_return_double7 s7.f6: got %f but expected %d\n", s7.f6, 6);
7100 if (s7.f7 != 7) {
7101 fprintf(stderr, "mono_return_double7 s7.f7: got %f but expected %d\n", s7.f7, 7);
7103 s7.f1+=addend; s7.f2+=addend; s7.f3+=addend; s7.f4+=addend; s7.f5+=addend; s7.f6+=addend; s7.f7+=addend;
7104 return s7;
7107 typedef struct {
7108 double f1,f2,f3,f4,f5,f6,f7,f8;
7109 } double8;
7111 LIBTEST_API double8 STDCALL
7112 mono_return_double8 (double8 s8, int addend) {
7113 if (s8.f1 != 1) {
7114 fprintf(stderr, "mono_return_double8 s8.f1: got %f but expected %d\n", s8.f1, 1);
7116 if (s8.f2 != 2) {
7117 fprintf(stderr, "mono_return_double8 s8.f2: got %f but expected %d\n", s8.f2, 2);
7119 if (s8.f3 != 3) {
7120 fprintf(stderr, "mono_return_double8 s8.f3: got %f but expected %d\n", s8.f3, 3);
7122 if (s8.f4 != 4) {
7123 fprintf(stderr, "mono_return_double8 s8.f4: got %f but expected %d\n", s8.f4, 4);
7125 if (s8.f5 != 5) {
7126 fprintf(stderr, "mono_return_double8 s8.f5: got %f but expected %d\n", s8.f5, 5);
7128 if (s8.f6 != 6) {
7129 fprintf(stderr, "mono_return_double8 s8.f6: got %f but expected %d\n", s8.f6, 6);
7131 if (s8.f7 != 7) {
7132 fprintf(stderr, "mono_return_double8 s8.f7: got %f but expected %d\n", s8.f7, 7);
7134 if (s8.f8 != 8) {
7135 fprintf(stderr, "mono_return_double8 s8.f8: got %f but expected %d\n", s8.f8, 8);
7137 s8.f1+=addend; s8.f2+=addend; s8.f3+=addend; s8.f4+=addend; s8.f5+=addend; s8.f6+=addend; s8.f7+=addend; s8.f8+=addend;
7138 return s8;
7141 typedef struct {
7142 double f1,f2,f3,f4,f5,f6,f7,f8,f9;
7143 } double9;
7145 LIBTEST_API double9 STDCALL
7146 mono_return_double9 (double9 s9, int addend) {
7147 if (s9.f1 != 1) {
7148 fprintf(stderr, "mono_return_double9 s9.f1: got %f but expected %d\n", s9.f1, 1);
7150 if (s9.f2 != 2) {
7151 fprintf(stderr, "mono_return_double9 s9.f2: got %f but expected %d\n", s9.f2, 2);
7153 if (s9.f3 != 3) {
7154 fprintf(stderr, "mono_return_double9 s9.f3: got %f but expected %d\n", s9.f3, 3);
7156 if (s9.f4 != 4) {
7157 fprintf(stderr, "mono_return_double9 s9.f4: got %f but expected %d\n", s9.f4, 4);
7159 if (s9.f5 != 5) {
7160 fprintf(stderr, "mono_return_double9 s9.f5: got %f but expected %d\n", s9.f5, 5);
7162 if (s9.f6 != 6) {
7163 fprintf(stderr, "mono_return_double9 s9.f6: got %f but expected %d\n", s9.f6, 6);
7165 if (s9.f7 != 7) {
7166 fprintf(stderr, "mono_return_double9 s9.f7: got %f but expected %d\n", s9.f7, 7);
7168 if (s9.f8 != 8) {
7169 fprintf(stderr, "mono_return_double9 s9.f8: got %f but expected %d\n", s9.f8, 8);
7171 if (s9.f9 != 9) {
7172 fprintf(stderr, "mono_return_double9 s9.f9: got %f but expected %d\n", s9.f9, 9);
7174 s9.f1+=addend; s9.f2+=addend; s9.f3+=addend; s9.f4+=addend; s9.f5+=addend; s9.f6+=addend; s9.f7+=addend; s9.f8+=addend; s9.f9+=addend;
7175 return s9;
7178 typedef struct {
7179 struct {
7180 double f1;
7181 } nested1;
7182 struct {
7183 double f2;
7184 } nested2;
7185 } double2_nested;
7187 LIBTEST_API double2_nested STDCALL
7188 mono_return_double2_nested (double2_nested sn2, int addend) {
7189 if (sn2.nested1.f1 != 1) {
7190 fprintf(stderr, "mono_return_double2_nested sn2.nested1.f1: got %f but expected %d\n", sn2.nested1.f1, 1);
7192 if (sn2.nested2.f2 != 2) {
7193 fprintf(stderr, "mono_return_double2_nested sn2.nested2.f2: got %f but expected %d\n", sn2.nested2.f2, 2);
7195 sn2.nested1.f1+=addend; sn2.nested2.f2+=addend;
7196 return sn2;
7201 typedef struct {
7202 double f1[4];
7203 } double_array4;
7205 LIBTEST_API double_array4 STDCALL
7206 mono_return_double_array4 (double_array4 sa4, int addend) {
7207 if (sa4.f1[0] != 1) {
7208 fprintf(stderr, "mono_return_double_array4 sa4.f1[0]: got %f but expected %d\n", sa4.f1[0], 1);
7210 if (sa4.f1[1] != 2) {
7211 fprintf(stderr, "mono_return_double_array4 sa4.f1[1]: got %f but expected %d\n", sa4.f1[1], 2);
7213 if (sa4.f1[2] != 3) {
7214 fprintf(stderr, "mono_return_double_array4 sa4.f1[2]: got %f but expected %d\n", sa4.f1[2], 3);
7216 if (sa4.f1[3] != 4) {
7217 fprintf(stderr, "mono_return_double_array4 sa4.f1[3]: got %f but expected %d\n", sa4.f1[3], 4);
7219 sa4.f1[0]+=addend; sa4.f1[1]+=addend; sa4.f1[2]+=addend; sa4.f1[3]+=addend;
7220 return sa4;
7223 typedef struct {
7224 int array [3];
7225 } FixedArrayStruct;
7227 LIBTEST_API int STDCALL
7228 mono_test_marshal_fixed_array (FixedArrayStruct s)
7230 return s.array [0] + s.array [1] + s.array [2];
7233 typedef struct {
7234 char array [16];
7235 char c;
7236 } FixedBufferChar;
7238 LIBTEST_API int STDCALL
7239 mono_test_marshal_fixed_buffer_char (FixedBufferChar *s)
7241 if (!(s->array [0] == 'A' && s->array [1] == 'B' && s->array [2] == 'C' && s->c == 'D'))
7242 return 1;
7243 s->array [0] = 'E';
7244 s->array [1] = 'F';
7245 s->c = 'G';
7246 return 0;
7249 typedef struct {
7250 short array [16];
7251 short c;
7252 } FixedBufferUnicode;
7254 LIBTEST_API int STDCALL
7255 mono_test_marshal_fixed_buffer_unicode (FixedBufferUnicode *s)
7257 if (!(s->array [0] == 'A' && s->array [1] == 'B' && s->array [2] == 'C' && s->c == 'D'))
7258 return 1;
7259 s->array [0] = 'E';
7260 s->array [1] = 'F';
7261 s->c = 'G';
7262 return 0;
7265 const int NSTRINGS = 6;
7266 //test strings
7267 const char *utf8Strings[] = {
7268 "Managed",
7269 "Sîne klâwen durh die wolken sint geslagen" ,
7270 "काचं शक्नोम्यत्तुम् । नोपहिनस्ति माम्",
7271 "我能吞下玻璃而不伤身体",
7272 "ღმერთსი შემვედრე,შემვედრე, ნუთუ კვლა დამხსნას შემვედრე,სოფლისა შემვედრე, შემვედრე,შემვედრე,შემვედრე,შრომასა, ცეცხლს, წყალსა და მიწასა, ჰაერთა თანა მრომასა; მომცნეს ფრთენი და აღვფრინდე, მივჰხვდე მას ჩემსა ნდომასა, დღისით და ღამით ვჰხედვიდე მზისა ელვათა კრთომაასაშემვედრე,შემვედრე,",
7273 "Τη γλώσσα μου έδωσαν ελληνική",
7274 "\0"
7277 LIBTEST_API char *
7278 build_return_string(const char* pReturn)
7280 char *ret = 0;
7281 if (pReturn == 0 || *pReturn == 0)
7282 return ret;
7284 size_t strLength = strlen(pReturn);
7285 ret = (char *)(marshal_alloc (sizeof(char)* (strLength + 1)));
7286 memcpy(ret, pReturn, strLength);
7287 ret [strLength] = '\0';
7288 return ret;
7291 LIBTEST_API char *
7292 StringParameterInOut(/*[In,Out]*/ char *s, int index)
7294 // return a copy
7295 return build_return_string(s);
7298 LIBTEST_API void
7299 StringParameterRefOut(/*out*/ char **s, int index)
7301 char *pszTextutf8 = (char*)utf8Strings[index];
7302 size_t strLength = strlen(pszTextutf8);
7303 *s = (char *)(marshal_alloc (sizeof(char)* (strLength + 1)));
7304 memcpy(*s, pszTextutf8, strLength);
7305 (*s)[strLength] = '\0';
7308 LIBTEST_API void
7309 StringParameterRef(/*ref*/ char **s, int index)
7311 char *pszTextutf8 = (char*)utf8Strings[index];
7312 size_t strLength = strlen(pszTextutf8);
7313 // do byte by byte validation of in string
7314 size_t szLen = strlen(*s);
7315 for (size_t i = 0; i < szLen; i++)
7317 if ((*s)[i] != pszTextutf8[i])
7319 printf("[in] managed string do not match native string\n");
7320 abort ();
7324 if (*s)
7326 marshal_free (*s);
7328 // overwrite the orginal
7329 *s = (char *)(marshal_alloc (sizeof(char)* (strLength + 1)));
7330 memcpy(*s, pszTextutf8, strLength);
7331 (*s)[strLength] = '\0';
7334 LIBTEST_API void
7335 StringBuilderParameterInOut(/*[In,Out] StringBuilder*/ char *s, int index)
7337 // if string.empty
7338 if (s == 0 || *s == 0)
7339 return;
7341 char *pszTextutf8 = (char*)utf8Strings[index];
7343 // do byte by byte validation of in string
7344 size_t szLen = strlen(s);
7345 for (size_t i = 0; i < szLen; i++)
7347 if (s[i] != pszTextutf8[i])
7349 printf("[in] managed string do not match native string\n");
7350 abort ();
7354 // modify the string inplace
7355 size_t outLen = strlen(pszTextutf8);
7356 for (size_t i = 0; i < outLen; i++) {
7357 s[i] = pszTextutf8[i];
7359 s[outLen] = '\0';
7362 //out string builder
7363 LIBTEST_API void
7364 StringBuilderParameterOut(/*[Out] StringBuilder*/ char *s, int index)
7366 char *pszTextutf8 = (char*)utf8Strings[index];
7368 printf ("SBPO: Receiving %s\n", s);
7369 // modify the string inplace
7370 size_t outLen = strlen(pszTextutf8);
7371 for (size_t i = 0; i < outLen; i++) {
7372 s[i] = pszTextutf8[i];
7374 s[outLen] = '\0';
7377 LIBTEST_API char *
7378 StringParameterOut(/*[Out]*/ char *s, int index)
7380 // return a copy
7381 return build_return_string(s);
7384 // Utf8 field
7385 typedef struct FieldWithUtf8
7387 char *pFirst;
7388 int index;
7389 }FieldWithUtf8;
7391 //utf8 struct field
7392 LIBTEST_API void
7393 TestStructWithUtf8Field(struct FieldWithUtf8 fieldStruct)
7395 char *pszManagedutf8 = fieldStruct.pFirst;
7396 int stringIndex = fieldStruct.index;
7397 char *pszNative = 0;
7398 size_t outLen = 0;
7400 if (pszManagedutf8 == 0 || *pszManagedutf8 == 0)
7401 return;
7403 pszNative = (char*)utf8Strings[stringIndex];
7405 outLen = strlen(pszNative);
7406 // do byte by byte comparision
7407 for (size_t i = 0; i < outLen; i++)
7409 if (pszNative[i] != pszManagedutf8[i])
7411 printf("Native and managed string do not match.\n");
7412 abort ();
7417 typedef void (* Callback2)(char *text, int index);
7419 LIBTEST_API void
7420 Utf8DelegateAsParameter(Callback2 managedCallback)
7422 for (int i = 0; i < NSTRINGS; ++i)
7424 char *pszNative = 0;
7425 pszNative = (char*)utf8Strings[i];
7426 managedCallback(pszNative, i);
7431 LIBTEST_API char*
7432 StringBuilderParameterReturn(int index)
7434 char *pszTextutf8 = (char*)utf8Strings[index];
7435 size_t strLength = strlen(pszTextutf8);
7436 char * ret = (char *)(marshal_alloc (sizeof(char)* (strLength + 1)));
7437 memcpy(ret, pszTextutf8, strLength);
7438 ret[strLength] = '\0';
7440 return ret;
7443 LIBTEST_API int STDCALL
7444 mono_test_marshal_pointer_array (int *arr[])
7446 int i;
7448 for (i = 0; i < 10; ++i) {
7449 if (*arr [i] != -1)
7450 return 1;
7452 return 0;