2015-09-24 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / objc / execute / class-7.m
blob31e240945bb320e2bd77a24a58145d93187cc28d
1 /* Contributed by Nicola Pero - Tue Mar  6 23:05:53 CET 2001 */
3 #include <objc/objc.h>
5 /* Tests creating a root class and a subclass with an ivar and
6    accessor methods; accessor methods implemented in a separate
7    category */
9 @interface RootClass
11   Class isa;
13 @end
15 @implementation RootClass
16 + initialize { return self; }
17 @end
19 @interface SubClass : RootClass
21   int state;
23 @end
25 @implementation SubClass
26 @end
28 @interface SubClass (Additions)
29 - (void) setState: (int)number;
30 - (int) state;
31 @end
33 @implementation SubClass (Additions)
34 - (void) setState: (int)number
36   state = number;
38 - (int) state
40   return state;
42 @end
44 #include "class-tests-1.h"
45 #define TYPE_OF_OBJECT_WITH_ACCESSOR_METHOD SubClass *
46 #include "class-tests-2.h"
48 int main (void)
50   SubClass *object;
52   test_class_with_superclass ("SubClass", "RootClass");
54   /* The NeXT runtime's category implementation is lazy: categories are not attached 
55      to classes until the class is initialized (at +initialize time).  */
56 #ifdef __NEXT_RUNTIME__
57   [SubClass initialize];
58 #endif
60   test_that_class_has_instance_method ("SubClass", @selector (setState:));
61   test_that_class_has_instance_method ("SubClass", @selector (state));
63   object = class_createInstance (objc_getClass ("SubClass"), 0);
64   test_accessor_method (object, 0, 1, 1, -3, -3);
66   return 0;