Debian Codegraph @

gcc/testsuite/objc.dg/property/at-property-19.m

raw
1 /* Contributed by Nicola Pero <[email protected]>, October 2010. */
2 /* { dg-do run } */
3 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
4
5 /* Test looking up a @property in a protocol of a category of a superclass. */
6
7 #include <stdlib.h>
8 #include <objc/objc.h>
9 #include <objc/runtime.h>
10
11 @interface MyRootClass
12 {
13 Class isa;
14 int a;
15 }
16 + (id) initialize;
17 + (id) alloc;
18 - (id) init;
19 @end
20
21 @implementation MyRootClass
22 + (id) initialize { return self; }
23 + (id) alloc { return class_createInstance (self, 0); }
24 - (id) init { return self; }
25 @end
26
27 /* Use a different getter/setter, so that the only way to compile
28 object.count is to find the actual @property. */
29 @protocol count
30 @property (getter=number, setter=setNumber:) int count;
31 @end
32
33 @interface MySubClass : MyRootClass
34 - (int) testMe;
35 @end
36
37 @interface MySubClass (Category) <count>
38 @end
39
40 @implementation MySubClass (Category)
41 - (int) number
42 {
43 return a;
44 }
45 - (void) setNumber: (int)count
46 {
47 a = count;
48 }
49 @end
50
51 @implementation MySubClass
52 - (int) testMe
53 {
54 self.count = 400;
55 if (self.count != 400)
56 abort ();
57
58 return self.count;
59 }
60 @end
61
62 int main (void)
63 {
64 MySubClass *object = [[MySubClass alloc] init];
65
66 object.count = 44;
67 if (object.count != 44)
68 abort ();
69
70 if ([object testMe] != 400)
71 abort ();
72
73 return 0;
74 }