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"
27 static bool test_list_empty(struct torture_context
*tctx
,
28 const void *tcase_data
,
29 const void *test_data
)
31 struct share_context
*ctx
= (struct share_context
*)discard_const(tcase_data
);
35 torture_assert_ntstatus_ok(tctx
, share_list_all(tctx
, ctx
, &count
, &names
),
36 "share_list_all failed");
41 static bool test_create(struct torture_context
*tctx
,
42 const void *tcase_data
,
43 const void *test_data
)
45 struct share_context
*ctx
= (struct share_context
*)discard_const(tcase_data
);
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") }
56 status
= share_create(ctx
, "bloe", inf
, 2);
58 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_IMPLEMENTED
))
59 torture_skip(tctx
, "Not supported by backend");
61 torture_assert_ntstatus_ok(tctx
, status
, "create_share failed");
63 torture_assert_ntstatus_ok(tctx
, share_list_all(tctx
, ctx
, &count
, &names
),
64 "share_list_all failed");
66 torture_assert(tctx
, count
>= 1, "creating share failed");
69 for (i
= 0; i
< count
; i
++) {
70 found
|= strcmp(names
[i
], "bloe") == 0;
73 torture_assert(tctx
, found
, "created share found");
79 static bool test_create_invalid(struct torture_context
*tctx
,
80 const void *tcase_data
,
81 const void *test_data
)
83 struct share_context
*ctx
= (struct share_context
*)discard_const(tcase_data
);
86 status
= share_create(ctx
, "bla", NULL
, 0);
88 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_IMPLEMENTED
))
89 torture_skip(tctx
, "Not supported by backend");
91 torture_assert_ntstatus_equal(tctx
, NT_STATUS_INVALID_PARAMETER
,
93 "create_share failed");
95 torture_assert_ntstatus_equal(tctx
, NT_STATUS_INVALID_PARAMETER
,
96 share_create(ctx
, NULL
, NULL
, 0),
97 "create_share failed");
102 static bool test_share_remove_invalid(struct torture_context
*tctx
,
103 const void *tcase_data
,
104 const void *test_data
)
106 struct share_context
*ctx
= (struct share_context
*)discard_const(tcase_data
);
109 status
= share_remove(ctx
, "nonexistent");
111 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_IMPLEMENTED
))
112 torture_skip(tctx
, "Not supported by backend");
114 torture_assert_ntstatus_equal(tctx
, status
, NT_STATUS_UNSUCCESSFUL
, "remove fails");
121 static bool test_share_remove(struct torture_context
*tctx
,
122 const void *tcase_data
,
123 const void *test_data
)
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") }
132 status
= share_create(ctx
, "blie", inf
, 2);
134 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_IMPLEMENTED
))
135 torture_skip(tctx
, "Not supported by backend");
137 torture_assert_ntstatus_ok(tctx
, status
, "create_share failed");
139 torture_assert_ntstatus_ok(tctx
, share_remove(ctx
, "blie"), "remove failed");
144 static bool test_double_create(struct torture_context
*tctx
,
145 const void *tcase_data
,
146 const void *test_data
)
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") }
155 status
= share_create(ctx
, "bla", inf
, 2);
157 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_IMPLEMENTED
))
158 torture_skip(tctx
, "Not supported by backend");
160 torture_assert_ntstatus_ok(tctx
, status
, "create_share failed");
162 torture_assert_ntstatus_equal(tctx
, NT_STATUS_OBJECT_NAME_COLLISION
,
163 share_create(ctx
, "bla", inf
, 2),
164 "create_share failed");
169 static void tcase_add_share_tests(struct torture_tcase
*tcase
)
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
,
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
);
183 static bool setup_ldb(struct torture_context
*tctx
, void **data
)
185 return NT_STATUS_IS_OK(share_get_context_by_name(tctx
, "ldb", tctx
->ev
, tctx
->lp_ctx
, (struct share_context
**)data
));
188 static bool setup_classic(struct torture_context
*tctx
, void **data
)
190 return NT_STATUS_IS_OK(share_get_context_by_name(tctx
, "classic", tctx
->ev
, tctx
->lp_ctx
, (struct share_context
**)data
));
193 static bool teardown(struct torture_context
*tctx
, void *data
)
199 struct torture_suite
*torture_local_share(TALLOC_CTX
*mem_ctx
)
201 struct torture_suite
*suite
= torture_suite_create(mem_ctx
, "share");
202 struct torture_tcase
*tcase
;
206 tcase
= torture_suite_add_tcase(suite
, "ldb");
207 torture_tcase_set_fixture(tcase
, setup_ldb
, teardown
);
208 tcase_add_share_tests(tcase
);
210 tcase
= torture_suite_add_tcase(suite
, "classic");
211 torture_tcase_set_fixture(tcase
, setup_classic
, teardown
);
212 tcase_add_share_tests(tcase
);