Merge from mainline (168000:168310).
[official-gcc/graphite-test-results.git] / gcc / testsuite / obj-c++.dg / gnu-api-2-property.mm
blob0279124dcc099cdc4df868357e6c7d1550a291d2
1 /* Test the Modern GNU Objective-C Runtime API.
3   This is test 'property', covering all functions starting with 'property'.  */
5 /* { dg-do run } */
7 /* To get the modern GNU Objective-C Runtime API, you include
8    objc/runtime.h.  */
9 #include <objc/runtime.h>
10 #include <stdlib.h>
11 #include <iostream>
12 #include <cstring>
14 @interface MyRootClass
15 { Class isa; }
16 + alloc;
17 - init;
18 + initialize;
19 @end
21 @implementation MyRootClass
22 + alloc { return class_createInstance (self, 0); }
23 - init  { return self; }
24 + initialize { return self; }
25 @end
27 @protocol MyProtocol
28 - (id) variable;
29 @end
31 @protocol MySecondProtocol
32 - (id) setVariable: (id)value;
33 @end
35 @interface MySubClass : MyRootClass <MyProtocol>
36 { id variable_ivar; }
37 - (void) setVariable: (id)value;
38 - (id) variable;
39 @end
41 @implementation MySubClass
42 - (void) setVariable: (id)value { variable_ivar = value; }
43 - (id) variable { return variable_ivar; }
44 @end
47 int main ()
49   /* Functions are tested in alphabetical order.  */
51   /* TODO: Test new ABI (when available).  */
52   std::cout << "Testing property_getAttributes () ...\n";
53   {
54     /* The Apple/NeXT runtime seems to crash on the following.  */
55 #ifdef __GNU_LIBOBJC__
56     if (property_getAttributes (NULL) != NULL)
57       abort ();
58 #endif
59   }
61   /* TODO: Test new ABI (when available).  */
62   std::cout << "Testing property_getName () ...\n";
63   {
64     /* The Apple/NeXT runtime seems to crash on the following.  */
65 #ifdef __GNU_LIBOBJC__
67     if (property_getName (NULL) != NULL)
68       abort ();
69 #endif
70   }
72   return (0);