Annotation of embedaddon/confuse/tests/section_getopt.c, revision 1.1.1.1

1.1       misho       1: #include "check_confuse.h"
                      2: #include <string.h>
                      3: 
                      4: int main(void)
                      5: {
                      6:        static cfg_opt_t sub_opts[] = {
                      7:                CFG_INT("int", 1, CFGF_NONE),
                      8:                CFG_END()
                      9:        };
                     10: 
                     11:        cfg_opt_t opts[] = {
                     12:                CFG_SEC("single", sub_opts, CFGF_NONE),
                     13:                CFG_SEC("multi", sub_opts, CFGF_MULTI),
                     14:                CFG_SEC("multi-title", sub_opts, CFGF_TITLE | CFGF_MULTI),
                     15:                CFG_SEC("multi-title-no-dupes", sub_opts,
                     16:                        CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES),
                     17:                CFG_END()
                     18:        };
                     19: 
                     20:        const char *config_data =
                     21:                "single { int = 11 }\n"
                     22:                "multi { int = 21 }\n"
                     23:                "multi { int = 22 }\n"
                     24:                "multi { int = 23 }\n"
                     25:                "multi-title name { int = 30 }\n"
                     26:                "multi-title name { int = 31 }\n"
                     27:                "multi-title odd  { int = 32 }\n"
                     28:                "multi-title-no-dupes name1 { int = 41 }\n"
                     29:                "multi-title-no-dupes name2 { int = 42 }\n"
                     30:                "multi-title-no-dupes name3 { int = 43 }\n";
                     31: 
                     32:        int rc;
                     33:        cfg_t *cfg = cfg_init(opts, CFGF_NONE);
                     34:        cfg_t *sec;
                     35: 
                     36:        fail_unless(cfg);
                     37: 
                     38:        rc = cfg_parse_buf(cfg, config_data);
                     39:        fail_unless(rc == CFG_SUCCESS);
                     40: 
                     41:        fail_unless(cfg_addtsec(cfg, "multi-title", "'a-very'silly|option\\title") != NULL);
                     42: 
                     43:        fail_unless(cfg_getint(cfg, "single|int") == 11);
                     44:        fail_unless(cfg_getint(cfg, "multi=0|int") == 21);
                     45:        fail_unless(cfg_getint(cfg, "multi=1|int") == 22);
                     46:        fail_unless(cfg_getint(cfg, "multi=2|int") == 23);
                     47:        fail_unless(cfg_getint(cfg, "multi-title=name|int") == 31);
                     48:        fail_unless(cfg_getint(cfg, "multi-title=odd|int") == 32);
                     49:        fail_unless(cfg_getint(cfg, "multi-title='\\'a-very\\'silly|option\\\\title'|int") == 1);
                     50:        fail_unless(cfg_getint(cfg, "multi-title-no-dupes=name1|int") == 41);
                     51:        fail_unless(cfg_getint(cfg, "multi-title-no-dupes=name2|int") == 42);
                     52:        fail_unless(cfg_getint(cfg, "multi-title-no-dupes=name3|int") == 43);
                     53:        sec = cfg_getsec(cfg, "single");
                     54:        fail_unless(cfg_getint(sec, "int") == 11);
                     55:        sec = cfg_getsec(cfg, "multi=0");
                     56:        fail_unless(cfg_getint(sec, "int") == 21);
                     57:        sec = cfg_getsec(cfg, "multi=1");
                     58:        fail_unless(cfg_getint(sec, "int") == 22);
                     59:        sec = cfg_getsec(cfg, "multi=2");
                     60:        fail_unless(cfg_getint(sec, "int") == 23);
                     61:        sec = cfg_getsec(cfg, "multi-title=name");
                     62:        fail_unless(cfg_getint(sec, "int") == 31);
                     63:        sec = cfg_getsec(cfg, "multi-title=odd");
                     64:        fail_unless(cfg_getint(sec, "int") == 32);
                     65:        sec = cfg_getsec(cfg, "multi-title='\\'a-very\\'silly|option\\\\title'");
                     66:        fail_unless(cfg_getint(sec, "int") == 1);
                     67:        sec = cfg_getsec(cfg, "multi-title-no-dupes=name1");
                     68:        fail_unless(cfg_getint(sec, "int") == 41);
                     69:        sec = cfg_getsec(cfg, "multi-title-no-dupes=name2");
                     70:        fail_unless(cfg_getint(sec, "int") == 42);
                     71:        sec = cfg_getsec(cfg, "multi-title-no-dupes=name3");
                     72:        fail_unless(cfg_getint(sec, "int") == 43);
                     73: 
                     74:        /* for backwards compat */
                     75:        fail_unless(cfg_getint(cfg, "multi|int") == 21);
                     76:        fail_unless(cfg_getint(cfg, "multi-title|int") == 31);
                     77:        fail_unless(cfg_getint(cfg, "multi-title-no-dupes|int") == 41);
                     78:        sec = cfg_getsec(cfg, "multi");
                     79:        fail_unless(cfg_getint(sec, "int") == 21);
                     80:        sec = cfg_getsec(cfg, "multi-title");
                     81:        fail_unless(cfg_getint(sec, "int") == 31);
                     82:        sec = cfg_getsec(cfg, "multi-title-no-dupes");
                     83:        fail_unless(cfg_getint(sec, "int") == 41);
                     84: 
                     85:        /* expected failures */
                     86:        fail_unless(cfg_getopt(cfg, "single=0|int") == NULL);
                     87:        fail_unless(cfg_getopt(cfg, "multi=4|int") == NULL);
                     88:        fail_unless(cfg_getopt(cfg, "multi-title=0|int") == NULL);
                     89:        fail_unless(cfg_getopt(cfg, "multi-title=bad|int") == NULL);
                     90:        fail_unless(cfg_getopt(cfg, "multi-title-no-dupes=0|int") == NULL);
                     91:        fail_unless(cfg_getopt(cfg, "multi-title-no-dupes=bad|int") == NULL);
                     92:        fail_unless(cfg_getsec(cfg, "single=0") == NULL);
                     93:        fail_unless(cfg_getsec(cfg, "multi=4") == NULL);
                     94:        fail_unless(cfg_getsec(cfg, "multi-title=0") == NULL);
                     95:        fail_unless(cfg_getsec(cfg, "multi-title=bad") == NULL);
                     96:        fail_unless(cfg_getsec(cfg, "multi-title-no-dupes=0") == NULL);
                     97:        fail_unless(cfg_getsec(cfg, "multi-title-no-dupes=bad") == NULL);
                     98: 
                     99:        cfg_free(cfg);
                    100: 
                    101:        return 0;
                    102: }
                    103: 
                    104: /**
                    105:  * Local Variables:
                    106:  *  indent-tabs-mode: t
                    107:  *  c-file-style: "linux"
                    108:  * End:
                    109:  */

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