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