xamarin-macios/tests/bindings-test/RegistrarBindingTest.cs

106 строки
2.5 KiB
C#
Исходник Обычный вид История

using System;
[ObjCRuntime] Don't double-retain blocks. (#3717) * [ObjCRuntime] Don't double-retain blocks. First there was darkness; no blocks were retained. Then came the light; and all blocks were retained [1] Forever. But all that once is, must one day not be, and thus the light gave way to darkness, and blocks were only retained as long as need be [2]. But before there was a balance, there was a crossroad. In some places the light shone forever, and all blocks were retained. In other places there was a balance, and the light shone only as long as needed. A desire to unify arose. Alas, it could not be. It was a bright and sunny day When a merge failed [3]. And all blocks were retained. Twice. Once [here][4] and once [there][5]. For many years we could not see. Until a dark and rainy night, when an awareness arose. And the desire to unify the balance could finally be fulfilled. [1]: https://github.com/xamarin/maccore/commit/6efca92acb5d0f2b1b495a40ac2e89586200d206 [2]: https://github.com/xamarin/maccore/commit/a22f877539058b889555ae4decae0f2e9aca029c [3]: https://github.com/xamarin/maccore/commit/befa0477cf9f3c9602d3fda6b9dee65e5bba506f [4]: https://github.com/xamarin/xamarin-macios/blob/5158a3c00138ae9bc45979487ca6a0fbc3fccc4d/src/ObjCRuntime/Runtime.cs#L858 [5]: https://github.com/xamarin/xamarin-macios/blob/5158a3c00138ae9bc45979487ca6a0fbc3fccc4d/runtime/runtime.m#L2091 * [tests] Fix test builds. * [monotouch-test] RegistrarTest.BlockCollection: allocate more and wait longer for the GC. Allocate more objects and wait longer for the GC to run. Hopefully fixes this problem: [FAIL] RegistrarTest.BlockCollection : freed blocks Expected: greater than 0 But was: 0 The blocks are freed if we just wait long enough... The problem is that we don't want to wait very long (makes the tests slow to run), so try to speed things up by allocating more.
2018-03-13 14:30:32 +03:00
using System.Threading;
#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 ();
ObjCBlockTester.TestClass = new Class (typeof (BlockCallbackClass));
ObjCBlockTester.CallRequiredStaticCallback ();
ObjCBlockTester.CallOptionalStaticCallback ();
obj.TestObject = new BlockCallbackClassExplicit ();
obj.CallOptionalCallback ();
obj.CallRequiredCallback ();
ObjCBlockTester.TestClass = new Class (typeof (BlockCallbackClassExplicit));
ObjCBlockTester.CallRequiredStaticCallback ();
ObjCBlockTester.CallOptionalStaticCallback ();
}
}
class BlockCallbackClass : NSObject, IObjCProtocolBlockTest
{
public void RequiredCallback (Action<int> completionHandler)
{
completionHandler (42);
}
[Export ("optionalCallback:")]
public void OptionalCallback (Action<int> completionHandler)
{
completionHandler (42);
}
[Export ("requiredStaticCallback:")]
public static void RequiredStaticCallback (Action<int> completionHandler)
{
completionHandler (42);
}
[Export ("optionalStaticCallback:")]
public static void OptionalStaticCallback (Action<int> completionHandler)
{
completionHandler (42);
}
}
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);
}
[Export ("requiredStaticCallback:")]
public static void RequiredStaticCallback (Action<int> completionHandler)
{
completionHandler (42);
}
[Export ("optionalStaticCallback:")]
public static void OptionalRequiredCallback (Action<int> completionHandler)
{
completionHandler (42);
}
}
[ObjCRuntime] Don't double-retain blocks. (#3717) * [ObjCRuntime] Don't double-retain blocks. First there was darkness; no blocks were retained. Then came the light; and all blocks were retained [1] Forever. But all that once is, must one day not be, and thus the light gave way to darkness, and blocks were only retained as long as need be [2]. But before there was a balance, there was a crossroad. In some places the light shone forever, and all blocks were retained. In other places there was a balance, and the light shone only as long as needed. A desire to unify arose. Alas, it could not be. It was a bright and sunny day When a merge failed [3]. And all blocks were retained. Twice. Once [here][4] and once [there][5]. For many years we could not see. Until a dark and rainy night, when an awareness arose. And the desire to unify the balance could finally be fulfilled. [1]: https://github.com/xamarin/maccore/commit/6efca92acb5d0f2b1b495a40ac2e89586200d206 [2]: https://github.com/xamarin/maccore/commit/a22f877539058b889555ae4decae0f2e9aca029c [3]: https://github.com/xamarin/maccore/commit/befa0477cf9f3c9602d3fda6b9dee65e5bba506f [4]: https://github.com/xamarin/xamarin-macios/blob/5158a3c00138ae9bc45979487ca6a0fbc3fccc4d/src/ObjCRuntime/Runtime.cs#L858 [5]: https://github.com/xamarin/xamarin-macios/blob/5158a3c00138ae9bc45979487ca6a0fbc3fccc4d/runtime/runtime.m#L2091 * [tests] Fix test builds. * [monotouch-test] RegistrarTest.BlockCollection: allocate more and wait longer for the GC. Allocate more objects and wait longer for the GC to run. Hopefully fixes this problem: [FAIL] RegistrarTest.BlockCollection : freed blocks Expected: greater than 0 But was: 0 The blocks are freed if we just wait long enough... The problem is that we don't want to wait very long (makes the tests slow to run), so try to speed things up by allocating more.
2018-03-13 14:30:32 +03:00
public class BlockCallbackTester : ObjCBlockTester
{
public override void ClassCallback (Action<int> completionHandler)
{
completionHandler (42);
}
}
}
}