1 // TEST_CFLAGS -Os -framework Foundation
2 // TEST_DISABLED pending clang support for rdar://20530049
7 #include <objc/objc-internal.h>
8 #include <objc/objc-abi.h>
9 #include <Foundation/Foundation.h>
11 @interface TestObject : TestRoot @end
12 @implementation TestObject @end
14 @interface Tester : NSObject @end
15 @implementation Tester {
33 objc_retainAutoreleasedReturnValue(id obj);
35 // Accept a value returned through a +0 autoreleasing convention for use at +0.
38 objc_unsafeClaimAutoreleasedReturnValue(id obj);
45 Tester *tt = [Tester new];
48 // need to get DYLD to resolve the stubs on x86
50 TestObject *warm_up = [[TestObject alloc] init];
52 warm_up = objc_retainAutoreleasedReturnValue(warm_up);
53 warm_up = objc_unsafeClaimAutoreleasedReturnValue(warm_up);
58 testprintf(" Successful +1 -> +1 handshake\n");
61 obj = [[TestObject alloc] init];
68 TestRootAutorelease = 0;
71 TestObject *tmp = [tt return1];
73 testassert(TestRootDealloc == 0);
74 testassert(TestRootRetain == 1);
75 testassert(TestRootRelease == 0);
76 testassert(TestRootAutorelease == 0);
79 testassert(TestRootDealloc == 0);
80 testassert(TestRootRetain == 1);
81 testassert(TestRootRelease == 1);
82 testassert(TestRootAutorelease == 0);
85 testassert(TestRootDealloc == 1);
86 testassert(TestRootRetain == 1);
87 testassert(TestRootRelease == 2);
88 testassert(TestRootAutorelease == 0);
92 testprintf(" Successful +0 -> +0 handshake\n");
95 obj = [[TestObject alloc] init];
102 TestRootAutorelease = 0;
105 __unsafe_unretained TestObject *tmp = [tt return0];
107 testassert(TestRootDealloc == 0);
108 testassert(TestRootRetain == 0);
109 testassert(TestRootRelease == 0);
110 testassert(TestRootAutorelease == 0);
113 testassert(TestRootDealloc == 0);
114 testassert(TestRootRetain == 0);
115 testassert(TestRootRelease == 0);
116 testassert(TestRootAutorelease == 0);
119 testassert(TestRootDealloc == 1);
120 testassert(TestRootRetain == 0);
121 testassert(TestRootRelease == 1);
122 testassert(TestRootAutorelease == 0);
127 testprintf(" Successful +1 -> +0 handshake\n");
130 obj = [[TestObject alloc] init];
137 TestRootAutorelease = 0;
140 __unsafe_unretained TestObject *tmp = [tt return1];
142 testassert(TestRootDealloc == 0);
143 testassert(TestRootRetain == 1);
144 testassert(TestRootRelease == 1);
145 testassert(TestRootAutorelease == 0);
148 testassert(TestRootDealloc == 0);
149 testassert(TestRootRetain == 1);
150 testassert(TestRootRelease == 1);
151 testassert(TestRootAutorelease == 0);
154 testassert(TestRootDealloc == 1);
155 testassert(TestRootRetain == 1);
156 testassert(TestRootRelease == 2);
157 testassert(TestRootAutorelease == 0);
162 testprintf(" Successful +0 -> +1 handshake\n");
165 obj = [[TestObject alloc] init];
172 TestRootAutorelease = 0;
175 TestObject *tmp = [tt return0];
177 testassert(TestRootDealloc == 0);
178 testassert(TestRootRetain == 1);
179 testassert(TestRootRelease == 0);
180 testassert(TestRootAutorelease == 0);
183 testassert(TestRootDealloc == 0);
184 testassert(TestRootRetain == 1);
185 testassert(TestRootRelease == 1);
186 testassert(TestRootAutorelease == 0);
189 testassert(TestRootDealloc == 1);
190 testassert(TestRootRetain == 1);
191 testassert(TestRootRelease == 2);
192 testassert(TestRootAutorelease == 0);