]> git.saurik.com Git - apple/objc4.git/blame - test/weakcopy.m
objc4-818.2.tar.gz
[apple/objc4.git] / test / weakcopy.m
CommitLineData
13ba007e
A
1// TEST_CFLAGS -fobjc-weak
2
3#include "test.h"
4
5#include "testroot.i"
6#include <stdint.h>
7#include <string.h>
8#include <objc/objc-runtime.h>
9
10@interface Weak : TestRoot {
11 @public
12 __weak id value;
13}
14@end
15@implementation Weak
16@end
17
18Weak *oldObject;
19Weak *newObject;
20
21int main()
22{
23 testonthread(^{
24 TestRoot *value;
25
26 PUSH_POOL {
27 value = [TestRoot new];
28 testassert(value);
29 oldObject = [Weak new];
30 testassert(oldObject);
31
32 oldObject->value = value;
33 testassert(oldObject->value == value);
34
35 newObject = [oldObject copy];
36 testassert(newObject);
37 testassert(newObject->value == oldObject->value);
38
39 newObject->value = nil;
40 testassert(newObject->value == nil);
41 testassert(oldObject->value == value);
42 } POP_POOL;
43
44 testcollect();
45 TestRootDealloc = 0;
46 RELEASE_VAR(value);
47 });
48
49 testcollect();
50 testassert(TestRootDealloc);
51
52#if __has_feature(objc_arc_weak)
53 testassert(oldObject->value == nil);
54#endif
55 testassert(newObject->value == nil);
56
57 RELEASE_VAR(newObject);
58 RELEASE_VAR(oldObject);
59
60 succeed(__FILE__);
61 return 0;
62}