98 строки
3.5 KiB
C#
98 строки
3.5 KiB
C#
using System;
|
|
using System.Runtime.InteropServices;
|
|
|
|
using NUnit.Framework;
|
|
|
|
#if XAMCORE_2_0
|
|
using Foundation;
|
|
using ObjCRuntime;
|
|
#else
|
|
using MonoTouch.Foundation;
|
|
using MonoTouch.ObjCRuntime;
|
|
#endif
|
|
|
|
#if XAMCORE_2_0
|
|
using RectangleF=CoreGraphics.CGRect;
|
|
using SizeF=CoreGraphics.CGSize;
|
|
using PointF=CoreGraphics.CGPoint;
|
|
#else
|
|
using nfloat=global::System.Single;
|
|
using nint=global::System.Int32;
|
|
using nuint=global::System.UInt32;
|
|
#endif
|
|
|
|
namespace monotouchtest
|
|
{
|
|
[TestFixture]
|
|
public class NSMutableDictionaryTest {
|
|
|
|
[Test]
|
|
public void IndexerTest ()
|
|
{
|
|
IntPtr strkeyptr = IntPtr.Zero;
|
|
IntPtr strobjptr = IntPtr.Zero;
|
|
IntPtr objptr;
|
|
IntPtr keyptr;
|
|
|
|
NSString obj, key;
|
|
NSString v;
|
|
|
|
try {
|
|
strkeyptr = Marshal.StringToHGlobalAuto ("key");
|
|
strobjptr = Marshal.StringToHGlobalAuto ("obj");
|
|
|
|
// this[string]
|
|
keyptr = Messaging.IntPtr_objc_msgSend_IntPtr (Class.GetHandle (typeof (NSString)), Selector.GetHandle ("stringWithUTF8String:"), strkeyptr);
|
|
objptr = Messaging.IntPtr_objc_msgSend_IntPtr (Class.GetHandle (typeof (NSString)), Selector.GetHandle ("stringWithUTF8String:"), strobjptr);
|
|
using (var dict = Runtime.GetNSObject<NSMutableDictionary> (Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr (Class.GetHandle (typeof (NSMutableDictionary)), Selector.GetHandle ("dictionaryWithObject:forKey:"), objptr, keyptr))) {
|
|
v = (NSString) dict ["key"];
|
|
Assert.AreEqual ("obj", (string) v, "a");
|
|
|
|
dict ["key"] = (NSString) "value";
|
|
v = (NSString) dict ["key"];
|
|
Assert.AreEqual ("value", (string) v, "a");
|
|
}
|
|
|
|
// this[NSObject]
|
|
keyptr = Messaging.IntPtr_objc_msgSend_IntPtr (Class.GetHandle (typeof (NSString)), Selector.GetHandle ("stringWithUTF8String:"), strkeyptr);
|
|
objptr = Messaging.IntPtr_objc_msgSend_IntPtr (Class.GetHandle (typeof (NSString)), Selector.GetHandle ("stringWithUTF8String:"), strobjptr);
|
|
using (var dict = Runtime.GetNSObject<NSMutableDictionary> (Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr (Class.GetHandle (typeof (NSMutableDictionary)), Selector.GetHandle ("dictionaryWithObject:forKey:"), objptr, keyptr))) {
|
|
v = (NSString) dict [(NSObject) (NSString) "key"];
|
|
Assert.AreEqual ("obj", (string) v, "b");
|
|
|
|
dict [(NSObject) (NSString) "key"] = (NSString) "value";
|
|
v = (NSString) dict ["key"];
|
|
Assert.AreEqual ("value", (string) v, "a");
|
|
}
|
|
|
|
// this[NSString]
|
|
keyptr = Messaging.IntPtr_objc_msgSend_IntPtr (Class.GetHandle (typeof (NSString)), Selector.GetHandle ("stringWithUTF8String:"), strkeyptr);
|
|
objptr = Messaging.IntPtr_objc_msgSend_IntPtr (Class.GetHandle (typeof (NSString)), Selector.GetHandle ("stringWithUTF8String:"), strobjptr);
|
|
using (var dict = Runtime.GetNSObject<NSMutableDictionary> (Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr (Class.GetHandle (typeof (NSMutableDictionary)), Selector.GetHandle ("dictionaryWithObject:forKey:"), objptr, keyptr))) {
|
|
v = (NSString) dict [(NSString) "key"];
|
|
Assert.AreEqual ("obj", (string) v, "c");
|
|
|
|
dict [(NSString) "key"] = (NSString) "value";
|
|
v = (NSString) dict ["key"];
|
|
Assert.AreEqual ("value", (string) v, "a");
|
|
}
|
|
|
|
} finally {
|
|
Marshal.FreeHGlobal (strkeyptr);
|
|
Marshal.FreeHGlobal (strobjptr);
|
|
}
|
|
}
|
|
|
|
[Test]
|
|
public void Bug39993 ()
|
|
{
|
|
using (NSMutableDictionary testDict = new NSMutableDictionary ()) {
|
|
testDict.Add ((NSString) "Key1", (NSString) "Key1");
|
|
testDict.Add ((NSString) "Key2", (NSString) "KeyTest2");
|
|
Assert.NotNull (testDict ["Key1"], "Key1");
|
|
Assert.NotNull (testDict ["Key2"], "Key2");
|
|
}
|
|
}
|
|
}
|
|
}
|