3 /* test config - test code to the config set */
8 /*====[ Prototypes ]=========================================================*/
9 gras_cfg_t *make_set(void); /* build a minimal set */
11 /*====[ Code ]===============================================================*/
12 gras_cfg_t *make_set(){
17 TRYFAIL(gras_cfg_register_str(set,"speed:1_to_2_int"));
18 TRYFAIL(gras_cfg_register_str(set,"hostname:1_to_1_string"));
19 TRYFAIL(gras_cfg_register_str(set,"user:1_to_10_string"));
21 TRYFAIL(gras_cfg_set_parse(set, "hostname:veloce "
22 "user:mquinson\nuser:oaumage\tuser:alegrand"));
26 int main(int argc, char **argv) {
34 gras_init_defaultlog(&argc,argv,"config.thresh=debug root.thresh=info");
36 fprintf(stderr,"==== Alloc and free a config set.\n");
38 gras_cfg_dump("test set","",set);
42 fprintf(stderr,"==== Try to use an unregistered option. (ERROR EXPECTED: 'color' not registered)\n");
44 TRYEXPECT(mismatch_error,gras_cfg_set_parse(set,"color:blue"));
49 "==== Validation test. (ERROR EXPECTED: not enough values of 'speed')\n");
55 fprintf(stderr,"==== Validation test (ERROR EXPECTED: too many elements)\n");
57 gras_cfg_set_parse(set,"hostname:toto:42");
58 gras_cfg_set_parse(set,"speed:42 speed:24 speed:34");
62 fprintf(stderr,"==== Get single value (Expected: 'speed value: 42')\n");
64 gras_cfg_set_parse(set,"hostname:toto:42 speed:42");
65 gras_cfg_get_int(set,"speed",&ival);
66 fprintf(stderr,"speed value: %d\n",ival);
69 fprintf(stderr,"==== Get multiple values (Expected: 'Count: 3; Options: mquinson;ecaron;alegrand;')\n");
71 gras_cfg_set_parse(set,"speed:42");
73 gras_cfg_get_dynar(set,"user",&dyn);
74 fprintf(stderr,"Count: %lu; Options: ",gras_dynar_length(dyn));
75 gras_dynar_foreach(dyn,ival,str) {
76 fprintf(stderr,"%s;",str);