1.1 --- a/test/prop_tests.c Sun Jul 14 17:11:34 2013 +0200 1.2 +++ b/test/prop_tests.c Mon Jul 15 13:53:51 2013 +0200 1.3 @@ -28,8 +28,8 @@ 1.4 1.5 #include "prop_tests.h" 1.6 1.7 -UCX_TEST_IMPLEMENT(test_ucx_prop_new) { 1.8 - UcxPropParser *parser = ucx_prop_new(); 1.9 +UCX_TEST_IMPLEMENT(test_ucx_properties_new) { 1.10 + UcxProperties *parser = ucx_properties_new(); 1.11 1.12 UCX_TEST_BEGIN 1.13 1.14 @@ -39,10 +39,10 @@ 1.15 1.16 UCX_TEST_END 1.17 1.18 - ucx_prop_free(parser); 1.19 + ucx_properties_free(parser); 1.20 } 1.21 1.22 -UCX_TEST_IMPLEMENT(test_ucx_prop_parse) { 1.23 +UCX_TEST_IMPLEMENT(test_ucx_properties_next) { 1.24 const char *tests[] = { 1.25 "name = value\n", 1.26 "name=value\n", 1.27 @@ -88,32 +88,32 @@ 1.28 sstr_t value; 1.29 1.30 for(int i=0;i<10;i++) { 1.31 - UcxPropParser *parser = ucx_prop_new(); 1.32 + UcxProperties *parser = ucx_properties_new(); 1.33 1.34 - ucx_prop_fill(parser, (char*)tests[i], strlen(tests[i])); 1.35 + ucx_properties_fill(parser, (char*)tests[i], strlen(tests[i])); 1.36 UCX_TEST_ASSERT(parser->buffer == tests[i], "fill failed"); 1.37 UCX_TEST_ASSERT(parser->buflen == strlen(tests[i]), "wrong buflen"); 1.38 1.39 - int r = ucx_prop_parse(parser, &name, &value); 1.40 + int r = ucx_properties_next(parser, &name, &value); 1.41 sstr_t n = sstr((char*)names[i]); 1.42 sstr_t v = sstr((char*)values[i]); 1.43 - UCX_TEST_ASSERT(r == 1, "parse returned 0"); 1.44 + UCX_TEST_ASSERT(r == 1, "next returned 0"); 1.45 UCX_TEST_ASSERT((!sstrcmp(name, n)), "wrong property name"); 1.46 UCX_TEST_ASSERT((!sstrcmp(value, v)), "wrong property value"); 1.47 1.48 - r = ucx_prop_parse(parser, &name, &value); 1.49 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.50 + r = ucx_properties_next(parser, &name, &value); 1.51 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.52 UCX_TEST_ASSERT(parser->tmp == NULL, "tmp not NULL"); 1.53 UCX_TEST_ASSERT(parser->tmpcap == 0, "tmpcap not NULL"); 1.54 UCX_TEST_ASSERT(parser->tmplen == 0, "tmplen not NULL"); 1.55 1.56 - ucx_prop_free(parser); 1.57 + ucx_properties_free(parser); 1.58 } 1.59 1.60 UCX_TEST_END 1.61 } 1.62 1.63 -UCX_TEST_IMPLEMENT(test_ucx_prop_parse_multi) { 1.64 +UCX_TEST_IMPLEMENT(test_ucx_properties_next_multi) { 1.65 const char *names[] = { 1.66 "a", 1.67 "b", 1.68 @@ -153,31 +153,31 @@ 1.69 "key2 = value2\n" 1.70 "\n\n\n \n key3=value3\n"; 1.71 1.72 - UcxPropParser *parser = ucx_prop_new(); 1.73 + UcxProperties *parser = ucx_properties_new(); 1.74 1.75 UCX_TEST_BEGIN 1.76 1.77 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.78 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.79 1.80 sstr_t name; 1.81 sstr_t value; 1.82 for(int i=0;i<8;i++) { 1.83 - int r = ucx_prop_parse(parser, &name, &value); 1.84 - UCX_TEST_ASSERT(r == 1, "parse returned 0"); 1.85 + int r = ucx_properties_next(parser, &name, &value); 1.86 + UCX_TEST_ASSERT(r == 1, "next returned 0"); 1.87 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)names[i]))), "wrong name"); 1.88 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)values[i]))), 1.89 "wrong value"); 1.90 } 1.91 - int r = ucx_prop_parse(parser, &name, &value); 1.92 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.93 + int r = ucx_properties_next(parser, &name, &value); 1.94 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.95 1.96 UCX_TEST_END 1.97 1.98 - ucx_prop_free(parser); 1.99 + ucx_properties_free(parser); 1.100 } 1.101 1.102 -UCX_TEST_IMPLEMENT(test_ucx_prop_parse_part) { 1.103 - UcxPropParser *parser = ucx_prop_new(); 1.104 +UCX_TEST_IMPLEMENT(test_ucx_properties_next_part) { 1.105 + UcxProperties *parser = ucx_properties_new(); 1.106 const char *str; 1.107 int r; 1.108 sstr_t name; 1.109 @@ -186,108 +186,108 @@ 1.110 UCX_TEST_BEGIN 1.111 1.112 str = ""; 1.113 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.114 - r = ucx_prop_parse(parser, &name, &value); 1.115 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.116 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.117 + r = ucx_properties_next(parser, &name, &value); 1.118 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.119 1.120 str = " \n"; 1.121 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.122 - r = ucx_prop_parse(parser, &name, &value); 1.123 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.124 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.125 + r = ucx_properties_next(parser, &name, &value); 1.126 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.127 1.128 str = "name"; 1.129 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.130 - r = ucx_prop_parse(parser, &name, &value); 1.131 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.132 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.133 + r = ucx_properties_next(parser, &name, &value); 1.134 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.135 1.136 str = " "; 1.137 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.138 - r = ucx_prop_parse(parser, &name, &value); 1.139 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.140 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.141 + r = ucx_properties_next(parser, &name, &value); 1.142 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.143 1.144 str = "= "; 1.145 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.146 - r = ucx_prop_parse(parser, &name, &value); 1.147 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.148 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.149 + r = ucx_properties_next(parser, &name, &value); 1.150 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.151 1.152 str = "value"; 1.153 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.154 - r = ucx_prop_parse(parser, &name, &value); 1.155 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.156 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.157 + r = ucx_properties_next(parser, &name, &value); 1.158 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.159 1.160 str = "\n"; 1.161 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.162 - r = ucx_prop_parse(parser, &name, &value); 1.163 - UCX_TEST_ASSERT(r == 1, "parse returned 0"); 1.164 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.165 + r = ucx_properties_next(parser, &name, &value); 1.166 + UCX_TEST_ASSERT(r == 1, "next returned 0"); 1.167 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"name"))), "wrong name"); 1.168 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"value"))), "wrong value"); 1.169 1.170 // second round 1.171 str = "#comment\n"; 1.172 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.173 - r = ucx_prop_parse(parser, &name, &value); 1.174 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.175 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.176 + r = ucx_properties_next(parser, &name, &value); 1.177 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.178 1.179 str = "#comment\nname = "; 1.180 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.181 - r = ucx_prop_parse(parser, &name, &value); 1.182 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.183 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.184 + r = ucx_properties_next(parser, &name, &value); 1.185 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.186 1.187 str = "value\na = b\n"; 1.188 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.189 - r = ucx_prop_parse(parser, &name, &value); 1.190 - UCX_TEST_ASSERT(r == 1, "parse returned 0"); 1.191 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.192 + r = ucx_properties_next(parser, &name, &value); 1.193 + UCX_TEST_ASSERT(r == 1, "next returned 0"); 1.194 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"name"))), "wrong name"); 1.195 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"value"))), "wrong value"); 1.196 1.197 - r = ucx_prop_parse(parser, &name, &value); 1.198 - UCX_TEST_ASSERT(r == 1, "parse returned 0"); 1.199 + r = ucx_properties_next(parser, &name, &value); 1.200 + UCX_TEST_ASSERT(r == 1, "next returned 0"); 1.201 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"a"))), "wrong name"); 1.202 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"b"))), "wrong value"); 1.203 1.204 str = "# comment\n#\n#\ntests = "; 1.205 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.206 - r = ucx_prop_parse(parser, &name, &value); 1.207 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.208 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.209 + r = ucx_properties_next(parser, &name, &value); 1.210 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.211 1.212 str = "test1 "; 1.213 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.214 - r = ucx_prop_parse(parser, &name, &value); 1.215 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.216 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.217 + r = ucx_properties_next(parser, &name, &value); 1.218 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.219 1.220 str = "test2 test3 test4\n"; 1.221 sstr_t testv = sstr((char*)"test1 test2 test3 test4"); 1.222 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.223 - r = ucx_prop_parse(parser, &name, &value); 1.224 - UCX_TEST_ASSERT(r == 1, "parse returned 0"); 1.225 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.226 + r = ucx_properties_next(parser, &name, &value); 1.227 + UCX_TEST_ASSERT(r == 1, "next returned 0"); 1.228 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"tests"))), "wrong name"); 1.229 UCX_TEST_ASSERT((!sstrcmp(value, testv)), "wrong value"); 1.230 1.231 - // test if parse finds a name/value after a tmp comment 1.232 + // test if ucx_properties_next finds a name/value after a tmp comment 1.233 str = "# just a comment"; 1.234 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.235 - r = ucx_prop_parse(parser, &name, &value); 1.236 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.237 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.238 + r = ucx_properties_next(parser, &name, &value); 1.239 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.240 1.241 str = " in 3"; 1.242 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.243 - r = ucx_prop_parse(parser, &name, &value); 1.244 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.245 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.246 + r = ucx_properties_next(parser, &name, &value); 1.247 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.248 1.249 str = " parts\na = 1\n"; 1.250 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.251 - r = ucx_prop_parse(parser, &name, &value); 1.252 - UCX_TEST_ASSERT(r == 1, "parse returned 0"); 1.253 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.254 + r = ucx_properties_next(parser, &name, &value); 1.255 + UCX_TEST_ASSERT(r == 1, "next returned 0"); 1.256 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"a"))), "wrong name"); 1.257 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"1"))), "wrong value"); 1.258 1.259 UCX_TEST_END 1.260 1.261 - ucx_prop_free(parser); 1.262 + ucx_properties_free(parser); 1.263 } 1.264 1.265 -UCX_TEST_IMPLEMENT(test_ucx_prop_parse_long) { 1.266 - UcxPropParser *parser = ucx_prop_new(); 1.267 +UCX_TEST_IMPLEMENT(test_ucx_properties_next_long) { 1.268 + UcxProperties *parser = ucx_properties_new(); 1.269 int r; 1.270 size_t name_len = 512; 1.271 char *long_name = (char*)malloc(name_len); 1.272 @@ -305,75 +305,75 @@ 1.273 sstr_t name; 1.274 sstr_t value; 1.275 1.276 - ucx_prop_fill(parser, long_name, 10); 1.277 - r = ucx_prop_parse(parser, &name, &value); 1.278 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.279 + ucx_properties_fill(parser, long_name, 10); 1.280 + r = ucx_properties_next(parser, &name, &value); 1.281 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.282 1.283 - ucx_prop_fill(parser, long_name+10, 202); 1.284 - r = ucx_prop_parse(parser, &name, &value); 1.285 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.286 + ucx_properties_fill(parser, long_name+10, 202); 1.287 + r = ucx_properties_next(parser, &name, &value); 1.288 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.289 1.290 - ucx_prop_fill(parser, long_name+212, 200); 1.291 - r = ucx_prop_parse(parser, &name, &value); 1.292 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.293 + ucx_properties_fill(parser, long_name+212, 200); 1.294 + r = ucx_properties_next(parser, &name, &value); 1.295 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.296 1.297 - ucx_prop_fill(parser, long_name+412, 100); 1.298 - r = ucx_prop_parse(parser, &name, &value); 1.299 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.300 + ucx_properties_fill(parser, long_name+412, 100); 1.301 + r = ucx_properties_next(parser, &name, &value); 1.302 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.303 1.304 const char *str = " = "; 1.305 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.306 - r = ucx_prop_parse(parser, &name, &value); 1.307 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.308 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.309 + r = ucx_properties_next(parser, &name, &value); 1.310 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.311 1.312 - ucx_prop_fill(parser, long_value, 512); 1.313 - r = ucx_prop_parse(parser, &name, &value); 1.314 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.315 + ucx_properties_fill(parser, long_value, 512); 1.316 + r = ucx_properties_next(parser, &name, &value); 1.317 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.318 1.319 - ucx_prop_fill(parser, long_value+512, 1024); 1.320 - r = ucx_prop_parse(parser, &name, &value); 1.321 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.322 + ucx_properties_fill(parser, long_value+512, 1024); 1.323 + r = ucx_properties_next(parser, &name, &value); 1.324 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.325 1.326 - ucx_prop_fill(parser, long_value+1536, 512); 1.327 - r = ucx_prop_parse(parser, &name, &value); 1.328 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.329 + ucx_properties_fill(parser, long_value+1536, 512); 1.330 + r = ucx_properties_next(parser, &name, &value); 1.331 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.332 1.333 str = "\n#comment\nkey = value\n"; 1.334 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.335 - r = ucx_prop_parse(parser, &name, &value); 1.336 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.337 + r = ucx_properties_next(parser, &name, &value); 1.338 sstr_t n = sstrn(long_name, name_len); 1.339 sstr_t v = sstrn(long_value, value_len); 1.340 - UCX_TEST_ASSERT(r == 1, "parse returned 0"); 1.341 + UCX_TEST_ASSERT(r == 1, "next returned 0"); 1.342 UCX_TEST_ASSERT((!sstrcmp(name, n)), "wrong name"); 1.343 UCX_TEST_ASSERT((!sstrcmp(value, v)), "wrong value"); 1.344 1.345 - r = ucx_prop_parse(parser, &name, &value); 1.346 - UCX_TEST_ASSERT(r == 1, "parse returned 0"); 1.347 + r = ucx_properties_next(parser, &name, &value); 1.348 + UCX_TEST_ASSERT(r == 1, "next returned 0"); 1.349 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"key"))), "wrong name"); 1.350 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"value"))), "wrong value"); 1.351 1.352 - r = ucx_prop_parse(parser, &name, &value); 1.353 - UCX_TEST_ASSERT(r == 0, "parse returned 1"); 1.354 + r = ucx_properties_next(parser, &name, &value); 1.355 + UCX_TEST_ASSERT(r == 0, "next returned 1"); 1.356 1.357 UCX_TEST_END 1.358 1.359 free(long_name); 1.360 free(long_value); 1.361 - ucx_prop_free(parser); 1.362 + ucx_properties_free(parser); 1.363 } 1.364 1.365 -UCX_TEST_IMPLEMENT(test_ucx_prop_parse2map) { 1.366 +UCX_TEST_IMPLEMENT(test_ucx_properties2map) { 1.367 UcxMap *map = ucx_map_new(16); 1.368 - UcxPropParser *parser = ucx_prop_new(); 1.369 + UcxProperties *parser = ucx_properties_new(); 1.370 1.371 UCX_TEST_BEGIN 1.372 1.373 const char *str = "key1 = value1\nkey2 = value2\n\n#comment\n\nkey3 = value3\n"; 1.374 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.375 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.376 1.377 - int r = ucx_prop_parse2map(parser, map); 1.378 + int r = ucx_properties2map(parser, map); 1.379 1.380 - UCX_TEST_ASSERT(r == 0, "parse2map failed"); 1.381 + UCX_TEST_ASSERT(r == 0, "properties2map failed"); 1.382 UCX_TEST_ASSERT(map->count == 3, "wrong number of properties"); 1.383 1.384 char *v1 = (char*)ucx_map_cstr_get(map, "key1"); 1.385 @@ -396,17 +396,17 @@ 1.386 map = ucx_map_new(16); 1.387 1.388 str = "\n#comment\n"; 1.389 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.390 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.391 1.392 - r = ucx_prop_parse2map(parser, map); 1.393 - UCX_TEST_ASSERT(r == 0, "parse2map failed"); 1.394 + r = ucx_properties2map(parser, map); 1.395 + UCX_TEST_ASSERT(r == 0, "properties2map failed"); 1.396 UCX_TEST_ASSERT(map->count == 0, "wrong number of properties"); 1.397 1.398 str = "key1 = value1\nsyntax error line\n"; 1.399 - ucx_prop_fill(parser, (char*)str, strlen(str)); 1.400 + ucx_properties_fill(parser, (char*)str, strlen(str)); 1.401 1.402 - r = ucx_prop_parse2map(parser, map); 1.403 - UCX_TEST_ASSERT(r == 1, "parse2map should return 1"); 1.404 + r = ucx_properties2map(parser, map); 1.405 + UCX_TEST_ASSERT(r == 1, "properties2map should return 1"); 1.406 UCX_TEST_ASSERT(map->count == 1, "wrong number of properties"); 1.407 1.408 char *v = (char*)ucx_map_cstr_get(map, "key1"); 1.409 @@ -414,7 +414,7 @@ 1.410 1.411 UCX_TEST_END 1.412 1.413 - ucx_prop_free(parser); 1.414 + ucx_properties_free(parser); 1.415 } 1.416 1.417 UCX_TEST_IMPLEMENT(test_ucx_properties_load) {