mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Make base do unintuitive and stupid things in the name of Apple compatibility (hopefully Apple will fix their implementation in 10.7.something...).
Fix some tests. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@33687 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
6dfb591252
commit
682c9beb5b
6 changed files with 34 additions and 76 deletions
|
@ -40,8 +40,15 @@
|
|||
# define STRONG_ACQUIRE(x) x
|
||||
#elif defined(OBJC_CAP_ARC)
|
||||
# include <objc/objc-arc.h>
|
||||
/*
|
||||
* OS X 10.7 uses weak to mean unsafe unretained, which is stupid and wrong,
|
||||
* but we should probably do the same thing for now. Uncomment this when Apple
|
||||
* fixes their implementation.
|
||||
# define WEAK_READ(x) objc_loadWeak((id*)x)
|
||||
# define WEAK_WRITE(addr, x) objc_storeWeak((id*)addr, (id)x)
|
||||
*/
|
||||
# define WEAK_READ(x) (*x)
|
||||
# define WEAK_WRITE(addr, x) (*(addr) = x)
|
||||
# define STRONG_WRITE(addr, x) objc_storeStrong((id*)addr, (id)x)
|
||||
# define STRONG_ACQUIRE(x) objc_retain(x)
|
||||
#else
|
||||
|
|
|
@ -124,7 +124,14 @@ int main(void)
|
|||
testProperty("enumDefault", "Ti,VenumDefault");
|
||||
testProperty("floatDefault", "Tf,VfloatDefault");
|
||||
testProperty("intDefault", "Ti,VintDefault");
|
||||
testProperty("longDefault", "Tl,VlongDefault");
|
||||
if (sizeof(long) == 4)
|
||||
{
|
||||
testProperty("longDefault", "Tl,VlongDefault");
|
||||
}
|
||||
else
|
||||
{
|
||||
testProperty("longDefault", "Tq,VlongDefault");
|
||||
}
|
||||
testProperty("shortDefault", "Ts,VshortDefault");
|
||||
testProperty("signedDefault", "Ti,VsignedDefault");
|
||||
testProperty("structDefault", "T{YorkshireTeaStruct=ic},VstructDefault");
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
#import "ObjectTesting.h"
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import <Foundation/NSHashTable.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
[NSAutoreleasePool new];
|
||||
id pool = [NSAutoreleasePool new];
|
||||
NSHashTable *ht = [[NSHashTable hashTableWithWeakObjects] retain];
|
||||
id obj = [NSObject new];
|
||||
[ht addObject: obj];
|
||||
PASS([ht containsObject: obj], "Added object to weak hash table");
|
||||
PASS(1 == [ht count], "Weak hash table contains one object");
|
||||
PASS([ht containsObject: obj], "Added object to weak hash table");
|
||||
[obj release];
|
||||
[pool drain];
|
||||
PASS(0 == [ht count], "Weak hash table contains no objects");
|
||||
PASS(0 == [[ht allObjects] count], "Weak hash table contains no objects");
|
||||
return 0;
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
#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;
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
#import "ObjectTesting.h"
|
||||
#import <Foundation/NSPointerArray.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
[NSAutoreleasePool new];
|
||||
id pool = [NSAutoreleasePool new];
|
||||
NSPointerArray *pa = [[NSPointerArray pointerArrayWithWeakObjects] retain];
|
||||
id obj = [NSObject new];
|
||||
[pa addPointer: obj];
|
||||
PASS([pa count] == 1, "Added object to weak array");
|
||||
[obj release];
|
||||
[pool drain];
|
||||
[pa compact];
|
||||
PASS([pa count] == 0, "Removed object to weak array");
|
||||
return 0;
|
||||
}
|
|
@ -1,17 +1,25 @@
|
|||
#import <Foundation/NSString.h>
|
||||
#import <Foundation/NSRegularExpression.h>
|
||||
#import "ObjectTesting.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
||||
NSString *regex = @"abcd*";
|
||||
NSString *source = @"abcdddddd e f g";
|
||||
NSRange r = [source rangeOfString: regex options: NSRegularExpressionSearch];
|
||||
PASS(r.length == 9, "Correct length for regex, expected 9 got %d", (int)r.length);
|
||||
regex = @"aBcD*";
|
||||
r = [source rangeOfString: regex options: (NSRegularExpressionSearch | NSCaseInsensitiveSearch)];
|
||||
PASS(r.length == 9, "Correct length for regex, expected 9 got %d", (int)r.length);
|
||||
|
||||
[pool release];
|
||||
return 0;
|
||||
[NSAutoreleasePool new];
|
||||
START_SET("NSString + regex")
|
||||
NS_DURING
|
||||
[NSRegularExpression new];
|
||||
NS_HANDLER
|
||||
SKIP("NSRegularExpression not built, please install libicu")
|
||||
return 0;
|
||||
NS_ENDHANDLER
|
||||
|
||||
NSString *regex = @"abcd*";
|
||||
NSString *source = @"abcdddddd e f g";
|
||||
NSRange r = [source rangeOfString: regex options: NSRegularExpressionSearch];
|
||||
PASS(r.length == 9, "Correct length for regex, expected 9 got %d", (int)r.length);
|
||||
regex = @"aBcD*";
|
||||
r = [source rangeOfString: regex options: (NSRegularExpressionSearch | NSCaseInsensitiveSearch)];
|
||||
PASS(r.length == 9, "Correct length for regex, expected 9 got %d", (int)r.length);
|
||||
END_SET("NSString + regex")
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue