2016-12-21 Vladimir Makarov <vmakarov@redhat.com>
[official-gcc.git] / gcc / testsuite / objc / execute / class-8.m
blobef4c2a3c8f3af6f716d8492320fb056a7abf5de9
1 /* Contributed by Nicola Pero - Tue Mar  6 23:05:53 CET 2001 */
3 #include <objc/objc.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 - in a category */
9 @interface RootClass
11   Class isa;
13 @end
15 @implementation RootClass
16 + initialize { return self; }
17 @end
19 @interface SubClass : RootClass
21   int state;
23 - (void) setState: (int)number;
24 - (int) state;
25 @end
27 @implementation SubClass
28 - (void) setState: (int)number
30   state = number;
32 - (int) state
34   return state;
36 @end
38 @interface SubSubClass : SubClass
39 @end
41 @implementation SubSubClass
42 @end
44 @implementation SubSubClass (Additions)
45 - (int) state
47   return state + 1;
49 @end
51 #include "class-tests-1.h"
52 #define TYPE_OF_OBJECT_WITH_ACCESSOR_METHOD SubClass *
53 #include "class-tests-2.h"
55 int main (void)
57   SubClass *object;
58   SubSubClass *sub_object;
60   test_class_with_superclass ("SubClass", "RootClass");
61   test_that_class_has_instance_method ("SubClass", @selector (setState:));
62   test_that_class_has_instance_method ("SubClass", @selector (state));
64   test_class_with_superclass ("SubSubClass", "SubClass");
65   test_that_class_has_instance_method ("SubSubClass", @selector (setState:));
66   test_that_class_has_instance_method ("SubSubClass", @selector (state));
67   
68   object = class_createInstance (objc_getClass ("SubClass"), 0);
69   test_accessor_method (object, 0, -1, -1, 1, 1);
71   sub_object = class_createInstance (objc_getClass ("SubSubClass"), 0);
72   test_accessor_method (sub_object, 1, -1, 0, 1, 2);
74   return 0;