r19339: Merge my 4.0-unittest branch. This adds an API for more fine-grained
[Samba.git] / source / torture / local / util_strlist.c
blob7dbb5f8ce6e8a9c51340e7baa049ba5a62863108
1 /*
2 Unix SMB/CIFS implementation.
4 util_strlist testing
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 2 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, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "includes.h"
24 #include "torture/torture.h"
26 static const char *test_lists_shell_strings[] = {
27 "",
28 "foo",
29 "foo bar",
30 "foo bar \"bla \"",
31 "foo \"\" bla",
32 "bla \"\"\"\" blie",
33 NULL
36 static bool test_lists_shell(struct torture_context *tctx,
37 const void *test_data)
39 const char *data = test_data;
40 const char **ret1, **ret2, *tmp;
41 BOOL match = True;
42 TALLOC_CTX *mem_ctx = tctx;
44 ret1 = str_list_make_shell(mem_ctx, data, " ");
45 tmp = str_list_join_shell(mem_ctx, ret1, ' ');
46 ret2 = str_list_make_shell(mem_ctx, tmp, " ");
48 if ((ret1 == NULL || ret2 == NULL) && ret2 != ret1) {
49 match = False;
50 } else {
51 int j;
52 for (j = 0; ret1[j] && ret2[j]; j++) {
53 if (strcmp(ret1[j], ret2[j]) != 0) {
54 match = False;
55 break;
59 if (ret1[j] || ret2[j])
60 match = False;
63 torture_assert(tctx, match, talloc_asprintf(tctx,
64 "str_list_{make,join}_shell: Error double parsing, first run:\n%s\nSecond run: \n%s", data, tmp));
65 return true;
68 struct torture_suite *torture_local_util_strlist(TALLOC_CTX *mem_ctx)
70 struct torture_suite *suite = torture_suite_create(mem_ctx, "STRLIST");
71 int i;
73 for (i = 0; test_lists_shell_strings[i]; i++) {
74 torture_suite_add_simple_tcase(suite,
75 "lists_shell", test_lists_shell,
76 &test_lists_shell_strings[i]);
79 return suite;