Tue, 29 Oct 2024 18:15:06 +0100
use cx_array_add() instead of reimplementing the magic
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 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
35 | CX_TEST(test_cx_properties_init) { |
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); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
44 | CX_TEST_ASSERT(prop.flags == 0); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
45 | CX_TEST_ASSERT(prop.text == NULL); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
46 | CX_TEST_ASSERT(prop.buf == NULL); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
47 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
48 | cxPropertiesDestroy(&prop); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
49 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
50 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
51 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
52 | CX_TEST(test_cx_properties_next) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
53 | const char *tests[] = { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
54 | "name = value\n", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
55 | "name=value\n", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
56 | "n=value\n", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
57 | "name=v\n", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
58 | "n=v\n", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
59 | "name = value # comment\n", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
60 | "#comment\nn=v\n", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
61 | "# comment1\n# comment2\n\n \n\nname = value\n", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
62 | " name = value\n", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
63 | "name = value\n\n" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
64 | }; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
65 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
66 | const char *keys[] = { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
67 | "name", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
68 | "name", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
69 | "n", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
70 | "name", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
71 | "n", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
72 | "name", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
73 | "n", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
74 | "name", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
75 | "name", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
76 | "name" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
77 | }; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
78 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
79 | const char *values[] = { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
80 | "value", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
81 | "value", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
82 | "value", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
83 | "v", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
84 | "v", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
85 | "value", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
86 | "v", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
87 | "value", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
88 | "value", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
89 | "value" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
90 | }; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
91 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
92 | CxProperties prop; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
93 | cxPropertiesInitDefault(&prop); |
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
94 | CxPropertiesStatus result; |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
95 | cxstring key; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
96 | cxstring value; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
97 | CX_TEST_DO { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
98 | for (int i = 0; i < 10; i++) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
99 | cxPropertiesInput(&prop, tests[i], strlen(tests[i])); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
100 | CX_TEST_ASSERT(prop.text == tests[i]); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
101 | CX_TEST_ASSERT(prop.text_size == strlen(tests[i])); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
102 | CX_TEST_ASSERT(prop.text_pos == 0); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
103 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
104 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
105 | cxstring k = cx_str(keys[i]); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
106 | cxstring v = cx_str(values[i]); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
107 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
108 | CX_TEST_ASSERT(0 == cx_strcmp(key, k)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
109 | CX_TEST_ASSERT(0 == cx_strcmp(value, v)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
110 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
111 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
112 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
113 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
114 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
115 | cxPropertiesDestroy(&prop); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
116 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
117 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
118 | CX_TEST(test_cx_properties_next_multi) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
119 | const char *keys[] = { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
120 | "a", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
121 | "b", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
122 | "c", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
123 | "uap", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
124 | "name", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
125 | "key1", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
126 | "key2", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
127 | "key3" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
128 | }; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
129 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
130 | const char *values[] = { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
131 | "a value", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
132 | "b value", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
133 | "core", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
134 | "core", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
135 | "ucx", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
136 | "value1", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
137 | "value2", |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
138 | "value3" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
139 | }; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
140 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
141 | const char *str = "#\n" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
142 | "# properties\n" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
143 | "# contains key/value pairs\n" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
144 | "#\n" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
145 | "a = a value\n" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
146 | "b = b value\n" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
147 | "c = core\n" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
148 | "\n# test\n" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
149 | "uap = core\n" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
150 | "name = ucx\n" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
151 | "# no = property\n" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
152 | "key1 = value1\n" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
153 | "#key1 = wrong value\n" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
154 | "#key2 = not value 2\n" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
155 | "key2 = value2\n" |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
156 | "\n\n\n \n key3=value3\n"; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
157 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
158 | CxProperties prop; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
159 | cxPropertiesInitDefault(&prop); |
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
160 | CxPropertiesStatus result; |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
161 | cxstring key; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
162 | cxstring value; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
163 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
164 | CX_TEST_DO { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
165 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
166 | CX_TEST_ASSERT(result == CX_PROPERTIES_NULL_INPUT); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
167 | cxPropertiesInput(&prop, str, strlen(str)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
168 | for (int i = 0; i < 8; i++) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
169 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
170 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
171 | CX_TEST_ASSERT(!cx_strcmp(key, cx_str(keys[i]))); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
172 | CX_TEST_ASSERT(!cx_strcmp(value, cx_str(values[i]))); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
173 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
174 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
175 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
176 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
177 | cxPropertiesDestroy(&prop); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
178 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
179 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
180 | CX_TEST(test_cx_properties_next_part) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
181 | CxProperties prop; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
182 | cxPropertiesInitDefault(&prop); |
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
183 | CxPropertiesStatus result; |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
184 | cxstring key; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
185 | cxstring value; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
186 | const char *str; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
187 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
188 | CX_TEST_DO { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
189 | str = ""; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
190 | cxPropertiesFill(&prop, str, strlen(str)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
191 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
192 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
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 | str = " \n"; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
195 | cxPropertiesFill(&prop, str, strlen(str)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
196 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
197 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
198 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
199 | str = "name"; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
200 | cxPropertiesFill(&prop, str, strlen(str)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
201 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
202 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
203 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
204 | str = " "; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
205 | cxPropertiesFill(&prop, str, strlen(str)); |
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_INCOMPLETE_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 | // call fill twice in a row |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
210 | str = "= "; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
211 | cxPropertiesFill(&prop, str, strlen(str)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
212 | str = "value"; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
213 | cxPropertiesFill(&prop, str, strlen(str)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
214 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
215 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
216 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
217 | str = "\n"; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
218 | cxPropertiesFill(&prop, str, strlen(str)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
219 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
220 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
221 | 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
|
222 | 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
|
223 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
224 | // second round |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
225 | str = "#comment\n"; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
226 | cxPropertiesFill(&prop, str, strlen(str)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
227 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
228 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
229 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
230 | str = "#comment\nname2 = "; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
231 | cxPropertiesFill(&prop, str, strlen(str)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
232 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
233 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
234 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
235 | str = "value2\na = b\n"; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
236 | cxPropertiesFill(&prop, str, strlen(str)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
237 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
238 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
239 | 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
|
240 | 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
|
241 | |
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_ERROR); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
244 | 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
|
245 | 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
|
246 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
247 | str = "# comment\n#\n#\ntests = "; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
248 | cxPropertiesFill(&prop, str, strlen(str)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
249 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
250 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
251 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
252 | str = "test1 "; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
253 | cxPropertiesFill(&prop, str, strlen(str)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
254 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
255 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
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 | str = "test2 test3 test4\n"; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
258 | cxPropertiesFill(&prop, str, strlen(str)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
259 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
260 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
261 | 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
|
262 | 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
|
263 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
264 | // 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
|
265 | str = "# just a comment"; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
266 | cxPropertiesFill(&prop, str, strlen(str)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
267 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
268 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
269 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
270 | str = " in 3"; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
271 | cxPropertiesFill(&prop, str, strlen(str)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
272 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
273 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
274 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
275 | str = " parts\nx = 1\n"; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
276 | cxPropertiesFill(&prop, str, strlen(str)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
277 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
278 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
279 | 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
|
280 | CX_TEST_ASSERT(0 == cx_strcmp(value, cx_str("1"))); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
281 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
282 | // finally we are done |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
283 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
284 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
285 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
286 | cxPropertiesDestroy(&prop); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
287 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
288 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
289 | CX_TEST(test_ucx_properties_next_long_lines) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
290 | CxProperties prop; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
291 | cxPropertiesInitDefault(&prop); |
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
292 | CxPropertiesStatus result; |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
293 | cxstring key; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
294 | cxstring value; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
295 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
296 | size_t key_len = 512; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
297 | char *long_key = (char*)malloc(key_len); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
298 | memset(long_key, 'a', 70); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
299 | memset(long_key + 70, 'b', 242); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
300 | memset(long_key + 312, 'c', 200); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
301 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
302 | size_t value_len = 2048; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
303 | char *long_value = (char*)malloc(value_len); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
304 | memset(long_value, 'x', 1024); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
305 | memset(long_value+1024, 'y', 1024); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
306 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
307 | CX_TEST_DO { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
308 | cxPropertiesFill(&prop, long_key, 10); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
309 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
310 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
311 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
312 | cxPropertiesFill(&prop, long_key + 10, 202); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
313 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
314 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
315 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
316 | cxPropertiesFill(&prop, long_key + 212, 200); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
317 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
318 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
319 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
320 | cxPropertiesFill(&prop, long_key + 412, 100); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
321 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
322 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
323 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
324 | const char *str = " = "; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
325 | cxPropertiesFill(&prop, str, strlen(str)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
326 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
327 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
328 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
329 | cxPropertiesFill(&prop, long_value, 512); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
330 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
331 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
332 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
333 | cxPropertiesFill(&prop, long_value + 512, 1024); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
334 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
335 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
336 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
337 | cxPropertiesFill(&prop, long_value + 1536, 512); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
338 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
339 | CX_TEST_ASSERT(result == CX_PROPERTIES_INCOMPLETE_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
340 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
341 | str = "\n#comment\nkey = value\n"; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
342 | cxPropertiesFill(&prop, str, strlen(str)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
343 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
344 | cxstring k = cx_strn(long_key, key_len); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
345 | cxstring v = cx_strn(long_value, value_len); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
346 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
347 | CX_TEST_ASSERT(0 == cx_strcmp(key, k)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
348 | CX_TEST_ASSERT(0 == cx_strcmp(value, v)); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
349 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
350 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
351 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_ERROR); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
352 | 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
|
353 | 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
|
354 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
355 | result = cxPropertiesNext(&prop, &key, &value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
356 | CX_TEST_ASSERT(result == CX_PROPERTIES_NO_DATA); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
357 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
358 | CX_TEST_ASSERT(prop.buf != NULL); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
359 | CX_TEST_ASSERT(prop.buf_capacity > 0); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
360 | CX_TEST_ASSERT(prop.buf_size == 0); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
361 | cxPropertiesDestroy(&prop); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
362 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
363 | CX_TEST_ASSERT(prop.buf == NULL); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
364 | CX_TEST_ASSERT(prop.buf_capacity == 0); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
365 | CX_TEST_ASSERT(prop.buf_size == 0); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
366 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
367 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
368 | free(long_key); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
369 | free(long_value); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
370 | } |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
371 | |
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
372 | CX_TEST(test_cx_properties_load_string_to_map) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
373 | CxTestingAllocator talloc; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
374 | cx_testing_allocator_init(&talloc); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
375 | CxAllocator *alloc = &talloc.base; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
376 | CX_TEST_DO { |
929
192a440b99df
fix totally bugged assertion in cxPropertiesUseStack()
Mike Becker <universe@uap-core.de>
parents:
928
diff
changeset
|
377 | char buffer[512]; |
192a440b99df
fix totally bugged assertion in cxPropertiesUseStack()
Mike Becker <universe@uap-core.de>
parents:
928
diff
changeset
|
378 | CxProperties prop; |
192a440b99df
fix totally bugged assertion in cxPropertiesUseStack()
Mike Becker <universe@uap-core.de>
parents:
928
diff
changeset
|
379 | cxPropertiesInitDefault(&prop); |
192a440b99df
fix totally bugged assertion in cxPropertiesUseStack()
Mike Becker <universe@uap-core.de>
parents:
928
diff
changeset
|
380 | cxPropertiesUseStack(&prop, buffer, 512); |
192a440b99df
fix totally bugged assertion in cxPropertiesUseStack()
Mike Becker <universe@uap-core.de>
parents:
928
diff
changeset
|
381 | |
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
382 | const char *str = "key1 = value1\nkey2 = value2\n\n#comment\n\nkey3 = value3\n"; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
383 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
384 | CxMap *map = cxHashMapCreateSimple(CX_STORE_POINTERS); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
385 | cxDefineAdvancedDestructor(map, cxFree, alloc); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
386 | CxPropertiesSink sink = cxPropertiesMapSink(map); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
387 | sink.data = alloc; // use the testing allocator |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
388 | CxPropertiesSource src = cxPropertiesCstrSource(str); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
389 | CxPropertiesStatus status = cxPropertiesLoad(&prop, sink, src); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
390 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
391 | 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
|
392 | CX_TEST_ASSERT(cxMapSize(map) == 3); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
393 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
394 | char *v1 = cxMapGet(map, "key1"); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
395 | char *v2 = cxMapGet(map, "key2"); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
396 | char *v3 = cxMapGet(map, "key3"); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
397 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
398 | 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
|
399 | 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
|
400 | 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
|
401 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
402 | 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
|
403 | 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
|
404 | 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
|
405 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
406 | // second test |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
407 | cxMapClear(map); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
408 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
409 | str = "\n#comment\n"; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
410 | src = cxPropertiesCstrnSource(str, strlen(str)); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
411 | status = cxPropertiesLoad(&prop, sink, src); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
412 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
413 | CX_TEST_ASSERT(status == CX_PROPERTIES_NO_DATA); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
414 | CX_TEST_ASSERT(cxMapSize(map) == 0); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
415 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
416 | str = "key1 = value1\nsyntax error line\n"; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
417 | src = cxPropertiesStringSource(cx_str(str)); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
418 | status = cxPropertiesLoad(&prop, sink, src); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
419 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
420 | CX_TEST_ASSERT(status == CX_PROPERTIES_INVALID_MISSING_DELIMITER); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
421 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
422 | // the successfully read k/v-pair is in the map, nevertheless |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
423 | CX_TEST_ASSERT(cxMapSize(map) == 1); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
424 | char *v = cxMapGet(map, "key1"); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
425 | CX_TEST_ASSERT(!strcmp(v, "value1")); |
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 | cxMapDestroy(map); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
428 | cxPropertiesDestroy(&prop); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
429 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
430 | CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
431 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
432 | cx_testing_allocator_destroy(&talloc); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
433 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
434 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
435 | CX_TEST(test_cx_properties_load_file_to_map) { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
436 | CxTestingAllocator talloc; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
437 | cx_testing_allocator_init(&talloc); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
438 | CxAllocator *alloc = &talloc.base; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
439 | CX_TEST_DO { |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
440 | FILE *f = tmpfile(); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
441 | 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
|
442 | 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
|
443 | 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
|
444 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
445 | size_t key_len = 512; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
446 | 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
|
447 | memset(long_key, 'k', 512); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
448 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
449 | size_t value_len = 2048; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
450 | 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
|
451 | memset(long_value, 'v', 2048); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
452 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
453 | 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
|
454 | fprintf(f, " = "); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
455 | 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
|
456 | fprintf(f, " \n"); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
457 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
458 | fprintf(f, "\n\n\n\nlast_key = property value\n"); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
459 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
460 | fflush(f); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
461 | fseek(f, 0, SEEK_SET); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
462 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
463 | // preparation of test file complete |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
464 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
465 | CxMap *map = cxHashMapCreateSimple(CX_STORE_POINTERS); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
466 | cxDefineAdvancedDestructor(map, cxFree, alloc); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
467 | CxProperties prop; |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
468 | cxPropertiesInitDefault(&prop); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
469 | CxPropertiesSink sink = cxPropertiesMapSink(map); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
470 | sink.data = alloc; // use the testing allocator |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
471 | CxPropertiesSource src = cxPropertiesFileSource(f, 512); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
472 | CxPropertiesStatus status = cxPropertiesLoad(&prop, sink, src); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
473 | fclose(f); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
474 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
475 | 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
|
476 | 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
|
477 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
478 | char *v1 = cxMapGet(map, "key1"); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
479 | 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
|
480 | char *v3 = cxMapGet(map, "key3"); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
481 | 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
|
482 | 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
|
483 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
484 | 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
|
485 | 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
|
486 | 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
|
487 | 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
|
488 | 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
|
489 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
490 | 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
|
491 | 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
|
492 | 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
|
493 | 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
|
494 | cxstring actual = cx_str(lv); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
495 | 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
|
496 | 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
|
497 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
498 | free(long_key); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
499 | free(long_value); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
500 | cxMapDestroy(map); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
501 | cxPropertiesDestroy(&prop); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
502 | |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
503 | CX_TEST_ASSERT(cx_testing_allocator_verify(&talloc)); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
504 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
505 | cx_testing_allocator_destroy(&talloc); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
506 | } |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
507 | |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
508 | CxTestSuite *cx_test_suite_properties(void) { |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
509 | CxTestSuite *suite = cx_test_suite_new("properties"); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
510 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
511 | cx_test_register(suite, test_cx_properties_init); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
512 | cx_test_register(suite, test_cx_properties_next); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
513 | cx_test_register(suite, test_cx_properties_next_multi); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
514 | cx_test_register(suite, test_cx_properties_next_part); |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
515 | cx_test_register(suite, test_ucx_properties_next_long_lines); |
928
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
516 | cx_test_register(suite, test_cx_properties_load_string_to_map); |
d2d42cb1d59e
add source/sink facility for properties - fixes #430
Mike Becker <universe@uap-core.de>
parents:
924
diff
changeset
|
517 | cx_test_register(suite, test_cx_properties_load_file_to_map); |
924
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
518 | |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
519 | return suite; |
3c90dfc35f06
add implementation for the properties parser
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
520 | } |