libs-base/Tests/base/NSMapTable/weak.m
theraven 407c9d0053 Tweak the weak tests so that they should still work, even if -base was compiled
with something that doesn't do a very good job of optimising autorelease
operations away.



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@33644 72102866-910b-0410-8b05-ffd578937521
2011-07-26 20:12:32 +00:00

27 lines
1,003 B
Objective-C

#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSMapTable.h>
int main()
{
[NSAutoreleasePool new];
id pool = [NSAutoreleasePool new];
NSMapTable *map = [[NSMapTable mapTableWithStrongToWeakObjects] retain];
NSMapTable *map2 = [[NSMapTable mapTableWithWeakToStrongObjects] retain];
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");
[pool drain];
[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;
}