Annotation of embedaddon/confuse/tests/print_filter.c, revision 1.1.1.1
1.1 misho 1: #include "check_confuse.h"
2: #include <stdio.h>
3: #include <string.h>
4:
5: static int no_foo(cfg_t *cfg, cfg_opt_t *opt)
6: {
7: return !strncmp(cfg_opt_name(opt), "foo-", 4);
8: }
9:
10: static int no_bar(cfg_t *cfg, cfg_opt_t *opt)
11: {
12: return !strncmp(cfg_opt_name(opt), "bar-", 4);
13: }
14:
15: int main(void)
16: {
17: cfg_opt_t sub[] = {
18: CFG_INT_LIST("bar-int", "{0,1,2}", CFGF_NONE),
19: CFG_INT_LIST("foo-int", NULL, CFGF_NONE),
20: CFG_BOOL("bar-bool", cfg_false, CFGF_NONE),
21: CFG_FLOAT("foo-float", 2.718, CFGF_NONE),
22: CFG_STR("gazonk-string", NULL, CFGF_NONE),
23: CFG_END()
24: };
25: cfg_opt_t opts[] = {
26: CFG_INT_LIST("foo-int", "{0,1,2}", CFGF_NONE),
27: CFG_INT_LIST("bar-int", NULL, CFGF_NONE),
28: CFG_BOOL("foo-bool", cfg_true, CFGF_NONE),
29: CFG_FLOAT("bar-float", 3.14, CFGF_NONE),
30: CFG_STR("gazonk-string", "foobar", CFGF_NONE),
31: CFG_SEC("sub", sub, CFGF_NONE),
32: CFG_END()
33: };
34: char buf[200]; /* should be enough */
35: FILE *f;
36:
37: cfg_t *cfg = cfg_init(opts, 0);
38:
39: cfg_set_print_filter_func(cfg, no_foo);
40: f = fmemopen(buf, sizeof(buf), "w+");
41: fail_unless(f != NULL);
42: cfg_print(cfg, f);
43: fclose(f);
44:
45: fprintf(stderr, "no_foo filter:\n%s", buf);
46: fail_unless(strstr(buf, "foo-") == NULL);
47: fail_unless(strstr(buf, "bar-") != NULL);
48:
49: cfg_set_print_filter_func(cfg, no_bar);
50: f = fmemopen(buf, sizeof(buf), "w+");
51: fail_unless(f != NULL);
52: cfg_print(cfg, f);
53: fclose(f);
54:
55: fprintf(stderr, "----\n");
56: fprintf(stderr, "no_bar filter:\n%s", buf);
57: fail_unless(strstr(buf, "foo-") != NULL);
58: fail_unless(strstr(buf, "bar-") == NULL);
59:
60: cfg_free(cfg);
61:
62: return 0;
63: }
64:
65: /**
66: * Local Variables:
67: * indent-tabs-mode: t
68: * c-file-style: "linux"
69: * End:
70: */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>