6 #include <objc/objc-runtime.h>
17 +class { return self; }
18 +new { return class_createInstance(self, 0); }
22 @interface Sub : Super {
28 @implementation Sub @end
34 Runtime layout of Sub:
44 testassert(((uintptr_t *)sub)[2] == 10);
46 ivar = class_getInstanceVariable([Sub class], "subIvar");
48 testassert(2*sizeof(intptr_t) == (size_t)ivar_getOffset(ivar));
49 testassert(0 == strcmp(ivar_getName(ivar), "subIvar"));
51 testassert(0 == strcmp(ivar_getTypeEncoding(ivar), "Q"));
53 testassert(0 == strcmp(ivar_getTypeEncoding(ivar), "L"));
55 testassert(0 == strcmp(ivar_getTypeEncoding(ivar), "I"));
58 ivar = class_getInstanceVariable([Super class], "superIvar");
60 testassert(sizeof(intptr_t) == (size_t)ivar_getOffset(ivar));
61 testassert(0 == strcmp(ivar_getName(ivar), "superIvar"));
62 testassert(0 == strcmp(ivar_getTypeEncoding(ivar), "c"));
63 testassert(ivar == class_getInstanceVariable([Sub class], "superIvar"));
65 ivar = class_getInstanceVariable([Super class], "subIvar");
68 ivar = class_getInstanceVariable([Sub class]->isa, "subIvar");
74 object_getInstanceVariable(sub, "subIvar", (void **)&value);
75 testassert(value == 10);
77 object_setInstanceVariable(sub, "subIvar", (void *)11);
78 testassert(sub->subIvar == 11);
80 ivar = class_getInstanceVariable([Sub class], "subIvar");
81 object_setIvar(sub, ivar, (id)12);
82 testassert(sub->subIvar == 12);
83 testassert((id)12 == object_getIvar(sub, ivar));
85 ivar = class_getInstanceVariable([Sub class], "subIvar");
86 testassert(ivar == object_getInstanceVariable(sub, "subIvar", NULL));
89 testassert(NULL == class_getInstanceVariable(NULL, "foo"));
90 testassert(NULL == class_getInstanceVariable([Sub class], NULL));
91 testassert(NULL == class_getInstanceVariable(NULL, NULL));
93 testassert(NULL == object_getIvar(sub, NULL));
94 testassert(NULL == object_getIvar(NULL, ivar));
95 testassert(NULL == object_getIvar(NULL, NULL));
97 testassert(NULL == object_getInstanceVariable(sub, NULL, NULL));
98 testassert(NULL == object_getInstanceVariable(NULL, "foo", NULL));
99 testassert(NULL == object_getInstanceVariable(NULL, NULL, NULL));
101 testassert(NULL == object_getInstanceVariable(sub, NULL, (void **)&value));
102 testassert(value == 0);
104 testassert(NULL == object_getInstanceVariable(NULL, "foo", (void **)&value));
105 testassert(value == 0);
107 testassert(NULL == object_getInstanceVariable(NULL, NULL, (void **)&value));
108 testassert(value == 0);
110 object_setIvar(sub, NULL, NULL);
111 object_setIvar(NULL, ivar, NULL);
112 object_setIvar(NULL, NULL, NULL);
114 testassert(NULL == object_setInstanceVariable(sub, NULL, NULL));
115 testassert(NULL == object_setInstanceVariable(NULL, "foo", NULL));
116 testassert(NULL == object_setInstanceVariable(NULL, NULL, NULL));