1 /* Test the Modern GNU Objective-C Runtime API.
3 This is test 'ivar', covering all functions starting with 'ivar'. */
6 /* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */
7 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
9 /* To get the modern GNU Objective-C Runtime API, you include
11 #include <objc/runtime.h>
16 @interface MyRootClass
23 @implementation MyRootClass
24 + alloc { return class_createInstance (self, 0); }
25 - init { return self; }
26 + initialize { return self; }
33 @protocol MySecondProtocol
34 - (id) setVariable: (id)value;
37 @interface MySubClass : MyRootClass <MyProtocol>
39 - (void) setVariable: (id)value;
43 @implementation MySubClass
44 - (void) setVariable: (id)value { variable_ivar = value; }
45 - (id) variable { return variable_ivar; }
49 int main(int argc, void **args)
51 /* Functions are tested in alphabetical order. */
53 printf ("Testing ivar_getName () ...\n");
55 Ivar ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
57 if (strcmp (ivar_getName (ivar), "variable_ivar") != 0)
60 ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
66 printf ("Testing ivar_getOffset () ...\n");
68 Ivar ivar = class_getInstanceVariable (objc_getClass ("MyRootClass"),
70 if (ivar_getOffset (ivar) != 0)
74 printf ("Testing ivar_getTypeEncoding () ...\n");
76 Ivar ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
78 if (strcmp (ivar_getTypeEncoding (ivar), "@") != 0)