olaf@108: /* olaf@108: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. olaf@108: * universe@259: * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved. olaf@108: * olaf@108: * Redistribution and use in source and binary forms, with or without olaf@108: * modification, are permitted provided that the following conditions are met: olaf@108: * olaf@108: * 1. Redistributions of source code must retain the above copyright olaf@108: * notice, this list of conditions and the following disclaimer. olaf@108: * olaf@108: * 2. Redistributions in binary form must reproduce the above copyright olaf@108: * notice, this list of conditions and the following disclaimer in the olaf@108: * documentation and/or other materials provided with the distribution. olaf@108: * olaf@108: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" olaf@108: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE olaf@108: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE olaf@108: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE olaf@108: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR olaf@108: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF olaf@108: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS olaf@108: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN olaf@108: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) olaf@108: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE olaf@108: * POSSIBILITY OF SUCH DAMAGE. olaf@108: */ olaf@108: olaf@108: #include "prop_tests.h" universe@251: #include olaf@108: universe@134: UCX_TEST(test_ucx_properties_new) { olaf@110: UcxProperties *parser = ucx_properties_new(); olaf@108: olaf@108: UCX_TEST_BEGIN olaf@108: olaf@108: UCX_TEST_ASSERT(parser != NULL, "failed"); olaf@108: UCX_TEST_ASSERT(parser->buffer == NULL, "parser has buffer"); olaf@108: UCX_TEST_ASSERT(parser->tmp == NULL, "parser has tmp buffer"); olaf@108: olaf@108: UCX_TEST_END olaf@108: olaf@110: ucx_properties_free(parser); olaf@108: } olaf@108: universe@134: UCX_TEST(test_ucx_properties_next) { olaf@109: const char *tests[] = { olaf@108: "name = value\n", olaf@108: "name=value\n", olaf@108: "n=value\n", olaf@108: "name=v\n", olaf@108: "n=v\n", olaf@108: "name = value # comment\n", olaf@108: "#comment\nn=v\n", olaf@108: "# comment1\n# comment2\n\n \n\nname = value\n", olaf@108: " name = value\n", olaf@108: "name = value\n\n" olaf@108: }; olaf@108: olaf@109: const char *names[] = { olaf@108: "name", olaf@108: "name", olaf@108: "n", olaf@108: "name", olaf@108: "n", olaf@108: "name", olaf@108: "n", olaf@108: "name", olaf@108: "name", olaf@108: "name" olaf@108: }; olaf@108: olaf@109: const char *values[] = { olaf@108: "value", olaf@108: "value", olaf@108: "value", olaf@108: "v", olaf@108: "v", olaf@108: "value", olaf@108: "v", olaf@108: "value", olaf@108: "value", olaf@108: "value" olaf@108: }; olaf@108: olaf@108: UCX_TEST_BEGIN olaf@108: olaf@108: sstr_t name; olaf@108: sstr_t value; olaf@108: olaf@108: for(int i=0;i<10;i++) { olaf@110: UcxProperties *parser = ucx_properties_new(); olaf@108: olaf@110: ucx_properties_fill(parser, (char*)tests[i], strlen(tests[i])); olaf@108: UCX_TEST_ASSERT(parser->buffer == tests[i], "fill failed"); olaf@108: UCX_TEST_ASSERT(parser->buflen == strlen(tests[i]), "wrong buflen"); olaf@108: olaf@110: int r = ucx_properties_next(parser, &name, &value); olaf@109: sstr_t n = sstr((char*)names[i]); olaf@109: sstr_t v = sstr((char*)values[i]); olaf@110: UCX_TEST_ASSERT(r == 1, "next returned 0"); olaf@108: UCX_TEST_ASSERT((!sstrcmp(name, n)), "wrong property name"); olaf@108: UCX_TEST_ASSERT((!sstrcmp(value, v)), "wrong property value"); olaf@108: olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: UCX_TEST_ASSERT(parser->tmp == NULL, "tmp not NULL"); olaf@108: UCX_TEST_ASSERT(parser->tmpcap == 0, "tmpcap not NULL"); olaf@108: UCX_TEST_ASSERT(parser->tmplen == 0, "tmplen not NULL"); olaf@108: olaf@110: ucx_properties_free(parser); olaf@108: } olaf@108: olaf@108: UCX_TEST_END olaf@108: } olaf@108: universe@134: UCX_TEST(test_ucx_properties_next_multi) { olaf@109: const char *names[] = { olaf@108: "a", olaf@108: "b", olaf@108: "c", olaf@108: "uap", olaf@108: "name", olaf@108: "key1", olaf@108: "key2", olaf@108: "key3" olaf@108: }; olaf@108: olaf@109: const char *values[] = { olaf@108: "a value", olaf@108: "b value", olaf@108: "core", olaf@108: "core", olaf@108: "ucx", olaf@108: "value1", olaf@108: "value2", olaf@108: "value3" olaf@108: }; olaf@108: olaf@109: const char *str = "#\n" olaf@108: "# properties\n" olaf@108: "# contains key/value pairs\n" olaf@108: "#\n" olaf@108: "a = a value\n" olaf@108: "b = b value\n" olaf@108: "c = core\n" olaf@108: "\n# test\n" olaf@108: "uap = core\n" olaf@108: "name = ucx\n" olaf@108: "# no = property\n" olaf@108: "key1 = value1\n" olaf@108: "#key1 = wrong value\n" olaf@108: "#key2 = not value 2\n" olaf@108: "key2 = value2\n" olaf@108: "\n\n\n \n key3=value3\n"; olaf@108: olaf@110: UcxProperties *parser = ucx_properties_new(); olaf@108: olaf@108: UCX_TEST_BEGIN olaf@108: olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@108: olaf@108: sstr_t name; olaf@108: sstr_t value; olaf@108: for(int i=0;i<8;i++) { olaf@110: int r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 1, "next returned 0"); olaf@109: UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)names[i]))), "wrong name"); olaf@109: UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)values[i]))), olaf@109: "wrong value"); olaf@108: } olaf@110: int r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@108: UCX_TEST_END olaf@108: olaf@110: ucx_properties_free(parser); olaf@108: } olaf@108: universe@134: UCX_TEST(test_ucx_properties_next_part) { olaf@110: UcxProperties *parser = ucx_properties_new(); olaf@109: const char *str; olaf@108: int r; olaf@108: sstr_t name; olaf@108: sstr_t value; olaf@108: olaf@108: UCX_TEST_BEGIN olaf@108: olaf@108: str = ""; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@108: str = " \n"; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@108: str = "name"; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@108: str = " "; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@108: str = "= "; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@108: str = "value"; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@108: str = "\n"; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 1, "next returned 0"); olaf@109: UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"name"))), "wrong name"); olaf@109: UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"value"))), "wrong value"); olaf@108: olaf@108: // second round olaf@108: str = "#comment\n"; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@108: str = "#comment\nname = "; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@108: str = "value\na = b\n"; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 1, "next returned 0"); olaf@109: UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"name"))), "wrong name"); olaf@109: UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"value"))), "wrong value"); olaf@108: olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 1, "next returned 0"); olaf@109: UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"a"))), "wrong name"); olaf@109: UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"b"))), "wrong value"); olaf@108: olaf@108: str = "# comment\n#\n#\ntests = "; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@108: str = "test1 "; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@108: str = "test2 test3 test4\n"; olaf@109: sstr_t testv = sstr((char*)"test1 test2 test3 test4"); olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 1, "next returned 0"); olaf@109: UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"tests"))), "wrong name"); olaf@108: UCX_TEST_ASSERT((!sstrcmp(value, testv)), "wrong value"); olaf@108: olaf@110: // test if ucx_properties_next finds a name/value after a tmp comment olaf@108: str = "# just a comment"; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@108: str = " in 3"; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@108: str = " parts\na = 1\n"; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 1, "next returned 0"); olaf@109: UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"a"))), "wrong name"); olaf@109: UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"1"))), "wrong value"); olaf@108: olaf@108: UCX_TEST_END olaf@108: olaf@110: ucx_properties_free(parser); olaf@108: } olaf@108: universe@134: UCX_TEST(test_ucx_properties_next_long) { olaf@110: UcxProperties *parser = ucx_properties_new(); olaf@108: int r; olaf@108: size_t name_len = 512; olaf@108: char *long_name = (char*)malloc(name_len); olaf@108: memset(long_name, 'a', 70); olaf@108: memset(long_name+70, 'b', 242); olaf@108: memset(long_name+312, 'c', 200); olaf@108: olaf@108: size_t value_len = 2048; olaf@108: char *long_value = (char*)malloc(value_len); olaf@108: memset(long_value, 'x', 1024); olaf@108: memset(long_value+1024, 'y', 1024); olaf@108: olaf@108: UCX_TEST_BEGIN olaf@108: olaf@108: sstr_t name; olaf@108: sstr_t value; olaf@108: olaf@110: ucx_properties_fill(parser, long_name, 10); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@110: ucx_properties_fill(parser, long_name+10, 202); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@110: ucx_properties_fill(parser, long_name+212, 200); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@110: ucx_properties_fill(parser, long_name+412, 100); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@109: const char *str = " = "; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@110: ucx_properties_fill(parser, long_value, 512); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@110: ucx_properties_fill(parser, long_value+512, 1024); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@110: ucx_properties_fill(parser, long_value+1536, 512); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@108: str = "\n#comment\nkey = value\n"; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@108: sstr_t n = sstrn(long_name, name_len); olaf@108: sstr_t v = sstrn(long_value, value_len); olaf@110: UCX_TEST_ASSERT(r == 1, "next returned 0"); olaf@108: UCX_TEST_ASSERT((!sstrcmp(name, n)), "wrong name"); olaf@108: UCX_TEST_ASSERT((!sstrcmp(value, v)), "wrong value"); olaf@108: olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 1, "next returned 0"); olaf@109: UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"key"))), "wrong name"); olaf@109: UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"value"))), "wrong value"); olaf@108: olaf@110: r = ucx_properties_next(parser, &name, &value); olaf@110: UCX_TEST_ASSERT(r == 0, "next returned 1"); olaf@108: olaf@108: UCX_TEST_END olaf@108: olaf@108: free(long_name); olaf@108: free(long_value); olaf@110: ucx_properties_free(parser); olaf@108: } olaf@109: universe@134: UCX_TEST(test_ucx_properties2map) { olaf@147: UcxMempool *mp = ucx_mempool_new(64); olaf@158: UcxMap *map = ucx_map_new_a(mp->allocator, 16); olaf@110: UcxProperties *parser = ucx_properties_new(); olaf@109: olaf@109: UCX_TEST_BEGIN olaf@109: olaf@109: const char *str = "key1 = value1\nkey2 = value2\n\n#comment\n\nkey3 = value3\n"; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@109: olaf@110: int r = ucx_properties2map(parser, map); olaf@109: olaf@110: UCX_TEST_ASSERT(r == 0, "properties2map failed"); olaf@109: UCX_TEST_ASSERT(map->count == 3, "wrong number of properties"); olaf@109: olaf@109: char *v1 = (char*)ucx_map_cstr_get(map, "key1"); olaf@109: char *v2 = (char*)ucx_map_cstr_get(map, "key2"); olaf@109: char *v3 = (char*)ucx_map_cstr_get(map, "key3"); olaf@109: olaf@109: UCX_TEST_ASSERT(v1, "value for key1 not found"); olaf@109: UCX_TEST_ASSERT(v2, "value for key2 not found"); olaf@109: UCX_TEST_ASSERT(v3, "value for key3 not found"); olaf@109: olaf@109: UCX_TEST_ASSERT((!strcmp(v1, "value1")), "wrong value for key1"); olaf@109: UCX_TEST_ASSERT((!strcmp(v2, "value2")), "wrong value for key2"); olaf@109: UCX_TEST_ASSERT((!strcmp(v3, "value3")), "wrong value for key3"); olaf@109: olaf@109: // second test olaf@109: ucx_map_free(map); olaf@158: map = ucx_map_new_a(mp->allocator, 16); olaf@109: olaf@109: str = "\n#comment\n"; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@109: olaf@110: r = ucx_properties2map(parser, map); olaf@110: UCX_TEST_ASSERT(r == 0, "properties2map failed"); olaf@109: UCX_TEST_ASSERT(map->count == 0, "wrong number of properties"); olaf@109: olaf@109: str = "key1 = value1\nsyntax error line\n"; olaf@110: ucx_properties_fill(parser, (char*)str, strlen(str)); olaf@109: olaf@110: r = ucx_properties2map(parser, map); olaf@110: UCX_TEST_ASSERT(r == 1, "properties2map should return 1"); olaf@109: UCX_TEST_ASSERT(map->count == 1, "wrong number of properties"); olaf@109: olaf@109: char *v = (char*)ucx_map_cstr_get(map, "key1"); olaf@109: UCX_TEST_ASSERT((!strcmp(v, "value1")), "wrong value"); olaf@109: olaf@109: UCX_TEST_END olaf@109: olaf@147: ucx_mempool_destroy(mp); olaf@110: ucx_properties_free(parser); olaf@109: } olaf@109: universe@134: UCX_TEST(test_ucx_properties_load) { olaf@109: UCX_TEST_BEGIN olaf@109: FILE *f = tmpfile(); olaf@109: UCX_TEST_ASSERT(f, "test file cannot be opened, test aborted"); olaf@109: olaf@109: fprintf(f, "# properties file\n\nkey1 = value1\nkey2 = value2\n"); olaf@109: fprintf(f, "\n\nkey3 = value3\n\n"); olaf@109: olaf@109: size_t name_len = 512; olaf@109: char *long_name = (char*)malloc(name_len); olaf@109: memset(long_name, 'k', 512); olaf@109: olaf@109: size_t value_len = 2048; olaf@109: char *long_value = (char*)malloc(value_len); olaf@109: memset(long_value, 'v', 2048); olaf@109: olaf@109: fwrite(long_name, 1, name_len, f); olaf@109: fprintf(f, " = "); olaf@109: fwrite(long_value, 1, value_len, f); olaf@109: fprintf(f, " \n"); olaf@109: olaf@109: fprintf(f, "\n\n\n\nlast_key = property value\n"); olaf@109: olaf@109: fflush(f); olaf@109: fseek(f, 0, SEEK_SET); olaf@109: olaf@109: UcxMap *map = ucx_map_new(8); olaf@109: int r = ucx_properties_load(map, f); olaf@109: olaf@109: UCX_TEST_ASSERT(r == 0, "ucx_properties_load failed"); olaf@109: UCX_TEST_ASSERT(map->count == 5, "wrong number of properties"); olaf@109: olaf@109: char *v1 = (char*)ucx_map_cstr_get(map, "key1"); olaf@109: char *v2 = (char*)ucx_map_cstr_get(map, "key2"); olaf@109: char *v3 = (char*)ucx_map_cstr_get(map, "key3"); olaf@109: char *lv = (char*)ucx_map_sstr_get(map, sstrn(long_name, name_len)); olaf@109: char *lk = (char*)ucx_map_cstr_get(map, "last_key"); olaf@109: olaf@109: UCX_TEST_ASSERT(v1, "value for key1 not found"); olaf@109: UCX_TEST_ASSERT(v2, "value for key2 not found"); olaf@109: UCX_TEST_ASSERT(v3, "value for key3 not found"); olaf@109: UCX_TEST_ASSERT(lv, "value for long key not found"); olaf@109: UCX_TEST_ASSERT(lk, "value for last_key not found"); olaf@109: olaf@109: UCX_TEST_ASSERT((!strcmp(v1, "value1")), "wrong value for key1"); olaf@109: UCX_TEST_ASSERT((!strcmp(v2, "value2")), "wrong value for key2"); olaf@109: UCX_TEST_ASSERT((!strcmp(v3, "value3")), "wrong value for key3"); olaf@109: sstr_t long1 = sstrn(long_value, value_len); olaf@109: sstr_t long2 = sstr(lv); olaf@109: UCX_TEST_ASSERT((!sstrcmp(long1, long2)), "wrong value for long key"); olaf@109: UCX_TEST_ASSERT(!strcmp(lk, "property value"), "wrong value for last_key"); olaf@109: olaf@109: free(v1); olaf@109: free(v2); olaf@109: free(v3); olaf@109: free(lv); olaf@109: free(lk); olaf@109: ucx_map_free(map); olaf@109: fclose(f); olaf@109: olaf@147: free(long_name); olaf@147: free(long_value); olaf@147: olaf@109: UCX_TEST_END olaf@109: } olaf@109: universe@134: UCX_TEST(test_ucx_properties_store) { olaf@109: UcxMap *map1 = ucx_map_new(16); olaf@109: ucx_map_cstr_put(map1, "key1", "value1"); olaf@109: ucx_map_cstr_put(map1, "key2", "value2"); olaf@109: ucx_map_cstr_put(map1, "key3", "value3"); olaf@109: ucx_map_cstr_put(map1, "key4", "value4"); olaf@109: ucx_map_cstr_put(map1, "property.key1", "some value 1"); olaf@109: ucx_map_cstr_put(map1, "property.key2", "some value 2"); olaf@109: ucx_map_cstr_put(map1, "property.key3", "some value 3"); olaf@109: ucx_map_cstr_put(map1, "property.key4", "some value 4"); olaf@109: olaf@109: UCX_TEST_BEGIN olaf@109: olaf@109: FILE *f = tmpfile(); olaf@109: fprintf(f, "#\n# test property file\n#\n#\n"); olaf@109: ucx_properties_store(map1, f); olaf@109: olaf@109: fflush(f); olaf@109: fseek(f, 0, SEEK_SET); olaf@109: UcxMap *map2 = ucx_map_new(16); olaf@109: ucx_properties_load(map2, f); olaf@109: olaf@109: UCX_TEST_ASSERT(map2->count == 8, "wrong number of properties in map2"); olaf@109: olaf@109: char *v1 = (char*)ucx_map_cstr_get(map2, "key1"); olaf@109: char *v2 = (char*)ucx_map_cstr_get(map2, "key2"); olaf@109: char *v3 = (char*)ucx_map_cstr_get(map2, "key3"); olaf@109: char *v4 = (char*)ucx_map_cstr_get(map2, "key4"); olaf@109: char *v5 = (char*)ucx_map_cstr_get(map2, "property.key1"); olaf@109: char *v6 = (char*)ucx_map_cstr_get(map2, "property.key2"); olaf@109: char *v7 = (char*)ucx_map_cstr_get(map2, "property.key3"); olaf@109: char *v8 = (char*)ucx_map_cstr_get(map2, "property.key4"); olaf@109: olaf@109: UCX_TEST_ASSERT(v1 && v2 && v3 && v4 && v5 && v6 && v7 && v8, olaf@109: "missing values"); olaf@109: olaf@109: UCX_TEST_ASSERT((!strcmp(v1, "value1")), "wrong value 1"); olaf@109: UCX_TEST_ASSERT((!strcmp(v2, "value2")), "wrong value 2"); olaf@109: UCX_TEST_ASSERT((!strcmp(v3, "value3")), "wrong value 3"); olaf@109: UCX_TEST_ASSERT((!strcmp(v4, "value4")), "wrong value 4"); olaf@109: UCX_TEST_ASSERT((!strcmp(v5, "some value 1")), "wrong value 5"); olaf@109: UCX_TEST_ASSERT((!strcmp(v6, "some value 2")), "wrong value 6"); olaf@109: UCX_TEST_ASSERT((!strcmp(v7, "some value 3")), "wrong value 7"); olaf@109: UCX_TEST_ASSERT((!strcmp(v8, "some value 4")), "wrong value 8"); olaf@109: olaf@109: free(v1); olaf@109: free(v2); olaf@109: free(v3); olaf@109: free(v4); olaf@109: free(v5); olaf@109: free(v6); olaf@109: free(v7); olaf@109: free(v8); olaf@109: ucx_map_free(map2); olaf@109: fclose(f); olaf@109: olaf@109: UCX_TEST_END olaf@109: olaf@109: ucx_map_free(map1); olaf@109: }