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 XBT_LOG_NEW_DEFAULT_CATEGORY(test,"Logging for this test");
15 /*====[ Code ]===============================================================*/
16 static xbt_cfg_t make_set(){
21 TRYFAIL(xbt_cfg_register_str(set,"speed:1_to_2_int"));
22 TRYFAIL(xbt_cfg_register_str(set,"hostname:1_to_1_string"));
23 TRYFAIL(xbt_cfg_register_str(set,"user:1_to_10_string"));
26 } /* end_of_make_set */
28 int main(int argc, char **argv) {
34 xbt_init_defaultlog(&argc,argv,"config.thresh=debug root.thresh=info");
36 fprintf(stderr,"==== Alloc and free a config set.\n");
38 TRYFAIL(xbt_cfg_set_parse(set, "hostname:veloce user:mquinson\nuser:oaumage\tuser:alegrand"));
39 xbt_cfg_dump("test set","",set);
44 "==== Validation test. (ERROR EXPECTED: not enough values of 'speed')\n");
46 xbt_cfg_set_parse(set, "hostname:veloce user:mquinson\nuser:oaumage\tuser:alegrand");
51 fprintf(stderr,"==== Validation test (ERROR EXPECTED: too many elements)\n");
53 xbt_cfg_set_parse(set,"hostname:toto:42");
54 xbt_cfg_set_parse(set,"speed:42 speed:24 speed:34");
59 fprintf(stderr,"==== Get single value (Expected: 'speed value: 42')\n");
61 /* get_single_value */
63 xbt_cfg_t myset=make_set();
65 xbt_cfg_set_parse(myset,"hostname:toto:42 speed:42");
66 xbt_cfg_get_int(myset,"speed",&ival);
67 fprintf(stderr,"speed value: %d\n",ival); /* Prints: "speed value: 42" */
71 fprintf(stderr,"==== Get multiple values (Expected: 'Count: 3; Options: mquinson;ecaron;alegrand;')\n");
73 /* get_multiple_value */
76 xbt_cfg_t myset=make_set();
78 xbt_cfg_set_parse(myset, "hostname:veloce user:mquinson\nuser:oaumage\tuser:alegrand");
79 xbt_cfg_set_parse(myset,"speed:42");
81 xbt_cfg_get_dynar(myset,"user",&dyn);
82 fprintf(stderr,"Count: %lu; Options: ",xbt_dynar_length(dyn));
83 xbt_dynar_foreach(dyn,ival,str) {
84 fprintf(stderr,"%s;",str);
87 /* This prints: "Count: 3; Options: mquinson;ecaron;alegrand;" */
91 fprintf(stderr,"==== Try to use an unregistered option. (ERROR EXPECTED: 'color' not registered)\n");
93 xbt_cfg_t myset=make_set();
94 TRYEXPECT(mismatch_error,xbt_cfg_set_parse(myset,"color:blue"));
95 /* This spits an error: 'color' not registered */
99 fprintf(stderr,"==== Success\n");