5 #include <malloc/malloc.h>
6 #include <objc/objc-runtime.h>
13 @protocol SubProps <SuperProps>
26 @protocol NoProps @end
28 static int isNamed(objc_property_t p, const char *name)
30 return (0 == strcmp(name, property_getName(p)));
35 objc_property_t *props;
39 proto = @protocol(SubProps);
43 props = protocol_copyPropertyList(proto, &count);
45 testassert(count == 2);
46 testassert((isNamed(props[0], "prop4") && isNamed(props[1], "prop3")) ||
47 (isNamed(props[0], "prop3") && isNamed(props[1], "prop4")));
48 // props[] should be null-terminated
49 testassert(props[2] == NULL);
52 proto = @protocol(SuperProps);
56 props = protocol_copyPropertyList(proto, &count);
58 testassert(count == 2);
59 testassert((isNamed(props[0], "prop1") && isNamed(props[1], "prop2")) ||
60 (isNamed(props[0], "prop2") && isNamed(props[1], "prop1")));
61 // props[] should be null-terminated
62 testassert(props[2] == NULL);
65 // Check null-termination - this property list block would be 16 bytes
66 // if it weren't for the terminator
67 proto = @protocol(FourProps);
71 props = protocol_copyPropertyList(proto, &count);
73 testassert(count == 4);
74 testassert(malloc_size(props) >= 5 * sizeof(objc_property_t));
75 testassert(props[3] != NULL);
76 testassert(props[4] == NULL);
79 // Check NULL count parameter
80 props = protocol_copyPropertyList(proto, NULL);
82 testassert(props[4] == NULL);
83 testassert(props[3] != NULL);
86 // Check NULL protocol parameter
88 props = protocol_copyPropertyList(NULL, &count);
90 testassert(count == 0);
92 // Check NULL protocol and count
93 props = protocol_copyPropertyList(NULL, NULL);
96 // Check protocol with no properties
97 proto = @protocol(NoProps);
101 props = protocol_copyPropertyList(proto, &count);
103 testassert(count == 0);