/* [<][>][^][v][top][bottom][index][help] */
DEFINITIONS
This source file includes following definitions.
- test_list_empty
- test_create
- test_create_invalid
- test_share_remove_invalid
- test_share_remove
- test_double_create
- tcase_add_share_tests
- setup_ldb
- setup_classic
- teardown
- torture_local_share
1 /*
2 Unix SMB/CIFS implementation.
3
4 local testing of share code
5
6 Copyright (C) Jelmer Vernooij 2007
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 "param/share.h"
24 #include "param/param.h"
25 #include "torture/torture.h"
26
27 static bool test_list_empty(struct torture_context *tctx,
/* [<][>][^][v][top][bottom][index][help] */
28 const void *tcase_data,
29 const void *test_data)
30 {
31 struct share_context *ctx = (struct share_context *)discard_const(tcase_data);
32 int count;
33 const char **names;
34
35 torture_assert_ntstatus_ok(tctx, share_list_all(tctx, ctx, &count, &names),
36 "share_list_all failed");
37
38 return true;
39 }
40
41 static bool test_create(struct torture_context *tctx,
/* [<][>][^][v][top][bottom][index][help] */
42 const void *tcase_data,
43 const void *test_data)
44 {
45 struct share_context *ctx = (struct share_context *)discard_const(tcase_data);
46 int count;
47 const char **names;
48 int i;
49 bool found = false;
50 struct share_info inf[] = {
51 { SHARE_INFO_STRING, SHARE_TYPE, discard_const_p(void *, "IPC$") },
52 { SHARE_INFO_STRING, SHARE_PATH, discard_const_p(void *, "/tmp/bla") }
53 };
54 NTSTATUS status;
55
56 status = share_create(ctx, "bloe", inf, 2);
57
58 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
59 torture_skip(tctx, "Not supported by backend");
60
61 torture_assert_ntstatus_ok(tctx, status, "create_share failed");
62
63 torture_assert_ntstatus_ok(tctx, share_list_all(tctx, ctx, &count, &names),
64 "share_list_all failed");
65
66 torture_assert(tctx, count >= 1, "creating share failed");
67
68
69 for (i = 0; i < count; i++) {
70 found |= strcmp(names[i], "bloe") == 0;
71 }
72
73 torture_assert(tctx, found, "created share found");
74
75 return true;
76 }
77
78
79 static bool test_create_invalid(struct torture_context *tctx,
/* [<][>][^][v][top][bottom][index][help] */
80 const void *tcase_data,
81 const void *test_data)
82 {
83 struct share_context *ctx = (struct share_context *)discard_const(tcase_data);
84 NTSTATUS status;
85
86 status = share_create(ctx, "bla", NULL, 0);
87
88 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
89 torture_skip(tctx, "Not supported by backend");
90
91 torture_assert_ntstatus_equal(tctx, NT_STATUS_INVALID_PARAMETER,
92 status,
93 "create_share failed");
94
95 torture_assert_ntstatus_equal(tctx, NT_STATUS_INVALID_PARAMETER,
96 share_create(ctx, NULL, NULL, 0),
97 "create_share failed");
98
99 return true;
100 }
101
102 static bool test_share_remove_invalid(struct torture_context *tctx,
/* [<][>][^][v][top][bottom][index][help] */
103 const void *tcase_data,
104 const void *test_data)
105 {
106 struct share_context *ctx = (struct share_context *)discard_const(tcase_data);
107 NTSTATUS status;
108
109 status = share_remove(ctx, "nonexistant");
110
111 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
112 torture_skip(tctx, "Not supported by backend");
113
114 torture_assert_ntstatus_equal(tctx, status, NT_STATUS_UNSUCCESSFUL, "remove fails");
115
116 return true;
117 }
118
119
120
121 static bool test_share_remove(struct torture_context *tctx,
/* [<][>][^][v][top][bottom][index][help] */
122 const void *tcase_data,
123 const void *test_data)
124 {
125 struct share_context *ctx = (struct share_context *)discard_const(tcase_data);
126 struct share_info inf[] = {
127 { SHARE_INFO_STRING, SHARE_TYPE, discard_const_p(void *, "IPC$") },
128 { SHARE_INFO_STRING, SHARE_PATH, discard_const_p(void *, "/tmp/bla") }
129 };
130 NTSTATUS status;
131
132 status = share_create(ctx, "blie", inf, 2);
133
134 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
135 torture_skip(tctx, "Not supported by backend");
136
137 torture_assert_ntstatus_ok(tctx, status, "create_share failed");
138
139 torture_assert_ntstatus_ok(tctx, share_remove(ctx, "blie"), "remove failed");
140
141 return true;
142 }
143
144 static bool test_double_create(struct torture_context *tctx,
/* [<][>][^][v][top][bottom][index][help] */
145 const void *tcase_data,
146 const void *test_data)
147 {
148 struct share_context *ctx = (struct share_context *)discard_const(tcase_data);
149 struct share_info inf[] = {
150 { SHARE_INFO_STRING, SHARE_TYPE, discard_const_p(void *, "IPC$") },
151 { SHARE_INFO_STRING, SHARE_PATH, discard_const_p(void *, "/tmp/bla") }
152 };
153 NTSTATUS status;
154
155 status = share_create(ctx, "bla", inf, 2);
156
157 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
158 torture_skip(tctx, "Not supported by backend");
159
160 torture_assert_ntstatus_ok(tctx, status, "create_share failed");
161
162 torture_assert_ntstatus_equal(tctx, NT_STATUS_OBJECT_NAME_COLLISION,
163 share_create(ctx, "bla", inf, 2),
164 "create_share failed");
165
166 return true;
167 }
168
169 static void tcase_add_share_tests(struct torture_tcase *tcase)
/* [<][>][^][v][top][bottom][index][help] */
170 {
171 torture_tcase_add_test_const(tcase, "list_empty", test_list_empty,NULL);
172 torture_tcase_add_test_const(tcase, "share_create", test_create, NULL);
173 torture_tcase_add_test_const(tcase, "share_remove", test_share_remove,
174 NULL);
175 torture_tcase_add_test_const(tcase, "share_remove_invalid",
176 test_share_remove_invalid, NULL);
177 torture_tcase_add_test_const(tcase, "share_create_invalid",
178 test_create_invalid, NULL);
179 torture_tcase_add_test_const(tcase, "share_double_create",
180 test_double_create, NULL);
181 }
182
183 static bool setup_ldb(struct torture_context *tctx, void **data)
/* [<][>][^][v][top][bottom][index][help] */
184 {
185 return NT_STATUS_IS_OK(share_get_context_by_name(tctx, "ldb", tctx->ev, tctx->lp_ctx, (struct share_context **)data));
186 }
187
188 static bool setup_classic(struct torture_context *tctx, void **data)
/* [<][>][^][v][top][bottom][index][help] */
189 {
190 return NT_STATUS_IS_OK(share_get_context_by_name(tctx, "classic", tctx->ev, tctx->lp_ctx, (struct share_context **)data));
191 }
192
193 static bool teardown(struct torture_context *tctx, void *data)
/* [<][>][^][v][top][bottom][index][help] */
194 {
195 talloc_free(data);
196 return true;
197 }
198
199 struct torture_suite *torture_local_share(TALLOC_CTX *mem_ctx)
/* [<][>][^][v][top][bottom][index][help] */
200 {
201 struct torture_suite *suite = torture_suite_create(mem_ctx, "SHARE");
202 struct torture_tcase *tcase;
203
204 share_init();
205
206 tcase = torture_suite_add_tcase(suite, "ldb");
207 torture_tcase_set_fixture(tcase, setup_ldb, teardown);
208 tcase_add_share_tests(tcase);
209
210 tcase = torture_suite_add_tcase(suite, "classic");
211 torture_tcase_set_fixture(tcase, setup_classic, teardown);
212 tcase_add_share_tests(tcase);
213
214 return suite;
215 }