Sun, 07 Dec 2025 15:34:46 +0100
properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
resolves #610
|
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); |
|
1031
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
44 | 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
|
45 | CX_TEST_ASSERT(prop.buffer.space == NULL); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
46 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
47 | cxPropertiesDestroy(&prop); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
48 | } |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
49 | } |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
50 | |
|
964
3860f509fcbe
fix test function names not in line with naming convention
Mike Becker <universe@uap-core.de>
parents:
929
diff
changeset
|
51 | CX_TEST(test_properties_next) { |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
52 | const char *tests[] = { |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
53 | "name = value\n", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
54 | "name=value\n", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
55 | "n=value\n", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
56 | "name=v\n", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
57 | "n=v\n", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
58 | "name = value # comment\n", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
59 | "#comment\nn=v\n", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
60 | "# 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
|
61 | " name = value\n", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
62 | "name = value\n\n" |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
63 | }; |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
64 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
65 | const char *keys[] = { |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
66 | "name", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
67 | "name", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
68 | "n", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
69 | "name", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
70 | "n", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
71 | "name", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
72 | "n", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
73 | "name", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
74 | "name", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
75 | "name" |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
76 | }; |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
77 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
78 | const char *values[] = { |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
79 | "value", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
80 | "value", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
81 | "value", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
82 | "v", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
83 | "v", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
84 | "value", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
85 | "v", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
86 | "value", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
87 | "value", |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
88 | "value" |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
89 | }; |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
90 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
91 | CxProperties prop; |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
92 | cxPropertiesInitDefault(&prop); |
|
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
93 | CxPropertiesStatus result; |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
94 | cxstring key; |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
95 | cxstring value; |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
96 | CX_TEST_DO { |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
97 | 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
|
98 | 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
|
99 | 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
|
100 | 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
|
101 | CX_TEST_ASSERT(prop.input.pos == 0); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
102 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
103 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
104 | cxstring k = cx_str(keys[i]); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
105 | cxstring v = cx_str(values[i]); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
106 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
107 | CX_TEST_ASSERT(0 == cx_strcmp(key, k)); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
108 | CX_TEST_ASSERT(0 == cx_strcmp(value, v)); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
109 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
110 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
111 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
112 | } |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
113 | } |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
114 | cxPropertiesDestroy(&prop); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
115 | } |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
116 | |
|
972
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
117 | 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
|
118 | const char *keys[] = { |
|
972
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
119 | "a", |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
120 | "b", |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
121 | "c", |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
122 | "uap", |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
123 | "name", |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
124 | "key1", |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
125 | "key2", |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
126 | "key3" |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
127 | }; |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
128 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
129 | const char *values[] = { |
|
972
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
130 | "a value", |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
131 | "b value", |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
132 | "core", |
|
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 | "ucx", |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
135 | "value1", |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
136 | "value2", |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
137 | "value3" |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
138 | }; |
|
972
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
139 | CxPropertiesStatus result; |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
140 | cxstring key; |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
141 | cxstring value; |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
142 | 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
|
143 | result = cxPropertiesNext(prop, &key, &value); |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
144 | 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
|
145 | 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
|
146 | 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
|
147 | } |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
148 | result = cxPropertiesNext(prop, &key, &value); |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
149 | 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
|
150 | } |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
151 | |
|
972
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
152 | CX_TEST(test_properties_next_multi) { |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
153 | const char *str = "#\n" |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
154 | "# properties\n" |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
155 | "# contains key/value pairs\n" |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
156 | "#\n" |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
157 | "a = a value\n" |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
158 | "b = b value\n" |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
159 | "c = core\n" |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
160 | "\n# test\n" |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
161 | "uap = core\n" |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
162 | "name = ucx\n" |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
163 | "# no = property\n" |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
164 | "key1 = value1\n" |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
165 | "#key1 = wrong value\n" |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
166 | "#key2 = not value 2\n" |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
167 | "key2 = value2\n" |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
168 | "\n\n\n \n key3=value3\n"; |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
169 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
170 | CxProperties prop; |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
171 | cxPropertiesInitDefault(&prop); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
172 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
173 | CX_TEST_DO { |
|
972
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
174 | CxPropertiesStatus result; |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
175 | cxstring key; |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
176 | cxstring value; |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
177 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
178 | 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
|
179 | |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
180 | // check for C string |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
181 | cxPropertiesFill(&prop, str); |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
182 | 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
|
183 | |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
184 | // check for cxstring |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
185 | cxPropertiesFill(&prop, cx_str(str)); |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
186 | 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
|
187 | |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
188 | // check for mutstr |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
189 | cxPropertiesFill(&prop, cx_mutstr((char*)str)); |
|
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
190 | 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
|
191 | } |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
192 | cxPropertiesDestroy(&prop); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
193 | } |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
194 | |
|
964
3860f509fcbe
fix test function names not in line with naming convention
Mike Becker <universe@uap-core.de>
parents:
929
diff
changeset
|
195 | CX_TEST(test_properties_next_part) { |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
196 | CxProperties prop; |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
197 | cxPropertiesInitDefault(&prop); |
|
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
198 | CxPropertiesStatus result; |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
199 | cxstring key; |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
200 | cxstring value; |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
201 | const char *str; |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
202 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
203 | CX_TEST_DO { |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
204 | str = ""; |
|
1031
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
205 | CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str)); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
206 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
207 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
208 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
209 | str = " \n"; |
|
1031
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
210 | CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str)); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
211 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
212 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
213 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
214 | str = "name"; |
|
1031
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
215 | CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str)); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
216 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
217 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
218 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
219 | str = " "; |
|
1031
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
220 | CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str)); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
221 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
222 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
223 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
224 | // call fill twice in a row |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
225 | str = "= "; |
|
1031
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
226 | CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str)); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
227 | str = "value"; |
|
1031
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
228 | CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str)); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
229 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
230 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
231 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
232 | str = "\n"; |
|
1031
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
233 | CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str)); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
234 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
235 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
236 | 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
|
237 | 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
|
238 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
239 | // second round |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
240 | str = "#comment\n"; |
|
1031
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
241 | CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str)); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
242 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
243 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
244 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
245 | str = "#comment\nname2 = "; |
|
1031
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
246 | CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str)); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
247 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
248 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
249 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
250 | str = "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
|
251 | CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str)); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
252 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
253 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
254 | 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
|
255 | 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
|
256 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
257 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
258 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
259 | CX_TEST_ASSERT(0 == cx_strcmp(key, cx_str("a"))); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
260 | CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("b"))); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
261 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
262 | 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
|
263 | CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str)); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
264 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
265 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
266 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
267 | str = "test1 "; |
|
1031
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
268 | CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str)); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
269 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
270 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
271 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
272 | 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
|
273 | CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str)); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
274 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
275 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
276 | 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
|
277 | 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
|
278 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
279 | // 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
|
280 | 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
|
281 | CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str)); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
282 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
283 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
284 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
285 | str = " in 3"; |
|
1031
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
286 | CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str)); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
287 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
288 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
289 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
290 | 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
|
291 | CX_TEST_ASSERT(0 == cxPropertiesFill(&prop, str)); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
292 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
293 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
294 | 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
|
295 | 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
|
296 | |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
297 | // finally we are done |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
298 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
299 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
300 | } |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
301 | cxPropertiesDestroy(&prop); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
302 | } |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
303 | |
|
964
3860f509fcbe
fix test function names not in line with naming convention
Mike Becker <universe@uap-core.de>
parents:
929
diff
changeset
|
304 | CX_TEST(test_properties_next_long_lines) { |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
305 | CxProperties prop; |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
306 | cxPropertiesInitDefault(&prop); |
|
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
307 | CxPropertiesStatus result; |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
308 | cxstring key; |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
309 | cxstring value; |
|
1031
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
310 | |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
311 | size_t key_len = 512; |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
312 | char *long_key = (char*)malloc(key_len); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
313 | memset(long_key, 'a', 70); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
314 | memset(long_key + 70, 'b', 242); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
315 | memset(long_key + 312, 'c', 200); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
316 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
317 | size_t value_len = 2048; |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
318 | char *long_value = (char*)malloc(value_len); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
319 | memset(long_value, 'x', 1024); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
320 | memset(long_value+1024, 'y', 1024); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
321 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
322 | CX_TEST_DO { |
|
972
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
323 | cxPropertiesFilln(&prop, long_key, 10); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
324 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
325 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
326 | |
|
972
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
327 | cxPropertiesFilln(&prop, long_key + 10, 202); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
328 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
329 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
330 | |
|
972
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
331 | cxPropertiesFilln(&prop, long_key + 212, 200); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
332 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
333 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
334 | |
|
972
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
335 | cxPropertiesFilln(&prop, long_key + 412, 100); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
336 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
337 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
338 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
339 | const char *str = " = "; |
|
972
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
340 | cxPropertiesFill(&prop, str); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
341 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
342 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
343 | |
|
972
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
344 | cxPropertiesFilln(&prop, long_value, 512); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
345 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
346 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
347 | |
|
972
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
348 | cxPropertiesFilln(&prop, long_value + 512, 1024); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
349 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
350 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
351 | |
|
972
a9a1d07a6840
add support for UCX strings in cxPropertiesFill()
Mike Becker <universe@uap-core.de>
parents:
964
diff
changeset
|
352 | cxPropertiesFilln(&prop, long_value + 1536, 512); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
353 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
354 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
355 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
356 | 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
|
357 | cxPropertiesFill(&prop, str); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
358 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
359 | cxstring k = cx_strn(long_key, key_len); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
360 | cxstring v = cx_strn(long_value, value_len); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
361 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
362 | CX_TEST_ASSERT(0 == cx_strcmp(key, k)); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
363 | CX_TEST_ASSERT(0 == cx_strcmp(value, v)); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
364 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
365 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
366 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
367 | 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
|
368 | 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
|
369 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
370 | result = cxPropertiesNext(&prop, &key, &value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
371 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
372 | |
|
1031
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
373 | 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
|
374 | 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
|
375 | CX_TEST_ASSERT(cxBufferEof(&prop.input)); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
376 | cxPropertiesDestroy(&prop); |
|
1031
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
377 | 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
|
378 | 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
|
379 | CX_TEST_ASSERT(prop.buffer.pos == 0); |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
380 | } |
|
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 | free(long_key); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
383 | free(long_value); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
384 | } |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
385 | |
|
1555
8972247f54e8
properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents:
1124
diff
changeset
|
386 | CX_TEST(test_properties_load) { |
|
8972247f54e8
properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents:
1124
diff
changeset
|
387 | char fname[16] = "ucxtestXXXXXX"; |
|
8972247f54e8
properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents:
1124
diff
changeset
|
388 | int tmpfd = mkstemp(fname); |
|
8972247f54e8
properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents:
1124
diff
changeset
|
389 | FILE *f = tmpfd < 0 ? NULL : fdopen(tmpfd, "w"); |
|
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
390 | CX_TEST_DO { |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
391 | CX_TEST_ASSERTM(f, "test file cannot be opened, test aborted"); |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
392 | 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
|
393 | 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
|
394 | |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
395 | size_t key_len = 512; |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
396 | 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
|
397 | memset(long_key, 'k', 512); |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
398 | |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
399 | size_t value_len = 2048; |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
400 | 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
|
401 | memset(long_value, 'v', 2048); |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
402 | |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
403 | 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
|
404 | fprintf(f, " = "); |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
405 | 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
|
406 | fprintf(f, " \n"); |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
407 | |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
408 | 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
|
409 | 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
|
410 | f = NULL; |
|
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
411 | // preparation of test file complete |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
412 | |
|
1555
8972247f54e8
properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents:
1124
diff
changeset
|
413 | // we want to load the properties into a map of char* pointers |
|
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
414 | CxMap *map = cxHashMapCreateSimple(CX_STORE_POINTERS); |
|
1555
8972247f54e8
properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents:
1124
diff
changeset
|
415 | cxDefineDestructor(map, cxFreeDefault); |
|
8972247f54e8
properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents:
1124
diff
changeset
|
416 | CxPropertiesStatus status = cxPropertiesLoadDefault(fname, map); |
|
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
417 | |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
418 | 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
|
419 | 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
|
420 | |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
421 | char *v1 = cxMapGet(map, "key1"); |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
422 | 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
|
423 | char *v3 = cxMapGet(map, "key3"); |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
424 | 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
|
425 | 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
|
426 | |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
427 | 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
|
428 | 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
|
429 | 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
|
430 | 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
|
431 | 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
|
432 | |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
433 | 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
|
434 | 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
|
435 | 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
|
436 | 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
|
437 | cxstring actual = cx_str(lv); |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
438 | 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
|
439 | 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
|
440 | |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
441 | free(long_key); |
|
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
442 | free(long_value); |
|
993
b642eca4b956
make names of destroy and free functions consistent - fixes #484
Mike Becker <universe@uap-core.de>
parents:
972
diff
changeset
|
443 | cxMapFree(map); |
|
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
444 | } |
|
1555
8972247f54e8
properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents:
1124
diff
changeset
|
445 | if (f) 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
|
446 | 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
|
447 | } |
|
fcd5d86c472f
fix wrong status of cxPropertiesLoad() when data is incomplete - fixes #560
Mike Becker <universe@uap-core.de>
parents:
1031
diff
changeset
|
448 | |
|
1031
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
449 | 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
|
450 | 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
|
451 | 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
|
452 | 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
|
453 | |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
454 | CxProperties prop; |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
455 | cxPropertiesInitDefault(&prop); |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
456 | CxPropertiesStatus result; |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
457 | cxstring key; |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
458 | cxstring value; |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
459 | CX_TEST_DO { |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
460 | cxPropertiesFill(&prop, props1); |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
461 | cxPropertiesFill(&prop, props2); |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
462 | cxPropertiesFill(&prop, props3); |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
463 | 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
|
464 | 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
|
465 | 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
|
466 | 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
|
467 | 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
|
468 | 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
|
469 | 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
|
470 | 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
|
471 | 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
|
472 | 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
|
473 | 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
|
474 | 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
|
475 | |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
476 | 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
|
477 | 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
|
478 | } |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
479 | cxPropertiesDestroy(&prop); |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
480 | } |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
481 | |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
482 | 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
|
483 | 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
|
484 | 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
|
485 | 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
|
486 | char stackmem[16]; |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
487 | |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
488 | CxProperties prop; |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
489 | cxPropertiesInitDefault(&prop); |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
490 | cxPropertiesUseStack(&prop, stackmem, 16); |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
491 | CxPropertiesStatus result; |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
492 | cxstring key; |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
493 | cxstring value; |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
494 | CX_TEST_DO { |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
495 | cxPropertiesFill(&prop, props1); |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
496 | 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
|
497 | 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
|
498 | cxPropertiesFill(&prop, props2); |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
499 | 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
|
500 | 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
|
501 | 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
|
502 | 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
|
503 | 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
|
504 | 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
|
505 | cxPropertiesFill(&prop, props3); |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
506 | 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
|
507 | 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
|
508 | 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
|
509 | 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
|
510 | 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
|
511 | 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
|
512 | 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
|
513 | 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
|
514 | 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
|
515 | 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
|
516 | } |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
517 | cxPropertiesDestroy(&prop); |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
518 | } |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
519 | |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
520 | 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
|
521 | 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
|
522 | 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
|
523 | 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
|
524 | |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
525 | CxProperties prop; |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
526 | CxPropertiesStatus result; |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
527 | cxstring key; |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
528 | cxstring value; |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
529 | CX_TEST_DO { |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
530 | cxPropertiesInitDefault(&prop); |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
531 | cxPropertiesFill(&prop, fail1); |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
532 | 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
|
533 | 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
|
534 | cxPropertiesReset(&prop); |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
535 | cxPropertiesFill(&prop, fail2); |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
536 | 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
|
537 | 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
|
538 | cxPropertiesReset(&prop); |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
539 | cxPropertiesFill(&prop, good); |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
540 | 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
|
541 | 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
|
542 | 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
|
543 | 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
|
544 | cxPropertiesDestroy(&prop); |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
545 | } |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
546 | } |
|
8a90552bba29
rework of properties parser - fixes #529 and resolves #458
Mike Becker <universe@uap-core.de>
parents:
993
diff
changeset
|
547 | |
|
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
548 | CxTestSuite *cx_test_suite_properties(void) { |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
549 | CxTestSuite *suite = cx_test_suite_new("properties"); |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
550 | |
|
964
3860f509fcbe
fix test function names not in line with naming convention
Mike Becker <universe@uap-core.de>
parents:
929
diff
changeset
|
551 | 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
|
552 | 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
|
553 | 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
|
554 | 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
|
555 | cx_test_register(suite, test_properties_next_long_lines); |
|
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_register(suite, test_properties_load); |
|
8972247f54e8
properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents:
1124
diff
changeset
|
557 | // TODO: test_properties_load_empty_file |
|
8972247f54e8
properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents:
1124
diff
changeset
|
558 | // TODO: test_properties_load_invalid_key |
|
8972247f54e8
properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents:
1124
diff
changeset
|
559 | // TODO: test_properties_load_missing_delimiter |
|
8972247f54e8
properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents:
1124
diff
changeset
|
560 | // TODO: test_properties_load_unexpected_end |
|
8972247f54e8
properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents:
1124
diff
changeset
|
561 | // TODO: test_properties_load_file_not_exists |
|
8972247f54e8
properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents:
1124
diff
changeset
|
562 | // TODO: test_properties_load_exceed_stack |
|
8972247f54e8
properties.h: removes the source/sink API and adds a new cxPropertiesLoad()
Mike Becker <universe@uap-core.de>
parents:
1124
diff
changeset
|
563 | // TODO: 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
|
564 | 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
|
565 | 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
|
566 | 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
|
567 | |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
568 | return suite; |
|
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
569 | } |