mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
import testsuite
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32187 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
48cc36811f
commit
b179b29898
374 changed files with 20864 additions and 0 deletions
69
Tests/base/NSException/basic.m
Normal file
69
Tests/base/NSException/basic.m
Normal file
|
@ -0,0 +1,69 @@
|
|||
#import <Foundation/NSException.h>
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import "ObjectTesting.h"
|
||||
|
||||
static void
|
||||
handler(NSException *e)
|
||||
{
|
||||
PASS (YES == [[e reason] isEqual: @"Terminate"],
|
||||
"uncaught exceptionhandler called as expected");
|
||||
abort();
|
||||
}
|
||||
|
||||
@interface MyClass : NSObject
|
||||
+ (void) testAbc;
|
||||
@end
|
||||
@implementation MyClass
|
||||
+ (void) testAbc
|
||||
{
|
||||
[NSException raise: NSGenericException format: @"In MyClass"];
|
||||
}
|
||||
@end
|
||||
|
||||
int main()
|
||||
{
|
||||
NSException *obj;
|
||||
NSMutableArray *testObjs = [[NSMutableArray alloc] init];
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
|
||||
test_alloc_only(@"NSException");
|
||||
obj = [NSException exceptionWithName: NSGenericException
|
||||
reason: nil
|
||||
userInfo: nil];
|
||||
PASS((obj != nil), "can create an exception");
|
||||
PASS(([[obj name] isEqualToString: NSGenericException]), "name works");
|
||||
obj = [NSException exceptionWithName: NSGenericException
|
||||
reason: nil
|
||||
userInfo: nil];
|
||||
[testObjs addObject: obj];
|
||||
test_NSObject(@"NSException", testObjs);
|
||||
|
||||
NS_DURING
|
||||
[MyClass testAbc];
|
||||
NS_HANDLER
|
||||
{
|
||||
NSArray *a = [localException callStackSymbols];
|
||||
NSEnumerator *e = [a objectEnumerator];
|
||||
NSString *s = nil;
|
||||
|
||||
while ((s = [e nextObject]) != nil)
|
||||
if ([s rangeOfString: @"testAbc"].length > 0)
|
||||
break;
|
||||
testHopeful = YES;
|
||||
PASS(s != nil, "working callStackSymbols ... if this has failed it is probably due to a lack of support for objective-c method names (local symbols) in the backtrace_symbols() function of your libc. If so, you might lobby your operating system provider for a fix.");
|
||||
testHopeful = NO;
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
|
||||
PASS(NSGetUncaughtExceptionHandler() == 0, "default handler is null");
|
||||
NSSetUncaughtExceptionHandler(handler);
|
||||
PASS(NSGetUncaughtExceptionHandler() == handler, "setting handler works");
|
||||
|
||||
fprintf(stderr, "We expect a single FAIL without any explanation as\n"
|
||||
"the test is terminated by an uncaught exception ...\n");
|
||||
[NSException raise: NSGenericException format: @"Terminate"];
|
||||
PASS(NO, "shouldn't get here ... exception should have terminated process");
|
||||
|
||||
[arp release]; arp = nil;
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue