mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Added tests for NSHashTable/NSMapTable weak objects
This commit is contained in:
parent
e05c53f4b4
commit
79ac00e42c
3 changed files with 51 additions and 0 deletions
|
@ -1,3 +1,10 @@
|
|||
2019-10-17 Frederik Seiffert <frederik@algoriddim.com>
|
||||
|
||||
* Tests/base/NSHashTable/weakObjects.m:
|
||||
* Tests/base/NSMapTable/weakObjects.m:
|
||||
Added tests for [NSHashTable weakObjectsHashTable] and
|
||||
[NSMapTable strongToWeakObjectsMapTable].
|
||||
|
||||
2019-10-27 Fred Kiefer <fredkiefer@gmx.de>
|
||||
|
||||
* Headers/Foundation/NSUnit.h,
|
||||
|
|
22
Tests/base/NSHashTable/weakObjects.m
Normal file
22
Tests/base/NSHashTable/weakObjects.m
Normal file
|
@ -0,0 +1,22 @@
|
|||
#import "ObjectTesting.h"
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import <Foundation/NSHashTable.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSHashTable *hashTable = [NSHashTable weakObjectsHashTable];
|
||||
|
||||
NSAutoreleasePool *arp2 = [NSAutoreleasePool new];
|
||||
|
||||
id testObj = [[[NSObject alloc] init] autorelease];
|
||||
[hashTable addObject:testObj];
|
||||
PASS([[hashTable allObjects] count] == 1, "Table retains active weak reference");
|
||||
|
||||
[arp2 release]; arp2 = nil;
|
||||
|
||||
PASS([[hashTable allObjects] count] == 0, "Table removes dead weak reference");
|
||||
|
||||
[arp release]; arp = nil;
|
||||
return 0;
|
||||
}
|
22
Tests/base/NSMapTable/weakObjects.m
Normal file
22
Tests/base/NSMapTable/weakObjects.m
Normal file
|
@ -0,0 +1,22 @@
|
|||
#import "ObjectTesting.h"
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import <Foundation/NSMapTable.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSMapTable *mapTable = [NSMapTable strongToWeakObjectsMapTable];
|
||||
|
||||
NSAutoreleasePool *arp2 = [NSAutoreleasePool new];
|
||||
|
||||
id testObj = [[[NSObject alloc] init] autorelease];
|
||||
[mapTable setObject:testObj forKey:@"test"];
|
||||
PASS([mapTable objectForKey:@"test"] != nil, "Table retains active weak reference");
|
||||
|
||||
[arp2 release]; arp2 = nil;
|
||||
|
||||
PASS([mapTable objectForKey:@"test"] == nil, "Table removes dead weak reference");
|
||||
|
||||
[arp release]; arp = nil;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue