]> git.saurik.com Git - apple/objc4.git/blob - test/layout.m
objc4-680.tar.gz
[apple/objc4.git] / test / layout.m
1 // TEST_CONFIG MEM=gc OS=macosx
2
3 #include "test.h"
4 #include <string.h>
5 #include <objc/objc-runtime.h>
6
7 @class NSObject;
8
9 void printlayout(const char *name, const uint8_t *layout)
10 {
11 testprintf("%s: ", name);
12
13 if (!layout) {
14 testprintf("NULL\n");
15 return;
16 }
17
18 const uint8_t *c;
19 for (c = layout; *c; c++) {
20 testprintf("%02x ", *c);
21 }
22
23 testprintf("00\n");
24 }
25
26 OBJC_ROOT_CLASS
27 @interface Super { id isa; } @end
28 @implementation Super @end
29
30
31 // strong: 0c 00 (0a00 without structs)
32 // weak: NULL
33 @interface AllScanned : Super {
34 id id1;
35 NSObject *o1;
36 __strong void *v1;
37 __strong intptr_t *i1;
38 __strong long *l1;
39 /* fixme
40 struct {
41 id id1;
42 id id2;
43 } str;
44 */
45 id arr1[4];
46 }
47 @end
48 @implementation AllScanned @end
49
50 // strong: 00
51 // weak: 1b 00 (18 00 without structs)
52 @interface AllWeak : Super {
53 __weak id id1;
54 __weak NSObject *o1;
55 __weak void *v1;
56 __weak intptr_t *i1;
57 __weak long *l1;
58 /* fixme
59 struct {
60 __weak id id1;
61 __weak id id2;
62 } str;
63 */
64 __weak id arr1[4];
65 }
66 @end
67 @implementation AllWeak @end
68
69 // strong: ""
70 // weak: NULL
71 OBJC_ROOT_CLASS
72 @interface NoScanned { long i; } @end
73 @implementation NoScanned @end
74
75 int main()
76 {
77 const uint8_t *layout;
78
79 layout = class_getIvarLayout(objc_getClass("AllScanned"));
80 printlayout("AllScanned", layout);
81 layout = class_getWeakIvarLayout(objc_getClass("AllScanned"));
82 printlayout("AllScanned weak", layout);
83 // testassert(0 == strcmp(layout, "\x0a"));
84
85 layout = class_getIvarLayout(objc_getClass("AllWeak"));
86 printlayout("AllWeak", layout);
87 layout = class_getWeakIvarLayout(objc_getClass("AllWeak"));
88 printlayout("AllWeak weak", layout);
89 // testassert(0 == strcmp(layout, ""));
90
91 layout = class_getIvarLayout(objc_getClass("NoScanned"));
92 printlayout("NoScanned", layout);
93 // testassert(0 == strcmp(layout, ""));
94
95 succeed(__FILE__);
96 return 0;
97 }