OSDN Git Service

In gcc/testsuite/:
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / gnu-api-2-ivar.m
1 /* Test the Modern GNU Objective-C Runtime API.
2
3   This is test 'ivar', covering all functions starting with 'ivar'.  */
4
5 /* { dg-do run } */
6 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
7
8 /* To get the modern GNU Objective-C Runtime API, you include
9    objc/runtime.h.  */
10 #include <objc/runtime.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
14
15 @interface MyRootClass
16 { Class isa; }
17 + alloc;
18 - init;
19 + initialize;
20 @end
21
22 @implementation MyRootClass
23 + alloc { return class_createInstance (self, 0); }
24 - init  { return self; }
25 + initialize { return self; }
26 @end
27
28 @protocol MyProtocol
29 - (id) variable;
30 @end
31
32 @protocol MySecondProtocol
33 - (id) setVariable: (id)value;
34 @end
35
36 @interface MySubClass : MyRootClass <MyProtocol>
37 { id variable_ivar; }
38 - (void) setVariable: (id)value;
39 - (id) variable;
40 @end
41
42 @implementation MySubClass
43 - (void) setVariable: (id)value { variable_ivar = value; }
44 - (id) variable { return variable_ivar; }
45 @end
46
47
48 int main(int argc, void **args)
49 {
50   /* Functions are tested in alphabetical order.  */
51
52   printf ("Testing ivar_getName () ...\n");
53   {
54     Ivar ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
55                                            "variable_ivar");
56    if (strcmp (ivar_getName (ivar), "variable_ivar") != 0)
57       abort ();
58
59    ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
60                                      "variable");
61    if (ivar != 0)
62       abort ();
63   }
64
65   printf ("Testing ivar_getOffset () ...\n");
66   {
67     Ivar ivar = class_getInstanceVariable (objc_getClass ("MyRootClass"),
68                                            "isa");
69     if (ivar_getOffset (ivar) != 0)
70       abort ();
71   }
72
73   printf ("Testing ivar_getTypeEncoding () ...\n");
74   {
75     Ivar ivar = class_getInstanceVariable (objc_getClass ("MySubClass"),
76                                            "variable_ivar");
77     if (strcmp (ivar_getTypeEncoding (ivar), "@") != 0)
78       abort ();
79   }
80
81   return 0;
82 }