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_CATEGORY(test,"Logging for this test");
15 /*====[ Code ]===============================================================*/
16 static xbt_cfg_t make_set(){
20 xbt_cfg_register_str(set,"speed:1_to_2_int");
21 xbt_cfg_register_str(set,"hostname:1_to_1_string");
22 xbt_cfg_register_str(set,"user:1_to_10_string");
25 } /* end_of_make_set */
27 int main(int argc, char **argv) {
35 fprintf(stderr,"==== Alloc and free a config set.\n");
37 xbt_cfg_set_parse(set, "hostname:veloce user:mquinson\nuser:oaumage\tuser:alegrand");
38 xbt_cfg_dump("test set","",set);
42 fprintf(stderr, "==== Validation test with too few values of 'speed'\n");
44 xbt_cfg_set_parse(set, "hostname:veloce user:mquinson\nuser:oaumage\tuser:alegrand");
48 if (e.category != mismatch_error ||
49 strncmp(e.msg,"Config elem speed needs",strlen("Config elem speed needs")))
56 fprintf(stderr,"==== Validation test with too much values of 'speed'\n");
58 xbt_cfg_set_parse(set,"hostname:toto:42 user:alegrand");
60 xbt_cfg_set_parse(set,"speed:42 speed:24 speed:34");
62 if (e.category != mismatch_error ||
63 strncmp(e.msg,"Cannot add value 34 to the config elem speed",
64 strlen("Config elem speed needs")))
72 fprintf(stderr,"==== Get single value (Expected: 'speed value: 42')\n");
74 /* get_single_value */
76 xbt_cfg_t myset=make_set();
78 xbt_cfg_set_parse(myset,"hostname:toto:42 speed:42");
79 ival = xbt_cfg_get_int(myset,"speed");
80 fprintf(stderr,"speed value: %d\n",ival); /* Prints: "speed value: 42" */
84 fprintf(stderr,"==== Get multiple values (Expected: 'Count: 3; Options: mquinson;ecaron;alegrand;')\n");
86 /* get_multiple_value */
89 xbt_cfg_t myset=make_set();
91 xbt_cfg_set_parse(myset, "hostname:veloce user:mquinson\nuser:oaumage\tuser:alegrand");
92 xbt_cfg_set_parse(myset,"speed:42");
94 dyn = xbt_cfg_get_dynar(myset,"user");
95 fprintf(stderr,"Count: %lu; Options: ",xbt_dynar_length(dyn));
96 xbt_dynar_foreach(dyn,ival,str) {
97 fprintf(stderr,"%s;",str);
100 /* This prints: "Count: 3; Options: mquinson;ecaron;alegrand;" */
101 xbt_cfg_free(&myset);
104 fprintf(stderr,"==== Try to use an unregistered option. (ERROR EXPECTED: 'color' not registered)\n");
106 xbt_cfg_t myset=make_set();
108 xbt_cfg_set_parse(myset,"color:blue");
109 THROW1(mismatch_error,0,"Found an option which shouldn't be there (%s)","color:blue");
111 if (e.category != not_found_error)
115 /* This spits an error: 'color' not registered */
116 xbt_cfg_free(&myset);
119 fprintf(stderr,"==== Success\n");