X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/2e6f84f33cb3de2fd4caa15b22953d84cbf56597..7177327de6a1fed71b87aad08702213c7db81ac1:/src/xbt/dict_test.cpp diff --git a/src/xbt/dict_test.cpp b/src/xbt/dict_test.cpp index 6cd12ea5d9..5facbd8a55 100644 --- a/src/xbt/dict_test.cpp +++ b/src/xbt/dict_test.cpp @@ -10,6 +10,7 @@ #include "simgrid/Exception.hpp" #include #include +#include #include "catch.hpp" @@ -86,11 +87,7 @@ static void traverse(xbt_dict_t head) int i = 0; xbt_dict_foreach (head, cursor, key, data) { - if (not key || not data || strcmp(key, data)) { - INFO("Seen #" << ++i << ": " << STR(key) << "->" << STR(data)); - } else { - INFO("Seen #" << ++i << ": " << STR(key)); - } + INFO("Seen #" << ++i << ": " << STR(key) << "->" << STR(data)); REQUIRE((key && data && strcmp(key, data) == 0)); // key != value } } @@ -282,29 +279,25 @@ TEST_CASE("xbt::dict: dict data container", "dict") search_ext(head, "null", nullptr); INFO("Check whether I see it while traversing..."); - { - xbt_dict_cursor_t cursor = nullptr; - char* key; - int found = 0; - char* data; - - xbt_dict_foreach (head, cursor, key, data) { - if (not key || not data || strcmp(key, data)) { - INFO("Seen: " << STR(key) << "->" << STR(data)); - } else { - INFO("Seen: " << STR(key)); - } - if (key && strcmp(key, "null") == 0) - found = 1; - } - REQUIRE(found); // the key 'null', associated to nullptr is not found + xbt_dict_cursor_t cursor = nullptr; + char* key; + bool found = false; + char* data; + + xbt_dict_foreach (head, cursor, key, data) { + INFO("Seen: " << STR(key) << "->" << STR(data)); + if (key && strcmp(key, "null") == 0) + found = true; } + REQUIRE(found); // the key 'null', associated to nullptr is not found + xbt_dict_free(&head); } SECTION("Crash test") { - srand((unsigned int)time(nullptr)); + std::random_device rd; + std::default_random_engine rnd_engine(rd()); for (int i = 0; i < 10; i++) { INFO("CRASH test number " << i + 1 << " (" << 10 - i - 1 << " to go)"); @@ -317,7 +310,7 @@ TEST_CASE("xbt::dict: dict data container", "dict") do { for (int k = 0; k < SIZEOFKEY - 1; k++) { - key[k] = rand() % ('z' - 'a') + 'a'; + key[k] = rnd_engine() % ('z' - 'a') + 'a'; } key[SIZEOFKEY - 1] = '\0'; data = (char*)xbt_dict_get_or_null(head, key);