1 /* Test the Modern GNU Objective-C Runtime API.
3 This is test 'ivar', covering all functions starting with 'ivar'. */
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 ivar_getName () ...\n";
52 Ivar ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
54 if (strcmp (ivar_getName (ivar), "variable_ivar") != 0)
57 ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
63 std::cout << "Testing ivar_getOffset () ...\n";
65 Ivar ivar = class_getInstanceVariable (objc_getClass ("MyRootClass"),
67 if (ivar_getOffset (ivar) != 0)
71 std::cout << "Testing ivar_getTypeEncoding () ...\n";
73 Ivar ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
75 if (strcmp (ivar_getTypeEncoding (ivar), "@") != 0)