2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / objc / execute / class-6.m
blobfb2d64b431426ad1121bf9671fa6cd5fc417e929
1 /* Contributed by Nicola Pero - Tue Mar  6 23:05:53 CET 2001 */
2 #include <objc/objc.h>
3 #include <objc/objc-api.h>
5 #include "next_mapping.h"
7 /* Tests creating a root class and a subclass with an ivar and
8    accessor methods and a subclass overriding the superclass'
9    implementation but reusing it with super */
11 @interface RootClass
13   Class isa;
15 @end
17 @implementation RootClass
18 #ifdef __NEXT_RUNTIME__                                   
19 + initialize { return self; }
20 #endif
21 @end
23 @interface SubClass : RootClass
25   int state;
27 - (void) setState: (int)number;
28 - (int) state;
29 @end
31 @implementation SubClass
32 - (void) setState: (int)number
34   state = number;
36 - (int) state
38   return state;
40 @end
42 @interface SubSubClass : SubClass
43 @end
45 @implementation SubSubClass
46 - (int) state
48   return [super state] + 1;
50 @end
52 #include "class-tests-1.h"
53 #define TYPE_OF_OBJECT_WITH_ACCESSOR_METHOD SubClass *
54 #include "class-tests-2.h"
56 int main (void)
58   SubClass *object;
59   SubSubClass *sub_object;
61   test_class_with_superclass ("SubClass", "RootClass");
62   test_that_class_has_instance_method ("SubClass", @selector (setState:));
63   test_that_class_has_instance_method ("SubClass", @selector (state));
65   test_class_with_superclass ("SubSubClass", "SubClass");
66   test_that_class_has_instance_method ("SubSubClass", @selector (setState:));
67   test_that_class_has_instance_method ("SubSubClass", @selector (state));
68   
69   object = class_create_instance (objc_lookup_class ("SubClass"));
70   test_accessor_method (object, 0, -1, -1, 1, 1);
72   sub_object = class_create_instance (objc_lookup_class ("SubSubClass"));
73   test_accessor_method (sub_object, 1, -1, 0, 1, 2);
75   return 0;