Debian Codegraph @

gcc/testsuite/obj-c++.dg/gnu-api-2-property.mm

raw
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 // { dg-additional-options "-Wno-objc-root-class" }
8
9 /* To get the modern GNU Objective-C Runtime API, you include
10 objc/runtime.h. */
11 #include <objc/runtime.h>
12 #include <stdlib.h>
13 #include <iostream>
14 #include <cstring>
15
16 @interface MyRootClass
17 { Class isa; }
18 + alloc;
19 - init;
20 + initialize;
21 @end
22
23 @implementation MyRootClass
24 + alloc { return class_createInstance (self, 0); }
25 - init { return self; }
26 + initialize { return self; }
27 @end
28
29 @interface MySubClass : MyRootClass
30 {
31 id propertyA;
32 id propertyB;
33 }
34 @property (assign, getter=getP, setter=setP:) id propertyA;
35 @property (assign, nonatomic) id propertyB;
36 @end
37
38 @implementation MySubClass
39 @synthesize propertyA;
40 @synthesize propertyB;
41 @end
42
43
44 int main ()
45 {
46 /* Functions are tested in alphabetical order. */
47
48 std::cout << "Testing property_getAttributes () ...\n";
49 {
50 /* The Apple/NeXT runtime seems to crash on the following. */
51 #ifdef __GNU_LIBOBJC__
52 if (property_getAttributes (NULL) != NULL)
53 abort ();
54 #endif
55
56 /* The GNU runtime doesn't support looking up properties at
57 runtime yet. */
58 #ifdef __OBJC2__
59 {
60 objc_property_t property;
61
62 property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
63 if (std::strcmp (property_getAttributes (property),
64 "T@,GgetP,SsetP:,VpropertyA") != 0)
65 abort ();
66
67 property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
68 if (std::strcmp (property_getAttributes (property),
69 "T@,N,VpropertyB") != 0)
70 abort ();
71 }
72 #endif
73 }
74
75 std::cout << "Testing property_getName () ...\n";
76 {
77 /* The Apple/NeXT runtime seems to crash on the following. */
78 #ifdef __GNU_LIBOBJC__
79
80 if (property_getName (NULL) != NULL)
81 abort ();
82 #endif
83
84 /* The GNU runtime doesn't support looking up properties at
85 runtime yet. */
86 #ifdef __OBJC2__
87 {
88 objc_property_t property;
89
90 property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
91 if (std::strcmp (property_getName (property), "propertyA") != 0)
92 abort ();
93
94 property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
95 if (std::strcmp (property_getName (property), "propertyB") != 0)
96 abort ();
97 }
98 #endif
99 }
100
101 return (0);
102 }