Merge from mainline (165734:167278).
[official-gcc/graphite-test-results.git] / gcc / testsuite / objc.dg / property / at-property-19.m
blobbe898e21815b1fc4eb5b42bc0d812605d2869bc6
1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010.  */
2 /* { dg-do run } */
3 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
5 /* Test looking up a @property in a protocol of a category of a superclass.  */
7 #include <stdlib.h>
8 #include <objc/objc.h>
9 #include <objc/runtime.h>
11 @interface MyRootClass
13   Class isa;
14   int a;
16 + (id) initialize;
17 + (id) alloc;
18 - (id) init;
19 @end
21 @implementation MyRootClass
22 + (id) initialize { return self; }
23 + (id) alloc { return class_createInstance (self, 0); }
24 - (id) init { return self; }
25 @end
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
33 @interface MySubClass : MyRootClass
34 - (int) testMe;
35 @end
37 @interface MySubClass (Category) <count>
38 @end
40 @implementation MySubClass (Category)
41 - (int) number
43   return a;
45 - (void) setNumber: (int)count
47   a = count;
49 @end
51 @implementation MySubClass
52 - (int) testMe
54   self.count = 400;
55   if (self.count != 400)
56     abort ();             
58   return self.count;
60 @end
62 int main (void)
64   MySubClass *object = [[MySubClass alloc] init];
66   object.count = 44;
67   if (object.count != 44)
68     abort ();
70   if ([object testMe] != 400)
71     abort ();
73   return 0;