tests/test_properties.c

Wed, 31 Dec 2025 13:39:55 +0100

author
Mike Becker <universe@uap-core.de>
date
Wed, 31 Dec 2025 13:39:55 +0100
changeset 1689
a5b7cf49dea7
parent 1683
e5399c60ae96
permissions
-rw-r--r--

fix tree node destruction + reactivate all tests

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"
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
30 #include "util_allocator.h"
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
31
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
32 #include "cx/properties.h"
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
33 #include "cx/hash_map.h"
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
34
964
3860f509fcbe fix test function names not in line with naming convention
Mike Becker <universe@uap-core.de>
parents: 929
diff changeset
35 CX_TEST(test_properties_init) {
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
36 CxProperties prop;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37 CX_TEST_DO {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
38 cxPropertiesInitDefault(&prop);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
39
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
40 CX_TEST_ASSERT(prop.config.delimiter == '=');
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
41 CX_TEST_ASSERT(prop.config.comment1 == '#');
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
42 CX_TEST_ASSERT(prop.config.comment2 == 0);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
43 CX_TEST_ASSERT(prop.config.comment3 == 0);
1562
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
44 CX_TEST_ASSERT(prop.config.continuation == '\\');
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
45 CX_TEST_ASSERT(prop.input.space == NULL);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
46 CX_TEST_ASSERT(prop.buffer.space == NULL);
924
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 cxPropertiesDestroy(&prop);
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 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
51
964
3860f509fcbe fix test function names not in line with naming convention
Mike Becker <universe@uap-core.de>
parents: 929
diff changeset
52 CX_TEST(test_properties_next) {
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
53 const char *tests[] = {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
54 "name = value\n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
55 "name=value\n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
56 "n=value\n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
57 "name=v\n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
58 "n=v\n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
59 "name = value # comment\n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
60 "#comment\nn=v\n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
61 "# 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
62 " name = value\n",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
63 "name = value\n\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
64 };
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
65
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
66 const char *keys[] = {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
67 "name",
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 "n",
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 "name",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
76 "name"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
77 };
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
78
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
79 const char *values[] = {
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 "value",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
82 "value",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
83 "v",
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 "v",
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 "value",
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
89 "value"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
90 };
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
91
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
92 CxProperties prop;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
93 cxPropertiesInitDefault(&prop);
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
94 CxPropertiesStatus result;
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
95 cxstring key;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
96 cxstring value;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
97 CX_TEST_DO {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
98 for (int i = 0; i < 10; i++) {
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
99 cxPropertiesFill(&prop, tests[i]);
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
100 CX_TEST_ASSERT(prop.input.space == tests[i]);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
101 CX_TEST_ASSERT(prop.input.size == strlen(tests[i]));
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
102 CX_TEST_ASSERT(prop.input.pos == 0);
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
103
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
104 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
105 cxstring k = cx_str(keys[i]);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
106 cxstring v = cx_str(values[i]);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
107 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
108 CX_TEST_ASSERT(0 == cx_strcmp(key, k));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
109 CX_TEST_ASSERT(0 == cx_strcmp(value, v));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
110
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
111 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
112 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
113 }
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 cxPropertiesDestroy(&prop);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
116 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
117
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
118 CX_TEST_SUBROUTINE(test_properties_next_multi_check, CxProperties *prop) {
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
119 const char *keys[] = {
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
120 "a",
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
121 "b",
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
122 "c",
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
123 "uap",
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
124 "name",
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
125 "key1",
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
126 "key2",
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
127 "key3"
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
128 };
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
129
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
130 const char *values[] = {
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
131 "a value",
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
132 "b value",
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
133 "core",
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
134 "core",
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
135 "ucx",
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
136 "value1",
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
137 "value2",
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
138 "value3"
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
139 };
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
140 CxPropertiesStatus result;
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
141 cxstring key;
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
142 cxstring value;
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
143 for (int i = 0; i < 8; i++) {
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
144 result = cxPropertiesNext(prop, &key, &value);
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
145 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
146 CX_TEST_ASSERT(!cx_strcmp(key, cx_str(keys[i])));
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
147 CX_TEST_ASSERT(!cx_strcmp(value, cx_str(values[i])));
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
148 }
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
149 result = cxPropertiesNext(prop, &key, &value);
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
150 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA);
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
151 }
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
152
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
153 CX_TEST(test_properties_next_multi) {
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
154 const char *str = "#\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
155 "# properties\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
156 "# contains key/value pairs\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
157 "#\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
158 "a = a value\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
159 "b = b value\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
160 "c = core\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
161 "\n# test\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
162 "uap = core\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
163 "name = ucx\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
164 "# no = property\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
165 "key1 = value1\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
166 "#key1 = wrong value\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
167 "#key2 = not value 2\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
168 "key2 = value2\n"
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
169 "\n\n\n \n key3=value3\n";
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
170
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
171 CxProperties prop;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
172 cxPropertiesInitDefault(&prop);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
173
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
174 CX_TEST_DO {
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
175 CxPropertiesStatus result;
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
176 cxstring key;
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
177 cxstring value;
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
178 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
179 CX_TEST_ASSERT(result == CX_PROPERTIES_NULL_INPUT);
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
180
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
181 // check for C string
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
182 cxPropertiesFill(&prop, str);
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
183 CX_TEST_CALL_SUBROUTINE(test_properties_next_multi_check, &prop);
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
184
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
185 // check for cxstring
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
186 cxPropertiesFill(&prop, cx_str(str));
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
187 CX_TEST_CALL_SUBROUTINE(test_properties_next_multi_check, &prop);
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
188
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
189 // check for mutstr
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
190 cxPropertiesFill(&prop, cx_mutstr((char*)str));
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
191 CX_TEST_CALL_SUBROUTINE(test_properties_next_multi_check, &prop);
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
192 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
193 cxPropertiesDestroy(&prop);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
194 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
195
964
3860f509fcbe fix test function names not in line with naming convention
Mike Becker <universe@uap-core.de>
parents: 929
diff changeset
196 CX_TEST(test_properties_next_part) {
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
197 CxProperties prop;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
198 cxPropertiesInitDefault(&prop);
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
199 CxPropertiesStatus result;
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
200 cxstring key;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
201 cxstring value;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
202 const char *str;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
203
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
204 CX_TEST_DO {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
205 str = "";
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
206 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
207 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
208 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
209
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
210 str = " \n";
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
211 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
924
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_NO_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 = "name";
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
216 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
924
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_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
219
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
220 str = " ";
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
221 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
222 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
223 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
224
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
225 // call fill twice in a row
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
226 str = "= ";
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
227 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
228 str = "value";
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
229 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
924
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 = "\n";
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
234 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
924
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("name")));
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("value")));
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 // second round
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
241 str = "#comment\n";
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
242 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
243 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
244 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
245
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
246 str = "#comment\nname2 = ";
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
247 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
248 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
249 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
250
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
251 str = "value2\na = b\n";
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
252 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
253 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
254 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
255 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
256 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
257
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
258 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
259 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
260 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
261 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
262
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
263 str = "# comment\n#\n#\ntests = ";
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
264 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
924
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 = "test1 ";
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
269 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
924
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 = "test2 test3 test4\n";
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
274 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
924
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("tests")));
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("test1 test2 test3 test4")));
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 // 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
281 str = "# just a comment";
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
282 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
283 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
284 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
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 str = " in 3";
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
287 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
288 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
289 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
290
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
291 str = " parts\nx = 1\n";
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
292 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
293 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
294 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
295 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
296 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("1")));
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
297
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
298 // finally we are done
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
299 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
300 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
301 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
302 cxPropertiesDestroy(&prop);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
303 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
304
964
3860f509fcbe fix test function names not in line with naming convention
Mike Becker <universe@uap-core.de>
parents: 929
diff changeset
305 CX_TEST(test_properties_next_long_lines) {
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
306 CxProperties prop;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
307 cxPropertiesInitDefault(&prop);
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
308 CxPropertiesStatus result;
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
309 cxstring key;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
310 cxstring value;
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
311
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
312 size_t key_len = 512;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
313 char *long_key = (char*)malloc(key_len);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
314 memset(long_key, 'a', 70);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
315 memset(long_key + 70, 'b', 242);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
316 memset(long_key + 312, 'c', 200);
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 size_t value_len = 2048;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
319 char *long_value = (char*)malloc(value_len);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
320 memset(long_value, 'x', 1024);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
321 memset(long_value+1024, 'y', 1024);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
322
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
323 CX_TEST_DO {
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
324 cxPropertiesFilln(&prop, long_key, 10);
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
325 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
326 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
327
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
328 cxPropertiesFilln(&prop, long_key + 10, 202);
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
329 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
330 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
331
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
332 cxPropertiesFilln(&prop, long_key + 212, 200);
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
333 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
334 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
335
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
336 cxPropertiesFilln(&prop, long_key + 412, 100);
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
337 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
338 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
339
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
340 const char *str = " = ";
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
341 cxPropertiesFill(&prop, str);
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
342 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
343 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
344
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
345 cxPropertiesFilln(&prop, long_value, 512);
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
346 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
347 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
348
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
349 cxPropertiesFilln(&prop, long_value + 512, 1024);
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
350 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
351 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
352
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
353 cxPropertiesFilln(&prop, long_value + 1536, 512);
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
354 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
355 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
356
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
357 str = "\n#comment\nkey = value\n";
972
a9a1d07a6840 add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents: 964
diff changeset
358 cxPropertiesFill(&prop, str);
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
359 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
360 cxstring k = cx_strn(long_key, key_len);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
361 cxstring v = cx_strn(long_value, value_len);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
362 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
363 CX_TEST_ASSERT(0 == cx_strcmp(key, k));
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
364 CX_TEST_ASSERT(0 == cx_strcmp(value, v));
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 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
367 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
368 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
369 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
370
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
371 result = cxPropertiesNext(&prop, &key, &value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
372 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
373
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
374 CX_TEST_ASSERT(prop.buffer.capacity > 0);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
375 CX_TEST_ASSERT(cxBufferEof(&prop.buffer));
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
376 CX_TEST_ASSERT(cxBufferEof(&prop.input));
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
377 cxPropertiesDestroy(&prop);
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
378 CX_TEST_ASSERT(prop.buffer.capacity == 0);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
379 CX_TEST_ASSERT(prop.buffer.size == 0);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
380 CX_TEST_ASSERT(prop.buffer.pos == 0);
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
381 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
382
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
383 free(long_key);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
384 free(long_value);
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
385 }
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
386
1669
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
387 CX_TEST(test_properties_next_starts_with_newlines) {
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
388 const char *str1 = "key1 = value1";
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
389 const char *str2 = "\nkey2 = value2\n";
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
390
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
391 CxProperties prop;
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
392 cxPropertiesInitDefault(&prop);
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
393
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
394 cxstring key;
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
395 cxstring value;
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
396
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
397 CX_TEST_DO {
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
398 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str1));
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
399 CX_TEST_ASSERT(cxPropertiesNext(&prop, &key, &value) == CX_PROPERTIES_INCOMPLETE_DATA);
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
400 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str2));
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
401 CX_TEST_ASSERT(cxPropertiesNext(&prop, &key, &value) == CX_PROPERTIES_NO_ERROR);
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
402 CX_TEST_ASSERT(!cx_strcmp(key, "key1"));
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
403 CX_TEST_ASSERT(!cx_strcmp(value, "value1"));
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
404 CX_TEST_ASSERT(cxPropertiesNext(&prop, &key, &value) == CX_PROPERTIES_NO_ERROR);
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
405 CX_TEST_ASSERT(!cx_strcmp(key, "key2"));
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
406 CX_TEST_ASSERT(!cx_strcmp(value, "value2"));
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
407 CX_TEST_ASSERT(cxPropertiesNext(&prop, &key, &value) == CX_PROPERTIES_NO_DATA);
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
408 }
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
409
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
410 cxPropertiesDestroy(&prop);
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
411 }
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
412
1562
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
413 CX_TEST(test_properties_next_line_continuation) {
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
414 const char *str =
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
415 "key1 = multiline \\\nvalue\n"
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
416 "key2 = normal\n"
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
417 "key3 = multiline \\\n trim \n"
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
418 "key4 = m1\\\nm2\\\n m3\\\nm4 \n"
1570
8fd491bc2940 add test for multiple consecutive line continuations
Mike Becker <universe@uap-core.de>
parents: 1562
diff changeset
419 "key5 = no\\continuation\n"
8fd491bc2940 add test for multiple consecutive line continuations
Mike Becker <universe@uap-core.de>
parents: 1562
diff changeset
420 "key6 = multiple \\\n \\\n \\\n continuations\n";
1562
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
421
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
422 CxProperties prop;
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
423 cxPropertiesInitDefault(&prop);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
424
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
425 cxstring key;
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
426 cxstring value;
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
427
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
428 CX_TEST_DO {
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
429 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
430
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
431 CX_TEST_ASSERT(cxPropertiesNext(&prop, &key, &value) == CX_PROPERTIES_NO_ERROR);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
432 CX_TEST_ASSERT(!cx_strcmp(key, "key1"));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
433 CX_TEST_ASSERT(!cx_strcmp(value, "multiline value"));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
434
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
435 CX_TEST_ASSERT(cxPropertiesNext(&prop, &key, &value) == CX_PROPERTIES_NO_ERROR);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
436 CX_TEST_ASSERT(!cx_strcmp(key, "key2"));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
437 CX_TEST_ASSERT(!cx_strcmp(value, "normal"));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
438
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
439 CX_TEST_ASSERT(cxPropertiesNext(&prop, &key, &value) == CX_PROPERTIES_NO_ERROR);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
440 CX_TEST_ASSERT(!cx_strcmp(key, "key3"));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
441 CX_TEST_ASSERT(!cx_strcmp(value, "multiline trim"));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
442
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
443 CX_TEST_ASSERT(cxPropertiesNext(&prop, &key, &value) == CX_PROPERTIES_NO_ERROR);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
444 CX_TEST_ASSERT(!cx_strcmp(key, "key4"));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
445 CX_TEST_ASSERT(!cx_strcmp(value, "m1m2m3m4"));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
446
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
447 CX_TEST_ASSERT(cxPropertiesNext(&prop, &key, &value) == CX_PROPERTIES_NO_ERROR);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
448 CX_TEST_ASSERT(!cx_strcmp(key, "key5"));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
449 CX_TEST_ASSERT(!cx_strcmp(value, "no\\continuation"));
1570
8fd491bc2940 add test for multiple consecutive line continuations
Mike Becker <universe@uap-core.de>
parents: 1562
diff changeset
450
8fd491bc2940 add test for multiple consecutive line continuations
Mike Becker <universe@uap-core.de>
parents: 1562
diff changeset
451 CX_TEST_ASSERT(cxPropertiesNext(&prop, &key, &value) == CX_PROPERTIES_NO_ERROR);
8fd491bc2940 add test for multiple consecutive line continuations
Mike Becker <universe@uap-core.de>
parents: 1562
diff changeset
452 CX_TEST_ASSERT(!cx_strcmp(key, "key6"));
8fd491bc2940 add test for multiple consecutive line continuations
Mike Becker <universe@uap-core.de>
parents: 1562
diff changeset
453 CX_TEST_ASSERT(!cx_strcmp(value, "multiple continuations"));
1562
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
454 }
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
455
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
456 cxPropertiesDestroy(&prop);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
457 }
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
458
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
459 CX_TEST(test_properties_next_line_continuation_part) {
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
460 CxProperties prop;
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
461 cxPropertiesInitDefault(&prop);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
462
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
463 cxstring key;
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
464 cxstring value;
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
465 CxPropertiesStatus result;
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
466 const char *str;
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
467
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
468 CX_TEST_DO {
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
469 // key1 = continue continue ...line
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
470 str = "key1 ";
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
471 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
472 result = cxPropertiesNext(&prop, &key, &value);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
473 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
474
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
475 str = "= continue \\";
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
476 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
477 result = cxPropertiesNext(&prop, &key, &value);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
478 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
479
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
480 str = "\ncontinue \\\n";
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
481 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
482 result = cxPropertiesNext(&prop, &key, &value);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
483 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
484
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
485 str = "...";
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
486 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
487 result = cxPropertiesNext(&prop, &key, &value);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
488 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
489
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
490 str = "line\nkey2 = value2\n";
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
491 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
492 result = cxPropertiesNext(&prop, &key, &value);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
493 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
494 CX_TEST_ASSERT(!cx_strcmp(key, "key1"));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
495 CX_TEST_ASSERT(!cx_strcmp(value, "continue continue ...line"));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
496
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
497 // key2 = value2
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
498 result = cxPropertiesNext(&prop, &key, &value);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
499 CX_TEST_ASSERT(!cx_strcmp(key, "key2"));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
500 CX_TEST_ASSERT(!cx_strcmp(value, "value2"));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
501
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
502 // key3 = continue-line
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
503 str = "key3=\\\ncontinue-\\\n line";
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
504 size_t len = strlen(str);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
505 for(size_t i=0;i<len;i++) {
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
506 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, cx_strn(str+i, 1)));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
507 result = cxPropertiesNext(&prop, &key, &value);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
508 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
509 }
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
510 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, "\n"));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
511 result = cxPropertiesNext(&prop, &key, &value);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
512 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
513 CX_TEST_ASSERT(!cx_strcmp(key, "key3"));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
514 CX_TEST_ASSERT(!cx_strcmp(value, "continue-line"));
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
515 }
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
516
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
517 cxPropertiesDestroy(&prop);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
518 }
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
519
1683
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
520 CX_TEST(test_properties_next_alternative_delimiter) {
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
521 CxProperties prop;
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
522 CxPropertiesConfig alt_config = {0};
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
523 alt_config.delimiter = ':';
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
524 cxPropertiesInit(&prop, alt_config);
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
525
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
526 cxstring key;
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
527 cxstring value;
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
528 CxPropertiesStatus result;
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
529
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
530 CX_TEST_DO {
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
531 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, "no_delimiter = value\n"));
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
532 result = cxPropertiesNext(&prop, &key, &value);
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
533 CX_TEST_ASSERT(result == CX_PROPERTIES_INVALID_MISSING_DELIMITER);
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
534 cxPropertiesReset(&prop);
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
535 CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, "correct : value\n"));
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
536 result = cxPropertiesNext(&prop, &key, &value);
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
537 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
538 CX_TEST_ASSERT(!cx_strcmp(key, "correct"));
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
539 CX_TEST_ASSERT(!cx_strcmp(value, "value"));
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
540 }
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
541 cxPropertiesDestroy(&prop);
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
542 }
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
543
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
544 static FILE *cx_opentmp(char *tpl) {
1661
a389bf17eaaa add WITH_MKSTEMP macro because the previous feature test did not always work
Mike Becker <universe@uap-core.de>
parents: 1628
diff changeset
545 #ifdef WITH_MKSTEMP
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
546 strcpy(tpl, "ucxtestXXXXXX");
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
547 int fd = mkstemp(tpl);
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
548 if (fd < 0) return NULL;
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
549 return fdopen(fd, "w");
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
550 #else
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
551 char *fname = tmpnam(tpl);
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
552 return fname == NULL ? NULL : fopen(fname, "wx");
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
553 #endif
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
554 }
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
555
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1124
diff changeset
556 CX_TEST(test_properties_load) {
1557
03fbf1c99e73 add allocator support to cxPropertiesLoad() - resolves #776
Mike Becker <universe@uap-core.de>
parents: 1555
diff changeset
557 CxTestingAllocator talloc;
03fbf1c99e73 add allocator support to cxPropertiesLoad() - resolves #776
Mike Becker <universe@uap-core.de>
parents: 1555
diff changeset
558 cx_testing_allocator_init(&talloc);
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
559 char fname[L_tmpnam];
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
560 FILE *f = cx_opentmp(fname);
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
561 bool rmtmp = false;
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
562 CX_TEST_DO {
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
563 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted");
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
564 rmtmp = true;
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
565 fprintf(f, "# properties file\n\nkey1 = value1\nkey2 = value2\n");
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
566 fprintf(f, "\n\nkey3 = value3\n\n");
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
567
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
568 size_t key_len = 512;
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
569 char *long_key = (char *) malloc(key_len);
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
570 memset(long_key, 'k', 512);
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
571
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
572 size_t value_len = 2048;
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
573 char *long_value = (char *) malloc(value_len);
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
574 memset(long_value, 'v', 2048);
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
575
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
576 fwrite(long_key, 1, key_len, f);
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
577 fprintf(f, " = ");
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
578 fwrite(long_value, 1, value_len, f);
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
579 fprintf(f, " \n");
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
580
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
581 fprintf(f, "\n\n\n\nlast_key = property value\n");
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1124
diff changeset
582 fclose(f);
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1124
diff changeset
583 f = NULL;
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
584 // preparation of test file complete
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
585
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1124
diff changeset
586 // we want to load the properties into a map of char* pointers
1605
55b13f583356 refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents: 1582
diff changeset
587 CxMap *map = cxHashMapCreate(NULL, CX_STORE_POINTERS, 0);
55b13f583356 refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents: 1582
diff changeset
588 cxSetAdvancedDestructor(map, cxFree, &talloc);
1557
03fbf1c99e73 add allocator support to cxPropertiesLoad() - resolves #776
Mike Becker <universe@uap-core.de>
parents: 1555
diff changeset
589 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map);
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
590
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
591 CX_TEST_ASSERT(status == CX_PROPERTIES_NO_ERROR);
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
592 CX_TEST_ASSERT(cxMapSize(map) == 5);
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
593
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
594 char *v1 = cxMapGet(map, "key1");
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
595 char *v2 = cxMapGet(map, cx_str("key2"));
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
596 char *v3 = cxMapGet(map, "key3");
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
597 char *lv = cxMapGet(map, cx_strn(long_key, key_len));
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
598 char *lk = cxMapGet(map, "last_key");
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
599
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
600 CX_TEST_ASSERTM(v1, "value for key1 not found");
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
601 CX_TEST_ASSERTM(v2, "value for key2 not found");
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
602 CX_TEST_ASSERTM(v3, "value for key3 not found");
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
603 CX_TEST_ASSERTM(lv, "value for long key not found");
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
604 CX_TEST_ASSERTM(lk, "value for last_key not found");
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
605
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
606 CX_TEST_ASSERT(!strcmp(v1, "value1"));
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
607 CX_TEST_ASSERT(!strcmp(v2, "value2"));
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
608 CX_TEST_ASSERT(!strcmp(v3, "value3"));
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
609 cxstring expected = cx_strn(long_value, value_len);
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
610 cxstring actual = cx_str(lv);
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
611 CX_TEST_ASSERT(!cx_strcmp(expected, actual));
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
612 CX_TEST_ASSERT(!strcmp(lk, "property value"));
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
613
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
614 free(long_key);
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
615 free(long_value);
1557
03fbf1c99e73 add allocator support to cxPropertiesLoad() - resolves #776
Mike Becker <universe@uap-core.de>
parents: 1555
diff changeset
616 CX_TEST_ASSERT(cx_testing_allocator_used(&talloc));
993
b642eca4b956 make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents: 972
diff changeset
617 cxMapFree(map);
1557
03fbf1c99e73 add allocator support to cxPropertiesLoad() - resolves #776
Mike Becker <universe@uap-core.de>
parents: 1555
diff changeset
618 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
928
d2d42cb1d59e add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents: 924
diff changeset
619 }
1557
03fbf1c99e73 add allocator support to cxPropertiesLoad() - resolves #776
Mike Becker <universe@uap-core.de>
parents: 1555
diff changeset
620 cx_testing_allocator_destroy(&talloc);
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1124
diff changeset
621 if (f) fclose(f);
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
622 if (rmtmp) remove(fname);
1124
fcd5d86c472f fix wrong status of cxPropertiesLoad() when data is incomplete - fixes #560
Mike Becker <universe@uap-core.de>
parents: 1031
diff changeset
623 }
fcd5d86c472f fix wrong status of cxPropertiesLoad() when data is incomplete - fixes #560
Mike Becker <universe@uap-core.de>
parents: 1031
diff changeset
624
1558
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
625 CX_TEST(test_properties_load_empty_file) {
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
626 CxTestingAllocator talloc;
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
627 cx_testing_allocator_init(&talloc);
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
628 char fname[L_tmpnam];
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
629 FILE *f = cx_opentmp(fname);
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
630 bool rmtmp = false;
1558
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
631 CX_TEST_DO {
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
632 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted");
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
633 rmtmp = true;
1558
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
634 fclose(f);
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
635 f = NULL;
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
636
1605
55b13f583356 refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents: 1582
diff changeset
637 CxMap *map = cxHashMapCreate(NULL, CX_STORE_POINTERS, 0);
1558
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
638 // store something that we don't want to be deleted
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
639 cxMapPut(map, "test", "value");
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
640 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map);
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
641 CX_TEST_ASSERT(status == CX_PROPERTIES_NO_DATA);
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
642 CX_TEST_ASSERT(cxMapSize(map) == 1);
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
643
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
644 char *v = cxMapGet(map, "test");
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
645 CX_TEST_ASSERTM(v, "value was removed");
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
646 CX_TEST_ASSERT(!strcmp(v, "value"));
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
647 CX_TEST_ASSERT(!cx_testing_allocator_used(&talloc));
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
648 cxMapFree(map);
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
649 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
650 }
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
651 cx_testing_allocator_destroy(&talloc);
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
652 if (f) fclose(f);
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
653 if (rmtmp) remove(fname);
1558
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
654 }
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
655
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
656 CX_TEST(test_properties_load_only_comments) {
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
657 CxTestingAllocator talloc;
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
658 cx_testing_allocator_init(&talloc);
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
659 char fname[L_tmpnam];
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
660 FILE *f = cx_opentmp(fname);
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
661 bool rmtmp = false;
1558
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
662 CX_TEST_DO {
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
663 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted");
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
664 rmtmp = true;
1558
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
665 fputs("# test file\n\n# contains only comments\n\n# key = value\n", f);
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
666 fclose(f);
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
667 f = NULL;
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
668
1605
55b13f583356 refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents: 1582
diff changeset
669 CxMap *map = cxHashMapCreate(NULL, CX_STORE_POINTERS, 0);
1558
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
670 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map);
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
671 CX_TEST_ASSERT(status == CX_PROPERTIES_NO_DATA);
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
672 CX_TEST_ASSERT(cxMapSize(map) == 0);
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
673
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
674 CX_TEST_ASSERT(!cx_testing_allocator_used(&talloc));
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
675 cxMapFree(map);
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
676 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
677 }
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
678 cx_testing_allocator_destroy(&talloc);
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
679 if (f) fclose(f);
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
680 if (rmtmp) remove(fname);
1558
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
681 }
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
682
1561
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
683 CX_TEST(test_properties_load_error) {
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
684 CxTestingAllocator talloc;
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
685 cx_testing_allocator_init(&talloc);
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
686 char fname[L_tmpnam];
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
687 FILE *f = cx_opentmp(fname);
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
688 bool rmtmp = false;
1561
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
689 CX_TEST_DO {
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
690 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted");
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
691 rmtmp = true;
1561
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
692 fputs("# test file\n\ntest = value\n = value2\n", f);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
693 fclose(f);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
694 f = NULL;
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
695
1605
55b13f583356 refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents: 1582
diff changeset
696 CxMap *map = cxHashMapCreate(NULL, CX_STORE_POINTERS, 0);
55b13f583356 refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents: 1582
diff changeset
697 cxSetAdvancedDestructor(map, cxFree, &talloc);
1561
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
698 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
699 CX_TEST_ASSERT(status == CX_PROPERTIES_INVALID_EMPTY_KEY);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
700 // all keys that could be successfully parsed are added
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
701 CX_TEST_ASSERT(cxMapSize(map) == 1);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
702 char *v = cxMapGet(map, "test");
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
703 CX_TEST_ASSERT(v != NULL);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
704 CX_TEST_ASSERT(!strcmp(v, "value"));
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
705
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
706 cxMapFree(map);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
707 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
708 }
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
709 cx_testing_allocator_destroy(&talloc);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
710 if (f) fclose(f);
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
711 if (rmtmp) remove(fname);
1561
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
712 }
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
713
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
714 CX_TEST(test_properties_load_file_not_exists) {
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
715 CX_TEST_DO {
1605
55b13f583356 refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents: 1582
diff changeset
716 CxMap *map = cxHashMapCreate(NULL, CX_STORE_POINTERS, 0);
1561
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
717 CxPropertiesStatus status = cxPropertiesLoadDefault(NULL, "does-definitely-not-exist", map);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
718 CX_TEST_ASSERT(status == CX_PROPERTIES_FILE_ERROR);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
719 cxMapFree(map);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
720 }
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
721 }
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
722
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
723 CX_TEST(test_properties_load_cxmutstr_map) {
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
724 CxTestingAllocator talloc;
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
725 cx_testing_allocator_init(&talloc);
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
726 char fname[L_tmpnam];
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
727 FILE *f = cx_opentmp(fname);
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
728 bool rmtmp = false;
1561
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
729 CX_TEST_DO {
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
730 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted");
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
731 rmtmp = true;
1561
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
732 fputs("# test file\n\ntest = value\ntest2 = value2\n", f);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
733 fclose(f);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
734 f = NULL;
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
735
1605
55b13f583356 refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents: 1582
diff changeset
736 CxMap *map = cxHashMapCreate(NULL, sizeof(cxmutstr), 0);
55b13f583356 refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents: 1582
diff changeset
737 cxSetAdvancedDestructor(map, cx_strfree_a, &talloc);
1561
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
738 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
739 CX_TEST_ASSERT(status == CX_PROPERTIES_NO_ERROR);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
740 CX_TEST_ASSERT(cxMapSize(map) == 2);
1582
32b82c424252 removes the CX_STR() macro and instead makes the cx_str() inlinable
Mike Becker <universe@uap-core.de>
parents: 1570
diff changeset
741 cxstring v1 = cx_str("value");
32b82c424252 removes the CX_STR() macro and instead makes the cx_str() inlinable
Mike Becker <universe@uap-core.de>
parents: 1570
diff changeset
742 cxstring v2 = cx_str("value2");
1561
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
743 CX_TEST_ASSERT(cx_strcmp_p(cxMapGet(map, "test"), &v1) == 0);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
744 CX_TEST_ASSERT(cx_strcmp_p(cxMapGet(map, "test2"), &v2) == 0);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
745
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
746 CX_TEST_ASSERT(cx_testing_allocator_used(&talloc));
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
747 cxMapFree(map);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
748 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
749 }
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
750 cx_testing_allocator_destroy(&talloc);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
751 if (f) fclose(f);
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
752 if (rmtmp) remove(fname);
1561
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
753 }
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
754
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
755 CX_TEST(test_properties_load_incompatible_map) {
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
756 CxTestingAllocator talloc;
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
757 cx_testing_allocator_init(&talloc);
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
758 char fname[L_tmpnam];
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
759 FILE *f = cx_opentmp(fname);
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
760 bool rmtmp = false;
1561
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
761 CX_TEST_DO {
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
762 CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted");
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
763 rmtmp = true;
1561
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
764 fputs("# test file\n\ntest = value\ntest2 = value2\n", f);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
765 fclose(f);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
766 f = NULL;
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
767
1605
55b13f583356 refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents: 1582
diff changeset
768 CxMap *map = cxHashMapCreate(NULL, sizeof(CxBuffer), 0);
55b13f583356 refactor the list and map construction functions and remove the simple macros
Mike Becker <universe@uap-core.de>
parents: 1582
diff changeset
769 cxSetAdvancedDestructor(map, cxFree, &talloc);
1561
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
770 CxPropertiesStatus status = cxPropertiesLoadDefault(&talloc.base, fname, map);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
771 CX_TEST_ASSERT(status == CX_PROPERTIES_MAP_ERROR);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
772 CX_TEST_ASSERT(cxMapSize(map) == 0);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
773
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
774 cxMapFree(map);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
775 CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc));
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
776 }
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
777 cx_testing_allocator_destroy(&talloc);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
778 if (f) fclose(f);
1628
b15ed93f2aa7 add tmpnam() fallback when in ISO C23 mode - resolves #786
Mike Becker <universe@uap-core.de>
parents: 1605
diff changeset
779 if (rmtmp) remove(fname);
1561
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
780 }
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
781
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
782 CX_TEST(test_properties_multiple_fill) {
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
783 const char *props1 = "key1 = value1\n";
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
784 const char *props2 = "key2 = value2\n";
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
785 const char *props3 = "key3 = value3\n";
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
786
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
787 CxProperties prop;
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
788 cxPropertiesInitDefault(&prop);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
789 CxPropertiesStatus result;
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
790 cxstring key;
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
791 cxstring value;
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
792 CX_TEST_DO {
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
793 cxPropertiesFill(&prop, props1);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
794 cxPropertiesFill(&prop, props2);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
795 cxPropertiesFill(&prop, props3);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
796 result = cxPropertiesNext(&prop, &key, &value);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
797 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
798 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("key1")));
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
799 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("value1")));
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
800 result = cxPropertiesNext(&prop, &key, &value);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
801 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
802 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("key2")));
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
803 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("value2")));
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
804 result = cxPropertiesNext(&prop, &key, &value);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
805 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
806 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("key3")));
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
807 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("value3")));
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
808
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
809 result = cxPropertiesNext(&prop, &key, &value);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
810 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
811 }
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
812 cxPropertiesDestroy(&prop);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
813 }
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
814
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
815 CX_TEST(test_properties_use_stack) {
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
816 const char *props1 = "key1 = val";
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
817 const char *props2 = "ue1\nkey2 = value2";
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
818 const char *props3 = "\nkey3 = value3\n";
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
819 char stackmem[16];
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
820
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
821 CxProperties prop;
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
822 cxPropertiesInitDefault(&prop);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
823 cxPropertiesUseStack(&prop, stackmem, 16);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
824 CxPropertiesStatus result;
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
825 cxstring key;
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
826 cxstring value;
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
827 CX_TEST_DO {
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
828 cxPropertiesFill(&prop, props1);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
829 result = cxPropertiesNext(&prop, &key, &value);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
830 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
831 cxPropertiesFill(&prop, props2);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
832 result = cxPropertiesNext(&prop, &key, &value);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
833 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
834 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("key1")));
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
835 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("value1")));
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
836 result = cxPropertiesNext(&prop, &key, &value);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
837 CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
838 cxPropertiesFill(&prop, props3);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
839 result = cxPropertiesNext(&prop, &key, &value);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
840 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
841 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("key2")));
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
842 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("value2")));
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
843 result = cxPropertiesNext(&prop, &key, &value);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
844 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
845 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("key3")));
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
846 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("value3")));
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
847 result = cxPropertiesNext(&prop, &key, &value);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
848 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
849 }
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
850 cxPropertiesDestroy(&prop);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
851 }
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
852
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
853 CX_TEST(test_properties_empty_key) {
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
854 const char *fail1 = "= val\n";
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
855 const char *fail2 = " = val\n";
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
856 const char *good = " key = val\n";
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
857
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
858 CxProperties prop;
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
859 CxPropertiesStatus result;
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
860 cxstring key;
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
861 cxstring value;
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
862 CX_TEST_DO {
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
863 cxPropertiesInitDefault(&prop);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
864 cxPropertiesFill(&prop, fail1);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
865 result = cxPropertiesNext(&prop, &key, &value);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
866 CX_TEST_ASSERT(result == CX_PROPERTIES_INVALID_EMPTY_KEY);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
867 cxPropertiesReset(&prop);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
868 cxPropertiesFill(&prop, fail2);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
869 result = cxPropertiesNext(&prop, &key, &value);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
870 CX_TEST_ASSERT(result == CX_PROPERTIES_INVALID_EMPTY_KEY);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
871 cxPropertiesReset(&prop);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
872 cxPropertiesFill(&prop, good);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
873 result = cxPropertiesNext(&prop, &key, &value);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
874 CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
875 CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("key")));
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
876 CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("val")));
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
877 cxPropertiesDestroy(&prop);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
878 }
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
879 }
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
880
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
881 CxTestSuite *cx_test_suite_properties(void) {
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
882 CxTestSuite *suite = cx_test_suite_new("properties");
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
883
964
3860f509fcbe fix test function names not in line with naming convention
Mike Becker <universe@uap-core.de>
parents: 929
diff changeset
884 cx_test_register(suite, test_properties_init);
3860f509fcbe fix test function names not in line with naming convention
Mike Becker <universe@uap-core.de>
parents: 929
diff changeset
885 cx_test_register(suite, test_properties_next);
3860f509fcbe fix test function names not in line with naming convention
Mike Becker <universe@uap-core.de>
parents: 929
diff changeset
886 cx_test_register(suite, test_properties_next_multi);
3860f509fcbe fix test function names not in line with naming convention
Mike Becker <universe@uap-core.de>
parents: 929
diff changeset
887 cx_test_register(suite, test_properties_next_part);
3860f509fcbe fix test function names not in line with naming convention
Mike Becker <universe@uap-core.de>
parents: 929
diff changeset
888 cx_test_register(suite, test_properties_next_long_lines);
1669
d416628d6c7d add test_properties_next_starts_with_newlines()
Mike Becker <universe@uap-core.de>
parents: 1661
diff changeset
889 cx_test_register(suite, test_properties_next_starts_with_newlines);
1562
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
890 cx_test_register(suite, test_properties_next_line_continuation);
f2b63cad2142 add support for line continuation in the properties parser - resolves #457
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 1561
diff changeset
891 cx_test_register(suite, test_properties_next_line_continuation_part);
1683
e5399c60ae96 complete properties.c test coverage
Mike Becker <universe@uap-core.de>
parents: 1669
diff changeset
892 cx_test_register(suite, test_properties_next_alternative_delimiter);
1555
8972247f54e8 properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1124
diff changeset
893 cx_test_register(suite, test_properties_load);
1558
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
894 cx_test_register(suite, test_properties_load_empty_file);
fc863c877a75 fix return value of cxPropertiesLoad() for non-empty files that do not contain keys
Mike Becker <universe@uap-core.de>
parents: 1557
diff changeset
895 cx_test_register(suite, test_properties_load_only_comments);
1561
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
896 cx_test_register(suite, test_properties_load_error);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
897 cx_test_register(suite, test_properties_load_file_not_exists);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
898 cx_test_register(suite, test_properties_load_cxmutstr_map);
fcebf53de51c add more tests for cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents: 1558
diff changeset
899 cx_test_register(suite, test_properties_load_incompatible_map);
1031
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
900 cx_test_register(suite, test_properties_multiple_fill);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
901 cx_test_register(suite, test_properties_use_stack);
8a90552bba29 rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents: 993
diff changeset
902 cx_test_register(suite, test_properties_empty_key);
924
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
903
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
904 return suite;
3c90dfc35f06 add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff changeset
905 }

mercurial