]> git.saurik.com Git - apple/objc4.git/blob - test/rr-autorelease-fastarc.m
objc4-781.2.tar.gz
[apple/objc4.git] / test / rr-autorelease-fastarc.m
1 // TEST_CFLAGS -Os -framework Foundation
2 // TEST_DISABLED pending clang support for rdar://20530049
3
4 #include "test.h"
5 #include "testroot.i"
6
7 #include <objc/objc-internal.h>
8 #include <objc/objc-abi.h>
9 #include <Foundation/Foundation.h>
10
11 @interface TestObject : TestRoot @end
12 @implementation TestObject @end
13
14 @interface Tester : NSObject @end
15 @implementation Tester {
16 @public
17 id ivar;
18 }
19
20 -(id) return0 {
21 return ivar;
22 }
23 -(id) return1 {
24 id x = ivar;
25 [x self];
26 return x;
27 }
28
29 @end
30
31 OBJC_EXPORT
32 id
33 objc_retainAutoreleasedReturnValue(id obj);
34
35 // Accept a value returned through a +0 autoreleasing convention for use at +0.
36 OBJC_EXPORT
37 id
38 objc_unsafeClaimAutoreleasedReturnValue(id obj);
39
40
41 int
42 main()
43 {
44 TestObject *obj;
45 Tester *tt = [Tester new];
46
47 #ifdef __x86_64__
48 // need to get DYLD to resolve the stubs on x86
49 PUSH_POOL {
50 TestObject *warm_up = [[TestObject alloc] init];
51 testassert(warm_up);
52 warm_up = objc_retainAutoreleasedReturnValue(warm_up);
53 warm_up = objc_unsafeClaimAutoreleasedReturnValue(warm_up);
54 warm_up = nil;
55 } POP_POOL;
56 #endif
57
58 testprintf(" Successful +1 -> +1 handshake\n");
59
60 PUSH_POOL {
61 obj = [[TestObject alloc] init];
62 testassert(obj);
63 tt->ivar = obj;
64 obj = nil;
65
66 TestRootRetain = 0;
67 TestRootRelease = 0;
68 TestRootAutorelease = 0;
69 TestRootDealloc = 0;
70
71 TestObject *tmp = [tt return1];
72
73 testassert(TestRootDealloc == 0);
74 testassert(TestRootRetain == 1);
75 testassert(TestRootRelease == 0);
76 testassert(TestRootAutorelease == 0);
77
78 tt->ivar = nil;
79 testassert(TestRootDealloc == 0);
80 testassert(TestRootRetain == 1);
81 testassert(TestRootRelease == 1);
82 testassert(TestRootAutorelease == 0);
83
84 tmp = nil;
85 testassert(TestRootDealloc == 1);
86 testassert(TestRootRetain == 1);
87 testassert(TestRootRelease == 2);
88 testassert(TestRootAutorelease == 0);
89
90 } POP_POOL;
91
92 testprintf(" Successful +0 -> +0 handshake\n");
93
94 PUSH_POOL {
95 obj = [[TestObject alloc] init];
96 testassert(obj);
97 tt->ivar = obj;
98 obj = nil;
99
100 TestRootRetain = 0;
101 TestRootRelease = 0;
102 TestRootAutorelease = 0;
103 TestRootDealloc = 0;
104
105 __unsafe_unretained TestObject *tmp = [tt return0];
106
107 testassert(TestRootDealloc == 0);
108 testassert(TestRootRetain == 0);
109 testassert(TestRootRelease == 0);
110 testassert(TestRootAutorelease == 0);
111
112 tmp = nil;
113 testassert(TestRootDealloc == 0);
114 testassert(TestRootRetain == 0);
115 testassert(TestRootRelease == 0);
116 testassert(TestRootAutorelease == 0);
117
118 tt->ivar = nil;
119 testassert(TestRootDealloc == 1);
120 testassert(TestRootRetain == 0);
121 testassert(TestRootRelease == 1);
122 testassert(TestRootAutorelease == 0);
123
124 } POP_POOL;
125
126
127 testprintf(" Successful +1 -> +0 handshake\n");
128
129 PUSH_POOL {
130 obj = [[TestObject alloc] init];
131 testassert(obj);
132 tt->ivar = obj;
133 obj = nil;
134
135 TestRootRetain = 0;
136 TestRootRelease = 0;
137 TestRootAutorelease = 0;
138 TestRootDealloc = 0;
139
140 __unsafe_unretained TestObject *tmp = [tt return1];
141
142 testassert(TestRootDealloc == 0);
143 testassert(TestRootRetain == 1);
144 testassert(TestRootRelease == 1);
145 testassert(TestRootAutorelease == 0);
146
147 tmp = nil;
148 testassert(TestRootDealloc == 0);
149 testassert(TestRootRetain == 1);
150 testassert(TestRootRelease == 1);
151 testassert(TestRootAutorelease == 0);
152
153 tt->ivar = nil;
154 testassert(TestRootDealloc == 1);
155 testassert(TestRootRetain == 1);
156 testassert(TestRootRelease == 2);
157 testassert(TestRootAutorelease == 0);
158
159 } POP_POOL;
160
161
162 testprintf(" Successful +0 -> +1 handshake\n");
163
164 PUSH_POOL {
165 obj = [[TestObject alloc] init];
166 testassert(obj);
167 tt->ivar = obj;
168 obj = nil;
169
170 TestRootRetain = 0;
171 TestRootRelease = 0;
172 TestRootAutorelease = 0;
173 TestRootDealloc = 0;
174
175 TestObject *tmp = [tt return0];
176
177 testassert(TestRootDealloc == 0);
178 testassert(TestRootRetain == 1);
179 testassert(TestRootRelease == 0);
180 testassert(TestRootAutorelease == 0);
181
182 tmp = nil;
183 testassert(TestRootDealloc == 0);
184 testassert(TestRootRetain == 1);
185 testassert(TestRootRelease == 1);
186 testassert(TestRootAutorelease == 0);
187
188 tt->ivar = nil;
189 testassert(TestRootDealloc == 1);
190 testassert(TestRootRetain == 1);
191 testassert(TestRootRelease == 2);
192 testassert(TestRootAutorelease == 0);
193
194 } POP_POOL;
195
196
197
198 succeed(__FILE__);
199
200 return 0;
201 }
202
203
204 #endif