3 #include <malloc/malloc.h>
4 #include <objc/objc-runtime.h>
6 @interface SuperProps { id isa; int prop1; int prop2; }
10 @implementation SuperProps
15 @interface SubProps : SuperProps { int prop3; int prop4; }
19 @implementation SubProps
25 @interface FourProps { int prop1; int prop2; int prop3; int prop4; }
31 @implementation FourProps
38 @interface NoProps @end
39 @implementation NoProps @end
41 static int isNamed(objc_property_t p, const char *name)
43 return (0 == strcmp(name, property_getName(p)));
48 objc_property_t *props;
52 cls = objc_getClass("SubProps");
56 props = class_copyPropertyList(cls, &count);
58 testassert(count == 2);
59 testassert((isNamed(props[0], "prop3") && isNamed(props[1], "prop4")) ||
60 (isNamed(props[1], "prop3") && isNamed(props[0], "prop4")));
61 // props[] should be null-terminated
62 testassert(props[2] == NULL);
65 cls = objc_getClass("SuperProps");
69 props = class_copyPropertyList(cls, &count);
71 testassert(count == 2);
72 testassert((isNamed(props[0], "prop1") && isNamed(props[1], "prop2")) ||
73 (isNamed(props[1], "prop1") && isNamed(props[0], "prop2")));
74 // props[] should be null-terminated
75 testassert(props[2] == NULL);
78 // Check null-termination - this property list block would be 16 bytes
79 // if it weren't for the terminator
80 cls = objc_getClass("FourProps");
84 props = class_copyPropertyList(cls, &count);
86 testassert(count == 4);
87 testassert(malloc_size(props) >= 5 * sizeof(objc_property_t));
88 testassert(props[3] != NULL);
89 testassert(props[4] == NULL);
92 // Check NULL count parameter
93 props = class_copyPropertyList(cls, NULL);
95 testassert(props[4] == NULL);
96 testassert(props[3] != NULL);
99 // Check NULL class parameter
101 props = class_copyPropertyList(NULL, &count);
103 testassert(count == 0);
105 // Check NULL class and count
106 props = class_copyPropertyList(NULL, NULL);
109 // Check class with no properties
110 cls = objc_getClass("NoProps");
114 props = class_copyPropertyList(cls, &count);
116 testassert(count == 0);