2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / objc / execute / class-13.m
blob98cf0ccd7299ebbde92487ccce7f79d2340f9eec
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 a class accessor
8    methods and a subclass overriding the superclass' implementation
9    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 static int class_variable = 0;
25 @interface SubClass : RootClass
26 + (void) setState: (int)number;
27 + (int) state;
28 @end
30 @implementation SubClass
31 + (void) setState: (int)number
33   class_variable = number;
35 + (int) state
37   return class_variable;
39 @end
41 @interface SubSubClass : SubClass
42 @end
44 @implementation SubSubClass
45 + (int) state
47   return [super state] + 1;
49 @end
51 #include "class-tests-1.h"
52 #define TYPE_OF_OBJECT_WITH_ACCESSOR_METHOD Class
53 #include "class-tests-2.h"
55 int main (void)
57   Class class;
58   Class sub_class;
60   test_class_with_superclass ("SubClass", "RootClass");
61   test_that_class_has_class_method ("SubClass", @selector (setState:));
62   test_that_class_has_class_method ("SubClass", @selector (state));
64   test_class_with_superclass ("SubSubClass", "SubClass");
65   test_that_class_has_class_method ("SubSubClass", @selector (setState:));
66   test_that_class_has_class_method ("SubSubClass", @selector (state));
67   
68   class = objc_lookup_class ("SubClass");
69   test_accessor_method (class, 0, -1, -1, 1, 1);
71   sub_class = objc_lookup_class ("SubSubClass");
72   class_variable = 0;
73   test_accessor_method (sub_class, 1, -1, 0, 1, 2);
75   return 0;