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 /*====[ Prototypes ]=========================================================*/
14 xbt_cfg_t make_set(void); /* build a minimal set */
16 /*====[ Code ]===============================================================*/
22 TRYFAIL(xbt_cfg_register_str(set,"speed:1_to_2_int"));
23 TRYFAIL(xbt_cfg_register_str(set,"hostname:1_to_1_string"));
24 TRYFAIL(xbt_cfg_register_str(set,"user:1_to_10_string"));
26 TRYFAIL(xbt_cfg_set_parse(set, "hostname:veloce "
27 "user:mquinson\nuser:oaumage\tuser:alegrand"));
31 int main(int argc, char **argv) {
39 xbt_init_defaultlog(&argc,argv,"config.thresh=debug root.thresh=info");
41 fprintf(stderr,"==== Alloc and free a config set.\n");
43 xbt_cfg_dump("test set","",set);
48 fprintf(stderr,"==== Try to use an unregistered option. (ERROR EXPECTED: 'color' not registered)\n");
50 TRYEXPECT(mismatch_error,xbt_cfg_set_parse(set,"color:blue"));
56 "==== Validation test. (ERROR EXPECTED: not enough values of 'speed')\n");
62 fprintf(stderr,"==== Validation test (ERROR EXPECTED: too many elements)\n");
64 xbt_cfg_set_parse(set,"hostname:toto:42");
65 xbt_cfg_set_parse(set,"speed:42 speed:24 speed:34");
70 fprintf(stderr,"==== Get single value (Expected: 'speed value: 42')\n");
72 xbt_cfg_set_parse(set,"hostname:toto:42 speed:42");
73 xbt_cfg_get_int(set,"speed",&ival);
74 fprintf(stderr,"speed value: %d\n",ival);
78 fprintf(stderr,"==== Get multiple values (Expected: 'Count: 3; Options: mquinson;ecaron;alegrand;')\n");
80 xbt_cfg_set_parse(set,"speed:42");
82 xbt_cfg_get_dynar(set,"user",&dyn);
83 fprintf(stderr,"Count: %lu; Options: ",xbt_dynar_length(dyn));
84 xbt_dynar_foreach(dyn,ival,str) {
85 fprintf(stderr,"%s;",str);