]>
Commit | Line | Data |
---|---|---|
e2673f71 IS |
1 | /* test access in methods, auto-generated getter/setter based on property name. */ |
2 | /* { dg-do run } */ | |
5b4db3f5 | 3 | /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ |
e2673f71 IS |
4 | |
5 | extern int printf (char *fmt,...) ; | |
6 | extern void abort (void); | |
7 | ||
46a88c12 NP |
8 | #include <objc/objc.h> |
9 | #include <objc/runtime.h> | |
e2673f71 IS |
10 | |
11 | @interface Bar | |
12 | { | |
13 | @public | |
e2673f71 | 14 | Class isa; |
46a88c12 | 15 | int FooBar; |
e2673f71 IS |
16 | } |
17 | + (id) initialize; | |
18 | + (id) alloc ; | |
19 | - (id) init; | |
20 | ||
21 | - (int) lookAtProperty; | |
22 | - (void) setProperty: (int) v; | |
23 | ||
24 | @property int FooBar; | |
25 | @end | |
26 | ||
27 | @implementation Bar | |
28 | ||
29 | +initialize { return self;} | |
46a88c12 | 30 | + (id) alloc { return class_createInstance(self, 0);} |
e2673f71 IS |
31 | |
32 | - (id) init {return self;} | |
33 | ||
46a88c12 | 34 | @synthesize FooBar; |
e2673f71 IS |
35 | |
36 | - (int) lookAtProperty { return FooBar; } | |
37 | - (void) setProperty: (int) v { FooBar = v; } | |
38 | ||
39 | @end | |
40 | ||
41 | int main(int argc, char *argv[]) { | |
42 | int res; | |
43 | Bar *f = [[Bar alloc] init]; | |
44 | ||
45 | /* First, establish that the property getter & setter have been synthesized | |
46 | and operate correctly. */ | |
47 | [f setProperty:11]; | |
48 | ||
46a88c12 NP |
49 | if (f.FooBar != 11) |
50 | { printf ("setProperty did not set FooBar\n"); abort ();} | |
e2673f71 IS |
51 | |
52 | res = [f lookAtProperty]; | |
53 | if (res != 11 ) | |
54 | { printf ("[f lookAtProperty] = %d\n", res); abort ();} | |
55 | ||
56 | /* Make sure we haven't messed up the shortcut form. */ | |
57 | /* read ... */ | |
58 | res = f.FooBar; | |
59 | if (res != 11 ) | |
60 | { printf ("f.FooBar = %d\n", res); abort ();} | |
61 | ||
62 | /* ... write. */ | |
63 | f.FooBar = 0; | |
64 | /* printf ("seems OK\n", res); */ | |
65 | return f.FooBar; | |
66 | } | |
67 |