Logo AND Algorithmique Numérique Distribuée

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