]> git.saurik.com Git - apple/objc4.git/blob - test/layout.m
objc4-532.2.tar.gz
[apple/objc4.git] / test / layout.m
1 // TEST_CONFIG MEM=gc SDK=macos
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
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 @interface NoScanned { long i; } @end
72 @implementation NoScanned @end
73
74 int main()
75 {
76 const uint8_t *layout;
77
78 layout = class_getIvarLayout(objc_getClass("AllScanned"));
79 printlayout("AllScanned", layout);
80 layout = class_getWeakIvarLayout(objc_getClass("AllScanned"));
81 printlayout("AllScanned weak", layout);
82 // testassert(0 == strcmp(layout, "\x0a"));
83
84 layout = class_getIvarLayout(objc_getClass("AllWeak"));
85 printlayout("AllWeak", layout);
86 layout = class_getWeakIvarLayout(objc_getClass("AllWeak"));
87 printlayout("AllWeak weak", layout);
88 // testassert(0 == strcmp(layout, ""));
89
90 layout = class_getIvarLayout(objc_getClass("NoScanned"));
91 printlayout("NoScanned", layout);
92 // testassert(0 == strcmp(layout, ""));
93
94 succeed(__FILE__);
95 return 0;
96 }