5 #include <mach-o/ldsyms.h>
6 #include <objc/objc-runtime.h>
8 @interface Super { id isa; } @end
11 +class { return self; }
14 @interface Sub : Super { } @end
15 @implementation Sub @end
21 unsigned int count, count0;
30 // This shouldn't touch any classes.
31 dladdr(&_mh_execute_header, &info);
32 names = objc_copyClassNamesForImage(info.dli_fname, &count);
34 testassert(count == 2);
35 testassert(names[count] == NULL);
38 for (i = 0; i < count; i++) {
39 if (0 == strcmp(names[i], "Super")) foundSuper++;
40 if (0 == strcmp(names[i], "Sub")) foundSub++;
42 testassert(foundSuper == 1);
43 testassert(foundSub == 1);
46 // class Sub hasn't been touched - make sure it's in the class list too
47 count0 = objc_getClassList(NULL, 0);
48 testassert(count0 >= 2 && count0 < 100);
50 list[count0-1] = NULL;
51 count = objc_getClassList(list, count0-1);
52 testassert(list[count0-1] == NULL);
53 testassert(count == count0);
55 count = objc_getClassList(list, count0);
56 testassert(count == count0);
59 for (i = 0; i < count; i++) {
60 if (0 == strcmp(class_getName(list[i]), "Super")) foundSuper++;
61 if (0 == strcmp(class_getName(list[i]), "Sub")) foundSub++;
62 // list should be non-meta classes only
63 testassert(!class_isMetaClass(list[i]));
65 testassert(foundSuper == 1);
66 testassert(foundSub == 1);
68 // fixme check class handler
69 testassert(objc_getClass("Super") == [Super class]);
70 testassert(objc_getClass("DoesNotExist") == nil);
71 testassert(objc_getClass(NULL) == nil);
73 testassert(objc_getMetaClass("Super") == [Super class]->isa);
74 testassert(objc_getMetaClass("DoesNotExist") == nil);
75 testassert(objc_getMetaClass(NULL) == nil);
77 // fixme check class no handler
78 testassert(objc_lookUpClass("Super") == [Super class]);
79 testassert(objc_lookUpClass("DoesNotExist") == nil);
80 testassert(objc_lookUpClass(NULL) == nil);