]> git.saurik.com Git - apple/objc4.git/blob - test/future.m
objc4-532.tar.gz
[apple/objc4.git] / test / future.m
1 /*
2 TEST_BUILD
3 $C{COMPILE} $DIR/future0.m -o future0.dylib -dynamiclib
4 $C{COMPILE} $DIR/future2.m -x none future0.dylib -o future2.dylib -dynamiclib
5 $C{COMPILE} $DIR/future.m -x none future0.dylib -o future.out
6 END
7 */
8
9 #include "test.h"
10
11 #if __has_feature(objc_arc)
12
13 int main()
14 {
15 testwarn("rdar://10041403 future class API is not ARC-compatible");
16 succeed(__FILE__);
17 }
18
19
20 #else
21
22 #include <objc/runtime.h>
23 #include <malloc/malloc.h>
24 #include <string.h>
25 #include <dlfcn.h>
26 #include "future.h"
27
28 @implementation Sub2
29 +(int)method {
30 return 2;
31 }
32 +(Class)classref {
33 return [Sub2 class];
34 }
35 @end
36
37 @implementation SubSub2
38 +(int)method {
39 return 1 + [super method];
40 }
41 @end
42
43 int main()
44 {
45 Class oldTestRoot;
46 Class oldSub1;
47 Class newSub1;
48 #if !__OBJC2__
49 Class oldSub2;
50 Class newSub2;
51 uintptr_t buf[20];
52 #endif
53
54 // objc_getFutureClass with existing class
55 oldTestRoot = objc_getFutureClass("TestRoot");
56 testassert(oldTestRoot == [TestRoot class]);
57
58 // objc_getFutureClass with missing class
59 oldSub1 = objc_getFutureClass("Sub1");
60 testassert(oldSub1);
61 testassert(malloc_size(objc_unretainedPointer(oldSub1)) > 0);
62 testassert(objc_getClass("Sub1") == Nil);
63
64 // objc_getFutureClass a second time
65 testassert(oldSub1 == objc_getFutureClass("Sub1"));
66
67 #if !__OBJC2__
68 // objc_setFutureClass with existing class
69 oldSub2 = objc_getClass("Sub2");
70 testassert(oldSub2 == [Sub2 class]);
71 testassert(oldSub2 == class_getSuperclass(objc_getClass("SubSub2")));
72 objc_setFutureClass((Class)buf, "Sub2");
73 testassert(0 == strcmp(class_getName((Class)buf), "Sub2"));
74 newSub2 = objc_getClass("Sub2");
75 testassert(newSub2 == (Class)buf);
76 testassert(newSub2 != oldSub2);
77 // check classrefs
78 testassert(newSub2 == [Sub2 class]);
79 testassert(newSub2 == [newSub2 class]);
80 testassert(newSub2 == [newSub2 classref]);
81 testassert(newSub2 != [oldSub2 class]);
82 // check superclass chains
83 testassert(newSub2 == class_getSuperclass(objc_getClass("SubSub2")));
84 #else
85 // 64-bit ABI ignores objc_setFutureClass.
86 #endif
87
88 // Load class Sub1
89 dlopen("future2.dylib", 0);
90
91 // Verify use of future class
92 newSub1 = objc_getClass("Sub1");
93 testassert(oldSub1 == newSub1);
94 testassert(newSub1 == [newSub1 classref]);
95 testassert(newSub1 == class_getSuperclass(objc_getClass("SubSub1")));
96
97 testassert(1 == [oldSub1 method]);
98 testassert(1 == [newSub1 method]);
99 #if !__OBJC2__
100 testassert(2 == [newSub2 method]);
101 testassert(2 == [oldSub2 method]);
102 testassert(3 == [SubSub2 method]);
103 #endif
104
105 succeed(__FILE__);
106 }
107
108 #endif