1 // See instructions in weak.h
6 // Subclass of superclass that isn't there
7 @interface MyMissingSuper : MissingSuper
10 @implementation MyMissingSuper
11 +(int) method { return 1+[super method]; }
12 +(void) load { state++; }
15 // Subclass of subclass of superclass that isn't there
16 @interface MyMissingSub : MyMissingSuper
19 @implementation MyMissingSub
20 +(int) method { return 1+[super method]; }
21 +(void) load { state++; }
24 // Subclass of real superclass
25 @interface MyNotMissingSuper : NotMissingSuper
28 @implementation MyNotMissingSuper
29 +(int) method { return 1+[super method]; }
30 +(void) load { state++; }
33 // Subclass of subclass of superclass that isn't there
34 @interface MyNotMissingSub : MyNotMissingSuper
37 @implementation MyNotMissingSub
38 +(int) method { return 1+[super method]; }
39 +(void) load { state++; }
42 // Categories on all of the above
43 @interface MissingRoot (MissingRootExtras)
47 @implementation MissingRoot (MissingRootExtras)
48 +(void)load { state++; }
49 +(int) cat_method { return 40; }
52 @interface MissingSuper (MissingSuperExtras)
56 @implementation MissingSuper (MissingSuperExtras)
57 +(void)load { state++; }
58 +(int) cat_method { return 1+[super cat_method]; }
61 @interface MyMissingSuper (MyMissingSuperExtras)
65 @implementation MyMissingSuper (MyMissingSuperExtras)
66 +(void)load { state++; }
67 +(int) cat_method { return 1+[super cat_method]; }
70 @interface MyMissingSub (MyMissingSubExtras)
74 @implementation MyMissingSub (MyMissingSubExtras)
75 +(void)load { state++; }
76 +(int) cat_method { return 1+[super cat_method]; }
80 @interface NotMissingRoot (NotMissingRootExtras)
84 @implementation NotMissingRoot (NotMissingRootExtras)
85 +(void)load { state++; }
86 +(int) cat_method { return 30; }
89 @interface NotMissingSuper (NotMissingSuperExtras)
93 @implementation NotMissingSuper (NotMissingSuperExtras)
94 +(void)load { state++; }
95 +(int) cat_method { return 1+[super cat_method]; }
98 @interface MyNotMissingSuper (MyNotMissingSuperExtras)
102 @implementation MyNotMissingSuper (MyNotMissingSuperExtras)
103 +(void)load { state++; }
104 +(int) cat_method { return 1+[super cat_method]; }
107 @interface MyNotMissingSub (MyNotMissingSubExtras)
111 @implementation MyNotMissingSub (MyNotMissingSubExtras)
112 +(void)load { state++; }
113 +(int) cat_method { return 1+[super cat_method]; }
118 # define TESTIVAR(cond) testassert(cond)
120 # define TESTIVAR(cond) /* rdar */
123 static BOOL classInList(Class *classes, const char *name)
126 for (cp = classes; *cp; cp++) {
127 if (0 == strcmp(class_getName(*cp), name)) return YES;
132 static BOOL classInNameList(const char **names, const char *name)
135 for (cp = names; *cp; cp++) {
136 if (0 == strcmp(*cp, name)) return YES;
141 int main(int argc __unused, char **argv)
144 if (strstr(argv[0], "-not-missing.out")) {
146 } else if (strstr(argv[0], "-missing.out")) {
149 fail("executable name must be weak*-missing.out or weak*-not-missing.out");
152 // class and category +load methods
153 if (weakMissing) testassert(state == 8);
154 else testassert(state == 16);
158 testassert([NotMissingRoot class]);
159 testassert([NotMissingSuper class]);
160 testassert([MyNotMissingSuper class]);
161 testassert([MyNotMissingSub class]);
163 testassert(! [MissingRoot class]);
164 testassert(! [MissingSuper class]);
165 testassert(! [MyMissingSuper class]);
166 testassert(! [MyMissingSub class]);
168 testassert([MissingRoot class]);
169 testassert([MissingSuper class]);
170 testassert([MyMissingSuper class]);
171 testassert([MyMissingSub class]);
175 testassert(objc_getClass("NotMissingRoot"));
176 testassert(objc_getClass("NotMissingSuper"));
177 testassert(objc_getClass("MyNotMissingSuper"));
178 testassert(objc_getClass("MyNotMissingSub"));
180 testassert(! objc_getClass("MissingRoot"));
181 testassert(! objc_getClass("MissingSuper"));
182 testassert(! objc_getClass("MyMissingSuper"));
183 testassert(! objc_getClass("MyMissingSub"));
185 testassert(objc_getClass("MissingRoot"));
186 testassert(objc_getClass("MissingSuper"));
187 testassert(objc_getClass("MyMissingSuper"));
188 testassert(objc_getClass("MyMissingSub"));
192 Class *classes = objc_copyClassList(NULL);
193 testassert(classInList(classes, "NotMissingRoot"));
194 testassert(classInList(classes, "NotMissingSuper"));
195 testassert(classInList(classes, "MyNotMissingSuper"));
196 testassert(classInList(classes, "MyNotMissingSub"));
198 testassert(! classInList(classes, "MissingRoot"));
199 testassert(! classInList(classes, "MissingSuper"));
200 testassert(! classInList(classes, "MyMissingSuper"));
201 testassert(! classInList(classes, "MyMissingSub"));
203 testassert(classInList(classes, "MissingRoot"));
204 testassert(classInList(classes, "MissingSuper"));
205 testassert(classInList(classes, "MyMissingSuper"));
206 testassert(classInList(classes, "MyMissingSub"));
211 const char *image = class_getImageName(objc_getClass("NotMissingRoot"));
213 const char **names = objc_copyClassNamesForImage(image, NULL);
215 testassert(classInNameList(names, "NotMissingRoot"));
216 testassert(classInNameList(names, "NotMissingSuper"));
218 testassert(! classInNameList(names, "MissingRoot"));
219 testassert(! classInNameList(names, "MissingSuper"));
221 testassert(classInNameList(names, "MissingRoot"));
222 testassert(classInNameList(names, "MissingSuper"));
226 image = class_getImageName(objc_getClass("MyNotMissingSub"));
228 names = objc_copyClassNamesForImage(image, NULL);
230 testassert(classInNameList(names, "MyNotMissingSuper"));
231 testassert(classInNameList(names, "MyNotMissingSub"));
233 testassert(! classInNameList(names, "MyMissingSuper"));
234 testassert(! classInNameList(names, "MyMissingSub"));
236 testassert(classInNameList(names, "MyMissingSuper"));
237 testassert(classInNameList(names, "MyMissingSub"));
242 testassert(20 == [NotMissingRoot method]);
243 testassert(21 == [NotMissingSuper method]);
244 testassert(22 == [MyNotMissingSuper method]);
245 testassert(23 == [MyNotMissingSub method]);
247 testassert(0 == [MissingRoot method]);
248 testassert(0 == [MissingSuper method]);
249 testassert(0 == [MyMissingSuper method]);
250 testassert(0 == [MyMissingSub method]);
252 testassert(10 == [MissingRoot method]);
253 testassert(11 == [MissingSuper method]);
254 testassert(12 == [MyMissingSuper method]);
255 testassert(13 == [MyMissingSub method]);
259 testassert(30 == [NotMissingRoot cat_method]);
260 testassert(31 == [NotMissingSuper cat_method]);
261 testassert(32 == [MyNotMissingSuper cat_method]);
262 testassert(33 == [MyNotMissingSub cat_method]);
264 testassert(0 == [MissingRoot cat_method]);
265 testassert(0 == [MissingSuper cat_method]);
266 testassert(0 == [MyMissingSuper cat_method]);
267 testassert(0 == [MyMissingSub cat_method]);
269 testassert(40 == [MissingRoot cat_method]);
270 testassert(41 == [MissingSuper cat_method]);
271 testassert(42 == [MyMissingSuper cat_method]);
272 testassert(43 == [MyMissingSub cat_method]);
275 // allocations and ivars
277 NotMissingSuper *obj2;
279 testassert((obj = [[NotMissingRoot alloc] init]));
281 testassert((obj2 = [[NotMissingSuper alloc] init]));
282 TESTIVAR(obj2->ivar == 200);
284 testassert((obj2 = [[MyNotMissingSuper alloc] init]));
285 TESTIVAR(obj2->ivar == 200);
287 testassert((obj2 = [[MyNotMissingSub alloc] init]));
288 TESTIVAR(obj2->ivar == 200);
291 testassert(! [[MissingRoot alloc] init]);
292 testassert(! [[MissingSuper alloc] init]);
293 testassert(! [[MyMissingSuper alloc] init]);
294 testassert(! [[MyMissingSub alloc] init]);
296 testassert((obj = [[MissingRoot alloc] init]));
298 testassert((obj3 = [[MissingSuper alloc] init]));
299 TESTIVAR(obj3->ivar == 100);
301 testassert((obj3 = [[MyMissingSuper alloc] init]));
302 TESTIVAR(obj3->ivar == 100);
304 testassert((obj3 = [[MyMissingSub alloc] init]));
305 TESTIVAR(obj3->ivar == 100);
309 *strrchr(argv[0], '.') = 0;
310 succeed(basename(argv[0]));