]> git.saurik.com Git - apple/objc4.git/blob - test/load.m
objc4-756.2.tar.gz
[apple/objc4.git] / test / load.m
1 // TEST_CONFIG
2
3 #include "test.h"
4 #include "testroot.i"
5
6 int state = 0;
7 int catstate = 0;
8 int deallocstate = 0;
9
10 @interface Deallocator : TestRoot @end
11 @implementation Deallocator
12 -(void)dealloc {
13 deallocstate = 1;
14 SUPER_DEALLOC();
15 }
16 @end
17
18
19 @interface Super : TestRoot @end
20 @implementation Super
21 +(void)initialize {
22 if (self == [Super class]) {
23 testprintf("in +[Super initialize]\n");
24 testassert(state == 2);
25 state = 3;
26 } else {
27 testprintf("in +[Super initialize] on behalf of Sub\n");
28 testassert(state == 3);
29 state = 4;
30 }
31 }
32 -(void)load { fail("-[Super load] called!"); }
33 +(void)load {
34 testprintf("in +[Super load]\n");
35 testassert(state == 0);
36 state = 1;
37 }
38 @end
39
40 @interface Sub : Super { } @end
41 @implementation Sub
42 +(void)load {
43 testprintf("in +[Sub load]\n");
44 testassert(state == 1);
45 state = 2;
46 }
47 -(void)load { fail("-[Sub load] called!"); }
48 @end
49
50 @interface SubNoLoad : Super { } @end
51 @implementation SubNoLoad @end
52
53 @interface Super (Category) @end
54 @implementation Super (Category)
55 -(void)load { fail("-[Super(Category) load called!"); }
56 +(void)load {
57 testprintf("in +[Super(Category) load]\n");
58 testassert(state >= 1);
59 catstate++;
60 }
61 @end
62
63
64 @interface Sub (Category) @end
65 @implementation Sub (Category)
66 -(void)load { fail("-[Sub(Category) load called!"); }
67 +(void)load {
68 testprintf("in +[Sub(Category) load]\n");
69 testassert(state >= 2);
70 catstate++;
71
72 // test autorelease pool
73 __autoreleasing id x;
74 x = AUTORELEASE([Deallocator new]);
75 }
76 @end
77
78
79 @interface SubNoLoad (Category) @end
80 @implementation SubNoLoad (Category)
81 -(void)load { fail("-[SubNoLoad(Category) load called!"); }
82 +(void)load {
83 testprintf("in +[SubNoLoad(Category) load]\n");
84 testassert(state >= 1);
85 catstate++;
86 }
87 @end
88
89 int main()
90 {
91 testassert(state == 2);
92 testassert(catstate == 3);
93 testassert(deallocstate == 1);
94 [Sub class];
95 testassert(state == 4);
96 testassert(catstate == 3);
97
98 succeed(__FILE__);
99 }