aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicola Pero <nicola.pero@meta-innovation.com>2010-09-08 21:03:51 +0000
committerNicola Pero <nicola@gcc.gnu.org>2010-09-08 21:03:51 +0000
commit2023bba815a1d056a3f64aea988f0c24c3e4c15a (patch)
tree3994ea47b1c04b5f4eedb31f041cb25fb0984022
parente30511ed4b4e31f800fa1ff212006df2740bd410 (diff)
downloadgcc-2023bba815a1d056a3f64aea988f0c24c3e4c15a.zip
gcc-2023bba815a1d056a3f64aea988f0c24c3e4c15a.tar.gz
gcc-2023bba815a1d056a3f64aea988f0c24c3e4c15a.tar.bz2
throw-nil.m: New test.
* objc/execute/exceptions/throw-nil.m: New test. * objc/execute/exceptions/handler-1.m: Updated to use the new objc_set_uncaught_exception_handler() function. * objc/execute/exceptions/matcher-1.m: New test. From-SVN: r164024
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/objc/execute/exceptions/handler-1.m8
-rw-r--r--gcc/testsuite/objc/execute/exceptions/matcher-1.m68
-rw-r--r--gcc/testsuite/objc/execute/exceptions/throw-nil.m38
4 files changed, 118 insertions, 3 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 8c649a2..5e014b1 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,10 @@
+2010-09-08 Nicola Pero <nicola.pero@meta-innovation.com>
+
+ * objc/execute/exceptions/throw-nil.m: New test.
+ * objc/execute/exceptions/handler-1.m: Updated to use the new
+ objc_set_uncaught_exception_handler() function.
+ * objc/execute/exceptions/matcher-1.m: New test.
+
2010-09-08 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
PR fortran/38282
diff --git a/gcc/testsuite/objc/execute/exceptions/handler-1.m b/gcc/testsuite/objc/execute/exceptions/handler-1.m
index 684a831..ab2fe8c 100644
--- a/gcc/testsuite/objc/execute/exceptions/handler-1.m
+++ b/gcc/testsuite/objc/execute/exceptions/handler-1.m
@@ -2,7 +2,9 @@
/* Author: David Ayers */
#ifdef __NEXT_RUNTIME__
-/* This test only runs for the GNU runtime. */
+/* This test only runs for the GNU runtime. TODO: It should work on
+ the NEXT runtime as well (needs testing).
+ */
int main(void)
{
@@ -12,8 +14,8 @@ int main(void)
#else
#include <objc/objc-api.h>
+#include <objc/objc-exception.h>
#include <objc/Object.h>
-#include <stdio.h>
#include <stdlib.h>
static unsigned int handlerExpected = 0;
@@ -31,7 +33,7 @@ my_exception_handler(id excp)
int
main(int argc, char *argv[])
{
- _objc_unexpected_exception = my_exception_handler;
+ objc_setUncaughtExceptionHandler (my_exception_handler);
@try
{
diff --git a/gcc/testsuite/objc/execute/exceptions/matcher-1.m b/gcc/testsuite/objc/execute/exceptions/matcher-1.m
new file mode 100644
index 0000000..ef0b627
--- /dev/null
+++ b/gcc/testsuite/objc/execute/exceptions/matcher-1.m
@@ -0,0 +1,68 @@
+/* Test custom exception matchers */
+/* Author: Nicola Pero */
+
+#ifdef __NEXT_RUNTIME__
+/* This test only runs for the GNU runtime. TODO: It should work on
+ the NEXT runtime as well (needs testing).
+ */
+
+int main(void)
+{
+ return 0;
+}
+
+#else
+
+#include <objc/objc-api.h>
+#include <objc/objc-exception.h>
+#include <objc/Object.h>
+#include <stdlib.h>
+
+static unsigned int handlerExpected = 0;
+
+void
+my_exception_matcher(Class match_class, id exception)
+{
+ /* Always matches. */
+ return 1;
+}
+
+@interface A : Object
+@end
+
+@implementation A
+@end
+
+@interface B : Object
+@end
+
+@implementation B
+@end
+
+int
+main(int argc, char *argv[])
+{
+ objc_setExceptionMatcher (my_exception_matcher);
+
+ @try
+ {
+ @throw [A new];
+ }
+ @catch (B *exception)
+ {
+ /* Since we installed an exception matcher that always matches,
+ the exception should be sent here even if it's of class A and
+ this is looking for exceptions of class B.
+ */
+ return 0;
+ }
+ @catch (id exception)
+ {
+ abort ();
+ }
+
+ abort ();
+}
+
+
+#endif
diff --git a/gcc/testsuite/objc/execute/exceptions/throw-nil.m b/gcc/testsuite/objc/execute/exceptions/throw-nil.m
new file mode 100644
index 0000000..3092d14
--- /dev/null
+++ b/gcc/testsuite/objc/execute/exceptions/throw-nil.m
@@ -0,0 +1,38 @@
+#include <objc/objc.h>
+#include <objc/Object.h>
+
+/* Test throwing a nil exception. A 'nil' exception can only be
+ * caugth by a generic exception handler.
+ */
+
+int main (void)
+{
+ int exception_catched = 0;
+ int finally_called = 0;
+
+ @try
+ {
+ @throw nil;
+ }
+ @catch (Object *exc)
+ {
+ abort ();
+ }
+ @catch (id exc)
+ {
+ exception_catched = 1;
+ }
+ @finally
+ {
+ finally_called = 1;
+ }
+
+
+ if (exception_catched != 1
+ || finally_called != 1)
+ {
+ abort ();
+ }
+
+ return 0;
+}