]> git.saurik.com Git - apple/objc4.git/blob - test/instanceSize.m
objc4-787.1.tar.gz
[apple/objc4.git] / test / instanceSize.m
1 // TEST_CONFIG
2
3 #include "test.h"
4 #include "testroot.i"
5 #include <objc/runtime.h>
6
7
8 @interface Sub1 : TestRoot {
9 // id isa; // 0..4
10 BOOL b; // 4..5
11 }
12 @end
13
14 @implementation Sub1 @end
15
16 @interface Sub2 : Sub1 {
17 // id isa // 0..4 0..8
18 // BOOL b // 4..5 8..9
19 BOOL b2; // 5..6 9..10
20 id o; // 8..12 16..24
21 }
22 @end
23 @implementation Sub2 @end
24
25 @interface Sub3 : Sub1 {
26 // id isa; // 0..4 0..8
27 // BOOL b; // 4..5 8..9
28 id o; // 8..12 16..24
29 BOOL b2; // 12..13 24..25
30 }
31 @end
32 @implementation Sub3 @end
33
34 int main()
35 {
36 testassert(sizeof(id) == class_getInstanceSize([TestRoot class]));
37 testassert(2*sizeof(id) == class_getInstanceSize([Sub1 class]));
38 testassert(3*sizeof(id) == class_getInstanceSize([Sub2 class]));
39 testassert(4*sizeof(id) == class_getInstanceSize([Sub3 class]));
40
41 #if !__has_feature(objc_arc)
42 id o;
43
44 o = [TestRoot new];
45 testassert(object_getIndexedIvars(o) == (char *)o + class_getInstanceSize(object_getClass(o)));
46 RELEASE_VAR(o);
47 o = [Sub1 new];
48 testassert(object_getIndexedIvars(o) == (char *)o + class_getInstanceSize(object_getClass(o)));
49 RELEASE_VAR(o);
50 o = [Sub2 new];
51 testassert(object_getIndexedIvars(o) == (char *)o + class_getInstanceSize(object_getClass(o)));
52 RELEASE_VAR(o);
53 o = [Sub3 new];
54 testassert(object_getIndexedIvars(o) == (char *)o + class_getInstanceSize(object_getClass(o)));
55 RELEASE_VAR(o);
56 #endif
57
58 succeed(__FILE__);
59 }