1 // TEST_CFLAGS -framework Foundation
2 // need Foundation to get NSObject compatibility additions for class Protocol
3 // because ARC calls [protocol retain]
6 .*protocol_copyMethodList.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\]
7 .*protocol_copyMethodList.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\]
8 .*protocol_copyMethodList.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\]
9 .*protocol_copyMethodList.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\]
15 #include <malloc/malloc.h>
16 #include <objc/objc-runtime.h>
18 @protocol SuperMethods
19 +(void)SuperMethodClass;
20 +(void)SuperMethodClass2;
21 -(void)SuperMethodInstance;
22 -(void)SuperMethodInstance2;
26 +(void)SubMethodClass;
27 +(void)SubMethodClass2;
28 -(void)SubMethodInstance;
29 -(void)SubMethodInstance2;
32 @protocol SuperOptionalMethods
34 +(void)SuperOptMethodClass;
35 +(void)SuperOptMethodClass2;
36 -(void)SuperOptMethodInstance;
37 -(void)SuperOptMethodInstance2;
40 @protocol SubOptionalMethods <SuperOptionalMethods>
42 +(void)SubOptMethodClass;
43 +(void)SubOptMethodClass2;
44 -(void)SubOptMethodInstance;
45 -(void)SubOptMethodInstance2;
48 @protocol NoMethods @end
50 static int isNamed(struct objc_method_description m, const char *name)
52 return (m.name == sel_registerName(name));
57 struct objc_method_description *methods;
61 proto = @protocol(SubMethods);
64 // Check required methods
66 methods = protocol_copyMethodDescriptionList(proto, YES, YES, &count);
68 testassert(count == 2);
69 testassert((isNamed(methods[0], "SubMethodInstance") &&
70 isNamed(methods[1], "SubMethodInstance2"))
72 (isNamed(methods[1], "SubMethodInstance") &&
73 isNamed(methods[0], "SubMethodInstance2")));
77 methods = protocol_copyMethodDescriptionList(proto, YES, NO, &count);
79 testassert(count == 2);
80 testassert((isNamed(methods[0], "SubMethodClass") &&
81 isNamed(methods[1], "SubMethodClass2"))
83 (isNamed(methods[1], "SubMethodClass") &&
84 isNamed(methods[0], "SubMethodClass2")));
87 // Check lack of optional methods
89 methods = protocol_copyMethodDescriptionList(proto, NO, YES, &count);
91 testassert(count == 0);
93 methods = protocol_copyMethodDescriptionList(proto, NO, NO, &count);
95 testassert(count == 0);
98 proto = @protocol(SubOptionalMethods);
101 // Check optional methods
103 methods = protocol_copyMethodDescriptionList(proto, NO, YES, &count);
105 testassert(count == 2);
106 testassert((isNamed(methods[0], "SubOptMethodInstance") &&
107 isNamed(methods[1], "SubOptMethodInstance2"))
109 (isNamed(methods[1], "SubOptMethodInstance") &&
110 isNamed(methods[0], "SubOptMethodInstance2")));
114 methods = protocol_copyMethodDescriptionList(proto, NO, NO, &count);
116 testassert(count == 2);
117 testassert((isNamed(methods[0], "SubOptMethodClass") &&
118 isNamed(methods[1], "SubOptMethodClass2"))
120 (isNamed(methods[1], "SubOptMethodClass") &&
121 isNamed(methods[0], "SubOptMethodClass2")));
124 // Check lack of required methods
126 methods = protocol_copyMethodDescriptionList(proto, YES, YES, &count);
127 testassert(!methods);
128 testassert(count == 0);
130 methods = protocol_copyMethodDescriptionList(proto, YES, NO, &count);
131 testassert(!methods);
132 testassert(count == 0);
135 // Check NULL protocol parameter
137 methods = protocol_copyMethodDescriptionList(NULL, YES, YES, &count);
138 testassert(!methods);
139 testassert(count == 0);
141 methods = protocol_copyMethodDescriptionList(NULL, YES, NO, &count);
142 testassert(!methods);
143 testassert(count == 0);
145 methods = protocol_copyMethodDescriptionList(NULL, NO, YES, &count);
146 testassert(!methods);
147 testassert(count == 0);
149 methods = protocol_copyMethodDescriptionList(NULL, NO, NO, &count);
150 testassert(!methods);
151 testassert(count == 0);