]> git.saurik.com Git - apple/objc4.git/blob - test/cacheflush.m
objc4-437.tar.gz
[apple/objc4.git] / test / cacheflush.m
1 #include "test.h"
2 #include <objc/runtime.h>
3 #include <dlfcn.h>
4
5 #include "cacheflush.h"
6
7 @interface Sub : Super @end
8 @implementation Sub @end
9
10
11 int main()
12 {
13 uintptr_t buf[10];
14 uintptr_t buf2[10];
15 buf[0] = (uintptr_t)[Super class];
16 buf2[0] = (uintptr_t)[Sub class];
17
18 // Fill method cache
19 testassert(1 == [Super classMethod]);
20 testassert(1 == [(Super *)buf instanceMethod]);
21 testassert(1 == [Super classMethod]);
22 testassert(1 == [(Super *)buf instanceMethod]);
23
24 testassert(1 == [Sub classMethod]);
25 testassert(1 == [(Sub *)buf2 instanceMethod]);
26 testassert(1 == [Sub classMethod]);
27 testassert(1 == [(Sub *)buf2 instanceMethod]);
28
29 // Dynamically load a category
30 dlopen("cacheflush2.out", 0);
31
32 // Make sure old cache results are gone
33 testassert(2 == [Super classMethod]);
34 testassert(2 == [(Super *)buf instanceMethod]);
35
36 testassert(2 == [Sub classMethod]);
37 testassert(2 == [(Sub *)buf2 instanceMethod]);
38
39 // Dynamically load another category
40 dlopen("cacheflush3.out", 0);
41
42 // Make sure old cache results are gone
43 testassert(3 == [Super classMethod]);
44 testassert(3 == [(Super *)buf instanceMethod]);
45
46 testassert(3 == [Sub classMethod]);
47 testassert(3 == [(Sub *)buf2 instanceMethod]);
48
49 // fixme test subclasses
50
51 // fixme test objc_flush_caches(), class_addMethod(), class_addMethods()
52
53 succeed(__FILE__);
54 }