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

45 строки
939 B
C#
Исходник Обычный вид История

using System;
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.Tests
{
[TestFixture]
[Preserve (AllMembers = true)]
public class RuntimeTest
{
[Test]
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.
};
}
}
}
}