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