test/prop_tests.c

Wed, 17 Jul 2013 11:47:02 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 17 Jul 2013 11:47:02 +0200
changeset 114
5a0859739b76
parent 110
1cf71e56f01e
child 134
4d320dc3a7af
permissions
-rw-r--r--

added doxyfile and documentation for ucx.h

108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2013 Olaf Wintermann. All rights reserved.
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include "prop_tests.h"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
31 UCX_TEST_IMPLEMENT(test_ucx_properties_new) {
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
32 UcxProperties *parser = ucx_properties_new();
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 UCX_TEST_BEGIN
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
36 UCX_TEST_ASSERT(parser != NULL, "failed");
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
37 UCX_TEST_ASSERT(parser->buffer == NULL, "parser has buffer");
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 UCX_TEST_ASSERT(parser->tmp == NULL, "parser has tmp buffer");
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40 UCX_TEST_END
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
41
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
42 ucx_properties_free(parser);
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43 }
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
44
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
45 UCX_TEST_IMPLEMENT(test_ucx_properties_next) {
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
46 const char *tests[] = {
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
47 "name = value\n",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
48 "name=value\n",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
49 "n=value\n",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
50 "name=v\n",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
51 "n=v\n",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
52 "name = value # comment\n",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
53 "#comment\nn=v\n",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
54 "# comment1\n# comment2\n\n \n\nname = value\n",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55 " name = value\n",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 "name = value\n\n"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 };
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
58
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
59 const char *names[] = {
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 "name",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 "name",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62 "n",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 "name",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 "n",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65 "name",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
66 "n",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 "name",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
68 "name",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
69 "name"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70 };
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
71
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
72 const char *values[] = {
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 "value",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74 "value",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 "value",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 "v",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77 "v",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 "value",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 "v",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 "value",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 "value",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 "value"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 };
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
85 UCX_TEST_BEGIN
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
87 sstr_t name;
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
88 sstr_t value;
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
89
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 for(int i=0;i<10;i++) {
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
91 UcxProperties *parser = ucx_properties_new();
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
93 ucx_properties_fill(parser, (char*)tests[i], strlen(tests[i]));
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94 UCX_TEST_ASSERT(parser->buffer == tests[i], "fill failed");
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 UCX_TEST_ASSERT(parser->buflen == strlen(tests[i]), "wrong buflen");
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
97 int r = ucx_properties_next(parser, &name, &value);
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
98 sstr_t n = sstr((char*)names[i]);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
99 sstr_t v = sstr((char*)values[i]);
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
100 UCX_TEST_ASSERT(r == 1, "next returned 0");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 UCX_TEST_ASSERT((!sstrcmp(name, n)), "wrong property name");
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102 UCX_TEST_ASSERT((!sstrcmp(value, v)), "wrong property value");
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
104 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
105 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106 UCX_TEST_ASSERT(parser->tmp == NULL, "tmp not NULL");
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 UCX_TEST_ASSERT(parser->tmpcap == 0, "tmpcap not NULL");
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 UCX_TEST_ASSERT(parser->tmplen == 0, "tmplen not NULL");
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
110 ucx_properties_free(parser);
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 }
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 UCX_TEST_END
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114 }
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
116 UCX_TEST_IMPLEMENT(test_ucx_properties_next_multi) {
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
117 const char *names[] = {
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 "a",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 "b",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
120 "c",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 "uap",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
122 "name",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
123 "key1",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
124 "key2",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
125 "key3"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
126 };
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
127
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
128 const char *values[] = {
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129 "a value",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
130 "b value",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
131 "core",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
132 "core",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
133 "ucx",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 "value1",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 "value2",
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136 "value3"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
137 };
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
138
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
139 const char *str = "#\n"
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
140 "# properties\n"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
141 "# contains key/value pairs\n"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
142 "#\n"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
143 "a = a value\n"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
144 "b = b value\n"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
145 "c = core\n"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
146 "\n# test\n"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
147 "uap = core\n"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
148 "name = ucx\n"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
149 "# no = property\n"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
150 "key1 = value1\n"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
151 "#key1 = wrong value\n"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
152 "#key2 = not value 2\n"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
153 "key2 = value2\n"
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
154 "\n\n\n \n key3=value3\n";
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
155
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
156 UcxProperties *parser = ucx_properties_new();
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
157
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
158 UCX_TEST_BEGIN
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
159
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
160 ucx_properties_fill(parser, (char*)str, strlen(str));
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
161
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
162 sstr_t name;
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
163 sstr_t value;
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
164 for(int i=0;i<8;i++) {
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
165 int r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
166 UCX_TEST_ASSERT(r == 1, "next returned 0");
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
167 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)names[i]))), "wrong name");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
168 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)values[i]))),
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
169 "wrong value");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
170 }
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
171 int r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
172 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
173
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
174 UCX_TEST_END
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
175
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
176 ucx_properties_free(parser);
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
177 }
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
178
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
179 UCX_TEST_IMPLEMENT(test_ucx_properties_next_part) {
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
180 UcxProperties *parser = ucx_properties_new();
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
181 const char *str;
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
182 int r;
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
183 sstr_t name;
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
184 sstr_t value;
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
185
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
186 UCX_TEST_BEGIN
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
187
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
188 str = "";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
189 ucx_properties_fill(parser, (char*)str, strlen(str));
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
190 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
191 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
192
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
193 str = " \n";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
194 ucx_properties_fill(parser, (char*)str, strlen(str));
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
195 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
196 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 str = "name";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
199 ucx_properties_fill(parser, (char*)str, strlen(str));
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
200 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
201 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 str = " ";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
204 ucx_properties_fill(parser, (char*)str, strlen(str));
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
205 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
206 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 str = "= ";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
209 ucx_properties_fill(parser, (char*)str, strlen(str));
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
210 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
211 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 str = "value";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
214 ucx_properties_fill(parser, (char*)str, strlen(str));
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
215 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
216 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 str = "\n";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
219 ucx_properties_fill(parser, (char*)str, strlen(str));
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
220 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
221 UCX_TEST_ASSERT(r == 1, "next returned 0");
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
222 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"name"))), "wrong name");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
223 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"value"))), "wrong value");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 // second round
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226 str = "#comment\n";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
227 ucx_properties_fill(parser, (char*)str, strlen(str));
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
228 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
229 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 str = "#comment\nname = ";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
232 ucx_properties_fill(parser, (char*)str, strlen(str));
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
233 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
234 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 str = "value\na = b\n";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
237 ucx_properties_fill(parser, (char*)str, strlen(str));
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
238 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
239 UCX_TEST_ASSERT(r == 1, "next returned 0");
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
240 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"name"))), "wrong name");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
241 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"value"))), "wrong value");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
243 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
244 UCX_TEST_ASSERT(r == 1, "next returned 0");
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
245 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"a"))), "wrong name");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
246 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"b"))), "wrong value");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 str = "# comment\n#\n#\ntests = ";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
249 ucx_properties_fill(parser, (char*)str, strlen(str));
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
250 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
251 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 str = "test1 ";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
254 ucx_properties_fill(parser, (char*)str, strlen(str));
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
255 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
256 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 str = "test2 test3 test4\n";
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
259 sstr_t testv = sstr((char*)"test1 test2 test3 test4");
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
260 ucx_properties_fill(parser, (char*)str, strlen(str));
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
261 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
262 UCX_TEST_ASSERT(r == 1, "next returned 0");
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
263 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"tests"))), "wrong name");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
264 UCX_TEST_ASSERT((!sstrcmp(value, testv)), "wrong value");
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
265
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
266 // test if ucx_properties_next finds a name/value after a tmp comment
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 str = "# just a comment";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
268 ucx_properties_fill(parser, (char*)str, strlen(str));
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
269 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
270 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
272 str = " in 3";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
273 ucx_properties_fill(parser, (char*)str, strlen(str));
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
274 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
275 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
276
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
277 str = " parts\na = 1\n";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
278 ucx_properties_fill(parser, (char*)str, strlen(str));
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
279 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
280 UCX_TEST_ASSERT(r == 1, "next returned 0");
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
281 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"a"))), "wrong name");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
282 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"1"))), "wrong value");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
283
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
284 UCX_TEST_END
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
285
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
286 ucx_properties_free(parser);
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
287 }
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
288
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
289 UCX_TEST_IMPLEMENT(test_ucx_properties_next_long) {
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
290 UcxProperties *parser = ucx_properties_new();
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
291 int r;
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
292 size_t name_len = 512;
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
293 char *long_name = (char*)malloc(name_len);
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
294 memset(long_name, 'a', 70);
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
295 memset(long_name+70, 'b', 242);
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
296 memset(long_name+312, 'c', 200);
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
297
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
298 size_t value_len = 2048;
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
299 char *long_value = (char*)malloc(value_len);
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
300 memset(long_value, 'x', 1024);
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
301 memset(long_value+1024, 'y', 1024);
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
302
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
303 UCX_TEST_BEGIN
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
304
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
305 sstr_t name;
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 sstr_t value;
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
308 ucx_properties_fill(parser, long_name, 10);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
309 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
310 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
311
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
312 ucx_properties_fill(parser, long_name+10, 202);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
313 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
314 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
315
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
316 ucx_properties_fill(parser, long_name+212, 200);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
317 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
318 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
319
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
320 ucx_properties_fill(parser, long_name+412, 100);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
321 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
322 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
323
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
324 const char *str = " = ";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
325 ucx_properties_fill(parser, (char*)str, strlen(str));
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
326 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
327 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
328
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
329 ucx_properties_fill(parser, long_value, 512);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
330 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
331 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
332
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
333 ucx_properties_fill(parser, long_value+512, 1024);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
334 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
335 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
336
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
337 ucx_properties_fill(parser, long_value+1536, 512);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
338 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
339 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
340
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
341 str = "\n#comment\nkey = value\n";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
342 ucx_properties_fill(parser, (char*)str, strlen(str));
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
343 r = ucx_properties_next(parser, &name, &value);
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
344 sstr_t n = sstrn(long_name, name_len);
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
345 sstr_t v = sstrn(long_value, value_len);
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
346 UCX_TEST_ASSERT(r == 1, "next returned 0");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
347 UCX_TEST_ASSERT((!sstrcmp(name, n)), "wrong name");
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
348 UCX_TEST_ASSERT((!sstrcmp(value, v)), "wrong value");
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
349
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
350 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
351 UCX_TEST_ASSERT(r == 1, "next returned 0");
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
352 UCX_TEST_ASSERT((!sstrcmp(name, sstr((char*)"key"))), "wrong name");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
353 UCX_TEST_ASSERT((!sstrcmp(value, sstr((char*)"value"))), "wrong value");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
354
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
355 r = ucx_properties_next(parser, &name, &value);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
356 UCX_TEST_ASSERT(r == 0, "next returned 1");
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
357
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
358 UCX_TEST_END
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
359
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
360 free(long_name);
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
361 free(long_value);
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
362 ucx_properties_free(parser);
108
d2b1e67b2b48 new properties parser
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
363 }
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
364
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
365 UCX_TEST_IMPLEMENT(test_ucx_properties2map) {
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
366 UcxMap *map = ucx_map_new(16);
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
367 UcxProperties *parser = ucx_properties_new();
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
368
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
369 UCX_TEST_BEGIN
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
370
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
371 const char *str = "key1 = value1\nkey2 = value2\n\n#comment\n\nkey3 = value3\n";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
372 ucx_properties_fill(parser, (char*)str, strlen(str));
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
373
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
374 int r = ucx_properties2map(parser, map);
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
375
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
376 UCX_TEST_ASSERT(r == 0, "properties2map failed");
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
377 UCX_TEST_ASSERT(map->count == 3, "wrong number of properties");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
378
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
379 char *v1 = (char*)ucx_map_cstr_get(map, "key1");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
380 char *v2 = (char*)ucx_map_cstr_get(map, "key2");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
381 char *v3 = (char*)ucx_map_cstr_get(map, "key3");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
382
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
383 UCX_TEST_ASSERT(v1, "value for key1 not found");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
384 UCX_TEST_ASSERT(v2, "value for key2 not found");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
385 UCX_TEST_ASSERT(v3, "value for key3 not found");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
386
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
387 UCX_TEST_ASSERT((!strcmp(v1, "value1")), "wrong value for key1");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
388 UCX_TEST_ASSERT((!strcmp(v2, "value2")), "wrong value for key2");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
389 UCX_TEST_ASSERT((!strcmp(v3, "value3")), "wrong value for key3");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
390
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
391 // second test
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
392 ucx_map_free(map);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
393 free(v1);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
394 free(v2);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
395 free(v3);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
396 map = ucx_map_new(16);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
397
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
398 str = "\n#comment\n";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
399 ucx_properties_fill(parser, (char*)str, strlen(str));
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
400
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
401 r = ucx_properties2map(parser, map);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
402 UCX_TEST_ASSERT(r == 0, "properties2map failed");
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
403 UCX_TEST_ASSERT(map->count == 0, "wrong number of properties");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
404
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
405 str = "key1 = value1\nsyntax error line\n";
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
406 ucx_properties_fill(parser, (char*)str, strlen(str));
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
407
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
408 r = ucx_properties2map(parser, map);
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
409 UCX_TEST_ASSERT(r == 1, "properties2map should return 1");
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
410 UCX_TEST_ASSERT(map->count == 1, "wrong number of properties");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
411
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
412 char *v = (char*)ucx_map_cstr_get(map, "key1");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
413 UCX_TEST_ASSERT((!strcmp(v, "value1")), "wrong value");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
414
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
415 UCX_TEST_END
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
416
110
1cf71e56f01e renamed properties functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 109
diff changeset
417 ucx_properties_free(parser);
109
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
418 }
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
419
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
420 UCX_TEST_IMPLEMENT(test_ucx_properties_load) {
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
421 UCX_TEST_BEGIN
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
422 FILE *f = tmpfile();
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
423 UCX_TEST_ASSERT(f, "test file cannot be opened, test aborted");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
424
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
425 fprintf(f, "# properties file\n\nkey1 = value1\nkey2 = value2\n");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
426 fprintf(f, "\n\nkey3 = value3\n\n");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
427
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
428 size_t name_len = 512;
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
429 char *long_name = (char*)malloc(name_len);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
430 memset(long_name, 'k', 512);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
431
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
432 size_t value_len = 2048;
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
433 char *long_value = (char*)malloc(value_len);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
434 memset(long_value, 'v', 2048);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
435
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
436 fwrite(long_name, 1, name_len, f);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
437 fprintf(f, " = ");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
438 fwrite(long_value, 1, value_len, f);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
439 fprintf(f, " \n");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
440
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
441 fprintf(f, "\n\n\n\nlast_key = property value\n");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
442
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
443 fflush(f);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
444 fseek(f, 0, SEEK_SET);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
445
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
446 UcxMap *map = ucx_map_new(8);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
447 int r = ucx_properties_load(map, f);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
448
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
449 UCX_TEST_ASSERT(r == 0, "ucx_properties_load failed");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
450 UCX_TEST_ASSERT(map->count == 5, "wrong number of properties");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
451
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
452 char *v1 = (char*)ucx_map_cstr_get(map, "key1");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
453 char *v2 = (char*)ucx_map_cstr_get(map, "key2");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
454 char *v3 = (char*)ucx_map_cstr_get(map, "key3");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
455 char *lv = (char*)ucx_map_sstr_get(map, sstrn(long_name, name_len));
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
456 char *lk = (char*)ucx_map_cstr_get(map, "last_key");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
457
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
458 UCX_TEST_ASSERT(v1, "value for key1 not found");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
459 UCX_TEST_ASSERT(v2, "value for key2 not found");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
460 UCX_TEST_ASSERT(v3, "value for key3 not found");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
461 UCX_TEST_ASSERT(lv, "value for long key not found");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
462 UCX_TEST_ASSERT(lk, "value for last_key not found");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
463
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
464 UCX_TEST_ASSERT((!strcmp(v1, "value1")), "wrong value for key1");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
465 UCX_TEST_ASSERT((!strcmp(v2, "value2")), "wrong value for key2");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
466 UCX_TEST_ASSERT((!strcmp(v3, "value3")), "wrong value for key3");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
467 sstr_t long1 = sstrn(long_value, value_len);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
468 sstr_t long2 = sstr(lv);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
469 UCX_TEST_ASSERT((!sstrcmp(long1, long2)), "wrong value for long key");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
470 UCX_TEST_ASSERT(!strcmp(lk, "property value"), "wrong value for last_key");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
471
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
472 free(v1);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
473 free(v2);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
474 free(v3);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
475 free(lv);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
476 free(lk);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
477 ucx_map_free(map);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
478 fclose(f);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
479
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
480 UCX_TEST_END
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
481 }
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
482
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
483 UCX_TEST_IMPLEMENT(test_ucx_properties_store) {
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
484 UcxMap *map1 = ucx_map_new(16);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
485 ucx_map_cstr_put(map1, "key1", "value1");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
486 ucx_map_cstr_put(map1, "key2", "value2");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
487 ucx_map_cstr_put(map1, "key3", "value3");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
488 ucx_map_cstr_put(map1, "key4", "value4");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
489 ucx_map_cstr_put(map1, "property.key1", "some value 1");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
490 ucx_map_cstr_put(map1, "property.key2", "some value 2");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
491 ucx_map_cstr_put(map1, "property.key3", "some value 3");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
492 ucx_map_cstr_put(map1, "property.key4", "some value 4");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
493
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
494 UCX_TEST_BEGIN
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
495
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
496 FILE *f = tmpfile();
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
497 fprintf(f, "#\n# test property file\n#\n#\n");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
498 ucx_properties_store(map1, f);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
499
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
500 fflush(f);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
501 fseek(f, 0, SEEK_SET);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
502 UcxMap *map2 = ucx_map_new(16);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
503 ucx_properties_load(map2, f);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
504
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
505 UCX_TEST_ASSERT(map2->count == 8, "wrong number of properties in map2");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
506
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
507 char *v1 = (char*)ucx_map_cstr_get(map2, "key1");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
508 char *v2 = (char*)ucx_map_cstr_get(map2, "key2");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
509 char *v3 = (char*)ucx_map_cstr_get(map2, "key3");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
510 char *v4 = (char*)ucx_map_cstr_get(map2, "key4");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
511 char *v5 = (char*)ucx_map_cstr_get(map2, "property.key1");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
512 char *v6 = (char*)ucx_map_cstr_get(map2, "property.key2");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
513 char *v7 = (char*)ucx_map_cstr_get(map2, "property.key3");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
514 char *v8 = (char*)ucx_map_cstr_get(map2, "property.key4");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
515
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
516 UCX_TEST_ASSERT(v1 && v2 && v3 && v4 && v5 && v6 && v7 && v8,
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
517 "missing values");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
518
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
519 UCX_TEST_ASSERT((!strcmp(v1, "value1")), "wrong value 1");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
520 UCX_TEST_ASSERT((!strcmp(v2, "value2")), "wrong value 2");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
521 UCX_TEST_ASSERT((!strcmp(v3, "value3")), "wrong value 3");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
522 UCX_TEST_ASSERT((!strcmp(v4, "value4")), "wrong value 4");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
523 UCX_TEST_ASSERT((!strcmp(v5, "some value 1")), "wrong value 5");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
524 UCX_TEST_ASSERT((!strcmp(v6, "some value 2")), "wrong value 6");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
525 UCX_TEST_ASSERT((!strcmp(v7, "some value 3")), "wrong value 7");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
526 UCX_TEST_ASSERT((!strcmp(v8, "some value 4")), "wrong value 8");
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
527
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
528 free(v1);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
529 free(v2);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
530 free(v3);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
531 free(v4);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
532 free(v5);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
533 free(v6);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
534 free(v7);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
535 free(v8);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
536 ucx_map_free(map2);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
537 fclose(f);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
538
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
539 UCX_TEST_END
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
540
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
541 ucx_map_free(map1);
75cb6590358b added properties load/store functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 108
diff changeset
542 }

mercurial