| 1 |
/* Contributed by Nicola Pero <[email protected]>, October 2010. */ |
| 2 |
/* { dg-do run } */ |
| 3 |
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ |
| 4 |
|
| 5 |
/* Test the property syntax in a number of expressions. */ |
| 6 |
|
| 7 |
#include <stdlib.h> |
| 8 |
#include <objc/objc.h> |
| 9 |
#include <objc/runtime.h> |
| 10 |
|
| 11 |
@interface MyRootClass |
| 12 |
{ |
| 13 |
Class isa; |
| 14 |
int a; |
| 15 |
} |
| 16 |
/* Use the simplest synthesized accessor (assign, nonatomic) as we are |
| 17 |
not testing the synthesized accessors in this test, just the |
| 18 |
property syntax. */ |
| 19 |
@property (nonatomic) int a; |
| 20 |
+ (id) initialize; |
| 21 |
+ (id) alloc; |
| 22 |
- (id) init; |
| 23 |
@end |
| 24 |
|
| 25 |
@implementation MyRootClass |
| 26 |
+ (id) initialize { return self; } |
| 27 |
+ (id) alloc { return class_createInstance (self, 0); } |
| 28 |
- (id) init { return self; } |
| 29 |
@synthesize a; |
| 30 |
@end |
| 31 |
|
| 32 |
int |
| 33 |
test (int g) |
| 34 |
{ |
| 35 |
return g; |
| 36 |
} |
| 37 |
|
| 38 |
int main (void) |
| 39 |
{ |
| 40 |
MyRootClass *object = [[MyRootClass alloc] init]; |
| 41 |
MyRootClass *object2 = [[MyRootClass alloc] init]; |
| 42 |
|
| 43 |
object.a = 14; |
| 44 |
object.a = object.a + object.a; |
| 45 |
|
| 46 |
if (object.a != 28) |
| 47 |
abort (); |
| 48 |
|
| 49 |
object.a = 99; |
| 50 |
object.a++; |
| 51 |
|
| 52 |
if (object.a != 100) |
| 53 |
abort (); |
| 54 |
|
| 55 |
object.a = 99; |
| 56 |
object.a *= 2; |
| 57 |
|
| 58 |
if (object.a != 198) |
| 59 |
abort (); |
| 60 |
|
| 61 |
{ |
| 62 |
int f = object.a; |
| 63 |
|
| 64 |
if (f != 198) |
| 65 |
abort (); |
| 66 |
|
| 67 |
if (f != object.a) |
| 68 |
abort (); |
| 69 |
|
| 70 |
if (object.a != f) |
| 71 |
abort (); |
| 72 |
|
| 73 |
object.a = object.a; |
| 74 |
|
| 75 |
if (object.a != 198) |
| 76 |
abort (); |
| 77 |
} |
| 78 |
|
| 79 |
if (test (object.a) != 198) |
| 80 |
abort (); |
| 81 |
|
| 82 |
object.a = -object.a; |
| 83 |
|
| 84 |
if (object.a != -198) |
| 85 |
abort (); |
| 86 |
|
| 87 |
for (object.a = 0; object.a < 99; object.a++) |
| 88 |
object2.a = object.a; |
| 89 |
|
| 90 |
if (object2.a != object.a - 1) |
| 91 |
abort (); |
| 92 |
|
| 93 |
if (object2.a != 98) |
| 94 |
abort (); |
| 95 |
|
| 96 |
if (object.a != 99) |
| 97 |
abort (); |
| 98 |
|
| 99 |
return 0; |
| 100 |
} |