#include "simgrid/Exception.hpp"
#include <cstdio>
#include <cstring>
+#include <random>
#include "catch.hpp"
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
}
}
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)");
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);