2 Unix SMB/CIFS implementation.
6 Copyright (C) Jelmer Vernooij 2005
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "torture/torture.h"
25 static const char *test_lists_shell_strings[] = {
35 static bool test_lists_shell(struct torture_context *tctx,
36 const void *test_data)
38 const char *data = (const char *)test_data;
39 const char **ret1, **ret2, *tmp;
41 TALLOC_CTX *mem_ctx = tctx;
43 ret1 = str_list_make_shell(mem_ctx, data, " ");
44 tmp = str_list_join_shell(mem_ctx, ret1, ' ');
45 ret2 = str_list_make_shell(mem_ctx, tmp, " ");
47 if ((ret1 == NULL || ret2 == NULL) && ret2 != ret1) {
51 for (j = 0; ret1[j] && ret2[j]; j++) {
52 if (strcmp(ret1[j], ret2[j]) != 0) {
58 if (ret1[j] || ret2[j])
62 torture_assert(tctx, match, talloc_asprintf(tctx,
63 "str_list_{make,join}_shell: Error double parsing, first run:\n%s\nSecond run: \n%s", data, tmp));
67 static bool test_list_copy(struct torture_context *tctx)
70 const char *list[] = { "foo", "bar", NULL };
71 const char *empty_list[] = { NULL };
72 const char **null_list = NULL;
74 result = (const char **)str_list_copy(tctx, list);
75 torture_assert_int_equal(tctx, str_list_length(result), 2, "list length");
76 torture_assert_str_equal(tctx, result[0], "foo", "element 0");
77 torture_assert_str_equal(tctx, result[1], "bar", "element 1");
78 torture_assert_str_equal(tctx, result[2], NULL, "element 2");
80 result = (const char **)str_list_copy(tctx, empty_list);
81 torture_assert_int_equal(tctx, str_list_length(result), 0, "list length");
82 torture_assert_str_equal(tctx, result[0], NULL, "element 0");
84 result = (const char **)str_list_copy(tctx, null_list);
85 torture_assert(tctx, result == NULL, "result NULL");
90 struct torture_suite *torture_local_util_strlist(TALLOC_CTX *mem_ctx)
92 struct torture_suite *suite = torture_suite_create(mem_ctx, "STRLIST");
95 for (i = 0; test_lists_shell_strings[i]; i++) {
96 torture_suite_add_simple_tcase_const(suite, "lists_shell",
97 test_lists_shell, &test_lists_shell_strings[i]);
100 torture_suite_add_simple_test(suite, "list_copy", test_list_copy);