]> git.saurik.com Git - apple/objc4.git/blob - test/property.m
d62f45ff6690cab31f1d5d8c2f8b1f5dbb70d0b6
[apple/objc4.git] / test / property.m
1 #include "test.h"
2 #include <stdint.h>
3 #include <string.h>
4 #include <objc/objc-runtime.h>
5
6 @interface Super {
7 @public
8 id isa;
9 char superIvar;
10 }
11
12 @property(readonly) char superProp;
13 @end
14
15 @implementation Super
16 @synthesize superProp = superIvar;
17 +(void)initialize { }
18 +class { return self; }
19 @end
20
21
22 @interface Sub : Super {
23 @public
24 uintptr_t subIvar;
25 }
26 @property(readonly) uintptr_t subProp;
27 @end
28
29 @implementation Sub
30 @synthesize subProp = subIvar;
31 @end
32
33
34 int main()
35 {
36 /*
37 Runtime layout of Sub:
38 [0] isa
39 [1] superIvar
40 [2] subIvar
41 */
42
43 objc_property_t prop;
44
45 prop = class_getProperty([Sub class], "subProp");
46 testassert(prop);
47
48 prop = class_getProperty([Super class], "superProp");
49 testassert(prop);
50 testassert(prop == class_getProperty([Sub class], "superProp"));
51
52 prop = class_getProperty([Super class], "subProp");
53 testassert(!prop);
54
55 prop = class_getProperty([Sub class]->isa, "subProp");
56 testassert(!prop);
57
58
59 testassert(NULL == class_getProperty(NULL, "foo"));
60 testassert(NULL == class_getProperty([Sub class], NULL));
61 testassert(NULL == class_getProperty(NULL, NULL));
62
63 succeed(__FILE__);
64 return 0;
65 }