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 "param/param.h"
25 #include "torture/torture.h"
26 #include "torture/local/proto.h"
28 static bool test_list_empty(struct torture_context
*tctx
,
29 const void *tcase_data
,
30 const void *test_data
)
32 struct share_context
*ctx
= (struct share_context
*)discard_const(tcase_data
);
36 torture_assert_ntstatus_ok(tctx
, share_list_all(tctx
, ctx
, &count
, &names
),
37 "share_list_all failed");
42 static bool test_create(struct torture_context
*tctx
,
43 const void *tcase_data
,
44 const void *test_data
)
46 struct share_context
*ctx
= (struct share_context
*)discard_const(tcase_data
);
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") }
57 status
= share_create(ctx
, "bloe", inf
, 2);
59 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_IMPLEMENTED
))
60 torture_skip(tctx
, "Not supported by backend");
62 torture_assert_ntstatus_ok(tctx
, status
, "create_share failed");
64 torture_assert_ntstatus_ok(tctx
, share_list_all(tctx
, ctx
, &count
, &names
),
65 "share_list_all failed");
67 torture_assert(tctx
, count
>= 1, "creating share failed");
70 for (i
= 0; i
< count
; i
++) {
71 found
|= strcmp(names
[i
], "bloe") == 0;
74 torture_assert(tctx
, found
, "created share found");
80 static bool test_create_invalid(struct torture_context
*tctx
,
81 const void *tcase_data
,
82 const void *test_data
)
84 struct share_context
*ctx
= (struct share_context
*)discard_const(tcase_data
);
87 status
= share_create(ctx
, "bla", NULL
, 0);
89 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_IMPLEMENTED
))
90 torture_skip(tctx
, "Not supported by backend");
92 torture_assert_ntstatus_equal(tctx
, NT_STATUS_INVALID_PARAMETER
,
94 "create_share failed");
96 torture_assert_ntstatus_equal(tctx
, NT_STATUS_INVALID_PARAMETER
,
97 share_create(ctx
, NULL
, NULL
, 0),
98 "create_share failed");
103 static bool test_share_remove_invalid(struct torture_context
*tctx
,
104 const void *tcase_data
,
105 const void *test_data
)
107 struct share_context
*ctx
= (struct share_context
*)discard_const(tcase_data
);
110 status
= share_remove(ctx
, "nonexistent");
112 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_IMPLEMENTED
))
113 torture_skip(tctx
, "Not supported by backend");
115 torture_assert_ntstatus_equal(tctx
, status
, NT_STATUS_UNSUCCESSFUL
, "remove fails");
122 static bool test_share_remove(struct torture_context
*tctx
,
123 const void *tcase_data
,
124 const void *test_data
)
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") }
133 status
= share_create(ctx
, "blie", inf
, 2);
135 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_IMPLEMENTED
))
136 torture_skip(tctx
, "Not supported by backend");
138 torture_assert_ntstatus_ok(tctx
, status
, "create_share failed");
140 torture_assert_ntstatus_ok(tctx
, share_remove(ctx
, "blie"), "remove failed");
145 static bool test_double_create(struct torture_context
*tctx
,
146 const void *tcase_data
,
147 const void *test_data
)
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") }
156 status
= share_create(ctx
, "bla", inf
, 2);
158 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_IMPLEMENTED
))
159 torture_skip(tctx
, "Not supported by backend");
161 torture_assert_ntstatus_ok(tctx
, status
, "create_share failed");
163 torture_assert_ntstatus_equal(tctx
, NT_STATUS_OBJECT_NAME_COLLISION
,
164 share_create(ctx
, "bla", inf
, 2),
165 "create_share failed");
170 static void tcase_add_share_tests(struct torture_tcase
*tcase
)
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
,
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
);
184 static bool setup_ldb(struct torture_context
*tctx
, void **data
)
186 return NT_STATUS_IS_OK(share_get_context_by_name(tctx
, "ldb", tctx
->ev
, tctx
->lp_ctx
, (struct share_context
**)data
));
189 static bool setup_classic(struct torture_context
*tctx
, void **data
)
191 return NT_STATUS_IS_OK(share_get_context_by_name(tctx
, "classic", tctx
->ev
, tctx
->lp_ctx
, (struct share_context
**)data
));
194 static bool teardown(struct torture_context
*tctx
, void *data
)
200 struct torture_suite
*torture_local_share(TALLOC_CTX
*mem_ctx
)
202 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "share");
203 struct torture_tcase
*tcase
;
207 tcase
= torture_suite_add_tcase(suite
, "ldb");
208 torture_tcase_set_fixture(tcase
, setup_ldb
, teardown
);
209 tcase_add_share_tests(tcase
);
211 tcase
= torture_suite_add_tcase(suite
, "classic");
212 torture_tcase_set_fixture(tcase
, setup_classic
, teardown
);
213 tcase_add_share_tests(tcase
);