1 // TEST_CFLAGS -framework Foundation
2 // need Foundation to get NSObject compatibility additions for class Protocol
3 // because ARC calls [protocol retain]
7 #include <malloc/malloc.h>
8 #include <objc/runtime.h>
15 @protocol SubProps <SuperProps>
28 @protocol NoProps @end
30 static int isNamed(objc_property_t p, const char *name)
32 return (0 == strcmp(name, property_getName(p)));
37 objc_property_t *props;
41 proto = @protocol(SubProps);
45 props = protocol_copyPropertyList(proto, &count);
47 testassert(count == 2);
48 testassert((isNamed(props[0], "prop4") && isNamed(props[1], "prop3")) ||
49 (isNamed(props[0], "prop3") && isNamed(props[1], "prop4")));
50 // props[] should be null-terminated
51 testassert(props[2] == NULL);
54 proto = @protocol(SuperProps);
58 props = protocol_copyPropertyList(proto, &count);
60 testassert(count == 2);
61 testassert((isNamed(props[0], "prop1") && isNamed(props[1], "prop2")) ||
62 (isNamed(props[0], "prop2") && isNamed(props[1], "prop1")));
63 // props[] should be null-terminated
64 testassert(props[2] == NULL);
67 // Check null-termination - this property list block would be 16 bytes
68 // if it weren't for the terminator
69 proto = @protocol(FourProps);
73 props = protocol_copyPropertyList(proto, &count);
75 testassert(count == 4);
76 testassert(malloc_size(props) >= 5 * sizeof(objc_property_t));
77 testassert(props[3] != NULL);
78 testassert(props[4] == NULL);
81 // Check NULL count parameter
82 props = protocol_copyPropertyList(proto, NULL);
84 testassert(props[4] == NULL);
85 testassert(props[3] != NULL);
88 // Check NULL protocol parameter
90 props = protocol_copyPropertyList(NULL, &count);
92 testassert(count == 0);
94 // Check NULL protocol and count
95 props = protocol_copyPropertyList(NULL, NULL);
98 // Check protocol with no properties
99 proto = @protocol(NoProps);
103 props = protocol_copyPropertyList(proto, &count);
105 testassert(count == 0);