Annotation of embedaddon/confuse/tests/empty_string.c, revision 1.1.1.1
1.1 misho 1: #include "check_confuse.h"
2: #include <stdio.h>
3: #include <string.h>
4:
5: #ifndef HAVE_FMEMOPEN
6: extern FILE *fmemopen(void *buf, size_t size, const char *type);
7: #endif
8:
9: int main(void)
10: {
11: cfg_opt_t opts[] = {
12: CFG_STR("string", "hello", CFGF_NONE),
13: CFG_END()
14: };
15: cfg_t *cfg;
16: char buf[100]; /* should be enough */
17: FILE *f;
18:
19: /*
20: * override the default with a config with an empty string
21: * and then generate a temporary config file with that
22: */
23: cfg = cfg_init(opts, 0);
24: fail_unless(cfg_parse_buf(cfg, "string = ''") == CFG_SUCCESS);
25: fail_unless(strcmp(cfg_getstr(cfg, "string"), "") == 0);
26: f = fmemopen(buf, sizeof(buf), "w+");
27: fail_unless(f != NULL);
28: cfg_print(cfg, f);
29: cfg_free(cfg);
30:
31: /*
32: * try to reload the generated temporary config file to check
33: * that the default is indeed overridden by an empty string
34: */
35: cfg = cfg_init(opts, 0);
36: fseek(f, 0L, SEEK_SET);
37: fail_unless(cfg_parse_fp(cfg, f) == CFG_SUCCESS);
38: fclose(f);
39: fail_unless(strcmp(cfg_getstr(cfg, "string"), "") == 0);
40: cfg_free(cfg);
41:
42: return 0;
43: }
44:
45: /**
46: * Local Variables:
47: * indent-tabs-mode: t
48: * c-file-style: "linux"
49: * End:
50: */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>