[System] Tweak socket test
[mono-project.git] / mono / tests / marshal5.cs
blobf35d8f9e25cec0d0f65dc6fcc71d1886de234c07
1 using System;
2 using System.Runtime.InteropServices;
4 public class Test
6 [DllImport ("libtest", EntryPoint="mono_test_byvalstr_gen")]
7 public static extern IntPtr mono_test_byvalstr_gen();
9 [DllImport ("libtest", EntryPoint="mono_test_byvalstr_check")]
10 public static extern int mono_test_byvalstr_check(IntPtr data, string correctString);
12 [DllImport ("libtest", EntryPoint="mono_test_byvalstr_check_unicode")]
13 public static extern int mono_test_byvalstr_check_unicode(ref ByValStrStruct_Unicode var, int test);
15 [StructLayout (LayoutKind.Sequential)]
16 public struct ByValStrStruct
18 [MarshalAs(UnmanagedType.ByValTStr, SizeConst=100)]
19 public string a;
22 [StructLayout (LayoutKind.Sequential, CharSet=CharSet.Unicode)]
23 public struct ByValStrStruct_Unicode
25 [MarshalAs(UnmanagedType.ByValTStr, SizeConst=4)]
26 public string a;
28 public int flag;
31 public unsafe static int Main ()
33 string testString = "A small string";
35 IntPtr udata = mono_test_byvalstr_gen();
37 ByValStrStruct data = new ByValStrStruct();
38 data.a = testString;
40 Marshal.StructureToPtr(data, udata, false);
42 int c = mono_test_byvalstr_check(udata, testString);
43 if (c != 0)
44 return 1;
46 ByValStrStruct_Unicode a = new ByValStrStruct_Unicode ();
47 a.flag = 0x1234abcd;
48 a.a = "1234";
49 c = mono_test_byvalstr_check_unicode (ref a, 1);
50 if (c != 0)
51 return 2;
53 a.a = "12";
54 c = mono_test_byvalstr_check_unicode (ref a, 2);
55 if (c != 0)
56 return 3;
58 a.a = "1234567890";
59 c = mono_test_byvalstr_check_unicode (ref a, 3);
60 if (c != 0)
61 return 4;
63 return 0;