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