| 1 |
/* Contributed by Nicola Pero <[email protected]>, December 2010. */ |
| 2 |
/* { dg-do run } */ |
| 3 |
/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */ |
| 4 |
|
| 5 |
/* Test @properties in class extensions. */ |
| 6 |
|
| 7 |
#include <stdlib.h> |
| 8 |
#include <objc/objc.h> |
| 9 |
#include <objc/runtime.h> |
| 10 |
|
| 11 |
@interface MyRootClass |
| 12 |
{ |
| 13 |
Class isa; |
| 14 |
} |
| 15 |
+ (id) initialize; |
| 16 |
+ (id) alloc; |
| 17 |
- (id) init; |
| 18 |
@end |
| 19 |
|
| 20 |
@implementation MyRootClass |
| 21 |
+ (id) initialize { return self; } |
| 22 |
+ (id) alloc { return class_createInstance (self, 0); } |
| 23 |
- (id) init { return self; } |
| 24 |
@end |
| 25 |
|
| 26 |
@protocol count4 |
| 27 |
/* Use a different getters/setters, so that the only way to compile |
| 28 |
object.countX is to find the actual @property. */ |
| 29 |
@property (getter=number4, setter=setNumber4:) int count4; |
| 30 |
@end |
| 31 |
|
| 32 |
@interface MySubClass : MyRootClass |
| 33 |
{ |
| 34 |
int count1; |
| 35 |
int count2; |
| 36 |
int count3; |
| 37 |
int count4; |
| 38 |
} |
| 39 |
@property (getter=number1, setter=setNumber1:) int count1; |
| 40 |
@end |
| 41 |
|
| 42 |
@interface MySubClass () |
| 43 |
@property (getter=number2, setter=setNumber2:) int count2; |
| 44 |
@end |
| 45 |
|
| 46 |
@interface MySubClass () <count4> |
| 47 |
@property (getter=number3, setter=setNumber3:) int count3; |
| 48 |
@end |
| 49 |
|
| 50 |
@implementation MySubClass |
| 51 |
@synthesize count1; |
| 52 |
@synthesize count2; |
| 53 |
- (int) number3 |
| 54 |
{ |
| 55 |
return count3; |
| 56 |
} |
| 57 |
- (void) setNumber3: (int)value |
| 58 |
{ |
| 59 |
count3 = value; |
| 60 |
} |
| 61 |
@synthesize count4; |
| 62 |
@end |
| 63 |
|
| 64 |
int main (void) |
| 65 |
{ |
| 66 |
MySubClass *object = [[MySubClass alloc] init]; |
| 67 |
|
| 68 |
object.count1 = 20; |
| 69 |
if (object.count1 != 20) |
| 70 |
abort (); |
| 71 |
|
| 72 |
object.count2 = 11; |
| 73 |
if (object.count2 != 11) |
| 74 |
abort (); |
| 75 |
|
| 76 |
object.count3 = 19; |
| 77 |
if (object.count3 != 19) |
| 78 |
abort (); |
| 79 |
|
| 80 |
object.count4 = 74; |
| 81 |
if (object.count4 != 74) |
| 82 |
abort (); |
| 83 |
|
| 84 |
return 0; |
| 85 |
} |