Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Initial structure. Nothing works yet.
[simgrid.git] / src / config_unit.c
1 /*******************************/
2 /* GENERATED FILE, DO NOT EDIT */
3 /*******************************/
4
5 #include "xbt.h"
6 /*******************************/
7 /* GENERATED FILE, DO NOT EDIT */
8 /*******************************/
9
10 # 1143 "xbt/config.c" 
11 #include "xbt.h"
12 #include "xbt/ex.h"
13
14
15 static xbt_cfg_t make_set(){
16   xbt_cfg_t set=NULL; 
17
18   set = xbt_cfg_new();
19   xbt_cfg_register_str(set,"speed:1_to_2_int");
20   xbt_cfg_register_str(set,"peername:1_to_1_string");
21   xbt_cfg_register_str(set,"user:1_to_10_string");
22
23   return set;
24 } /* end_of_make_set */
25
26 XBT_TEST_UNIT("memuse",test_config_memuse,"Alloc and free a config set") {
27   xbt_cfg_t set=make_set();
28   xbt_test_add0("Alloc and free a config set");
29   xbt_cfg_set_parse(set, "peername:veloce user:mquinson\nuser:oaumage\tuser:alegrand");
30   xbt_cfg_free(&set);
31   xbt_cfg_free(&set);
32 }
33
34 XBT_TEST_UNIT("validation",test_config_validation,"Validation tests") {
35   xbt_cfg_t set = set=make_set();
36   xbt_ex_t e;
37   
38   xbt_test_add0("Having too few elements for speed");
39   xbt_cfg_set_parse(set, "peername:veloce user:mquinson\nuser:oaumage\tuser:alegrand");
40   TRY {
41     xbt_cfg_check(set);
42   } CATCH(e) {
43     if (e.category != mismatch_error || 
44         strncmp(e.msg,"Config elem speed needs",strlen("Config elem speed needs")))
45       xbt_test_fail1("Got an exception. msg=%s",e.msg);
46     xbt_ex_free(e);
47   }
48   xbt_cfg_free(&set);
49   xbt_cfg_free(&set);
50
51
52
53   xbt_test_add0("Having too much values of 'speed'");
54   set=make_set(); 
55   xbt_cfg_set_parse(set,"peername:toto:42 user:alegrand");
56   TRY {
57     xbt_cfg_set_parse(set,"speed:42 speed:24 speed:34");
58   } CATCH(e) {
59     if (e.category != mismatch_error ||
60         strncmp(e.msg,"Cannot add value 34 to the config elem speed",
61                 strlen("Config elem speed needs")))
62       xbt_test_fail1("Got an exception. msg=%s",e.msg);
63     xbt_ex_free(e);
64   }
65   xbt_cfg_check(set);
66   xbt_cfg_free(&set);
67   xbt_cfg_free(&set);
68
69 }
70
71 XBT_TEST_UNIT("use",test_config_use,"Data retrieving tests") {
72
73   xbt_test_add0("Get a single value");
74   {     
75     /* get_single_value */
76     int ival;
77     xbt_cfg_t myset=make_set();
78     
79     xbt_cfg_set_parse(myset,"peername:toto:42 speed:42");
80     ival = xbt_cfg_get_int(myset,"speed"); 
81     if (ival != 42) 
82       xbt_test_fail1("Speed value = %d, I expected 42",ival);
83     xbt_cfg_free(&myset);
84   }
85
86   xbt_test_add0("Get multiple values");
87   {     
88     /* get_multiple_value */
89     xbt_dynar_t dyn; 
90     xbt_cfg_t myset=make_set();
91     
92     xbt_cfg_set_parse(myset, "peername:veloce user:foo\nuser:bar\tuser:toto");
93     xbt_cfg_set_parse(myset,"speed:42");
94     xbt_cfg_check(myset); 
95     dyn = xbt_cfg_get_dynar(myset,"user");
96
97     if (xbt_dynar_length(dyn) != 3) 
98       xbt_test_fail1("Dynar length = %d, I expected 3", (int)xbt_dynar_length(dyn));
99
100     if (strcmp(xbt_dynar_get_as(dyn,0,char*),"foo"))
101       xbt_test_fail1("Dynar[0] = %s, I expected foo",   xbt_dynar_get_as(dyn,0,char*));
102
103     if (strcmp(xbt_dynar_get_as(dyn,1,char*),"bar"))
104       xbt_test_fail1("Dynar[1] = %s, I expected bar",   xbt_dynar_get_as(dyn,1,char*));
105
106     if (strcmp(xbt_dynar_get_as(dyn,2,char*),"toto"))
107       xbt_test_fail1("Dynar[2] = %s, I expected toto",  xbt_dynar_get_as(dyn,2,char*));
108     xbt_cfg_free(&myset);    
109   }
110   
111   xbt_test_add0("Access to a non-existant entry");
112   {     
113     /* non-existant_entry */
114     xbt_cfg_t myset=make_set();
115     xbt_ex_t e;
116     
117     TRY {
118       xbt_cfg_set_parse(myset, "color:blue");
119     } CATCH(e) {
120       if (e.category != not_found_error)
121         xbt_test_exception(e);
122       xbt_ex_free(e);
123     }
124     xbt_cfg_free(&myset);    
125   }
126 }
127 /*******************************/
128 /* GENERATED FILE, DO NOT EDIT */
129 /*******************************/
130