5 #include <objc/runtime.h>
14 @interface Super : TestRoot @end
16 +(void) one { state = ONE; }
17 +(void) two { state = TWO; }
18 +(void) length { state = LENGTH; }
19 +(void) count { state = COUNT; }
22 #define checkExchange(s1, v1, s2, v2) \
26 testprintf("Check unexchanged version\n"); \
29 testassert(state == v1); \
32 testassert(state == v2); \
34 testprintf("Exchange\n"); \
35 m1 = class_getClassMethod([Super class], @selector(s1)); \
36 m2 = class_getClassMethod([Super class], @selector(s2)); \
39 method_exchangeImplementations(m1, m2); \
41 testprintf("Check exchanged version\n"); \
44 testassert(state == v2); \
47 testassert(state == v1); \
49 testprintf("NULL should do nothing\n"); \
50 method_exchangeImplementations(m1, NULL); \
51 method_exchangeImplementations(NULL, m2); \
52 method_exchangeImplementations(NULL, NULL); \
54 testprintf("Make sure NULL did nothing\n"); \
57 testassert(state == v2); \
60 testassert(state == v1); \
62 testprintf("Put them back\n"); \
63 method_exchangeImplementations(m1, m2); \
65 testprintf("Check restored version\n"); \
68 testassert(state == v1); \
71 testassert(state == v2); \
76 // Check ordinary selectors
77 checkExchange(one, ONE, two, TWO);
79 // Check vtable selectors
80 checkExchange(length, LENGTH, count, COUNT);
82 // Check ordinary<->vtable and vtable<->ordinary
83 checkExchange(count, COUNT, one, ONE);
84 checkExchange(two, TWO, length, LENGTH);