summaryrefslogtreecommitdiff
path: root/gcc/testsuite/objc.dg/gnu-api-2-property.m
blob: 12c0d8b98e333659eb3113c2a70b76e4af529b01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* Test the Modern GNU Objective-C Runtime API.

  This is test 'property', covering all functions starting with 'property'.  */

/* { dg-do run } */
/* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */

/* To get the modern GNU Objective-C Runtime API, you include
   objc/runtime.h.  */
#include <objc/runtime.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

@interface MyRootClass
{ Class isa; }
+ alloc;
- init;
+ initialize;
@end

@implementation MyRootClass
+ alloc { return class_createInstance (self, 0); }
- init  { return self; }
+ initialize { return self; }
@end

@interface MySubClass : MyRootClass
{
  id propertyA;
  id propertyB;
}
@property (assign, getter=getP, setter=setP:) id propertyA;
@property (assign, nonatomic) id propertyB;
@end

@implementation MySubClass
@synthesize propertyA;
@synthesize propertyB;
@end


int main(int argc, void **args)
{
  /* Functions are tested in alphabetical order.  */

  printf ("Testing property_getAttributes () ...\n");
  {
    /* The Apple/NeXT runtime seems to crash on the following.  */
#ifdef __GNU_LIBOBJC__
    if (property_getAttributes (NULL) != NULL)
      abort ();
#endif

    /* The GNU runtime doesn't support looking up properties at
       runtime yet.  */
#ifdef __OBJC2__
    {
      objc_property_t property;
      
      property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
      if (strcmp (property_getAttributes (property),
		  "T@,GgetP,SsetP:,VpropertyA") != 0)
	abort ();

      property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
      if (strcmp (property_getAttributes (property),
		  "T@,N,VpropertyB") != 0)
	abort ();
    }
#endif    
  }

  printf ("Testing property_getName () ...\n");
  {
    /* The Apple/NeXT runtime seems to crash on the following.  */
#ifdef __GNU_LIBOBJC__
    if (property_getName (NULL) != NULL)
      abort ();
#endif

    /* The GNU runtime doesn't support looking up properties at
       runtime yet.  */
#ifdef __OBJC2__
    {
      objc_property_t property;
      
      property = class_getProperty (objc_getClass ("MySubClass"), "propertyA");
      if (strcmp (property_getName (property), "propertyA") != 0)
	abort ();

      property = class_getProperty (objc_getClass ("MySubClass"), "propertyB");
      if (strcmp (property_getName (property), "propertyB") != 0)
	abort ();
    }
#endif
  }

  return 0;
}