3 #include <malloc/malloc.h>
4 #include <objc/objc-runtime.h>
11 @protocol SubProps <SuperProps>
24 @protocol NoProps @end
26 static int isNamed(objc_property_t p, const char *name)
28 return (0 == strcmp(name, property_getName(p)));
33 objc_property_t *props;
37 proto = @protocol(SubProps);
41 props = protocol_copyPropertyList(proto, &count);
43 testassert(count == 2);
44 testassert(isNamed(props[0], "prop4"));
45 testassert(isNamed(props[1], "prop3"));
46 // props[] should be null-terminated
47 testassert(props[2] == NULL);
50 proto = @protocol(SuperProps);
54 props = protocol_copyPropertyList(proto, &count);
56 testassert(count == 2);
57 testassert(isNamed(props[0], "prop2"));
58 testassert(isNamed(props[1], "prop1"));
59 // props[] should be null-terminated
60 testassert(props[2] == NULL);
63 // Check null-termination - this property list block would be 16 bytes
64 // if it weren't for the terminator
65 proto = @protocol(FourProps);
69 props = protocol_copyPropertyList(proto, &count);
71 testassert(count == 4);
72 testassert(malloc_size(props) >= 5 * sizeof(objc_property_t));
73 testassert(props[3] != NULL);
74 testassert(props[4] == NULL);
77 // Check NULL count parameter
78 props = protocol_copyPropertyList(proto, NULL);
80 testassert(props[4] == NULL);
81 testassert(props[3] != NULL);
84 // Check NULL protocol parameter
86 props = protocol_copyPropertyList(NULL, &count);
88 testassert(count == 0);
90 // Check NULL protocol and count
91 props = protocol_copyPropertyList(NULL, NULL);
94 // Check protocol with no properties
95 proto = @protocol(NoProps);
99 props = protocol_copyPropertyList(proto, &count);
101 testassert(count == 0);