2019-11-04 12:45:28 +00:00
|
|
|
#import "ObjectTesting.h"
|
|
|
|
#import <Foundation/NSAutoreleasePool.h>
|
|
|
|
#import <Foundation/NSMapTable.h>
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2019-12-10 09:45:53 +00:00
|
|
|
START_SET("NSMapTable weak objects")
|
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];
|
|
|
|
|
2024-07-16 18:43:28 +00:00
|
|
|
[mapTable setObject: testObj1 forKey: @"test"];
|
|
|
|
PASS([mapTable objectForKey: @"test"] == testObj1,
|
|
|
|
"Table retains first active weak reference");
|
2020-06-05 09:48:35 +00:00
|
|
|
|
2024-07-16 18:43:28 +00:00
|
|
|
[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;
|
|
|
|
|
2024-07-16 18:43:28 +00:00
|
|
|
PASS([mapTable objectForKey: @"test"] == nil,
|
|
|
|
"Table removes dead weak reference");
|
2019-11-04 12:45:28 +00:00
|
|
|
|
|
|
|
[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;
|
|
|
|
}
|