2006-12-05 Chris Toshok <toshok@ximian.com>
[mcs.git] / tests / test-366.cs
blob357c4c5ac8ffb2a4088dbb605f401da815023c73
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;
9 [StructLayout(LayoutKind.Explicit)]
10 struct foo2 {
13 class C
15 static int Main ()
17 foo2 f = new foo2 ();
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
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;
29 Type t = typeof (foo2);
30 FieldInfo fi = t.GetField ("$PRIVATE$", BindingFlags.Instance | BindingFlags.NonPublic);
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;
40 Console.WriteLine ("PASS: Test passes on Mono");
41 return 0;