From aedd13dc94ffba2b6f31de49a27c185e53052e25 Mon Sep 17 00:00:00 2001 From: rfm Date: Sat, 16 Nov 2024 13:34:56 +0000 Subject: [PATCH] More leaks fixed --- Tests/base/NSKVOSupport/kvoToMany.m | 5 +- Tests/base/NSLock/RecursiveLock.m | 2 +- Tests/base/NSLock/condlock.m | 17 ++-- Tests/base/NSLock/doubleLocking.m | 22 ++--- Tests/base/NSLock/tryLock.m | 22 ++--- Tests/base/NSLock/unbalancedUnlock.m | 2 +- Tests/base/NSMethodSignature/general.m | 2 +- Tests/base/NSMutableAttributedString/basic.m | 7 +- Tests/base/NSMutableAttributedString/test00.m | 89 ++++++++++--------- Tests/base/NSMutableAttributedString/test01.m | 28 ++++-- Tests/base/NSMutableCharacterSet/basic.m | 3 +- Tests/base/NSMutableData/basic.m | 3 +- Tests/base/NSMutableData/general.m | 64 ++++++------- Tests/base/NSMutableDictionary/basic.m | 2 +- Tests/base/NSMutableDictionary/general.m | 8 +- Tests/base/NSMutableIndexSet/test0.m | 6 +- Tests/base/NSMutableString/basic.m | 25 +++--- Tests/base/NSNotification/basic.m | 12 +-- Tests/base/NSNotification/dynamic.m | 8 +- 19 files changed, 174 insertions(+), 153 deletions(-) diff --git a/Tests/base/NSKVOSupport/kvoToMany.m b/Tests/base/NSKVOSupport/kvoToMany.m index b612d1dbc..d68f958ef 100644 --- a/Tests/base/NSKVOSupport/kvoToMany.m +++ b/Tests/base/NSKVOSupport/kvoToMany.m @@ -873,8 +873,11 @@ NSArrayShouldThrowWhenTryingToObserveIndexesOutOfRange() { START_SET("NSArrayShouldThrowWhenTryingToObserveIndexesOutOfRange"); - NSArray *test = [NSArray arrayWithObjects: [Observee new], [Observee new], nil]; + NSArray *o1 = AUTORELEASE([Observee new]); + NSArray *o2 = AUTORELEASE([Observee new]); + NSArray *test = [NSArray arrayWithObjects: o1, o2, nil]; TestObserver *observer = [TestObserver new]; + PASS_EXCEPTION([test addObserver:observer toObjectsAtIndexes:[NSIndexSet indexSetWithIndex:4] forKeyPath:@"bareArray" diff --git a/Tests/base/NSLock/RecursiveLock.m b/Tests/base/NSLock/RecursiveLock.m index 930508faa..678fee126 100644 --- a/Tests/base/NSLock/RecursiveLock.m +++ b/Tests/base/NSLock/RecursiveLock.m @@ -6,7 +6,7 @@ int main() { NSAutoreleasePool *arp = [NSAutoreleasePool new]; BOOL ret; - NSLock *lock = [NSRecursiveLock new]; + NSLock *lock = AUTORELEASE([NSRecursiveLock new]); ret = [lock tryLock]; if (ret) diff --git a/Tests/base/NSLock/condlock.m b/Tests/base/NSLock/condlock.m index e429535fd..58b8a32a7 100644 --- a/Tests/base/NSLock/condlock.m +++ b/Tests/base/NSLock/condlock.m @@ -65,18 +65,20 @@ NSMutableArray *received; int main(void) { - [NSAutoreleasePool new]; + ENTER_POOL { - Queue *q = [Queue new]; - NSMutableArray *sent = [NSMutableArray new]; - received = [NSMutableArray new]; - unsigned int i; + Queue *q = AUTORELEASE([Queue new]); + NSMutableArray *sent = [NSMutableArray array]; + unsigned int i; + + received = [NSMutableArray array]; [NSThread detachNewThreadSelector: @selector(consumeFromQueue:) - toTarget: [Consumer new] - withObject: q]; + toTarget: [Consumer new] + withObject: q]; for (i = 0; i < 10000; i++) { id obj = [NSNumber numberWithUnsignedInt: i]; + [sent addObject: obj]; if (i % 10 == 0) { @@ -91,5 +93,6 @@ int main(void) [NSThread sleepForTimeInterval: 2.0]; PASS([sent isEqual: received], "Condition lock"); } + LEAVE_POOL return 0; } diff --git a/Tests/base/NSLock/doubleLocking.m b/Tests/base/NSLock/doubleLocking.m index 6f100915e..0ffb2ffb8 100644 --- a/Tests/base/NSLock/doubleLocking.m +++ b/Tests/base/NSLock/doubleLocking.m @@ -22,7 +22,7 @@ int main() helpers = [helpers stringByAppendingPathComponent: @"obj"]; command = [helpers stringByAppendingPathComponent: @"doubleNSLock"]; - task = [[NSTask alloc] init]; + task = AUTORELEASE([[NSTask alloc] init]); ePipe = [[NSPipe pipe] retain]; [task setLaunchPath: command]; [task setStandardError: ePipe]; @@ -34,8 +34,8 @@ int main() } data = [hdl availableData]; NSLog(@"Data was %*.*s", [data length], [data length], [data bytes]); - string = [NSString alloc]; - string = [string initWithData: data encoding: NSISOLatin1StringEncoding]; + string = AUTORELEASE([[NSString alloc] + initWithData: data encoding: NSISOLatin1StringEncoding]); PASS([string rangeOfString: @"deadlock"].length > 0, "NSLock reported deadlock as expected"); if (NO == testPassed) @@ -46,8 +46,8 @@ int main() [task waitUntilExit]; command = [helpers stringByAppendingPathComponent: @"doubleNSConditionLock"]; - task = [[NSTask alloc] init]; - ePipe = [[NSPipe pipe] retain]; + task = AUTORELEASE([[NSTask alloc] init]); + ePipe = [NSPipe pipe]; [task setLaunchPath: command]; [task setStandardError: ePipe]; hdl = [ePipe fileHandleForReading]; @@ -58,8 +58,8 @@ int main() } data = [hdl availableData]; NSLog(@"Data was %*.*s", [data length], [data length], [data bytes]); - string = [NSString alloc]; - string = [string initWithData: data encoding: NSISOLatin1StringEncoding]; + string = AUTORELEASE([[NSString alloc] + initWithData: data encoding: NSISOLatin1StringEncoding]); PASS([string rangeOfString: @"deadlock"].length > 0, "NSConditionLock reported deadlock as expected"); if (NO == testPassed) @@ -69,23 +69,23 @@ int main() } [task waitUntilExit]; - ASSIGN(lock,[NSRecursiveLock new]); + lock = AUTORELEASE([NSRecursiveLock new]); [lock lock]; [lock lock]; [lock unlock]; [lock unlock]; - ASSIGN(lock,[NSLock new]); + lock = AUTORELEASE([NSLock new]); PASS([lock tryLock] == YES, "NSLock can tryLock"); PASS([lock tryLock] == NO, "NSLock says NO for recursive tryLock"); [lock unlock]; - ASSIGN(lock,[NSConditionLock new]); + lock = AUTORELEASE([NSConditionLock new]); PASS([lock tryLock] == YES, "NSConditionLock can tryLock"); PASS([lock tryLock] == NO, "NSConditionLock says NO for recursive tryLock"); [lock unlock]; - ASSIGN(lock,[NSRecursiveLock new]); + lock = AUTORELEASE([NSRecursiveLock new]); PASS([lock tryLock] == YES, "NSRecursiveLock can tryLock"); PASS([lock tryLock] == YES, "NSRecursiveLock says YES for recursive tryLock"); [lock unlock]; diff --git a/Tests/base/NSLock/tryLock.m b/Tests/base/NSLock/tryLock.m index b2edbedf4..2818d7509 100644 --- a/Tests/base/NSLock/tryLock.m +++ b/Tests/base/NSLock/tryLock.m @@ -3,24 +3,24 @@ int main() { - NSAutoreleasePool *arp = [NSAutoreleasePool new]; - BOOL ret; - id lock; + NSAutoreleasePool *arp = [NSAutoreleasePool new]; + BOOL ret; + id lock = nil; - lock = [NSLock new]; + lock = AUTORELEASE([NSLock new]); ret = [lock tryLock]; if (ret) [lock unlock]; PASS(ret, "NSLock with tryLock, then unlocking"); - ASSIGN(lock,[NSLock new]); + lock = AUTORELEASE([NSLock new]); [lock tryLock]; ret = [lock tryLock]; if (ret) [lock unlock]; PASS(ret == NO, "Recursive try lock with NSLock should return NO"); - ASSIGN(lock,[NSConditionLock new]); + lock = AUTORELEASE([NSConditionLock new]); [lock lock]; ret = [lock tryLock]; if (ret) @@ -38,34 +38,34 @@ int main() [lock unlock]; PASS(ret == NO, "Recursive tryLockWhenCondition: with NSConditionLock (2) should return NO"); - ASSIGN(lock,[NSRecursiveLock new]); + lock = AUTORELEASE([NSRecursiveLock new]); [lock tryLock]; ret = [lock tryLock]; if (ret) [lock unlock]; PASS(ret == YES, "Recursive try lock with NSRecursiveLock should return YES"); - ASSIGN(lock,[NSLock new]); + lock = AUTORELEASE([NSLock new]); ret = [lock lockBeforeDate: [NSDate dateWithTimeIntervalSinceNow: 1]]; if (ret) [lock unlock]; PASS(ret, "NSLock lockBeforeDate: works"); - ASSIGN(lock,[NSLock new]); + lock = AUTORELEASE([NSLock new]); [lock tryLock]; ret = [lock lockBeforeDate: [NSDate dateWithTimeIntervalSinceNow: 1]]; if (ret) [lock unlock]; PASS(ret == NO, "Recursive lockBeforeDate: with NSLock returns NO"); - ASSIGN(lock,[NSConditionLock new]); + lock = AUTORELEASE([NSConditionLock new]); [lock tryLock]; ret = [lock lockBeforeDate: [NSDate dateWithTimeIntervalSinceNow: 1]]; if (ret) [lock unlock]; PASS(ret == NO, "Recursive lockBeforeDate: with NSConditionLock returns NO"); - ASSIGN(lock,[NSRecursiveLock new]); + lock = AUTORELEASE([NSRecursiveLock new]); [lock tryLock]; ret = [lock lockBeforeDate: [NSDate dateWithTimeIntervalSinceNow: 1]]; if (ret) diff --git a/Tests/base/NSLock/unbalancedUnlock.m b/Tests/base/NSLock/unbalancedUnlock.m index 5c9b04a1a..216bec4c0 100644 --- a/Tests/base/NSLock/unbalancedUnlock.m +++ b/Tests/base/NSLock/unbalancedUnlock.m @@ -6,7 +6,7 @@ int main() { START_SET("Unbalanced unlocking") - NSLock *lock = [NSLock new]; + NSLock *lock = AUTORELEASE([NSLock new]); NSUserDefaults *defs = [NSUserDefaults standardUserDefaults]; BOOL mode = [defs boolForKey: @"GSMacOSXCompatible"]; diff --git a/Tests/base/NSMethodSignature/general.m b/Tests/base/NSMethodSignature/general.m index eccffe6be..ae18b0faa 100644 --- a/Tests/base/NSMethodSignature/general.m +++ b/Tests/base/NSMethodSignature/general.m @@ -198,7 +198,7 @@ typedef struct _MySmallStruct MySmallStruct; void test_compare_server_signature(void) { - id objct = [MyClass new]; + id objct = AUTORELEASE([MyClass new]); id proxy = [NSConnection rootProxyForConnectionWithRegisteredName: SRV_NAME host: nil]; if (proxy) diff --git a/Tests/base/NSMutableAttributedString/basic.m b/Tests/base/NSMutableAttributedString/basic.m index 400c6b44b..8f3911247 100644 --- a/Tests/base/NSMutableAttributedString/basic.m +++ b/Tests/base/NSMutableAttributedString/basic.m @@ -3,9 +3,10 @@ #import "ObjectTesting.h" int main() { - NSAutoreleasePool *arp = [NSAutoreleasePool new]; - NSArray *arr = [NSArray arrayWithObject:[NSMutableAttributedString new]]; + ENTER_POOL + NSArray *arr; + arr = [NSArray arrayWithObject: AUTORELEASE([NSMutableAttributedString new])]; test_alloc(@"NSMutableAttributedString"); test_NSObject(@"NSMutableAttributedString", arr); test_NSCoding(arr); @@ -13,7 +14,7 @@ int main() test_NSCopying(@"NSAttributedString",@"NSMutableAttributedString",arr,NO, NO); test_NSMutableCopying(@"NSAttributedString",@"NSMutableAttributedString",arr); - [arp release]; arp = nil; + LEAVE_POOL return 0; } diff --git a/Tests/base/NSMutableAttributedString/test00.m b/Tests/base/NSMutableAttributedString/test00.m index c21c58e8a..b0a361f48 100644 --- a/Tests/base/NSMutableAttributedString/test00.m +++ b/Tests/base/NSMutableAttributedString/test00.m @@ -63,12 +63,13 @@ NSString *NSForegroundColorAttributeName = @"NSForegroundColorAttributeName"; int main() { - NSAutoreleasePool *arp = [NSAutoreleasePool new]; + ENTER_POOL NSMutableAttributedString *attrStr; NSString *baseString = @"0123456789"; NSDictionary *red, *gray, *blue; NSMutableAttributedString *s; + s = [[[NSMutableAttributedString alloc] initWithString: @"string"] autorelease]; [s _sanity]; @@ -97,8 +98,8 @@ int main() gray = [NSDictionary dictionaryWithObject:@"Gray" forKey:@"Color"]; blue = [NSDictionary dictionaryWithObject:@"Blue" forKey:@"Color"]; - attrStr = [[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]; + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; PASS([[attrStr string] isEqual:baseString] && [attrStr checkAttributes:red range:NSMakeRange(0,10)], @@ -109,8 +110,8 @@ int main() PASS([attrStr checkAttributes:blue range:NSMakeRange(0,10)], "-setAttributes:range: works for the whole string"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:blue range:NSMakeRange(0,5)]; [attrStr _sanity]; @@ -118,8 +119,8 @@ int main() [attrStr checkAttributes:red range:NSMakeRange(5,5)], "-setAttributes:range: works for the first half of the string"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:blue range:NSMakeRange(3,5)]; [attrStr _sanity]; @@ -135,8 +136,8 @@ int main() [attrStr checkAttributes:red range:NSMakeRange(8,2)], "-setAttributes:range: works for same attributes in middle of string"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:blue range:NSMakeRange(5,5)]; [attrStr _sanity]; @@ -144,8 +145,8 @@ int main() [attrStr checkAttributes:blue range:NSMakeRange(5,5)], "-setAttributes:range: works for the last half of the string"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:blue range:NSMakeRange(0,3)]; [attrStr _sanity]; @@ -158,8 +159,8 @@ int main() [attrStr checkAttributes:gray range:NSMakeRange(7,3)], "-setAttributes:range: works in three parts of the string"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:blue range:NSMakeRange(0,5)]; [attrStr _sanity]; @@ -173,8 +174,8 @@ int main() [attrStr checkAttributes:red range:NSMakeRange(9,1)], "-setAttributes:range: works with overlapping"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr= AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:blue range:NSMakeRange(1,2)]; [attrStr _sanity]; @@ -191,8 +192,8 @@ int main() [attrStr checkAttributes:red range:NSMakeRange(9,1)], "-setAttributes:range: works with overlapping (2)"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:blue range:NSMakeRange(2,5)]; [attrStr _sanity]; @@ -203,8 +204,8 @@ int main() [attrStr checkAttributes:red range:NSMakeRange(7,3)], "-setAttributes:range: works with replacing"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:blue range:NSMakeRange(1,8)]; [attrStr _sanity]; @@ -221,8 +222,8 @@ int main() [attrStr checkAttributes:red range:NSMakeRange(9,1)], "-setAttributes:range: works with chinese boxes"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:blue range:NSMakeRange(1,3)]; [attrStr _sanity]; @@ -233,8 +234,8 @@ int main() [attrStr checkAttributes:red range:NSMakeRange(5,5)], "-setAttributes:range: works with extending at the end (diff color)"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:gray range:NSMakeRange(1,3)]; [attrStr _sanity]; @@ -245,8 +246,8 @@ int main() [attrStr checkAttributes:red range:NSMakeRange(5,5)], "-setAttributes:range: works with extending at the end (diff color)"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:blue range:NSMakeRange(2,3)]; [attrStr _sanity]; @@ -257,8 +258,8 @@ int main() [attrStr checkAttributes:red range:NSMakeRange(5,5)], "-setAttributes:range: works with extending at the beginning (diff color)"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:gray range:NSMakeRange(2,3)]; [attrStr _sanity]; @@ -270,8 +271,8 @@ int main() "-setAttributes:range: works with extending at the beginning (same color)"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:blue range:NSMakeRange(1,3)]; [attrStr _sanity]; @@ -283,8 +284,8 @@ int main() [attrStr checkAttributes:red range:NSMakeRange(4,6)], "-setAttributes:range: works with subset at the end (diff color)"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:gray range:NSMakeRange(1,3)]; [attrStr _sanity]; @@ -295,8 +296,8 @@ int main() [attrStr checkAttributes:red range:NSMakeRange(4,6)], "-setAttributes:range: works with subset at the end (same color)"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:blue range:NSMakeRange(2,3)]; [attrStr _sanity]; @@ -308,8 +309,8 @@ int main() [attrStr checkAttributes:red range:NSMakeRange(5,5)], "-setAttributes:range: works with subset at the beginning (diff color)"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:gray range:NSMakeRange(2,3)]; [attrStr _sanity]; @@ -320,8 +321,8 @@ int main() [attrStr checkAttributes:red range:NSMakeRange(5,5)], "-setAttributes:range: works with subset at the beginning (same color)"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:gray range:NSMakeRange(2,1)]; [attrStr _sanity]; @@ -334,8 +335,8 @@ int main() [attrStr checkAttributes:red range:NSMakeRange(6,4)], "-setAttributes:range: works with subsets (diff color)"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:blue range:NSMakeRange(2,1)]; [attrStr _sanity]; @@ -348,8 +349,8 @@ int main() [attrStr checkAttributes:red range:NSMakeRange(6,4)], "-setAttributes:range: works with subsets (same color)"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:blue range:NSMakeRange(2,1)]; [attrStr _sanity]; @@ -364,8 +365,8 @@ int main() PASS([attrStr checkAttributes:gray range:NSMakeRange(0,10)], "-setAttributes:range: works with setting attributes for the whole string"); - ASSIGN(attrStr,[[NSMutableAttributedString alloc] initWithString:baseString - attributes:red]); + attrStr = AUTORELEASE([[NSMutableAttributedString alloc] + initWithString: baseString attributes: red]); [attrStr _sanity]; [attrStr setAttributes:blue range:NSMakeRange(0,1)]; [attrStr _sanity]; @@ -377,7 +378,7 @@ int main() [attrStr checkAttributes:red range:NSMakeRange(3,7)], "-setAttributes:range: works with nearby attributes"); - [arp release]; arp = nil; + LEAVE_POOL return 0; } diff --git a/Tests/base/NSMutableAttributedString/test01.m b/Tests/base/NSMutableAttributedString/test01.m index 60ea4fce8..9be82082b 100644 --- a/Tests/base/NSMutableAttributedString/test01.m +++ b/Tests/base/NSMutableAttributedString/test01.m @@ -44,6 +44,18 @@ } @end +@interface NSMutableAttributedString (autoreleased) ++ (NSMutableAttributedString*) stringWithString: (NSString*)s + attributes: (NSDictionary*)a; +@end +@implementation NSMutableAttributedString (autoreleased) ++ (NSMutableAttributedString*) stringWithString: (NSString*)s + attributes: (NSDictionary*)a +{ + return AUTORELEASE([[self alloc] initWithString: s attributes: a]); +} +@end + int main() { NSAutoreleasePool *arp = [NSAutoreleasePool new]; @@ -55,25 +67,25 @@ int main() [[[NSMutableAttributedString new] autorelease] _sanity]; - as = [[NSMutableAttributedString alloc] initWithString:base1 attributes:nil]; + as = [NSMutableAttributedString stringWithString:base1 attributes:nil]; [as replaceCharactersInRange:NSMakeRange(2,2) withString:@""]; [as _sanity]; PASS([[as string] isEqual:@"ba-1"], "-replaceCharactersInRange: withString: works with zero length string"); - as = [[NSMutableAttributedString alloc] initWithString:base1 attributes:nil]; + as = [NSMutableAttributedString stringWithString:base1 attributes:nil]; [as replaceCharactersInRange:NSMakeRange(2,2) withString:base2]; [as _sanity]; PASS([[as string] isEqual:@"babase-2-1"], "-replaceCharactersInRange:withString: works in middle of string"); - as = [[NSMutableAttributedString alloc] initWithString:base1 attributes:nil]; + as = [NSMutableAttributedString stringWithString:base1 attributes:nil]; [as replaceCharactersInRange:NSMakeRange(6,0) withString:base2]; [as _sanity]; PASS([[as string] isEqual:@"base-1base-2"], "-replaceCharactersInRange:withString: works at end of string works"); - as = [[NSMutableAttributedString alloc] initWithString:base1 attributes:nil]; + as = [NSMutableAttributedString stringWithString:base1 attributes:nil]; [as replaceCharactersInRange:NSMakeRange(0,0) withString:base2]; [as _sanity]; PASS([[as string] isEqual:@"base-2base-1"], @@ -82,7 +94,7 @@ int main() attrE = [NSDictionary dictionary]; attr1 = [NSDictionary dictionaryWithObject:@"a" forKey:@"1"]; attr2 = [NSDictionary dictionaryWithObject:@"b" forKey:@"2"]; - as = [[NSMutableAttributedString alloc] initWithString:base1 + as = [NSMutableAttributedString stringWithString:base1 attributes:attr1]; [as setAttributes:attr2 range:NSMakeRange(2,4)]; [as replaceCharactersInRange:NSMakeRange(0,6) withString:@""]; @@ -92,7 +104,7 @@ int main() PASS([as checkAttributes:attrE range:NSMakeRange(0,4)], "-replaceCharactersInRange:withString: keeps attributes if entire string is replaced"); - as = [[NSMutableAttributedString alloc] initWithString:base1 + as = [NSMutableAttributedString stringWithString:base1 attributes:attr1]; [as replaceCharactersInRange:NSMakeRange(0,6) withString:base2]; [as _sanity]; @@ -107,7 +119,7 @@ int main() BOOL removeAll,replaceAll; NSDictionary *aBegin,*aEnd; - as = [[NSMutableAttributedString alloc] initWithString:@"aabbccdd" + as = [NSMutableAttributedString stringWithString:@"aabbccdd" attributes:attr2]; removeAll = (start == 0 && length == 8); [as setAttributes:attr1 range:NSMakeRange(2,2)]; @@ -134,7 +146,7 @@ int main() "attribute/(replaceCharacters... with zero length string) interaction _sanity checks %i %i",start, length); } - as = [[NSMutableAttributedString alloc] initWithString:@"aabbccdd" + as = [NSMutableAttributedString stringWithString:@"aabbccdd" attributes:attr2]; replaceAll = (start == 0 && length == 8); [as setAttributes:attr1 range:NSMakeRange(2,2)]; diff --git a/Tests/base/NSMutableCharacterSet/basic.m b/Tests/base/NSMutableCharacterSet/basic.m index 7de9b397d..78b0e2cef 100644 --- a/Tests/base/NSMutableCharacterSet/basic.m +++ b/Tests/base/NSMutableCharacterSet/basic.m @@ -5,7 +5,8 @@ int main() { NSAutoreleasePool *arp = [NSAutoreleasePool new]; - id testObj = [NSMutableCharacterSet new]; + id testObj = AUTORELEASE([NSMutableCharacterSet new]); + test_alloc(@"NSMutableCharacterSet"); test_NSObject(@"NSMutableCharacterSet",[NSArray arrayWithObject:testObj]); test_NSCoding([NSArray arrayWithObject:testObj]); diff --git a/Tests/base/NSMutableData/basic.m b/Tests/base/NSMutableData/basic.m index c5fd17e9b..d8bf135b2 100644 --- a/Tests/base/NSMutableData/basic.m +++ b/Tests/base/NSMutableData/basic.m @@ -5,7 +5,8 @@ int main() { NSAutoreleasePool *arp = [NSAutoreleasePool new]; - id testObject = [NSMutableData new]; + id testObject = [NSMutableData data]; + test_alloc(@"NSMutableData"); test_NSObject(@"NSData",[NSArray arrayWithObject:testObject]); test_NSCoding([NSArray arrayWithObject:testObject]); diff --git a/Tests/base/NSMutableData/general.m b/Tests/base/NSMutableData/general.m index 8050c0f1c..a0604df43 100644 --- a/Tests/base/NSMutableData/general.m +++ b/Tests/base/NSMutableData/general.m @@ -6,52 +6,52 @@ int main() { - NSAutoreleasePool *arp = [NSAutoreleasePool new]; - char *str1,*str2,*tmp; - NSData *data1; + ENTER_POOL + char *str1, *str2, *tmp; + NSData *data1; NSMutableData *mutable; unsigned char *hold; str1 = "Test string for data classes"; - str2 = (char *) malloc(sizeof("insert")); - strcpy(str2,"insert"); + str2 = (char *)malloc(sizeof("insert")); + strcpy(str2, "insert"); - mutable = [NSMutableData dataWithLength:100]; + mutable = [NSMutableData dataWithLength: 100]; hold = [mutable mutableBytes]; - /* hmpf is this correct */ - data1 = [NSData dataWithBytes:str1 length:(strlen(str1) * sizeof(void*))]; - PASS(data1 != nil && - [data1 isKindOfClass:[NSData class]] && - [data1 length] == (strlen(str1) * sizeof(void*)) && - [data1 bytes] != str1 && - strcmp(str1,[data1 bytes]) == 0, - "+dataWithBytes:length: works"); + data1 = [NSData dataWithBytes: str1 length: (strlen(str1) + 1)]; + PASS(data1 != nil + && [data1 isKindOfClass: [NSData class]] + && [data1 length] == (strlen(str1) + 1) + && [data1 bytes] != str1 + && strcmp(str1, [data1 bytes]) == 0, + "+dataWithBytes:length: works") mutable = [NSMutableData data]; - PASS(mutable != nil && - [mutable isKindOfClass:[NSMutableData class]] && - [mutable length] == 0, - "+data creates empty mutable data"); + PASS(mutable != nil + && [mutable isKindOfClass: [NSMutableData class]] + && [mutable length] == 0, + "+data creates empty mutable data") - [mutable setData:data1]; - PASS(mutable != nil && - [mutable length] == (strlen(str1) * sizeof(void*)), - "-setData: works"); + [mutable setData: data1]; + PASS(mutable != nil + && [mutable length] == (strlen(str1) + 1), + "-setData: works") - [mutable replaceBytesInRange:NSMakeRange(22,6) withBytes:str2]; + [mutable replaceBytesInRange: NSMakeRange(22, 6) withBytes: str2]; tmp = (char *)malloc([mutable length]); - [mutable getBytes:tmp range:NSMakeRange(22,6)]; + [mutable getBytes: tmp range: NSMakeRange(22, 6)]; tmp[6] = '\0'; - PASS(mutable != nil && - strcmp(tmp,str2) == 0, - "-replaceBytesInRange:withBytes suceeds"); + PASS(mutable != nil + && strcmp(tmp, str2) == 0, + "-replaceBytesInRange:withBytes suceeds") free(tmp); - PASS_EXCEPTION([mutable replaceBytesInRange:NSMakeRange([mutable length]+1,6) - withBytes:str2];, - NSRangeException,"-replaceBytesInRange:withBytes out of range raises exception"); - + PASS_EXCEPTION([mutable + replaceBytesInRange: NSMakeRange([mutable length]+1, 6) withBytes: str2];, + NSRangeException, + "-replaceBytesInRange:withBytes out of range raises exception") - [arp release]; arp = nil; + free(str2); + LEAVE_POOL return 0; } diff --git a/Tests/base/NSMutableDictionary/basic.m b/Tests/base/NSMutableDictionary/basic.m index 52667308a..ecba146c2 100644 --- a/Tests/base/NSMutableDictionary/basic.m +++ b/Tests/base/NSMutableDictionary/basic.m @@ -7,7 +7,7 @@ int main() NSAutoreleasePool *arp = [NSAutoreleasePool new]; NSMutableDictionary *testObj; - testObj = [NSMutableDictionary new]; + testObj = [NSMutableDictionary dictionary]; test_NSObject(@"NSMutableDictionary", [NSArray arrayWithObject:testObj]); diff --git a/Tests/base/NSMutableDictionary/general.m b/Tests/base/NSMutableDictionary/general.m index 80ccf10b5..9a5f5a147 100644 --- a/Tests/base/NSMutableDictionary/general.m +++ b/Tests/base/NSMutableDictionary/general.m @@ -8,7 +8,7 @@ int main() { - NSAutoreleasePool *arp = [NSAutoreleasePool new]; + ENTER_POOL NSString *key1, *key2, *key3, *val1, *val2, *val3; NSArray *keys1, *keys2, *keys3, *vals1, *vals2, *vals3; id obj; @@ -28,7 +28,7 @@ int main() vals3 = [NSArray arrayWithObjects:val1,val2,val3,nil]; - dict = [NSMutableDictionary new]; + dict = [NSMutableDictionary dictionary]; PASS(dict != nil && [dict isKindOfClass:[NSMutableDictionary class]] && [dict count] == 0, @@ -207,7 +207,7 @@ int main() [obj isEqual:dict], "-description gives us a text property-list"); - dict = [NSMutableDictionary new]; + dict = [NSMutableDictionary dictionary]; [dict setObject:@"hello" forKey:@"world"]; PASS(dict != nil && [dict isKindOfClass:[NSMutableDictionary class]] && @@ -218,6 +218,6 @@ int main() PASS([[dict valueForKey:@"Lücke"] isEqualToString:@"hello"], "unicode keys work with setValue:forKey:"); - [arp release]; arp = nil; + LEAVE_POOL return 0; } diff --git a/Tests/base/NSMutableIndexSet/test0.m b/Tests/base/NSMutableIndexSet/test0.m index f71fd9fd8..1858ddb74 100644 --- a/Tests/base/NSMutableIndexSet/test0.m +++ b/Tests/base/NSMutableIndexSet/test0.m @@ -3,8 +3,8 @@ #include int main() { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSMutableIndexSet *set = [[NSMutableIndexSet alloc] init]; + ENTER_POOL + NSMutableIndexSet *set = AUTORELEASE([NSMutableIndexSet new]); [set addIndex:1]; [set addIndex:2]; @@ -22,6 +22,6 @@ int main() PASS([set containsIndexesInRange:NSMakeRange(0,2)], "contains range"); - [pool release]; + LEAVE_POOL return 0; } diff --git a/Tests/base/NSMutableString/basic.m b/Tests/base/NSMutableString/basic.m index 1912675de..715c62ed3 100644 --- a/Tests/base/NSMutableString/basic.m +++ b/Tests/base/NSMutableString/basic.m @@ -31,7 +31,7 @@ length: l encoding: encoding freeWhenDone: freeWhenDone]; - if (s == nil) return nil; + if (s == nil) {RELEASE(self); return nil;} l = [s length] * sizeof(unichar); characters = malloc(l); [s getCharacters: characters]; @@ -66,22 +66,22 @@ int main() { - NSAutoreleasePool *arp = [NSAutoreleasePool new]; + ENTER_POOL unichar u0 = 'a'; unichar u1 = 0xfe66; NSMutableString *testObj,*base,*ext,*want, *str1, *str2; unichar chars[3]; test_alloc(@"NSMutableString"); - testObj = [[NSMutableString alloc] initWithCString:"Hello\n"]; - test_NSCoding([NSArray arrayWithObject:testObj]); - test_keyed_NSCoding([NSArray arrayWithObject:testObj]); + testObj = AUTORELEASE([[NSMutableString alloc] initWithCString:"Hello\n"]); + test_NSCoding([NSArray arrayWithObject: testObj]); + test_keyed_NSCoding([NSArray arrayWithObject: testObj]); test_NSCopying(@"NSString",@"NSMutableString", - [NSArray arrayWithObject:testObj],NO,NO); + [NSArray arrayWithObject: testObj],NO,NO); test_NSMutableCopying(@"NSString",@"NSMutableString", - [NSArray arrayWithObject:testObj]); + [NSArray arrayWithObject: testObj]); - base = [[NSMutableString alloc] initWithCString:"hello"]; + base = [NSMutableString stringWithCString:"hello"]; ext = [@"\"\\UFE66???\"" propertyList]; want = [@"\"hello\\UFE66???\"" propertyList]; [base appendString:ext]; @@ -89,11 +89,11 @@ int main() && [want length] == 9 && [base isEqual:want], "We can append a unicode string to a C string"); - PASS([[[NSMutableString alloc] initWithCharacters: &u0 length: 1] + PASS([AUTORELEASE([[NSMutableString alloc] initWithCharacters: &u0 length: 1]) isKindOfClass: [NSMutableString class]], "initWithCharacters:length: creates mutable string for ascii"); - PASS([[[NSMutableString alloc] initWithCharacters: &u1 length: 1] + PASS([AUTORELEASE([[NSMutableString alloc] initWithCharacters: &u1 length: 1]) isKindOfClass: [NSMutableString class]], "initWithCharacters:length: creates mutable string for unicode"); @@ -101,7 +101,7 @@ int main() appendString: @"bar"];, "can append to string from NSMutableString +stringWithString:"); - testObj = [@"hello" mutableCopy]; + testObj = AUTORELEASE([@"hello" mutableCopy]); [testObj replaceCharactersInRange: NSMakeRange(1,1) withString: @"a"]; PASS([testObj isEqual: @"hallo"], "replaceCharactersInRange:withString: works in middle of string"); @@ -179,7 +179,6 @@ int main() PASS_EQUAL(str, @"Text Message", "remove combining-tilde") } - [testObj release]; - [arp release]; arp = nil; + LEAVE_POOL return 0; } diff --git a/Tests/base/NSNotification/basic.m b/Tests/base/NSNotification/basic.m index c62e65acc..3e2fd64cc 100644 --- a/Tests/base/NSNotification/basic.m +++ b/Tests/base/NSNotification/basic.m @@ -22,10 +22,9 @@ int main() { - NSNotification *obj; - NSMutableArray *testObjs = [[NSMutableArray alloc] init]; - NSAutoreleasePool *arp = [NSAutoreleasePool new]; - + ENTER_POOL + NSNotification *obj; + NSMutableArray *testObjs = [NSMutableArray array]; NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys: @"obj", @"key", nil]; NSNotification *o1 = [NSNotification notificationWithName: @"hello" @@ -34,18 +33,19 @@ int main() NSNotification *o2 = [NSNotification notificationWithName: @"hello" object: @"there" userInfo: info]; + PASS([o1 hash] == [o2 hash], "equal notification hashes") PASS_EQUAL(o1, o2, "equal notifications") test_alloc(@"NSNotification"); - obj = [NSNotification new]; + obj = AUTORELEASE([NSNotification new]); [testObjs addObject: obj]; test_NSObject(@"NSNotification", testObjs); test_NSCoding(testObjs); test_keyed_NSCoding(testObjs); test_NSCopying(@"NSNotification",@"NSNotification",testObjs,NO,NO); - [arp release]; arp = nil; + LEAVE_POOL return 0; } diff --git a/Tests/base/NSNotification/dynamic.m b/Tests/base/NSNotification/dynamic.m index b5f5e829d..95c33f3f4 100644 --- a/Tests/base/NSNotification/dynamic.m +++ b/Tests/base/NSNotification/dynamic.m @@ -20,18 +20,18 @@ static BOOL notifiedCurrent = NO; int main(void) { + ENTER_POOL NSNotificationCenter *nc; - id t = [Toggle new]; + id t = AUTORELEASE([Toggle new]); - [NSAutoreleasePool new]; - nc = [NSNotificationCenter new]; + nc = AUTORELEASE([NSNotificationCenter new]); [nc addObserver: t selector: @selector(foo:) name: nil object: nil]; class_replaceMethod([Toggle class], @selector(foo:), class_getMethodImplementation([Toggle class], @selector(bar:)), "v@:@"); [nc postNotificationName: @"foo" object: t]; - [t release]; PASS(YES == notifiedCurrent, "implementation not cached"); + LEAVE_POOL return 0; }