2019-11-04 12:45:28 +00:00
|
|
|
#import "ObjectTesting.h"
|
|
|
|
#import <Foundation/NSAutoreleasePool.h>
|
|
|
|
#import <Foundation/NSMapTable.h>
|
2019-12-10 09:45:53 +00:00
|
|
|
#if __has_include(<objc/capabilities.h>)
|
|
|
|
#include <objc/capabilities.h>
|
|
|
|
#endif
|
2019-11-04 12:45:28 +00:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2019-12-10 09:45:53 +00:00
|
|
|
START_SET("NSMapTable weak objects")
|
|
|
|
#ifdef OBJC_CAP_ARC
|
|
|
|
if (!objc_test_capability(OBJC_CAP_ARC))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
SKIP("ARC support unavailable")
|
|
|
|
}
|
2019-11-04 12:45:28 +00:00
|
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
|
|
|
NSMapTable *mapTable = [NSMapTable strongToWeakObjectsMapTable];
|
|
|
|
|
|
|
|
NSAutoreleasePool *arp2 = [NSAutoreleasePool new];
|
|
|
|
|
2020-06-05 09:48:35 +00:00
|
|
|
id testObj1 = [[[NSObject alloc] init] autorelease];
|
|
|
|
id testObj2 = [[[NSObject alloc] init] autorelease];
|
|
|
|
|
|
|
|
[mapTable setObject:testObj1 forKey:@"test"];
|
|
|
|
PASS([mapTable objectForKey:@"test"] == testObj1, "Table retains first active weak reference");
|
|
|
|
|
|
|
|
[mapTable setObject:testObj2 forKey:@"test"];
|
|
|
|
PASS([mapTable objectForKey:@"test"] == testObj2, "Table retains second active weak reference");
|
2019-11-04 12:45:28 +00:00
|
|
|
|
|
|
|
[arp2 release]; arp2 = nil;
|
|
|
|
|
|
|
|
PASS([mapTable objectForKey:@"test"] == nil, "Table removes dead weak reference");
|
|
|
|
|
|
|
|
[arp release]; arp = nil;
|
2019-12-10 09:45:53 +00:00
|
|
|
END_SET("NSMapTable weak objects")
|
2019-11-04 12:45:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|