]> git.saurik.com Git - apple/objc4.git/blob - test/property.m
objc4-532.tar.gz
[apple/objc4.git] / test / property.m
1 // TEST_CONFIG
2
3 #include "test.h"
4 #include "testroot.i"
5 #include <stdint.h>
6 #include <string.h>
7 #include <objc/objc-runtime.h>
8
9 @interface Super : TestRoot {
10 @public
11 char superIvar;
12 }
13
14 @property(readonly) char superProp;
15 @end
16
17 @implementation Super
18 @synthesize superProp = superIvar;
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(object_getClass([Sub class]), "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 }