Logo AND Algorithmique Numérique Distribuée

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