-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds ARC and ObjC++ variants of ExceptionTest.
- Loading branch information
Showing
4 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#include "Test.h" | ||
|
||
BOOL finallyEntered = NO; | ||
BOOL cleanupRun = NO; | ||
BOOL idRethrown = NO; | ||
BOOL catchallRethrown = NO; | ||
BOOL testCaught = NO; | ||
BOOL wrongMatch = NO; | ||
|
||
@interface NSString : Test @end | ||
void runCleanup(void *x) | ||
{ | ||
assert(cleanupRun == NO); | ||
cleanupRun = YES; | ||
} | ||
|
||
int throwException(void) | ||
{ | ||
@throw [Test new]; | ||
} | ||
|
||
int finally(void) | ||
{ | ||
__attribute__((cleanup(runCleanup))) | ||
int x; | ||
(void)x; | ||
@try { throwException(); } | ||
@finally { finallyEntered = YES; } | ||
return 0; | ||
} | ||
int rethrow_id(void) | ||
{ | ||
@try { finally(); } | ||
@catch(id x) | ||
{ | ||
assert(object_getClass(x) == [Test class]); | ||
idRethrown = YES; | ||
@throw; | ||
} | ||
return 0; | ||
} | ||
int rethrow_test(void) | ||
{ | ||
@try { rethrow_id(); } | ||
@catch (Test *t) | ||
{ | ||
testCaught = YES; | ||
@throw; | ||
} | ||
@catch (id x) | ||
{ | ||
assert(0 && "should not be reached!"); | ||
} | ||
@catch (...) | ||
{ | ||
assert(0 && "should not be reached!"); | ||
} | ||
} | ||
int rethrow_catchall(void) | ||
{ | ||
@try { rethrow_test(); } | ||
@catch(...) | ||
{ | ||
assert(testCaught); | ||
catchallRethrown = YES; | ||
@throw; | ||
} | ||
return 0; | ||
} | ||
int not_matched_catch(void) | ||
{ | ||
@try { rethrow_catchall(); } | ||
@catch(NSString *s) | ||
{ | ||
wrongMatch = YES; | ||
} | ||
return 0; | ||
} | ||
|
||
int main(void) | ||
{ | ||
@try | ||
{ | ||
rethrow_catchall(); | ||
} | ||
@catch (id x) | ||
{ | ||
assert(finallyEntered == YES); | ||
assert(cleanupRun == YES); | ||
assert(idRethrown == YES); | ||
assert(catchallRethrown == YES); | ||
assert(wrongMatch == NO); | ||
assert(object_getClass(x) == [Test class]); | ||
[x dealloc]; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include "Test.h" | ||
|
||
BOOL finallyEntered = NO; | ||
BOOL cleanupRun = NO; | ||
BOOL idRethrown = NO; | ||
BOOL catchallRethrown = NO; | ||
BOOL testCaught = NO; | ||
BOOL wrongMatch = NO; | ||
|
||
@interface NSString : Test @end | ||
void runCleanup(void *x) | ||
{ | ||
assert(cleanupRun == NO); | ||
cleanupRun = YES; | ||
} | ||
|
||
int throwException(void) | ||
{ | ||
@throw [Test new]; | ||
} | ||
|
||
int finally(void) | ||
{ | ||
__attribute__((cleanup(runCleanup))) | ||
int x; | ||
(void)x; | ||
@try { throwException(); } | ||
@finally { finallyEntered = YES; } | ||
return 0; | ||
} | ||
int rethrow_id(void) | ||
{ | ||
@try { finally(); } | ||
@catch(id x) | ||
{ | ||
assert(object_getClass(x) == [Test class]); | ||
idRethrown = YES; | ||
@throw; | ||
} | ||
return 0; | ||
} | ||
int rethrow_test(void) | ||
{ | ||
@try { rethrow_id(); } | ||
@catch (Test *t) | ||
{ | ||
testCaught = YES; | ||
@throw; | ||
} | ||
@catch (id x) | ||
{ | ||
assert(0 && "should not be reached!"); | ||
} | ||
@catch (...) | ||
{ | ||
assert(0 && "should not be reached!"); | ||
} | ||
} | ||
int rethrow_catchall(void) | ||
{ | ||
@try { rethrow_test(); } | ||
@catch(...) | ||
{ | ||
assert(testCaught); | ||
catchallRethrown = YES; | ||
@throw; | ||
} | ||
return 0; | ||
} | ||
int not_matched_catch(void) | ||
{ | ||
@try { rethrow_catchall(); } | ||
@catch(NSString *s) | ||
{ | ||
wrongMatch = YES; | ||
} | ||
return 0; | ||
} | ||
|
||
int main(void) | ||
{ | ||
@try | ||
{ | ||
rethrow_catchall(); | ||
} | ||
@catch (id x) | ||
{ | ||
assert(finallyEntered == YES); | ||
assert(cleanupRun == YES); | ||
assert(idRethrown == YES); | ||
assert(catchallRethrown == YES); | ||
assert(wrongMatch == NO); | ||
assert(object_getClass(x) == [Test class]); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#include "Test.h" | ||
|
||
#if __cplusplus | ||
#error This is not an ObjC++ test! | ||
#endif | ||
|
||
BOOL finallyEntered = NO; | ||
BOOL cleanupRun = NO; | ||
BOOL idRethrown = NO; | ||
BOOL catchallRethrown = NO; | ||
BOOL testCaught = NO; | ||
BOOL wrongMatch = NO; | ||
|
||
@interface NSString : Test @end | ||
void runCleanup(void *x) | ||
{ | ||
assert(cleanupRun == NO); | ||
cleanupRun = YES; | ||
} | ||
|
||
int throw(void) | ||
{ | ||
@throw [Test new]; | ||
} | ||
|
||
int finally(void) | ||
{ | ||
__attribute__((cleanup(runCleanup))) | ||
int x; | ||
(void)x; | ||
@try { throw(); } | ||
@finally { finallyEntered = YES; } | ||
return 0; | ||
} | ||
int rethrow_id(void) | ||
{ | ||
@try { finally(); } | ||
@catch(id x) | ||
{ | ||
assert(object_getClass(x) == [Test class]); | ||
idRethrown = YES; | ||
@throw; | ||
} | ||
return 0; | ||
} | ||
int rethrow_test(void) | ||
{ | ||
@try { rethrow_id(); } | ||
@catch (Test *t) | ||
{ | ||
testCaught = YES; | ||
@throw; | ||
} | ||
@catch (id x) | ||
{ | ||
assert(0 && "should not be reached!"); | ||
} | ||
@catch (...) | ||
{ | ||
assert(0 && "should not be reached!"); | ||
} | ||
} | ||
int rethrow_catchall(void) | ||
{ | ||
@try { rethrow_test(); } | ||
@catch(...) | ||
{ | ||
assert(testCaught); | ||
catchallRethrown = YES; | ||
@throw; | ||
} | ||
return 0; | ||
} | ||
int not_matched_catch(void) | ||
{ | ||
@try { rethrow_catchall(); } | ||
@catch(NSString *s) | ||
{ | ||
wrongMatch = YES; | ||
} | ||
return 0; | ||
} | ||
|
||
int main(void) | ||
{ | ||
@try | ||
{ | ||
rethrow_catchall(); | ||
} | ||
@catch (id x) | ||
{ | ||
assert(finallyEntered == YES); | ||
assert(cleanupRun == YES); | ||
assert(idRethrown == YES); | ||
assert(catchallRethrown == YES); | ||
assert(wrongMatch == NO); | ||
assert(object_getClass(x) == [Test class]); | ||
} | ||
return 0; | ||
} |