2003-10-06 Bernie Solomon <bernard@ugsolutions.com>
authorBernie Solomon <bernard@mono-cvs.ximian.com>
Mon, 6 Oct 2003 16:21:42 +0000 (16:21 -0000)
committerBernie Solomon <bernard@mono-cvs.ximian.com>
Mon, 6 Oct 2003 16:21:42 +0000 (16:21 -0000)
* mono/tests/pinvoke2.cs mono/tests/pinvoke11.cs
mono/tests/libtest.c: Add more pass by value struct
tests for platforms with more complex calling conventions
(Sparc V9, HPPA 64 bit).

svn path=/trunk/mono/; revision=18679

ChangeLog
mono/tests/libtest.c
mono/tests/pinvoke11.cs
mono/tests/pinvoke2.cs

index c54b5e5d99b210abb28dc769af6c3cabfed39a89..d73d5d347aacd06b2f471583bfaf4ad4df2595cc 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2003-10-06  Bernie Solomon  <bernard@ugsolutions.com>
+
+       * mono/tests/pinvoke2.cs mono/tests/pinvoke11.cs 
+       mono/tests/libtest.c: Add more pass by value struct
+       tests for platforms with more complex calling conventions 
+       (Sparc V9, HPPA 64 bit).
+
 2003-10-06  Zoltan Varga  <vargaz@freemail.hu>
 
        * mono/tests/pinvoke2.cs mono/tests/libtest.c: Add array of structs
index f0a6e93187610c9971c9f752c7baa3c90d759bf2..287e282796ed73bf02b3f937171003573273c2d9 100644 (file)
@@ -50,6 +50,52 @@ int mono_return_int_ss (struct ss a) {
        return a.i;
 }
 
+struct ss mono_return_ss (struct ss a) {
+       printf ("Got value %d\n", a.i);
+       a.i++;
+       return a;
+}
+
+struct sc1
+{
+       char c[1];
+};
+
+struct sc1 mono_return_sc1 (struct sc1 a) {
+       printf ("Got value %d\n", a.c[0]);
+       a.c[0]++;
+       return a;
+}
+
+
+struct sc3
+{
+       char c[3];
+};
+
+struct sc3 mono_return_sc3 (struct sc3 a) {
+       printf ("Got values %d %d %d\n", a.c[0], a.c[1], a.c[2]);
+       a.c[0]++;
+       a.c[1] += 2;
+       a.c[2] += 3;
+       return a;
+}
+
+struct sc5
+{
+       char c[5];
+};
+
+struct sc5 mono_return_sc5 (struct sc5 a) {
+       printf ("Got values %d %d %d\n", a.c[0], a.c[1], a.c[2], a.c[3], a.c[4]);
+       a.c[0]++;
+       a.c[1] += 2;
+       a.c[2] += 3;
+       a.c[3] += 4;
+       a.c[4] += 5;
+       return a;
+}
+
 union su
 {
        int i1;
@@ -267,6 +313,19 @@ mono_test_marshal_struct2 (simplestruct2 ss)
        return 1;
 }
 
+int
+mono_test_marshal_struct2_2 (int i, int j, int k, simplestruct2 ss)
+{
+       if (i != 10 || j != 11 || k != 12)
+               return 1;
+       if (ss.a == 0 && ss.b == 1 && ss.c == 0 &&
+           !strcmp (ss.d, "TEST") && 
+           ss.e == 99 && ss.f == 1.5 && ss.g == 42 && ss.h == (guint64)123)
+               return 0;
+
+       return 1;
+}
+
 int
 mono_test_marshal_struct_array (simplestruct2 *ss)
 {
@@ -572,3 +631,35 @@ GetVersionEx (OSVERSIONINFO *osvi)
 
        return osvi->a + osvi->b;
 }
+
+typedef struct {
+       double x;
+       double y;
+} point;
+
+int
+mono_test_marshal_point (point pt)
+{
+       printf("point %g %g\n", pt.x, pt.y);
+       if (pt.x == 1.25 && pt.y == 3.5)
+               return 0;
+
+       return 1;
+}
+
+typedef struct {
+       int x;
+       double y;
+} mixed_point;
+
+int
+mono_test_marshal_mixed_point (mixed_point pt)
+{
+       printf("mixed point %d %g\n", pt.x, pt.y);
+       if (pt.x == 5 && pt.y == 6.75)
+               return 0;
+
+       return 1;
+}
+
+
index 7031f30d4a0579a94c751623ed62422cf66df822..bff30b58bd7d9a048e0b2f7ce52b1db05eee26e0 100644 (file)
@@ -22,6 +22,33 @@ public struct cs
        public su u1;
 }
 
