tests/test_properties.c

Sat, 12 Oct 2024 19:34:19 +0200

author
Mike Becker <universe@uap-core.de>
date
Sat, 12 Oct 2024 19:34:19 +0200
changeset 924
3c90dfc35f06
permissions
-rw-r--r--

add implementation for the properties parser

relates to #429

924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
1 /*
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
3 *
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
4 * Copyright 2024 Mike Becker, Olaf Wintermann All rights reserved.
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
5 *
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
8 *
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
11 *
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
15 *
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
27 */
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
28
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
29 #include "cx/test.h"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
30
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31 #include "cx/properties.h"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
33 CX_TEST(test_cx_properties_init) {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34 CxProperties prop;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
35 CX_TEST_DO {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 cxPropertiesInitDefault(&prop);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 CX_TEST_ASSERT(prop.config.delimiter == '=');
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39 CX_TEST_ASSERT(prop.config.comment1 == '#');
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 CX_TEST_ASSERT(prop.config.comment2 == 0);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 CX_TEST_ASSERT(prop.config.comment3 == 0);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 CX_TEST_ASSERT(prop.flags == 0);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 CX_TEST_ASSERT(prop.text == NULL);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
44 CX_TEST_ASSERT(prop.buf == NULL);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
45
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
46 cxPropertiesDestroy(&prop);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
47 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
48 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
49
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
50 CX_TEST(test_cx_properties_next) {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51 const char *tests[] = {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
52 "name = value\n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 "name=value\n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 "n=value\n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 "name=v\n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 "n=v\n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 "name = value # comment\n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 "#comment\nn=v\n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 "# comment1\n# comment2\n\n \n\nname = value\n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 " name = value\n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 "name = value\n\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
62 };
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 const char *keys[] = {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65 "name",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 "name",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 "n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
68 "name",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
69 "n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
70 "name",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
71 "n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
72 "name",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
73 "name",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
74 "name"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
75 };
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
76
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 const char *values[] = {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78 "value",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 "value",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
80 "value",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
81 "v",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82 "v",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 "value",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
84 "v",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
85 "value",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
86 "value",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
87 "value"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
88 };
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 CxProperties prop;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91 cxPropertiesInitDefault(&prop);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 enum cx_properties_status result;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 cxstring key;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
94 cxstring value;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 CX_TEST_DO {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 for (int i = 0; i < 10; i++) {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 cxPropertiesInput(&prop, tests[i], strlen(tests[i]));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 CX_TEST_ASSERT(prop.text == tests[i]);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
99 CX_TEST_ASSERT(prop.text_size == strlen(tests[i]));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
100 CX_TEST_ASSERT(prop.text_pos == 0);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
101
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
102 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103 cxstring k = cx_str(keys[i]);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
104 cxstring v = cx_str(values[i]);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 CX_TEST_ASSERT(0 == cx_strcmp(key, k));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 CX_TEST_ASSERT(0 == cx_strcmp(value, v));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 cxPropertiesDestroy(&prop);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
114 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
115
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 CX_TEST(test_cx_properties_next_multi) {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117 const char *keys[] = {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
118 "a",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 "b",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
120 "c",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
121 "uap",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
122 "name",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
123 "key1",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
124 "key2",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
125 "key3"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
126 };
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
127
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128 const char *values[] = {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129 "a value",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 "b value",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
131 "core",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
132 "core",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
133 "ucx",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
134 "value1",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
135 "value2",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
136 "value3"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
137 };
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
138
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 const char *str = "#\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
140 "# properties\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
141 "# contains key/value pairs\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
142 "#\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
143 "a = a value\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
144 "b = b value\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
145 "c = core\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
146 "\n# test\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
147 "uap = core\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
148 "name = ucx\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
149 "# no = property\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
150 "key1 = value1\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
151 "#key1 = wrong value\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152 "#key2 = not value 2\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
153 "key2 = value2\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 "\n\n\n \n key3=value3\n";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156 CxProperties prop;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157 cxPropertiesInitDefault(&prop);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
158 enum cx_properties_status result;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159 cxstring key;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160 cxstring value;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 CX_TEST_DO {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 CX_TEST_ASSERT(result == CX_PROPERTIES_NULL_INPUT);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 cxPropertiesInput(&prop, str, strlen(str));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166 for (int i = 0; i < 8; i++) {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
169 CX_TEST_ASSERT(!cx_strcmp(key, cx_str(keys[i])));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
170 CX_TEST_ASSERT(!cx_strcmp(value, cx_str(values[i])));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
171 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
172 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
173 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
174 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
175 cxPropertiesDestroy(&prop);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
176 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
177
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
178 CX_TEST(test_cx_properties_next_part) {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179 CxProperties prop;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
180 cxPropertiesInitDefault(&prop);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
181 enum cx_properties_status result;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
182 cxstring key;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
183 cxstring value;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
184 const char *str;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
185
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
186 CX_TEST_DO {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
187 str = "";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
188 cxPropertiesFill(&prop, str, strlen(str));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
189 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
190 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
191
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
192 str = " \n";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
193 cxPropertiesFill(&prop, str, strlen(str));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
194 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
195 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
196
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
197 str = "name";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
198 cxPropertiesFill(&prop, str, strlen(str));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
199 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
200 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
201
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
202 str = " ";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
203 cxPropertiesFill(&prop, str, strlen(str));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
204 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
205 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
206
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
207 // call fill twice in a row
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
208 str = "= ";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
209 cxPropertiesFill(&prop, str, strlen(str));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
210 str = "value";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
211 cxPropertiesFill(&prop, str, strlen(str));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
212 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
213 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
214
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
215 str = "\n";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
216 cxPropertiesFill(&prop, str, strlen(str));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
217 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
218 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
219 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("name")));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
220 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("value")));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
221
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
222 // second round
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
223 str = "#comment\n";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
224 cxPropertiesFill(&prop, str, strlen(str));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
225 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
226 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
227
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
228 str = "#comment\nname2 = ";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
229 cxPropertiesFill(&prop, str, strlen(str));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
230 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
231 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
232
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
233 str = "value2\na = b\n";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
234 cxPropertiesFill(&prop, str, strlen(str));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
235 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
236 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
237 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("name2")));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
238 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("value2")));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
239
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
240 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
241 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
242 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("a")));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
243 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("b")));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
244
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
245 str = "# comment\n#\n#\ntests = ";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
246 cxPropertiesFill(&prop, str, strlen(str));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
247 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
248 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
249
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
250 str = "test1 ";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
251 cxPropertiesFill(&prop, str, strlen(str));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
252 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
253 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
254
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
255 str = "test2 test3 test4\n";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
256 cxPropertiesFill(&prop, str, strlen(str));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
257 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
258 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
259 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("tests")));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
260 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("test1 test2 test3 test4")));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
261
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
262 // test if cxPropertiesNext finds a name/value after a comment
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
263 str = "# just a comment";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
264 cxPropertiesFill(&prop, str, strlen(str));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
265 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
266 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
267
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
268 str = " in 3";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
269 cxPropertiesFill(&prop, str, strlen(str));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
270 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
271 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
272
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
273 str = " parts\nx = 1\n";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
274 cxPropertiesFill(&prop, str, strlen(str));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
275 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
276 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
277 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("x")));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
278 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("1")));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
279
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
280 // finally we are done
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
281 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
282 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
283 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
284 cxPropertiesDestroy(&prop);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
285 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
286
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
287 CX_TEST(test_ucx_properties_next_long_lines) {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
288 CxProperties prop;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
289 cxPropertiesInitDefault(&prop);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
290 enum cx_properties_status result;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
291 cxstring key;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
292 cxstring value;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
293
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
294 size_t key_len = 512;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
295 char *long_key = (char*)malloc(key_len);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
296 memset(long_key, 'a', 70);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
297 memset(long_key + 70, 'b', 242);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
298 memset(long_key + 312, 'c', 200);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
299
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
300 size_t value_len = 2048;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
301 char *long_value = (char*)malloc(value_len);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
302 memset(long_value, 'x', 1024);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
303 memset(long_value+1024, 'y', 1024);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
304
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
305 CX_TEST_DO {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
306 cxPropertiesFill(&prop, long_key, 10);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
307 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
308 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
309
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
310 cxPropertiesFill(&prop, long_key + 10, 202);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
311 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
312 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
313
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
314 cxPropertiesFill(&prop, long_key + 212, 200);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
315 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
316 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
317
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
318 cxPropertiesFill(&prop, long_key + 412, 100);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
319 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
320 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
321
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
322 const char *str = " = ";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
323 cxPropertiesFill(&prop, str, strlen(str));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
324 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
325 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
326
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
327 cxPropertiesFill(&prop, long_value, 512);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
328 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
329 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
330
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
331 cxPropertiesFill(&prop, long_value + 512, 1024);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
332 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
333 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
334
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
335 cxPropertiesFill(&prop, long_value + 1536, 512);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
336 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
337 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
338
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
339 str = "\n#comment\nkey = value\n";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
340 cxPropertiesFill(&prop, str, strlen(str));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
341 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
342 cxstring k = cx_strn(long_key, key_len);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
343 cxstring v = cx_strn(long_value, value_len);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
344 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
345 CX_TEST_ASSERT(0 == cx_strcmp(key, k));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
346 CX_TEST_ASSERT(0 == cx_strcmp(value, v));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
347
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
348 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
349 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
350 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("key")));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
351 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("value")));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
352
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
353 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
354 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
355
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
356 CX_TEST_ASSERT(prop.buf != NULL);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
357 CX_TEST_ASSERT(prop.buf_capacity > 0);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
358 CX_TEST_ASSERT(prop.buf_size == 0);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
359 cxPropertiesDestroy(&prop);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
360
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
361 CX_TEST_ASSERT(prop.buf == NULL);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
362 CX_TEST_ASSERT(prop.buf_capacity == 0);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
363 CX_TEST_ASSERT(prop.buf_size == 0);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
364 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
365
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
366 free(long_key);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
367 free(long_value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
368 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
369
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
370 CxTestSuite *cx_test_suite_properties(void) {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
371 CxTestSuite *suite = cx_test_suite_new("properties");
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
372
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
373 cx_test_register(suite, test_cx_properties_init);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
374 cx_test_register(suite, test_cx_properties_next);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
375 cx_test_register(suite, test_cx_properties_next_multi);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
376 cx_test_register(suite, test_cx_properties_next_part);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
377 cx_test_register(suite, test_ucx_properties_next_long_lines);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
378
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
379 return suite;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
380 }

mercurial