Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[Data description]
[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 int test3(void); /* validate=>not enought */
11 int test4(void); /* validate=> too many */
12 int test5(void); /* get users list */
13
14
15 /*====[ Code ]===============================================================*/
16 gras_cfg_t *make_set(){
17   gras_cfg_t *set=NULL; 
18   gras_error_t errcode;
19
20   TRYFAIL(gras_cfg_new(&set));
21   gras_cfg_register_str(set,"hostname:1_to_1_string");
22   gras_cfg_register_str(set,"user:1_to_10_string");
23   gras_cfg_register_str(set,"speed:1_to_1_int");
24
25   gras_cfg_set_parse(set,
26                    "hostname:veloce "
27                    "user:mquinson\nuser:ecaron\tuser:fsuter");
28   return set;
29 }
30
31
32 /*----[ get users list ]-----------------------------------------------------*/
33 int test5()
34 {
35   gras_dynar_t *dyn;
36   char *str;
37   int i;
38
39   gras_cfg_t *set=make_set();
40   gras_cfg_set_parse(set,"speed:42");
41   gras_cfg_check(set);
42   gras_cfg_get_dynar(set,"user",&dyn);
43   printf("Count: %d; Options: \n",gras_dynar_length(dyn));
44   gras_dynar_foreach(dyn,i,str) {
45     printf("%s\n",str);
46   }
47   gras_cfg_free(&set);
48   return 1;
49 }
50  
51 int main(int argc, char **argv) {
52   gras_error_t errcode;
53   gras_cfg_t *set;
54   int ival;
55   
56   gras_init_defaultlog(argc,argv,"config.thresh=debug root.thresh=info");
57
58   fprintf(stderr,"==== Alloc and free a config set.\n");
59   set=make_set();
60   gras_cfg_dump("test set","",set);
61   gras_cfg_free(&set);
62
63
64   fprintf(stderr,"==== Try to use an unregistered option (err msg expected).\n");
65   set=make_set();
66   TRYEXPECT(mismatch_error,gras_cfg_set_parse(set,"color:blue"));
67   gras_cfg_free(&set);
68
69
70   fprintf(stderr,
71           "\n==== Validation test (err msg about not enough values expected)\n");
72   set=make_set();
73   gras_cfg_check(set);
74   gras_cfg_free(&set);
75
76   fprintf(stderr,"\n==== Validation test (too many elements)\n");
77   set=make_set();
78   gras_cfg_set_parse(set,"hostname:toto:42");
79   gras_cfg_set_parse(set,"speed:42 speed:24");
80   gras_cfg_check(set);
81   gras_cfg_get_int(set,"speed",&ival);
82   printf("speed value: %d\n",ival);
83   gras_cfg_free(&set);
84
85   fprintf(stderr,"\n§§§§§§§§§ %s §§§§§§§§§\n§§§ Expected: %s\n",
86          "TEST5",
87          "Count: 3; Options:\\nmquinson\\necaron\\nfsuter");
88   test5();
89
90   return 0;
91 }
92