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/>.
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");
32 static bool test_set_option(struct torture_context *tctx)
34 struct loadparm_context *lp_ctx = loadparm_init(tctx);
35 torture_assert(tctx, lp_set_option(lp_ctx, "workgroup=werkgroep"), "lp_set_option failed");
36 torture_assert_str_equal(tctx, "WERKGROEP", lp_workgroup(lp_ctx), "workgroup");
40 static bool test_set_option_invalid(struct torture_context *tctx)
42 struct loadparm_context *lp_ctx = loadparm_init(tctx);
43 torture_assert(tctx, !lp_set_option(lp_ctx, "workgroup"), "lp_set_option succeeded");
47 static bool test_set_option_parametric(struct torture_context *tctx)
49 struct loadparm_context *lp_ctx = loadparm_init(tctx);
50 torture_assert(tctx, lp_set_option(lp_ctx, "some:thing=blaat"), "lp_set_option failed");
51 torture_assert_str_equal(tctx, lp_parm_string(lp_ctx, NULL, "some", "thing"), "blaat",
52 "invalid parametric option");
56 static bool test_lp_parm_double(struct torture_context *tctx)
58 struct loadparm_context *lp_ctx = loadparm_init(tctx);
59 torture_assert(tctx, lp_set_option(lp_ctx, "some:thing=3.4"), "lp_set_option failed");
60 torture_assert(tctx, lp_parm_double(lp_ctx, NULL, "some", "thing", 2.0) == 3.4,
61 "invalid parametric option");
62 torture_assert(tctx, lp_parm_double(lp_ctx, NULL, "some", "bla", 2.0) == 2.0,
63 "invalid parametric option");
67 static bool test_lp_parm_bool(struct torture_context *tctx)
69 struct loadparm_context *lp_ctx = loadparm_init(tctx);
70 torture_assert(tctx, lp_set_option(lp_ctx, "some:thing=true"), "lp_set_option failed");
71 torture_assert(tctx, lp_parm_bool(lp_ctx, NULL, "some", "thing", false) == true,
72 "invalid parametric option");
73 torture_assert(tctx, lp_parm_bool(lp_ctx, NULL, "some", "bla", true) == true,
74 "invalid parametric option");
78 static bool test_lp_parm_int(struct torture_context *tctx)
80 struct loadparm_context *lp_ctx = loadparm_init(tctx);
81 torture_assert(tctx, lp_set_option(lp_ctx, "some:thing=34"), "lp_set_option failed");
82 torture_assert_int_equal(tctx, lp_parm_int(lp_ctx, NULL, "some", "thing", 20), 34,
83 "invalid parametric option");
84 torture_assert_int_equal(tctx, lp_parm_int(lp_ctx, NULL, "some", "bla", 42), 42,
85 "invalid parametric option");
89 static bool test_lp_parm_bytes(struct torture_context *tctx)
91 struct loadparm_context *lp_ctx = loadparm_init(tctx);
92 torture_assert(tctx, lp_set_option(lp_ctx, "some:thing=16K"), "lp_set_option failed");
93 torture_assert_int_equal(tctx, lp_parm_bytes(lp_ctx, NULL, "some", "thing", 20), 16 * 1024,
94 "invalid parametric option");
95 torture_assert_int_equal(tctx, lp_parm_bytes(lp_ctx, NULL, "some", "bla", 42), 42,
96 "invalid parametric option");
100 struct torture_suite *torture_local_loadparm(TALLOC_CTX *mem_ctx)
102 struct torture_suite *suite = torture_suite_create(mem_ctx, "LOADPARM");
104 torture_suite_add_simple_test(suite, "create", test_create);
105 torture_suite_add_simple_test(suite, "set_option", test_set_option);
106 torture_suite_add_simple_test(suite, "set_option_invalid", test_set_option_invalid);
107 torture_suite_add_simple_test(suite, "set_option_parametric", test_set_option_parametric);
108 torture_suite_add_simple_test(suite, "set_lp_parm_double", test_lp_parm_double);
109 torture_suite_add_simple_test(suite, "set_lp_parm_bool", test_lp_parm_bool);
110 torture_suite_add_simple_test(suite, "set_lp_parm_int", test_lp_parm_int);
111 torture_suite_add_simple_test(suite, "set_lp_parm_bytes", test_lp_parm_bytes);