PR inline-asm/84742
[official-gcc.git] / gcc / testsuite / obj-c++.dg / gnu-api-2-property.mm
blob953e9bb156bcb2b55a3e08ffbc06d3a6e4eec962
1 /* Test the Modern GNU Objective-C Runtime API.
3   This is test 'property', covering all functions starting with 'property'.  */
5 /* { dg-do run } */
6 /* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */
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 <iostream>
13 #include <cstring>
15 @interface MyRootClass
16 { Class isa; }
17 + alloc;
18 - init;
19 + initialize;
20 @end
22 @implementation MyRootClass
23 + alloc { return class_createInstance (self, 0); }
24 - init  { return self; }
25 + initialize { return self; }
26 @end
28 @interface MySubClass : MyRootClass
30   id propertyA;
31   id propertyB;
33 @property (assign, getter=getP, setter=setP:) id propertyA;
34 @property (assign, nonatomic) id propertyB;
35 @end
37 @implementation MySubClass
38 @synthesize propertyA;
39 @synthesize propertyB;
40 @end
43 int main ()
45   /* Functions are tested in alphabetical order.  */
47   std::cout << "Testing property_getAttributes () ...\n";
48   {
49     /* The Apple/NeXT runtime seems to crash on the following.  */
50 #ifdef __GNU_LIBOBJC__
51     if (property_getAttributes (NULL) != NULL)
52       abort ();
53 #endif
55     /* The GNU runtime doesn't support looking up properties at
56        runtime yet.  */
57 #ifdef __OBJC2__
58     {
59       objc_property_t property;
60       
61       property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
62       if (std::strcmp (property_getAttributes (property),
63                   "T@,GgetP,SsetP:,VpropertyA") != 0)
64         abort ();
66       property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
67       if (std::strcmp (property_getAttributes (property),
68                   "T@,N,VpropertyB") != 0)
69         abort ();
70     }
71 #endif    
72   }
74   std::cout << "Testing property_getName () ...\n";
75   {
76     /* The Apple/NeXT runtime seems to crash on the following.  */
77 #ifdef __GNU_LIBOBJC__
79     if (property_getName (NULL) != NULL)
80       abort ();
81 #endif
83     /* The GNU runtime doesn't support looking up properties at
84        runtime yet.  */
85 #ifdef __OBJC2__
86     {
87       objc_property_t property;
88       
89       property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
90       if (std::strcmp (property_getName (property), "propertyA") != 0)
91         abort ();
93       property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
94       if (std::strcmp (property_getName (property), "propertyB") != 0)
95         abort ();
96     }
97 #endif
98   }
100   return (0);