More leaks fixed

This commit is contained in:
rfm 2024-11-16 13:34:56 +00:00
parent 87c50830e2
commit aedd13dc94
19 changed files with 174 additions and 153 deletions

View file

@ -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)];