+ /*
+ * Appdomain save/restore
+ */
+ static Func<int> callback;
+
+ [DllImport ("libtest", EntryPoint="mono_test_marshal_set_callback")]
+ public static extern int mono_test_marshal_set_callback (Func<int> a);
+
+ [DllImport ("libtest", EntryPoint="mono_test_marshal_call_callback")]
+ public static extern int mono_test_marshal_call_callback ();
+
+ public static int test_0_appdomain_switch () {
+ // FIXME: The appdomain unload hangs
+ //return 0;
+ AppDomain ad = AppDomain.CreateDomain ("foo");
+ var c = (CallbackClass)ad.CreateInstanceAndUnwrap (
+ typeof (CallbackClass).Assembly.FullName, "Tests/CallbackClass");
+ 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 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));
+ }