0759f70138bec18d193d019e5058087be5ae5422
[strongswan.git] / src / libstrongswan / tests / suites / test_settings.c
1 /*
2 * Copyright (C) 2014 Tobias Brunner
3 * HSR Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "test_suite.h"
17
18 #include <unistd.h>
19
20 #include <settings/settings.h>
21 #include <utils/chunk.h>
22 #include <utils/utils.h>
23 #include <collections/linked_list.h>
24
25 #ifdef WIN32
26 static char *path = "C:\\Windows\\Temp\\strongswan-settings-test";
27 #else
28 static char *path = "/tmp/strongswan-settings-test";
29 #endif
30 static settings_t *settings;
31
32 static void create_settings(chunk_t contents)
33 {
34 ck_assert(chunk_write(contents, path, 0022, TRUE));
35 settings = settings_create(path);
36 }
37
38 START_SETUP(setup_base_config)
39 {
40 create_settings(chunk_from_str(
41 "main {\n"
42 " key1 = val1\n"
43 " # this gets overridden below\n"
44 " key2 = val2\n"
45 " none = \n"
46 " empty = \"\"\n"
47 " sub1 {\n"
48 " key = value\n"
49 " key2 = value2\n"
50 " subsub {\n"
51 " foo = bar\n"
52 " }\n"
53 " # subsub is a section and a value\n"
54 " subsub = section value\n"
55 " }\n"
56 " sub% {\n"
57 " id = %any\n"
58 " }\n"
59 " key2 = with space\n"
60 " key3 = \"string with\\nnewline\"\n"
61 " key4 = \"multi line\n"
62 "string\"\n"
63 " key5 = \"escaped \\\n"
64 "newline\"\n"
65 "}\n"
66 "out = side\n"
67 "other {\n"
68 " key1 = other val\n"
69 " empty {\n"
70 " }\n"
71 "}"));
72 }
73 END_SETUP
74
75 START_TEARDOWN(teardown_config)
76 {
77 settings->destroy(settings);
78 unlink(path);
79 }
80 END_TEARDOWN
81
82 #define verify_string(expected, key, ...) \
83 ck_assert_str_eq(expected, settings->get_str(settings, key, NULL, ##__VA_ARGS__))
84 #define verify_null(key, ...) \
85 ck_assert(!settings->get_str(settings, key, NULL, ##__VA_ARGS__))
86
87 START_TEST(test_get_str)
88 {
89 verify_string("val1", "main.key1");
90 verify_string("val1", "main..key1");
91 verify_string("val1", ".main.key1");
92 verify_string("", "main.empty");
93 verify_string("with space", "main.key2");
94 verify_string("string with\nnewline", "main.key3");
95 verify_string("multi line\nstring", "main.key4");
96 verify_string("escaped newline", "main.key5");
97 verify_string("value", "main.sub1.key");
98 verify_string("value2", "main.sub1.key2");
99 verify_string("bar", "main.sub1.subsub.foo");
100 verify_string("section value", "main.sub1.subsub");
101 verify_string("%any", "main.sub%%.id");
102 verify_string("side", "out");
103 verify_string("other val", "other.key1");
104
105 verify_null("main.none");
106 verify_null("main.key6");
107 verify_null("other.sub");
108 }
109 END_TEST
110
111 enum {
112 KEY1,
113 SUB1
114 } settings_test_enum;
115
116 enum_name_t *test_settings_test_names;
117
118 ENUM_BEGIN(test_settings_test_names, KEY1, SUB1,
119 "key1", "sub1");
120 ENUM_END(test_settings_test_names, SUB1);
121
122 START_TEST(test_get_str_printf)
123 {
124 verify_string("val1", "%s.key1", "main");
125 verify_string("val1", "%s.%s", "main", "key1");
126 verify_string("val1", "%s.%N", "main", test_settings_test_names, KEY1);
127 verify_string("val1", "%s.%s%d", "main", "key", 1);
128 verify_string("bar", "%s.sub1.%s.foo", "main", "subsub");
129 verify_string("bar", "%s.%N.%s.foo", "main", test_settings_test_names, SUB1, "subsub");
130 verify_string("bar", "%s.sub%d.%s.foo", "main", 1, "subsub");
131 verify_string("%any", "%s.sub%%.id", "main");
132
133 /* FIXME: this is a bit inconsistent, while this works */
134 verify_string("value2", "main.%s%u.key2", "sub", 1);
135 /* this won't because no argument is consumed for %u so key1 will be tried
136 * granted, we never actually used any other specifiers, but we should
137 * probably document it at least */
138 verify_null("main.%s%u.key%d", "sub", 1, 2);
139
140 verify_null("%s.%s%d", "main", "key", 6);
141 }
142 END_TEST
143
144 START_TEST(test_set_str)
145 {
146 char *val1, *val2;
147
148 val1 = settings->get_str(settings, "main.key1", NULL);
149 ck_assert_str_eq("val1", val1);
150 settings->set_str(settings, "main.key1", "val");
151 verify_string("val", "main.key1");
152 /* the pointer we got before is still valid */
153 ck_assert_str_eq("val1", val1);
154
155 val2 = settings->get_str(settings, "main.key1", NULL);
156 ck_assert_str_eq("val", val2);
157 settings->set_str(settings, "main.key1", "longer value");
158 verify_string("longer value", "main.key1");
159 /* the pointers we got before are still valid */
160 ck_assert_str_eq("val1", val1);
161 ck_assert_str_eq("val", val2);
162
163 val1 = settings->get_str(settings, "main.key1", NULL);
164 settings->set_str(settings, "main.key1", "longer value");
165 val2 = settings->get_str(settings, "main.key1", NULL);
166 /* setting the same string should should get us the same pointer */
167 ck_assert(val1 == val2);
168
169 settings->set_str(settings, "main", "main val");
170 verify_string("main val", "main");
171 settings->set_str(settings, "main.sub1.new", "added");
172 verify_string("added", "main.sub1.new");
173 settings->set_str(settings, "main.sub2.newsub.foo", "bar");
174 verify_string("bar", "main.sub2.newsub.foo");
175 settings->set_str(settings, "new.newsub.foo", "bar");
176 verify_string("bar", "new.newsub.foo");
177 settings->set_str(settings, "main.key1", NULL);
178 verify_null("main.key1");
179 }
180 END_TEST
181
182 START_TEST(test_set_str_printf)
183 {
184 settings->set_str(settings, "%s.key1", "val", "main");
185 verify_string("val", "main.key1");
186 settings->set_str(settings, "main.%N.new", "added", test_settings_test_names, SUB1);
187 verify_string("added", "main.sub1.new");
188 settings->set_str(settings, "main.%s%d.newsub.%s", "bar", "sub", 2, "foo");
189 verify_string("bar", "main.sub2.newsub.foo");
190 }
191 END_TEST
192
193 START_TEST(test_set_default_str)
194 {
195 settings->set_default_str(settings, "main.key1", "default");
196 verify_string("val1", "main.key1");
197 settings->set_default_str(settings, "main.sub1.new", "added");
198 verify_string("added", "main.sub1.new");
199 settings->set_str(settings, "main.sub1.new", "changed");
200 verify_string("changed", "main.sub1.new");
201 }
202 END_TEST
203
204 START_SETUP(setup_bool_config)
205 {
206 create_settings(chunk_from_str(
207 "main {\n"
208 " key1 = yes\n"
209 " key2 = true\n"
210 " key3 = Enabled\n"
211 " key4 = 1\n"
212 " key5 = no\n"
213 " key6 = FALSE\n"
214 " key7 = disabled\n"
215 " key8 = 0\n"
216 " key9 = 5\n"
217 " empty = \"\"\n"
218 " none = \n"
219 " foo = bar\n"
220 "}"));
221 }
222 END_SETUP
223
224 #define verify_bool(expected, def, key, ...) \
225 ck_assert(expected == settings->get_bool(settings, key, def, ##__VA_ARGS__))
226
227 START_TEST(test_get_bool)
228 {
229 verify_bool(TRUE, FALSE, "main.key1");
230 verify_bool(TRUE, FALSE, "main.key2");
231 verify_bool(TRUE, FALSE, "main.key3");
232 verify_bool(TRUE, FALSE, "main.key4");
233 verify_bool(FALSE, TRUE, "main.key5");
234 verify_bool(FALSE, TRUE, "main.key6");
235 verify_bool(FALSE, TRUE, "main.key7");
236 verify_bool(FALSE, TRUE, "main.key8");
237
238 verify_bool(FALSE, FALSE, "main.empty");
239 verify_bool(TRUE, TRUE, "main.empty");
240 verify_bool(FALSE, FALSE, "main.none");
241 verify_bool(TRUE, TRUE, "main.none");
242 verify_bool(FALSE, FALSE, "main.foo");
243 verify_bool(TRUE, TRUE, "main.foo");
244
245 verify_bool(FALSE, FALSE, "main.key9");
246 verify_bool(TRUE, TRUE, "main.key9");
247 verify_bool(FALSE, FALSE, "main");
248 verify_bool(TRUE, TRUE, "main");
249
250 }
251 END_TEST
252
253 START_TEST(test_set_bool)
254 {
255 settings->set_str(settings, "main.key1", "no");
256 verify_bool(FALSE, TRUE, "main.key1");
257 settings->set_bool(settings, "main.key2", FALSE);
258 verify_bool(FALSE, TRUE, "main.key2");
259 settings->set_str(settings, "main.key3", NULL);
260 verify_bool(FALSE, FALSE, "main.key3");
261 verify_bool(TRUE, TRUE, "main.key3");
262 settings->set_bool(settings, "main.key5", TRUE);
263 verify_bool(TRUE, FALSE, "main.key5");
264 settings->set_bool(settings, "main.new", TRUE);
265 verify_bool(TRUE, FALSE, "main.new");
266 }
267 END_TEST
268
269 START_SETUP(setup_int_config)
270 {
271 create_settings(chunk_from_str(
272 "main {\n"
273 " key1 = 5\n"
274 " key2 = 5.5\n"
275 " key3 = -42\n"
276 " empty = \"\"\n"
277 " none = \n"
278 " foo1 = bar\n"
279 " foo2 = bar13\n"
280 " foo3 = 13bar\n"
281 "}"));
282 }
283 END_SETUP
284
285 #define verify_int(expected, def, key, ...) \
286 ck_assert_int_eq(expected, settings->get_int(settings, key, def, ##__VA_ARGS__))
287
288 START_TEST(test_get_int)
289 {
290 verify_int(5, 0, "main.key1");
291 verify_int(0, 0, "main.key2");
292 verify_int(-42, 0, "main.key3");
293
294 verify_int(11, 11, "main.empty");
295 verify_int(11, 11, "main.none");
296 verify_int(11, 11, "main.foo1");
297 verify_int(11, 11, "main.foo2");
298 verify_int(11, 11, "main.foo3");
299
300 verify_int(13, 13, "main.key4");
301 verify_int(-13, -13, "main");
302 }
303 END_TEST
304
305 START_TEST(test_set_int)
306 {
307 settings->set_str(settings, "main.key1", "13");
308 verify_int(13, 0, "main.key1");
309 settings->set_int(settings, "main.key2", 6);
310 verify_int(6, 0, "main.key2");
311 settings->set_int(settings, "main.key3", -6);
312 verify_int(-6, 0, "main.key3");
313 settings->set_str(settings, "main.key3", NULL);
314 verify_int(15, 15, "main.key3");
315 settings->set_int(settings, "main.new", 314);
316 verify_int(314, 0, "main.new");
317 }
318 END_TEST
319
320 START_TEST(test_value_as_unit64)
321 {
322 test_int_eq(1, settings_value_as_uint64(NULL, 1));
323 test_int_eq(1, settings_value_as_uint64("", 1));
324 test_int_eq(1, settings_value_as_uint64("2a", 1));
325 test_int_eq(1, settings_value_as_uint64("a2", 1));
326 test_int_eq(1, settings_value_as_uint64("2.0", 1));
327
328 test_int_eq(10, settings_value_as_uint64("10", 0));
329 test_int_eq(10, settings_value_as_uint64("010", 0));
330 test_int_eq(16, settings_value_as_uint64("0x010", 0));
331 test_int_eq(0x2a, settings_value_as_uint64("0x2a", 0));
332
333 test_int_eq(0xffffffffffffffffLL, settings_value_as_uint64("0xffffffffffffffff", 0));
334 test_int_eq(0xffffffff00000000LL, settings_value_as_uint64("0xffffffff00000000", 0));
335 test_int_eq(0xffffffff00000000LL, settings_value_as_uint64("18446744069414584320", 0));
336 test_int_eq(0xffffffff00000001LL, settings_value_as_uint64("18446744069414584321", 0));
337 }
338 END_TEST
339
340 START_SETUP(setup_double_config)
341 {
342 create_settings(chunk_from_str(
343 "main {\n"
344 " key1 = 5\n"
345 " key2 = 5.5\n"
346 " key3 = -42\n"
347 " key4 = -42.5\n"
348 " empty = \"\"\n"
349 " none = \n"
350 " foo1 = bar\n"
351 " foo2 = bar13.5\n"
352 " foo3 = 13.5bar\n"
353 "}"));
354 }
355 END_SETUP
356
357 #define verify_double(expected, def, key, ...) \
358 ck_assert(expected == settings->get_double(settings, key, def, ##__VA_ARGS__))
359
360 START_TEST(test_get_double)
361 {
362 verify_double(5, 0, "main.key1");
363 verify_double(5.5, 0, "main.key2");
364 verify_double(-42, 0, "main.key3");
365 verify_double(-42.5, 0, "main.key4");
366
367 verify_double(11.5, 11.5, "main.empty");
368 verify_double(11.5, 11.5, "main.none");
369 verify_double(11.5, 11.5, "main.foo1");
370 verify_double(11.5, 11.5, "main.foo2");
371 verify_double(11.5, 11.5, "main.foo3");
372
373 verify_double(11.5, 11.5, "main.key5");
374 verify_double(-11.5, -11.5, "main");
375 }
376 END_TEST
377
378 START_TEST(test_set_double)
379 {
380 settings->set_str(settings, "main.key1", "5.5");
381 verify_double(5.5, 0, "main.key1");
382 settings->set_double(settings, "main.key2", 13);
383 verify_double(13, 0, "main.key2");
384 settings->set_double(settings, "main.key3", -13.5);
385 verify_double(-13.5, 0, "main.key3");
386 settings->set_double(settings, "main.key4", 11.5);
387 verify_double(11.5, 0, "main.key4");
388 settings->set_str(settings, "main.key4", NULL);
389 verify_double(42.5, 42.5, "main.key4");
390 settings->set_double(settings, "main.new", 3.14);
391 verify_double(3.14, 0, "main.new");
392 }
393 END_TEST
394
395 START_SETUP(setup_time_config)
396 {
397 create_settings(chunk_from_str(
398 "main {\n"
399 " key0 = 5\n"
400 " key1 = 5s\n"
401 " key2 = 5m\n"
402 " key3 = 5 h\n"
403 " key4 = 5\td\n"
404 " empty = \"\"\n"
405 " none = \n"
406 " foo1 = bar\n"
407 " foo2 = bar13\n"
408 " foo3 = 13bar\n"
409 "}"));
410 }
411 END_SETUP
412
413 #define verify_time(expected, def, key, ...) \
414 ck_assert_int_eq(expected, settings->get_time(settings, key, def, ##__VA_ARGS__))
415
416 START_TEST(test_get_time)
417 {
418 verify_time(5, 0, "main.key0");
419 verify_time(5, 0, "main.key1");
420 verify_time(300, 0, "main.key2");
421 verify_time(18000, 0, "main.key3");
422 verify_time(432000, 0, "main.key4");
423
424 verify_time(11, 11, "main.empty");
425 verify_time(11, 11, "main.none");
426 verify_time(11, 11, "main.foo1");
427 verify_time(11, 11, "main.foo2");
428 verify_time(11, 11, "main.foo3");
429
430 verify_time(11, 11, "main.key5");
431 verify_time(11, 11, "main");
432 }
433 END_TEST
434
435 START_TEST(test_set_time)
436 {
437 settings->set_str(settings, "main.key1", "15m");
438 verify_time(900, 0, "main.key1");
439 settings->set_time(settings, "main.key2", 15);
440 verify_time(15, 0, "main.key2");
441 settings->set_str(settings, "main.key3", NULL);
442 verify_time(300, 300, "main.key3");
443 settings->set_time(settings, "main.new", 314);
444 verify_time(314, 0, "main.new");
445 }
446 END_TEST
447
448 static void verify_sections(linked_list_t *verifier, char *parent)
449 {
450 enumerator_t *enumerator, *ver;
451 char *section, *current;
452
453 enumerator = settings->create_section_enumerator(settings, parent);
454 ver = verifier->create_enumerator(verifier);
455 while (enumerator->enumerate(enumerator, &section) &&
456 ver->enumerate(ver, &current))
457 {
458 ck_assert_str_eq(section, current);
459 verifier->remove_at(verifier, ver);
460 }
461 enumerator->destroy(enumerator);
462 ver->destroy(ver);
463 ck_assert_int_eq(0, verifier->get_count(verifier));
464 verifier->destroy(verifier);
465 }
466
467 START_TEST(test_section_enumerator)
468 {
469 linked_list_t *verifier;
470
471 verifier = linked_list_create_with_items("sub1", "sub%", NULL);
472 verify_sections(verifier, "main");
473
474 settings->set_str(settings, "main.sub0.new", "added");
475 verifier = linked_list_create_with_items("sub1", "sub%", "sub0", NULL);
476 verify_sections(verifier, "main");
477
478 verifier = linked_list_create_with_items("subsub", NULL);
479 verify_sections(verifier, "main.sub1");
480
481 verifier = linked_list_create_with_items(NULL);
482 verify_sections(verifier, "main.sub%%");
483
484 verifier = linked_list_create_with_items(NULL);
485 verify_sections(verifier, "main.key1");
486
487 verifier = linked_list_create_with_items(NULL);
488 verify_sections(verifier, "main.unknown");
489 }
490 END_TEST
491
492 static void verify_key_values(linked_list_t *keys, linked_list_t *values,
493 char *parent)
494 {
495 enumerator_t *enumerator, *enum_keys, *enum_values;
496 char *key, *value, *current_key, *current_value;
497
498 enumerator = settings->create_key_value_enumerator(settings, parent);
499 enum_keys = keys->create_enumerator(keys);
500 enum_values = values->create_enumerator(values);
501 while (enumerator->enumerate(enumerator, &key, &value) &&
502 enum_keys->enumerate(enum_keys, &current_key) &&
503 enum_values->enumerate(enum_values, &current_value))
504 {
505 ck_assert_str_eq(current_key, key);
506 ck_assert_str_eq(current_value, value);
507 keys->remove_at(keys, enum_keys);
508 values->remove_at(values, enum_values);
509 }
510 enumerator->destroy(enumerator);
511 enum_keys->destroy(enum_keys);
512 enum_values->destroy(enum_values);
513 ck_assert_int_eq(0, keys->get_count(keys));
514 keys->destroy(keys);
515 values->destroy(values);
516 }
517
518 START_TEST(test_key_value_enumerator)
519 {
520 linked_list_t *keys, *values;
521
522 keys = linked_list_create_with_items("key1", "key2", "empty", "key3", NULL);
523 values = linked_list_create_with_items("val1", "with space", "", "string with\nnewline", NULL);
524 verify_key_values(keys, values, "main");
525
526 keys = linked_list_create_with_items("key", "key2", "subsub", NULL);
527 values = linked_list_create_with_items("value", "value2", "section value", NULL);
528 verify_key_values(keys, values, "main.sub1");
529
530 settings->set_str(settings, "main.sub2.new", "added");
531 keys = linked_list_create_with_items("new", NULL);
532 values = linked_list_create_with_items("added", NULL);
533 verify_key_values(keys, values, "main.sub2");
534
535 keys = linked_list_create_with_items(NULL);
536 values = linked_list_create_with_items(NULL);
537 verify_key_values(keys, values, "other.empty");
538
539 settings->set_str(settings, "other.empty.new", "added");
540 keys = linked_list_create_with_items("new", NULL);
541 values = linked_list_create_with_items("added", NULL);
542 verify_key_values(keys, values, "other.empty");
543
544 keys = linked_list_create_with_items(NULL);
545 values = linked_list_create_with_items(NULL);
546 verify_key_values(keys, values, "main.unknown");
547 }
548 END_TEST
549
550 #ifdef WIN32
551 # define include1 "C:\\Windows\\Temp\\strongswan-settings-test-include1"
552 # define include1_str "C:\\\\Windows\\\\Temp\\\\strongswan-settings-test-include1"
553 # define include2 "C:\\Windows\\Temp\\strongswan-settings-test-include2"
554 # define include2_str "C:\\\\Windows\\\\Temp\\\\strongswan-settings-test-include2"
555 #else
556 # define include1 "/tmp/strongswan-settings-test-include1"
557 # define include1_str include1
558 # define include2 "/tmp/strongswan-settings-test-include2"
559 # define include2_str include2
560 #endif
561
562 static char *include_content1 =
563 "main {\n"
564 " key1 = n1\n"
565 " key2 = n2\n"
566 " key3 = val3\n"
567 " none = \n"
568 " sub1 {\n"
569 " key3 = value\n"
570 " }\n"
571 " sub2 {\n"
572 " sub3 = val3\n"
573 " }\n"
574 " include " include2 "\n"
575 "}";
576 static char *include_content2 =
577 "key2 = v2\n"
578 "sub1 {\n"
579 " key = val\n"
580 "}";
581
582 START_SETUP(setup_include_config)
583 {
584 ck_assert(chunk_write(chunk_from_str(include_content1), include1, 0022, TRUE));
585 ck_assert(chunk_write(chunk_from_str(include_content2), include2, 0022, TRUE));
586 }
587 END_SETUP
588
589 START_TEARDOWN(teardown_include_config)
590 {
591 settings->destroy(settings);
592 unlink(include2);
593 unlink(include1);
594 unlink(path);
595 }
596 END_TEARDOWN
597
598 static void verify_include()
599 {
600 verify_string("n1", "main.key1");
601 verify_string("v2", "main.key2");
602 verify_string("val3", "main.key3");
603 verify_string("val", "main.sub1.key");
604 verify_string("v2", "main.sub1.key2");
605 verify_string("val", "main.sub1.sub1.key");
606 verify_string("value", "main.sub1.key3");
607 verify_string("value", "main.sub1.include");
608 verify_string("val3", "main.sub2.sub3");
609
610 verify_null("main.none");
611 }
612
613 START_TEST(test_include)
614 {
615 chunk_t contents = chunk_from_str(
616 "main {\n"
617 " key1 = val1\n"
618 " key2 = val2\n"
619 " none = x\n"
620 " sub1 {\n"
621 " include this/does/not/exist.conf\n"
622 " include = value\n"
623 " key2 = value2\n"
624 " include " include2 "\n"
625 " }\n"
626 "}\n"
627 "include " include1);
628
629 create_settings(contents);
630 verify_include();
631 }
632 END_TEST
633
634 START_TEST(test_include_string)
635 {
636 chunk_t contents = chunk_from_str(
637 "main {\n"
638 " key1 = val1\n"
639 " key2 = val2\n"
640 " none = x\n"
641 " sub1 {\n"
642 " include this/does/not/exist.conf\n"
643 " include = value\n"
644 " key2 = value2\n"
645 " include \"" include2_str "\"\n"
646 " }\n"
647 "}\n"
648 "include \"" include1_str "\"");
649
650 create_settings(contents);
651 verify_include();
652 }
653 END_TEST
654
655 START_TEST(test_load_files)
656 {
657 chunk_t contents = chunk_from_str(
658 "main {\n"
659 " key1 = val1\n"
660 " key2 = val2\n"
661 " key3 = val3\n"
662 " none = x\n"
663 " sub1 {\n"
664 " include = value\n"
665 " key2 = v2\n"
666 " sub1 {\n"
667 " key = val\n"
668 " }\n"
669 " }\n"
670 "}");
671 char *val1, *val2, *val3;
672
673 create_settings(contents);
674
675 val1 = settings->get_str(settings, "main.key1", NULL);
676 val2 = settings->get_str(settings, "main.sub1.key2", NULL);
677 /* loading the same file twice should not change anything, with... */
678 ck_assert(settings->load_files(settings, path, TRUE));
679 ck_assert(val1 == settings->get_str(settings, "main.key1", NULL));
680 ck_assert(val2 == settings->get_str(settings, "main.sub1.key2", NULL));
681 /* ...or without merging */
682 ck_assert(settings->load_files(settings, path, FALSE));
683 ck_assert(val1 == settings->get_str(settings, "main.key1", NULL));
684 ck_assert(val2 == settings->get_str(settings, "main.sub1.key2", NULL));
685
686 val1 = settings->get_str(settings, "main.key2", NULL);
687 val2 = settings->get_str(settings, "main.key3", NULL);
688 val3 = settings->get_str(settings, "main.none", NULL);
689 /* only pointers for modified settings should change, but still be valid */
690 ck_assert(settings->load_files(settings, include1, FALSE));
691 ck_assert(val1 != settings->get_str(settings, "main.key2", NULL));
692 ck_assert_str_eq(val1, "val2");
693 ck_assert(val2 == settings->get_str(settings, "main.key3", NULL));
694 ck_assert(val3 != settings->get_str(settings, "main.none", NULL));
695 ck_assert_str_eq(val3, "x");
696
697 settings->destroy(settings);
698 create_settings(contents);
699
700 ck_assert(settings->load_files(settings, include1, TRUE));
701 verify_include();
702
703 ck_assert(settings->load_files(settings, include2, FALSE));
704 verify_null("main.key1");
705 verify_string("v2", "key2");
706 verify_string("val", "sub1.key");
707 verify_null("main.sub1.key3");
708 }
709 END_TEST
710
711 START_TEST(test_load_files_section)
712 {
713 chunk_t contents = chunk_from_str(
714 "main {\n"
715 " key1 = val1\n"
716 " key2 = val2\n"
717 " none = x\n"
718 " sub1 {\n"
719 " include = value\n"
720 " key2 = value2\n"
721 " }\n"
722 "}");
723
724 create_settings(contents);
725
726 ck_assert(settings->load_files_section(settings, include1, TRUE, ""));
727 ck_assert(settings->load_files_section(settings, include2, TRUE, "main.sub1"));
728 verify_include();
729
730 /* non existing files are a failure here */
731 ck_assert(!settings->load_files_section(settings, include1".conf", TRUE, ""));
732 verify_include();
733
734 #ifndef WIN32
735 /* unreadable files are too (only fails when not running as root) */
736 if (getuid() != 0)
737 {
738 ck_assert(chunk_write(contents, include1".no", 0444, TRUE));
739 ck_assert(!settings->load_files_section(settings, include1".no", TRUE, ""));
740 unlink(include1".no");
741 verify_include();
742 }
743 #endif
744
745 ck_assert(settings->load_files_section(settings, include2, FALSE, "main"));
746 verify_null("main.key1");
747 verify_string("v2", "main.key2");
748 verify_string("val", "main.sub1.key");
749 verify_null("main.sub1.key3");
750 verify_null("main.sub2.sub3");
751
752 ck_assert(settings->load_files_section(settings, include2, TRUE, "main.sub2"));
753 verify_string("v2", "main.sub2.key2");
754 verify_string("val", "main.sub2.sub1.key");
755 }
756 END_TEST
757
758 START_TEST(test_order_kv)
759 {
760 chunk_t base = chunk_from_str(
761 "main {\n"
762 " key1 = val1\n"
763 " key2 = val2\n"
764 " key3 = val3\n"
765 "}");
766 chunk_t include = chunk_from_str(
767 "main {\n"
768 " key0 = val0\n"
769 " key3 = val3\n"
770 " key1 = val1\n"
771 "}");
772 linked_list_t *keys, *values;
773
774 create_settings(base);
775 ck_assert(chunk_write(include, include1, 0022, TRUE));
776
777 keys = linked_list_create_with_items("key1", "key2", "key3", NULL);
778 values = linked_list_create_with_items("val1", "val2", "val3", NULL);
779 verify_key_values(keys, values, "main");
780
781 /* the original order is maintained if the settings are merged */
782 ck_assert(settings->load_files(settings, include1, TRUE));
783 keys = linked_list_create_with_items("key1", "key2", "key3", "key0", NULL);
784 values = linked_list_create_with_items("val1", "val2", "val3", "val0", NULL);
785 verify_key_values(keys, values, "main");
786
787 /* but the new order is adopted if the settings are replaced */
788 ck_assert(settings->load_files(settings, include1, FALSE));
789 keys = linked_list_create_with_items("key0", "key3", "key1", NULL);
790 values = linked_list_create_with_items("val0", "val3", "val1", NULL);
791 verify_key_values(keys, values, "main");
792
793 unlink(include1);
794 }
795 END_TEST
796
797 START_TEST(test_order_section)
798 {
799 chunk_t base = chunk_from_str(
800 "main {\n"
801 " sub1 {\n"
802 " }\n"
803 " sub2 {\n"
804 " }\n"
805 " sub3 {\n"
806 " }\n"
807 "}");
808 chunk_t include = chunk_from_str(
809 "main {\n"
810 " sub0 {\n"
811 " }\n"
812 " sub3 {\n"
813 " }\n"
814 " sub1 {\n"
815 " }\n"
816 "}");
817 linked_list_t *sections;
818
819 create_settings(base);
820 ck_assert(chunk_write(include, include1, 0022, TRUE));
821
822 sections = linked_list_create_with_items("sub1", "sub2", "sub3", NULL);
823 verify_sections(sections, "main");
824
825 /* the original order is maintained if the settings are merged */
826 ck_assert(settings->load_files(settings, include1, TRUE));
827 sections = linked_list_create_with_items("sub1", "sub2", "sub3", "sub0", NULL);
828 verify_sections(sections, "main");
829
830 /* but the new order is adopted if the settings are replaced */
831 ck_assert(settings->load_files(settings, include1, FALSE));
832 sections = linked_list_create_with_items("sub0", "sub3", "sub1", NULL);
833 verify_sections(sections, "main");
834
835 unlink(include1);
836 }
837 END_TEST
838
839
840 START_TEST(test_load_string)
841 {
842 char *content =
843 "main {\n"
844 " key1 = val1\n"
845 " key2 = val2\n"
846 " key3 = val3\n"
847 " none = x\n"
848 " sub1 {\n"
849 " include = value\n"
850 " key2 = v2\n"
851 " sub1 {\n"
852 " key = val\n"
853 " }\n"
854 " }\n"
855 "}";
856 char *val1, *val2, *val3;
857
858 settings = settings_create_string(content);
859
860 val1 = settings->get_str(settings, "main.key1", NULL);
861 val2 = settings->get_str(settings, "main.sub1.key2", NULL);
862 /* loading the same content twice should not change anything, with... */
863 ck_assert(settings->load_string(settings, content, TRUE));
864 ck_assert(val1 == settings->get_str(settings, "main.key1", NULL));
865 ck_assert(val2 == settings->get_str(settings, "main.sub1.key2", NULL));
866 /* ...or without merging */
867 ck_assert(settings->load_string(settings, content, FALSE));
868 ck_assert(val1 == settings->get_str(settings, "main.key1", NULL));
869 ck_assert(val2 == settings->get_str(settings, "main.sub1.key2", NULL));
870
871 val1 = settings->get_str(settings, "main.key2", NULL);
872 val2 = settings->get_str(settings, "main.key3", NULL);
873 val3 = settings->get_str(settings, "main.none", NULL);
874 /* only pointers for modified settings should change, but still be valid */
875 ck_assert(settings->load_string(settings, include_content1, FALSE));
876 ck_assert(val1 != settings->get_str(settings, "main.key2", NULL));
877 ck_assert_str_eq(val1, "val2");
878 ck_assert(val2 == settings->get_str(settings, "main.key3", NULL));
879 ck_assert(val3 != settings->get_str(settings, "main.none", NULL));
880 ck_assert_str_eq(val3, "x");
881
882 settings->destroy(settings);
883 settings = settings_create_string(content);
884 ck_assert(settings);
885
886 ck_assert(settings->load_string(settings, include_content1, TRUE));
887 verify_include();
888
889 ck_assert(settings->load_string(settings, include_content2, FALSE));
890 verify_null("main.key1");
891 verify_string("v2", "key2");
892 verify_string("val", "sub1.key");
893 verify_null("main.sub1.key3");
894 }
895 END_TEST
896
897
898 START_TEST(test_load_string_section)
899 {
900 char *content =
901 "main {\n"
902 " key1 = val1\n"
903 " key2 = val2\n"
904 " none = x\n"
905 " sub1 {\n"
906 " include = value\n"
907 " key2 = value2\n"
908 " }\n"
909 "}";
910
911 settings = settings_create_string(content);
912
913 ck_assert(settings->load_string_section(settings, include_content1, TRUE, ""));
914 ck_assert(settings->load_string_section(settings, include_content2, TRUE, "main.sub1"));
915 verify_include();
916
917 /* invalid strings are a failure */
918 ck_assert(!settings->load_string_section(settings, "conf {", TRUE, ""));
919 /* NULL or empty strings are OK though */
920 ck_assert(settings->load_string_section(settings, "", TRUE, ""));
921 ck_assert(settings->load_string_section(settings, NULL, TRUE, ""));
922 verify_include();
923
924 ck_assert(settings->load_string_section(settings, include_content2, FALSE, "main"));
925 verify_null("main.key1");
926 verify_string("v2", "main.key2");
927 verify_string("val", "main.sub1.key");
928 verify_null("main.sub1.key3");
929 verify_null("main.sub2.sub3");
930
931 ck_assert(settings->load_string_section(settings, include_content2, TRUE, "main.sub2"));
932 verify_string("v2", "main.sub2.key2");
933 verify_string("val", "main.sub2.sub1.key");
934 }
935 END_TEST
936
937 START_SETUP(setup_fallback_config)
938 {
939 create_settings(chunk_from_str(
940 "main {\n"
941 " key1 = val1\n"
942 " sub1 {\n"
943 " key1 = val1\n"
944 " }\n"
945 "}\n"
946 "sub {\n"
947 " key1 = subval1\n"
948 " key2 = subval2\n"
949 " subsub {\n"
950 " subkey1 = subsubval1\n"
951 " }\n"
952 "}\n"
953 "base {\n"
954 " key1 = baseval1\n"
955 " key2 = baseval2\n"
956 " sub1 {\n"
957 " key1 = subbase1\n"
958 " key2 = subbase2\n"
959 " key3 = subbase3\n"
960 " subsub {\n"
961 " subkey1 = subsubbaseval1\n"
962 " subkey2 = subsubbaseval2\n"
963 " }\n"
964 " }\n"
965 " sub2 {\n"
966 " key4 = subbase4\n"
967 " }\n"
968 "}"));
969 }
970 END_SETUP
971
972 START_TEST(test_add_fallback)
973 {
974 linked_list_t *keys, *values;
975
976 settings->add_fallback(settings, "main.sub1", "sub");
977 verify_string("val1", "main.sub1.key1");
978 verify_string("subval2", "main.sub1.key2");
979 verify_string("subsubval1", "main.sub1.subsub.subkey1");
980
981 /* fallbacks are preserved even if the complete config is replaced */
982 settings->load_files(settings, path, FALSE);
983 verify_string("val1", "main.sub1.key1");
984 verify_string("subval2", "main.sub1.key2");
985 verify_string("subsubval1", "main.sub1.subsub.subkey1");
986
987 keys = linked_list_create_with_items("sub1", NULL);
988 verify_sections(keys, "main");
989 keys = linked_list_create_with_items("subsub", NULL);
990 verify_sections(keys, "main.sub1");
991
992 keys = linked_list_create_with_items("key1", NULL);
993 values = linked_list_create_with_items("val1", NULL);
994 verify_key_values(keys, values, "main");
995
996 keys = linked_list_create_with_items("key1", "key2", NULL);
997 values = linked_list_create_with_items("val1", "subval2", NULL);
998 verify_key_values(keys, values, "main.sub1");
999
1000 keys = linked_list_create_with_items("subkey1", NULL);
1001 values = linked_list_create_with_items("subsubval1", NULL);
1002 verify_key_values(keys, values, "main.sub1.subsub");
1003
1004 settings->add_fallback(settings, "main", "base");
1005 verify_string("val1", "main.key1");
1006 verify_string("baseval2", "main.key2");
1007 verify_string("val1", "main.sub1.key1");
1008 verify_string("subval2", "main.sub1.key2");
1009 verify_string("subsubval1", "main.sub1.subsub.subkey1");
1010 verify_string("subsubbaseval2", "main.sub1.subsub.subkey2");
1011 verify_string("subbase3", "main.sub1.key3");
1012 verify_string("subbase4", "main.sub2.key4");
1013
1014
1015 keys = linked_list_create_with_items("sub1", "sub2", NULL);
1016 verify_sections(keys, "main");
1017 keys = linked_list_create_with_items("subsub", NULL);
1018 verify_sections(keys, "main.sub1");
1019
1020 keys = linked_list_create_with_items("key1", "key2", NULL);
1021 values = linked_list_create_with_items("val1", "baseval2", NULL);
1022 verify_key_values(keys, values, "main");
1023
1024 keys = linked_list_create_with_items("key1", "key2", "key3", NULL);
1025 values = linked_list_create_with_items("val1", "subval2", "subbase3", NULL);
1026 verify_key_values(keys, values, "main.sub1");
1027
1028 keys = linked_list_create_with_items("subkey1", "subkey2", NULL);
1029 values = linked_list_create_with_items("subsubval1", "subsubbaseval2", NULL);
1030 verify_key_values(keys, values, "main.sub1.subsub");
1031
1032 settings->set_str(settings, "main.sub1.key2", "val2");
1033 verify_string("val2", "main.sub1.key2");
1034 settings->set_str(settings, "main.sub1.subsub.subkey2", "val2");
1035 verify_string("val2", "main.sub1.subsub.subkey2");
1036 verify_string("subsubval1", "main.sub1.subsub.subkey1");
1037 }
1038 END_TEST
1039
1040 START_TEST(test_add_fallback_printf)
1041 {
1042 settings->add_fallback(settings, "%s.sub1", "sub", "main");
1043 verify_string("val1", "main.sub1.key1");
1044 verify_string("subval2", "main.sub1.key2");
1045 verify_string("subsubval1", "main.sub1.subsub.subkey1");
1046
1047 settings->add_fallback(settings, "%s.%s2", "%s.%s1", "main", "sub");
1048 verify_string("val1", "main.sub2.key1");
1049 verify_string("subval2", "main.sub2.key2");
1050 verify_string("subsubval1", "main.sub2.subsub.subkey1");
1051 }
1052 END_TEST
1053
1054 START_SETUP(setup_string_config)
1055 {
1056 create_settings(chunk_from_str(
1057 "string = \" with accurate\twhite\\tspace\"\n"
1058 "special = \"all { special } characters # can be used.\"\n"
1059 "newlines = \"can be encoded explicitly\\nor implicitly\n"
1060 "or \\\n"
1061 "escaped\"\n"
1062 "quotes = \"\\\"and\\\" slashes \\\\ can \\\\ be\" # escaped too\n"
1063 "multiple = \"strings\" are \"combined\"\n"
1064 ));
1065 }
1066 END_SETUP
1067
1068 START_TEST(test_strings)
1069 {
1070 verify_string(" with accurate\twhite\tspace", "string");
1071 verify_string("all { special } characters # can be used.", "special");
1072 verify_string("can be encoded explicitly\nor implicitly\nor escaped", "newlines");
1073 verify_string("\"and\" slashes \\ can \\ be", "quotes");
1074 verify_string("strings are combined", "multiple");
1075 }
1076 END_TEST
1077
1078 START_TEST(test_valid)
1079 {
1080 chunk_t contents;
1081
1082 contents = chunk_from_str(
1083 "single = value");
1084 ck_assert(chunk_write(contents, path, 0022, TRUE));
1085 ck_assert(settings->load_files(settings, path, FALSE));
1086 verify_string("value", "single");
1087
1088 contents = chunk_from_str(
1089 "singleline { single = value }");
1090 ck_assert(chunk_write(contents, path, 0022, TRUE));
1091 ck_assert(settings->load_files(settings, path, FALSE));
1092 verify_string("value", "singleline.single");
1093
1094 contents = chunk_from_str(
1095 "singleline { sub { sub1 = val1 } single = value }");
1096 ck_assert(chunk_write(contents, path, 0022, TRUE));
1097 ck_assert(settings->load_files(settings, path, FALSE));
1098 verify_string("val1", "singleline.sub.sub1");
1099
1100 contents = chunk_from_str(
1101 "newline\n { single = value }");
1102 ck_assert(chunk_write(contents, path, 0022, TRUE));
1103 ck_assert(settings->load_files(settings, path, FALSE));
1104 verify_string("value", "newline.single");
1105
1106 contents = chunk_from_str(
1107 "section {\n"
1108 " include # without pattern produces a warning, but is fine\n"
1109 "}\n");
1110 ck_assert(chunk_write(contents, path, 0022, TRUE));
1111 ck_assert(settings->load_files(settings, path, FALSE));
1112
1113 contents = chunk_from_str(
1114 "equals = a setting with = and { character");
1115 ck_assert(chunk_write(contents, path, 0022, TRUE));
1116 ck_assert(settings->load_files(settings, path, FALSE));
1117 verify_string("a setting with = and { character", "equals");
1118 }
1119 END_TEST
1120
1121 START_TEST(test_invalid)
1122 {
1123 chunk_t contents;
1124
1125 contents = chunk_from_str(
1126 "{\n"
1127 " no = section name\n"
1128 "}\n");
1129 ck_assert(chunk_write(contents, path, 0022, TRUE));
1130 ck_assert(!settings->load_files(settings, path, FALSE));
1131
1132 contents = chunk_from_str(
1133 "no {\n"
1134 " = key name\n"
1135 "}\n");
1136 ck_assert(chunk_write(contents, path, 0022, TRUE));
1137 ck_assert(!settings->load_files(settings, path, FALSE));
1138
1139 contents = chunk_from_str(
1140 "unterminated {\n"
1141 " not = valid\n");
1142 ck_assert(chunk_write(contents, path, 0022, TRUE));
1143 ck_assert(!settings->load_files(settings, path, FALSE));
1144
1145 contents = chunk_from_str(
1146 "unterminated {\n"
1147 " strings = \"are invalid\n");
1148 ck_assert(chunk_write(contents, path, 0022, TRUE));
1149 ck_assert(!settings->load_files(settings, path, FALSE));
1150
1151 contents = chunk_from_str(
1152 "spaces in name {}");
1153 ck_assert(chunk_write(contents, path, 0022, TRUE));
1154 ck_assert(!settings->load_files(settings, path, FALSE));
1155
1156 contents = chunk_from_str(
1157 "\"unexpected\" = string");
1158 ck_assert(chunk_write(contents, path, 0022, TRUE));
1159 ck_assert(!settings->load_files(settings, path, FALSE));
1160 }
1161 END_TEST
1162
1163 START_SETUP(setup_crlf_config)
1164 {
1165 chunk_t inc1 = chunk_from_str(
1166 "main {\r\n"
1167 " key1 = n1\r\n"
1168 " key2 = n2\n"
1169 " key3 = val3\n"
1170 " none = \n"
1171 " sub1 {\n"
1172 " key3 = value\n"
1173 " }\n"
1174 " sub2 {\n"
1175 " sub3 = val3\n"
1176 " }\n"
1177 " include " include2 "\n"
1178 "}");
1179 chunk_t inc2 = chunk_from_str(
1180 "key2 = v2\n"
1181 "sub1 {\n"
1182 " key = val\n"
1183 "}");
1184 ck_assert(chunk_write(inc1, include1, 0022, TRUE));
1185 ck_assert(chunk_write(inc2, include2, 0022, TRUE));
1186 }
1187 END_SETUP
1188
1189 START_TEST(test_crlf)
1190 {
1191 chunk_t contents = chunk_from_str(
1192 "main {\r\n"
1193 " key1 = val1\r\n"
1194 " none =\r\n"
1195 " sub1 {\r\n"
1196 " key2 = v2\r\n"
1197 " # key2 = v3\r\n"
1198 " sub1 {\r\n"
1199 " key = val\r\n"
1200 " }\r\n"
1201 " }\r\n"
1202 "}");
1203
1204 create_settings(contents);
1205
1206 verify_string("val1", "main.key1");
1207 verify_string("v2", "main.sub1.key2");
1208 verify_string("val", "main.sub1.sub1.key");
1209 verify_null("main.none");
1210 }
1211 END_TEST
1212
1213 START_TEST(test_crlf_string)
1214 {
1215 chunk_t contents = chunk_from_str(
1216 "main {\r\n"
1217 " key1 = \"new\r\nline\"\r\n"
1218 " key2 = \"joi\\\r\nned\"\r\n"
1219 " none =\r\n"
1220 " sub1 {\r\n"
1221 " key2 = v2\r\n"
1222 " sub1 {\r\n"
1223 " key = val\r\n"
1224 " }\r\n"
1225 " }\r\n"
1226 "}");
1227
1228 create_settings(contents);
1229
1230 verify_string("new\nline", "main.key1");
1231 verify_string("joined", "main.key2");
1232 verify_string("v2", "main.sub1.key2");
1233 verify_string("val", "main.sub1.sub1.key");
1234 verify_null("main.none");
1235 }
1236 END_TEST
1237
1238 START_TEST(test_crlf_include)
1239 {
1240 chunk_t contents = chunk_from_str(
1241 "main {\r\n"
1242 " key1 = val1\r\n"
1243 " none =\r\n"
1244 " sub1 {\r\n"
1245 " key2 = v2\r\n"
1246 " sub1 {\r\n"
1247 " key = val\r\n"
1248 " }\r\n"
1249 " }\r\n"
1250 "}");
1251
1252 create_settings(contents);
1253
1254 verify_string("val1", "main.key1");
1255 verify_string("v2", "main.sub1.key2");
1256 verify_string("val", "main.sub1.sub1.key");
1257 verify_null("main.none");
1258 }
1259 END_TEST
1260
1261 Suite *settings_suite_create()
1262 {
1263 Suite *s;
1264 TCase *tc;
1265
1266 s = suite_create("settings");
1267
1268 tc = tcase_create("get/set_str (basic behavior)");
1269 tcase_add_checked_fixture(tc, setup_base_config, teardown_config);
1270 tcase_add_test(tc, test_get_str);
1271 tcase_add_test(tc, test_get_str_printf);
1272 tcase_add_test(tc, test_set_str);
1273 tcase_add_test(tc, test_set_str_printf);
1274 tcase_add_test(tc, test_set_default_str);
1275 suite_add_tcase(s, tc);
1276
1277 tc = tcase_create("get/set_bool");
1278 tcase_add_checked_fixture(tc, setup_bool_config, teardown_config);
1279 tcase_add_test(tc, test_get_bool);
1280 tcase_add_test(tc, test_set_bool);
1281 suite_add_tcase(s, tc);
1282
1283 tc = tcase_create("get/set_int");
1284 tcase_add_checked_fixture(tc, setup_int_config, teardown_config);
1285 tcase_add_test(tc, test_get_int);
1286 tcase_add_test(tc, test_set_int);
1287 suite_add_tcase(s, tc);
1288
1289 tc = tcase_create("settings_value_as_uint64");
1290 tcase_add_test(tc, test_value_as_unit64);
1291 suite_add_tcase(s, tc);
1292
1293 tc = tcase_create("get/set_double");
1294 tcase_add_checked_fixture(tc, setup_double_config, teardown_config);
1295 tcase_add_test(tc, test_get_double);
1296 tcase_add_test(tc, test_set_double);
1297 suite_add_tcase(s, tc);
1298
1299 tc = tcase_create("get/set_time");
1300 tcase_add_checked_fixture(tc, setup_time_config, teardown_config);
1301 tcase_add_test(tc, test_get_time);
1302 tcase_add_test(tc, test_set_time);
1303 suite_add_tcase(s, tc);
1304
1305 tc = tcase_create("section enumerator");
1306 tcase_add_checked_fixture(tc, setup_base_config, teardown_config);
1307 tcase_add_test(tc, test_section_enumerator);
1308 suite_add_tcase(s, tc);
1309
1310 tc = tcase_create("key/value enumerator");
1311 tcase_add_checked_fixture(tc, setup_base_config, teardown_config);
1312 tcase_add_test(tc, test_key_value_enumerator);
1313 suite_add_tcase(s, tc);
1314
1315 tc = tcase_create("include/load_files[_section]");
1316 tcase_add_checked_fixture(tc, setup_include_config, teardown_include_config);
1317 tcase_add_test(tc, test_include);
1318 tcase_add_test(tc, test_include_string);
1319 tcase_add_test(tc, test_load_files);
1320 tcase_add_test(tc, test_load_files_section);
1321 tcase_add_test(tc, test_order_kv);
1322 tcase_add_test(tc, test_order_section);
1323 suite_add_tcase(s, tc);
1324
1325 tc = tcase_create("load_string[_section]");
1326 tcase_add_checked_fixture(tc, setup_include_config, teardown_config);
1327 tcase_add_test(tc, test_load_string);
1328 tcase_add_test(tc, test_load_string_section);
1329 suite_add_tcase(s, tc);
1330
1331 tc = tcase_create("fallback");
1332 tcase_add_checked_fixture(tc, setup_fallback_config, teardown_config);
1333 tcase_add_test(tc, test_add_fallback);
1334 tcase_add_test(tc, test_add_fallback_printf);
1335 suite_add_tcase(s, tc);
1336
1337 tc = tcase_create("strings");
1338 tcase_add_checked_fixture(tc, setup_string_config, teardown_config);
1339 tcase_add_test(tc, test_strings);
1340 suite_add_tcase(s, tc);
1341
1342 tc = tcase_create("valid/invalid data");
1343 tcase_add_checked_fixture(tc, setup_base_config, teardown_config);
1344 tcase_add_test(tc, test_valid);
1345 tcase_add_test(tc, test_invalid);
1346 suite_add_tcase(s, tc);
1347
1348 tc = tcase_create("crlf");
1349 tcase_add_checked_fixture(tc, setup_crlf_config, teardown_include_config);
1350 tcase_add_test(tc, test_crlf);
1351 tcase_add_test(tc, test_crlf_string);
1352 tcase_add_test(tc, test_crlf_include);
1353 suite_add_tcase(s, tc);
1354
1355 return s;
1356 }