source: vendor/current/source4/param/tests/share.c

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

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