Merge pull request #4840 from kumpera/unaligned-access
[mono.git] / mono / tests / marshalbool.cs
index e0402180db3ef3f231d27f5f25b3d952c5182a86..67cf19636328e473993d78d75f13ea12f257f72a 100644 (file)
@@ -3,6 +3,11 @@ using System.Runtime.InteropServices;
 
 public class marshalbool
 {
+       [AttributeUsage (AttributeTargets.Method)]
+       sealed class MonoPInvokeCallbackAttribute : Attribute {
+               public MonoPInvokeCallbackAttribute (Type t) {}
+       }
+
        [DllImport ("libtest")]
        static extern int mono_test_marshal_bool_in (int arg, uint expected,
                                                     bool bDefaultMarsh,
@@ -154,11 +159,12 @@ public class marshalbool
        unsafe public static int test_0_VariantBool_In_Native ()
        {
                int ret;
+               int m1 = -1;
 
                ret = mono_test_marshal_bool_in (5, 0, false, false, false, false, false);
                if (ret != 0)
                        return 0x0100 + ret;
-               ret = mono_test_marshal_bool_in (5, 0xFFFF, false, false, false, false, true);
+               ret = mono_test_marshal_bool_in (5, (uint)m1, false, false, false, false, true);
                if (ret != 0)
                        return 0x0200 + ret;
 
@@ -166,7 +172,7 @@ public class marshalbool
                bool* ptestVal = &testVal;
 
                Marshal.WriteByte ((IntPtr)ptestVal, 0x22);
-               ret = mono_test_marshal_bool_in (5, 0xFFFF, false, false, false, false, testVal);
+               ret = mono_test_marshal_bool_in (5, (uint)m1, false, false, false, false, testVal);
                if (ret != 0)
                        return 0x0300 + ret;
 
@@ -595,7 +601,7 @@ public class marshalbool
 
        public static int test_0_Default_In_Managed ()
        {
-               MarshalBoolInDelegate fcn = new MarshalBoolInDelegate (new marshalbool ().MarshalBoolInHelper);
+               MarshalBoolInDelegate fcn = new MarshalBoolInDelegate (MarshalBoolInHelper);
                int ret;
 
                ret = mono_test_managed_marshal_bool_in (1, 0, 0, fcn);
@@ -612,7 +618,7 @@ public class marshalbool
 
        public static int test_0_Bool_In_Managed ()
        {
-               MarshalBoolInDelegate fcn = new MarshalBoolInDelegate (new marshalbool ().MarshalBoolInHelper);
+               MarshalBoolInDelegate fcn = new MarshalBoolInDelegate (MarshalBoolInHelper);
                int ret;
 
                ret = mono_test_managed_marshal_bool_in (2, 0, 0, fcn);
@@ -629,7 +635,7 @@ public class marshalbool
 
        public static int test_0_I1_In_Managed ()
        {
-               MarshalBoolInDelegate fcn = new MarshalBoolInDelegate (new marshalbool ().MarshalBoolInHelper);
+               MarshalBoolInDelegate fcn = new MarshalBoolInDelegate (MarshalBoolInHelper);
                int ret;
 
                ret = mono_test_managed_marshal_bool_in (3, 0, 0, fcn);
@@ -646,7 +652,7 @@ public class marshalbool
 
        public static int test_0_U1_In_Managed ()
        {
-               MarshalBoolInDelegate fcn = new MarshalBoolInDelegate (new marshalbool ().MarshalBoolInHelper);
+               MarshalBoolInDelegate fcn = new MarshalBoolInDelegate (MarshalBoolInHelper);
                int ret;
 
                ret = mono_test_managed_marshal_bool_in (4, 0, 0, fcn);
@@ -663,7 +669,7 @@ public class marshalbool
 
        public static int test_0_VariantBool_In_Managed ()
        {
-               MarshalBoolInDelegate fcn = new MarshalBoolInDelegate (new marshalbool ().MarshalBoolInHelper);
+               MarshalBoolInDelegate fcn = new MarshalBoolInDelegate (MarshalBoolInHelper);
                int ret;
 
                ret = mono_test_managed_marshal_bool_in (5, 0, 0, fcn);
@@ -680,7 +686,7 @@ public class marshalbool
 
        public static int test_0_Default_Out_Managed ()
        {
-               MarshalBoolOutDelegate fcn = new MarshalBoolOutDelegate (new marshalbool ().MarshalBoolOutHelper);
+               MarshalBoolOutDelegate fcn = new MarshalBoolOutDelegate (MarshalBoolOutHelper);
                int ret;
 
                ret = mono_test_managed_marshal_bool_out (1, 0, 0, fcn);
@@ -697,7 +703,7 @@ public class marshalbool
 
        public static int test_0_Bool_Out_Managed ()
        {
-               MarshalBoolOutDelegate fcn = new MarshalBoolOutDelegate (new marshalbool ().MarshalBoolOutHelper);
+               MarshalBoolOutDelegate fcn = new MarshalBoolOutDelegate (MarshalBoolOutHelper);
                int ret;
                
                ret = mono_test_managed_marshal_bool_out (2, 0, 0, fcn);
@@ -714,7 +720,7 @@ public class marshalbool
 
        public static int test_0_I1_Out_Managed ()
        {
-               MarshalBoolOutDelegate fcn = new MarshalBoolOutDelegate (new marshalbool ().MarshalBoolOutHelper);
+               MarshalBoolOutDelegate fcn = new MarshalBoolOutDelegate (MarshalBoolOutHelper);
                int ret;
                
                ret = mono_test_managed_marshal_bool_out (3, 0, 0, fcn);
@@ -731,7 +737,7 @@ public class marshalbool
 
        public static int test_0_U1_Out_Managed ()
        {
-               MarshalBoolOutDelegate fcn = new MarshalBoolOutDelegate (new marshalbool ().MarshalBoolOutHelper);
+               MarshalBoolOutDelegate fcn = new MarshalBoolOutDelegate (MarshalBoolOutHelper);
                int ret;
                
                ret = mono_test_managed_marshal_bool_out (4, 0, 0, fcn);
@@ -748,7 +754,7 @@ public class marshalbool
 
        public static int test_0_VariantBool_Out_Managed ()
        {
-               MarshalBoolOutDelegate fcn = new MarshalBoolOutDelegate (new marshalbool ().MarshalBoolOutHelper);
+               MarshalBoolOutDelegate fcn = new MarshalBoolOutDelegate (MarshalBoolOutHelper);
                int ret;
                
                ret = mono_test_managed_marshal_bool_out (5, 0, 0, fcn);
@@ -765,7 +771,7 @@ public class marshalbool
 
        public static int test_0_Default_Ref_Managed ()
        {
-               MarshalBoolRefDelegate fcn = new MarshalBoolRefDelegate (new marshalbool ().MarshalBoolRefHelper);
+               MarshalBoolRefDelegate fcn = new MarshalBoolRefDelegate (MarshalBoolRefHelper);
                int ret;
 
                ret = mono_test_managed_marshal_bool_ref (1, 0, 0, 0, 0, fcn);
@@ -794,7 +800,7 @@ public class marshalbool
 
        public static int test_0_Bool_Ref_Managed ()
        {
-               MarshalBoolRefDelegate fcn = new MarshalBoolRefDelegate (new marshalbool ().MarshalBoolRefHelper);
+               MarshalBoolRefDelegate fcn = new MarshalBoolRefDelegate (MarshalBoolRefHelper);
                int ret;
 
                ret = mono_test_managed_marshal_bool_ref (2, 0, 0, 0, 0, fcn);
@@ -823,7 +829,7 @@ public class marshalbool
 
        public static int test_0_I1_Ref_Managed ()
        {
-               MarshalBoolRefDelegate fcn = new MarshalBoolRefDelegate (new marshalbool ().MarshalBoolRefHelper);
+               MarshalBoolRefDelegate fcn = new MarshalBoolRefDelegate (MarshalBoolRefHelper);
                int ret;
 
                ret = mono_test_managed_marshal_bool_ref (3, 0, 0, 0, 0, fcn);
@@ -852,7 +858,7 @@ public class marshalbool
 
        public static int test_0_U1_Ref_Managed ()
        {
-               MarshalBoolRefDelegate fcn = new MarshalBoolRefDelegate (new marshalbool ().MarshalBoolRefHelper);
+               MarshalBoolRefDelegate fcn = new MarshalBoolRefDelegate (MarshalBoolRefHelper);
                int ret;
 
                ret = mono_test_managed_marshal_bool_ref (4, 0, 0, 0, 0, fcn);
@@ -881,7 +887,7 @@ public class marshalbool
 
        public static int test_0_VariantBool_Ref_Managed ()
        {
-               MarshalBoolRefDelegate fcn = new MarshalBoolRefDelegate (new marshalbool ().MarshalBoolRefHelper);
+               MarshalBoolRefDelegate fcn = new MarshalBoolRefDelegate (MarshalBoolRefHelper);
                int ret;
 
                ret = mono_test_managed_marshal_bool_ref (5, 0, 0, 0, 0, fcn);
@@ -910,8 +916,9 @@ public class marshalbool
 
 ///////////////////////////////////////////////////////////////////
 
-       unsafe int MarshalBoolInHelper (int arg, uint expected, bool bDefaultMarsh, bool bBoolCustMarsh, bool bI1CustMarsh,
-                                       bool bU1CustMarsh, bool bVBCustMarsh)
+       [MonoPInvokeCallback (typeof (MarshalBoolInDelegate))]
+       unsafe static int MarshalBoolInHelper (int arg, uint expected, bool bDefaultMarsh, bool bBoolCustMarsh, bool bI1CustMarsh,
+                                                                                  bool bU1CustMarsh, bool bVBCustMarsh)
        {
                bool* ptestVal;
                switch (arg) {
@@ -946,8 +953,9 @@ public class marshalbool
                return 0;
        }
 
-       unsafe int MarshalBoolOutHelper (int arg, uint testVal, out bool bDefaultMarsh, out bool bBoolCustMarsh,
-                                        out bool bI1CustMarsh, out bool bU1CustMarsh, out bool bVBCustMarsh)
+       [MonoPInvokeCallback (typeof (MarshalBoolOutDelegate))]
+       unsafe static int MarshalBoolOutHelper (int arg, uint testVal, out bool bDefaultMarsh, out bool bBoolCustMarsh,
+                                                                                       out bool bI1CustMarsh, out bool bU1CustMarsh, out bool bVBCustMarsh)
        {
                bDefaultMarsh = bBoolCustMarsh = bI1CustMarsh = bU1CustMarsh = bVBCustMarsh = false;
                switch (arg) {
@@ -987,8 +995,9 @@ public class marshalbool
                return 0;
        }
 
-       unsafe int MarshalBoolRefHelper (int arg, uint expected, uint testVal, ref bool bDefaultMarsh, ref bool bBoolCustMarsh,
-                                        ref bool bI1CustMarsh, ref bool bU1CustMarsh, ref bool bVBCustMarsh)
+       [MonoPInvokeCallback (typeof (MarshalBoolRefDelegate))]
+       unsafe static int MarshalBoolRefHelper (int arg, uint expected, uint testVal, ref bool bDefaultMarsh, ref bool bBoolCustMarsh,
+                                                                                       ref bool bI1CustMarsh, ref bool bU1CustMarsh, ref bool bVBCustMarsh)
        {
                switch (arg) {
                case 1: