]> git.saurik.com Git - apple/objc4.git/blob - test/classname.m
objc4-437.tar.gz
[apple/objc4.git] / test / classname.m
1 #include "test.h"
2 #include <string.h>
3 #include <objc/objc-runtime.h>
4
5 @interface Super { @public id isa; } @end
6 @implementation Super
7 +(void)initialize { }
8 +class { return self; }
9 @end
10
11 @interface Fake { @public id isa; } @end
12 @implementation Fake
13 +(void)initialize { }
14 +class { return self; }
15 @end
16
17 int main()
18 {
19 id buf[10];
20 Super *obj = (Super *)buf;
21 buf[0] = [Fake class];
22
23 testassert(obj->isa == [Fake class]);
24 testassert(object_setClass(obj, [Super class]) == [Fake class]);
25 testassert(obj->isa == [Super class]);
26 testassert(object_setClass(nil, [Super class]) == nil);
27
28 testassert(object_getClass(obj) == buf[0]);
29 testassert(object_getClass([Super class]) == [Super class]->isa);
30 testassert(object_getClass(nil) == Nil);
31
32 testassert(0 == strcmp(object_getClassName(obj), "Super"));
33 testassert(0 == strcmp(object_getClassName([Super class]), "Super"));
34 testassert(0 == strcmp(object_getClassName(nil), "nil"));
35
36 testassert(0 == strcmp(class_getName([Super class]), "Super"));
37 testassert(0 == strcmp(class_getName([Super class]->isa), "Super"));
38 testassert(0 == strcmp(class_getName(nil), "nil"));
39
40 succeed(__FILE__);
41 }