X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/cf2261b8e065347d0fa26473f4b808e50b81e451..406f54970c00ca178fa918763d943027bd09e3ba:/src/xbt/set.c diff --git a/src/xbt/set.c b/src/xbt/set.c index 4de1a1726a..eb09a357fb 100644 --- a/src/xbt/set.c +++ b/src/xbt/set.c @@ -57,7 +57,7 @@ void xbt_set_free(xbt_set_t * set) static int _xbt_set_get_id(xbt_set_t set) { int id; - if (xbt_dynar_length(set->available_ids) > 0) { + if (!xbt_dynar_is_empty(set->available_ids)) { /* if there are some available ids */ xbt_dynar_pop(set->available_ids, &id); } else { @@ -71,7 +71,7 @@ static int _xbt_set_get_id(xbt_set_t set) * * \param set set to populate * \param elm element to add. - * \param free_func How to add the data + * \param free_func how to free the data * * elm->name must be set; * if elm->name_len <= 0, it is recomputed. If >0, it's used as is; @@ -85,7 +85,7 @@ void xbt_set_add(xbt_set_t set, xbt_set_elm_t elm, xbt_set_elm_t found_in_dict = NULL; xbt_ex_t e; - VERB1("add %s to the set", elm->name); + XBT_VERB("add %s to the set", elm->name); if (elm->name_len <= 0) { elm->name_len = strlen(elm->name); @@ -101,19 +101,19 @@ void xbt_set_add(xbt_set_t set, xbt_set_elm_t elm, elm->ID = _xbt_set_get_id(set); xbt_dict_set_ext(set->dict, elm->name, elm->name_len, elm, free_func); xbt_dynar_set(set->dynar, elm->ID, &elm); - DEBUG2("Insertion of key '%s' (id %d)", elm->name, elm->ID); + XBT_DEBUG("Insertion of key '%s' (id %u)", elm->name, elm->ID); xbt_ex_free(e); } if (found) { if (elm == found_in_dict) { - DEBUG2 - ("Ignoring request to insert the same element twice (key %s ; id %d)", + XBT_DEBUG + ("Ignoring request to insert the same element twice (key %s ; id %u)", elm->name, elm->ID); return; } else { elm->ID = found_in_dict->ID; - DEBUG2("Reinsertion of key %s (id %d)", elm->name, elm->ID); + XBT_DEBUG("Reinsertion of key %s (id %u)", elm->name, elm->ID); xbt_dict_set_ext(set->dict, elm->name, elm->name_len, elm, free_func); xbt_dynar_set(set->dynar, elm->ID, &elm); @@ -180,7 +180,7 @@ void xbt_set_remove_by_id(xbt_set_t set, int id) */ xbt_set_elm_t xbt_set_get_by_name(xbt_set_t set, const char *name) { - DEBUG1("Lookup key %s", name); + XBT_DEBUG("Lookup key %s", name); return xbt_dict_get(set->dict, name); } @@ -192,7 +192,7 @@ xbt_set_elm_t xbt_set_get_by_name(xbt_set_t set, const char *name) */ xbt_set_elm_t xbt_set_get_by_name_or_null(xbt_set_t set, const char *name) { - DEBUG1("Lookup key %s", name); + XBT_DEBUG("Lookup key %s", name); return xbt_dict_get_or_null(set->dict, name); } @@ -229,9 +229,9 @@ xbt_set_elm_t xbt_set_get_by_id(xbt_set_t set, int id) res = xbt_dynar_get_as(set->dynar, id, xbt_set_elm_t); if (res == NULL) { - THROW1(not_found_error, 0, "Invalid id: %d", id); + THROWF(not_found_error, 0, "Invalid id: %d", id); } - DEBUG3("Lookup type of id %d (of %lu): %s", + XBT_DEBUG("Lookup type of id %d (of %lu): %s", id, xbt_dynar_length(set->dynar), res->name); return res; @@ -262,9 +262,9 @@ void xbt_set_cursor_first(xbt_set_t set, xbt_set_cursor_t * cursor) if (set != NULL) { if (!*cursor) { - DEBUG0("Create the cursor on first use"); + XBT_DEBUG("Create the cursor on first use"); *cursor = xbt_new(s_xbt_set_cursor_t, 1); - xbt_assert0(*cursor, + xbt_assert(*cursor, "Malloc error during the creation of the cursor"); } (*cursor)->set = set; @@ -354,13 +354,13 @@ static void debuged_add(xbt_set_t set, const char *name, const char *data) elm->data = xbt_strdup(data); - xbt_test_log2("Add %s (->%s)", name, data); + xbt_test_log("Add %s (->%s)", name, data); xbt_set_add(set, (xbt_set_elm_t) elm, &my_elem_free); } static void fill(xbt_set_t * set) { - xbt_test_add0("Fill in the data set"); + xbt_test_add("Fill in the data set"); *set = xbt_set_new(); debuged_add(*set, "12", "12"); @@ -368,9 +368,9 @@ static void fill(xbt_set_t * set) debuged_add(*set, "12b", "12b"); debuged_add(*set, "123", "123"); debuged_add(*set, "123456", "123456"); - xbt_test_log0("Child becomes child of what to add"); + xbt_test_log("Child becomes child of what to add"); debuged_add(*set, "1234", "1234"); - xbt_test_log0("Need of common ancestor"); + xbt_test_log("Need of common ancestor"); debuged_add(*set, "123457", "123457"); } @@ -378,15 +378,15 @@ static void search_name(xbt_set_t head, const char *key) { my_elem_t elm; - xbt_test_add1("Search by name %s", key); + xbt_test_add("Search by name %s", key); elm = (my_elem_t) xbt_set_get_by_name(head, key); - xbt_test_log2(" Found %s (under ID %d)\n", + xbt_test_log(" Found %s (under ID %u)\n", elm ? elm->data : "(null)", elm ? elm->ID : -1); if (strcmp(key, elm->name)) - THROW2(mismatch_error, 0, "The key (%s) is not the one expected (%s)", + THROWF(mismatch_error, 0, "The key (%s) is not the one expected (%s)", key, elm->name); if (strcmp(elm->name, elm->data)) - THROW2(mismatch_error, 0, "The name (%s) != data (%s)", key, + THROWF(mismatch_error, 0, "The name (%s) != data (%s)", key, elm->name); fflush(stdout); } @@ -395,18 +395,18 @@ static void search_id(xbt_set_t head, int id, const char *key) { my_elem_t elm; - xbt_test_add1("Search by id %d", id); + xbt_test_add("Search by id %d", id); elm = (my_elem_t) xbt_set_get_by_id(head, id); - xbt_test_log2("Found %s (data %s)", + xbt_test_log("Found %s (data %s)", elm ? elm->name : "(null)", elm ? elm->data : "(null)"); if (id != elm->ID) - THROW2(mismatch_error, 0, - "The found ID (%d) is not the one expected (%d)", elm->ID, id); + THROWF(mismatch_error, 0, + "The found ID (%u) is not the one expected (%d)", elm->ID, id); if (strcmp(key, elm->name)) - THROW2(mismatch_error, 0, "The key (%s) is not the one expected (%s)", + THROWF(mismatch_error, 0, "The key (%s) is not the one expected (%s)", elm->name, key); if (strcmp(elm->name, elm->data)) - THROW2(mismatch_error, 0, "The name (%s) != data (%s)", + THROWF(mismatch_error, 0, "The name (%s) != data (%s)", elm->name, elm->data); } @@ -417,9 +417,9 @@ static void traverse(xbt_set_t set) my_elem_t elm = NULL; xbt_set_foreach(set, cursor, elm) { - xbt_test_assert0(elm, "Dude ! Got a null elm during traversal!"); - xbt_test_log3("Id(%d): %s->%s\n", elm->ID, elm->name, elm->data); - xbt_test_assert2(!strcmp(elm->name, elm->data), + xbt_test_assert(elm, "Dude ! Got a null elm during traversal!"); + xbt_test_log("Id(%u): %s->%s\n", elm->ID, elm->name, elm->data); + xbt_test_assert(!strcmp(elm->name, elm->data), "Key(%s) != value(%s). Abording", elm->name, elm->data); } @@ -429,12 +429,13 @@ static void search_not_found(xbt_set_t set, const char *data) { xbt_ex_t e; - xbt_test_add1("Search %s (expected not to be found)", data); + xbt_test_add("Search %s (expected not to be found)", data); TRY { xbt_set_get_by_name(set, data); - THROW1(unknown_error, 0, + THROWF(unknown_error, 0, "Found something which shouldn't be there (%s)", data); - } CATCH(e) { + } + CATCH(e) { if (e.category != not_found_error) xbt_test_exception(e); xbt_ex_free(e); @@ -448,14 +449,14 @@ XBT_TEST_UNIT("basic", test_set_basic, "Basic usage") { set = NULL; - xbt_test_add0("Traverse the empty set"); + xbt_test_add("Traverse the empty set"); traverse(set); - xbt_test_add0("Free a data set"); + xbt_test_add("Free a data set"); fill(&set); xbt_set_free(&set); - xbt_test_add0("Free the NULL data set"); + xbt_test_add("Free the NULL data set"); xbt_set_free(&set); } @@ -464,20 +465,20 @@ XBT_TEST_UNIT("change", test_set_change, "Changing some values") { fill(&set); - xbt_test_add0("Change 123 to 'Changed 123'"); + xbt_test_add("Change 123 to 'Changed 123'"); debuged_add(set, "123", "Changed 123"); - xbt_test_add0("Change 123 back to '123'"); + xbt_test_add("Change 123 back to '123'"); debuged_add(set, "123", "123"); - xbt_test_add0("Change 12a to 'Dummy 12a'"); + xbt_test_add("Change 12a to 'Dummy 12a'"); debuged_add(set, "12a", "Dummy 12a"); - xbt_test_add0("Change 12a to '12a'"); + xbt_test_add("Change 12a to '12a'"); debuged_add(set, "12a", "12a"); /* xbt_dict_dump(head,(void (*)(void*))&printf); */ - xbt_test_add0("Traverse the resulting data set"); + xbt_test_add("Traverse the resulting data set"); traverse(set); } @@ -485,9 +486,9 @@ XBT_TEST_UNIT("retrieve", test_set_retrieve, "Retrieving some values") { my_elem_t elm; - xbt_test_add0("Search 123"); + xbt_test_add("Search 123"); elm = (my_elem_t) xbt_set_get_by_name(set, "123"); - xbt_test_assert0(elm, "elm must be there"); + xbt_test_assert(elm, "elm must be there"); xbt_assert(!strcmp("123", elm->data)); search_not_found(set, "Can't be found"); @@ -510,16 +511,16 @@ XBT_TEST_UNIT("retrieve", test_set_retrieve, "Retrieving some values") search_id(set, 5, "1234"); search_id(set, 6, "123457"); - xbt_test_add0("Traverse the resulting data set"); + xbt_test_add("Traverse the resulting data set"); traverse(set); /* xbt_dict_dump(head,(void (*)(void*))&printf); */ - xbt_test_add0("Free the data set (twice)"); + xbt_test_add("Free the data set (twice)"); xbt_set_free(&set); xbt_set_free(&set); - xbt_test_add0("Traverse the resulting data set"); + xbt_test_add("Traverse the resulting data set"); traverse(set); } @@ -548,7 +549,7 @@ XBT_TEST_UNIT("remove", test_set_remove, "Removing some values") debuged_add(set, "12anew", "12anew"); elm = (my_elem_t) xbt_set_get_by_id(set, 1); - xbt_test_assert1(elm->ID == 1, "elm->ID is %d but should be 1", elm->ID); + xbt_test_assert(elm->ID == 1, "elm->ID is %u but should be 1", elm->ID); xbt_set_free(&set); }