File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / confuse / tests / section_title_dupes.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Mar 17 00:49:17 2021 UTC (3 years, 3 months ago) by misho
Branches: confuse, MAIN
CVS tags: v3_3, HEAD
confuse 3.3

    1: #include "check_confuse.h"
    2: #include <string.h>
    3: 
    4: int main(void)
    5: {
    6: 	static cfg_opt_t section_opts[] = {
    7: 		CFG_STR("prop", 0, CFGF_NONE),
    8: 		CFG_END()
    9: 	};
   10: 
   11: 	cfg_opt_t opts[] = {
   12: 		CFG_SEC("section", section_opts, CFGF_TITLE | CFGF_MULTI),
   13: 		CFG_END()
   14: 	};
   15: 
   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: 	};
   21: 
   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! */
   26: 
   27: 	int rc;
   28: 	cfg_t *cfg = cfg_init(opts, CFGF_NONE);
   29: 
   30: 	fail_unless(cfg);
   31: 
   32: 	rc = cfg_parse_buf(cfg, config_data);
   33: 	fail_unless(rc == CFG_SUCCESS);
   34: 
   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);
   38: 
   39: 	cfg_free(cfg);
   40: 
   41: 	cfg = cfg_init(opts_no_dupes, CFGF_NONE);
   42: 	fail_unless(cfg);
   43: 
   44: 	rc = cfg_parse_buf(cfg, config_data);
   45: 	fail_unless(rc == CFG_PARSE_ERROR);
   46: 
   47: 	cfg_free(cfg);
   48: 
   49: 	return 0;
   50: }
   51: 
   52: /**
   53:  * Local Variables:
   54:  *  indent-tabs-mode: t
   55:  *  c-file-style: "linux"
   56:  * End:
   57:  */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>