test/prop_tests.c

changeset 390
d345541018fa
parent 389
92e482410453
child 391
f094a53c1178
     1.1 --- a/test/prop_tests.c	Mon Dec 30 09:54:10 2019 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,545 +0,0 @@
     1.4 -/*
     1.5 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     1.6 - *
     1.7 - * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved.
     1.8 - *
     1.9 - * Redistribution and use in source and binary forms, with or without
    1.10 - * modification, are permitted provided that the following conditions are met:
    1.11 - *
    1.12 - *   1. Redistributions of source code must retain the above copyright
    1.13 - *      notice, this list of conditions and the following disclaimer.
    1.14 - *
    1.15 - *   2. Redistributions in binary form must reproduce the above copyright
    1.16 - *      notice, this list of conditions and the following disclaimer in the
    1.17 - *      documentation and/or other materials provided with the distribution.
    1.18 - *
    1.19 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1.20 - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.21 - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.22 - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
    1.23 - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    1.24 - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    1.25 - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    1.26 - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    1.27 - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    1.28 - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    1.29 - * POSSIBILITY OF SUCH DAMAGE.
    1.30 - */
    1.31 -
    1.32 -#include "prop_tests.h"
    1.33 -#include <ucx/mempool.h>
    1.34 -
    1.35 -UCX_TEST(test_ucx_properties_new) {
    1.36 -    UcxProperties *parser = ucx_properties_new();
    1.37 -    
    1.38 -    UCX_TEST_BEGIN
    1.39 -            
    1.40 -    UCX_TEST_ASSERT(parser != NULL, "failed");
    1.41 -    UCX_TEST_ASSERT(parser->buffer == NULL, "parser has buffer");
    1.42 -    UCX_TEST_ASSERT(parser->tmp == NULL, "parser has tmp buffer");
    1.43 -    
    1.44 -    UCX_TEST_END
    1.45 -            
    1.46 -    ucx_properties_free(parser);
    1.47 -}
    1.48 -
    1.49 -UCX_TEST(test_ucx_properties_next) {  
    1.50 -    const char *tests[] = {
    1.51 -        "name = value\n",
    1.52 -        "name=value\n",
    1.53 -        "n=value\n",
    1.54 -        "name=v\n",
    1.55 -        "n=v\n",
    1.56 -        "name = value # comment\n",
    1.57 -        "#comment\nn=v\n",
    1.58 -        "# comment1\n# comment2\n\n    \n\nname = value\n",
    1.59 -        "    name     =      value\n",
    1.60 -        "name = value\n\n"
    1.61 -    };
    1.62 -    
    1.63 -    const char *names[] = {
    1.64 -        "name",
    1.65 -        "name",
    1.66 -        "n",
    1.67 -        "name",
    1.68 -        "n",
    1.69 -        "name",
    1.70 -        "n",
    1.71 -        "name",
    1.72 -        "name",
    1.73 -        "name"
    1.74 -    };
    1.75 -    
    1.76 -    const char *values[] = {
    1.77 -        "value",
    1.78 -        "value",
    1.79 -        "value",
    1.80 -        "v",
    1.81 -        "v",
    1.82 -        "value",
    1.83 -        "v",
    1.84 -        "value",
    1.85 -        "value",
    1.86 -        "value"
    1.87 -    };
    1.88 -    
    1.89 -    UCX_TEST_BEGIN
    1.90 -    
    1.91 -    sstr_t name;
    1.92 -    sstr_t value;
    1.93 -    
    1.94 -    for(int i=0;i<10;i++) {
    1.95 -        UcxProperties *parser = ucx_properties_new();
    1.96 -        
    1.97 -        ucx_properties_fill(parser, (char*)tests[i], strlen(tests[i]));
    1.98 -        UCX_TEST_ASSERT(parser->buffer == tests[i], "fill failed");
    1.99 -        UCX_TEST_ASSERT(parser->buflen == strlen(tests[i]), "wrong buflen");
   1.100 -        
   1.101 -        int r = ucx_properties_next(parser, &name, &value);
   1.102 -        sstr_t n = sstr((char*)names[i]);
   1.103 -        sstr_t v = sstr((char*)values[i]);
   1.104 -        UCX_TEST_ASSERT(r == 1, "next returned 0");
   1.105 -        UCX_TEST_ASSERT((!sstrcmp(name, n)), "wrong property name");
   1.106 -        UCX_TEST_ASSERT((!sstrcmp(value, v)), "wrong property value");
   1.107 -        
   1.108 -        r = ucx_properties_next(parser, &name, &value);
   1.109 -        UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.110 -        UCX_TEST_ASSERT(parser->tmp == NULL, "tmp not NULL");
   1.111 -        UCX_TEST_ASSERT(parser->tmpcap == 0, "tmpcap not NULL");
   1.112 -        UCX_TEST_ASSERT(parser->tmplen == 0, "tmplen not NULL");
   1.113 -        
   1.114 -        ucx_properties_free(parser);
   1.115 -    }
   1.116 -    
   1.117 -    UCX_TEST_END       
   1.118 -}
   1.119 -
   1.120 -UCX_TEST(test_ucx_properties_next_multi) {
   1.121 -    const char *names[] = {
   1.122 -        "a",
   1.123 -        "b",
   1.124 -        "c",
   1.125 -        "uap",
   1.126 -        "name",
   1.127 -        "key1",
   1.128 -        "key2",
   1.129 -        "key3"
   1.130 -    };
   1.131 -    
   1.132 -    const char *values[] = {
   1.133 -        "a value",
   1.134 -        "b value",
   1.135 -        "core",
   1.136 -        "core",
   1.137 -        "ucx",
   1.138 -        "value1",
   1.139 -        "value2",
   1.140 -        "value3"
   1.141 -    };
   1.142 -    
   1.143 -    const char *str = "#\n"
   1.144 -        "# properties\n"
   1.145 -        "# contains key/value pairs\n"
   1.146 -        "#\n"
   1.147 -        "a = a value\n"
   1.148 -        "b = b value\n"
   1.149 -        "c = core\n"
   1.150 -        "\n# test\n"
   1.151 -        "uap = core\n"
   1.152 -        "name = ucx\n"
   1.153 -        "# no = property\n"
   1.154 -        "key1 = value1\n"
   1.155 -        "#key1 = wrong value\n"
   1.156 -        "#key2 = not value 2\n"
   1.157 -        "key2 = value2\n"
   1.158 -        "\n\n\n        \n           key3=value3\n";
   1.159 -    
   1.160 -    UcxProperties *parser = ucx_properties_new();
   1.161 -    
   1.162 -    UCX_TEST_BEGIN
   1.163 -    
   1.164 -    ucx_properties_fill(parser, (char*)str, strlen(str));
   1.165 -    
   1.166 -    sstr_t name;
   1.167 -    sstr_t value;
   1.168 -    for(int i=0;i<8;i++) {
   1.169 -        int r = ucx_properties_next(parser, &name, &value);
   1.170 -        UCX_TEST_ASSERT(r == 1, "next returned 0");
   1.171 -        UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)names[i]))), "wrong name");
   1.172 -        UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)values[i]))),
   1.173 -                "wrong value");
   1.174 -    }
   1.175 -    int r = ucx_properties_next(parser, &name, &value);
   1.176 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.177 -    
   1.178 -    UCX_TEST_END
   1.179 -    
   1.180 -    ucx_properties_free(parser);
   1.181 -}
   1.182 -
   1.183 -UCX_TEST(test_ucx_properties_next_part) {
   1.184 -    UcxProperties *parser = ucx_properties_new();
   1.185 -    const char *str;
   1.186 -    int r;
   1.187 -    sstr_t name;
   1.188 -    sstr_t value;
   1.189 -    
   1.190 -    UCX_TEST_BEGIN
   1.191 -    
   1.192 -    str = "";
   1.193 -    ucx_properties_fill(parser, (char*)str, strlen(str));
   1.194 -    r = ucx_properties_next(parser, &name, &value);
   1.195 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.196 -    
   1.197 -    str = "  \n";
   1.198 -    ucx_properties_fill(parser, (char*)str, strlen(str));
   1.199 -    r = ucx_properties_next(parser, &name, &value); 
   1.200 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.201 -    
   1.202 -    str = "name";
   1.203 -    ucx_properties_fill(parser, (char*)str, strlen(str));
   1.204 -    r = ucx_properties_next(parser, &name, &value); 
   1.205 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.206 -    
   1.207 -    str = "    ";
   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 = "= ";
   1.213 -    ucx_properties_fill(parser, (char*)str, strlen(str));
   1.214 -    r = ucx_properties_next(parser, &name, &value); 
   1.215 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.216 -    
   1.217 -    str = "value";
   1.218 -    ucx_properties_fill(parser, (char*)str, strlen(str));
   1.219 -    r = ucx_properties_next(parser, &name, &value); 
   1.220 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.221 -    
   1.222 -    str = "\n";
   1.223 -    ucx_properties_fill(parser, (char*)str, strlen(str));
   1.224 -    r = ucx_properties_next(parser, &name, &value); 
   1.225 -    UCX_TEST_ASSERT(r == 1, "next returned 0");
   1.226 -    UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"name"))), "wrong name");
   1.227 -    UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"value"))), "wrong value");
   1.228 -    
   1.229 -    // second round
   1.230 -    str = "#comment\n";
   1.231 -    ucx_properties_fill(parser, (char*)str, strlen(str));
   1.232 -    r = ucx_properties_next(parser, &name, &value); 
   1.233 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.234 -    
   1.235 -    str = "#comment\nname = ";
   1.236 -    ucx_properties_fill(parser, (char*)str, strlen(str));
   1.237 -    r = ucx_properties_next(parser, &name, &value); 
   1.238 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.239 -    
   1.240 -    str = "value\na = b\n";
   1.241 -    ucx_properties_fill(parser, (char*)str, strlen(str));
   1.242 -    r = ucx_properties_next(parser, &name, &value); 
   1.243 -    UCX_TEST_ASSERT(r == 1, "next returned 0");
   1.244 -    UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"name"))), "wrong name");
   1.245 -    UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"value"))), "wrong value");
   1.246 -    
   1.247 -    r = ucx_properties_next(parser, &name, &value); 
   1.248 -    UCX_TEST_ASSERT(r == 1, "next returned 0");
   1.249 -    UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"a"))), "wrong name");
   1.250 -    UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"b"))), "wrong value");
   1.251 -    
   1.252 -    str = "# comment\n#\n#\ntests = ";
   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 == 0, "next returned 1");
   1.256 -    
   1.257 -    str = "test1 ";
   1.258 -    ucx_properties_fill(parser, (char*)str, strlen(str));
   1.259 -    r = ucx_properties_next(parser, &name, &value); 
   1.260 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.261 -    
   1.262 -    str = "test2 test3 test4\n";
   1.263 -    sstr_t testv = sstr((char*)"test1 test2 test3 test4");
   1.264 -    ucx_properties_fill(parser, (char*)str, strlen(str));
   1.265 -    r = ucx_properties_next(parser, &name, &value); 
   1.266 -    UCX_TEST_ASSERT(r == 1, "next returned 0");
   1.267 -    UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"tests"))), "wrong name");
   1.268 -    UCX_TEST_ASSERT((!sstrcmp(value, testv)), "wrong value");
   1.269 -    
   1.270 -    // test if ucx_properties_next finds a name/value after a tmp comment
   1.271 -    str = "# just a comment";
   1.272 -    ucx_properties_fill(parser, (char*)str, strlen(str));
   1.273 -    r = ucx_properties_next(parser, &name, &value); 
   1.274 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.275 -    
   1.276 -    str = " in 3";
   1.277 -    ucx_properties_fill(parser, (char*)str, strlen(str));
   1.278 -    r = ucx_properties_next(parser, &name, &value); 
   1.279 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.280 -    
   1.281 -    str = " parts\na = 1\n";
   1.282 -    ucx_properties_fill(parser, (char*)str, strlen(str));
   1.283 -    r = ucx_properties_next(parser, &name, &value); 
   1.284 -    UCX_TEST_ASSERT(r == 1, "next returned 0");
   1.285 -    UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"a"))), "wrong name");
   1.286 -    UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"1"))), "wrong value");
   1.287 -    
   1.288 -    UCX_TEST_END
   1.289 -    
   1.290 -    ucx_properties_free(parser);
   1.291 -}
   1.292 -
   1.293 -UCX_TEST(test_ucx_properties_next_long) {
   1.294 -    UcxProperties *parser = ucx_properties_new();
   1.295 -    int r;
   1.296 -    size_t name_len = 512;
   1.297 -    char *long_name = (char*)malloc(name_len);
   1.298 -    memset(long_name, 'a', 70);
   1.299 -    memset(long_name+70, 'b', 242);
   1.300 -    memset(long_name+312, 'c', 200);
   1.301 -    
   1.302 -    size_t value_len = 2048;
   1.303 -    char *long_value = (char*)malloc(value_len);
   1.304 -    memset(long_value, 'x', 1024);
   1.305 -    memset(long_value+1024, 'y', 1024);
   1.306 -    
   1.307 -    UCX_TEST_BEGIN
   1.308 -    
   1.309 -    sstr_t name;
   1.310 -    sstr_t value;
   1.311 -    
   1.312 -    ucx_properties_fill(parser, long_name, 10);
   1.313 -    r = ucx_properties_next(parser, &name, &value);
   1.314 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.315 -    
   1.316 -    ucx_properties_fill(parser, long_name+10, 202);
   1.317 -    r = ucx_properties_next(parser, &name, &value);
   1.318 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.319 -    
   1.320 -    ucx_properties_fill(parser, long_name+212, 200);
   1.321 -    r = ucx_properties_next(parser, &name, &value);
   1.322 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.323 -    
   1.324 -    ucx_properties_fill(parser, long_name+412, 100);
   1.325 -    r = ucx_properties_next(parser, &name, &value);
   1.326 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.327 -    
   1.328 -    const char *str = " = ";
   1.329 -    ucx_properties_fill(parser, (char*)str, strlen(str));
   1.330 -    r = ucx_properties_next(parser, &name, &value);
   1.331 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.332 -    
   1.333 -    ucx_properties_fill(parser, long_value, 512);
   1.334 -    r = ucx_properties_next(parser, &name, &value); 
   1.335 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.336 -    
   1.337 -    ucx_properties_fill(parser, long_value+512, 1024);
   1.338 -    r = ucx_properties_next(parser, &name, &value);
   1.339 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.340 -    
   1.341 -    ucx_properties_fill(parser, long_value+1536, 512);
   1.342 -    r = ucx_properties_next(parser, &name, &value);
   1.343 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.344 -    
   1.345 -    str = "\n#comment\nkey = value\n";
   1.346 -    ucx_properties_fill(parser, (char*)str, strlen(str));    
   1.347 -    r = ucx_properties_next(parser, &name, &value);
   1.348 -    sstr_t n = sstrn(long_name, name_len);
   1.349 -    sstr_t v = sstrn(long_value, value_len);
   1.350 -    UCX_TEST_ASSERT(r == 1, "next returned 0");
   1.351 -    UCX_TEST_ASSERT((!sstrcmp(name, n)), "wrong name");
   1.352 -    UCX_TEST_ASSERT((!sstrcmp(value, v)), "wrong value");
   1.353 -    
   1.354 -    r = ucx_properties_next(parser, &name, &value);
   1.355 -    UCX_TEST_ASSERT(r == 1, "next returned 0");
   1.356 -    UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"key"))), "wrong name");
   1.357 -    UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"value"))), "wrong value");
   1.358 -    
   1.359 -    r = ucx_properties_next(parser, &name, &value);
   1.360 -    UCX_TEST_ASSERT(r == 0, "next returned 1");
   1.361 -    
   1.362 -    UCX_TEST_END
   1.363 -    
   1.364 -    free(long_name);
   1.365 -    free(long_value);
   1.366 -    ucx_properties_free(parser);
   1.367 -}
   1.368 -
   1.369 -UCX_TEST(test_ucx_properties2map) {
   1.370 -    UcxMempool *mp = ucx_mempool_new(64);
   1.371 -    UcxMap *map = ucx_map_new_a(mp->allocator, 16);
   1.372 -    UcxProperties *parser = ucx_properties_new();
   1.373 -    
   1.374 -    UCX_TEST_BEGIN
   1.375 -    
   1.376 -    const char *str = "key1 = value1\nkey2 = value2\n\n#comment\n\nkey3 = value3\n";
   1.377 -    ucx_properties_fill(parser, (char*)str, strlen(str));
   1.378 -    
   1.379 -    int r = ucx_properties2map(parser, map);
   1.380 -    
   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 -    char *v2 = (char*)ucx_map_cstr_get(map, "key2");
   1.386 -    char *v3 = (char*)ucx_map_cstr_get(map, "key3");
   1.387 -    
   1.388 -    UCX_TEST_ASSERT(v1, "value for key1 not found");
   1.389 -    UCX_TEST_ASSERT(v2, "value for key2 not found");
   1.390 -    UCX_TEST_ASSERT(v3, "value for key3 not found");
   1.391 -    
   1.392 -    UCX_TEST_ASSERT((!strcmp(v1, "value1")), "wrong value for key1");
   1.393 -    UCX_TEST_ASSERT((!strcmp(v2, "value2")), "wrong value for key2");
   1.394 -    UCX_TEST_ASSERT((!strcmp(v3, "value3")), "wrong value for key3");
   1.395 -    
   1.396 -    // second test
   1.397 -    ucx_map_free(map);
   1.398 -    map = ucx_map_new_a(mp->allocator, 16);
   1.399 -    
   1.400 -    str = "\n#comment\n";
   1.401 -    ucx_properties_fill(parser, (char*)str, strlen(str));
   1.402 -    
   1.403 -    r = ucx_properties2map(parser, map);
   1.404 -    UCX_TEST_ASSERT(r == 0, "properties2map failed");
   1.405 -    UCX_TEST_ASSERT(map->count == 0, "wrong number of properties");
   1.406 -    
   1.407 -    str = "key1 = value1\nsyntax error line\n";
   1.408 -    ucx_properties_fill(parser, (char*)str, strlen(str));
   1.409 -    
   1.410 -    r = ucx_properties2map(parser, map);
   1.411 -    UCX_TEST_ASSERT(r == 1, "properties2map should return 1");
   1.412 -    UCX_TEST_ASSERT(map->count == 1, "wrong number of properties");
   1.413 -    
   1.414 -    char *v = (char*)ucx_map_cstr_get(map, "key1");
   1.415 -    UCX_TEST_ASSERT((!strcmp(v, "value1")), "wrong value");
   1.416 -    
   1.417 -    UCX_TEST_END
   1.418 -    
   1.419 -    ucx_mempool_destroy(mp);
   1.420 -    ucx_properties_free(parser);
   1.421 -}
   1.422 -
   1.423 -UCX_TEST(test_ucx_properties_load) { 
   1.424 -    UCX_TEST_BEGIN
   1.425 -    FILE *f = tmpfile();
   1.426 -    UCX_TEST_ASSERT(f, "test file cannot be opened, test aborted");
   1.427 -    
   1.428 -    fprintf(f, "# properties file\n\nkey1 = value1\nkey2 = value2\n");
   1.429 -    fprintf(f, "\n\nkey3    = value3\n\n");
   1.430 -    
   1.431 -    size_t name_len = 512;
   1.432 -    char *long_name = (char*)malloc(name_len);
   1.433 -    memset(long_name, 'k', 512);
   1.434 -    
   1.435 -    size_t value_len = 2048;
   1.436 -    char *long_value = (char*)malloc(value_len);
   1.437 -    memset(long_value, 'v', 2048);
   1.438 -    
   1.439 -    fwrite(long_name, 1, name_len, f);
   1.440 -    fprintf(f, "    =    ");
   1.441 -    fwrite(long_value, 1, value_len, f);
   1.442 -    fprintf(f, "                         \n");
   1.443 -    
   1.444 -    fprintf(f, "\n\n\n\nlast_key = property value\n");
   1.445 -    
   1.446 -    fflush(f);
   1.447 -    fseek(f, 0, SEEK_SET);
   1.448 -    
   1.449 -    UcxMap *map = ucx_map_new(8);
   1.450 -    int r = ucx_properties_load(map, f);
   1.451 -    
   1.452 -    UCX_TEST_ASSERT(r == 0, "ucx_properties_load failed");
   1.453 -    UCX_TEST_ASSERT(map->count == 5, "wrong number of properties");
   1.454 -    
   1.455 -    char *v1 = (char*)ucx_map_cstr_get(map, "key1");
   1.456 -    char *v2 = (char*)ucx_map_cstr_get(map, "key2");
   1.457 -    char *v3 = (char*)ucx_map_cstr_get(map, "key3");
   1.458 -    char *lv = (char*)ucx_map_sstr_get(map, sstrn(long_name, name_len));
   1.459 -    char *lk = (char*)ucx_map_cstr_get(map, "last_key");
   1.460 -    
   1.461 -    UCX_TEST_ASSERT(v1, "value for key1 not found");
   1.462 -    UCX_TEST_ASSERT(v2, "value for key2 not found");
   1.463 -    UCX_TEST_ASSERT(v3, "value for key3 not found");
   1.464 -    UCX_TEST_ASSERT(lv, "value for long key not found");
   1.465 -    UCX_TEST_ASSERT(lk, "value for last_key not found");
   1.466 -    
   1.467 -    UCX_TEST_ASSERT((!strcmp(v1, "value1")), "wrong value for key1");
   1.468 -    UCX_TEST_ASSERT((!strcmp(v2, "value2")), "wrong value for key2");
   1.469 -    UCX_TEST_ASSERT((!strcmp(v3, "value3")), "wrong value for key3");
   1.470 -    sstr_t long1 = sstrn(long_value, value_len);
   1.471 -    sstr_t long2 = sstr(lv);
   1.472 -    UCX_TEST_ASSERT((!sstrcmp(long1, long2)), "wrong value for long key");
   1.473 -    UCX_TEST_ASSERT(!strcmp(lk, "property value"), "wrong value for last_key");
   1.474 -    
   1.475 -    free(v1);
   1.476 -    free(v2);
   1.477 -    free(v3);
   1.478 -    free(lv);
   1.479 -    free(lk);
   1.480 -    ucx_map_free(map);
   1.481 -    fclose(f);
   1.482 -    
   1.483 -    free(long_name);
   1.484 -    free(long_value);
   1.485 -    
   1.486 -    UCX_TEST_END
   1.487 -}
   1.488 -
   1.489 -UCX_TEST(test_ucx_properties_store) {
   1.490 -    UcxMap *map1 = ucx_map_new(16);
   1.491 -    ucx_map_cstr_put(map1, "key1", "value1");
   1.492 -    ucx_map_cstr_put(map1, "key2", "value2");
   1.493 -    ucx_map_cstr_put(map1, "key3", "value3");
   1.494 -    ucx_map_cstr_put(map1, "key4", "value4");
   1.495 -    ucx_map_cstr_put(map1, "property.key1", "some value 1");
   1.496 -    ucx_map_cstr_put(map1, "property.key2", "some value 2");
   1.497 -    ucx_map_cstr_put(map1, "property.key3", "some value 3");
   1.498 -    ucx_map_cstr_put(map1, "property.key4", "some value 4");
   1.499 -    
   1.500 -    UCX_TEST_BEGIN
   1.501 -    
   1.502 -    FILE *f = tmpfile();
   1.503 -    fprintf(f, "#\n# test property file\n#\n#\n");
   1.504 -    ucx_properties_store(map1, f);
   1.505 -    
   1.506 -    fflush(f);
   1.507 -    fseek(f, 0, SEEK_SET);
   1.508 -    UcxMap *map2 = ucx_map_new(16);
   1.509 -    ucx_properties_load(map2, f);
   1.510 -    
   1.511 -    UCX_TEST_ASSERT(map2->count == 8, "wrong number of properties in map2");
   1.512 -    
   1.513 -    char *v1 = (char*)ucx_map_cstr_get(map2, "key1");
   1.514 -    char *v2 = (char*)ucx_map_cstr_get(map2, "key2");
   1.515 -    char *v3 = (char*)ucx_map_cstr_get(map2, "key3");
   1.516 -    char *v4 = (char*)ucx_map_cstr_get(map2, "key4");
   1.517 -    char *v5 = (char*)ucx_map_cstr_get(map2, "property.key1");
   1.518 -    char *v6 = (char*)ucx_map_cstr_get(map2, "property.key2");
   1.519 -    char *v7 = (char*)ucx_map_cstr_get(map2, "property.key3");
   1.520 -    char *v8 = (char*)ucx_map_cstr_get(map2, "property.key4");
   1.521 -    
   1.522 -    UCX_TEST_ASSERT(v1 && v2 && v3 && v4 && v5 && v6 && v7 && v8,
   1.523 -            "missing values");
   1.524 -    
   1.525 -    UCX_TEST_ASSERT((!strcmp(v1, "value1")), "wrong value 1");
   1.526 -    UCX_TEST_ASSERT((!strcmp(v2, "value2")), "wrong value 2");
   1.527 -    UCX_TEST_ASSERT((!strcmp(v3, "value3")), "wrong value 3");
   1.528 -    UCX_TEST_ASSERT((!strcmp(v4, "value4")), "wrong value 4");
   1.529 -    UCX_TEST_ASSERT((!strcmp(v5, "some value 1")), "wrong value 5");
   1.530 -    UCX_TEST_ASSERT((!strcmp(v6, "some value 2")), "wrong value 6");
   1.531 -    UCX_TEST_ASSERT((!strcmp(v7, "some value 3")), "wrong value 7");
   1.532 -    UCX_TEST_ASSERT((!strcmp(v8, "some value 4")), "wrong value 8");
   1.533 -    
   1.534 -    free(v1);
   1.535 -    free(v2);
   1.536 -    free(v3);
   1.537 -    free(v4);
   1.538 -    free(v5);
   1.539 -    free(v6);
   1.540 -    free(v7);
   1.541 -    free(v8);
   1.542 -    ucx_map_free(map2);
   1.543 -    fclose(f);
   1.544 -    
   1.545 -    UCX_TEST_END
   1.546 -    
   1.547 -    ucx_map_free(map1);
   1.548 -}

mercurial