libs-base/Tests/base/NSAutoreleasePool/autorelease_eh.m
Fred Kiefer 6ebcdc0883 Use raise instead of @throw.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@35108 72102866-910b-0410-8b05-ffd578937521
2012-04-23 20:24:32 +00:00

50 lines
1.3 KiB
Objective-C

#import "ObjectTesting.h"
#import <Foundation/Foundation.h>
#import <Foundation/NSException.h>
@interface TestClass : NSObject
- (void)runTest;
- (void)exceptionThrowingMethod;
@end
@implementation TestClass
- (void)runTest
{
int c = 0;
int i;
for (i = 0; i < 10; i++)
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NS_DURING
[self exceptionThrowingMethod];
NS_HANDLER
c++;
NS_ENDHANDLER
[pool release];
}
PASS(c == 10, "Caught the correct number of exceptions without breaking the autorelease pool\n");
}
- (void)exceptionThrowingMethod
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
[@"Hello" stringByAppendingString: @" something to create a autoreleased object"];
NSLog(@"Throwing an exception");
[[NSException exceptionWithName: @"MyFunException" reason: @"it was always meant to happen" userInfo: [NSDictionary dictionary]] raise];
[pool release]; // Obviously this doesn't get run, but the [NSAutorelease new] at the top causes the problem
}
@end
int main(int argc, char** argv)
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
TestClass *testClass = [[TestClass new] autorelease];
[testClass runTest];
[pool release];
PASS(1, "Destroying pools in the wrong order didn't break anything...");
return 0;
}