Added test for Apple-compatible unified exception model.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32661 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
David Chisnall 2011-03-20 22:06:44 +00:00
parent 9d6a3d4d42
commit dbc38567b6

View file

@ -0,0 +1,65 @@
#import <ObjectTesting.h>
#import <Foundation/NSObject.h>
#if !__has_feature(objc_nonfragile_abi)
int main(void)
{
START_SET("String throwing")
SKIP("Unified exception model not supported")
END_SET("String throwing");
return 0;
}
#else
/**
* Tests throwing an exception with the C++ exception throwing mechanism and
* catching it with the Objective-C exception handling mechanism. This
* behaviour is required for compatibility with Apple's new exception model.
* The converse should also work - throwing an object with @throw and catching
* it with catch().
*/
int main(void)
{
NSString *foo = @"foo";
id caught = nil;
int final = 0;
int wrongCatch = 0;
@try
{
throw foo;
}
@catch(NSString *f)
{
caught = f;
}
@finally
{
final = 1;
}
pass(caught == foo, "Unified exception model works correctly");
pass(1==final, "@finally works in ObjC++");
final = 0;
caught = nil;
try
{
@throw foo;
}
catch (NSArray *a)
{
wrongCatch = 1;
}
catch (NSString *f)
{
caught = f;
}
catch(...)
{
final = 1;
}
pass(0==final, "catchall not used to catch object");
pass(0==wrongCatch, "Incorrect object catch not used to catch object");
pass(caught == foo, "Unified exception model works correctly");
return 0;
}
#endif