Small ChangeLog tweak.
[official-gcc.git] / gcc / testsuite / objc.dg / property / dotsyntax-21.m
blob4b8945ed644e1b76d98f24ef7a5517fd153ab8c4
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 dot-syntax with super in a category.  */
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 - (int) count;
20 - (void) setCount: (int)count;
21 @end
23 @implementation MyRootClass
24 + (id) initialize { return self; }
25 + (id) alloc { return class_createInstance (self, 0); }
26 - (id) init { return self; }
27 - (int) count
29   return a;
31 - (void) setCount: (int)count
33   a = count;
35 @end
37 /* First, test 'super' in the main implementation of a subclass.  */
38 @interface MySubClass : MyRootClass
39 - (int) superCount;
40 - (void) setSuperCount: (int)count;
41 @end
43 @implementation MySubClass
44 - (int) superCount
46   return super.count;
48 - (void) setSuperCount: (int)count
50   super.count = count;
52 @end
54 /* Now, test 'super' in a category of a subclass.  */
55 @interface MySubClass (Category)
56 - (int) superCount2;
57 - (void) setSuperCount2: (int)count;
58 - (int) test: (int)x;
59 @end
61 @implementation MySubClass (Category)
62 - (int) superCount2
64   return super.count;
66 - (void) setSuperCount2: (int)count
68   super.count = count;
70 - (int) test: (int)x
72   /* For positive x, the following will leave super.count
73      unchanged.  */
74   super.count++;
75   --super.count;
77   super.count = (x < 0 ? x : super.count);
78   
79   if ((x = super.count))
80     super.count += 1;
82   if ((x = super.count))
83     super.count -= 1;
85   /* Finally, also put a bit of self.count in the mix.  */
86   self.count++;
87   super.count--;
89   return super.count;
91 @end
93 int main (void)
95   MySubClass *object = [[MySubClass alloc] init];
97   object.count = 10;
98   if (object.count != 10)
99     abort ();
101   object.superCount = 11;
102   if (object.superCount != 11)
103     abort ();
105   object.superCount2 = 12;
106   if (object.superCount2 != 12)
107     abort ();
109   if ([object test: 45] != 12)
110     abort ();
112   return 0;