Merge pull request #5382 from kumpera/pedump_fix
[mono.git] / mono / tests / marshal7.cs
index 9e91e65443d756639427f96e733ef630f5da1d58..640f4a04d7822e98699f3a79b4b144833f1bed78 100644 (file)
@@ -1,4 +1,5 @@
 using System;
+using System.Reflection;
 using System.Runtime.InteropServices;
 
 public class Test 
@@ -51,6 +52,80 @@ public class Test
                object itf;
        }
 
+       // Size should be 16 in both 32 and 64 bits win/linux
+       // Size should be 12 on 32bits OSX size alignment of long is 4
+       [StructLayout (LayoutKind.Explicit)]
+       struct TestStruct8 {
+               [FieldOffset (0)]
+               public int a;
+               [FieldOffset (4)]
+               public ulong b;
+       }
+
+       // Size should be 12 in both 32 and 64 bits
+       [StructLayout (LayoutKind.Explicit, Size=12)]
+       struct TestStruct9 {
+               [FieldOffset (0)]
+               public int a;
+               [FieldOffset (4)]
+               public ulong b;
+       }
+
+       // Size should be 16 in both 32 and 64 bits
+       // Size should be 12 on 32bits OSX size alignment of long is 4
+       [StructLayout (LayoutKind.Explicit)]
+       struct TestStruct10 {
+               [FieldOffset (0)]
+               public int a;
+               [FieldOffset (3)]
+               public ulong b;
+       }
+
+       // Size should be 11 in both 32 and 64 bits
+       [StructLayout (LayoutKind.Explicit, Size=11)]
+       struct TestStruct11 {
+               [FieldOffset (0)]
+               public int a;
+               [FieldOffset (3)]
+               public ulong b;
+       }
+
+       [StructLayout (LayoutKind.Explicit, Pack=1)]
+       struct TestStruct12 {
+               [FieldOffset (0)]
+               public short a;
+               [FieldOffset (2)]
+               public int b;
+       }
+
+       // Size should always be 12, since pack = 0, size = 0 and min alignment = 4
+       //When pack is not set, we default to 8, so min (8, min alignment) -> 4
+       [StructLayout (LayoutKind.Explicit)]
+       struct TestStruct13 {
+               [FieldOffset(0)]
+               int one;
+               [FieldOffset(4)]
+               int two;
+               [FieldOffset(8)]
+               int three;
+       }
+
+       // Size should always be 12, since pack = 8, size = 0 and min alignment = 4
+       //It's aligned to min (pack, min alignment) -> 4
+       [StructLayout (LayoutKind.Explicit)]
+       struct TestStruct14 {
+               [FieldOffset(0)]
+               int one;
+               [FieldOffset(4)]
+               int two;
+               [FieldOffset(8)]
+               int three;
+       }
+       static bool IsOSX ()
+       {
+               return (int)typeof (Environment).GetMethod ("get_Platform", BindingFlags.Static | BindingFlags.NonPublic).Invoke (null, null) == 6;
+       }
+
        public unsafe static int Main () 
        {
                ///
@@ -137,7 +212,27 @@ public class Test
                // a VARIANT is 
                if (Marshal.SizeOf (typeof (TestStruct7)) != 16)
                        return 13;
-
+               if (IsOSX () && IntPtr.Size == 4) {
+                       if (Marshal.SizeOf (typeof (TestStruct8)) != 12)
+                               return 14;
+                       if (Marshal.SizeOf (typeof (TestStruct10)) != 12)
+                               return 16;
+               } else {
+                       if (Marshal.SizeOf (typeof (TestStruct8)) != 16 && Marshal.SizeOf (typeof (TestStruct8)) != 12)
+                               return 14;
+                       if (Marshal.SizeOf (typeof (TestStruct10)) != 16 && Marshal.SizeOf (typeof (TestStruct10)) != 12)
+                               return 16;
+               }
+               if (Marshal.SizeOf (typeof (TestStruct9)) != 12)
+                       return 15;
+               if (Marshal.SizeOf (typeof (TestStruct11)) != 11)
+                       return 17;
+               if (Marshal.SizeOf (typeof (TestStruct12)) != 6)
+                       return 18;
+               if (Marshal.SizeOf (typeof (TestStruct13)) != 12)
+                       return 19;
+               if (Marshal.SizeOf (typeof (TestStruct14)) != 12)
+                       return 20;
                return 0;
        }
 }