]> git.saurik.com Git - apple/objc4.git/blob - test/exchangeImp.m
objc4-779.1.tar.gz
[apple/objc4.git] / test / exchangeImp.m
1 /*
2 TEST_BUILD_OUTPUT
3 .*exchangeImp.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'checkExchange')?
4 .*exchangeImp.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'checkExchange')?
5 .*exchangeImp.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'checkExchange')?
6 .*exchangeImp.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'checkExchange')?
7 .*exchangeImp.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'checkExchange')?
8 .*exchangeImp.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'checkExchange')?
9 .*exchangeImp.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'checkExchange')?
10 .*exchangeImp.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'checkExchange')?
11 .*exchangeImp.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'checkExchange')?
12 .*exchangeImp.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'checkExchange')?
13 .*exchangeImp.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'checkExchange')?
14 .*exchangeImp.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'checkExchange')?
15 .*exchangeImp.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'checkExchange')?
16 .*exchangeImp.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'checkExchange')?
17 .*exchangeImp.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'checkExchange')?
18 .*exchangeImp.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'checkExchange')?
19 END
20 */
21
22 #include "test.h"
23 #include "testroot.i"
24 #include <objc/runtime.h>
25
26 static int state;
27
28 #define ONE 1
29 #define TWO 2
30 #define LENGTH 3
31 #define COUNT 4
32
33 @interface Super : TestRoot @end
34 @implementation Super
35 +(void) one { state = ONE; }
36 +(void) two { state = TWO; }
37 +(void) length { state = LENGTH; }
38 +(void) count { state = COUNT; }
39 @end
40
41 #define checkExchange(s1, v1, s2, v2) \
42 do { \
43 Method m1, m2; \
44 \
45 testprintf("Check unexchanged version\n"); \
46 state = 0; \
47 [Super s1]; \
48 testassert(state == v1); \
49 state = 0; \
50 [Super s2]; \
51 testassert(state == v2); \
52 \
53 testprintf("Exchange\n"); \
54 m1 = class_getClassMethod([Super class], @selector(s1)); \
55 m2 = class_getClassMethod([Super class], @selector(s2)); \
56 testassert(m1); \
57 testassert(m2); \
58 method_exchangeImplementations(m1, m2); \
59 \
60 testprintf("Check exchanged version\n"); \
61 state = 0; \
62 [Super s1]; \
63 testassert(state == v2); \
64 state = 0; \
65 [Super s2]; \
66 testassert(state == v1); \
67 \
68 testprintf("NULL should do nothing\n"); \
69 method_exchangeImplementations(m1, NULL); \
70 method_exchangeImplementations(NULL, m2); \
71 method_exchangeImplementations(NULL, NULL); \
72 \
73 testprintf("Make sure NULL did nothing\n"); \
74 state = 0; \
75 [Super s1]; \
76 testassert(state == v2); \
77 state = 0; \
78 [Super s2]; \
79 testassert(state == v1); \
80 \
81 testprintf("Put them back\n"); \
82 method_exchangeImplementations(m1, m2); \
83 \
84 testprintf("Check restored version\n"); \
85 state = 0; \
86 [Super s1]; \
87 testassert(state == v1); \
88 state = 0; \
89 [Super s2]; \
90 testassert(state == v2); \
91 } while (0)
92
93 int main()
94 {
95 // Check ordinary selectors
96 checkExchange(one, ONE, two, TWO);
97
98 // Check vtable selectors
99 checkExchange(length, LENGTH, count, COUNT);
100
101 // Check ordinary<->vtable and vtable<->ordinary
102 checkExchange(count, COUNT, one, ONE);
103 checkExchange(two, TWO, length, LENGTH);
104
105 succeed(__FILE__);
106 }