util/strlist: Fix up "const" warnings in the string list and test code
authorMatthias Dieter Wallnöfer <mwallnoefer@yahoo.de>
Fri, 16 Oct 2009 17:06:29 +0000 (19:06 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 20 Nov 2009 15:50:47 +0000 (16:50 +0100)
This work I did using suggestions by Jelmer.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
lib/util/tests/strlist.c
lib/util/util.h
lib/util/util_strlist.c

index a974f581841f942f127a9aa178f63620e24157e1..8940dab4156462a59aa0db4b3125682c29fef7e1 100644 (file)
@@ -30,7 +30,7 @@ struct test_list_element {
        const char *list[5];
 };
 
-struct test_list_element test_lists_strings[] = {
+const struct test_list_element test_lists_strings[] = {
        {
                .list_as_string = "",
                .list = { NULL }
@@ -63,7 +63,7 @@ struct test_list_element test_lists_strings[] = {
        }
 };
 
-struct test_list_element test_lists_shell_strings[] = {
+const struct test_list_element test_lists_shell_strings[] = {
        {
                .list_as_string = "",
                .list = { NULL }
@@ -99,18 +99,18 @@ struct test_list_element test_lists_shell_strings[] = {
        }
 };
 
-static bool test_lists_shell(struct torture_context *tctx,
-                            const void *data)
+static bool test_lists_shell(struct torture_context *tctx, const void *data)
 {
        const struct test_list_element *element = data;
-       const char **ret1, **ret2, *tmp;
+
+       char **ret1, **ret2, *tmp;
        bool match = true;
        TALLOC_CTX *mem_ctx = tctx;
 
        ret1 = str_list_make_shell(mem_ctx, element->list_as_string, element->seperators);
        
        torture_assert(tctx, ret1, "str_list_make_shell() must not return NULL");
-       tmp = str_list_join_shell(mem_ctx, ret1, element->seperators ? *element->seperators : ' ');
+       tmp = str_list_join_shell(mem_ctx, (const char **) ret1, element->seperators ? *element->seperators : ' ');
        ret2 = str_list_make_shell(mem_ctx, tmp, element->seperators);
 
        if ((ret1 == NULL || ret2 == NULL) && ret2 != ret1) {
@@ -130,7 +130,8 @@ static bool test_lists_shell(struct torture_context *tctx,
 
        torture_assert(tctx, match, talloc_asprintf(tctx, 
                "str_list_{make,join}_shell: Error double parsing, first run:\n%s\nSecond run: \n%s", element->list_as_string, tmp));
-       torture_assert(tctx, str_list_equal(ret1, element->list), 
+       torture_assert(tctx, str_list_equal((const char * const *) ret1,
+                                           element->list),
                       talloc_asprintf(tctx, 
                                       "str_list_make_shell(%s) failed to create correct list", 
                                       element->list_as_string));
@@ -141,10 +142,12 @@ static bool test_lists_shell(struct torture_context *tctx,
 static bool test_list_make(struct torture_context *tctx, const void *data)
 {
        const struct test_list_element *element = data;
+
        char **result;
        result = str_list_make(tctx, element->list_as_string, element->seperators);
        torture_assert(tctx, result, "str_list_make() must not return NULL");
-       torture_assert(tctx, str_list_equal((const char **)result, element->list), 
+       torture_assert(tctx, str_list_equal((const char * const *) result,
+                                           element->list),
                       talloc_asprintf(tctx, 
                                       "str_list_make(%s) failed to create correct list", 
                                       element->list_as_string));
@@ -250,7 +253,7 @@ static bool test_list_length(struct torture_context *tctx)
 
 static bool test_list_add(struct torture_context *tctx)
 {
-       char **result, **result2;
+       const char **result, **result2;
        const char *list[] = {
                "element_0", 
                "element_1",
@@ -258,9 +261,9 @@ static bool test_list_add(struct torture_context *tctx)
                "element_3",
                NULL
        };
-       result = str_list_make(tctx, "element_0, element_1, element_2", NULL);
+       result = (const char **) str_list_make(tctx, "element_0, element_1, element_2", NULL);
        torture_assert(tctx, result, "str_list_make() must not return NULL");
-       result2 = str_list_add(result, "element_3");
+       result2 = str_list_add((const char **) result, "element_3");
        torture_assert(tctx, result2, "str_list_add() must not return NULL");
        torture_assert(tctx, str_list_equal(result2, list), 
                       "str_list_add() failed");
@@ -270,7 +273,7 @@ static bool test_list_add(struct torture_context *tctx)
 
 static bool test_list_add_const(struct torture_context *tctx)
 {
-       char **result, **result2;
+       const char **result, **result2;
        const char *list[] = {
                "element_0", 
                "element_1",
@@ -278,7 +281,7 @@ static bool test_list_add_const(struct torture_context *tctx)
                "element_3",
                NULL
        };
-       result = str_list_make(tctx, "element_0, element_1, element_2", NULL);
+       result = (const char **) str_list_make(tctx, "element_0, element_1, element_2", NULL);
        torture_assert(tctx, result, "str_list_make() must not return NULL");
        result2 = str_list_add_const(result, "element_3");
        torture_assert(tctx, result2, "str_list_add_const() must not return NULL");
@@ -290,14 +293,14 @@ static bool test_list_add_const(struct torture_context *tctx)
 
 static bool test_list_remove(struct torture_context *tctx)
 {
-       char **result;
+       const char **result;
        const char *list[] = {
                "element_0", 
                "element_1",
                "element_3",
                NULL
        };
-       result = str_list_make(tctx, "element_0, element_1, element_2, element_3", NULL);
+       result = (const char **) str_list_make(tctx, "element_0, element_1, element_2, element_3", NULL);
        torture_assert(tctx, result, "str_list_make() must not return NULL");
        str_list_remove(result, "element_2");
        torture_assert(tctx, str_list_equal(result, list), 
@@ -336,7 +339,7 @@ static bool test_list_check_ci(struct torture_context *tctx)
 
 static bool test_list_unique(struct torture_context *tctx)
 {
-       char **result;
+       const char **result;
        const char *list[] = {
                "element_0", 
                "element_1",
@@ -354,7 +357,7 @@ static bool test_list_unique(struct torture_context *tctx)
                "element_2",
                NULL
        };
-       result = str_list_copy(tctx, list_dup);
+       result = (const char **) str_list_copy(tctx, list_dup);
        /* We must copy the list, as str_list_unique does a talloc_realloc() on it's parameter */
        result = str_list_unique(result);
        torture_assert(tctx, result, "str_list_unique() must not return NULL");
@@ -398,7 +401,7 @@ static bool test_list_unique_2(struct torture_context *tctx)
 
 static bool test_list_append(struct torture_context *tctx)
 {
-       char **result;
+       const char **result;
        const char *list[] = {
                "element_0", 
                "element_1",
@@ -420,7 +423,7 @@ static bool test_list_append(struct torture_context *tctx)
                "element_5",
                NULL
        };
-       result = str_list_copy(tctx, list);
+       result = (const char **) str_list_copy(tctx, list);
        torture_assert(tctx, result, "str_list_copy() must not return NULL");
        result = str_list_append(result, list2);
        torture_assert(tctx, result, "str_list_append() must not return NULL");
@@ -432,7 +435,7 @@ static bool test_list_append(struct torture_context *tctx)
 
 static bool test_list_append_const(struct torture_context *tctx)
 {
-       char **result;
+       const char **result;
        const char *list[] = {
                "element_0", 
                "element_1",
@@ -454,7 +457,7 @@ static bool test_list_append_const(struct torture_context *tctx)
                "element_5",
                NULL
        };
-       result = str_list_copy(tctx, list);
+       result = (const char **) str_list_copy(tctx, list);
        torture_assert(tctx, result, "str_list_copy() must not return NULL");
        result = str_list_append_const(result, list2);
        torture_assert(tctx, result, "str_list_append_const() must not return NULL");
@@ -471,12 +474,12 @@ struct torture_suite *torture_local_util_strlist(TALLOC_CTX *mem_ctx)
 
        for (i = 0; i < ARRAY_SIZE(test_lists_shell_strings); i++) {
                torture_suite_add_simple_tcase_const(suite, "lists_shell",
-                               test_lists_shell, &test_lists_shell_strings[i]);
+                       test_lists_shell,  &test_lists_shell_strings[i]);
        }
 
        for (i = 0; i < ARRAY_SIZE(test_lists_strings); i++) {
-               torture_suite_add_simple_tcase_const(suite, "lists",
-                                                    test_list_make, &test_lists_strings[i]);
+               torture_suite_add_simple_tcase_const(suite, "list_make",
+                       test_list_make, &test_lists_strings[i]);
        }
 
        torture_suite_add_simple_test(suite, "list_copy", test_list_copy);
index 159f812d984d78ccf45848d2c0e288e558e06917..e7ea0ba5270c9c27496eed6d025f8898ae493bba 100644 (file)
@@ -477,7 +477,7 @@ _PUBLIC_ char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list);
 /**
    Return true if all the elements of the list match exactly.
  */
-_PUBLIC_ bool str_list_equal(const char **list1, const char **list2);
+_PUBLIC_ bool str_list_equal(const char * const *list1, const char * const *list2);
 
 /**
   add an entry to a string list
index 8d69eef23336fd8830684b4b73b664260222295f..71998b9a5c4110dd157401a8eefd67e18df6dd0e 100644 (file)
@@ -264,7 +264,8 @@ _PUBLIC_ char **str_list_copy(TALLOC_CTX *mem_ctx, const char **list)
 /**
    Return true if all the elements of the list match exactly.
  */
-_PUBLIC_ bool str_list_equal(const char **list1, const char **list2)
+_PUBLIC_ bool str_list_equal(const char * const *list1,
+                            const char * const *list2)
 {
        int i;