[System] Tweak socket test
[mono-project.git] / mono / tests / pinvoke11.cs
blob252700fe3442a38b7af62472c35d1df83de2491c
1 using System;
2 using System.Runtime.InteropServices;
4 [StructLayout(LayoutKind.Sequential)]
5 public struct ss
7 public int i1;
10 [StructLayout(LayoutKind.Explicit)]
11 public struct su
13 [FieldOffset(0)] public int i1;
14 [FieldOffset(0)] public int i2;
17 [StructLayout(LayoutKind.Sequential)]
18 public struct cs
20 public bool b1;
21 public int i1;
22 public su u1;
25 /* various small structs for testing struct-by-value where they are handled specially
26 on some platforms.
28 [StructLayout(LayoutKind.Sequential)]
29 public struct sc1
31 public byte c0;
34 [StructLayout(LayoutKind.Sequential)]
35 public struct sc3
37 public byte c0;
38 public byte c1;
39 public byte c2;
42 [StructLayout(LayoutKind.Sequential)]
43 public struct sc5
45 public byte c0;
46 public byte c1;
47 public byte c2;
48 public byte c3;
49 public byte c4;
52 public struct FI {
53 public float f1;
54 public float f2;
55 public float f3;
58 public struct NestedFloat {
59 public FI fi;
60 public float f4;
63 public class Test
65 [DllImport ("libtest")]
66 public static extern int mono_union_test_1 (cs a);
68 [DllImport ("libtest")]
69 public static extern int mono_return_int (int a);
71 [DllImport ("libtest", EntryPoint="mono_return_int_ss")]
72 public static extern int mono_return_int_ss (ss a);
74 [DllImport ("libtest", EntryPoint="mono_return_ss")]
75 public static extern ss mono_return_ss (ss a);
77 [DllImport ("libtest", EntryPoint="mono_return_sc1")]
78 public static extern sc1 mono_return_sc1 (sc1 a);
80 [DllImport ("libtest", EntryPoint="mono_return_sc3")]
81 public static extern sc3 mono_return_sc3 (sc3 a);
83 [DllImport ("libtest", EntryPoint="mono_return_sc5")]
84 public static extern sc5 mono_return_sc5 (sc5 a);
86 [DllImport ("libtest", EntryPoint="mono_return_int_su")]
87 public static extern int mono_return_int_su (su a);
89 [DllImport ("libtest", EntryPoint="mono_return_nested_float")]
90 public static extern NestedFloat mono_return_nested_float ();
92 static int Main()
94 if (mono_return_int (5) != 5)
95 return 1;
97 ss s1;
98 s1.i1 = 4;
99 if (mono_return_int_ss (s1) != 4)
100 return 2;
102 s1 = mono_return_ss (s1);
103 if (s1.i1 != 5)
104 return 3;
106 su s2;
107 s2.i1 = 2;
108 s2.i2 = 3;
109 if (mono_return_int_su (s2) != 3)
110 return 4;
112 s2.i1 = 2;
113 if (mono_return_int_su (s2) != 2)
114 return 5;
117 cs s3;
118 s3.b1 = false;
119 s3.i1 = 12;
120 s3.u1.i1 = 2;
121 s3.u1.i2 = 1;
123 if (mono_union_test_1 (s3) != 13)
124 return 6;
126 s3.u1.i1 = 2;
127 if (mono_union_test_1 (s3) != 14)
128 return 7;
130 s3.b1 = true;
131 if (mono_union_test_1 (s3) != 15)
132 return 8;
134 sc1 s4;
135 s4.c0 = 3;
136 s4 = mono_return_sc1(s4);
137 if (s4.c0 != 4)
138 return 9;
140 sc3 s5;
141 s5.c0 = 4;
142 s5.c1 = 5;
143 s5.c2 = 6;
144 s5 = mono_return_sc3(s5);
145 if (s5.c0 != 5 || s5.c1 != 7 || s5.c2 != 9)
146 return 10;
148 sc5 s6;
149 s6.c0 = 4;
150 s6.c1 = 5;
151 s6.c2 = 6;
152 s6.c3 = 7;
153 s6.c4 = 8;
154 s6 = mono_return_sc5(s6);
155 if (s6.c0 != 5 || s6.c1 != 7 || s6.c2 != 9 || s6.c3 != 11 || s6.c4 != 13)
156 return 11;
158 var f = mono_return_nested_float ();
159 if (f.fi.f1 != 1.0)
160 return 12;
162 return 0;