Annotation of embedaddon/confuse/tests/section_title_dupes.c, revision 1.1.1.2
1.1 misho 1: #include "check_confuse.h"
2: #include <string.h>
3:
4: int main(void)
5: {
1.1.1.2 ! misho 6: static cfg_opt_t section_opts[] = {
! 7: CFG_STR("prop", 0, CFGF_NONE),
! 8: CFG_END()
! 9: };
1.1 misho 10:
1.1.1.2 ! misho 11: cfg_opt_t opts[] = {
! 12: CFG_SEC("section", section_opts, CFGF_TITLE | CFGF_MULTI),
! 13: CFG_END()
! 14: };
1.1 misho 15:
1.1.1.2 ! misho 16: cfg_opt_t opts_no_dupes[] = {
! 17: CFG_SEC("section", section_opts,
! 18: CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES),
! 19: CFG_END()
! 20: };
1.1 misho 21:
1.1.1.2 ! misho 22: const char *config_data =
! 23: "section title_one { prop = 'value_one' }\n"
! 24: "section title_two { prop = 'value_two' }\n"
! 25: "section title_one { prop = 'value_one' }\n"; /* Duplicate! */
1.1 misho 26:
1.1.1.2 ! misho 27: int rc;
! 28: cfg_t *cfg = cfg_init(opts, CFGF_NONE);
1.1 misho 29:
1.1.1.2 ! misho 30: fail_unless(cfg);
1.1 misho 31:
1.1.1.2 ! misho 32: rc = cfg_parse_buf(cfg, config_data);
! 33: fail_unless(rc == CFG_SUCCESS);
1.1 misho 34:
1.1.1.2 ! misho 35: fail_unless(cfg_size(cfg, "section") == 2);
! 36: fail_unless(strcmp(cfg_title(cfg_getnsec(cfg, "section", 0)), "title_one") == 0);
! 37: fail_unless(strcmp(cfg_title(cfg_getnsec(cfg, "section", 1)), "title_two") == 0);
1.1 misho 38:
1.1.1.2 ! misho 39: cfg_free(cfg);
1.1 misho 40:
1.1.1.2 ! misho 41: cfg = cfg_init(opts_no_dupes, CFGF_NONE);
! 42: fail_unless(cfg);
1.1 misho 43:
1.1.1.2 ! misho 44: rc = cfg_parse_buf(cfg, config_data);
! 45: fail_unless(rc == CFG_PARSE_ERROR);
1.1 misho 46:
1.1.1.2 ! misho 47: cfg_free(cfg);
1.1 misho 48:
1.1.1.2 ! misho 49: return 0;
1.1 misho 50: }
51:
1.1.1.2 ! misho 52: /**
! 53: * Local Variables:
! 54: * indent-tabs-mode: t
! 55: * c-file-style: "linux"
! 56: * End:
! 57: */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>