mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +00:00
Fix some more leaks
This commit is contained in:
parent
9573539795
commit
87c50830e2
5 changed files with 78 additions and 66 deletions
|
@ -4,13 +4,14 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSDictionary *dict;
|
||||
NSArray *cookies;
|
||||
NSURL *url;
|
||||
NSHTTPCookie *cookie;
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSDictionary *dict;
|
||||
NSArray *cookies;
|
||||
NSURL *url;
|
||||
NSHTTPCookie *cookie;
|
||||
|
||||
TEST_FOR_CLASS(@"NSHTTPCookie", [NSHTTPCookie alloc],
|
||||
cookie = AUTORELEASE([NSHTTPCookie new]);
|
||||
TEST_FOR_CLASS(@"NSHTTPCookie", cookie,
|
||||
"NSHTTPCookie +alloc returns an NSHTTPCookie");
|
||||
|
||||
dict = [NSDictionary dictionaryWithObjectsAndKeys: @"myname", @"Name",
|
||||
|
|
|
@ -103,10 +103,10 @@
|
|||
@end
|
||||
|
||||
@implementation TestKVOChange
|
||||
+ (id)changeWithKeypath:(NSString *)keypath
|
||||
object:(id)object
|
||||
info:(NSDictionary *)info
|
||||
context:(void *)context
|
||||
+ (id) changeWithKeypath: (NSString *)keypath
|
||||
object: (id)object
|
||||
info: (NSDictionary *)info
|
||||
context: (void *)context
|
||||
{
|
||||
TestKVOChange *change = [[[self alloc] init] autorelease];
|
||||
[change setKeypath: keypath];
|
||||
|
@ -116,55 +116,60 @@
|
|||
return change;
|
||||
}
|
||||
|
||||
- (NSString *)keypath {
|
||||
return _keypath;
|
||||
- (NSString *) keypath
|
||||
{
|
||||
return _keypath;
|
||||
}
|
||||
|
||||
- (void)setKeypath:(NSString *)newKeypath
|
||||
- (void) setKeypath: (NSString *)newKeypath
|
||||
{
|
||||
if (_keypath != newKeypath)
|
||||
if (_keypath != newKeypath)
|
||||
{
|
||||
[_keypath release];
|
||||
_keypath = [newKeypath copy];
|
||||
[_keypath release];
|
||||
_keypath = [newKeypath copy];
|
||||
}
|
||||
}
|
||||
|
||||
- (id)object
|
||||
- (id) object
|
||||
{
|
||||
return _object;
|
||||
return _object;
|
||||
}
|
||||
|
||||
- (void)setObject:(id)newObject
|
||||
- (void) setObject: (id)newObject
|
||||
{
|
||||
ASSIGN(_object, newObject);
|
||||
}
|
||||
|
||||
- (NSDictionary *)info
|
||||
{
|
||||
return _info;
|
||||
return _info;
|
||||
}
|
||||
|
||||
- (void)setInfo:(NSDictionary *)newInfo
|
||||
- (void) setInfo: (NSDictionary *)newInfo
|
||||
{
|
||||
ASSIGN(_info, [newInfo copy]);
|
||||
if (newInfo != _info)
|
||||
{
|
||||
[_info release];
|
||||
_info = [newInfo copy];
|
||||
}
|
||||
}
|
||||
|
||||
- (void *)context
|
||||
- (void *) context
|
||||
{
|
||||
return _context;
|
||||
return _context;
|
||||
}
|
||||
|
||||
- (void)setContext:(void *)newContext
|
||||
- (void) setContext:(void *)newContext
|
||||
{
|
||||
_context = newContext;
|
||||
_context = newContext;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
- (void) dealloc
|
||||
{
|
||||
[_object release];
|
||||
[_keypath release];
|
||||
[_info release];
|
||||
[super dealloc];
|
||||
[_object release];
|
||||
[_keypath release];
|
||||
[_info release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -216,7 +221,7 @@
|
|||
[_lock lock];
|
||||
NSSet *paths = [[_changedKeypaths objectForKey:keypath] copy];
|
||||
[_lock unlock];
|
||||
return paths;
|
||||
return AUTORELEASE(paths);
|
||||
}
|
||||
- (void)clear
|
||||
{
|
||||
|
|
|
@ -3,10 +3,15 @@
|
|||
int main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
|
||||
test_alloc_only(@"NSKeyedArchiver");
|
||||
test_NSObject(@"NSKeyedArchiver",[NSArray arrayWithObject:[[NSKeyedArchiver alloc] initForWritingWithMutableData: [NSMutableData data]]]);
|
||||
test_NSObject(@"NSKeyedArchiver", [NSArray arrayWithObject:
|
||||
AUTORELEASE([[NSKeyedArchiver alloc] initForWritingWithMutableData:
|
||||
[NSMutableData data]])]);
|
||||
test_alloc_only(@"NSKeyedUnarchiver");
|
||||
test_NSObject(@"NSKeyedUnarchiver",[NSArray arrayWithObject:[[NSKeyedUnarchiver alloc] initForReadingWithData: [NSKeyedArchiver archivedDataWithRootObject: [NSData data]]]]);
|
||||
test_NSObject(@"NSKeyedUnarchiver", [NSArray arrayWithObject:
|
||||
AUTORELEASE([[NSKeyedUnarchiver alloc] initForReadingWithData:
|
||||
[NSKeyedArchiver archivedDataWithRootObject: [NSData data]]])]);
|
||||
|
||||
[arp release]; arp = nil;
|
||||
return 0;
|
||||
|
|
|
@ -7,18 +7,20 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
id obj;
|
||||
NSMutableData *data1;
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
id obj;
|
||||
NSMutableData *data1;
|
||||
|
||||
obj = [NSKeyedArchiver alloc];
|
||||
data1 = [NSMutableData dataWithLength: 0];
|
||||
obj = [obj initForWritingWithMutableData: data1];
|
||||
PASS((obj != nil && [obj isKindOfClass:[NSKeyedArchiver class]]), "-initForWritingWithMutableData seems ok");
|
||||
obj = AUTORELEASE([[NSKeyedArchiver alloc]
|
||||
initForWritingWithMutableData: data1]);
|
||||
PASS((obj != nil && [obj isKindOfClass: [NSKeyedArchiver class]]),
|
||||
"-initForWritingWithMutableData seems ok")
|
||||
|
||||
PASS_EXCEPTION([[NSUnarchiver alloc] initForReadingWithData:nil];,
|
||||
@"NSInvalidArgumentException",
|
||||
"Creating an NSUnarchiver with nil data throws an exception");
|
||||
PASS_EXCEPTION(AUTORELEASE([[NSUnarchiver alloc]
|
||||
initForReadingWithData: nil]);,
|
||||
@"NSInvalidArgumentException",
|
||||
"Creating an NSUnarchiver with nil data throws an exception")
|
||||
|
||||
[arp release]; arp = nil;
|
||||
return 0;
|
||||
|
|
|
@ -27,8 +27,9 @@ int main()
|
|||
u = [NSURL URLWithString: @"http://www.w3.org/"];
|
||||
ms = [NSMutableSet set];
|
||||
[ms addObject: u];
|
||||
data2 = [NSMutableData new];
|
||||
archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData: data2];
|
||||
data2 = [NSMutableData data];
|
||||
archiver = AUTORELEASE([[NSKeyedArchiver alloc]
|
||||
initForWritingWithMutableData: data2]);
|
||||
[archiver setOutputFormat: NSPropertyListXMLFormat_v1_0];
|
||||
[archiver encodeObject: ms forKey: @"root"];
|
||||
[archiver finishEncoding];
|
||||
|
@ -38,28 +39,25 @@ int main()
|
|||
PASS([[[ms anyObject] absoluteString] isEqual: @"http://www.w3.org/"],
|
||||
"Can archive and restore a URL");
|
||||
|
||||
[archiver release];
|
||||
[data2 release];
|
||||
|
||||
|
||||
PASS_RUNS(val1 = [NSString stringWithCString:"Archiver.dat"];
|
||||
val2 = [NSString stringWithCString:"A Goodbye"];
|
||||
val3 = [NSString stringWithCString:"Testing all strings"];
|
||||
val4 = [NSNumber numberWithUnsignedInt: 100];
|
||||
vals1 = [[[NSArray arrayWithObject:val1]
|
||||
arrayByAddingObject:val2]
|
||||
arrayByAddingObject: val4];
|
||||
vals2 = [vals1 arrayByAddingObject: val2];,
|
||||
"We can build basic strings and arrays for tests");
|
||||
PASS_RUNS(
|
||||
val1 = [NSString stringWithCString:"Archiver.dat"];
|
||||
val2 = [NSString stringWithCString:"A Goodbye"];
|
||||
val3 = [NSString stringWithCString:"Testing all strings"];
|
||||
val4 = [NSNumber numberWithUnsignedInt: 100];
|
||||
vals1 = [[[NSArray arrayWithObject: val1]
|
||||
arrayByAddingObject: val2]
|
||||
arrayByAddingObject: val4];
|
||||
vals2 = [vals1 arrayByAddingObject: val2];,
|
||||
"We can build basic strings and arrays for tests")
|
||||
|
||||
PASS([NSKeyedArchiver archiveRootObject:vals2 toFile:val1],
|
||||
PASS([NSKeyedArchiver archiveRootObject: vals2 toFile: val1],
|
||||
"archiveRootObject:toFile: seems ok");
|
||||
|
||||
data1 = [NSKeyedArchiver archivedDataWithRootObject:vals2];
|
||||
data1 = [NSKeyedArchiver archivedDataWithRootObject: vals2];
|
||||
PASS((data1 != nil && [data1 length] != 0),
|
||||
"archivedDataWithRootObject: seems ok");
|
||||
|
||||
a = [NSKeyedUnarchiver unarchiveObjectWithData:data1];
|
||||
a = [NSKeyedUnarchiver unarchiveObjectWithData: data1];
|
||||
NSLog(@"From data: original array %@, decoded array %@",vals2, a);
|
||||
PASS((a != nil && [a isKindOfClass:[NSArray class]] && [a isEqual:vals2]),
|
||||
"unarchiveObjectWithData: seems ok");
|
||||
|
@ -70,17 +68,18 @@ int main()
|
|||
"unarchiveObjectWithFile: seems ok");
|
||||
|
||||
// encode
|
||||
data2 = [[NSMutableData alloc] initWithCapacity: 10240];
|
||||
archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData: data2];
|
||||
data2 = [NSMutableData dataWithCapacity: 10240];
|
||||
archiver = AUTORELEASE([[NSKeyedArchiver alloc]
|
||||
initForWritingWithMutableData: data2]);
|
||||
[archiver encodeObject: val3 forKey: @"string"];
|
||||
[archiver finishEncoding];
|
||||
|
||||
// decode...
|
||||
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData: data2];
|
||||
s = [[unarchiver decodeObjectForKey: @"string"] retain];
|
||||
unarchiver = AUTORELEASE([[NSKeyedUnarchiver alloc]
|
||||
initForReadingWithData: data2]);
|
||||
s = [unarchiver decodeObjectForKey: @"string"];
|
||||
PASS((s != nil && [s isKindOfClass:[NSString class]] && [s isEqual: val3]),
|
||||
"encodeObject:forKey: seems okay");
|
||||
[data2 release];
|
||||
|
||||
NSLog(@"Original string: %@, unarchived string: %@",val3, s);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue