| 1 |
/* Contributed by Nicola Pero <[email protected]>, November 2010. */ |
| 2 |
/* { dg-do run } */ |
| 3 |
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ |
| 4 |
|
| 5 |
/* Test nested 'dot syntax' (xxx.yyy.zzz or [xxx yyy].zzz). */ |
| 6 |
|
| 7 |
#include <stdlib.h> |
| 8 |
#include <objc/objc.h> |
| 9 |
#include <objc/runtime.h> |
| 10 |
|
| 11 |
@class MyRootClass; |
| 12 |
|
| 13 |
static MyRootClass *shared_root = nil; |
| 14 |
|
| 15 |
@interface MyRootClass |
| 16 |
{ |
| 17 |
Class isa; |
| 18 |
int a; |
| 19 |
int b; |
| 20 |
MyRootClass *next; |
| 21 |
} |
| 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 |
| 32 |
|
| 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 |
| 40 |
{ |
| 41 |
if (!shared_root) |
| 42 |
shared_root = [[self alloc] init]; |
| 43 |
|
| 44 |
return shared_root; |
| 45 |
} |
| 46 |
- (MyRootClass *)same |
| 47 |
{ |
| 48 |
return self; |
| 49 |
} |
| 50 |
- (int) count |
| 51 |
{ |
| 52 |
return a; |
| 53 |
} |
| 54 |
- (void) setCount: (int)count |
| 55 |
{ |
| 56 |
a = count; |
| 57 |
} |
| 58 |
@end |
| 59 |
|
| 60 |
int main (void) |
| 61 |
{ |
| 62 |
MyRootClass *object = [[MyRootClass alloc] init]; |
| 63 |
|
| 64 |
/* Test ClassName.accessor.accessor. */ |
| 65 |
MyRootClass.sharedInstance.count = 500; |
| 66 |
if (MyRootClass.sharedInstance.count != 500) |
| 67 |
abort (); |
| 68 |
|
| 69 |
/* Test object.accessor.accessor. */ |
| 70 |
object.same.count = 1000; |
| 71 |
if (object.same.count != 1000) |
| 72 |
abort (); |
| 73 |
|
| 74 |
/* Test object.accessor.property. */ |
| 75 |
object.same.next = object; |
| 76 |
if (object.same.next != object) |
| 77 |
abort (); |
| 78 |
|
| 79 |
/* Test lots of nesting. */ |
| 80 |
if (object.next.next.same.same.next.next.same != object) |
| 81 |
abort (); |
| 82 |
|
| 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 (); |
| 88 |
|
| 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 (); |
| 93 |
|
| 94 |
/* Test [object method].property. */ |
| 95 |
[MyRootClass sharedInstance].count = 5000; |
| 96 |
if ([MyRootClass sharedInstance].count != 5000) |
| 97 |
abort (); |
| 98 |
|
| 99 |
/* Just a final check. */ |
| 100 |
if (shared_root.count != 5000) |
| 101 |
abort (); |
| 102 |
|
| 103 |
return 0; |
| 104 |
} |
| 105 |
|
| 106 |
|