git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32686 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2011-03-22 19:47:10 +00:00
parent ae273366e8
commit 603e2f2f08
4 changed files with 138 additions and 137 deletions

View file

@ -7,7 +7,7 @@ int main(void)
START_SET("String throwing")
SKIP("Unified exception model not supported")
END_SET("String throwing");
return 0;
return 0;
}
#else
@ -21,45 +21,46 @@ int main(void)
*/
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;
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

View file

@ -10,7 +10,7 @@ int main(void)
START_SET("String throwing")
SKIP("Unified exception model not supported")
END_SET("String throwing");
return 0;
return 0;
}
#else
@ -25,25 +25,25 @@ int final = 0;
void testThrow(void)
{
caughtObj = nil;
caughtStr = nil;
final = 0;
try
{
throw foo;
}
catch (NSString *f)
{
caughtStr = f;
}
catch (NSObject *o)
{
caughtObj = o;
}
catch(...)
{
final = 1;
}
caughtObj = nil;
caughtStr = nil;
final = 0;
try
{
throw foo;
}
catch (NSString *f)
{
caughtStr = f;
}
catch (NSObject *o)
{
caughtObj = o;
}
catch(...)
{
final = 1;
}
}
/**
* Tests whether C++ exception catching uses Objective-C semantics.
@ -54,18 +54,18 @@ void testThrow(void)
*/
int main(void)
{
testThrow();
pass(0==final, "catchall not used to catch object");
pass(caughtObj == nil, "Thrown string cast to NSObject matched NSObject (Apple mode)");
pass(caughtStr == foo, "Thrown string cast to NSObject matched NSString (Apple mode)");
testThrow();
PASS(0==final, "catchall not used to catch object");
PASS(caughtObj == nil, "Thrown string cast to NSObject matched NSObject (Apple mode)");
PASS(caughtStr == foo, "Thrown string cast to NSObject matched NSString (Apple mode)");
#ifdef OBJC_UNIFIED_EXCEPTION_MODEL
// Turn off Apple compatibility mode and try again
objc_set_apple_compatible_objcxx_exceptions(0);
testThrow();
pass(0==final, "catchall not used to catch object");
pass(caughtObj == foo, "Thrown string cast to NSObject matched NSObject (sane mode)");
pass(caughtStr == nil, "Thrown string cast to NSObject matched NSString (sane mode)");
// Turn off Apple compatibility mode and try again
objc_set_apple_compatible_objcxx_exceptions(0);
testThrow();
PASS(0==final, "catchall not used to catch object");
PASS(caughtObj == foo, "Thrown string cast to NSObject matched NSObject (sane mode)");
PASS(caughtStr == nil, "Thrown string cast to NSObject matched NSString (sane mode)");
#endif
return 0;
return 0;
}
#endif

View file

@ -7,7 +7,7 @@ int main(void)
START_SET("Unified exception model")
SKIP("Unified exception model not supported")
END_SET("Unified exception model")
return 0;
return 0;
}
#else
@ -24,29 +24,29 @@ int main(void)
*/
int main(void)
{
NSString *foo = @"foo";
id caught = nil;
int final = 0;
int wrongCatch = 0;
try
{
@throw foo;
}
catch (void *foo)
{
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;
NSString *foo = @"foo";
id caught = nil;
int final = 0;
int wrongCatch = 0;
try
{
@throw foo;
}
catch (void *foo)
{
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

View file

@ -10,66 +10,66 @@ static int B_destroyed;
class A
{
int b;
public:
A() : b(12)
{
pass(0 == A_init, "Constructor only called once");
pass(0 == B_init, "a constructor called before b constructor ");
A_init = 1;
};
~A()
{
pass(0 == A_destroyed, "Destructor only called once");
pass(1 == B_destroyed, "b destructor called before a destructor");
A_destroyed = 1;
};
int b;
public:
A() : b(12)
{
PASS(0 == A_init, "Constructor only called once");
PASS(0 == B_init, "a constructor called before b constructor ");
A_init = 1;
};
~A()
{
PASS(0 == A_destroyed, "Destructor only called once");
PASS(1 == B_destroyed, "b destructor called before a destructor");
A_destroyed = 1;
};
};
class A1
{
int b;
public:
A1() : b(12)
{
pass(1 == A_init, "a constructor called before b constructor ");
B_init = 1;
};
~A1()
{
pass(0 == A_destroyed, "b destructor called before a destructor");
B_destroyed = 1;
};
int b;
public:
A1() : b(12)
{
PASS(1 == A_init, "a constructor called before b constructor ");
B_init = 1;
};
~A1()
{
PASS(0 == A_destroyed, "b destructor called before a destructor");
B_destroyed = 1;
};
};
@interface B : NSObject
{
A a;
A a;
}
@end
@interface C : B
{
A1 b;
A1 b;
}
@end
@implementation B
- (id)init
- (id) init
{
pass(1 == A_init, "a constructor called before -init");
pass(1 == B_init, "b constructor called before -init");
pass(0 == A_destroyed, "a destructor not called before -init");
pass(0 == B_destroyed, "b destructor not called before -init");
return self;
PASS(1 == A_init, "a constructor called before -init");
PASS(1 == B_init, "b constructor called before -init");
PASS(0 == A_destroyed, "a destructor not called before -init");
PASS(0 == B_destroyed, "b destructor not called before -init");
return self;
}
@end
@implementation C @end
int main(void)
{
// Make sure constructors / destructors are called even without -init
[[C alloc] release];
// Reset state
A_init = B_init = A_destroyed = B_destroyed = 0;
// Check init is called in the middle
[[C new] release];
// Make sure constructors / destructors are called even without -init
[[C alloc] release];
// Reset state
A_init = B_init = A_destroyed = B_destroyed = 0;
// Check init is called in the middle
[[C new] release];
}