]> git.saurik.com Git - apple/objc4.git/blob - test/objectCopy.m
objc4-680.tar.gz
[apple/objc4.git] / test / objectCopy.m
1 // TEST_CONFIG MEM=mrc,gc
2
3 #include "test.h"
4 #include <objc/NSObject.h>
5
6 @interface Test : NSObject {
7 @public
8 char bytes[32-sizeof(void*)];
9 }
10 @end
11 @implementation Test
12 @end
13
14
15 int main()
16 {
17 Test *o0 = [Test new];
18 [o0 retain];
19 Test *o1 = class_createInstance([Test class], 32);
20 [o1 retain];
21 id o2 = object_copy(o0, 0);
22 id o3 = object_copy(o1, 0);
23 id o4 = object_copy(o1, 32);
24 testassert(malloc_size(o0) == 32);
25 testassert(malloc_size(o1) == 64);
26 testassert(malloc_size(o2) == 32);
27 testassert(malloc_size(o3) == 32);
28 testassert(malloc_size(o4) == 64);
29 if (!objc_collecting_enabled()) {
30 testassert([o0 retainCount] == 2);
31 testassert([o1 retainCount] == 2);
32 testassert([o2 retainCount] == 1);
33 testassert([o3 retainCount] == 1);
34 testassert([o4 retainCount] == 1);
35 }
36 succeed(__FILE__);
37 }