Debian Codegraph @

gcc/testsuite/objc/execute/class-11.m

raw
1 /* Contributed by Nicola Pero - Tue Mar 6 23:05:53 CET 2001 */
2
3 #include <objc/objc.h>
4
5 /* Tests creating a root class and a subclass with an ivar and
6 accessor methods and a subclass overriding the superclass'
7 implementation and using self to call another method of itself - in
8 a category */
9
10 @interface RootClass
11 {
12 Class isa;
13 }
14 @end
15
16 @implementation RootClass
17 + initialize { return self; }
18 @end
19
20 @interface SubClass : RootClass
21 {
22 int state;
23 }
24 - (void) setState: (int)number;
25 - (int) state;
26 @end
27
28 @implementation SubClass
29 - (void) setState: (int)number
30 {
31 state = number;
32 }
33 - (int) state
34 {
35 return state;
36 }
37 @end
38
39 @interface SubSubClass : SubClass
40 - (int) shift;
41 @end
42
43 @implementation SubSubClass
44 - (int) shift
45 {
46 return 1;
47 }
48 @end
49
50 @implementation SubSubClass (Additions)
51 - (int) state
52 {
53 return state + [self shift];
54 }
55 @end
56
57 #include "class-tests-1.h"
58 #define TYPE_OF_OBJECT_WITH_ACCESSOR_METHOD SubClass *
59 #include "class-tests-2.h"
60
61 int main (void)
62 {
63 SubClass *object;
64 SubSubClass *sub_object;
65
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));
69
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_createInstance (objc_getClass ("SubClass"), 0);
76 test_accessor_method (object, 0, -1, -1, 1, 1);
77
78 sub_object = class_createInstance (objc_getClass ("SubSubClass"), 0);
79 test_accessor_method (sub_object, 1, -1, 0, 1, 2);
80
81 return 0;
82 }