FSF GCC merge 02/23/03
[official-gcc.git] / gcc / testsuite / objc / execute / class-9.m
blobbb405fbc982e50da312372c421529f9e9e8be1f8
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 /* Tests creating a root class and a subclass with an ivar and
6    accessor methods and a subclass overriding the superclass'
7    implementation but reusing it with super - in a category */
9 @interface RootClass
11   Class isa;
13 @end
15 @implementation RootClass
16 @end
18 @interface SubClass : RootClass
20   int state;
22 - (void) setState: (int)number;
23 - (int) state;
24 @end
26 @implementation SubClass
27 - (void) setState: (int)number
29   state = number;
31 - (int) state
33   return state;
35 @end
37 @interface SubSubClass : SubClass
38 @end
40 @implementation SubSubClass
41 @end
43 @implementation SubSubClass (Additions)
44 - (int) state
46   return [super state] + 1;
48 @end
50 #include "class-tests-1.h"
51 #define TYPE_OF_OBJECT_WITH_ACCESSOR_METHOD SubClass *
52 #include "class-tests-2.h"
54 int main (void)
56   SubClass *object;
57   SubSubClass *sub_object;
59   test_class_with_superclass ("SubClass", "RootClass");
60   test_that_class_has_instance_method ("SubClass", @selector (setState:));
61   test_that_class_has_instance_method ("SubClass", @selector (state));
63   test_class_with_superclass ("SubSubClass", "SubClass");
64   test_that_class_has_instance_method ("SubSubClass", @selector (setState:));
65   test_that_class_has_instance_method ("SubSubClass", @selector (state));
66   
67   object = class_create_instance (objc_lookup_class ("SubClass"));
68   test_accessor_method (object, 0, -1, -1, 1, 1);
70   sub_object = class_create_instance (objc_lookup_class ("SubSubClass"));
71   test_accessor_method (sub_object, 1, -1, 0, 1, 2);
73   return 0;