1/* Test the Modern GNU Objective-C Runtime API.
2
3  This is test 'property', covering all functions starting with 'property'.  */
4
5/* { dg-do run } */
6/* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-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 <iostream>
13#include <cstring>
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@interface MySubClass : MyRootClass
29{
30  id propertyA;
31  id propertyB;
32}
33@property (assign, getter=getP, setter=setP:) id propertyA;
34@property (assign, nonatomic) id propertyB;
35@end
36
37@implementation MySubClass
38@synthesize propertyA;
39@synthesize propertyB;
40@end
41
42
43int main ()
44{
45  /* Functions are tested in alphabetical order.  */
46
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
54
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 ();
65
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  }
73
74  std::cout << "Testing property_getName () ...\n";
75  {
76    /* The Apple/NeXT runtime seems to crash on the following.  */
77#ifdef __GNU_LIBOBJC__
78
79    if (property_getName (NULL) != NULL)
80      abort ();
81#endif
82
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 ();
92
93      property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
94      if (std::strcmp (property_getName (property), "propertyB") != 0)
95	abort ();
96    }
97#endif
98  }
99
100  return (0);
101}
102