]> git.saurik.com Git - apple/objc4.git/blob - test/setSuper.m
objc4-437.tar.gz
[apple/objc4.git] / test / setSuper.m
1 #include "test.h"
2 #include <objc/runtime.h>
3
4 @interface Super1 { id isa; } @end
5 @implementation Super1
6 +class { return self; }
7 +(void)initialize { }
8 +(int)classMethod { return 1; }
9 -(int)instanceMethod { return 10000; }
10 @end
11
12 @interface Super2 { id isa; } @end
13 @implementation Super2
14 +class { return self; }
15 +(void)initialize { }
16 +(int)classMethod { return 2; }
17 -(int)instanceMethod { return 20000; }
18 @end
19
20 @interface Sub : Super1 @end
21 @implementation Sub
22 +new { return class_createInstance(self, 0); }
23 +(int)classMethod { return [super classMethod] + 100; }
24 -(int)instanceMethod { return [super instanceMethod] + 1000000; }
25 @end
26
27 int main()
28 {
29 Class cls;
30 Sub *obj = [Sub new];
31
32 testassert(101 == [[Sub class] classMethod]);
33 testassert(1010000 == [obj instanceMethod]);
34
35 cls = class_setSuperclass([Sub class], [Super2 class]);
36
37 testassert(cls == [Super1 class]);
38 testassert(cls->isa == [Super1 class]->isa);
39
40 testassert(102 == [[Sub class] classMethod]);
41 testassert(1020000 == [obj instanceMethod]);
42
43 succeed(__FILE__);
44 }