| 113 } |
113 } |
| 114 } |
114 } |
| 115 cxPropertiesDestroy(&prop); |
115 cxPropertiesDestroy(&prop); |
| 116 } |
116 } |
| 117 |
117 |
| |
118 CX_TEST_SUBROUTINE(test_properties_next_multi_check, CxProperties *prop) { |
| |
119 const char *keys[] = { |
| |
120 "a", |
| |
121 "b", |
| |
122 "c", |
| |
123 "uap", |
| |
124 "name", |
| |
125 "key1", |
| |
126 "key2", |
| |
127 "key3" |
| |
128 }; |
| |
129 |
| |
130 const char *values[] = { |
| |
131 "a value", |
| |
132 "b value", |
| |
133 "core", |
| |
134 "core", |
| |
135 "ucx", |
| |
136 "value1", |
| |
137 "value2", |
| |
138 "value3" |
| |
139 }; |
| |
140 CxPropertiesStatus result; |
| |
141 cxstring key; |
| |
142 cxstring value; |
| |
143 for (int i = 0; i < 8; i++) { |
| |
144 result = cxPropertiesNext(prop, &key, &value); |
| |
145 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
| |
146 CX_TEST_ASSERT(!cx_strcmp(key, cx_str(keys[i]))); |
| |
147 CX_TEST_ASSERT(!cx_strcmp(value, cx_str(values[i]))); |
| |
148 } |
| |
149 result = cxPropertiesNext(prop, &key, &value); |
| |
150 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
| |
151 } |
| |
152 |
| 118 CX_TEST(test_properties_next_multi) { |
153 CX_TEST(test_properties_next_multi) { |
| 119 const char *keys[] = { |
|
| 120 "a", |
|
| 121 "b", |
|
| 122 "c", |
|
| 123 "uap", |
|
| 124 "name", |
|
| 125 "key1", |
|
| 126 "key2", |
|
| 127 "key3" |
|
| 128 }; |
|
| 129 |
|
| 130 const char *values[] = { |
|
| 131 "a value", |
|
| 132 "b value", |
|
| 133 "core", |
|
| 134 "core", |
|
| 135 "ucx", |
|
| 136 "value1", |
|
| 137 "value2", |
|
| 138 "value3" |
|
| 139 }; |
|
| 140 |
|
| 141 const char *str = "#\n" |
154 const char *str = "#\n" |
| 142 "# properties\n" |
155 "# properties\n" |
| 143 "# contains key/value pairs\n" |
156 "# contains key/value pairs\n" |
| 144 "#\n" |
157 "#\n" |
| 145 "a = a value\n" |
158 "a = a value\n" |
| 155 "key2 = value2\n" |
168 "key2 = value2\n" |
| 156 "\n\n\n \n key3=value3\n"; |
169 "\n\n\n \n key3=value3\n"; |
| 157 |
170 |
| 158 CxProperties prop; |
171 CxProperties prop; |
| 159 cxPropertiesInitDefault(&prop); |
172 cxPropertiesInitDefault(&prop); |
| 160 CxPropertiesStatus result; |
173 |
| 161 cxstring key; |
174 CX_TEST_DO { |
| 162 cxstring value; |
175 CxPropertiesStatus result; |
| 163 |
176 cxstring key; |
| 164 CX_TEST_DO { |
177 cxstring value; |
| 165 result = cxPropertiesNext(&prop, &key, &value); |
178 result = cxPropertiesNext(&prop, &key, &value); |
| 166 CX_TEST_ASSERT(result == CX_PROPERTIES_NULL_INPUT); |
179 CX_TEST_ASSERT(result == CX_PROPERTIES_NULL_INPUT); |
| 167 cxPropertiesInput(&prop, str, strlen(str)); |
180 |
| 168 for (int i = 0; i < 8; i++) { |
181 // check for C string |
| 169 result = cxPropertiesNext(&prop, &key, &value); |
182 cxPropertiesFill(&prop, str); |
| 170 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
183 CX_TEST_CALL_SUBROUTINE(test_properties_next_multi_check, &prop); |
| 171 CX_TEST_ASSERT(!cx_strcmp(key, cx_str(keys[i]))); |
184 |
| 172 CX_TEST_ASSERT(!cx_strcmp(value, cx_str(values[i]))); |
185 // check for cxstring |
| 173 } |
186 cxPropertiesFill(&prop, cx_str(str)); |
| 174 result = cxPropertiesNext(&prop, &key, &value); |
187 CX_TEST_CALL_SUBROUTINE(test_properties_next_multi_check, &prop); |
| 175 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
188 |
| |
189 // check for mutstr |
| |
190 cxPropertiesFill(&prop, cx_mutstr((char*)str)); |
| |
191 CX_TEST_CALL_SUBROUTINE(test_properties_next_multi_check, &prop); |
| 176 } |
192 } |
| 177 cxPropertiesDestroy(&prop); |
193 cxPropertiesDestroy(&prop); |
| 178 } |
194 } |
| 179 |
195 |
| 180 CX_TEST(test_properties_next_part) { |
196 CX_TEST(test_properties_next_part) { |
| 185 cxstring value; |
201 cxstring value; |
| 186 const char *str; |
202 const char *str; |
| 187 |
203 |
| 188 CX_TEST_DO { |
204 CX_TEST_DO { |
| 189 str = ""; |
205 str = ""; |
| 190 cxPropertiesFill(&prop, str, strlen(str)); |
206 cxPropertiesFill(&prop, str); |
| 191 result = cxPropertiesNext(&prop, &key, &value); |
207 result = cxPropertiesNext(&prop, &key, &value); |
| 192 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
208 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
| 193 |
209 |
| 194 str = " \n"; |
210 str = " \n"; |
| 195 cxPropertiesFill(&prop, str, strlen(str)); |
211 cxPropertiesFill(&prop, str); |
| 196 result = cxPropertiesNext(&prop, &key, &value); |
212 result = cxPropertiesNext(&prop, &key, &value); |
| 197 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
213 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
| 198 |
214 |
| 199 str = "name"; |
215 str = "name"; |
| 200 cxPropertiesFill(&prop, str, strlen(str)); |
216 cxPropertiesFill(&prop, str); |
| 201 result = cxPropertiesNext(&prop, &key, &value); |
217 result = cxPropertiesNext(&prop, &key, &value); |
| 202 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
218 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
| 203 |
219 |
| 204 str = " "; |
220 str = " "; |
| 205 cxPropertiesFill(&prop, str, strlen(str)); |
221 cxPropertiesFill(&prop, str); |
| 206 result = cxPropertiesNext(&prop, &key, &value); |
222 result = cxPropertiesNext(&prop, &key, &value); |
| 207 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
223 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
| 208 |
224 |
| 209 // call fill twice in a row |
225 // call fill twice in a row |
| 210 str = "= "; |
226 str = "= "; |
| 211 cxPropertiesFill(&prop, str, strlen(str)); |
227 cxPropertiesFill(&prop, str); |
| 212 str = "value"; |
228 str = "value"; |
| 213 cxPropertiesFill(&prop, str, strlen(str)); |
229 cxPropertiesFill(&prop, str); |
| 214 result = cxPropertiesNext(&prop, &key, &value); |
230 result = cxPropertiesNext(&prop, &key, &value); |
| 215 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
231 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
| 216 |
232 |
| 217 str = "\n"; |
233 str = "\n"; |
| 218 cxPropertiesFill(&prop, str, strlen(str)); |
234 cxPropertiesFill(&prop, str); |
| 219 result = cxPropertiesNext(&prop, &key, &value); |
235 result = cxPropertiesNext(&prop, &key, &value); |
| 220 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
236 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
| 221 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("name"))); |
237 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("name"))); |
| 222 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("value"))); |
238 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("value"))); |
| 223 |
239 |
| 224 // second round |
240 // second round |
| 225 str = "#comment\n"; |
241 str = "#comment\n"; |
| 226 cxPropertiesFill(&prop, str, strlen(str)); |
242 cxPropertiesFill(&prop, str); |
| 227 result = cxPropertiesNext(&prop, &key, &value); |
243 result = cxPropertiesNext(&prop, &key, &value); |
| 228 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
244 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
| 229 |
245 |
| 230 str = "#comment\nname2 = "; |
246 str = "#comment\nname2 = "; |
| 231 cxPropertiesFill(&prop, str, strlen(str)); |
247 cxPropertiesFill(&prop, str); |
| 232 result = cxPropertiesNext(&prop, &key, &value); |
248 result = cxPropertiesNext(&prop, &key, &value); |
| 233 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
249 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
| 234 |
250 |
| 235 str = "value2\na = b\n"; |
251 str = "value2\na = b\n"; |
| 236 cxPropertiesFill(&prop, str, strlen(str)); |
252 cxPropertiesFill(&prop, str); |
| 237 result = cxPropertiesNext(&prop, &key, &value); |
253 result = cxPropertiesNext(&prop, &key, &value); |
| 238 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
254 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
| 239 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("name2"))); |
255 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("name2"))); |
| 240 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("value2"))); |
256 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("value2"))); |
| 241 |
257 |
| 243 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
259 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
| 244 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("a"))); |
260 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("a"))); |
| 245 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("b"))); |
261 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("b"))); |
| 246 |
262 |
| 247 str = "# comment\n#\n#\ntests = "; |
263 str = "# comment\n#\n#\ntests = "; |
| 248 cxPropertiesFill(&prop, str, strlen(str)); |
264 cxPropertiesFill(&prop, str); |
| 249 result = cxPropertiesNext(&prop, &key, &value); |
265 result = cxPropertiesNext(&prop, &key, &value); |
| 250 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
266 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
| 251 |
267 |
| 252 str = "test1 "; |
268 str = "test1 "; |
| 253 cxPropertiesFill(&prop, str, strlen(str)); |
269 cxPropertiesFill(&prop, str); |
| 254 result = cxPropertiesNext(&prop, &key, &value); |
270 result = cxPropertiesNext(&prop, &key, &value); |
| 255 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
271 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
| 256 |
272 |
| 257 str = "test2 test3 test4\n"; |
273 str = "test2 test3 test4\n"; |
| 258 cxPropertiesFill(&prop, str, strlen(str)); |
274 cxPropertiesFill(&prop, str); |
| 259 result = cxPropertiesNext(&prop, &key, &value); |
275 result = cxPropertiesNext(&prop, &key, &value); |
| 260 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
276 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
| 261 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("tests"))); |
277 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("tests"))); |
| 262 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("test1 test2 test3 test4"))); |
278 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("test1 test2 test3 test4"))); |
| 263 |
279 |
| 264 // test if cxPropertiesNext finds a name/value after a comment |
280 // test if cxPropertiesNext finds a name/value after a comment |
| 265 str = "# just a comment"; |
281 str = "# just a comment"; |
| 266 cxPropertiesFill(&prop, str, strlen(str)); |
282 cxPropertiesFill(&prop, str); |
| 267 result = cxPropertiesNext(&prop, &key, &value); |
283 result = cxPropertiesNext(&prop, &key, &value); |
| 268 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
284 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
| 269 |
285 |
| 270 str = " in 3"; |
286 str = " in 3"; |
| 271 cxPropertiesFill(&prop, str, strlen(str)); |
287 cxPropertiesFill(&prop, str); |
| 272 result = cxPropertiesNext(&prop, &key, &value); |
288 result = cxPropertiesNext(&prop, &key, &value); |
| 273 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
289 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
| 274 |
290 |
| 275 str = " parts\nx = 1\n"; |
291 str = " parts\nx = 1\n"; |
| 276 cxPropertiesFill(&prop, str, strlen(str)); |
292 cxPropertiesFill(&prop, str); |
| 277 result = cxPropertiesNext(&prop, &key, &value); |
293 result = cxPropertiesNext(&prop, &key, &value); |
| 278 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
294 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
| 279 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("x"))); |
295 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("x"))); |
| 280 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("1"))); |
296 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("1"))); |
| 281 |
297 |
| 303 char *long_value = (char*)malloc(value_len); |
319 char *long_value = (char*)malloc(value_len); |
| 304 memset(long_value, 'x', 1024); |
320 memset(long_value, 'x', 1024); |
| 305 memset(long_value+1024, 'y', 1024); |
321 memset(long_value+1024, 'y', 1024); |
| 306 |
322 |
| 307 CX_TEST_DO { |
323 CX_TEST_DO { |
| 308 cxPropertiesFill(&prop, long_key, 10); |
324 cxPropertiesFilln(&prop, long_key, 10); |
| 309 result = cxPropertiesNext(&prop, &key, &value); |
325 result = cxPropertiesNext(&prop, &key, &value); |
| 310 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
326 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
| 311 |
327 |
| 312 cxPropertiesFill(&prop, long_key + 10, 202); |
328 cxPropertiesFilln(&prop, long_key + 10, 202); |
| 313 result = cxPropertiesNext(&prop, &key, &value); |
329 result = cxPropertiesNext(&prop, &key, &value); |
| 314 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
330 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
| 315 |
331 |
| 316 cxPropertiesFill(&prop, long_key + 212, 200); |
332 cxPropertiesFilln(&prop, long_key + 212, 200); |
| 317 result = cxPropertiesNext(&prop, &key, &value); |
333 result = cxPropertiesNext(&prop, &key, &value); |
| 318 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
334 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
| 319 |
335 |
| 320 cxPropertiesFill(&prop, long_key + 412, 100); |
336 cxPropertiesFilln(&prop, long_key + 412, 100); |
| 321 result = cxPropertiesNext(&prop, &key, &value); |
337 result = cxPropertiesNext(&prop, &key, &value); |
| 322 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
338 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
| 323 |
339 |
| 324 const char *str = " = "; |
340 const char *str = " = "; |
| 325 cxPropertiesFill(&prop, str, strlen(str)); |
341 cxPropertiesFill(&prop, str); |
| 326 result = cxPropertiesNext(&prop, &key, &value); |
342 result = cxPropertiesNext(&prop, &key, &value); |
| 327 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
343 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
| 328 |
344 |
| 329 cxPropertiesFill(&prop, long_value, 512); |
345 cxPropertiesFilln(&prop, long_value, 512); |
| 330 result = cxPropertiesNext(&prop, &key, &value); |
346 result = cxPropertiesNext(&prop, &key, &value); |
| 331 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
347 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
| 332 |
348 |
| 333 cxPropertiesFill(&prop, long_value + 512, 1024); |
349 cxPropertiesFilln(&prop, long_value + 512, 1024); |
| 334 result = cxPropertiesNext(&prop, &key, &value); |
350 result = cxPropertiesNext(&prop, &key, &value); |
| 335 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
351 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
| 336 |
352 |
| 337 cxPropertiesFill(&prop, long_value + 1536, 512); |
353 cxPropertiesFilln(&prop, long_value + 1536, 512); |
| 338 result = cxPropertiesNext(&prop, &key, &value); |
354 result = cxPropertiesNext(&prop, &key, &value); |
| 339 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
355 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
| 340 |
356 |
| 341 str = "\n#comment\nkey = value\n"; |
357 str = "\n#comment\nkey = value\n"; |
| 342 cxPropertiesFill(&prop, str, strlen(str)); |
358 cxPropertiesFill(&prop, str); |
| 343 result = cxPropertiesNext(&prop, &key, &value); |
359 result = cxPropertiesNext(&prop, &key, &value); |
| 344 cxstring k = cx_strn(long_key, key_len); |
360 cxstring k = cx_strn(long_key, key_len); |
| 345 cxstring v = cx_strn(long_value, value_len); |
361 cxstring v = cx_strn(long_value, value_len); |
| 346 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
362 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
| 347 CX_TEST_ASSERT(0 == cx_strcmp(key, k)); |
363 CX_TEST_ASSERT(0 == cx_strcmp(key, k)); |