-
Notifications
You must be signed in to change notification settings - Fork 517
/
Copy pathclassname.m
40 lines (31 loc) · 1.35 KB
/
classname.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// TEST_CONFIG
#include "test.h"
#include "testroot.i"
#include <string.h>
#include <objc/runtime.h>
#include <ptrauth.h>
@interface Fake : TestRoot @end
@implementation Fake @end
int main()
{
TestRoot *obj = [TestRoot new];
void *buf = (__bridge void *)(obj);
*(Class __ptrauth_objc_isa_pointer *)buf = [Fake class];
testassert(object_getClass(obj) == [Fake class]);
testassert(object_setClass(obj, [TestRoot class]) == [Fake class]);
testassert(object_getClass(obj) == [TestRoot class]);
testassert(object_setClass(nil, [TestRoot class]) == nil);
testassert(malloc_size(buf) >= sizeof(id));
memset(buf, 0, malloc_size(buf));
testassert(object_setClass(obj, [TestRoot class]) == nil);
testassert(object_getClass(obj) == [TestRoot class]);
testassert(object_getClass([TestRoot class]) == object_getClass([TestRoot class]));
testassert(object_getClass(nil) == Nil);
testassert(0 == strcmp(object_getClassName(obj), "TestRoot"));
testassert(0 == strcmp(object_getClassName([TestRoot class]), "TestRoot"));
testassert(0 == strcmp(object_getClassName(nil), "nil"));
testassert(0 == strcmp(class_getName([TestRoot class]), "TestRoot"));
testassert(0 == strcmp(class_getName(object_getClass([TestRoot class])), "TestRoot"));
testassert(0 == strcmp(class_getName(nil), "nil"));
succeed(__FILE__);
}