1 /* Test the Modern GNU Objective-C Runtime API.
3 This is test 'ivar', covering all functions starting with 'ivar'. */
6 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
8 /* To get the modern GNU Objective-C Runtime API, you include
10 #include <objc/runtime.h>
15 @interface MyRootClass
22 @implementation MyRootClass
23 + alloc { return class_createInstance (self, 0); }
24 - init { return self; }
25 + initialize { return self; }
32 @protocol MySecondProtocol
33 - (id) setVariable: (id)value;
36 @interface MySubClass : MyRootClass <MyProtocol>
38 - (void) setVariable: (id)value;
42 @implementation MySubClass
43 - (void) setVariable: (id)value { variable_ivar = value; }
44 - (id) variable { return variable_ivar; }
48 int main(int argc, void **args)
50 /* Functions are tested in alphabetical order. */
52 printf ("Testing ivar_getName () ...\n");
54 Ivar ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
56 if (strcmp (ivar_getName (ivar), "variable_ivar") != 0)
59 ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
65 printf ("Testing ivar_getOffset () ...\n");
67 Ivar ivar = class_getInstanceVariable (objc_getClass ("MyRootClass"),
69 if (ivar_getOffset (ivar) != 0)
73 printf ("Testing ivar_getTypeEncoding () ...\n");
75 Ivar ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
77 if (strcmp (ivar_getTypeEncoding (ivar), "@") != 0)