Create embedded-5_0-branch branch for development on ARM embedded cores.
[official-gcc.git] / embedded-5_0-branch / gcc / testsuite / obj-c++.dg / property / at-property-24.mm
blobb4a7699f6e409b373ccaf811b9edb06086a7c620
1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010.  */
2 /* { dg-do run } */
3 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
5 /* Test @optional @properties.  */
7 #include <stdlib.h>
8 #include <objc/objc.h>
9 #include <objc/runtime.h>
11 @interface MyRootClass
13   Class isa;
15 + (id) initialize;
16 + (id) alloc;
17 - (id) init;
18 @end
20 @implementation MyRootClass
21 + (id) initialize { return self; }
22 + (id) alloc { return class_createInstance (self, 0); }
23 - (id) init { return self; }
24 @end
26 /* Use a different getters/setters, so that the only way to compile
27    object.countX is to find the actual @property.  */
28 @protocol count
29 @required
30 /* @required + @synthesize.  */
31 @property (getter=number1, setter=setNumber1:) int count1;
32 /* @required + manual setters/getters.  */
33 @property (getter=number2, setter=setNumber2:) int count2;
35 @optional
36 /* @optional + @synthesize.  */
37 @property (getter=number3, setter=setNumber3:) int count3;
38 /* @optional + manual setters/getters.  */
39 @property (getter=number4, setter=setNumber4:) int count4;
41 @optional
42 /* @optional + readonly, with a setter added in the class itself.  */
43 @property (readonly, getter=number5) int count5;
44 @end
46 @interface MySubClass : MyRootClass <count>
48   int count1;
49   int count2;
50   int count3;
51   int count4;
52   int count5;
54 - (void) setCount5: (int)value;
55 @end
57 @implementation MySubClass
58 @synthesize count1;
59 - (int) number2
61   return count2;
63 - (void) setNumber2: (int)value
65   count2 = value;
67 @synthesize count3;
68 - (int) number4
70   return count4;
72 - (void) setNumber4: (int)value
74   count4 = value;
76 - (int) number5
78   return count5;
80 - (void) setCount5: (int)value
82   count5 = value;
84 @end
86 int main (void)
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.  */
92   object.count1 = 44;
93   if (object.count1 != 44)
94     abort ();
96   object.count2 = 88;
97   if (object.count2 != 88)
98     abort ();
100   object.count3 = 77;
101   if (object.count3 != 77)
102     abort ();
104   object.count4 = 11;
105   if (object.count4 != 11)
106     abort ();
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.  */
113   object.count5 = 99;
114   if (object.count5 != 99)
115     abort ();
117   return 0;