2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / objc / execute / class-11.m
blob00c488bd1b9369cfa69f763592bd54aba223db44
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 and using self to call another method of itself - in
10    a category */
12 @interface RootClass
14   Class isa;
16 @end
18 @implementation RootClass
19 #ifdef __NEXT_RUNTIME__                                   
20 + initialize { return self; }
21 #endif
22 @end
24 @interface SubClass : RootClass
26   int state;
28 - (void) setState: (int)number;
29 - (int) state;
30 @end
32 @implementation SubClass
33 - (void) setState: (int)number
35   state = number;
37 - (int) state
39   return state;
41 @end
43 @interface SubSubClass : SubClass
44 - (int) shift;
45 @end
47 @implementation SubSubClass
48 - (int) shift
50   return 1;
52 @end
54 @implementation SubSubClass (Additions)
55 - (int) state
57   return state + [self shift];
59 @end
61 #include "class-tests-1.h"
62 #define TYPE_OF_OBJECT_WITH_ACCESSOR_METHOD SubClass *
63 #include "class-tests-2.h"
65 int main (void)
67   SubClass *object;
68   SubSubClass *sub_object;
70   test_class_with_superclass ("SubClass", "RootClass");
71   test_that_class_has_instance_method ("SubClass", @selector (setState:));
72   test_that_class_has_instance_method ("SubClass", @selector (state));
74   test_class_with_superclass ("SubSubClass", "SubClass");
75   test_that_class_has_instance_method ("SubSubClass", @selector (setState:));
76   test_that_class_has_instance_method ("SubSubClass", @selector (state));
77   test_that_class_has_instance_method ("SubSubClass", @selector (shift));
78   
79   object = class_create_instance (objc_lookup_class ("SubClass"));
80   test_accessor_method (object, 0, -1, -1, 1, 1);
82   sub_object = class_create_instance (objc_lookup_class ("SubSubClass"));
83   test_accessor_method (sub_object, 1, -1, 0, 1, 2);
85   return 0;