]> git.saurik.com Git - apple/objc4.git/blob - test/setSuper.m
objc4-756.2.tar.gz
[apple/objc4.git] / test / setSuper.m
1 // TEST_CONFIG
2
3 #include "test.h"
4 #include "testroot.i"
5 #include <objc/runtime.h>
6
7 @interface Super1 : TestRoot @end
8 @implementation Super1
9 +(int)classMethod { return 1; }
10 -(int)instanceMethod { return 10000; }
11 @end
12
13 @interface Super2 : TestRoot @end
14 @implementation Super2
15 +(int)classMethod { return 2; }
16 -(int)instanceMethod { return 20000; }
17 @end
18
19 @interface Sub : Super1 @end
20 @implementation Sub
21 +(int)classMethod { return [super classMethod] + 100; }
22 -(int)instanceMethod {
23 return [super instanceMethod] + 1000000;
24 }
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(object_getClass(cls) == object_getClass([Super1 class]));
39
40 testassert(102 == [[Sub class] classMethod]);
41 testassert(1020000 == [obj instanceMethod]);
42
43 succeed(__FILE__);
44 }