internal static void Init() { if (!ms_inited) { if (!ms_canInit) { throw new InvalidOperationException("mobjc was used, but CanInit is false"); } // This will force AppKit and Foundation to load if they have not already been loaded // (normally the static NSApplication ctor in mcocoa will take care of this, but some // apps may want to create NSObjects before that). Unused.Value = NSAvailableWindowDepths(); NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool")); DoInit(); // NSAutoreleasePool cannot be used within Posix threads unless Cocoa // is switched to "multithreading mode". We always have at least two // threads (the main thread and the finalizer thread) so we'll switch // to multithreading mode here. Selector selector = new Selector("foo"); NSObject thread = new Class("NSThread").Call("alloc").Call("initWithTarget:selector:object:", null, selector, null).To <NSObject>(); Unused.Value = thread.Call("start"); ms_inited = true; pool.release(); } }
public override void TestInvocation(int iterations) { var selector = new Selector("hash"); var instance = new Class("NSNumber").Call("numberWithInt:", 10); for (int i = 0; i < iterations; i++) { instance.Call(selector); } }
public override void TestAllocation(int iterations) { var @class = new Class("NSNumber"); var selector = new Selector("numberWithInt:"); for (int i = 0; i < iterations; i++) { @class.Call(selector, 10); } }
public override void TestExceptionRethrow(int iterations) { var instance = new Class(typeof(ExceptionTester).Name).Call("alloc").Call("init").To <NSObject>(); var selector = new Selector("Throw:arg2:arg3:arg4:arg5:"); for (int i = 0; i < iterations; i++) { try { instance.Call(selector, 10L, 20L, 30L, 40L, 50L); } catch { } } }
public override void TestVarargMarshaling(int iterations) { throw new NotImplementedException(); var instance = new Class("NSString").Call("stringWithUTF8String:", "some string to test"); var selector = new Selector("stringByAppendingFormat:"); for (int i = 0; i < iterations; i++) { instance.Call(selector, " %@ %@ %f %d %d", "some", "text", System.Math.PI, true, 10); } }