Debian Codegraph @

gcc/testsuite/objc.dg/property/synthesize-3.m

raw
1 /* Contributed by Nicola Pero <[email protected]>, November 2010. */
2 /* { dg-do run } */
3 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
4
5 /* Test @synthesize for a @property which is not declared directly in
6 the @interface, but in a @protocol that the @interface conforms
7 to. */
8
9 #include <objc/objc.h>
10 #include <objc/runtime.h>
11 #include <stdlib.h>
12
13 @interface MyRootClass
14 {
15 Class isa;
16 }
17 + (id) initialize;
18 + (id) alloc;
19 - (id) init;
20 @end
21
22 @implementation MyRootClass
23 + (id) initialize { return self; }
24 + (id) alloc { return class_createInstance (self, 0); }
25 - (id) init { return self; }
26 @end
27
28 @protocol MyProtocol
29 @property int v1;
30 @end
31
32 @protocol MyProtocol2
33 @property int v2;
34 @end
35
36 @interface Test : MyRootClass <MyProtocol, MyProtocol2>
37 {
38 int v1;
39 int _v2;
40 }
41 @end
42
43 @implementation Test
44 @synthesize v1;
45 @synthesize v2 = _v2;
46 @end
47
48 int main (void)
49 {
50 Test *object = [[Test alloc] init];
51
52 /* Check that the synthesized methods exist and work. Do not invoke
53 them via property syntax - that is another test. Here we just
54 want to test the synthesis of the methods. */
55 [object setV1: 400];
56
57 if ([object v1] != 400)
58 abort ();
59
60 [object setV2: 31];
61
62 if ([object v2] != 31)
63 abort ();
64
65 return 0;
66 }