]> git.saurik.com Git - apple/objc4.git/blob - test/weakReferenceHook.m
objc4-818.2.tar.gz
[apple/objc4.git] / test / weakReferenceHook.m
1 /*
2 TEST_CONFIG MEM=mrc
3 TEST_ENV OBJC_DISABLE_NONPOINTER_ISA=YES
4 */
5
6 #include "test.h"
7 #include "testroot.i"
8
9 bool hasWeakRefs = false;
10
11 @interface TestRoot (WeakHooks)
12 @end
13
14 @implementation TestRoot (WeakHooks)
15
16 - (void)_setWeaklyReferenced {
17 hasWeakRefs = true;
18 }
19
20 // -_setWeaklyReferenced is currently limited to raw-isa custom-rr to avoid overhead
21 - (void) release {
22 }
23
24 @end
25
26 int main() {
27 id obj = [TestRoot new];
28 id wobj = nil;
29 objc_storeWeak(&wobj, obj);
30 testassert(hasWeakRefs == true);
31
32 id out = objc_loadWeak(&wobj);
33 testassert(out == obj);
34
35 objc_storeWeak(&wobj, nil);
36 out = objc_loadWeak(&wobj);
37 testassert(out == nil);
38
39 hasWeakRefs = false;
40 objc_storeWeak(&wobj, obj);
41 testassert(hasWeakRefs == true);
42
43
44 out = objc_loadWeak(&wobj);
45 testassert(out == obj);
46 objc_storeWeak(&wobj, nil);
47
48 succeed(__FILE__);
49 }