r14720: Add torture_context argument to all torture tests
[samba.git] / source4 / torture / local / util_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 2 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, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "torture/torture.h"
25
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
34 };
35
36 static BOOL test_lists_shell(TALLOC_CTX *mem_ctx)
37 {
38         int i;
39         for (i = 0; test_lists_shell_strings[i]; i++) {
40                 const char **ret1, **ret2, *tmp;
41                 BOOL match = True;
42
43                 ret1 = str_list_make_shell(mem_ctx, test_lists_shell_strings[i], " ");
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                 if (!match) {
63                         printf("str_list_{make,join}_shell: Error double parsing, first run:\n%s\nSecond run: \n%s\n", 
64                                    test_lists_shell_strings[i],
65                                    tmp);
66                         return False;
67                 }
68         }
69
70         return True;
71 }
72
73 BOOL torture_local_util_strlist(struct torture_context *torture) 
74 {
75         BOOL ret = True;
76         TALLOC_CTX *mem_ctx = talloc_init("test_util_strlist");
77
78         ret &= test_lists_shell(mem_ctx);
79         talloc_free(mem_ctx);
80
81         return ret;
82 }