Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
cosmetics
[simgrid.git] / testsuite / xbt / config_usage.c
1 /* $Id$ */
2
3 /* test config - test code to the config set */
4
5 /* Copyright (c) 2004 Martin Quinson. All rights reserved.                  */
6
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. */
9
10 #include <stdio.h>
11 #include "gras.h"
12
13 /*====[ Prototypes ]=========================================================*/
14 xbt_cfg_t make_set(void); /* build a minimal set */
15
16 /*====[ Code ]===============================================================*/
17 xbt_cfg_t make_set(){
18   xbt_cfg_t set=NULL; 
19   xbt_error_t errcode;
20
21   set = xbt_cfg_new();
22   TRYFAIL(xbt_cfg_register_str(set,"speed:1_to_2_int"));
23   TRYFAIL(xbt_cfg_register_str(set,"hostname:1_to_1_string"));
24   TRYFAIL(xbt_cfg_register_str(set,"user:1_to_10_string"));
25
26   TRYFAIL(xbt_cfg_set_parse(set, "hostname:veloce "
27                              "user:mquinson\nuser:oaumage\tuser:alegrand"));
28   return set;
29 }
30  
31 int main(int argc, char **argv) {
32   xbt_error_t errcode;
33   xbt_cfg_t set;
34
35   xbt_dynar_t dyn;
36   char *str;
37   int ival;
38   
39   xbt_init_defaultlog(&argc,argv,"config.thresh=debug root.thresh=info");
40
41   fprintf(stderr,"==== Alloc and free a config set.\n");
42   set=make_set();
43   xbt_cfg_dump("test set","",set);
44   xbt_cfg_free(&set);
45   xbt_cfg_free(&set);
46
47
48   fprintf(stderr,"==== Try to use an unregistered option. (ERROR EXPECTED: 'color' not registered)\n");
49   set=make_set();
50   TRYEXPECT(mismatch_error,xbt_cfg_set_parse(set,"color:blue"));
51   xbt_cfg_free(&set);
52   xbt_cfg_free(&set);
53
54
55   fprintf(stderr,
56           "==== Validation test. (ERROR EXPECTED: not enough values of 'speed')\n");
57   set=make_set();
58   xbt_cfg_check(set);
59   xbt_cfg_free(&set);
60   xbt_cfg_free(&set);
61
62   fprintf(stderr,"==== Validation test (ERROR EXPECTED: too many elements)\n");
63   set=make_set();
64   xbt_cfg_set_parse(set,"hostname:toto:42");
65   xbt_cfg_set_parse(set,"speed:42 speed:24 speed:34");
66   xbt_cfg_check(set);
67   xbt_cfg_free(&set);
68   xbt_cfg_free(&set);
69
70   fprintf(stderr,"==== Get single value (Expected: 'speed value: 42')\n");
71   set=make_set();
72   xbt_cfg_set_parse(set,"hostname:toto:42 speed:42");
73   xbt_cfg_get_int(set,"speed",&ival);
74   fprintf(stderr,"speed value: %d\n",ival); 
75   xbt_cfg_free(&set);
76   xbt_cfg_free(&set);
77
78   fprintf(stderr,"==== Get multiple values (Expected: 'Count: 3; Options: mquinson;ecaron;alegrand;')\n");
79   set=make_set();
80   xbt_cfg_set_parse(set,"speed:42");
81   xbt_cfg_check(set);
82   xbt_cfg_get_dynar(set,"user",&dyn);
83   fprintf(stderr,"Count: %lu; Options: ",xbt_dynar_length(dyn));
84   xbt_dynar_foreach(dyn,ival,str) {
85     fprintf(stderr,"%s;",str);
86   }
87   fprintf(stderr,"\n");
88   xbt_cfg_free(&set);
89   xbt_cfg_free(&set);
90
91   xbt_exit();
92   return 0;
93 }
94