]> git.saurik.com Git - apple/objc4.git/blob - test/weakcopy.m
objc4-680.tar.gz
[apple/objc4.git] / test / weakcopy.m
1 // TEST_CONFIG
2
3 #include "test.h"
4
5 #if __OBJC_GC__ && __cplusplus && __i386__
6
7 int main()
8 {
9 testwarn("rdar://19042235 test disabled for 32-bit objc++ GC because of unknown bit rot");
10 succeed(__FILE__);
11 }
12
13 #else
14
15 #include "testroot.i"
16 #include <stdint.h>
17 #include <string.h>
18 #include <objc/objc-runtime.h>
19
20 @interface Weak : TestRoot {
21 @public
22 __weak id value;
23 }
24 @end
25 @implementation Weak
26 @end
27
28 Weak *oldObject;
29 Weak *newObject;
30
31 void *fn(void *arg __unused)
32 {
33 objc_registerThreadWithCollector();
34
35 return NULL;
36 }
37
38 int main()
39 {
40 testonthread(^{
41 TestRoot *value;
42
43 PUSH_POOL {
44 value = [TestRoot new];
45 testassert(value);
46 oldObject = [Weak new];
47 testassert(oldObject);
48
49 oldObject->value = value;
50 testassert(oldObject->value == value);
51
52 newObject = [oldObject copy];
53 testassert(newObject);
54 testassert(newObject->value == oldObject->value);
55
56 newObject->value = nil;
57 testassert(newObject->value == nil);
58 testassert(oldObject->value == value);
59 } POP_POOL;
60
61 testcollect();
62 TestRootDealloc = 0;
63 TestRootFinalize = 0;
64 RELEASE_VAR(value);
65 });
66
67 testcollect();
68 testassert(TestRootDealloc || TestRootFinalize);
69
70 #if defined(__OBJC_GC__) || __has_feature(objc_arc)
71 testassert(oldObject->value == nil);
72 #else
73 testassert(oldObject->value != nil);
74 #endif
75 testassert(newObject->value == nil);
76
77 RELEASE_VAR(newObject);
78 RELEASE_VAR(oldObject);
79
80 succeed(__FILE__);
81 return 0;
82 }
83
84 #endif