3 .*propertyDesc.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\]
4 .*propertyDesc.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\]
5 .*propertyDesc.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\]
6 .*propertyDesc.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\]
7 .*propertyDesc.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\]
8 .*propertyDesc.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\]
9 .*propertyDesc.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\]
10 .*propertyDesc.m:\d+:\d+: warning: null passed to a callee that requires a non-null argument \[-Wnonnull\]
18 #include <objc/runtime.h>
20 struct objc_property {
25 #define checkattrlist(attrs, attrcount, target) \
29 testassert(attrcount == target); \
30 testassert(malloc_size(attrs) >= \
31 (1+target) * sizeof(objc_property_attribute_t)); \
32 testassert(attrs[target].name == NULL); \
33 testassert(attrs[target].value == NULL); \
36 testassert(attrcount == 0); \
40 #define checkattr(attrs, i, n, v) \
42 char *attrsstart = (char *)attrs; \
43 char *attrsend = (char *)attrs + malloc_size(attrs); \
44 testassert((char*)(attrs+i+1) <= attrsend); \
45 testassert(attrs[i].name >= attrsstart); \
46 testassert(attrs[i].value >= attrsstart); \
47 testassert(attrs[i].name + strlen(attrs[i].name) + 1 <= attrsend); \
48 testassert(attrs[i].value + strlen(attrs[i].value) + 1 <= attrsend); \
49 if (n) testassert(0 == strcmp(attrs[i].name, n)); \
50 else testassert(attrs[i].name == NULL); \
51 if (v) testassert(0 == strcmp(attrs[i].value, v)); \
52 else testassert(attrs[i].value == NULL); \
58 objc_property_attribute_t *attrs;
59 unsigned int attrcount;
61 // STRING TO ATTRIBUTE LIST (property_copyAttributeList)
63 struct objc_property prop;
68 attrs = property_copyAttributeList(NULL, &attrcount);
70 testassert(attrcount == 0);
71 attrs = property_copyAttributeList(NULL, NULL);
77 attrs = property_copyAttributeList(&prop, &attrcount);
78 checkattrlist(attrs, attrcount, 0);
79 attrs = property_copyAttributeList(&prop, NULL);
85 attrs = property_copyAttributeList(&prop, &attrcount);
86 checkattrlist(attrs, attrcount, 0);
87 attrs = property_copyAttributeList(&prop, NULL);
93 attrs = property_copyAttributeList(&prop, &attrcount);
94 checkattrlist(attrs, attrcount, 0);
95 attrs = property_copyAttributeList(&prop, NULL);
98 // long and short names, with and without values
100 prop.attr = "?XX,',\"?!?!\"YY,\"''''\"";
101 attrs = property_copyAttributeList(&prop, &attrcount);
102 checkattrlist(attrs, attrcount, 4);
103 checkattr(attrs, 0, "?", "XX");
104 checkattr(attrs, 1, "'", "");
105 checkattr(attrs, 2, "?!?!", "YY");
106 checkattr(attrs, 3, "''''", "");
109 // all recognized attributes simultaneously, values with quotes
111 prop.attr = "T11,V2222,S333333\",G\"44444444,W,P,D,R,N,C,&";
112 attrs = property_copyAttributeList(&prop, &attrcount);
113 checkattrlist(attrs, attrcount, 11);
114 checkattr(attrs, 0, "T", "11");
115 checkattr(attrs, 1, "V", "2222");
116 checkattr(attrs, 2, "S", "333333\"");
117 checkattr(attrs, 3, "G", "\"44444444");
118 checkattr(attrs, 4, "W", "");
119 checkattr(attrs, 5, "P", "");
120 checkattr(attrs, 6, "D", "");
121 checkattr(attrs, 7, "R", "");
122 checkattr(attrs, 8, "N", "");
123 checkattr(attrs, 9, "C", "");
124 checkattr(attrs,10, "&", "");
129 prop.attr = "W,T11,P,?XX,D,V2222,R,',N,S333333\",C,\"?!?!\"YY,&,G\"44444444,\"''''\"";
130 attrs = property_copyAttributeList(&prop, &attrcount);
131 checkattrlist(attrs, attrcount, 15);
132 checkattr(attrs, 0, "W", "");
133 checkattr(attrs, 1, "T", "11");
134 checkattr(attrs, 2, "P", "");
135 checkattr(attrs, 3, "?", "XX");
136 checkattr(attrs, 4, "D", "");
137 checkattr(attrs, 5, "V", "2222");
138 checkattr(attrs, 6, "R", "");
139 checkattr(attrs, 7, "'", "");
140 checkattr(attrs, 8, "N", "");
141 checkattr(attrs, 9, "S", "333333\"");
142 checkattr(attrs,10, "C", "");
143 checkattr(attrs,11, "?!?!", "YY");
144 checkattr(attrs,12, "&", "");
145 checkattr(attrs,13, "G", "\"44444444");
146 checkattr(attrs,14, "''''", "");
149 // SEARCH ATTRIBUTE LIST (property_copyAttributeValue)
151 // null property, null name, empty name
152 value = property_copyAttributeValue(NULL, NULL);
154 value = property_copyAttributeValue(NULL, "foo");
156 value = property_copyAttributeValue(NULL, "");
158 value = property_copyAttributeValue(&prop, NULL);
160 value = property_copyAttributeValue(&prop, "");
163 // null attributes, empty attributes
165 value = property_copyAttributeValue(&prop, "foo");
168 value = property_copyAttributeValue(&prop, "foo");
171 // long and short names, with and without values
172 prop.attr = "?XX,',\"?!?!\"YY,\"''''\"";
173 value = property_copyAttributeValue(&prop, "missing");
175 value = property_copyAttributeValue(&prop, "X");
177 value = property_copyAttributeValue(&prop, "\"");
179 value = property_copyAttributeValue(&prop, "'''");
181 value = property_copyAttributeValue(&prop, "'''''");
184 value = property_copyAttributeValue(&prop, "?");
185 testassert(0 == strcmp(value, "XX"));
186 testassert(malloc_size(value) >= 1 + strlen(value));
188 value = property_copyAttributeValue(&prop, "'");
189 testassert(0 == strcmp(value, ""));
190 testassert(malloc_size(value) >= 1 + strlen(value));
192 value = property_copyAttributeValue(&prop, "?!?!");
193 testassert(0 == strcmp(value, "YY"));
194 testassert(malloc_size(value) >= 1 + strlen(value));
196 value = property_copyAttributeValue(&prop, "''''");
197 testassert(0 == strcmp(value, ""));
198 testassert(malloc_size(value) >= 1 + strlen(value));
201 // all recognized attributes simultaneously, values with quotes
202 prop.attr = "T11,V2222,S333333\",G\"44444444,W,P,D,R,N,C,&";
203 value = property_copyAttributeValue(&prop, "T");
204 testassert(0 == strcmp(value, "11"));
205 testassert(malloc_size(value) >= 1 + strlen(value));
207 value = property_copyAttributeValue(&prop, "V");
208 testassert(0 == strcmp(value, "2222"));
209 testassert(malloc_size(value) >= 1 + strlen(value));
211 value = property_copyAttributeValue(&prop, "S");
212 testassert(0 == strcmp(value, "333333\""));
213 testassert(malloc_size(value) >= 1 + strlen(value));
215 value = property_copyAttributeValue(&prop, "G");
216 testassert(0 == strcmp(value, "\"44444444"));
217 testassert(malloc_size(value) >= 1 + strlen(value));
219 value = property_copyAttributeValue(&prop, "W");
220 testassert(0 == strcmp(value, ""));
221 testassert(malloc_size(value) >= 1 + strlen(value));
223 value = property_copyAttributeValue(&prop, "P");
224 testassert(0 == strcmp(value, ""));
225 testassert(malloc_size(value) >= 1 + strlen(value));
227 value = property_copyAttributeValue(&prop, "D");
228 testassert(0 == strcmp(value, ""));
229 testassert(malloc_size(value) >= 1 + strlen(value));
231 value = property_copyAttributeValue(&prop, "R");
232 testassert(0 == strcmp(value, ""));
233 testassert(malloc_size(value) >= 1 + strlen(value));
235 value = property_copyAttributeValue(&prop, "N");
236 testassert(0 == strcmp(value, ""));
237 testassert(malloc_size(value) >= 1 + strlen(value));
239 value = property_copyAttributeValue(&prop, "C");
240 testassert(0 == strcmp(value, ""));
241 testassert(malloc_size(value) >= 1 + strlen(value));
243 value = property_copyAttributeValue(&prop, "&");
244 testassert(0 == strcmp(value, ""));
245 testassert(malloc_size(value) >= 1 + strlen(value));
248 // ATTRIBUTE LIST TO STRING (class_addProperty)
251 objc_property_t prop2;
254 ok = class_addProperty([TestRoot class], NULL, (objc_property_attribute_t *)1, 1);
258 ok = class_addProperty([TestRoot class], "test-null-desc", NULL, 0);
260 prop2 = class_getProperty([TestRoot class], "test-null-desc");
262 testassert(0 == strcmp(property_getAttributes(prop2), ""));
265 ok = class_addProperty([TestRoot class], "test-empty-desc", (objc_property_attribute_t*)1, 0);
267 prop2 = class_getProperty([TestRoot class], "test-empty-desc");
269 testassert(0 == strcmp(property_getAttributes(prop2), ""));
271 // long and short names, with and without values
272 objc_property_attribute_t attrs2[] = {
279 ok = class_addProperty([TestRoot class], "test-unrecognized", attrs2, 5);
281 prop2 = class_getProperty([TestRoot class], "test-unrecognized");
283 testassert(0 == strcmp(property_getAttributes(prop2), "?XX,',\"?!?!\"YY,\"''''\""));
285 // all recognized attributes simultaneously, values with quotes
286 objc_property_attribute_t attrs3[] = {
294 { "G", "\"44444444" },
299 ok = class_addProperty([TestRoot class], "test-recognized", attrs3, 11);
301 prop2 = class_getProperty([TestRoot class], "test-recognized");
303 testassert(0 == strcmp(property_getAttributes(prop2),
304 "&,C,N,R,D,P,W,G\"44444444,S333333\",V2222,T11"));
307 objc_property_attribute_t attrs4[] = {
316 { "G", "\"44444444" },
325 ok = class_addProperty([TestRoot class], "test-sink", attrs4, 16);
327 prop2 = class_getProperty([TestRoot class], "test-sink");
329 testassert(0 == strcmp(property_getAttributes(prop2),
330 "&,C,N,R,D,P,W,G\"44444444,S333333\",V2222,T11,"
331 "?XX,',\"?!?!\"YY,\"''''\""));