Merged r157653 through r157895 into branch.
[official-gcc.git] / gcc / testsuite / objc / execute / forward-1.m
blobc20f8c4934f795d91b22c6924ff6718359bde3f2
1 /* See if -forward::/-performv:: is able to work. */
3 #include <stdio.h>
4 #include <stdlib.h>
6 #import "../../objc-obj-c++-shared/Object1.h"
7 #import "../../objc-obj-c++-shared/next-mapping.h"
8 #include <objc/objc-api.h>
10 #define VALUETOUSE 1234567890
12 id forwarder, receiver;
14 @interface Forwarder: Object
16     id receiver;
19 -initWithReceiver:theReceiver;
21 @end
23 @interface Receiver:Object
25     int foo;
27 -display;
28 -initWithFoo:(int)theFoo;
29 @end
30 @implementation Receiver
32 -initWithFoo: (int)theFoo
34     foo = theFoo;
35     return self;
38 -display
40     /* Check to see if we are really the reciever. */
41     if (self != receiver)
42         abort ();
43     /* And the value of foo is set correctly. */
44     if (foo != VALUETOUSE)
45       abort ();
46     return self;
49 @end
51 @implementation Forwarder
52 -initWithReceiver: theReceiver
54     [super init];
55     receiver = theReceiver;
56     return self;
58 #ifdef NEXT_OBJC_USE_NEW_INTERFACE
59 - forward: (SEL)theSel: (marg_list)theArgFrame
61 #else
62 -(retval_t) forward: (SEL)theSel: (arglist_t)theArgFrame
64 #endif
65   /* If we have a reciever try to perform on that object */
66     if (receiver)
67         return [receiver performv: theSel: theArgFrame];
68     return [self doesNotRecognize:theSel];
70 @end
71 int main()
73     /* Init the reciever. */
74     receiver = [[Receiver alloc] initWithFoo: VALUETOUSE];
75     /* Init the fowarder. */
76     forwarder = [[Forwarder alloc] initWithReceiver: receiver];
77     /* Call display on the forwarder which in turns calls display on
78        the reciever. */
79     [forwarder display];
80     exit(0);