3 /* test config - test code to the config set */
5 /* Copyright (c) 2004 Martin Quinson. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
13 /*====[ Code ]===============================================================*/
14 static xbt_cfg_t make_set(){
19 TRYFAIL(xbt_cfg_register_str(set,"speed:1_to_2_int"));
20 TRYFAIL(xbt_cfg_register_str(set,"hostname:1_to_1_string"));
21 TRYFAIL(xbt_cfg_register_str(set,"user:1_to_10_string"));
24 } /* end_of_make_set */
26 int main(int argc, char **argv) {
32 xbt_init_defaultlog(&argc,argv,"config.thresh=debug root.thresh=info");
34 fprintf(stderr,"==== Alloc and free a config set.\n");
36 TRYFAIL(xbt_cfg_set_parse(set, "hostname:veloce user:mquinson\nuser:oaumage\tuser:alegrand"));
37 xbt_cfg_dump("test set","",set);
42 "==== Validation test. (ERROR EXPECTED: not enough values of 'speed')\n");
44 xbt_cfg_set_parse(set, "hostname:veloce user:mquinson\nuser:oaumage\tuser:alegrand");
49 fprintf(stderr,"==== Validation test (ERROR EXPECTED: too many elements)\n");
51 xbt_cfg_set_parse(set,"hostname:toto:42");
52 xbt_cfg_set_parse(set,"speed:42 speed:24 speed:34");
57 fprintf(stderr,"==== Get single value (Expected: 'speed value: 42')\n");
59 /* get_single_value */
61 xbt_cfg_t myset=make_set();
63 xbt_cfg_set_parse(myset,"hostname:toto:42 speed:42");
64 xbt_cfg_get_int(myset,"speed",&ival);
65 fprintf(stderr,"speed value: %d\n",ival); /* Prints: "speed value: 42" */
69 fprintf(stderr,"==== Get multiple values (Expected: 'Count: 3; Options: mquinson;ecaron;alegrand;')\n");
71 /* get_multiple_value */
74 xbt_cfg_t myset=make_set();
76 xbt_cfg_set_parse(myset, "hostname:veloce user:mquinson\nuser:oaumage\tuser:alegrand");
77 xbt_cfg_set_parse(myset,"speed:42");
79 xbt_cfg_get_dynar(myset,"user",&dyn);
80 fprintf(stderr,"Count: %lu; Options: ",xbt_dynar_length(dyn));
81 xbt_dynar_foreach(dyn,ival,str) {
82 fprintf(stderr,"%s;",str);
85 /* This prints: "Count: 3; Options: mquinson;ecaron;alegrand;" */
89 fprintf(stderr,"==== Try to use an unregistered option. (ERROR EXPECTED: 'color' not registered)\n");
91 xbt_cfg_t myset=make_set();
92 TRYEXPECT(mismatch_error,xbt_cfg_set_parse(myset,"color:blue"));
93 /* This spits an error: 'color' not registered */
97 fprintf(stderr,"==== Success\n");