3 /* test config - test code to the config set */
8 /*====[ Prototypes ]=========================================================*/
9 gras_cfg_t *make_set(void); /* build a minimal set */
10 int test3(void); /* validate=>not enought */
11 int test4(void); /* validate=> too many */
12 int test5(void); /* get users list */
15 /*====[ Code ]===============================================================*/
16 gras_cfg_t *make_set(){
20 TRYFAIL(gras_cfg_new(&set));
21 gras_cfg_register_str(set,"hostname:1_to_1_string");
22 gras_cfg_register_str(set,"user:1_to_10_string");
23 gras_cfg_register_str(set,"speed:1_to_1_int");
25 gras_cfg_set_parse(set,
27 "user:mquinson\nuser:ecaron\tuser:fsuter");
32 /*----[ get users list ]-----------------------------------------------------*/
39 gras_cfg_t *set=make_set();
40 gras_cfg_set_parse(set,"speed:42");
42 gras_cfg_get_dynar(set,"user",&dyn);
43 printf("Count: %d; Options: \n",gras_dynar_length(dyn));
44 gras_dynar_foreach(dyn,i,str) {
51 void parse_log_opt(int argc, char **argv,const char *deft);
53 int main(int argc, char **argv) {
58 parse_log_opt(argc,argv,"config.thresh=debug root.thresh=info");
60 fprintf(stderr,"==== Alloc and free a config set.\n");
62 gras_cfg_dump("test set","",set);
66 fprintf(stderr,"==== Try to use an unregistered option (err msg expected).\n");
68 TRYEXPECT(mismatch_error,gras_cfg_set_parse(set,"color:blue"));
73 "\n==== Validation test (err msg about not enough values expected)\n");
78 fprintf(stderr,"\n==== Validation test (too many elements)\n");
80 gras_cfg_set_parse(set,"hostname:toto:42");
81 gras_cfg_set_parse(set,"speed:42 speed:24");
83 gras_cfg_get_int(set,"speed",&ival);
84 printf("speed value: %d\n",ival);
87 fprintf(stderr,"\n§§§§§§§§§ %s §§§§§§§§§\n§§§ Expected: %s\n",
89 "Count: 3; Options:\\nmquinson\\necaron\\nfsuter");