Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
basic support for automatic testing easing problem support from the users
[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 void parse_log_opt(int argc, char **argv,const char *deft);
52
53 int main(int argc, char **argv) {
54   gras_error_t errcode;
55   gras_cfg_t *set;
56   int ival;
57   
58   parse_log_opt(argc,argv,"config.thresh=debug root.thresh=info");
59
60   fprintf(stderr,"==== Alloc and free a config set.\n");
61   set=make_set();
62   gras_cfg_dump("test set","",set);
63   gras_cfg_free(&set);
64
65
66   fprintf(stderr,"==== Try to use an unregistered option (err msg expected).\n");
67   set=make_set();
68   TRYEXPECT(mismatch_error,gras_cfg_set_parse(set,"color:blue"));
69   gras_cfg_free(&set);
70
71
72   fprintf(stderr,
73           "\n==== Validation test (err msg about not enough values expected)\n");
74   set=make_set();
75   gras_cfg_check(set);
76   gras_cfg_free(&set);
77
78   fprintf(stderr,"\n==== Validation test (too many elements)\n");
79   set=make_set();
80   gras_cfg_set_parse(set,"hostname:toto:42");
81   gras_cfg_set_parse(set,"speed:42 speed:24");
82   gras_cfg_check(set);
83   gras_cfg_get_int(set,"speed",&ival);
84   printf("speed value: %d\n",ival);
85   gras_cfg_free(&set);
86
87   fprintf(stderr,"\n§§§§§§§§§ %s §§§§§§§§§\n§§§ Expected: %s\n",
88          "TEST5",
89          "Count: 3; Options:\\nmquinson\\necaron\\nfsuter");
90   test5();
91
92   return 0;
93 }
94