Mike Stump | 4617191 | 2010-01-23 20:12:18 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s -Wno-unreachable-code |
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 | |
Eli Friedman | 772494c | 2009-12-16 06:28:21 +0000 | [diff] [blame] | 47 | void abort(void); |
Steve Naroff | 22dc0b0 | 2009-02-26 19:11:32 +0000 | [diff] [blame] | 48 | int main () |
| 49 | { |
| 50 | Test *x = [[Test alloc] init]; |
Chris Lattner | fc8f0e1 | 2011-04-15 05:22:18 +0000 | [diff] [blame] | 51 | /* 1. Test of a required property */ |
Steve Naroff | 22dc0b0 | 2009-02-26 19:11:32 +0000 | [diff] [blame] | 52 | x.required1 = 100; |
| 53 | if (x.required1 != 100) |
| 54 | abort (); |
| 55 | |
| 56 | /* 2. Test of a synthesize optional property */ |
| 57 | x.optional_to_be_defined = 123; |
| 58 | if (x.optional_to_be_defined != 123) |
| 59 | abort (); |
| 60 | |
| 61 | /* 3. Test of optional property with pre-sxisting defined setter/getter */ |
| 62 | x.optional_preexisting_setter_getter = 200; |
| 63 | if (x.optional_preexisting_setter_getter != 200) |
| 64 | abort (); |
| 65 | |
| 66 | /* 4. Test of optional property with setter/getter attribute */ |
| 67 | if (x.optional_with_setter_getter_attr != 200) |
| 68 | abort (); |
| 69 | return 0; |
| 70 | |
| 71 | /* 5. Test of optional property with getter attribute and default setter method. */ |
| 72 | x.optional_getter_attr = 1000; |
| 73 | if (x.optional_getter_attr != 1000) |
| 74 | abort (); |
| 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |