5 #include <malloc/malloc.h>
6 #include <objc/objc-runtime.h>
9 @interface SuperProps { id isa; int prop1; int prop2; }
13 @implementation SuperProps
18 @interface SubProps : SuperProps { int prop3; int prop4; }
22 @implementation SubProps
28 @interface FourProps { int prop1; int prop2; int prop3; int prop4; }
34 @implementation FourProps
42 @interface NoProps @end
43 @implementation NoProps @end
45 static int isNamed(objc_property_t p, const char *name)
47 return (0 == strcmp(name, property_getName(p)));
52 objc_property_t *props;
56 cls = objc_getClass("SubProps");
60 props = class_copyPropertyList(cls, &count);
62 testassert(count == 2);
63 testassert((isNamed(props[0], "prop3") && isNamed(props[1], "prop4")) ||
64 (isNamed(props[1], "prop3") && isNamed(props[0], "prop4")));
65 // props[] should be null-terminated
66 testassert(props[2] == NULL);
69 cls = objc_getClass("SuperProps");
73 props = class_copyPropertyList(cls, &count);
75 testassert(count == 2);
76 testassert((isNamed(props[0], "prop1") && isNamed(props[1], "prop2")) ||
77 (isNamed(props[1], "prop1") && isNamed(props[0], "prop2")));
78 // props[] should be null-terminated
79 testassert(props[2] == NULL);
82 // Check null-termination - this property list block would be 16 bytes
83 // if it weren't for the terminator
84 cls = objc_getClass("FourProps");
88 props = class_copyPropertyList(cls, &count);
90 testassert(count == 4);
91 testassert(malloc_size(props) >= 5 * sizeof(objc_property_t));
92 testassert(props[3] != NULL);
93 testassert(props[4] == NULL);
96 // Check NULL count parameter
97 props = class_copyPropertyList(cls, NULL);
99 testassert(props[4] == NULL);
100 testassert(props[3] != NULL);
103 // Check NULL class parameter
105 props = class_copyPropertyList(NULL, &count);
107 testassert(count == 0);
109 // Check NULL class and count
110 props = class_copyPropertyList(NULL, NULL);
113 // Check class with no properties
114 cls = objc_getClass("NoProps");
118 props = class_copyPropertyList(cls, &count);
120 testassert(count == 0);