| 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 dot-syntax with pre/post increment and decrement. */ |
| 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 |
+ (id) initialize; |
| 17 |
+ (id) alloc; |
| 18 |
- (id) init; |
| 19 |
- (int) count; |
| 20 |
- (void) setCount: (int)count; |
| 21 |
@end |
| 22 |
|
| 23 |
@implementation MyRootClass |
| 24 |
+ (id) initialize { return self; } |
| 25 |
+ (id) alloc { return class_createInstance (self, 0); } |
| 26 |
- (id) init { return self; } |
| 27 |
- (int) count |
| 28 |
{ |
| 29 |
return a; |
| 30 |
} |
| 31 |
- (void) setCount: (int)count |
| 32 |
{ |
| 33 |
a = count; |
| 34 |
} |
| 35 |
@end |
| 36 |
|
| 37 |
int main (void) |
| 38 |
{ |
| 39 |
MyRootClass *object = [[MyRootClass alloc] init]; |
| 40 |
|
| 41 |
object.count = 10; |
| 42 |
if (object.count != 10) |
| 43 |
abort (); |
| 44 |
|
| 45 |
/* First, test that they increment/decrement as expected. */ |
| 46 |
object.count++; |
| 47 |
if (object.count != 11) |
| 48 |
abort (); |
| 49 |
|
| 50 |
++object.count; |
| 51 |
if (object.count != 12) |
| 52 |
abort (); |
| 53 |
|
| 54 |
object.count--; |
| 55 |
if (object.count != 11) |
| 56 |
abort (); |
| 57 |
|
| 58 |
--object.count; |
| 59 |
if (object.count != 10) |
| 60 |
abort (); |
| 61 |
|
| 62 |
/* Now, test that they are pre/post increment/decrement, as |
| 63 |
expected. */ |
| 64 |
if (object.count++ != 10) |
| 65 |
abort (); |
| 66 |
|
| 67 |
if (object.count != 11) |
| 68 |
abort (); |
| 69 |
|
| 70 |
if (++object.count != 12) |
| 71 |
abort (); |
| 72 |
|
| 73 |
if (object.count != 12) |
| 74 |
abort (); |
| 75 |
|
| 76 |
if (object.count-- != 12) |
| 77 |
abort (); |
| 78 |
|
| 79 |
if (object.count != 11) |
| 80 |
abort (); |
| 81 |
|
| 82 |
if (--object.count != 10) |
| 83 |
abort (); |
| 84 |
|
| 85 |
if (object.count != 10) |
| 86 |
abort (); |
| 87 |
|
| 88 |
return 0; |
| 89 |
} |
| 90 |
|
| 91 |
|