]>
Commit | Line | Data |
---|---|---|
13ba007e A |
1 | /* |
2 | TEST_CFLAGS -Wno-deprecated-declarations | |
3 | TEST_BUILD_OUTPUT | |
4 | .*methodArgs.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')? | |
5 | .*methodArgs.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')? | |
6 | .*methodArgs.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')? | |
7 | .*methodArgs.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')? | |
8 | .*methodArgs.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\](\n.* note: expanded from macro 'testassert')? | |
9 | .*methodArgs.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\] | |
10 | .*methodArgs.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\] | |
11 | .*methodArgs.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\] | |
12 | .*methodArgs.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\] | |
13 | .*methodArgs.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\] | |
14 | .*methodArgs.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\] | |
15 | .*methodArgs.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\] | |
16 | .*methodArgs.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\] | |
17 | .*methodArgs.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\] | |
18 | .*methodArgs.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\] | |
19 | .*methodArgs.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\] | |
20 | END | |
21 | */ | |
22 | ||
23 | #include "test.h" | |
24 | #include "testroot.i" | |
25 | #include <string.h> | |
26 | #include <objc/objc-runtime.h> | |
27 | ||
28 | @interface Super : TestRoot @end | |
29 | @implementation Super | |
30 | +(id)method:(int)__unused arg :(void(^)(void)) __unused arg2 { | |
31 | return 0; | |
32 | } | |
33 | @end | |
34 | ||
35 | ||
36 | int main() | |
37 | { | |
38 | char buf[128]; | |
39 | char *arg; | |
40 | struct objc_method_description *desc; | |
41 | Method m = class_getClassMethod([Super class], sel_registerName("method::")); | |
42 | testassert(m); | |
43 | ||
44 | testassert(method_getNumberOfArguments(m) == 4); | |
45 | ||
46 | arg = method_copyArgumentType(m, 0); | |
47 | testassert(arg); | |
48 | testassert(0 == strcmp(arg, "@")); | |
49 | memset(buf, 1, 128); | |
50 | method_getArgumentType(m, 0, buf, 1+strlen(arg)); | |
51 | testassert(0 == strcmp(arg, buf)); | |
52 | testassert(buf[1+strlen(arg)] == 1); | |
53 | memset(buf, 1, 128); | |
54 | method_getArgumentType(m, 0, buf, 2); | |
55 | testassert(0 == strncmp(arg, buf, 2)); | |
56 | testassert(buf[2] == 1); | |
57 | free(arg); | |
58 | ||
59 | arg = method_copyArgumentType(m, 1); | |
60 | testassert(arg); | |
61 | testassert(0 == strcmp(arg, ":")); | |
62 | memset(buf, 1, 128); | |
63 | method_getArgumentType(m, 1, buf, 1+strlen(arg)); | |
64 | testassert(0 == strcmp(arg, buf)); | |
65 | testassert(buf[1+strlen(arg)] == 1); | |
66 | memset(buf, 1, 128); | |
67 | method_getArgumentType(m, 1, buf, 2); | |
68 | testassert(0 == strncmp(arg, buf, 2)); | |
69 | testassert(buf[2] == 1); | |
70 | free(arg); | |
71 | ||
72 | arg = method_copyArgumentType(m, 2); | |
73 | testassert(arg); | |
74 | testassert(0 == strcmp(arg, "i")); | |
75 | memset(buf, 1, 128); | |
76 | method_getArgumentType(m, 2, buf, 1+strlen(arg)); | |
77 | testassert(0 == strcmp(arg, buf)); | |
78 | testassert(buf[1+strlen(arg)] == 1); | |
79 | memset(buf, 1, 128); | |
80 | method_getArgumentType(m, 2, buf, 2); | |
81 | testassert(0 == strncmp(arg, buf, 2)); | |
82 | testassert(buf[2] == 1); | |
83 | free(arg); | |
84 | ||
85 | arg = method_copyArgumentType(m, 3); | |
86 | testassert(arg); | |
87 | testassert(0 == strcmp(arg, "@?")); | |
88 | memset(buf, 1, 128); | |
89 | method_getArgumentType(m, 3, buf, 1+strlen(arg)); | |
90 | testassert(0 == strcmp(arg, buf)); | |
91 | testassert(buf[1+strlen(arg)] == 1); | |
92 | memset(buf, 1, 128); | |
93 | method_getArgumentType(m, 3, buf, 2); | |
94 | testassert(0 == strncmp(arg, buf, 2)); | |
95 | testassert(buf[2] == 1); | |
96 | memset(buf, 1, 128); | |
97 | method_getArgumentType(m, 3, buf, 3); | |
98 | testassert(0 == strncmp(arg, buf, 3)); | |
99 | testassert(buf[3] == 1); | |
100 | free(arg); | |
101 | ||
102 | arg = method_copyArgumentType(m, 4); | |
103 | testassert(!arg); | |
104 | ||
105 | arg = method_copyArgumentType(m, -1); | |
106 | testassert(!arg); | |
107 | ||
108 | memset(buf, 1, 128); | |
109 | method_getArgumentType(m, 4, buf, 127); | |
110 | testassert(buf[0] == 0); | |
111 | testassert(buf[1] == 0); | |
112 | testassert(buf[127] == 1); | |
113 | ||
114 | memset(buf, 1, 128); | |
115 | method_getArgumentType(m, -1, buf, 127); | |
116 | testassert(buf[0] == 0); | |
117 | testassert(buf[1] == 0); | |
118 | testassert(buf[127] == 1); | |
119 | ||
120 | arg = method_copyReturnType(m); | |
121 | testassert(arg); | |
122 | testassert(0 == strcmp(arg, "@")); | |
123 | memset(buf, 1, 128); | |
124 | method_getReturnType(m, buf, 1+strlen(arg)); | |
125 | testassert(0 == strcmp(arg, buf)); | |
126 | testassert(buf[1+strlen(arg)] == 1); | |
127 | memset(buf, 1, 128); | |
128 | method_getReturnType(m, buf, 2); | |
129 | testassert(0 == strncmp(arg, buf, 2)); | |
130 | testassert(buf[2] == 1); | |
131 | free(arg); | |
132 | ||
133 | desc = method_getDescription(m); | |
134 | testassert(desc); | |
135 | testassert(desc->name == sel_registerName("method::")); | |
136 | #if __LP64__ | |
137 | testassert(0 == strcmp(desc->types, "@28@0:8i16@?20")); | |
138 | #else | |
139 | testassert(0 == strcmp(desc->types, "@16@0:4i8@?12")); | |
140 | #endif | |
141 | ||
142 | testassert(0 == method_getNumberOfArguments(NULL)); | |
143 | testassert(NULL == method_copyArgumentType(NULL, 10)); | |
144 | testassert(NULL == method_copyReturnType(NULL)); | |
145 | testassert(NULL == method_getDescription(NULL)); | |
146 | ||
147 | memset(buf, 1, 128); | |
148 | method_getArgumentType(NULL, 1, buf, 127); | |
149 | testassert(buf[0] == 0); | |
150 | testassert(buf[1] == 0); | |
151 | testassert(buf[127] == 1); | |
152 | ||
153 | memset(buf, 1, 128); | |
154 | method_getArgumentType(NULL, 1, buf, 0); | |
155 | testassert(buf[0] == 1); | |
156 | testassert(buf[1] == 1); | |
157 | ||
158 | method_getArgumentType(m, 1, NULL, 128); | |
159 | method_getArgumentType(m, 1, NULL, 0); | |
160 | method_getArgumentType(NULL, 1, NULL, 128); | |
161 | method_getArgumentType(NULL, 1, NULL, 0); | |
162 | ||
163 | memset(buf, 1, 128); | |
164 | method_getReturnType(NULL, buf, 127); | |
165 | testassert(buf[0] == 0); | |
166 | testassert(buf[1] == 0); | |
167 | testassert(buf[127] == 1); | |
168 | ||
169 | memset(buf, 1, 128); | |
170 | method_getReturnType(NULL, buf, 0); | |
171 | testassert(buf[0] == 1); | |
172 | testassert(buf[1] == 1); | |
173 | ||
174 | method_getReturnType(m, NULL, 128); | |
175 | method_getReturnType(m, NULL, 0); | |
176 | method_getReturnType(NULL, NULL, 128); | |
177 | method_getReturnType(NULL, NULL, 0); | |
178 | ||
179 | succeed(__FILE__); | |
180 | } |