1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */
3 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
5 /* Test retain and copy synthesized methods. */
9 #include <objc/runtime.h>
11 @interface MyRootClass
18 @property (copy) id a;
19 @property (retain) id b;
23 - (id) copyWithZone: (void *)zone;
26 - (oneway void) release;
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; }
47 MyRootClass *object = [[MyRootClass alloc] init];
48 MyRootClass *argument = [[MyRootClass alloc] init];
50 /* This should copy argument. */
52 if (object.a != argument)
55 /* Test that it was copied. */
56 if ([object.a copyCount] != 1)
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
64 if (object.b != argument)
67 /* Test that it was not copied. */
68 if ([object.b copyCount] != 1)