2 Unix SMB/CIFS implementation.
4 local testing of share code
6 Copyright (C) Jelmer Vernooij 2007
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.
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, see <http://www.gnu.org/licenses/>.
23 #include "param/share.h"
24 #include "torture/torture.h"
26 static bool test_list_empty(struct torture_context *tctx,
27 const void *tcase_data,
28 const void *test_data)
30 struct share_context *ctx = discard_const(tcase_data);
34 torture_assert_ntstatus_ok(tctx, share_list_all(tctx, ctx, &count, &names),
35 "share_list_all failed");
40 static bool test_create(struct torture_context *tctx,
41 const void *tcase_data,
42 const void *test_data)
44 struct share_context *ctx = discard_const(tcase_data);
49 struct share_info inf[] = {
50 { SHARE_INFO_STRING, SHARE_TYPE, discard_const_p(void *, "IPC$") },
51 { SHARE_INFO_STRING, SHARE_PATH, discard_const_p(void *, "/tmp/bla") }
55 status = share_create(ctx, "bloe", inf, 2);
57 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
58 torture_skip(tctx, "Not supported by backend");
60 torture_assert_ntstatus_ok(tctx, status, "create_share failed");
62 torture_assert_ntstatus_ok(tctx, share_list_all(tctx, ctx, &count, &names),
63 "share_list_all failed");
65 torture_assert(tctx, count >= 1, "creating share failed");
68 for (i = 0; i < count; i++) {
69 found |= strcmp(names[i], "bloe") == 0;
72 torture_assert(tctx, found, "created share found");
78 static bool test_create_invalid(struct torture_context *tctx,
79 const void *tcase_data,
80 const void *test_data)
82 struct share_context *ctx = discard_const(tcase_data);
85 status = share_create(ctx, "bla", NULL, 0);
87 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
88 torture_skip(tctx, "Not supported by backend");
90 torture_assert_ntstatus_equal(tctx, NT_STATUS_INVALID_PARAMETER,
92 "create_share failed");
94 torture_assert_ntstatus_equal(tctx, NT_STATUS_INVALID_PARAMETER,
95 share_create(ctx, NULL, NULL, 0),
96 "create_share failed");
101 static bool test_share_remove_invalid(struct torture_context *tctx,
102 const void *tcase_data,
103 const void *test_data)
105 struct share_context *ctx = discard_const(tcase_data);
108 status = share_remove(ctx, "nonexistant");
110 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
111 torture_skip(tctx, "Not supported by backend");
113 torture_assert_ntstatus_equal(tctx, status, NT_STATUS_UNSUCCESSFUL, "remove fails");
120 static bool test_share_remove(struct torture_context *tctx,
121 const void *tcase_data,
122 const void *test_data)
124 struct share_context *ctx = discard_const(tcase_data);
125 struct share_info inf[] = {
126 { SHARE_INFO_STRING, SHARE_TYPE, discard_const_p(void *, "IPC$") },
127 { SHARE_INFO_STRING, SHARE_PATH, discard_const_p(void *, "/tmp/bla") }
131 status = share_create(ctx, "blie", inf, 2);
133 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
134 torture_skip(tctx, "Not supported by backend");
136 torture_assert_ntstatus_ok(tctx, status, "create_share failed");
138 torture_assert_ntstatus_ok(tctx, share_remove(ctx, "blie"), "remove failed");
143 static bool test_double_create(struct torture_context *tctx,
144 const void *tcase_data,
145 const void *test_data)
147 struct share_context *ctx = discard_const(tcase_data);
148 struct share_info inf[] = {
149 { SHARE_INFO_STRING, SHARE_TYPE, discard_const_p(void *, "IPC$") },
150 { SHARE_INFO_STRING, SHARE_PATH, discard_const_p(void *, "/tmp/bla") }
154 status = share_create(ctx, "bla", inf, 2);
156 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED))
157 torture_skip(tctx, "Not supported by backend");
159 torture_assert_ntstatus_ok(tctx, status, "create_share failed");
161 torture_assert_ntstatus_equal(tctx, NT_STATUS_OBJECT_NAME_COLLISION,
162 share_create(ctx, "bla", inf, 2),
163 "create_share failed");
168 static void tcase_add_share_tests(struct torture_tcase *tcase)
170 torture_tcase_add_test(tcase, "list_empty", test_list_empty, NULL);
171 torture_tcase_add_test(tcase, "share_create", test_create, NULL);
172 torture_tcase_add_test(tcase, "share_remove", test_share_remove, NULL);
173 torture_tcase_add_test(tcase, "share_remove_invalid", test_share_remove_invalid, NULL);
174 torture_tcase_add_test(tcase, "share_create_invalid", test_create_invalid, NULL);
175 torture_tcase_add_test(tcase, "share_double_create", test_double_create, NULL);
178 static BOOL setup_ldb(struct torture_context *tctx, void **data)
180 return NT_STATUS_IS_OK(share_get_context_by_name(tctx, "ldb", (struct share_context **)data));
183 static BOOL setup_classic(struct torture_context *tctx, void **data)
185 return NT_STATUS_IS_OK(share_get_context_by_name(tctx, "classic", (struct share_context **)data));
188 static BOOL teardown(struct torture_context *tctx, void *data)
194 struct torture_suite *torture_local_share(TALLOC_CTX *mem_ctx)
196 struct torture_suite *suite = torture_suite_create(mem_ctx, "SHARE");
197 struct torture_tcase *tcase;
201 tcase = torture_suite_add_tcase(suite, "ldb");
202 torture_tcase_set_fixture(tcase, setup_ldb, teardown);
203 tcase_add_share_tests(tcase);
205 tcase = torture_suite_add_tcase(suite, "classic");
206 torture_tcase_set_fixture(tcase, setup_classic, teardown);
207 tcase_add_share_tests(tcase);