diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/util/test_configuration.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/util/test_configuration.c')
-rw-r--r-- | src/util/test_configuration.c | 605 |
1 files changed, 304 insertions, 301 deletions
diff --git a/src/util/test_configuration.c b/src/util/test_configuration.c index b5b1e238c..c3a773ab6 100644 --- a/src/util/test_configuration.c +++ b/src/util/test_configuration.c | |||
@@ -28,7 +28,8 @@ | |||
28 | 28 | ||
29 | 29 | ||
30 | /* Test Configuration Diffs Options */ | 30 | /* Test Configuration Diffs Options */ |
31 | enum { | 31 | enum |
32 | { | ||
32 | EDIT_NOTHING, | 33 | EDIT_NOTHING, |
33 | EDIT_SECTION, | 34 | EDIT_SECTION, |
34 | EDIT_ALL, | 35 | EDIT_ALL, |
@@ -43,7 +44,8 @@ enum { | |||
43 | static struct GNUNET_CONFIGURATION_Handle *cfg; | 44 | static struct GNUNET_CONFIGURATION_Handle *cfg; |
44 | static struct GNUNET_CONFIGURATION_Handle *cfg_default; | 45 | static struct GNUNET_CONFIGURATION_Handle *cfg_default; |
45 | 46 | ||
46 | struct DiffsCBData { | 47 | struct DiffsCBData |
48 | { | ||
47 | struct GNUNET_CONFIGURATION_Handle *cfg; | 49 | struct GNUNET_CONFIGURATION_Handle *cfg; |
48 | struct GNUNET_CONFIGURATION_Handle *cfgDiffs; | 50 | struct GNUNET_CONFIGURATION_Handle *cfgDiffs; |
49 | const char *section; | 51 | const char *section; |
@@ -53,7 +55,7 @@ struct DiffsCBData { | |||
53 | 55 | ||
54 | 56 | ||
55 | static void | 57 | static void |
56 | initDiffsCBData(struct DiffsCBData *cbData) | 58 | initDiffsCBData (struct DiffsCBData *cbData) |
57 | { | 59 | { |
58 | cbData->section = NULL; | 60 | cbData->section = NULL; |
59 | cbData->cfg = NULL; | 61 | cbData->cfg = NULL; |
@@ -68,136 +70,136 @@ initDiffsCBData(struct DiffsCBData *cbData) | |||
68 | * and comparing configuration | 70 | * and comparing configuration |
69 | */ | 71 | */ |
70 | static void | 72 | static void |
71 | diffsCallBack(void *cls, const char *section, const char *option, | 73 | diffsCallBack (void *cls, const char *section, const char *option, |
72 | const char *value) | 74 | const char *value) |
73 | { | 75 | { |
74 | struct DiffsCBData *cbData = cls; | 76 | struct DiffsCBData *cbData = cls; |
75 | int cbOption = cbData->callBackOption; | 77 | int cbOption = cbData->callBackOption; |
76 | 78 | ||
77 | switch (cbOption) | 79 | switch (cbOption) |
80 | { | ||
81 | case EDIT_SECTION: | ||
82 | if (NULL == cbData->section) | ||
83 | cbData->section = section; | ||
84 | if (strcmp (cbData->section, section) == 0) | ||
78 | { | 85 | { |
79 | case EDIT_SECTION: | 86 | GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option, |
80 | if (NULL == cbData->section) | 87 | "new-value"); |
81 | cbData->section = section; | 88 | GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, option, |
82 | if (strcmp(cbData->section, section) == 0) | 89 | "new-value"); |
83 | { | 90 | } |
84 | GNUNET_CONFIGURATION_set_value_string(cbData->cfg, section, option, | 91 | break; |
85 | "new-value"); | ||
86 | GNUNET_CONFIGURATION_set_value_string(cbData->cfgDiffs, section, option, | ||
87 | "new-value"); | ||
88 | } | ||
89 | break; | ||
90 | 92 | ||
91 | case EDIT_ALL: | 93 | case EDIT_ALL: |
92 | GNUNET_CONFIGURATION_set_value_string(cbData->cfg, section, option, | 94 | GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, option, |
93 | "new-value"); | 95 | "new-value"); |
94 | GNUNET_CONFIGURATION_set_value_string(cbData->cfgDiffs, section, option, | 96 | GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, option, |
95 | "new-value"); | 97 | "new-value"); |
96 | break; | 98 | break; |
97 | 99 | ||
98 | case ADD_NEW_ENTRY: | 100 | case ADD_NEW_ENTRY: |
99 | { | 101 | { |
100 | static int hit = 0; | 102 | static int hit = 0; |
101 | 103 | ||
102 | if (hit == 0) | 104 | if (hit == 0) |
103 | { | 105 | { |
104 | hit = 1; | 106 | hit = 1; |
105 | GNUNET_CONFIGURATION_set_value_string(cbData->cfg, section, "new-key", | 107 | GNUNET_CONFIGURATION_set_value_string (cbData->cfg, section, "new-key", |
106 | "new-value"); | 108 | "new-value"); |
107 | GNUNET_CONFIGURATION_set_value_string(cbData->cfgDiffs, section, | 109 | GNUNET_CONFIGURATION_set_value_string (cbData->cfgDiffs, section, |
108 | "new-key", "new-value"); | 110 | "new-key", "new-value"); |
109 | } | 111 | } |
110 | break; | 112 | break; |
111 | } | 113 | } |
112 | 114 | ||
113 | case COMPARE: | 115 | case COMPARE: |
114 | { | 116 | { |
115 | int ret; | 117 | int ret; |
116 | char *diffValue; | 118 | char *diffValue; |
117 | 119 | ||
118 | diffValue = NULL; | 120 | diffValue = NULL; |
119 | ret = | 121 | ret = |
120 | GNUNET_CONFIGURATION_get_value_string(cbData->cfgDiffs, section, | 122 | GNUNET_CONFIGURATION_get_value_string (cbData->cfgDiffs, section, |
121 | option, &diffValue); | 123 | option, &diffValue); |
122 | if (NULL != diffValue) | 124 | if (NULL != diffValue) |
123 | { | 125 | { |
124 | if (ret == GNUNET_SYSERR || strcmp(diffValue, value) != 0) | 126 | if ((ret == GNUNET_SYSERR) ||(strcmp (diffValue, value) != 0) ) |
125 | cbData->status = 1; | 127 | cbData->status = 1; |
126 | } | 128 | } |
127 | else | 129 | else |
128 | cbData->status = 1; | 130 | cbData->status = 1; |
129 | GNUNET_free_non_null(diffValue); | 131 | GNUNET_free_non_null (diffValue); |
130 | break; | 132 | break; |
131 | } | 133 | } |
132 | 134 | ||
133 | #if 0 | 135 | #if 0 |
134 | case PRINT: | 136 | case PRINT: |
135 | if (NULL == cbData->section) | 137 | if (NULL == cbData->section) |
136 | { | 138 | { |
137 | cbData->section = section; | 139 | cbData->section = section; |
138 | printf("\nSection: %s\n", section); | 140 | printf ("\nSection: %s\n", section); |
139 | } | ||
140 | else if (strcmp(cbData->section, section) != 0) | ||
141 | { | ||
142 | cbData->section = section; | ||
143 | printf("\nSection: %s\n", section); | ||
144 | } | ||
145 | printf("%s = %s\n", option, value); | ||
146 | #endif | ||
147 | default: | ||
148 | break; | ||
149 | } | 141 | } |
142 | else if (strcmp (cbData->section, section) != 0) | ||
143 | { | ||
144 | cbData->section = section; | ||
145 | printf ("\nSection: %s\n", section); | ||
146 | } | ||
147 | printf ("%s = %s\n", option, value); | ||
148 | #endif | ||
149 | default: | ||
150 | break; | ||
151 | } | ||
150 | } | 152 | } |
151 | 153 | ||
152 | 154 | ||
153 | static struct GNUNET_CONFIGURATION_Handle * | 155 | static struct GNUNET_CONFIGURATION_Handle * |
154 | editConfiguration(struct GNUNET_CONFIGURATION_Handle *cfg, int option) | 156 | editConfiguration (struct GNUNET_CONFIGURATION_Handle *cfg, int option) |
155 | { | 157 | { |
156 | struct DiffsCBData diffsCB; | 158 | struct DiffsCBData diffsCB; |
157 | 159 | ||
158 | initDiffsCBData(&diffsCB); | 160 | initDiffsCBData (&diffsCB); |
159 | diffsCB.cfgDiffs = GNUNET_CONFIGURATION_create(); | 161 | diffsCB.cfgDiffs = GNUNET_CONFIGURATION_create (); |
160 | 162 | ||
161 | switch (option) | 163 | switch (option) |
162 | { | 164 | { |
163 | case EDIT_SECTION: | 165 | case EDIT_SECTION: |
164 | case EDIT_ALL: | 166 | case EDIT_ALL: |
165 | case ADD_NEW_ENTRY: | 167 | case ADD_NEW_ENTRY: |
166 | diffsCB.callBackOption = option; | 168 | diffsCB.callBackOption = option; |
167 | diffsCB.cfg = cfg; | 169 | diffsCB.cfg = cfg; |
168 | GNUNET_CONFIGURATION_iterate(cfg, diffsCallBack, &diffsCB); | 170 | GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &diffsCB); |
169 | break; | 171 | break; |
170 | 172 | ||
171 | case EDIT_NOTHING: | 173 | case EDIT_NOTHING: |
172 | /* Do nothing */ | 174 | /* Do nothing */ |
173 | break; | 175 | break; |
174 | 176 | ||
175 | case ADD_NEW_SECTION: | 177 | case ADD_NEW_SECTION: |
176 | { | 178 | { |
177 | int i; | 179 | int i; |
178 | char *key; | 180 | char *key; |
179 | 181 | ||
180 | for (i = 0; i < 5; i++) | 182 | for (i = 0; i < 5; i++) |
181 | { | 183 | { |
182 | GNUNET_asprintf(&key, "key%d", i); | 184 | GNUNET_asprintf (&key, "key%d", i); |
183 | GNUNET_CONFIGURATION_set_value_string(cfg, "new-section", key, | 185 | GNUNET_CONFIGURATION_set_value_string (cfg, "new-section", key, |
184 | "new-value"); | 186 | "new-value"); |
185 | GNUNET_CONFIGURATION_set_value_string(diffsCB.cfgDiffs, "new-section", | 187 | GNUNET_CONFIGURATION_set_value_string (diffsCB.cfgDiffs, "new-section", |
186 | key, "new-value"); | 188 | key, "new-value"); |
187 | GNUNET_free(key); | 189 | GNUNET_free (key); |
188 | } | 190 | } |
189 | break; | 191 | break; |
190 | } | 192 | } |
191 | 193 | ||
192 | case REMOVE_SECTION: | 194 | case REMOVE_SECTION: |
193 | break; | 195 | break; |
194 | 196 | ||
195 | case REMOVE_ENTRY: | 197 | case REMOVE_ENTRY: |
196 | break; | 198 | break; |
197 | 199 | ||
198 | default: | 200 | default: |
199 | break; | 201 | break; |
200 | } | 202 | } |
201 | 203 | ||
202 | return diffsCB.cfgDiffs; | 204 | return diffsCB.cfgDiffs; |
203 | } | 205 | } |
@@ -206,7 +208,7 @@ editConfiguration(struct GNUNET_CONFIGURATION_Handle *cfg, int option) | |||
206 | * Checking configuration diffs | 208 | * Checking configuration diffs |
207 | */ | 209 | */ |
208 | static int | 210 | static int |
209 | checkDiffs(struct GNUNET_CONFIGURATION_Handle *cfg_default, int option) | 211 | checkDiffs (struct GNUNET_CONFIGURATION_Handle *cfg_default, int option) |
210 | { | 212 | { |
211 | struct GNUNET_CONFIGURATION_Handle *cfg; | 213 | struct GNUNET_CONFIGURATION_Handle *cfg; |
212 | struct GNUNET_CONFIGURATION_Handle *cfgDiffs; | 214 | struct GNUNET_CONFIGURATION_Handle *cfgDiffs; |
@@ -214,135 +216,136 @@ checkDiffs(struct GNUNET_CONFIGURATION_Handle *cfg_default, int option) | |||
214 | int ret; | 216 | int ret; |
215 | char *diffsFileName; | 217 | char *diffsFileName; |
216 | 218 | ||
217 | initDiffsCBData(&cbData); | 219 | initDiffsCBData (&cbData); |
218 | 220 | ||
219 | cfg = GNUNET_CONFIGURATION_create(); | 221 | cfg = GNUNET_CONFIGURATION_create (); |
220 | /* load defaults */ | 222 | /* load defaults */ |
221 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_load(cfg, NULL)); | 223 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, NULL)); |
222 | 224 | ||
223 | /* Modify configuration and save it */ | 225 | /* Modify configuration and save it */ |
224 | cfgDiffs = editConfiguration(cfg, option); | 226 | cfgDiffs = editConfiguration (cfg, option); |
225 | diffsFileName = GNUNET_DISK_mktemp("gnunet-test-configurations-diffs.conf"); | 227 | diffsFileName = GNUNET_DISK_mktemp ("gnunet-test-configurations-diffs.conf"); |
226 | if (diffsFileName == NULL) | 228 | if (diffsFileName == NULL) |
227 | { | 229 | { |
228 | GNUNET_break(0); | 230 | GNUNET_break (0); |
229 | GNUNET_CONFIGURATION_destroy(cfg); | 231 | GNUNET_CONFIGURATION_destroy (cfg); |
230 | GNUNET_CONFIGURATION_destroy(cfgDiffs); | 232 | GNUNET_CONFIGURATION_destroy (cfgDiffs); |
231 | return 1; | 233 | return 1; |
232 | } | 234 | } |
233 | GNUNET_CONFIGURATION_write_diffs(cfg_default, cfg, diffsFileName); | 235 | GNUNET_CONFIGURATION_write_diffs (cfg_default, cfg, diffsFileName); |
234 | GNUNET_CONFIGURATION_destroy(cfg); | 236 | GNUNET_CONFIGURATION_destroy (cfg); |
235 | 237 | ||
236 | /* Compare the dumped configuration with modifications done */ | 238 | /* Compare the dumped configuration with modifications done */ |
237 | cfg = GNUNET_CONFIGURATION_create(); | 239 | cfg = GNUNET_CONFIGURATION_create (); |
238 | GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_parse(cfg, diffsFileName)); | 240 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_parse (cfg, diffsFileName)); |
239 | if (0 != remove(diffsFileName)) | 241 | if (0 != remove (diffsFileName)) |
240 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "remove", diffsFileName); | 242 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "remove", |
243 | diffsFileName); | ||
241 | cbData.callBackOption = COMPARE; | 244 | cbData.callBackOption = COMPARE; |
242 | cbData.cfgDiffs = cfgDiffs; | 245 | cbData.cfgDiffs = cfgDiffs; |
243 | GNUNET_CONFIGURATION_iterate(cfg, diffsCallBack, &cbData); | 246 | GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &cbData); |
244 | if (1 == (ret = cbData.status)) | 247 | if (1 == (ret = cbData.status)) |
245 | { | 248 | { |
246 | fprintf(stderr, "%s", | 249 | fprintf (stderr, "%s", |
247 | "Incorrect Configuration Diffs: Diffs may contain data not actually edited\n"); | 250 | "Incorrect Configuration Diffs: Diffs may contain data not actually edited\n"); |
248 | goto housekeeping; | 251 | goto housekeeping; |
249 | } | 252 | } |
250 | cbData.cfgDiffs = cfg; | 253 | cbData.cfgDiffs = cfg; |
251 | GNUNET_CONFIGURATION_iterate(cfgDiffs, diffsCallBack, &cbData); | 254 | GNUNET_CONFIGURATION_iterate (cfgDiffs, diffsCallBack, &cbData); |
252 | if ((ret = cbData.status) == 1) | 255 | if ((ret = cbData.status) == 1) |
253 | fprintf(stderr, "%s", | 256 | fprintf (stderr, "%s", |
254 | "Incorrect Configuration Diffs: Data may be missing in diffs\n"); | 257 | "Incorrect Configuration Diffs: Data may be missing in diffs\n"); |
255 | 258 | ||
256 | housekeeping: | 259 | housekeeping: |
257 | #if 0 | 260 | #if 0 |
258 | cbData.section = NULL; | 261 | cbData.section = NULL; |
259 | cbData.callBackOption = PRINT; | 262 | cbData.callBackOption = PRINT; |
260 | printf("\nExpected Diffs:\n"); | 263 | printf ("\nExpected Diffs:\n"); |
261 | GNUNET_CONFIGURATION_iterate(cfgDiffs, diffsCallBack, &cbData); | 264 | GNUNET_CONFIGURATION_iterate (cfgDiffs, diffsCallBack, &cbData); |
262 | cbData.section = NULL; | 265 | cbData.section = NULL; |
263 | printf("\nActual Diffs:\n"); | 266 | printf ("\nActual Diffs:\n"); |
264 | GNUNET_CONFIGURATION_iterate(cfg, diffsCallBack, &cbData); | 267 | GNUNET_CONFIGURATION_iterate (cfg, diffsCallBack, &cbData); |
265 | #endif | 268 | #endif |
266 | GNUNET_CONFIGURATION_destroy(cfg); | 269 | GNUNET_CONFIGURATION_destroy (cfg); |
267 | GNUNET_CONFIGURATION_destroy(cfgDiffs); | 270 | GNUNET_CONFIGURATION_destroy (cfgDiffs); |
268 | GNUNET_free(diffsFileName); | 271 | GNUNET_free (diffsFileName); |
269 | return ret; | 272 | return ret; |
270 | } | 273 | } |
271 | 274 | ||
272 | 275 | ||
273 | static int | 276 | static int |
274 | testConfig() | 277 | testConfig () |
275 | { | 278 | { |
276 | char *c; | 279 | char *c; |
277 | unsigned long long l; | 280 | unsigned long long l; |
278 | 281 | ||
279 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, "test", "b", &c)) | 282 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, "test", "b", &c)) |
280 | return 1; | 283 | return 1; |
281 | if (0 != strcmp("b", c)) | 284 | if (0 != strcmp ("b", c)) |
282 | { | 285 | { |
283 | fprintf(stderr, "Got `%s'\n", c); | 286 | fprintf (stderr, "Got `%s'\n", c); |
284 | GNUNET_free(c); | 287 | GNUNET_free (c); |
285 | return 2; | 288 | return 2; |
286 | } | 289 | } |
287 | GNUNET_free(c); | 290 | GNUNET_free (c); |
288 | if (GNUNET_OK != | 291 | if (GNUNET_OK != |
289 | GNUNET_CONFIGURATION_get_value_number(cfg, "test", "five", &l)) | 292 | GNUNET_CONFIGURATION_get_value_number (cfg, "test", "five", &l)) |
290 | { | 293 | { |
291 | GNUNET_break(0); | 294 | GNUNET_break (0); |
292 | return 3; | 295 | return 3; |
293 | } | 296 | } |
294 | if (5 != l) | 297 | if (5 != l) |
295 | { | 298 | { |
296 | GNUNET_break(0); | 299 | GNUNET_break (0); |
297 | return 4; | 300 | return 4; |
298 | } | 301 | } |
299 | GNUNET_CONFIGURATION_set_value_string(cfg, "more", "c", "YES"); | 302 | GNUNET_CONFIGURATION_set_value_string (cfg, "more", "c", "YES"); |
300 | if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_yesno(cfg, "more", "c")) | 303 | if (GNUNET_NO == GNUNET_CONFIGURATION_get_value_yesno (cfg, "more", "c")) |
301 | { | 304 | { |
302 | GNUNET_break(0); | 305 | GNUNET_break (0); |
303 | return 5; | 306 | return 5; |
304 | } | 307 | } |
305 | GNUNET_CONFIGURATION_set_value_number(cfg, "NUMBERS", "TEN", 10); | 308 | GNUNET_CONFIGURATION_set_value_number (cfg, "NUMBERS", "TEN", 10); |
306 | if (GNUNET_OK != | 309 | if (GNUNET_OK != |
307 | GNUNET_CONFIGURATION_get_value_string(cfg, "NUMBERS", "TEN", &c)) | 310 | GNUNET_CONFIGURATION_get_value_string (cfg, "NUMBERS", "TEN", &c)) |
308 | { | 311 | { |
309 | GNUNET_break(0); | 312 | GNUNET_break (0); |
310 | return 6; | 313 | return 6; |
311 | } | 314 | } |
312 | if (0 != strcmp(c, "10")) | 315 | if (0 != strcmp (c, "10")) |
313 | { | 316 | { |
314 | GNUNET_free(c); | 317 | GNUNET_free (c); |
315 | GNUNET_break(0); | 318 | GNUNET_break (0); |
316 | return 7; | 319 | return 7; |
317 | } | 320 | } |
318 | GNUNET_free(c); | 321 | GNUNET_free (c); |
319 | 322 | ||
320 | if (GNUNET_OK != | 323 | if (GNUNET_OK != |
321 | GNUNET_CONFIGURATION_get_value_filename(cfg, "last", "test", &c)) | 324 | GNUNET_CONFIGURATION_get_value_filename (cfg, "last", "test", &c)) |
322 | { | 325 | { |
323 | GNUNET_break(0); | 326 | GNUNET_break (0); |
324 | return 8; | 327 | return 8; |
325 | } | 328 | } |
326 | 329 | ||
327 | if (0 != strcmp(c, "/hello/world")) | 330 | if (0 != strcmp (c, "/hello/world")) |
328 | { | 331 | { |
329 | GNUNET_break(0); | 332 | GNUNET_break (0); |
330 | GNUNET_free(c); | 333 | GNUNET_free (c); |
331 | return 9; | 334 | return 9; |
332 | } | 335 | } |
333 | GNUNET_free(c); | 336 | GNUNET_free (c); |
334 | 337 | ||
335 | if (GNUNET_OK != | 338 | if (GNUNET_OK != |
336 | GNUNET_CONFIGURATION_get_value_size(cfg, "last", "size", &l)) | 339 | GNUNET_CONFIGURATION_get_value_size (cfg, "last", "size", &l)) |
337 | { | 340 | { |
338 | GNUNET_break(0); | 341 | GNUNET_break (0); |
339 | return 10; | 342 | return 10; |
340 | } | 343 | } |
341 | if (l != 512 * 1024) | 344 | if (l != 512 * 1024) |
342 | { | 345 | { |
343 | GNUNET_break(0); | 346 | GNUNET_break (0); |
344 | return 11; | 347 | return 11; |
345 | } | 348 | } |
346 | return 0; | 349 | return 0; |
347 | } | 350 | } |
348 | 351 | ||
@@ -355,198 +358,198 @@ static const char *want[] = { | |||
355 | }; | 358 | }; |
356 | 359 | ||
357 | static int | 360 | static int |
358 | check(void *data, const char *fn) | 361 | check (void *data, const char *fn) |
359 | { | 362 | { |
360 | int *idx = data; | 363 | int *idx = data; |
361 | 364 | ||
362 | if (0 == strcmp(want[*idx], fn)) | 365 | if (0 == strcmp (want[*idx], fn)) |
363 | { | 366 | { |
364 | (*idx)++; | 367 | (*idx)++; |
365 | return GNUNET_OK; | 368 | return GNUNET_OK; |
366 | } | 369 | } |
367 | GNUNET_break(0); | 370 | GNUNET_break (0); |
368 | return GNUNET_SYSERR; | 371 | return GNUNET_SYSERR; |
369 | } | 372 | } |
370 | 373 | ||
371 | static int | 374 | static int |
372 | testConfigFilenames() | 375 | testConfigFilenames () |
373 | { | 376 | { |
374 | int idx; | 377 | int idx; |
375 | 378 | ||
376 | idx = 0; | 379 | idx = 0; |
377 | if (3 != | 380 | if (3 != |
378 | GNUNET_CONFIGURATION_iterate_value_filenames(cfg, "FILENAMES", "test", | 381 | GNUNET_CONFIGURATION_iterate_value_filenames (cfg, "FILENAMES", "test", |
379 | &check, &idx)) | 382 | &check, &idx)) |
380 | { | 383 | { |
381 | GNUNET_break(0); | 384 | GNUNET_break (0); |
382 | return 8; | 385 | return 8; |
383 | } | 386 | } |
384 | if (idx != 3) | 387 | if (idx != 3) |
385 | return 16; | 388 | return 16; |
386 | if (GNUNET_OK != | 389 | if (GNUNET_OK != |
387 | GNUNET_CONFIGURATION_remove_value_filename(cfg, "FILENAMES", "test", | 390 | GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test", |
388 | "/File Name")) | 391 | "/File Name")) |
389 | { | 392 | { |
390 | GNUNET_break(0); | 393 | GNUNET_break (0); |
391 | return 24; | 394 | return 24; |
392 | } | 395 | } |
393 | 396 | ||
394 | if (GNUNET_NO != | 397 | if (GNUNET_NO != |
395 | GNUNET_CONFIGURATION_remove_value_filename(cfg, "FILENAMES", "test", | 398 | GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test", |
396 | "/File Name")) | 399 | "/File Name")) |
397 | { | 400 | { |
398 | GNUNET_break(0); | 401 | GNUNET_break (0); |
399 | return 32; | 402 | return 32; |
400 | } | 403 | } |
401 | if (GNUNET_NO != | 404 | if (GNUNET_NO != |
402 | GNUNET_CONFIGURATION_remove_value_filename(cfg, "FILENAMES", "test", | 405 | GNUNET_CONFIGURATION_remove_value_filename (cfg, "FILENAMES", "test", |
403 | "Stuff")) | 406 | "Stuff")) |
404 | { | 407 | { |
405 | GNUNET_break(0); | 408 | GNUNET_break (0); |
406 | return 40; | 409 | return 40; |
407 | } | 410 | } |
408 | 411 | ||
409 | if (GNUNET_NO != | 412 | if (GNUNET_NO != |
410 | GNUNET_CONFIGURATION_append_value_filename(cfg, "FILENAMES", "test", | 413 | GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test", |
411 | "/Hello")) | 414 | "/Hello")) |
412 | { | 415 | { |
413 | GNUNET_break(0); | 416 | GNUNET_break (0); |
414 | return 48; | 417 | return 48; |
415 | } | 418 | } |
416 | if (GNUNET_NO != | 419 | if (GNUNET_NO != |
417 | GNUNET_CONFIGURATION_append_value_filename(cfg, "FILENAMES", "test", | 420 | GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test", |
418 | "/World")) | 421 | "/World")) |
419 | { | 422 | { |
420 | GNUNET_break(0); | 423 | GNUNET_break (0); |
421 | return 56; | 424 | return 56; |
422 | } | 425 | } |
423 | 426 | ||
424 | if (GNUNET_YES != | 427 | if (GNUNET_YES != |
425 | GNUNET_CONFIGURATION_append_value_filename(cfg, "FILENAMES", "test", | 428 | GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test", |
426 | "/File 1")) | 429 | "/File 1")) |
427 | { | 430 | { |
428 | GNUNET_break(0); | 431 | GNUNET_break (0); |
429 | return 64; | 432 | return 64; |
430 | } | 433 | } |
431 | 434 | ||
432 | if (GNUNET_YES != | 435 | if (GNUNET_YES != |
433 | GNUNET_CONFIGURATION_append_value_filename(cfg, "FILENAMES", "test", | 436 | GNUNET_CONFIGURATION_append_value_filename (cfg, "FILENAMES", "test", |
434 | "/File 2")) | 437 | "/File 2")) |
435 | { | 438 | { |
436 | GNUNET_break(0); | 439 | GNUNET_break (0); |
437 | return 72; | 440 | return 72; |
438 | } | 441 | } |
439 | 442 | ||
440 | idx = 0; | 443 | idx = 0; |
441 | want[1] = "/World"; | 444 | want[1] = "/World"; |
442 | want[2] = "/File 1"; | 445 | want[2] = "/File 1"; |
443 | want[3] = "/File 2"; | 446 | want[3] = "/File 2"; |
444 | if (4 != | 447 | if (4 != |
445 | GNUNET_CONFIGURATION_iterate_value_filenames(cfg, "FILENAMES", "test", | 448 | GNUNET_CONFIGURATION_iterate_value_filenames (cfg, "FILENAMES", "test", |
446 | &check, &idx)) | 449 | &check, &idx)) |
447 | { | 450 | { |
448 | GNUNET_break(0); | 451 | GNUNET_break (0); |
449 | return 80; | 452 | return 80; |
450 | } | 453 | } |
451 | if (idx != 4) | 454 | if (idx != 4) |
452 | { | 455 | { |
453 | GNUNET_break(0); | 456 | GNUNET_break (0); |
454 | return 88; | 457 | return 88; |
455 | } | 458 | } |
456 | return 0; | 459 | return 0; |
457 | } | 460 | } |
458 | 461 | ||
459 | 462 | ||
460 | int | 463 | int |
461 | main(int argc, char *argv[]) | 464 | main (int argc, char *argv[]) |
462 | { | 465 | { |
463 | int failureCount = 0; | 466 | int failureCount = 0; |
464 | char *c; | 467 | char *c; |
465 | 468 | ||
466 | GNUNET_log_setup("test_configuration", "WARNING", NULL); | 469 | GNUNET_log_setup ("test_configuration", "WARNING", NULL); |
467 | cfg = GNUNET_CONFIGURATION_create(); | 470 | cfg = GNUNET_CONFIGURATION_create (); |
468 | GNUNET_assert(cfg != NULL); | 471 | GNUNET_assert (cfg != NULL); |
469 | if (GNUNET_OK != | 472 | if (GNUNET_OK != |
470 | GNUNET_CONFIGURATION_parse(cfg, "test_configuration_data.conf")) | 473 | GNUNET_CONFIGURATION_parse (cfg, "test_configuration_data.conf")) |
471 | { | 474 | { |
472 | fprintf(stderr, "%s", "Failed to parse configuration file\n"); | 475 | fprintf (stderr, "%s", "Failed to parse configuration file\n"); |
473 | GNUNET_CONFIGURATION_destroy(cfg); | 476 | GNUNET_CONFIGURATION_destroy (cfg); |
474 | return 1; | 477 | return 1; |
475 | } | 478 | } |
476 | failureCount += testConfig(); | 479 | failureCount += testConfig (); |
477 | if (failureCount > 0) | 480 | if (failureCount > 0) |
478 | goto error; | 481 | goto error; |
479 | 482 | ||
480 | failureCount = testConfigFilenames(); | 483 | failureCount = testConfigFilenames (); |
481 | if (failureCount > 0) | 484 | if (failureCount > 0) |
482 | goto error; | 485 | goto error; |
483 | 486 | ||
484 | if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg, "/tmp/gnunet-test.conf")) | 487 | if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, "/tmp/gnunet-test.conf")) |
485 | { | 488 | { |
486 | fprintf(stderr, "%s", "Failed to write configuration file\n"); | 489 | fprintf (stderr, "%s", "Failed to write configuration file\n"); |
487 | GNUNET_CONFIGURATION_destroy(cfg); | 490 | GNUNET_CONFIGURATION_destroy (cfg); |
488 | return 1; | 491 | return 1; |
489 | } | 492 | } |
490 | GNUNET_CONFIGURATION_destroy(cfg); | 493 | GNUNET_CONFIGURATION_destroy (cfg); |
491 | GNUNET_assert(0 == unlink("/tmp/gnunet-test.conf")); | 494 | GNUNET_assert (0 == unlink ("/tmp/gnunet-test.conf")); |
492 | 495 | ||
493 | cfg = GNUNET_CONFIGURATION_create(); | 496 | cfg = GNUNET_CONFIGURATION_create (); |
494 | if (GNUNET_OK != | 497 | if (GNUNET_OK != |
495 | GNUNET_CONFIGURATION_load(cfg, "test_configuration_data.conf")) | 498 | GNUNET_CONFIGURATION_load (cfg, "test_configuration_data.conf")) |
496 | { | 499 | { |
497 | GNUNET_break(0); | 500 | GNUNET_break (0); |
498 | GNUNET_CONFIGURATION_destroy(cfg); | 501 | GNUNET_CONFIGURATION_destroy (cfg); |
499 | return 1; | 502 | return 1; |
500 | } | 503 | } |
501 | if (GNUNET_OK != | 504 | if (GNUNET_OK != |
502 | GNUNET_CONFIGURATION_get_value_string(cfg, "TESTING", "WEAKRANDOM", &c)) | 505 | GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "WEAKRANDOM", &c)) |
503 | { | 506 | { |
504 | GNUNET_break(0); | 507 | GNUNET_break (0); |
505 | GNUNET_CONFIGURATION_destroy(cfg); | 508 | GNUNET_CONFIGURATION_destroy (cfg); |
506 | return 1; | 509 | return 1; |
507 | } | 510 | } |
508 | if (0 != strcmp(c, "YES")) | 511 | if (0 != strcmp (c, "YES")) |
509 | { | 512 | { |
510 | GNUNET_break(0); | 513 | GNUNET_break (0); |
511 | GNUNET_free(c); | 514 | GNUNET_free (c); |
512 | GNUNET_CONFIGURATION_destroy(cfg); | 515 | GNUNET_CONFIGURATION_destroy (cfg); |
513 | return 1; | 516 | return 1; |
514 | } | 517 | } |
515 | 518 | ||
516 | GNUNET_free(c); | 519 | GNUNET_free (c); |
517 | GNUNET_CONFIGURATION_destroy(cfg); | 520 | GNUNET_CONFIGURATION_destroy (cfg); |
518 | 521 | ||
519 | /* Testing configuration diffs */ | 522 | /* Testing configuration diffs */ |
520 | cfg_default = GNUNET_CONFIGURATION_create(); | 523 | cfg_default = GNUNET_CONFIGURATION_create (); |
521 | if (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg_default, NULL)) | 524 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg_default, NULL)) |
522 | { | 525 | { |
523 | GNUNET_break(0); | 526 | GNUNET_break (0); |
524 | GNUNET_CONFIGURATION_destroy(cfg_default); | 527 | GNUNET_CONFIGURATION_destroy (cfg_default); |
525 | return 1; | 528 | return 1; |
526 | } | 529 | } |
527 | 530 | ||
528 | /* Nothing changed in the new configuration */ | 531 | /* Nothing changed in the new configuration */ |
529 | failureCount += checkDiffs(cfg_default, EDIT_NOTHING); | 532 | failureCount += checkDiffs (cfg_default, EDIT_NOTHING); |
530 | 533 | ||
531 | /* Modify all entries of the last section */ | 534 | /* Modify all entries of the last section */ |
532 | failureCount += checkDiffs(cfg_default, EDIT_SECTION); | 535 | failureCount += checkDiffs (cfg_default, EDIT_SECTION); |
533 | 536 | ||
534 | /* Add a new section */ | 537 | /* Add a new section */ |
535 | failureCount += checkDiffs(cfg_default, ADD_NEW_SECTION); | 538 | failureCount += checkDiffs (cfg_default, ADD_NEW_SECTION); |
536 | 539 | ||
537 | /* Add a new entry to the last section */ | 540 | /* Add a new entry to the last section */ |
538 | failureCount += checkDiffs(cfg_default, ADD_NEW_ENTRY); | 541 | failureCount += checkDiffs (cfg_default, ADD_NEW_ENTRY); |
539 | 542 | ||
540 | /* Modify all entries in the configuration */ | 543 | /* Modify all entries in the configuration */ |
541 | failureCount += checkDiffs(cfg_default, EDIT_ALL); | 544 | failureCount += checkDiffs (cfg_default, EDIT_ALL); |
542 | 545 | ||
543 | GNUNET_CONFIGURATION_destroy(cfg_default); | 546 | GNUNET_CONFIGURATION_destroy (cfg_default); |
544 | 547 | ||
545 | error: | 548 | error: |
546 | if (failureCount != 0) | 549 | if (failureCount != 0) |
547 | { | 550 | { |
548 | fprintf(stderr, "Test failed: %u\n", failureCount); | 551 | fprintf (stderr, "Test failed: %u\n", failureCount); |
549 | return 1; | 552 | return 1; |
550 | } | 553 | } |
551 | return 0; | 554 | return 0; |
552 | } | 555 | } |