Debian Codegraph @

gcc/testsuite/objc.dg/gnu-api-2-property.m

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 <stdio.h>
14 #include <string.h>
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(int argc, void **args)
45 {
46 /* Functions are tested in alphabetical order. */
47
48 printf ("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 (strcmp (property_getAttributes (property),
64 "T@,GgetP,SsetP:,VpropertyA") != 0)
65 abort ();
66
67 property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
68 if (strcmp (property_getAttributes (property),
69 "T@,N,VpropertyB") != 0)
70 abort ();
71 }
72 #endif
73 }
74
75 printf ("Testing property_getName () ...\n");
76 {
77 /* The Apple/NeXT runtime seems to crash on the following. */
78 #ifdef __GNU_LIBOBJC__
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 (strcmp (property_getName (property), "propertyA") != 0)
91 abort ();
92
93 property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
94 if (strcmp (property_getName (property), "propertyB") != 0)
95 abort ();
96 }
97 #endif
98 }
99
100 return 0;
101 }