Merge pull request #80 from triplef/add-weak-table-tests

Added tests for NSHashTable/NSMapTable weak objects support
This commit is contained in:
Fred Kiefer 2019-12-10 16:25:19 +01:00 committed by GitHub
commit 834e915b6d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 0 deletions

View file

@ -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-11-26 Niels Grewe <niels.grewe@halbordnung.de>
* Source/NSRunLoop.m:

View file

@ -0,0 +1,33 @@
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSHashTable.h>
#if __has_include(<objc/capabilities.h>)
#include <objc/capabilities.h>
#endif
int main()
{
START_SET("NSHashTable weak objects")
#ifdef OBJC_CAP_ARC
if (!objc_test_capability(OBJC_CAP_ARC))
#endif
{
SKIP("ARC support unavailable")
}
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;
END_SET("NSHashTable weak objects")
return 0;
}

View file

@ -0,0 +1,33 @@
#import "ObjectTesting.h"
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSMapTable.h>
#if __has_include(<objc/capabilities.h>)
#include <objc/capabilities.h>
#endif
int main()
{
START_SET("NSMapTable weak objects")
#ifdef OBJC_CAP_ARC
if (!objc_test_capability(OBJC_CAP_ARC))
#endif
{
SKIP("ARC support unavailable")
}
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;
END_SET("NSMapTable weak objects")
return 0;
}