1 /* Test the Modern GNU Objective-C Runtime API.
3 This is test 'sel', covering all functions starting with 'sel'. */
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 @interface MySubClass : MyRootClass <MyProtocol>
36 - (void) setVariable: (id)value;
40 @implementation MySubClass
41 - (void) setVariable: (id)value { variable_ivar = value; }
42 - (id) variable { return variable_ivar; }
48 /* Functions are tested in alphabetical order. */
50 std::cout << "Testing sel_getName () ...\n";
52 if (std::strcmp (sel_getName (@selector (variable)), "variable") != 0)
55 if (std::strcmp (sel_getName (NULL), "<null selector>") != 0)
59 std::cout << "Testing sel_getType () ...\n";
61 /* Get a selector from a real class, so it has interesting
63 Method method = class_getInstanceMethod (objc_getClass ("MySubClass"),
64 @selector (variable));
66 if (std::strcmp (sel_getType (method_getName (method)), method_getTypeEncoding (method)) != 0)
70 std::cout << "Testing sel_getUid () ...\n";
72 if (std::strcmp (sel_getName (sel_getUid ("myMethod")), "myMethod") != 0)
76 std::cout << "Testing sel_isEqual () ...\n";
78 if (! sel_isEqual (@selector (setVariable:), @selector (setVariable:)))
82 std::cout << "Testing sel_registerName () ...\n";
84 if (std::strcmp (sel_getName (sel_registerName ("myMethod")), "myMethod") != 0)
88 std::cout << "Testing set_registerTypedName () ...\n";
90 const char *types = method_getTypeEncoding (class_getInstanceMethod
91 (objc_getClass ("MySubClass"),
92 @selector (variable)));
93 SEL selector = sel_registerTypedName ("aMethod", types);
95 if (std::strcmp (sel_getName (selector), "aMethod") != 0)
98 if (std::strcmp (sel_getType (selector), types) != 0)