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