Fix type in the changelog entry,
[official-gcc.git] / gcc / testsuite / objc.dg / property / fsf-property-basic.m
blobddc0589e02ac32aa03379b955746a5c8d01db511
1 /* Basic test, auto-generated getter/setter based on property name.  */
2 /* { dg-do run } */
3 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
5 extern int printf (char *fmt,...) ;
6 extern void abort (void);
8 #include <objc/objc.h>
9 #include <objc/runtime.h>
11 @interface Bar
13 @public
14   Class isa;
15   int FooBar;
17 + (id) initialize;
18 + (id) alloc ;
19 - (id) init;
20 - (int) whatIsFooBar;
21 @property int FooBar;
22 @end
24 @implementation Bar
26 +initialize { return self;}
27 + (id) alloc { return class_createInstance (self, 0); }
29 - (id) init {return self;}
31 - (int) whatIsFooBar { return self->FooBar; }
32 @synthesize FooBar;
33 @end
35 int main(int argc, char *argv[]) {
36   int res;
37   Bar *f = [[Bar alloc] init];
39   /* First, establish that the property getter & setter have been synthesized 
40      and operate correctly.  */
41   [f setFooBar:1];
43   if ([f whatIsFooBar] != 1)
44     { printf ("setFooBar did not set FooBar\n"); abort ();}
45       
46   res = [f FooBar];
47     
48   if (res != 1 )
49     { printf ("[f FooBar] = %d\n",  res); abort ();}
50   
51   /* Now check the short-cut object.property syntax.  */
52   /* Read... */
53   res = f.FooBar;
54   if (res != 1 )
55     { printf ("f.FooBar = %d\n",  res); abort ();}
56   
57   /* .... write. */
58   f.FooBar = 0;
59   /* printf ("seems OK\n",  res); */
60   return f.FooBar;