Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / gcc / testsuite / objc / execute / class-10.m
blobd984d62ac9996435eecfa20302df916e1ce8f5b3
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 */
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 - (int) shift;
44 @end
46 @implementation SubSubClass
47 - (int) state
49   return state + [self shift];
51 - (int) shift
53   return 1;
55 @end
57 #include "class-tests-1.h"
58 #define TYPE_OF_OBJECT_WITH_ACCESSOR_METHOD SubClass *
59 #include "class-tests-2.h"
61 int main (void)
63   SubClass *object;
64   SubSubClass *sub_object;
66   test_class_with_superclass ("SubClass", "RootClass");
67   test_that_class_has_instance_method ("SubClass", @selector (setState:));
68   test_that_class_has_instance_method ("SubClass", @selector (state));
70   test_class_with_superclass ("SubSubClass", "SubClass");
71   test_that_class_has_instance_method ("SubSubClass", @selector (setState:));
72   test_that_class_has_instance_method ("SubSubClass", @selector (state));
73   test_that_class_has_instance_method ("SubSubClass", @selector (shift));
74   
75   object = class_create_instance (objc_lookup_class ("SubClass"));
76   test_accessor_method (object, 0, -1, -1, 1, 1);
78   sub_object = class_create_instance (objc_lookup_class ("SubSubClass"));
79   test_accessor_method (sub_object, 1, -1, 0, 1, 2);
81   return 0;