Merge from mainline (163495:164578).
[official-gcc/graphite-test-results.git] / gcc / testsuite / objc / execute / exceptions / matcher-1.m
blobef0b627dab49b6fedf472a4c231c430c8383f7bd
1 /* Test custom exception matchers  */
2 /* Author: Nicola Pero */
4 #ifdef __NEXT_RUNTIME__
5 /* This test only runs for the GNU runtime.  TODO: It should work on
6    the NEXT runtime as well (needs testing).
7  */
9 int main(void)
11   return 0;
14 #else
16 #include <objc/objc-api.h>
17 #include <objc/objc-exception.h>
18 #include <objc/Object.h>
19 #include <stdlib.h>
21 static unsigned int handlerExpected = 0;
23 void
24 my_exception_matcher(Class match_class, id exception)
26   /* Always matches.  */
27   return 1;
30 @interface A : Object
31 @end
33 @implementation A
34 @end
36 @interface B : Object
37 @end
39 @implementation B
40 @end
42 int 
43 main(int argc, char *argv[])
45   objc_setExceptionMatcher (my_exception_matcher);
47   @try
48     {
49       @throw [A new];
50     }
51   @catch (B *exception)
52     {
53       /* Since we installed an exception matcher that always matches,
54          the exception should be sent here even if it's of class A and
55          this is looking for exceptions of class B.
56        */
57       return 0;
58     }
59   @catch (id exception)
60     {
61       abort ();
62     }
64   abort ();
68 #endif