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) {
36 fprintf(stderr,"==== Alloc and free a config set.\n");
38 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\n");
54 xbt_cfg_set_parse(set,"hostname:toto:42");
55 xbt_cfg_set_parse(set,"speed:42 speed:24 speed:34");
57 if (e.category != mismatch_error)
65 fprintf(stderr,"==== Get single value (Expected: 'speed value: 42')\n");
67 /* get_single_value */
69 xbt_cfg_t myset=make_set();
71 xbt_cfg_set_parse(myset,"hostname:toto:42 speed:42");
72 ival = xbt_cfg_get_int(myset,"speed");
73 fprintf(stderr,"speed value: %d\n",ival); /* Prints: "speed value: 42" */
77 fprintf(stderr,"==== Get multiple values (Expected: 'Count: 3; Options: mquinson;ecaron;alegrand;')\n");
79 /* get_multiple_value */
82 xbt_cfg_t myset=make_set();
84 xbt_cfg_set_parse(myset, "hostname:veloce user:mquinson\nuser:oaumage\tuser:alegrand");
85 xbt_cfg_set_parse(myset,"speed:42");
87 dyn = xbt_cfg_get_dynar(myset,"user");
88 fprintf(stderr,"Count: %lu; Options: ",xbt_dynar_length(dyn));
89 xbt_dynar_foreach(dyn,ival,str) {
90 fprintf(stderr,"%s;",str);
93 /* This prints: "Count: 3; Options: mquinson;ecaron;alegrand;" */
97 fprintf(stderr,"==== Try to use an unregistered option. (ERROR EXPECTED: 'color' not registered)\n");
99 xbt_cfg_t myset=make_set();
101 xbt_cfg_set_parse(myset,"color:blue");
102 THROW1(mismatch_error,0,"Found an option which shouldn't be there (%s)","color:blue");
104 if (e.category != not_found_error)
108 /* This spits an error: 'color' not registered */
109 xbt_cfg_free(&myset);
112 fprintf(stderr,"==== Success\n");