Add support (and test) for weak keys and values in NSMapTable. This support should work in GC mode. It also works if the runtime supports ARC, even if the compiler does not use this support.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@33617 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
David Chisnall 2011-07-23 16:16:01 +00:00
parent 3e3d12b661
commit bc37adfb0c
4 changed files with 123 additions and 78 deletions

View file

@ -0,0 +1,25 @@
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSMapTable.h>
int main()
{
[NSAutoreleasePool new];
NSMapTable *map = [NSMapTable mapTableWithStrongToWeakObjects];
NSMapTable *map2 = [NSMapTable mapTableWithWeakToStrongObjects];
id obj = [NSObject new];
[map setObject: obj forKey: @"1"];
[map2 setObject: @"1" forKey: obj];
PASS(obj == [map objectForKey: @"1"], "Value stored in weak-value map");
PASS(nil != [map2 objectForKey: obj], "Value stored in weak-key map");
[obj release];
PASS(nil == [map objectForKey: @"1"], "Value removed from weak-value map");
NSEnumerator *enumerator = [map2 keyEnumerator];
NSUInteger count = 0;
while ([enumerator nextObject] != nil) { count++; }
PASS(count == 0, "Value removed from weak-key map");
PASS(0 == [map count], "Weak-value map reports correct count");
PASS(0 == [map2 count], "Weak-key map reports correct count");
return 0;
}