2008-12-05 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / tests / libtest.c
index b0da6df852047cb65e0022e68303fe7a3209e7db..3fd22de9edde942c1d9d51839c98f71c2d12295d 100644 (file)
@@ -109,6 +109,11 @@ mono_return_int (int a) {
        return a;
 }
 
+LIBTEST_API float STDCALL  
+mono_test_marshal_pass_return_float (float f) {
+       return f + 1.0;
+}
+
 struct ss
 {
        int i;
@@ -675,6 +680,19 @@ mono_test_marshal_delegate (SimpleDelegate delegate)
        return delegate (2);
 }
 
+static int STDCALL inc_cb (int i)
+{
+       return i + 1;
+}
+
+LIBTEST_API int STDCALL 
+mono_test_marshal_out_delegate (SimpleDelegate *delegate)
+{
+       *delegate = inc_cb;
+
+       return 0;
+}
+
 LIBTEST_API SimpleDelegate STDCALL 
 mono_test_marshal_return_delegate (SimpleDelegate delegate)
 {
@@ -1512,6 +1530,17 @@ mono_test_marshal_amd64_pass_return_struct1 (amd64_struct1 s)
        return s;
 }
 
+LIBTEST_API amd64_struct1 STDCALL 
+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)
+{
+       s.i ++;
+       s.j ++;
+       s.k ++;
+       s.l += 1 + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8;
+
+       return s;
+}
+
 typedef struct amd64_struct2 {
        int i;
        int j;
@@ -1559,10 +1588,10 @@ typedef struct test_struct5 {
 } test_struct5;
 
 LIBTEST_API test_struct5 STDCALL 
-mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, test_struct5 s, double d3, double d4)
+mono_test_marshal_ia64_pass_return_struct5 (double d1, double d2, test_struct5 s, int i, double d3, double d4)
 {
-       s.d1 += d1 + d2;
-       s.d2 += d3 + d4;
+       s.d1 += d1 + d2 + i;
+       s.d2 += d3 + d4 + i;
 
        return s;
 }
@@ -1572,9 +1601,9 @@ typedef struct test_struct6 {
 } test_struct6;
 
 LIBTEST_API test_struct6 STDCALL 
-mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, test_struct6 s, double d3, double d4)
+mono_test_marshal_ia64_pass_return_struct6 (double d1, double d2, test_struct6 s, int i, double d3, double d4)
 {
-       s.d1 += d1 + d2;
+       s.d1 += d1 + d2 + i;
        s.d2 += d3 + d4;
 
        return s;
@@ -2022,7 +2051,7 @@ mono_test_marshal_cdecl_delegate (CdeclDelegate del)
        return 0;
 }
 
-typedef char** (*ReturnStringArrayDelegate) (int i);
+typedef char** (STDCALL *ReturnStringArrayDelegate) (int i);
 
 LIBTEST_API int STDCALL 
 mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d)
@@ -2043,6 +2072,28 @@ mono_test_marshal_return_string_array_delegate (ReturnStringArrayDelegate d)
        return res;
 }
 
