1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
3 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
5 /* Test @optional @properties. */
9 #include <objc/runtime.h>
11 @interface MyRootClass
20 @implementation MyRootClass
21 + (id) initialize { return self; }
22 + (id) alloc { return class_createInstance (self, 0); }
23 - (id) init { return self; }
26 /* Use a different getters/setters, so that the only way to compile
27 object.countX is to find the actual @property. */
30 /* @required + @synthesize. */
31 @property (getter=number1, setter=setNumber1:) int count1;
32 /* @required + manual setters/getters. */
33 @property (getter=number2, setter=setNumber2:) int count2;
36 /* @optional + @synthesize. */
37 @property (getter=number3, setter=setNumber3:) int count3;
38 /* @optional + manual setters/getters. */
39 @property (getter=number4, setter=setNumber4:) int count4;
42 /* @optional + readonly, with a setter added in the class itself. */
43 @property (readonly, getter=number5) int count5;
46 @interface MySubClass : MyRootClass <count>
54 - (void) setCount5: (int)value;
57 @implementation MySubClass
63 - (void) setNumber2: (int)value
72 - (void) setNumber4: (int)value
80 - (void) setCount5: (int)value
88 MySubClass *object = [[MySubClass alloc] init];
90 /* First, test that @required and @optional properties work as
91 expected if implemented either via @synthesize or manually. */
93 if (object.count1 != 44)
97 if (object.count2 != 88)
101 if (object.count3 != 77)
105 if (object.count4 != 11)
108 /* Now, test the complication: @optional @property which is
109 readonly, but which has a setter manually implemented.
110 Apparently it is possible to use the dotsyntax and the @optional
111 @property getter is used when reading, while the manual setter is
112 used when writing. */
114 if (object.count5 != 99)