1 /* Test the Modern GNU Objective-C Runtime API.
3 This is test 'protocol', covering all functions starting with 'protocol'. */
6 /* { dg-skip-if "" { *-*-* } { "-fnext-runtime" } { "" } } */
8 /* To get the modern GNU Objective-C Runtime API, you include
10 #include <objc/runtime.h>
15 @interface MyRootClass
21 @implementation MyRootClass
22 + alloc { return class_createInstance (self, 0); }
23 - init { return self; }
30 @protocol MySecondProtocol
31 - (id) setVariable: (id)value;
34 @protocol MyThirdProtocol <MySecondProtocol>
35 - (id) setAnotherVariable: (id)value;
38 @interface MySubClass : MyRootClass <MyProtocol>
40 - (void) setVariable: (id)value;
44 @implementation MySubClass
45 - (void) setVariable: (id)value { variable_ivar = value; }
46 - (id) variable { return variable_ivar; }
50 int main(int argc, void **args)
52 /* Functions are tested in alphabetical order. */
54 printf ("Testing protocol_conformsToProtocol ()...\n");
56 if (!protocol_conformsToProtocol (@protocol (MyProtocol),
57 @protocol (MyProtocol)))
60 if (!protocol_conformsToProtocol (@protocol (MyThirdProtocol),
61 @protocol (MySecondProtocol)))
64 if (protocol_conformsToProtocol (@protocol (MyProtocol),
65 @protocol (MySecondProtocol)))
69 printf ("Testing protocol_copyMethodDescriptionList ()...\n");
72 struct objc_method_description *list;
74 list = protocol_copyMethodDescriptionList (@protocol (MyThirdProtocol),
80 if (strcmp (sel_getName (list[0].name), "setAnotherVariable:") != 0)
83 if (list[1].name != NULL && list[1].types != NULL)
87 /* TODO: Test new ABI (when available). */
88 printf ("Testing protocol_copyPropertyList ()...\n");
93 list = protocol_copyPropertyList (@protocol (MyProtocol), &count);
95 if (count != 0 || list != NULL)
99 printf ("Testing protocol_copyProtocolList ()...\n");
104 list = protocol_copyProtocolList (@protocol (MyThirdProtocol), &count);
109 if (strcmp (protocol_getName (list[0]), "MySecondProtocol") != 0)
116 printf ("Testing protocol_getMethodDescription ()...\n");
118 struct objc_method_description description;
120 description = protocol_getMethodDescription (@protocol (MySecondProtocol),
121 @selector (setVariable:),
123 if (description.name == NULL && description.types == NULL)
126 if (strcmp (sel_getName (description.name), "setVariable:") != 0)
130 printf ("Testing protocol_getName ()...\n");
132 if (strcmp (protocol_getName (@protocol (MyProtocol)), "MyProtocol") != 0)
136 /* TODO: Test new ABI (when available). */
137 printf ("Testing protocol_getProperty ()...\n");
141 property = protocol_getProperty (objc_getProtocol ("MyProtocol"), "someProperty",
144 if (property != NULL)
148 printf ("Testing protocol_isEqual ()...\n");
150 if (!protocol_isEqual (@protocol (MyProtocol),
151 @protocol (MyProtocol)))
154 if (!protocol_isEqual (@protocol (MyProtocol),
155 objc_getProtocol ("MyProtocol")))