2018-04-27 08:40:03 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
|
|
using Foundation;
|
|
|
|
|
using ObjCRuntime;
|
|
|
|
|
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
|
|
using Bindings.Test;
|
|
|
|
|
|
|
|
|
|
namespace Xamarin.Tests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
[Preserve (AllMembers = true)]
|
|
|
|
|
public class RuntimeTest
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
2018-04-27 12:33:33 +03:00
|
|
|
|
public void WrapperTypeLookupTest ()
|
|
|
|
|
{
|
|
|
|
|
using (var assigner = new MyProtocolAssigner ()) {
|
|
|
|
|
assigner.SetProtocol ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MyProtocolAssigner : ProtocolAssigner {
|
|
|
|
|
public bool Called;
|
|
|
|
|
public override void CompletedSetProtocol (IProtocolAssignerProtocol value)
|
|
|
|
|
{
|
|
|
|
|
Called = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-27 08:40:03 +03:00
|
|
|
|
public void EvilDeallocatorTest ()
|
|
|
|
|
{
|
|
|
|
|
// Create a few toggle-ref objects
|
|
|
|
|
for (var i = 0; i < 10; i++) {
|
|
|
|
|
var ed = new EvilDeallocator ();
|
|
|
|
|
ed.MarkMeDirty ();
|
|
|
|
|
}
|
|
|
|
|
// Now create an object that will call a managed callback in its destructor
|
|
|
|
|
using (var evil = new EvilDeallocator ()) {
|
|
|
|
|
evil.EvilCallback += (int obj) => {
|
|
|
|
|
// Running the GC will cause the GC to check the toggle-ref status
|
|
|
|
|
// of the objects we created above.
|
|
|
|
|
var t = new Thread (() => {
|
|
|
|
|
GC.Collect ();
|
|
|
|
|
});
|
|
|
|
|
t.Start ();
|
|
|
|
|
t.Join (); // If the test fails, this will deadlock.
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-29 11:42:25 +03:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void MainThreadDeallocationTest ()
|
|
|
|
|
{
|
2018-09-05 13:47:52 +03:00
|
|
|
|
#if OPTIMIZEALL
|
|
|
|
|
if (!TestRuntime.IsLinkAll)
|
|
|
|
|
Assert.Ignore ("This test must be processed by the linker if all optimizations are turned on.");
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-06-29 11:42:25 +03:00
|
|
|
|
ObjCBlockTester.CallAssertMainThreadBlockRelease ((callback) => {
|
|
|
|
|
callback (42);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
using (var main_thread_tester = new MainThreadTest ()) {
|
|
|
|
|
main_thread_tester.CallAssertMainThreadBlockReleaseCallback ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-12 16:56:45 +03:00
|
|
|
|
[Test]
|
|
|
|
|
public void MainThreadDeallocationTestQOS ()
|
|
|
|
|
{
|
|
|
|
|
#if OPTIMIZEALL
|
|
|
|
|
if (!TestRuntime.IsLinkAll)
|
|
|
|
|
Assert.Ignore ("This test must be processed by the linker if all optimizations are turned on.");
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
ObjCBlockTester.CallAssertMainThreadBlockReleaseQOS ((callback) => {
|
|
|
|
|
callback (42);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
using (var main_thread_tester = new MainThreadTest ()) {
|
|
|
|
|
main_thread_tester.CallAssertMainThreadBlockReleaseCallbackQOS ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-29 11:42:25 +03:00
|
|
|
|
class MainThreadTest : ObjCBlockTester {
|
|
|
|
|
public override void AssertMainThreadBlockReleaseCallback (InnerBlock completionHandler)
|
|
|
|
|
{
|
|
|
|
|
completionHandler (42);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-27 08:40:03 +03:00
|
|
|
|
}
|
|
|
|
|
}
|