Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
alpha portability again (damn size_t)
[simgrid.git] / testsuite / xbt / config_usage.c
1 /* $Id$ */
2
3 /* test config - test code to the config set */
4
5 #include <stdio.h>
6 #include <gras.h>
7
8 /*====[ Prototypes ]=========================================================*/
9 gras_cfg_t *make_set(void); /* build a minimal set */
10
11 /*====[ Code ]===============================================================*/
12 gras_cfg_t *make_set(){
13   gras_cfg_t *set=NULL; 
14   gras_error_t errcode;
15
16   TRYFAIL(gras_cfg_new(&set));
17   TRYFAIL(gras_cfg_register_str(set,"speed:1_to_2_int"));
18   TRYFAIL(gras_cfg_register_str(set,"hostname:1_to_1_string"));
19   TRYFAIL(gras_cfg_register_str(set,"user:1_to_10_string"));
20
21   TRYFAIL(gras_cfg_set_parse(set, "hostname:veloce "
22                              "user:mquinson\nuser:oaumage\tuser:alegrand"));
23   return set;
24 }
25  
26 int main(int argc, char **argv) {
27   gras_error_t errcode;
28   gras_cfg_t *set;
29
30   gras_dynar_t *dyn;
31   char *str;
32   int ival;
33   
34   gras_init_defaultlog(&argc,argv,"config.thresh=debug root.thresh=info");
35
36   fprintf(stderr,"==== Alloc and free a config set.\n");
37   set=make_set();
38   gras_cfg_dump("test set","",set);
39   gras_cfg_free(&set);
40
41
42   fprintf(stderr,"==== Try to use an unregistered option. (ERROR EXPECTED: 'color' not registered)\n");
43   set=make_set();
44   TRYEXPECT(mismatch_error,gras_cfg_set_parse(set,"color:blue"));
45   gras_cfg_free(&set);
46
47
48   fprintf(stderr,
49           "==== Validation test. (ERROR EXPECTED: not enough values of 'speed')\n");
50   set=make_set();
51   gras_cfg_check(set);
52   gras_cfg_free(&set);
53   gras_cfg_free(&set);
54
55   fprintf(stderr,"==== Validation test (ERROR EXPECTED: too many elements)\n");
56   set=make_set();
57   gras_cfg_set_parse(set,"hostname:toto:42");
58   gras_cfg_set_parse(set,"speed:42 speed:24 speed:34");
59   gras_cfg_check(set);
60   gras_cfg_free(&set);
61
62   fprintf(stderr,"==== Get single value (Expected: 'speed value: 42')\n");
63   set=make_set();
64   gras_cfg_set_parse(set,"hostname:toto:42 speed:42");
65   gras_cfg_get_int(set,"speed",&ival);
66   fprintf(stderr,"speed value: %d\n",ival); 
67   gras_cfg_free(&set);
68
69   fprintf(stderr,"==== Get multiple values (Expected: 'Count: 3; Options: mquinson;ecaron;alegrand;')\n");
70   set=make_set();
71   gras_cfg_set_parse(set,"speed:42");
72   gras_cfg_check(set);
73   gras_cfg_get_dynar(set,"user",&dyn);
74   fprintf(stderr,"Count: %lu; Options: ",gras_dynar_length(dyn));
75   gras_dynar_foreach(dyn,ival,str) {
76     fprintf(stderr,"%s;",str);
77   }
78   fprintf(stderr,"\n");
79   gras_cfg_free(&set);
80
81   gras_exit();
82   return 0;
83 }
84