Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Another bunch of const qualifiers.
[simgrid.git] / src / xbt / dict_test.cpp
index bd54663..f24acad 100644 (file)
@@ -25,7 +25,7 @@ static void debugged_add_ext(xbt_dict_t head, const char* key, const char* data_
 
   INFO("Add " << STR(data_to_fill) << " under " << STR(key));
 
-  xbt_dict_set(head, key, data, nullptr);
+  xbt_dict_set(head, key, data);
 }
 
 static void debugged_add(xbt_dict_t head, const char* key)
@@ -49,7 +49,7 @@ static xbt_dict_t new_fixture()
   return head;
 }
 
-static void search_ext(xbt_dict_t head, const char* key, const char* data)
+static void search_ext(const_xbt_dict_t head, const char* key, const char* data)
 {
   INFO("Search " << STR(key));
   char* found = (char*)xbt_dict_get(head, key);
@@ -63,7 +63,7 @@ static void search_ext(xbt_dict_t head, const char* key, const char* data)
   }
 }
 
-static void search(xbt_dict_t head, const char* key)
+static void search(const_xbt_dict_t head, const char* key)
 {
   search_ext(head, key, key);
 }
@@ -74,7 +74,7 @@ static void debugged_remove(xbt_dict_t head, const char* key)
   xbt_dict_remove(head, key);
 }
 
-static void traverse(xbt_dict_t head)
+static void traverse(const_xbt_dict_t head)
 {
   xbt_dict_cursor_t cursor = nullptr;
   char* key;
@@ -87,13 +87,13 @@ static void traverse(xbt_dict_t head)
   }
 }
 
-static void search_not_found(xbt_dict_t head, const char* data)
+static void search_not_found(const_xbt_dict_t head, const char* data)
 {
   INFO("Search " << STR(data) << " (expected not to be found)");
   REQUIRE_THROWS_AS(xbt_dict_get(head, data), std::out_of_range);
 }
 
-static void count(xbt_dict_t dict, int length)
+static void count(const_xbt_dict_t dict, int length)
 {
   INFO("Count elements (expecting " << length << ")");
   REQUIRE(xbt_dict_length(dict) == length); // Announced length differs
@@ -108,7 +108,7 @@ static void count(xbt_dict_t dict, int length)
   REQUIRE(effective == length); // Effective length differs
 }
 
-static void count_check_get_key(xbt_dict_t dict, int length)
+static void count_check_get_key(const_xbt_dict_t dict, int length)
 {
   xbt_dict_cursor_t cursor;
   char* key;
@@ -127,7 +127,7 @@ static void count_check_get_key(xbt_dict_t dict, int length)
   REQUIRE(effective == length); // Effective length differs
 }
 
-static int countelems(xbt_dict_t head)
+static int countelems(const_xbt_dict_t head)
 {
   xbt_dict_cursor_t cursor;
   char* key;
@@ -142,7 +142,6 @@ static int countelems(xbt_dict_t head)
 
 TEST_CASE("xbt::dict: dict data container", "dict")
 {
-
   SECTION("Basic usage: change, retrieve and traverse homogeneous dicts")
   {
     INFO("Traversal the null dictionary");
@@ -173,19 +172,19 @@ TEST_CASE("xbt::dict: dict data container", "dict")
     head = new_fixture();
     count_check_get_key(head, 7);
     INFO("Change 123 to 'Changed 123'");
-    xbt_dict_set(head, "123", xbt_strdup("Changed 123"), nullptr);
+    xbt_dict_set(head, "123", xbt_strdup("Changed 123"));
     count_check_get_key(head, 7);
 
     INFO("Change 123 back to '123'");
-    xbt_dict_set(head, "123", xbt_strdup("123"), nullptr);
+    xbt_dict_set(head, "123", xbt_strdup("123"));
     count_check_get_key(head, 7);
 
     INFO("Change 12a to 'Dummy 12a'");
-    xbt_dict_set(head, "12a", xbt_strdup("Dummy 12a"), nullptr);
+    xbt_dict_set(head, "12a", xbt_strdup("Dummy 12a"));
     count_check_get_key(head, 7);
 
     INFO("Change 12a to '12a'");
-    xbt_dict_set(head, "12a", xbt_strdup("12a"), nullptr);
+    xbt_dict_set(head, "12a", xbt_strdup("12a"));
     count_check_get_key(head, 7);
 
     INFO("Traverse the resulting dictionary");
@@ -193,7 +192,7 @@ TEST_CASE("xbt::dict: dict data container", "dict")
 
     /* RETRIEVE */
     INFO("Search 123");
-    char* data = (char*)xbt_dict_get(head, "123");
+    const char* data = (char*)xbt_dict_get(head, "123");
     REQUIRE((data && strcmp("123", data) == 0));
 
     search_not_found(head, "Can't be found");
@@ -270,7 +269,7 @@ TEST_CASE("xbt::dict: dict data container", "dict")
     xbt_dict_t head = new_fixture();
 
     INFO("Store nullptr under 'null'");
-    xbt_dict_set(head, "null", nullptr, nullptr);
+    xbt_dict_set(head, "null", nullptr);
     search_ext(head, "null", nullptr);
 
     INFO("Check whether I see it while traversing...");
@@ -300,7 +299,7 @@ TEST_CASE("xbt::dict: dict data container", "dict")
       INFO("using 1000 elements with " << SIZEOFKEY << " chars long randomized keys.");
       xbt_dict_t head = xbt_dict_new_homogeneous(free);
       for (int j = 0; j < 1000; j++) {
-        char* data = nullptr;
+        const char* data = nullptr;
         char* key  = (char*)xbt_malloc(SIZEOFKEY);
 
         do {
@@ -311,7 +310,7 @@ TEST_CASE("xbt::dict: dict data container", "dict")
           data               = (char*)xbt_dict_get_or_null(head, key);
         } while (data != nullptr);
 
-        xbt_dict_set(head, key, key, nullptr);
+        xbt_dict_set(head, key, key);
         data = (char*)xbt_dict_get(head, key);
         REQUIRE(not strcmp(key, data)); // Retrieved value != Injected value
 
@@ -328,7 +327,7 @@ TEST_CASE("xbt::dict: dict data container", "dict")
       char* key = (char*)xbt_malloc(10);
 
       snprintf(key, 10, "%d", j);
-      xbt_dict_set(head, key, key, nullptr);
+      xbt_dict_set(head, key, key);
     }
 
     INFO("Count the elements (retrieving the key and data for each)");
@@ -360,15 +359,15 @@ TEST_CASE("xbt::dict: dict data container", "dict")
     xbt_dict_free(&head);
   }
 
-  SECTION("Test dictionnary with int keys")
+  SECTION("Test dictionary with int keys")
   {
     xbt_dict_t dict = xbt_dict_new_homogeneous(nullptr);
     int count       = 500;
 
     INFO("Insert elements");
     for (int i = 0; i < count; ++i)
-      xbt_dict_set_ext(dict, (char*)&i, sizeof(i), (void*)(intptr_t)i, nullptr);
-    REQUIRE(xbt_dict_size(dict) == (unsigned)count); // Bad number of elements in the dictionnary
+      xbt_dict_set_ext(dict, (char*)&i, sizeof(i), (void*)(intptr_t)i);
+    REQUIRE(xbt_dict_size(dict) == (unsigned)count); // Bad number of elements in the dictionary
 
     INFO("Check elements");
     for (int i = 0; i < count; ++i) {