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" } { "" } } */
8 /* { dg-additional-options "-Wno-objc-root-class" } */
10 /* To get the modern GNU Objective-C Runtime API, you include
12 #include <objc/runtime.h>
17 @interface MyRootClass
24 @implementation MyRootClass
25 + alloc { return class_createInstance (self, 0); }
26 - init { return self; }
27 + initialize { return self; }
34 @protocol MySecondProtocol
35 - (id) setVariable: (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 ivar_getName () ...\n");
56 Ivar ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
58 if (strcmp (ivar_getName (ivar), "variable_ivar") != 0)
61 ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
67 printf ("Testing ivar_getOffset () ...\n");
69 Ivar ivar = class_getInstanceVariable (objc_getClass ("MyRootClass"),
71 if (ivar_getOffset (ivar) != 0)
75 printf ("Testing ivar_getTypeEncoding () ...\n");
77 Ivar ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
79 if (strcmp (ivar_getTypeEncoding (ivar), "@") != 0)