New test.
[mono.git] / mcs / tests / test-366.cs
1 //
2 // Check that the empty field we produce on empty structs with LayoutKind.Explicit
3 // has a FieldOffset of zero, or the .NET runtime complains
4 //
5 using System;
6 using System.Reflection;
7 using System.Runtime.InteropServices;
8
9 [StructLayout(LayoutKind.Explicit)]
10 struct foo2 {
11 }
12
13 class C
14 {
15         static int Main ()
16         {
17                 foo2 f = new foo2 ();
18
19                 // On .NET if we got this far, we run
20                 // On Mono, we are going to actually use an internal routine to check if the offset is there
21                 //
22                 Type fit = typeof (FieldInfo);
23                 MethodInfo gfo = fit.GetMethod ("GetFieldOffset", BindingFlags.Instance | BindingFlags.NonPublic);
24                 if (gfo == null){
25                         Console.WriteLine ("PASS: On MS runtime, Test OK");
26                         return 0;
27                 }
28                 
29                 Type t = typeof (foo2);
30                 FieldInfo fi = t.GetField ("$PRIVATE$", BindingFlags.Instance | BindingFlags.NonPublic);
31
32                 object res = gfo.Invoke (fi, null);
33                 if (res.GetType () != typeof (Int32))
34                         return 1;
35                 int r = (int) res;
36                 if (r != 0){
37                         Console.WriteLine ("FAIL: Offset is not zero");
38                         return 1;
39                 }
40                 Console.WriteLine ("PASS: Test passes on Mono");
41                 return 0;
42     }
43 }
44
45