+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
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;
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)
{
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;
+}
+
+
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")]
[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);
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;
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;
}
}
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);
[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);
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;
}