librpc: Shorten dcerpc_binding_handle_call a bit
[Samba/gebeck_regimport.git] / source4 / param / tests / loadparm.c
blobf375bb42384aed0039161cba48e08e7f9ff9d607
1 /*
2 Unix SMB/CIFS implementation.
3 Samba utility functions
4 Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "param/share.h"
22 #include "param/param.h"
23 #include "torture/torture.h"
25 static bool test_create(struct torture_context *tctx)
27 struct loadparm_context *lp_ctx = loadparm_init(tctx);
28 torture_assert(tctx, lp_ctx != NULL, "lp_ctx");
29 return true;
32 static bool test_set_option(struct torture_context *tctx)
34 struct loadparm_context *lp_ctx = loadparm_init(tctx);
35 torture_assert(tctx, lpcfg_set_option(lp_ctx, "workgroup=werkgroep"), "lpcfg_set_option failed");
36 torture_assert_str_equal(tctx, "WERKGROEP", lpcfg_workgroup(lp_ctx), "workgroup");
37 return true;
40 static bool test_set_cmdline(struct torture_context *tctx)
42 struct loadparm_context *lp_ctx = loadparm_init(tctx);
43 torture_assert(tctx, lpcfg_set_cmdline(lp_ctx, "workgroup", "werkgroep"), "lpcfg_set_cmdline failed");
44 torture_assert(tctx, lpcfg_do_global_parameter(lp_ctx, "workgroup", "barbla"), "lpcfg_set_option failed");
45 torture_assert_str_equal(tctx, "WERKGROEP", lpcfg_workgroup(lp_ctx), "workgroup");
46 return true;
49 static bool test_do_global_parameter(struct torture_context *tctx)
51 struct loadparm_context *lp_ctx = loadparm_init(tctx);
52 torture_assert(tctx, lpcfg_do_global_parameter(lp_ctx, "workgroup", "werkgroep42"),
53 "lpcfg_set_cmdline failed");
54 torture_assert_str_equal(tctx, lpcfg_workgroup(lp_ctx), "WERKGROEP42", "workgroup");
55 return true;
59 static bool test_do_global_parameter_var(struct torture_context *tctx)
61 struct loadparm_context *lp_ctx = loadparm_init(tctx);
62 torture_assert(tctx, lpcfg_do_global_parameter_var(lp_ctx, "workgroup", "werk%s%d", "groep", 42),
63 "lpcfg_set_cmdline failed");
64 torture_assert_str_equal(tctx, lpcfg_workgroup(lp_ctx), "WERKGROEP42", "workgroup");
65 return true;
69 static bool test_set_option_invalid(struct torture_context *tctx)
71 struct loadparm_context *lp_ctx = loadparm_init(tctx);
72 torture_assert(tctx, !lpcfg_set_option(lp_ctx, "workgroup"), "lpcfg_set_option succeeded");
73 return true;
76 static bool test_set_option_parametric(struct torture_context *tctx)
78 struct loadparm_context *lp_ctx = loadparm_init(tctx);
79 torture_assert(tctx, lpcfg_set_option(lp_ctx, "some:thing=blaat"), "lpcfg_set_option failed");
80 torture_assert_str_equal(tctx, lpcfg_parm_string(lp_ctx, NULL, "some", "thing"), "blaat",
81 "invalid parametric option");
82 return true;
85 static bool test_lp_parm_double(struct torture_context *tctx)
87 struct loadparm_context *lp_ctx = loadparm_init(tctx);
88 torture_assert(tctx, lpcfg_set_option(lp_ctx, "some:thing=3.4"), "lpcfg_set_option failed");
89 torture_assert(tctx, lpcfg_parm_double(lp_ctx, NULL, "some", "thing", 2.0) == 3.4,
90 "invalid parametric option");
91 torture_assert(tctx, lpcfg_parm_double(lp_ctx, NULL, "some", "bla", 2.0) == 2.0,
92 "invalid parametric option");
93 return true;
96 static bool test_lp_parm_bool(struct torture_context *tctx)
98 struct loadparm_context *lp_ctx = loadparm_init(tctx);
99 torture_assert(tctx, lpcfg_set_option(lp_ctx, "some:thing=true"), "lpcfg_set_option failed");
100 torture_assert(tctx, lpcfg_parm_bool(lp_ctx, NULL, "some", "thing", false) == true,
101 "invalid parametric option");
102 torture_assert(tctx, lpcfg_parm_bool(lp_ctx, NULL, "some", "bla", true) == true,
103 "invalid parametric option");
104 return true;
107 static bool test_lp_parm_int(struct torture_context *tctx)
109 struct loadparm_context *lp_ctx = loadparm_init(tctx);
110 torture_assert(tctx, lpcfg_set_option(lp_ctx, "some:thing=34"), "lpcfg_set_option failed");
111 torture_assert_int_equal(tctx, lpcfg_parm_int(lp_ctx, NULL, "some", "thing", 20), 34,
112 "invalid parametric option");
113 torture_assert_int_equal(tctx, lpcfg_parm_int(lp_ctx, NULL, "some", "bla", 42), 42,
114 "invalid parametric option");
115 return true;
118 static bool test_lp_parm_bytes(struct torture_context *tctx)
120 struct loadparm_context *lp_ctx = loadparm_init(tctx);
121 torture_assert(tctx, lpcfg_set_option(lp_ctx, "some:thing=16K"), "lpcfg_set_option failed");
122 torture_assert_int_equal(tctx, lpcfg_parm_bytes(lp_ctx, NULL, "some", "thing", 20), 16 * 1024,
123 "invalid parametric option");
124 torture_assert_int_equal(tctx, lpcfg_parm_bytes(lp_ctx, NULL, "some", "bla", 42), 42,
125 "invalid parametric option");
126 return true;
129 static bool test_lp_do_service_parameter(struct torture_context *tctx)
131 struct loadparm_context *lp_ctx = loadparm_init(tctx);
132 struct loadparm_service *service = lpcfg_add_service(lp_ctx, lpcfg_default_service(lp_ctx), "foo");
133 torture_assert(tctx, lpcfg_do_service_parameter(lp_ctx, service,
134 "some:thing", "foo"), "lpcfg_set_option failed");
135 torture_assert_str_equal(tctx, lpcfg_parm_string(lp_ctx, service, "some", "thing"), "foo",
136 "invalid parametric option");
137 return true;
140 static bool test_lp_service(struct torture_context *tctx)
142 struct loadparm_context *lp_ctx = loadparm_init(tctx);
143 struct loadparm_service *service = lpcfg_add_service(lp_ctx, lpcfg_default_service(lp_ctx), "foo");
144 torture_assert(tctx, service == lpcfg_service(lp_ctx, "foo"), "invalid service");
145 return true;
148 static bool test_server_role_default(struct torture_context *tctx)
150 struct loadparm_context *lp_ctx = loadparm_init(tctx);
151 torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_STANDALONE, "ROLE should be standalone by default");
152 torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_USER, "security should be user");
153 return true;
156 static bool test_server_role_dc_specified(struct torture_context *tctx)
158 struct loadparm_context *lp_ctx = loadparm_init(tctx);
159 torture_assert(tctx, lpcfg_set_option(lp_ctx, "server role=domain controller"), "lpcfg_set_option failed");
160 torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_ACTIVE_DIRECTORY_DC, "ROLE should be DC");
161 torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_USER, "security should be USER");
162 return true;
165 static bool test_server_role_member_specified(struct torture_context *tctx)
167 struct loadparm_context *lp_ctx = loadparm_init(tctx);
168 torture_assert(tctx, lpcfg_set_option(lp_ctx, "server role=member"), "lpcfg_set_option failed");
169 torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_DOMAIN_MEMBER, "ROLE should be member");
170 torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_ADS, "security should be ADS");
171 return true;
174 static bool test_server_role_member_specified2(struct torture_context *tctx)
176 struct loadparm_context *lp_ctx = loadparm_init(tctx);
177 torture_assert(tctx, lpcfg_set_option(lp_ctx, "server role=member"), "lpcfg_set_option failed");
178 torture_assert(tctx, lpcfg_set_option(lp_ctx, "security=domain"), "lpcfg_set_option failed");
179 torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_DOMAIN_MEMBER, "ROLE should be member");
180 torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_DOMAIN, "security should be domain");
181 return true;
184 static bool test_server_role_member_specified3(struct torture_context *tctx)
186 struct loadparm_context *lp_ctx = loadparm_init(tctx);
187 torture_assert(tctx, lpcfg_set_option(lp_ctx, "server role=member"), "lpcfg_set_option failed");
188 torture_assert(tctx, lpcfg_set_option(lp_ctx, "security=ads"), "lpcfg_set_option failed");
189 torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_DOMAIN_MEMBER, "ROLE should be member");
190 torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_ADS, "security should be ads");
191 return true;
194 static bool test_server_role_standalone_specified(struct torture_context *tctx)
196 struct loadparm_context *lp_ctx = loadparm_init(tctx);
197 torture_assert(tctx, lpcfg_set_option(lp_ctx, "server role=standalone"), "lpcfg_set_option failed");
198 torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_STANDALONE, "ROLE should be standalone");
199 torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_USER, "security should be USER");
200 return true;
203 static bool test_server_role_dc_domain_logons(struct torture_context *tctx)
205 struct loadparm_context *lp_ctx = loadparm_init(tctx);
206 torture_assert(tctx, lpcfg_set_option(lp_ctx, "domain logons=true"), "lpcfg_set_option failed");
207 torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_DOMAIN_PDC, "ROLE should be PDC");
208 torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_USER, "security should be user");
209 return true;
212 static bool test_server_role_dc_domain_logons_and_not_master(struct torture_context *tctx)
214 struct loadparm_context *lp_ctx = loadparm_init(tctx);
215 torture_assert(tctx, lpcfg_set_option(lp_ctx, "domain logons=true"), "lpcfg_set_option failed");
216 torture_assert(tctx, lpcfg_set_option(lp_ctx, "domain master=false"), "lpcfg_set_option failed");
217 torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_DOMAIN_BDC, "ROLE should be BDC");
218 torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_USER, "security should be user");
219 return true;
222 static bool test_server_role_security_ads(struct torture_context *tctx)
224 struct loadparm_context *lp_ctx = loadparm_init(tctx);
225 torture_assert(tctx, lpcfg_set_option(lp_ctx, "security=ads"), "lpcfg_set_option failed");
226 torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_DOMAIN_MEMBER, "ROLE should be MEMBER");
227 torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_ADS, "security should be ads");
228 return true;
231 static bool test_server_role_security_domain(struct torture_context *tctx)
233 struct loadparm_context *lp_ctx = loadparm_init(tctx);
234 torture_assert(tctx, lpcfg_set_option(lp_ctx, "security=domain"), "lpcfg_set_option failed");
235 torture_assert_int_equal(tctx, lpcfg_server_role(lp_ctx), ROLE_DOMAIN_MEMBER, "ROLE should be MEMBER");
236 torture_assert_int_equal(tctx, lpcfg_security(lp_ctx), SEC_DOMAIN, "security should be domain");
237 return true;
240 struct torture_suite *torture_local_loadparm(TALLOC_CTX *mem_ctx)
242 struct torture_suite *suite = torture_suite_create(mem_ctx, "loadparm");
244 torture_suite_add_simple_test(suite, "create", test_create);
245 torture_suite_add_simple_test(suite, "set_option", test_set_option);
246 torture_suite_add_simple_test(suite, "set_cmdline", test_set_cmdline);
247 torture_suite_add_simple_test(suite, "set_option_invalid", test_set_option_invalid);
248 torture_suite_add_simple_test(suite, "set_option_parametric", test_set_option_parametric);
249 torture_suite_add_simple_test(suite, "set_lp_parm_double", test_lp_parm_double);
250 torture_suite_add_simple_test(suite, "set_lp_parm_bool", test_lp_parm_bool);
251 torture_suite_add_simple_test(suite, "set_lp_parm_int", test_lp_parm_int);
252 torture_suite_add_simple_test(suite, "set_lp_parm_bytes", test_lp_parm_bytes);
253 torture_suite_add_simple_test(suite, "service_parameter", test_lp_do_service_parameter);
254 torture_suite_add_simple_test(suite, "lpcfg_service", test_lp_service);
255 torture_suite_add_simple_test(suite, "do_global_parameter_var", test_do_global_parameter_var);
256 torture_suite_add_simple_test(suite, "do_global_parameter", test_do_global_parameter);
257 torture_suite_add_simple_test(suite, "test_server_role_default", test_server_role_default);
258 torture_suite_add_simple_test(suite, "test_server_role_dc_specified", test_server_role_dc_specified);
259 torture_suite_add_simple_test(suite, "test_server_role_member_specified", test_server_role_member_specified);
260 torture_suite_add_simple_test(suite, "test_server_role_member_specified2", test_server_role_member_specified2);
261 torture_suite_add_simple_test(suite, "test_server_role_member_specified3", test_server_role_member_specified3);
262 torture_suite_add_simple_test(suite, "test_server_role_standalone_specified", test_server_role_standalone_specified);
263 torture_suite_add_simple_test(suite, "test_server_role_dc_domain_logons", test_server_role_dc_domain_logons);
264 torture_suite_add_simple_test(suite, "test_server_role_dc_domain_logons_and_not_master", test_server_role_dc_domain_logons_and_not_master);
265 torture_suite_add_simple_test(suite, "test_server_role_security_ads", test_server_role_security_ads);
266 torture_suite_add_simple_test(suite, "test_server_role_security_domain", test_server_role_security_domain);
268 return suite;