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