]> git.saurik.com Git - apple/objc4.git/blob - test/cacheflush-constant.m
objc4-818.2.tar.gz
[apple/objc4.git] / test / cacheflush-constant.m
1 // TEST_CFLAGS -framework Foundation
2 /*
3 TEST_RUN_OUTPUT
4 foo
5 bar
6 bar
7 foo
8 END
9 */
10
11 // NOTE: This test won't catch problems when running against a root, so it's of
12 // limited utility, but it would at least catch things when testing against the
13 // shared cache.
14
15 #include <Foundation/Foundation.h>
16 #include <objc/runtime.h>
17
18 @interface NSBlock: NSObject @end
19
20 // NSBlock is a conveniently accessible superclass that (currently) has a constant cache.
21 @interface MyBlock: NSBlock
22 +(void)foo;
23 +(void)bar;
24 @end
25 @implementation MyBlock
26 +(void)foo {
27 printf("foo\n");
28 }
29 +(void)bar {
30 printf("bar\n");
31 }
32 @end
33
34 int main() {
35 [MyBlock foo];
36 [MyBlock bar];
37
38 Method m1 = class_getClassMethod([MyBlock class], @selector(foo));
39 Method m2 = class_getClassMethod([MyBlock class], @selector(bar));
40 method_exchangeImplementations(m1, m2);
41
42 [MyBlock foo];
43 [MyBlock bar];
44 }