2018-03-02 16:30:18 +03:00
|
|
|
|
using System;
|
2018-03-13 14:30:32 +03:00
|
|
|
|
using System.Threading;
|
2018-03-02 16:30:18 +03:00
|
|
|
|
|
|
|
|
|
#if __UNIFIED__
|
|
|
|
|
using Foundation;
|
|
|
|
|
using ObjCRuntime;
|
|
|
|
|
#else
|
|
|
|
|
using MonoTouch.Foundation;
|
|
|
|
|
using MonoTouch.ObjCRuntime;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
|
|
using Bindings.Test;
|
|
|
|
|
|
|
|
|
|
namespace Xamarin.BindingTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
[Preserve (AllMembers = true)]
|
|
|
|
|
public class RegistrarBindingTest
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void BlockCallback ()
|
|
|
|
|
{
|
|
|
|
|
using (var obj = new BlockCallbackTester ()) {
|
|
|
|
|
obj.CallClassCallback ();
|
|
|
|
|
|
|
|
|
|
obj.TestObject = new BlockCallbackClass ();
|
|
|
|
|
obj.CallOptionalCallback ();
|
|
|
|
|
obj.CallRequiredCallback ();
|
2018-03-17 01:01:56 +03:00
|
|
|
|
ObjCBlockTester.TestClass = new Class (typeof (BlockCallbackClass));
|
|
|
|
|
ObjCBlockTester.CallRequiredStaticCallback ();
|
|
|
|
|
ObjCBlockTester.CallOptionalStaticCallback ();
|
2018-03-02 16:30:18 +03:00
|
|
|
|
|
|
|
|
|
obj.TestObject = new BlockCallbackClassExplicit ();
|
|
|
|
|
obj.CallOptionalCallback ();
|
|
|
|
|
obj.CallRequiredCallback ();
|
2018-03-17 01:01:56 +03:00
|
|
|
|
ObjCBlockTester.TestClass = new Class (typeof (BlockCallbackClassExplicit));
|
|
|
|
|
ObjCBlockTester.CallRequiredStaticCallback ();
|
|
|
|
|
ObjCBlockTester.CallOptionalStaticCallback ();
|
2018-03-02 16:30:18 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class BlockCallbackClass : NSObject, IObjCProtocolBlockTest
|
|
|
|
|
{
|
|
|
|
|
public void RequiredCallback (Action<int> completionHandler)
|
|
|
|
|
{
|
|
|
|
|
completionHandler (42);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Export ("optionalCallback:")]
|
|
|
|
|
public void OptionalCallback (Action<int> completionHandler)
|
|
|
|
|
{
|
|
|
|
|
completionHandler (42);
|
|
|
|
|
}
|
2018-03-17 01:01:56 +03:00
|
|
|
|
|
|
|
|
|
[Export ("requiredStaticCallback:")]
|
|
|
|
|
public static void RequiredStaticCallback (Action<int> completionHandler)
|
|
|
|
|
{
|
|
|
|
|
completionHandler (42);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Export ("optionalStaticCallback:")]
|
|
|
|
|
public static void OptionalStaticCallback (Action<int> completionHandler)
|
|
|
|
|
{
|
|
|
|
|
completionHandler (42);
|
|
|
|
|
}
|
2018-03-02 16:30:18 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class BlockCallbackClassExplicit : NSObject, IObjCProtocolBlockTest
|
|
|
|
|
{
|
|
|
|
|
// Explicitly implemented interface member
|
|
|
|
|
void IObjCProtocolBlockTest.RequiredCallback (Action<int> completionHandler)
|
|
|
|
|
{
|
|
|
|
|
completionHandler (42);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Export ("optionalCallback:")]
|
|
|
|
|
public void OptionalCallback (Action<int> completionHandler)
|
|
|
|
|
{
|
|
|
|
|
completionHandler (42);
|
|
|
|
|
}
|
2018-03-17 01:01:56 +03:00
|
|
|
|
|
|
|
|
|
[Export ("requiredStaticCallback:")]
|
|
|
|
|
public static void RequiredStaticCallback (Action<int> completionHandler)
|
|
|
|
|
{
|
|
|
|
|
completionHandler (42);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Export ("optionalStaticCallback:")]
|
|
|
|
|
public static void OptionalRequiredCallback (Action<int> completionHandler)
|
|
|
|
|
{
|
|
|
|
|
completionHandler (42);
|
|
|
|
|
}
|
2018-03-02 16:30:18 +03:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-13 14:30:32 +03:00
|
|
|
|
public class BlockCallbackTester : ObjCBlockTester
|
2018-03-02 16:30:18 +03:00
|
|
|
|
{
|
|
|
|
|
public override void ClassCallback (Action<int> completionHandler)
|
|
|
|
|
{
|
|
|
|
|
completionHandler (42);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|