]> git.saurik.com Git - apple/objc4.git/blob - test/association.m
5d1536a19a39aa2ee55e62ce742836b728d5132c
[apple/objc4.git] / test / association.m
1 // TEST_CFLAGS -framework Foundation
2
3 #include "test.h"
4 #include <Foundation/Foundation.h>
5 #include <objc/runtime.h>
6
7 static int values;
8 static int subs;
9
10 static const char *key = "key";
11
12
13 @interface Value : NSObject @end
14 @interface Super : NSObject @end
15 @interface Sub : NSObject @end
16
17 @implementation Super
18 -(id) init
19 {
20 // rdar://8270243 don't lose associations after isa swizzling
21
22 id value = [Value new];
23 objc_setAssociatedObject(self, &key, value, OBJC_ASSOCIATION_RETAIN);
24 [value release];
25
26 object_setClass(self, [Sub class]);
27
28 return self;
29 }
30
31 @end
32
33 @implementation Sub
34 -(void) dealloc
35 {
36 subs++;
37 [super dealloc];
38 }
39 -(void) finalize
40 {
41 subs++;
42 [super finalize];
43 }
44 @end
45
46 @implementation Value
47 -(void) dealloc {
48 values++;
49 [super dealloc];
50 }
51 -(void) finalize {
52 values++;
53 [super finalize];
54 }
55 @end
56
57 int main()
58 {
59 int i;
60 for (i = 0; i < 100; i++) {
61 [[[Super alloc] init] release];
62 }
63
64 testcollect();
65
66 testassert(subs > 0);
67 testassert(subs == values);
68
69 succeed(__FILE__);
70 }