Merge from mainline (165734:167278).
[official-gcc/graphite-test-results.git] / gcc / testsuite / obj-c++.dg / property / at-property-13.mm
blob6786c3aa857960cde6cbb1bdf00dd866aa6a4a2c
1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010.  */
2 /* { dg-do run } */
3 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
5 /* Test retain and copy synthesized methods.  */
7 #include <stdlib.h>
8 #include <objc/objc.h>
9 #include <objc/runtime.h>
11 @interface MyRootClass
13   Class isa;
14   int copy_count;
15   id a;
16   id b;
18 @property (copy) id a;
19 @property (retain) id b;
20 + (id) initialize;
21 + (id) alloc;
22 - (id) init;
23 - (id) copyWithZone: (void *)zone;
24 - (int) copyCount;
25 - (id) autorelease;
26 - (oneway void) release;
27 - (id) retain;
28 @end
30 /* This class implements copyWithZone, which doesn't do anything other
31    than increasing a counter of how many copies were made.  */
32 @implementation MyRootClass
33 + (id) initialize { return self; }
34 + (id) alloc { return class_createInstance (self, 0); }
35 - (id) init { return self; }
36 - (id) copyWithZone: (void *)zone { copy_count++; return self; }
37 - (int) copyCount { return copy_count; }
38 - (id) autorelease { return self; }
39 - (oneway void) release { return; }
40 - (id) retain { return self; }
41 @synthesize a;
42 @synthesize b;
43 @end
45 int main (void)
47   MyRootClass *object = [[MyRootClass alloc] init];
48   MyRootClass *argument = [[MyRootClass alloc] init];
50   /* This should copy argument.  */
51   object.a = argument;
52   if (object.a != argument)
53     abort ();
55   /* Test that it was copied.  */
56   if ([object.a copyCount] != 1)
57     abort ();
59   /* We just test that the retain accessors seem to work and that they
60      don't copy.  We don't test that retain was actually called,
61      because if garbage collection is enabled, it may never be
62      called!  */
63   object.b = argument;
64   if (object.b != argument)
65     abort ();
67   /* Test that it was not copied.  */
68   if ([object.b copyCount] != 1)
69     abort ();
71   return (0);