2012-04-06 12:02:59 +00:00
|
|
|
#import "ObjectTesting.h"
|
|
|
|
#import <Foundation/NSAutoreleasePool.h>
|
|
|
|
#import <Foundation/NSObject.h>
|
|
|
|
|
|
|
|
static BOOL freed;
|
|
|
|
@interface Test : NSObject @end
|
|
|
|
@implementation Test
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
2016-02-09 15:56:43 +00:00
|
|
|
freed = YES;
|
|
|
|
[super dealloc];
|
2012-04-06 12:02:59 +00:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2016-02-09 15:56:43 +00:00
|
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
|
|
|
NSObject *o = [NSObject new];
|
|
|
|
unsigned c;
|
|
|
|
unsigned i;
|
2012-04-06 22:27:55 +00:00
|
|
|
|
2016-02-09 15:56:43 +00:00
|
|
|
[[o retain] autorelease];
|
|
|
|
RELEASE(arp);
|
|
|
|
|
|
|
|
arp = [NSAutoreleasePool new];
|
|
|
|
c = [arp autoreleaseCount];
|
|
|
|
printf("Initial count %u\n", c);
|
2012-04-06 22:27:55 +00:00
|
|
|
for (i = 0; i < 1000; i++)
|
2016-02-09 15:56:43 +00:00
|
|
|
{
|
|
|
|
[[o retain] autorelease];
|
|
|
|
}
|
|
|
|
i = [arp autoreleaseCount];
|
|
|
|
printf("Final count %u\n", i);
|
|
|
|
NSCAssert(arp == [NSAutoreleasePool currentPool],
|
|
|
|
NSInternalInconsistencyException);
|
|
|
|
PASS(1000 == i - c, "Autorelease count is correct");
|
|
|
|
PASS([arp autoreleaseCountForObject: o] == 1000,
|
|
|
|
"Autorelease count for object is correct");
|
2012-04-06 12:02:59 +00:00
|
|
|
PASS([NSAutoreleasePool autoreleaseCountForObject: o] == 1000,
|
|
|
|
"Autorelease count for object is correct");
|
|
|
|
PASS(freed == NO, "Object not prematurely freed");
|
|
|
|
[arp release];
|
|
|
|
arp = [NSAutoreleasePool new];
|
|
|
|
[o release];
|
|
|
|
PASS(freed == NO, "Object freed by autoreleasing");
|
|
|
|
[arp release];
|
|
|
|
return 0;
|
|
|
|
}
|