Debian Codegraph @

gcc/testsuite/objc.dg/property/fsf-property-method-access.m

raw
1 /* test access in methods, auto-generated getter/setter based on property name. */
2 /* { dg-do run } */
3 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
4
5 extern int printf (char *fmt,...) ;
6 extern void abort (void);
7
8 #include <objc/objc.h>
9 #include <objc/runtime.h>
10
11 @interface Bar
12 {
13 @public
14 Class isa;
15 int FooBar;
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;}
30 + (id) alloc { return class_createInstance(self, 0);}
31
32 - (id) init {return self;}
33
34 @synthesize FooBar;
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
49 if (f.FooBar != 11)
50 { printf ("setProperty did not set FooBar\n"); abort ();}
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