OSDN Git Service

* objc/execute/exceptions/exceptions.exp: New exp for the exceptions
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc / execute / exceptions / catchall-1.m
1 /* Test out '@catch(id foo) {...}', which should catch all uncaught
2    exceptions.  */
3 /* Developed by Ziemowit Laski <zlaski@apple.com>.  */
4
5 #include <objc/Object.h>
6 #include <stdio.h>
7
8 /* The following is not required in actual user code; we include it
9    here to check that the compiler generates an internal definition of
10    _setjmp that is consistent with what <setjmp.h> provides.  */
11 #include <setjmp.h>
12
13 extern void abort(void);
14 #define CHECK_IF(expr) if(!(expr)) abort()
15
16 @interface Frob: Object
17 @end
18
19 @implementation Frob: Object
20 @end
21
22 static Frob* _connection = nil;
23
24 //--------------------------------------------------------------------
25
26
27 void test (Object* sendPort)
28 {
29         int cleanupPorts = 1;
30         Frob* receivePort = nil;
31         
32         @try {
33                 printf ("receivePort = %p\n", receivePort);
34                 printf ("sendPort = %p\n", sendPort);
35                 printf ("cleanupPorts = %d\n", cleanupPorts);
36                 printf ("---\n");
37                 
38                 receivePort = (Frob *) -1;
39                 _connection = (Frob *) -1;
40                 printf ("receivePort = %p\n", receivePort);
41                 printf ("sendPort = %p\n", sendPort);
42                 printf ("cleanupPorts = %d\n", cleanupPorts);
43                 printf ("---\n");
44                 
45                 receivePort = nil;
46                 sendPort = nil;
47                 cleanupPorts = 0;
48                 
49                 printf ("receivePort = %p\n", receivePort);
50                 printf ("sendPort = %p\n", sendPort);
51                 printf ("cleanupPorts = %d\n", cleanupPorts);
52                 printf ("---\n");               
53                 
54                 @throw [Object new];
55         }
56         @catch(Frob *obj) {
57                 printf ("Exception caught by incorrect handler!\n");
58                 CHECK_IF(0);
59         }
60         @catch(id exc) {
61                 printf ("Exception caught by correct handler.\n");
62                 printf ("receivePort = %p (expected 0x0)\n", receivePort);
63                 printf ("sendPort = %p (expected 0x0)\n", sendPort);
64                 printf ("cleanupPorts = %d (expected 0)\n", cleanupPorts);
65                 printf ("---");
66                 CHECK_IF(!receivePort);
67                 CHECK_IF(!sendPort);
68                 CHECK_IF(!cleanupPorts);
69         }
70 }
71
72 int main (void) {
73
74         test((Object *)-1);
75         return 0;
76 }