5 #include <malloc/malloc.h>
6 #include <objc/objc-runtime.h>
8 @interface SuperProps { id isa; int prop1; int prop2; }
12 @implementation SuperProps
17 @interface SubProps : SuperProps { int prop3; int prop4; }
21 @implementation SubProps
27 @interface FourProps { int prop1; int prop2; int prop3; int prop4; }
33 @implementation FourProps
40 @interface NoProps @end
41 @implementation NoProps @end
43 static int isNamed(objc_property_t p, const char *name)
45 return (0 == strcmp(name, property_getName(p)));
50 objc_property_t *props;
54 cls = objc_getClass("SubProps");
58 props = class_copyPropertyList(cls, &count);
60 testassert(count == 2);
61 testassert((isNamed(props[0], "prop3") && isNamed(props[1], "prop4")) ||
62 (isNamed(props[1], "prop3") && isNamed(props[0], "prop4")));
63 // props[] should be null-terminated
64 testassert(props[2] == NULL);
67 cls = objc_getClass("SuperProps");
71 props = class_copyPropertyList(cls, &count);
73 testassert(count == 2);
74 testassert((isNamed(props[0], "prop1") && isNamed(props[1], "prop2")) ||
75 (isNamed(props[1], "prop1") && isNamed(props[0], "prop2")));
76 // props[] should be null-terminated
77 testassert(props[2] == NULL);
80 // Check null-termination - this property list block would be 16 bytes
81 // if it weren't for the terminator
82 cls = objc_getClass("FourProps");
86 props = class_copyPropertyList(cls, &count);
88 testassert(count == 4);
89 testassert(malloc_size(props) >= 5 * sizeof(objc_property_t));
90 testassert(props[3] != NULL);
91 testassert(props[4] == NULL);
94 // Check NULL count parameter
95 props = class_copyPropertyList(cls, NULL);
97 testassert(props[4] == NULL);
98 testassert(props[3] != NULL);
101 // Check NULL class parameter
103 props = class_copyPropertyList(NULL, &count);
105 testassert(count == 0);
107 // Check NULL class and count
108 props = class_copyPropertyList(NULL, NULL);
111 // Check class with no properties
112 cls = objc_getClass("NoProps");
116 props = class_copyPropertyList(cls, &count);
118 testassert(count == 0);