r23792: convert Samba4 to GPLv3
[amitay/samba.git] / source4 / lib / util / tests / strlist.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    util_strlist testing
5
6    Copyright (C) Jelmer Vernooij 2005
7    
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.
12    
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.
17    
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/>.
20 */
21
22 #include "includes.h"
23 #include "torture/torture.h"
24
25 static const char *test_lists_shell_strings[] = {
26         "",
27         "foo",
28         "foo bar",
29         "foo bar \"bla \"",
30         "foo \"\" bla",
31         "bla \"\"\"\" blie",
32         NULL
33 };
34
35 static bool test_lists_shell(struct torture_context *tctx,
36                                                          const void *test_data)
37 {
38         const char *data = test_data;
39         const char **ret1, **ret2, *tmp;
40         BOOL match = True;
41         TALLOC_CTX *mem_ctx = tctx;
42
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, " ");
46
47         if ((ret1 == NULL || ret2 == NULL) && ret2 != ret1) {
48                 match = False;
49         } else {
50                 int j;
51                 for (j = 0; ret1[j] && ret2[j]; j++) {
52                         if (strcmp(ret1[j], ret2[j]) != 0) {
53                                 match = False;
54                                 break;
55                         }
56                 }
57
58                 if (ret1[j] || ret2[j])
59                         match = False;
60         }
61
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));
64         return true;
65 }
66
67 struct torture_suite *torture_local_util_strlist(TALLOC_CTX *mem_ctx)
68 {
69         struct torture_suite *suite = torture_suite_create(mem_ctx, "STRLIST");
70         int i;
71
72         for (i = 0; test_lists_shell_strings[i]; i++) {
73                 torture_suite_add_simple_tcase(suite, 
74                                                                            "lists_shell", test_lists_shell,
75                                                                            &test_lists_shell_strings[i]);
76         }
77
78         return suite;
79 }