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