+/* various small structs for testing struct-by-value where they are handled specially 
+   on some platforms.
+*/
+[StructLayout(LayoutKind.Sequential)]
+public struct sc1
+{
+       public byte c0;
+}
+
+[StructLayout(LayoutKind.Sequential)]
+public struct sc3
+{
+       public byte c0;
+       public byte c1;
+       public byte c2;
+}
+
+[StructLayout(LayoutKind.Sequential)]
+public struct sc5
+{
+       public byte c0;
+       public byte c1;
+       public byte c2;
+       public byte c3;
+       public byte c4;
+}
+
 public class Test
 {
        [DllImport ("libtest")]
@@ -33,6 +60,18 @@ public class Test
        [DllImport ("libtest", EntryPoint="mono_return_int_ss")]
        public static extern int mono_return_int_ss (ss a);
 
+       [DllImport ("libtest", EntryPoint="mono_return_ss")]
+       public static extern ss mono_return_ss (ss a);
+
+       [DllImport ("libtest", EntryPoint="mono_return_sc1")]
+       public static extern sc1 mono_return_sc1 (sc1 a);
+
+       [DllImport ("libtest", EntryPoint="mono_return_sc3")]
+       public static extern sc3 mono_return_sc3 (sc3 a);
+
+       [DllImport ("libtest", EntryPoint="mono_return_sc5")]
+       public static extern sc5 mono_return_sc5 (sc5 a);
+
        [DllImport ("libtest", EntryPoint="mono_return_int_su")]
        public static extern int mono_return_int_su (su a);
 
@@ -45,16 +84,20 @@ public class Test
                s1.i1 = 4;
                if (mono_return_int_ss (s1) != 4)
                        return 2;
+
+               s1 = mono_return_ss (s1);
+               if (s1.i1 != 5)
+                       return 3;
                
                su s2;
                s2.i1 = 2;
                s2.i2 = 3;
                if (mono_return_int_su (s2) != 3)
-                       return 3;
+                       return 4;
                
                s2.i1 = 2;
                if (mono_return_int_su (s2) != 2)
-                       return 4;
+                       return 5;
 
 
                cs s3;
@@ -64,16 +107,40 @@ public class Test
                s3.u1.i2 = 1;
                
                if (mono_union_test_1 (s3) != 13)
-                       return 5;
+                       return 6;
 
                s3.u1.i1 = 2;
                if (mono_union_test_1 (s3) != 14)
-                       return 6;
+                       return 7;
 
                s3.b1 = true;
                if (mono_union_test_1 (s3) != 15)
-                       return 7;
-               
+                       return 8;
+
+               sc1 s4;
+               s4.c0 = 3;
+               s4 = mono_return_sc1(s4);
+               if (s4.c0 != 4)
+                       return 9;
+
+               sc3 s5;
+               s5.c0 = 4;
+               s5.c1 = 5;
+               s5.c2 = 6;
+               s5 = mono_return_sc3(s5);
+               if (s5.c0 != 5 || s5.c1 != 7 || s5.c2 != 9)
+                       return 10;
+
+               sc5 s6;
+               s6.c0 = 4;
+               s6.c1 = 5;
+               s6.c2 = 6;
+               s6.c3 = 7;
+               s6.c4 = 8;
+               s6 = mono_return_sc5(s6);
+               if (s6.c0 != 5 || s6.c1 != 7 || s6.c2 != 9 || s6.c3 != 11 || s6.c4 != 13)
+                       return 11;
+
                return 0;
         }
 }
index ffd2c0c579f397188b0170394fc69844b9cd4951..b52cb99409978b485bec1066bd1ec152e2d016e6 100755 (executable)
@@ -33,6 +33,19 @@ public class Test {
                public long h;
        }
 
+       /* sparcv9 has complex conventions when passing structs with doubles in them 
+          by value, some simple tests for them */
+       [StructLayout (LayoutKind.Sequential)]
+       public struct Point {
+               public double x;
+               public double y;
+       }
+
+       [StructLayout (LayoutKind.Sequential)]
+       public struct MixedPoint {
+               public int x;
+               public double y;
+       }
 
        [DllImport ("libtest", EntryPoint="mono_test_marshal_char")]
        public static extern int mono_test_marshal_char (char a1);
@@ -46,6 +59,15 @@ public class Test {
        [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2")]
        public static extern int mono_test_marshal_struct2 (SimpleStruct2 ss);
 
+       [DllImport ("libtest", EntryPoint="mono_test_marshal_struct2_2")]
+       public static extern int mono_test_marshal_struct2_2 (int i, int j, int k, SimpleStruct2 ss);
+
+       [DllImport ("libtest", EntryPoint="mono_test_marshal_point")]
+       public static extern int mono_test_marshal_point (Point p);
+
+       [DllImport ("libtest", EntryPoint="mono_test_marshal_mixed_point")]
+       public static extern int mono_test_marshal_mixed_point (MixedPoint p);
+
        [DllImport ("libtest", EntryPoint="mono_test_marshal_struct_array")]
        public static extern int mono_test_marshal_struct_array (SimpleStruct2[] ss);
 
@@ -89,10 +111,25 @@ public class Test {
                if (mono_test_marshal_struct_array (ss_arr) != 0)
                        return 5;
                
+               if (mono_test_marshal_struct2_2 (10, 11, 12, ss2) != 0)
+                       return 6;
+               
                SimpleDelegate d = new SimpleDelegate (delegate_test);
 
                if (mono_test_marshal_delegate (d) != 0)
-                       return 6;
+                       return 7;
+
+               Point pt = new Point();
+               pt.x = 1.25;
+               pt.y = 3.5;
+               if (mono_test_marshal_point(pt) != 0)
+                       return 8;
+
+               MixedPoint mpt = new MixedPoint();
+               mpt.x = 5;
+               mpt.y = 6.75;
+               if (mono_test_marshal_mixed_point(mpt) != 0)
+                       return 9;
 
                return 0;
        }