public bool validateMenuItem(NSObject menuItem) { bool enabled = false; #if DEBUG Selector selector = (Selector)menuItem.Call("action"); if (selector.Name == "memoryTest:") { NSObject text; lock (m_lock) { if (m_checkingMemory) { text = (NSObject) new Class("NSString").Call("stringWithUTF8String:", Marshal.StringToHGlobalAuto("Stop Memory Test")); } else { text = (NSObject) new Class("NSString").Call("stringWithUTF8String:", Marshal.StringToHGlobalAuto("Start Memory Test")); } } menuItem.Call("setTitle:", text); enabled = true; } else if (respondsToSelector(selector)) { return(true); } #endif return(enabled); }
public void MyDerived() { NSObject str = (NSObject) new Class("MyDerived").Call("alloc").Call("init"); // can call NSString methods sbyte b = (sbyte)str.Call("boolValue"); Assert.AreEqual(0, b); // can call MyBase methods int i = (int)str.Call("get33"); Assert.AreEqual(33, i); // can call new MyDerived methods i = (int)str.Call("get63"); Assert.AreEqual(63, i); // can call overriden NSString methods i = (int)str.Call("intValue"); Assert.AreEqual(73, i); // can call overriden MyBase methods i = (int)str.Call("integerValue"); Assert.AreEqual(74, i); }
public void NilCallTest() { NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool")); NSObject nil = new NSObject(IntPtr.Zero); // Calling an NSObject method on nil does nothing and returns nil. NSObject result = (NSObject)nil.Call("hash"); Assert.IsTrue(result.IsNil()); // Calling a unknown method on nil does nothing and returns nil. result = (NSObject)nil.Call("foo"); Assert.IsTrue(result.IsNil()); // Can chain calls to nil. result = (NSObject)nil.Call("foo").Call("bar"); Assert.IsTrue(result.IsNil()); // Can use Native with null. result = (NSObject)nil.Call("foo"); Assert.IsTrue(result.IsNil()); pool.release(); }
public void BadUInt16To() { Class klass = new Class("NSNumber"); NSObject num = klass.Call("alloc").To <NSObject>(); num = num.Call("initWithInt:", 5000).To <NSObject>(); num.Call("unsignedShortValue").To <Int32>(); }
public void BadFloatTo() { Class klass = new Class("NSNumber"); NSObject num = klass.Call("alloc").To <NSObject>(); num = num.Call("initWithInt:", 5000).To <NSObject>(); num.Call("floatValue").To <double>(); }
public void CreateTest() { NSObject instance = (NSObject) new Class("Subclass1").Call("alloc").Call("init"); instance.Call("initValue"); int value = (int)instance.Call("getValue"); Assert.AreEqual(100, value); }
public void BadLongTo() { Class klass = new Class("NSNumber"); NSObject num = klass.Call("alloc").To <NSObject>(); num = num.Call("initWithInt:", 5000).To <NSObject>(); num.Call("longValue").To <Int64>(); }
public NSObject MungeRect(NSRect r) { NSObject str = (NSObject) new Class("NSMutableString").Call("alloc").Call("init"); str.Call("appendString:", DoCreateStr(((int)r.origin.x).ToString())); str.Call("appendString:", DoCreateStr(((int)r.origin.y).ToString())); str.Call("appendString:", DoCreateStr(((int)r.size.width).ToString())); str.Call("appendString:", DoCreateStr(((int)r.size.height).ToString())); return(str); }
public void DoubleWithTo() { Class klass = new Class("NSNumber"); NSObject num = klass.Call("alloc").To <NSObject>(); num = num.Call("initWithInt:", 122).To <NSObject>(); double result = num.Call("doubleValue").To <double>(); Assert.IsTrue(Math.Abs(122.0 - result) < 0.001); }
public void ULongLongWithTo() { Class klass = new Class("NSNumber"); NSObject num = klass.Call("alloc").To <NSObject>(); num = num.Call("initWithInt:", 122).To <NSObject>(); ulong result = num.Call("unsignedLongLongValue").To <ulong>(); Assert.AreEqual(122, result); }
public void IntWithTo() { Class klass = new Class("NSNumber"); NSObject num = klass.Call("alloc").To <NSObject>(); num = num.Call("initWithInt:", 122).To <NSObject>(); int result = num.Call("intValue").To <int>(); Assert.AreEqual(122, result); }
public void CharWithTo() { Class klass = new Class("NSNumber"); NSObject num = klass.Call("alloc").To <NSObject>(); num = num.Call("initWithInt:", 122).To <NSObject>(); byte result = num.Call("unsignedCharValue").To <byte>(); Assert.AreEqual(122, result); }
// Create a new view to be added/animated. Any kind of view can be added here, we // go for simple colored box using the Leopard "custom" box type. private NSObject DoNewBox() { NSRect frame = new NSRect(0.0f, 0.0f, BoxWidth, BoxHeight); NSObject box = (NSObject) new Class("NSBox").Call("alloc").Call("initWithFrame:", frame); box.Call("setBoxType:", 4U); box.Call("setBorderType:", 1U); box.Call("setTitlePosition:", 0U); box.Call("setFillColor:", this["boxColorField"].Call("color")); return(box); }
public void BoolWithTo() { Class klass = new Class("NSNumber"); NSObject num = klass.Call("alloc").To <NSObject>(); num = num.Call("initWithBool:", (sbyte)1).To <NSObject>(); sbyte result = num.Call("boolValue").To <sbyte>(); Assert.AreEqual(1, result); }
public void UInt16WithCast() { Class klass = new Class("NSNumber"); NSObject num = klass.Call("alloc").To <NSObject>(); num = num.Call("initWithInt:", 5000).To <NSObject>(); UInt16 result = (UInt16)num.Call("unsignedShortValue"); Assert.AreEqual(5000, result); }
public void BoolWithTo2() { Class klass = new Class("NSNumber"); NSObject num = klass.Call("alloc").To <NSObject>(); num = num.Call("initWithBool:", (sbyte)1).To <NSObject>(); bool b = num.Call("boolValue").To <bool>(); // To special cases sbyte to bool Assert.AreEqual(true, b); }
public void OverrideTest() { NSObject data = (NSObject) new Class("PrettyData").Call("alloc").Call("init"); int value = (int)data.Call("get33"); Assert.AreEqual(33, value); NSObject istr = (NSObject)data.Call("description"); string str = Marshal.PtrToStringAuto((IntPtr)istr.Call("UTF8String")); Assert.AreEqual("pretty: <>", str); }
public new NSObject description() { Class nsString = new Class("NSMutableString"); NSObject str = (NSObject)nsString.Call("alloc"); str = (NSObject)str.Call("initWithUTF8String:", Marshal.StringToHGlobalAuto("pretty: ")); NSObject ss = (NSObject)SuperCall(new Class("NSConcreteData"), "description"); str.Call("appendString:", ss); return(str); }
public override void SubmitGameData(U8ExtraGameData data) { NSObject extraData = Class.newInstance("U8UserExtraData"); extraData.setValueForKey("dataType", data.dataType); extraData.setValueForKey("roleID", data.roleID); extraData.setValueForKey("roleName", data.roleName); extraData.setValueForKey("roleLevel", data.roleLevel); extraData.setValueForKey("serverID", data.serverID); extraData.setValueForKey("serverName", data.serverName); extraData.setValueForKey("moneyNum", data.moneyNum); u8SDK.Call("submitGameData", extraData); }
public void DerivedWithCast() { NSObject o = (NSObject) new Class("Subclass1").Call("alloc").Call("initValue"); NSObject p = (NSObject)o.Call("Clone"); Assert.IsTrue((IntPtr)o != (IntPtr)p); Assert.AreEqual(100, (int)p.Call("getValue")); Subclass1 q = (Subclass1)o.Call("Clone"); Assert.IsTrue((IntPtr)o != (IntPtr)q); Assert.AreEqual(100, q.GetValue()); }
public void SelectorWithCast() { NSObject table = (NSObject) new Class("NSHashTable").Call("alloc").Call("init"); Selector selector = new Selector("addObject:"); NSObject sig = (NSObject)table.Call("methodSignatureForSelector:", selector); Class klass = new Class("NSInvocation"); NSObject invoke = (NSObject)klass.Call("invocationWithMethodSignature:", sig); invoke.Call("setSelector:", selector); Selector result = (Selector)invoke.Call("selector"); Assert.AreEqual("addObject:", result.Name); }
public void ArrayArg() { NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool")); Class nsData = new Class("NSData"); long bytes = DoGetMemory(); for (int j = 1; j < 100; ++j) { for (int i = 0; i < NumIterations / 100; ++i) { byte[] data = new byte[] { 2, 5, 6, 3 }; NSObject d = new NSObject(nsData.Call("alloc")); NSObject e = (NSObject)d.Call("initWithBytes:length:", data, data.Length); e.release(); } GC.Collect(); } pool.release(); GC.Collect(); GC.WaitForPendingFinalizers(); long delta = DoGetMemory() - bytes; if (delta / NumIterations > 4) { Assert.Fail("ArrayArg used {0}K of memory ({1} bytes per iteration)!", delta / 1024, delta / NumIterations); } }
public void IntArg() { NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool")); long bytes = DoGetMemory(); Class nsString = new Class("NSString"); NSObject str = (NSObject)nsString.Call("stringWithUTF8String:", Marshal.StringToHGlobalAuto("hello world")); for (int j = 1; j < 100; ++j) { for (int i = 0; i < NumIterations / 100; ++i) { str.Call("characterAtIndex:", 2); } GC.Collect(); } pool.release(); GC.Collect(); GC.WaitForPendingFinalizers(); long delta = DoGetMemory() - bytes; if (delta / NumIterations > 4) { Assert.Fail("IntArg used {0}K of memory ({1} bytes per iteration)!", delta / 1024, delta / NumIterations); } }
public void ClassWithCast() { NSObject table = (NSObject) new Class("NSHashTable").Call("alloc").Call("init"); Class result = (Class)table.Call("class"); Assert.AreEqual("NSConcreteHashTable", result.Name); }
public void TooManyArgs() { NSObject array = (NSObject) new Class("NSMutableArray").Call("alloc").Call("init"); NSObject str = (NSObject) new Class("NSString").Call("alloc").Call("init"); array.Call("addObject:", str, str); }
private NSObject DoCreateStr(string s) { Class nsString = new Class("NSMutableString"); NSObject str = (NSObject)nsString.Call("alloc"); return((NSObject)str.Call("initWithUTF8String:", Marshal.StringToHGlobalAuto(s))); }
public void Managed() { NSObject pool = new NSObject(NSObject.AllocAndInitInstance("NSAutoreleasePool")); long bytes = DoGetMemory(); for (int j = 1; j < 100; ++j) { for (int i = 0; i < NumIterations / 100; ++i) { NSObject instance = (NSObject) new Class("Subclass1").Call("alloc").Call("init"); instance.Call("TakeString", "what"); instance.release(); } GC.Collect(); } pool.release(); GC.Collect(); GC.WaitForPendingFinalizers(); long delta = DoGetMemory() - bytes; if (delta / NumIterations > 4) { Assert.Fail("Managed used {0}K of memory ({1} bytes per iteration)!", delta / 1024, delta / NumIterations); } }
public void StringArg() { NSObject instance = (NSObject) new Class("Subclass1").Call("alloc").Call("init"); NSString n = (NSString)instance.Call("TakeString", NSString.Create("hmm")); Assert.AreEqual("hmmhmm", n.ToString()); }
public void UShortArg() { NSObject instance = (NSObject) new Class("Subclass1").Call("alloc").Call("init"); ushort n = (ushort)instance.Call("TakeUInt162", (ushort)12); Assert.AreEqual(22, n); }
public void SlowBadArg() { Class klass = new Class("NSString"); NSObject str = (NSObject)klass.Call("stringWithUTF8String:", Marshal.StringToHGlobalAuto("hello world")); NSObject padding = (NSObject)klass.Call("stringWithUTF8String:", Marshal.StringToHGlobalAuto(" ")); str.Call("stringByPaddingToLength:withString:startingAtIndex:", 10, padding, padding); }