Annotation of embedaddon/confuse/tests/ignore_parm.c, revision 1.1.1.1
1.1 misho 1: /* Test handling of parameters that should be ignored.
2: */
3:
4: #include <string.h>
5: #include <stdlib.h>
6: #include "check_confuse.h"
7:
8: cfg_opt_t section_opts[] = {
9: CFG_STR("section_parameter", NULL, CFGF_NONE),
10: CFG_END()
11: };
12:
13: cfg_opt_t opts[] = {
14: CFG_STR("parameter", NULL, CFGF_NONE),
15: CFG_SEC("section", section_opts, CFGF_TITLE | CFGF_MULTI),
16: CFG_END()
17: };
18:
19: static int testconfig(const char *buf)
20: {
21: cfg_t *cfg;
22:
23: cfg = cfg_init(opts, CFGF_IGNORE_UNKNOWN);
24: if (!cfg)
25: return 0;
26:
27: if (cfg_parse_buf(cfg, buf) != CFG_SUCCESS)
28: return 0;
29:
30: cfg_free(cfg);
31:
32: return 1;
33: }
34:
35: int main(void)
36: {
37: /* Sanity check cases that don't need to ignore parameters. */
38: fail_unless(testconfig("parameter=5"));
39: fail_unless(testconfig("parameter=5\n"
40: "section mysection {\n"
41: "\tsection_parameter=1\n"
42: "}"));
43:
44: /* Ignore each type (no lists) */
45: fail_unless(testconfig("unknown_int=1"));
46: fail_unless(testconfig("unknown_string=\"hello\""));
47: fail_unless(testconfig("unknown_float=1.1"));
48: fail_unless(testconfig("unknown_bool=true"));
49:
50: /* Ignore multiple parameters */
51: fail_unless(testconfig("unknown_one=1\n"
52: "unknown_two=2\n"
53: "unknown_three=3\n"));
54:
55: /* Test ignore parameters in a section */
56: fail_unless(testconfig("section mysection {\n"
57: "\tunknown_section_parameter=1\n"
58: "}"));
59:
60: /* Ignore unknown section, with unknown parameters */
61: fail_unless(testconfig("parameter=5\n"
62: "unknown section {\n"
63: "\tunknown_param=1\n"
64: "\tunknown_list={1,2,3,4}\n"
65: "}\n"
66: "section hej { section_parameter = \"gnejs\" }\n"
67: "parameter = \"ormbunke\""));
68:
69: return 0;
70: }
71:
72: /**
73: * Local Variables:
74: * indent-tabs-mode: t
75: * c-file-style: "linux"
76: * End:
77: */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>