Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s |
Steve Naroff | 22dc0b0 | 2009-02-26 19:11:32 +0000 | [diff] [blame] | 2 | |
| 3 | @interface NSObject |
| 4 | + alloc; |
| 5 | - init; |
| 6 | @end |
| 7 | |
| 8 | @protocol Test |
| 9 | @property int required; |
| 10 | |
| 11 | @optional |
| 12 | @property int optional; |
| 13 | @property int optional1; |
| 14 | @property int optional_preexisting_setter_getter; |
| 15 | @property (setter = setOptional_preexisting_setter_getter: , |
| 16 | getter = optional_preexisting_setter_getter) int optional_with_setter_getter_attr; |
| 17 | @required |
| 18 | @property int required1; |
| 19 | @optional |
| 20 | @property int optional_to_be_defined; |
| 21 | @property (readonly, getter = optional_preexisting_setter_getter) int optional_getter_attr; |
| 22 | @end |
| 23 | |
| 24 | @interface Test : NSObject <Test> { |
| 25 | int ivar; |
| 26 | int ivar1; |
| 27 | int ivar2; |
| 28 | } |
| 29 | @property int required; |
| 30 | @property int optional_to_be_defined; |
| 31 | - (int) optional_preexisting_setter_getter; |
| 32 | - (void) setOptional_preexisting_setter_getter:(int)value; |
| 33 | @end |
| 34 | |
| 35 | @implementation Test |
| 36 | @synthesize required = ivar; |
| 37 | @synthesize required1 = ivar1; |
| 38 | @synthesize optional_to_be_defined = ivar2; |
| 39 | - (int) optional_preexisting_setter_getter { return ivar; } |
| 40 | - (void) setOptional_preexisting_setter_getter:(int)value |
| 41 | { |
| 42 | ivar = value; |
| 43 | } |
| 44 | - (void) setOptional_getter_attr:(int)value { ivar = value; } |
| 45 | @end |
| 46 | |
| 47 | int main () |
| 48 | { |
| 49 | Test *x = [[Test alloc] init]; |
| 50 | /* 1. Test of a requred property */ |
| 51 | x.required1 = 100; |
| 52 | if (x.required1 != 100) |
| 53 | abort (); |
| 54 | |
| 55 | /* 2. Test of a synthesize optional property */ |
| 56 | x.optional_to_be_defined = 123; |
| 57 | if (x.optional_to_be_defined != 123) |
| 58 | abort (); |
| 59 | |
| 60 | /* 3. Test of optional property with pre-sxisting defined setter/getter */ |
| 61 | x.optional_preexisting_setter_getter = 200; |
| 62 | if (x.optional_preexisting_setter_getter != 200) |
| 63 | abort (); |
| 64 | |
| 65 | /* 4. Test of optional property with setter/getter attribute */ |
| 66 | if (x.optional_with_setter_getter_attr != 200) |
| 67 | abort (); |
| 68 | return 0; |
| 69 | |
| 70 | /* 5. Test of optional property with getter attribute and default setter method. */ |
| 71 | x.optional_getter_attr = 1000; |
| 72 | if (x.optional_getter_attr != 1000) |
| 73 | abort (); |
| 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |