Merge from mainline (165734:167278).
[official-gcc/graphite-test-results.git] / gcc / testsuite / objc.dg / property / dotsyntax-6.m
blob7ecd34e3d0b6c32920e395e0b99c8d038e186b1f
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 nested 'dot syntax' (xxx.yyy.zzz or [xxx yyy].zzz).  */
7 #include <stdlib.h>
8 #include <objc/objc.h>
9 #include <objc/runtime.h>
11 @class MyRootClass;
13 static MyRootClass *shared_root = nil;
15 @interface MyRootClass
17   Class isa;
18   int a;
19   int b;
20   MyRootClass *next;
22 @property int b;
23 @property (assign) MyRootClass *next;
24 + (id) initialize;
25 + (MyRootClass *)sharedInstance;
26 + (id) alloc;
27 - (id) init;
28 - (MyRootClass *)same;
29 - (int) count;
30 - (void) setCount: (int)count;
31 @end
33 @implementation MyRootClass
34 @synthesize b;
35 @synthesize next;
36 + (id) initialize { return self; }
37 + (id) alloc { return class_createInstance (self, 0); }
38 - (id) init { return self; }
39 + (MyRootClass *)sharedInstance
41   if (!shared_root)
42     shared_root = [[self alloc] init];
44   return shared_root;
46 - (MyRootClass *)same
48   return self;
50 - (int) count
52   return a;
54 - (void) setCount: (int)count
56   a = count;
58 @end
60 int main (void)
62   MyRootClass *object = [[MyRootClass alloc] init];
64   /* Test ClassName.accessor.accessor.  */
65   MyRootClass.sharedInstance.count = 500;
66   if (MyRootClass.sharedInstance.count != 500)
67     abort ();
69   /* Test object.accessor.accessor.  */
70   object.same.count = 1000;
71   if (object.same.count != 1000)
72     abort ();
74   /* Test object.accessor.property.  */
75   object.same.next = object;
76   if (object.same.next != object)
77     abort ();
79   /* Test lots of nesting.  */
80   if (object.next.next.same.same.next.next.same != object)
81     abort ();
83   /* Test more nesting.  */
84   MyRootClass.sharedInstance.next = object;
85   MyRootClass.sharedInstance.next.next.next.next.next.count = 2000;
86   if (MyRootClass.sharedInstance.next.next.next.next.next.count != 2000)
87     abort ();
89   /* Test more nesting.  */
90   MyRootClass.sharedInstance.same.same.same.same.same.count = 3000;
91   if (MyRootClass.sharedInstance.same.same.same.same.same.count != 3000)
92     abort ();
94   /* Test [object method].property.  */
95   [MyRootClass sharedInstance].count = 5000;
96   if ([MyRootClass sharedInstance].count != 5000)
97     abort ();
99   /* Just a final check.  */
100   if (shared_root.count != 5000)
101     abort ();
103   return 0;