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
|
|
|
|
{
|
|
|
|
freed = YES;
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
|
|
|
NSObject *o = [NSObject new];
|
2012-04-06 22:27:55 +00:00
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < 1000; i++)
|
2012-04-06 12:02:59 +00:00
|
|
|
{
|
2012-04-06 22:27:55 +00:00
|
|
|
[[o retain] autorelease];
|
2012-04-06 12:02:59 +00:00
|
|
|
}
|
|
|
|
NSUInteger totalCount = [arp autoreleaseCount];
|
|
|
|
PASS(totalCount == 1000, "Autorelease count is correct");
|
|
|
|
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;
|
|
|
|
}
|