+ xbt_test_add("Having too much values of 'speed'");
+ xbt_cfg_set_parse("peername:toto:42 user:alegrand");
+ TRY {
+ xbt_cfg_set_parse("speed:42 speed:24 speed:34");
+ } CATCH(e) {
+ if (e.category != mismatch_error ||
+ strncmp(e.msg, "Cannot add value 34 to the config elem speed", strlen("Config elem speed needs")))
+ xbt_test_fail("Got an exception. msg=%s", e.msg);
+ xbt_ex_free(e);
+ }
+ xbt_cfg_check();
+ xbt_cfg_free(&simgrid_config);
+}
+
+XBT_TEST_UNIT("use", test_config_use, "Data retrieving tests")
+{
+ simgrid_config = make_set();
+ xbt_test_add("Get a single value");
+ {
+ /* get_single_value */
+ int ival;
+
+ xbt_cfg_set_parse("peername:toto:42 speed:42");
+ ival = xbt_cfg_get_int("speed");
+ if (ival != 42)
+ xbt_test_fail("Speed value = %d, I expected 42", ival);
+ }
+
+ xbt_test_add("Get multiple values");
+ {
+ /* get_multiple_value */
+ xbt_dynar_t dyn;
+
+ xbt_cfg_set_parse("peername:veloce user:foo\nuser:bar\tuser:toto");
+ xbt_cfg_set_parse("speed:42");
+ xbt_cfg_check();
+ dyn = xbt_cfg_get_dynar("user");
+
+ if (xbt_dynar_length(dyn) != 3)
+ xbt_test_fail("Dynar length = %lu, I expected 3", xbt_dynar_length(dyn));
+
+ if (strcmp(xbt_dynar_get_as(dyn, 0, char *), "foo"))
+ xbt_test_fail("Dynar[0] = %s, I expected foo", xbt_dynar_get_as(dyn, 0, char *));
+
+ if (strcmp(xbt_dynar_get_as(dyn, 1, char *), "bar"))
+ xbt_test_fail("Dynar[1] = %s, I expected bar", xbt_dynar_get_as(dyn, 1, char *));
+
+ if (strcmp(xbt_dynar_get_as(dyn, 2, char *), "toto"))
+ xbt_test_fail("Dynar[2] = %s, I expected toto", xbt_dynar_get_as(dyn, 2, char *));
+ }
+
+ xbt_test_add("Access to a non-existant entry");
+ {
+ xbt_ex_t e;
+
+ TRY {
+ xbt_cfg_set_parse("color:blue");
+ } CATCH(e) {
+ if (e.category != not_found_error)
+ xbt_test_exception(e);
+ xbt_ex_free(e);
+ }
+ }
+ xbt_cfg_free(&simgrid_config);