3 #include <objc/objc-runtime.h>
4 #include <objc/Protocol.h>
6 @interface Super { id isa; } @end
9 +class { return self; }
10 +(id)method:(int)arg { return (id)(intptr_t)arg; }
18 struct objc_method_description *desc;
19 Method m = class_getClassMethod([Super class], sel_registerName("method:"));
22 testassert(method_getNumberOfArguments(m) == 3);
24 testassert(method_getSizeOfArguments(m) == 12);
27 arg = method_copyArgumentType(m, 0);
29 testassert(0 == strcmp(arg, "@"));
31 method_getArgumentType(m, 0, buf, 1+strlen(arg));
32 testassert(0 == strcmp(arg, buf));
33 testassert(buf[1+strlen(arg)] == 1);
35 method_getArgumentType(m, 0, buf, 2);
36 testassert(0 == strncmp(arg, buf, 2));
37 testassert(buf[2] == 1);
40 arg = method_copyArgumentType(m, 1);
42 testassert(0 == strcmp(arg, ":"));
44 method_getArgumentType(m, 1, buf, 1+strlen(arg));
45 testassert(0 == strcmp(arg, buf));
46 testassert(buf[1+strlen(arg)] == 1);
48 method_getArgumentType(m, 1, buf, 2);
49 testassert(0 == strncmp(arg, buf, 2));
50 testassert(buf[2] == 1);
53 arg = method_copyArgumentType(m, 2);
55 testassert(0 == strcmp(arg, "i"));
57 method_getArgumentType(m, 2, buf, 1+strlen(arg));
58 testassert(0 == strcmp(arg, buf));
59 testassert(buf[1+strlen(arg)] == 1);
61 method_getArgumentType(m, 2, buf, 2);
62 testassert(0 == strncmp(arg, buf, 2));
63 testassert(buf[2] == 1);
66 arg = method_copyArgumentType(m, 3);
69 arg = method_copyArgumentType(m, -1);
73 method_getArgumentType(m, 3, buf, 127);
74 testassert(buf[0] == 0);
75 testassert(buf[1] == 0);
76 testassert(buf[127] == 1);
79 method_getArgumentType(m, -1, buf, 127);
80 testassert(buf[0] == 0);
81 testassert(buf[1] == 0);
82 testassert(buf[127] == 1);
84 arg = method_copyReturnType(m);
86 testassert(0 == strcmp(arg, "@"));
88 method_getReturnType(m, buf, 1+strlen(arg));
89 testassert(0 == strcmp(arg, buf));
90 testassert(buf[1+strlen(arg)] == 1);
92 method_getReturnType(m, buf, 2);
93 testassert(0 == strncmp(arg, buf, 2));
94 testassert(buf[2] == 1);
97 desc = method_getDescription(m);
99 testassert(desc->name == sel_registerName("method:"));
101 testassert(0 == strcmp(desc->types, "@20@0:8i16"));
103 testassert(0 == strcmp(desc->types, "@12@0:4i8"));
106 testassert(0 == method_getNumberOfArguments(NULL));
108 testassert(0 == method_getSizeOfArguments(NULL));
110 testassert(NULL == method_copyArgumentType(NULL, 10));
111 testassert(NULL == method_copyReturnType(NULL));
112 testassert(NULL == method_getDescription(NULL));
115 method_getArgumentType(NULL, 1, buf, 127);
116 testassert(buf[0] == 0);
117 testassert(buf[1] == 0);
118 testassert(buf[127] == 1);
121 method_getArgumentType(NULL, 1, buf, 0);
122 testassert(buf[0] == 1);
123 testassert(buf[1] == 1);
125 method_getArgumentType(m, 1, NULL, 128);
126 method_getArgumentType(m, 1, NULL, 0);
127 method_getArgumentType(NULL, 1, NULL, 128);
128 method_getArgumentType(NULL, 1, NULL, 0);
131 method_getReturnType(NULL, buf, 127);
132 testassert(buf[0] == 0);
133 testassert(buf[1] == 0);
134 testassert(buf[127] == 1);
137 method_getReturnType(NULL, buf, 0);
138 testassert(buf[0] == 1);
139 testassert(buf[1] == 1);
141 method_getReturnType(m, NULL, 128);
142 method_getReturnType(m, NULL, 0);
143 method_getReturnType(NULL, NULL, 128);
144 method_getReturnType(NULL, NULL, 0);