A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
typos
[simgrid.git]
/
src
/
xbt
/
dict_test.cpp
diff --git
a/src/xbt/dict_test.cpp
b/src/xbt/dict_test.cpp
index dd2fc82a5d46c091bb44bb9dd7021d027c531490..bd54663bb87e977d3bb1050cf60736b6439be13d 100644
(file)
--- a/
src/xbt/dict_test.cpp
+++ b/
src/xbt/dict_test.cpp
@@
-10,16
+10,12
@@
#include "simgrid/Exception.hpp"
#include <cstdio>
#include <cstring>
#include "simgrid/Exception.hpp"
#include <cstdio>
#include <cstring>
+#include <random>
#include "catch.hpp"
#define STR(str) ((str) ? (str) : "(null)")
#include "catch.hpp"
#define STR(str) ((str) ? (str) : "(null)")
-#define REQUIRE_THROWS_XBT_EX(...) \
- REQUIRE_THROWS_MATCHES((__VA_ARGS__), xbt_ex, Catch::Matchers::Predicate<xbt_ex>( \
- [](xbt_ex const& e) { return e.category == not_found_error; }, \
- "category not_found_error"))
-
static constexpr int NB_ELM = 20000;
static constexpr int SIZEOFKEY = 1024;
static constexpr int NB_ELM = 20000;
static constexpr int SIZEOFKEY = 1024;
@@
-94,7
+90,7
@@
static void traverse(xbt_dict_t head)
static void search_not_found(xbt_dict_t head, const char* data)
{
INFO("Search " << STR(data) << " (expected not to be found)");
static void search_not_found(xbt_dict_t head, const char* data)
{
INFO("Search " << STR(data) << " (expected not to be found)");
- REQUIRE_THROWS_
XBT_EX(data = (const char*)xbt_dict_get(head, data)
);
+ REQUIRE_THROWS_
AS(xbt_dict_get(head, data), std::out_of_range
);
}
static void count(xbt_dict_t dict, int length)
}
static void count(xbt_dict_t dict, int length)
@@
-155,7
+151,7
@@
TEST_CASE("xbt::dict: dict data container", "dict")
INFO("Traversal and search the empty dictionary");
xbt_dict_t head = xbt_dict_new_homogeneous(&free);
traverse(head);
INFO("Traversal and search the empty dictionary");
xbt_dict_t head = xbt_dict_new_homogeneous(&free);
traverse(head);
- REQUIRE_THROWS_
XBT_EX(debugged_remove(head, "12346")
);
+ REQUIRE_THROWS_
AS(debugged_remove(head, "12346"), std::out_of_range
);
xbt_dict_free(&head);
INFO("Traverse the full dictionary");
xbt_dict_free(&head);
INFO("Traverse the full dictionary");
@@
-227,7
+223,7
@@
TEST_CASE("xbt::dict: dict data container", "dict")
xbt_dict_t head = new_fixture();
count(head, 7);
INFO("Remove non existing data");
xbt_dict_t head = new_fixture();
count(head, 7);
INFO("Remove non existing data");
- REQUIRE_THROWS_
XBT_EX(debugged_remove(head, "Does not exist")
);
+ REQUIRE_THROWS_
AS(debugged_remove(head, "Does not exist"), std::out_of_range
);
traverse(head);
xbt_dict_free(&head);
traverse(head);
xbt_dict_free(&head);
@@
-246,7
+242,7
@@
TEST_CASE("xbt::dict: dict data container", "dict")
debugged_remove(head, "123456");
traverse(head);
count(head, 3);
debugged_remove(head, "123456");
traverse(head);
count(head, 3);
- REQUIRE_THROWS_
XBT_EX(debugged_remove(head, "12346")
);
+ REQUIRE_THROWS_
AS(debugged_remove(head, "12346"), std::out_of_range
);
traverse(head);
debugged_remove(head, "1234");
traverse(head);
traverse(head);
debugged_remove(head, "1234");
traverse(head);
@@
-254,7
+250,7
@@
TEST_CASE("xbt::dict: dict data container", "dict")
traverse(head);
debugged_remove(head, "123");
traverse(head);
traverse(head);
debugged_remove(head, "123");
traverse(head);
- REQUIRE_THROWS_
XBT_EX(debugged_remove(head, "12346")
);
+ REQUIRE_THROWS_
AS(debugged_remove(head, "12346"), std::out_of_range
);
traverse(head);
INFO("Free dict, create new fresh one, and then reset the dict");
traverse(head);
INFO("Free dict, create new fresh one, and then reset the dict");
@@
-295,7
+291,8
@@
TEST_CASE("xbt::dict: dict data container", "dict")
SECTION("Crash test")
{
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)");
for (int i = 0; i < 10; i++) {
INFO("CRASH test number " << i + 1 << " (" << 10 - i - 1 << " to go)");
@@
-308,7
+305,7
@@
TEST_CASE("xbt::dict: dict data container", "dict")
do {
for (int k = 0; k < SIZEOFKEY - 1; k++) {
do {
for (int k = 0; k < SIZEOFKEY - 1; k++) {
- key[k] = r
and
() % ('z' - 'a') + 'a';
+ key[k] = r
nd_engine
() % ('z' - 'a') + 'a';
}
key[SIZEOFKEY - 1] = '\0';
data = (char*)xbt_dict_get_or_null(head, key);
}
key[SIZEOFKEY - 1] = '\0';
data = (char*)xbt_dict_get_or_null(head, key);