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 int main(int argc, char **argv) {
56 gras_init_defaultlog(&argc,argv,"config.thresh=debug root.thresh=info");
58 fprintf(stderr,"==== Alloc and free a config set.\n");
60 gras_cfg_dump("test set","",set);
64 fprintf(stderr,"==== Try to use an unregistered option (err msg expected).\n");
66 TRYEXPECT(mismatch_error,gras_cfg_set_parse(set,"color:blue"));
71 "\n==== Validation test (err msg about not enough values expected)\n");
76 fprintf(stderr,"\n==== Validation test (too many elements)\n");
78 gras_cfg_set_parse(set,"hostname:toto:42");
79 gras_cfg_set_parse(set,"speed:42 speed:24");
81 gras_cfg_get_int(set,"speed",&ival);
82 printf("speed value: %d\n",ival);
85 fprintf(stderr,"\n§§§§§§§§§ %s §§§§§§§§§\n§§§ Expected: %s\n",
87 "Count: 3; Options:\\nmquinson\\necaron\\nfsuter");