+typedef int (STDCALL *ByrefStringDelegate) (char **s);
+
+LIBTEST_API int STDCALL 
+mono_test_marshal_byref_string_delegate (ByrefStringDelegate d)
+{
+       char *s = (char*)"ABC";
+       int res;
+
+       res = d (&s);
+       if (res != 0)
+               return res;
+
+       if (!strcmp (s, "DEF"))
+               res = 0;
+       else
+               res = 2;
+
+       marshal_free (s);
+
+       return res;
+}
+
 LIBTEST_API int STDCALL 
 add_delegate (int i, int j)
 {
@@ -2071,6 +2122,8 @@ mono_xr_as_handle (int code)
 {
        HandleRef ref;
 
+       memset (&ref, 0, sizeof (ref));
+
        return ref;
 }
  
@@ -2925,7 +2978,7 @@ mono_test_marshal_ccw_itest (MonoComObject *pUnk)
  * mono_method_get_unmanaged_thunk tests
  */
 
-#if defined(__GNUC__) && defined(__i386__) && (defined(__linux__) || defined (__APPLE__))
+#if defined(__GNUC__) && ((defined(__i386__) && (defined(__linux__) || defined (__APPLE__))) || (defined(__ppc__) && defined(__APPLE__)))
 #define ALIGN(size) __attribute__ ((aligned(size)))
 #else
 #define ALIGN(size)
@@ -2940,7 +2993,7 @@ typedef struct _TestStruct {
 
 /* Searches for mono symbols in all loaded modules */
 static gpointer
-lookup_mono_symbol (char *symbol_name)
+lookup_mono_symbol (const char *symbol_name)
 {
        gpointer symbol;
        if (g_module_symbol (g_module_open (NULL, G_MODULE_BIND_LAZY), symbol_name, &symbol))
@@ -2962,7 +3015,7 @@ test_method_thunk (int test_id, gpointer test_method_handle, gpointer create_obj
        gpointer (*mono_method_get_unmanaged_thunk)(gpointer)
                = lookup_mono_symbol ("mono_method_get_unmanaged_thunk");
 
-       gpointer (*mono_string_new_wrapper)(char *)
+       gpointer (*mono_string_new_wrapper)(const char *)
                = lookup_mono_symbol ("mono_string_new_wrapper");
 
        char* (*mono_string_to_utf8)(gpointer)
@@ -3401,7 +3454,7 @@ mono_test_Winx64_struct5_in (winx64_struct5 var)
 typedef struct
 {
        winx64_struct1 a;
-       short b;\r
+       short b;
        char c;
 } winx64_struct6;
 
@@ -3512,7 +3565,7 @@ mono_test_Winx64_structs_in3 (winx64_struct1 var1,
 }
 
 LIBTEST_API winx64_struct1 STDCALL  
-mono_test_Winx64_struct1_ret ()
+mono_test_Winx64_struct1_ret (void)
 {
        winx64_struct1 ret;
        ret.a = 123;
@@ -3520,7 +3573,7 @@ mono_test_Winx64_struct1_ret ()
 }
 
 LIBTEST_API winx64_struct2 STDCALL  
-mono_test_Winx64_struct2_ret ()
+mono_test_Winx64_struct2_ret (void)
 {
        winx64_struct2 ret;
        ret.a = 4;
@@ -3529,7 +3582,7 @@ mono_test_Winx64_struct2_ret ()
 }
 
 LIBTEST_API winx64_struct3 STDCALL  
-mono_test_Winx64_struct3_ret ()
+mono_test_Winx64_struct3_ret (void)
 {
        winx64_struct3 ret;
        ret.a = 4;
@@ -3539,7 +3592,7 @@ mono_test_Winx64_struct3_ret ()
 }
 
 LIBTEST_API winx64_struct4 STDCALL  
-mono_test_Winx64_struct4_ret ()
+mono_test_Winx64_struct4_ret (void)
 {
        winx64_struct4 ret;
        ret.a = 4;
@@ -3550,7 +3603,7 @@ mono_test_Winx64_struct4_ret ()
 }
 
 LIBTEST_API winx64_struct5 STDCALL  
-mono_test_Winx64_struct5_ret ()
+mono_test_Winx64_struct5_ret (void)
 {
        winx64_struct5 ret;
        ret.a = 4;
@@ -3559,6 +3612,24 @@ mono_test_Winx64_struct5_ret ()
        return ret;
 }
 
+LIBTEST_API winx64_struct1 STDCALL  
+mono_test_Winx64_struct1_ret_5_args (char a, char b, char c, char d, char e)
+{
+       winx64_struct1 ret;
+       ret.a = a + b + c + d + e;
+       return ret;
+}
+
+LIBTEST_API winx64_struct5 STDCALL
+mono_test_Winx64_struct5_ret6_args (char a, char b, char c, char d, char e)
+{
+       winx64_struct5 ret;
+       ret.a = a + b;
+       ret.b = c + d;
+       ret.c = e;
+       return ret;
+}
+
 typedef struct
 {
        float a;
@@ -3601,3 +3672,70 @@ mono_test_managed_Winx64_struct1_in(managed_struct1_delegate func)
        return func (val);
 }
 
+typedef int (STDCALL *managed_struct5_delegate) (winx64_struct5 a);
+
+LIBTEST_API int STDCALL 
+mono_test_managed_Winx64_struct5_in(managed_struct5_delegate func)
+{
+       winx64_struct5 val;
+       val.a = 5;
+       val.b = 0x10;
+       val.c = 0x99;
+       return func (val);
+}
+
+typedef int (STDCALL *managed_struct1_struct5_delegate) (winx64_struct1 a, winx64_struct5 b,
+                                                        winx64_struct1 c, winx64_struct5 d,
+                                                        winx64_struct1 e, winx64_struct5 f);
+
+LIBTEST_API int STDCALL 
+mono_test_managed_Winx64_struct1_struct5_in(managed_struct1_struct5_delegate func)
+{
+       winx64_struct1 a, c, e;
+       winx64_struct5 b, d, f;
+       a.a = 1;
+       b.a = 2; b.b = 3; b.c = 4;
+       c.a = 5;
+       d.a = 6; d.b = 7; d.c = 8;
+       e.a = 9;
+       f.a = 10; f.b = 11; f.c = 12;
+
+       return func (a, b, c, d, e, f);
+}
+
+typedef winx64_struct1 (STDCALL *managed_struct1_ret_delegate) (void);
+
+LIBTEST_API int STDCALL 
+mono_test_Winx64_struct1_ret_managed (managed_struct1_ret_delegate func)
+{
+       winx64_struct1 ret;
+
+       ret = func ();
+
+       if (ret.a != 0x45)
+               return 1;
+       
+       return 0;
+}
+
+typedef winx64_struct5 (STDCALL *managed_struct5_ret_delegate) (void);
+
+LIBTEST_API int STDCALL 
+mono_test_Winx64_struct5_ret_managed (managed_struct5_ret_delegate func)
+{
+       winx64_struct5 ret;
+
+       ret = func ();
+
+       if (ret.a != 0x12)
+               return 1;
+       if (ret.b != 0x34)
+               return 2;
+       if (ret.c != 0x56)
+               return 3;
+       
+       return 0;
+}
+
+
+