Merge pull request #1718 from madewokherd/sgenthreadcleanup
[mono.git] / mono / tests / pinvoke3.cs
index ded0626819ad13cf20be8654fd9f5946f5d06ed2..29ed8ea7eee8498f00e11aaf06d54b7109a8150d 100644 (file)
@@ -188,6 +188,17 @@ public class Tests {
        [DllImport ("libtest", EntryPoint="mono_test_marshal_return_delegate_delegate")]
        public static extern int mono_test_marshal_return_delegate_delegate (ReturnDelegateDelegate d);
 
+       [DllImport ("libtest", EntryPoint="mono_test_marshal_delegate_ref_delegate")]
+       public static extern int mono_test_marshal_delegate_ref_delegate (DelegateByrefDelegate del);
+
+       [DllImport ("libtest", EntryPoint="mono_test_marshal_virtual_delegate")]
+       public static extern int mono_test_marshal_virtual_delegate (VirtualDelegate del);
+
+       [DllImport ("libtest", EntryPoint="mono_test_marshal_icall_delegate")]
+       public static extern int mono_test_marshal_icall_delegate (IcallDelegate del);
+
+       public delegate string IcallDelegate (IntPtr p);
+
        public delegate int TestDelegate (int a, ref SimpleStruct ss, int b);
 
        public delegate SimpleStruct SimpleDelegate2 (SimpleStruct ss);
@@ -210,6 +221,10 @@ public class Tests {
 
        public delegate return_int_delegate ReturnDelegateDelegate ();
 
+       public delegate int DelegateByrefDelegate (ref return_int_delegate del);
+
+       public delegate int VirtualDelegate (int i);
+
        public static int Main () {
                return TestDriver.RunTests (typeof (Tests));
        }
@@ -333,6 +348,20 @@ public class Tests {
                return mono_test_marshal_return_delegate_delegate (new ReturnDelegateDelegate (return_delegate));
        }
 
+       public static int return_plus_1 (int i) {
+               return i + 1;
+       }
+
+       public static int ref_delegate_delegate (ref return_int_delegate del) {
+               del = return_plus_1;
+               return 0;
+       }
+
+       public static int test_55_marshal_delegate_ref_delegate () {
+               var del = new DelegateByrefDelegate (ref_delegate_delegate);
+               return mono_test_marshal_delegate_ref_delegate (del);
+       }
+
        /* Passing and returning strings */
 
        public delegate String ReturnStringDelegate (String s);
@@ -1087,29 +1116,60 @@ public class Tests {
        [DllImport ("libtest", EntryPoint="mono_test_marshal_call_callback")]
        public static extern int mono_test_marshal_call_callback ();
 
-       public static int test_0_appdomain_swich () {
-        callback = delegate () { return 42; };
-        mono_test_marshal_set_callback (callback);
-
+       public static int test_0_appdomain_switch () {
                // FIXME: The appdomain unload hangs
-               return 0;
-               /*
+               //return 0;
         AppDomain ad = AppDomain.CreateDomain ("foo");
                var c = (CallbackClass)ad.CreateInstanceAndUnwrap (
                                typeof (CallbackClass).Assembly.FullName, "Tests/CallbackClass");
-               int res = c.OtherDomainTest ();
+               c.SetCallback ();
+               int domain_id = AppDomain.CurrentDomain.Id;
+               int new_id = mono_test_marshal_call_callback ();
+               int res = 0;
+               if (new_id == domain_id)
+                       res = 1;
+               if (AppDomain.CurrentDomain.Id != domain_id)
+                       res = 2;
                AppDomain.Unload (ad);
                return res;
-               */
     }
 
+       static int domain_callback () {
+               return AppDomain.CurrentDomain.Id;
+       }
+
        class CallbackClass : MarshalByRefObject {
-               public int OtherDomainTest () {
-                       int appDomainId = AppDomain.CurrentDomain.Id;
-                       int res = mono_test_marshal_call_callback ();
-                       if (res != 42)
-                               return 2;
-                       return appDomainId == AppDomain.CurrentDomain.Id ? 0 : 1;
+               public int SetCallback () {
+                       mono_test_marshal_set_callback (domain_callback);
+                       return 0;
                }
     }
+
+       class Base {
+               public VirtualDelegate get_del () {
+                       return delegate_test;
+               }
+
+               public virtual int delegate_test (int i) {
+                       return i;
+               }
+       }
+
+       class Derived : Base {
+               public override int delegate_test (int i) {
+                       return i + 1;
+               }
+       }
+
+       public static int test_43_virtual () {
+               Base b = new Derived ();
+
+               return mono_test_marshal_virtual_delegate (b.get_del ());
+       }
+
+       public static int test_0_icall_delegate () {
+               var m = typeof (Marshal).GetMethod ("PtrToStringAnsi", new Type[] { typeof (IntPtr) });
+
+               return mono_test_marshal_icall_delegate ((IcallDelegate)Delegate.CreateDelegate (typeof (IcallDelegate), m));
+       }
 }