public static void TestXml() { // Parse an example plist file NSObject x = PropertyListParser.Parse(new FileInfo("test-files/test1.plist")); // check the data in it NSDictionary d = (NSDictionary)x; Assert.True(d.Count == 5); Assert.True(((NSString)d.ObjectForKey("keyA")).ToString().Equals("valueA")); Assert.True(((NSString)d.ObjectForKey("key&B")).ToString().Equals("value&B")); Assert.True(((NSDate)d.ObjectForKey("date")).Date.ToUniversalTime().Equals(new DateTime(2011, 11, 28, 10, 21, 30, DateTimeKind.Utc)) || ((NSDate)d.ObjectForKey("date")).Date.ToUniversalTime().Equals(new DateTime(2011, 11, 28, 9, 21, 30, DateTimeKind.Utc))); Assert.True(ArrayEquals(((NSData)d.ObjectForKey("data")).Bytes, new byte[] { 0x00, 0x00, 0x00, 0x04, 0x10, 0x41, 0x08, 0x20, (byte)0x82 })); NSArray a = (NSArray)d.ObjectForKey("array"); Assert.True(a.Count == 4); Assert.True(a.ObjectAtIndex(0).Equals(new NSNumber(true))); Assert.True(a.ObjectAtIndex(1).Equals(new NSNumber(false))); Assert.True(a.ObjectAtIndex(2).Equals(new NSNumber(87))); Assert.True(a.ObjectAtIndex(3).Equals(new NSNumber(3.14159))); // read/write it, make sure we get the same thing PropertyListParser.SaveAsXml(x, new FileInfo("test-files/out-testXml.plist")); NSObject y = PropertyListParser.Parse(new FileInfo("test-files/out-testXml.plist")); Assert.True(x.Equals(y)); }
public virtual void Awake(NSArray rootObjects, IBObjectContainer objects, NSDictionary context) { NSEnumerator en; id obj; NSMutableArray topLevelObjects = (NSMutableArray)context.ObjectForKey((id)NS.NibTopLevelObjects); id owner = context.ObjectForKey(NS.NibOwner); id first = null; id app = null; // Get the file's owner and NSApplication object references... if (((NSCustomObject)rootObjects.ObjectAtIndex(1)).ClassName.IsEqualToString(@"FirstResponder")) first = ((NSCustomObject)rootObjects.ObjectAtIndex(1)).RealObject; else NS.Log(@"%s:first responder missing\n", "Awake"); if (((NSCustomObject)rootObjects.ObjectAtIndex(2)).ClassName.IsEqualToString(@"NSApplication")) app = ((NSCustomObject)rootObjects.ObjectAtIndex(2)).RealObject; else NS.Log(@"%s:NSApplication missing\n", "Awake"); // Use the owner as first root object ((NSCustomObject)rootObjects.ObjectAtIndex(0)).SetRealObject(owner); en = rootObjects.ObjectEnumerator(); while ((obj = en.NextObject()) != null) { if (obj.RespondsToSelector(new SEL("NibInstantiate"))) { obj = (id)Objc.MsgSend(obj, "NibInstantiate", null); } // IGNORE file's owner, first responder and NSApplication instances... if ((obj != null) && (obj != owner) && (obj != first) && (obj != app)) { topLevelObjects.AddObject(obj); // All top level objects must be released by the caller to avoid // leaking, unless they are going to be released by other nib // objects on behalf of the owner. //RETAIN(obj); } //FIXME //if ((obj.IsKindOfClass(NSMenu.Class)) && // (((NSMenu)obj _isMainMenu])) // { // // add the menu... // NSApp._setMainMenu(obj); // } } // Load connections and awaken objects Objc.MsgSend(objects, "NibInstantiate", null); }
public virtual NSData AuthenticationDataForComponents(NSArray components) { NSUInteger idx1; int idx2; NSUInteger count = components.Count; byte checksum = 0; // Compute authentication data for the components in the // given array. There are two types of components, NSPorts // and NSDatas. You should ignore a component of a type // which you don't understand. // Here, we compute a trivial 1 byte checksum over all the // bytes in the NSData objects in the array. for (idx1 = 0; idx1 < count; idx1++) { NSObject item = components.ObjectAtIndex (idx1).CastTo<NSObject> (); if (!item.IsKindOfClass (NSData.NSDataClass)) { continue; } NSData data = item.CastTo<NSData> (); byte[] buffer = data.GetBuffer (); for (idx2 = 0; idx2 < buffer.Length; idx2++) { checksum ^= buffer[idx2]; } } return new NSData (new byte[] { checksum }).Autorelease<NSData> (); }
public static void TestGnuStepASCII() { NSObject x = PropertyListParser.Parse(new FileInfo("test-files/test1-ascii-gnustep.plist")); NSDictionary d = (NSDictionary)x; Assert.True(d.Count == 5); Assert.True(((NSString)d.ObjectForKey("keyA")).ToString().Equals("valueA")); Assert.True(((NSString)d.ObjectForKey("key&B")).ToString().Equals("value&B")); Assert.True(((NSDate)d.ObjectForKey("date")).Date.Equals(new DateTime(2011, 11, 28, 9, 21, 30, DateTimeKind.Utc).ToLocalTime())); Assert.True(ArrayEquals(((NSData)d.ObjectForKey("data")).Bytes, new byte[] { 0x00, 0x00, 0x00, 0x04, 0x10, 0x41, 0x08, 0x20, (byte)0x82 })); NSArray a = (NSArray)d.ObjectForKey("array"); Assert.True(a.Count == 4); Assert.True(a.ObjectAtIndex(0).Equals(new NSNumber(true))); Assert.True(a.ObjectAtIndex(1).Equals(new NSNumber(false))); Assert.True(a.ObjectAtIndex(2).Equals(new NSNumber(87))); Assert.True(a.ObjectAtIndex(3).Equals(new NSNumber(3.14159))); }
public void InsertTest() { NSArray array = new NSArray(); array.Add(0); array.Add(1); array.Add(2); array.Insert(1, "test"); Assert.Equal(4, array.Count); Assert.Equal("test", array.ObjectAtIndex(1).ToObject()); }
public static void TestASCII() { NSObject x = PropertyListParser.Parse(new FileInfo("test-files/test1-ascii.plist")); NSDictionary d = (NSDictionary)x; Assert.True(d.Count == 5); Assert.True(((NSString)d.ObjectForKey("keyA")).ToString().Equals("valueA")); Assert.True(((NSString)d.ObjectForKey("key&B")).ToString().Equals("value&B")); var actualDate = (NSDate)d.ObjectForKey("date"); var expectedDate = new DateTime(2011, 11, 28, 9, 21, 30, DateTimeKind.Utc).ToLocalTime(); Assert.Equal(actualDate.Date, expectedDate); Assert.True(ArrayEquals(((NSData)d.ObjectForKey("data")).Bytes, new byte[] { 0x00, 0x00, 0x00, 0x04, 0x10, 0x41, 0x08, 0x20, (byte)0x82 })); NSArray a = (NSArray)d.ObjectForKey("array"); Assert.True(a.Count == 4); Assert.True(a.ObjectAtIndex(0).Equals(new NSString("YES"))); Assert.True(a.ObjectAtIndex(1).Equals(new NSString("NO"))); Assert.True(a.ObjectAtIndex(2).Equals(new NSString("87"))); Assert.True(a.ObjectAtIndex(3).Equals(new NSString("3.14159"))); }
public NSArray AllKeywords() { NSArray array = new NSArray(); array.Autorelease(); if (this._allKeywords == null) { uint i, count; this._allKeywords = this._builtInKeywords.MutableCopy<NSMutableArray>(); count = array.Count; for (i = 0; i < count; i++) { if (this._allKeywords.IndexOfObject(array.ObjectAtIndex(i)) == NSUInteger.NSNotFound) { this._allKeywords.AddObject(array.ObjectAtIndex(i)); } } this._allKeywords.SortUsingSelector(ObjectiveCRuntime.Selector("compare:")); } return this._allKeywords; }