| 1 | /* | 
|---|
| 2 | Unix SMB/CIFS implementation. | 
|---|
| 3 | Samba utility functions | 
|---|
| 4 | Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007 | 
|---|
| 5 |  | 
|---|
| 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. | 
|---|
| 10 |  | 
|---|
| 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. | 
|---|
| 15 |  | 
|---|
| 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/>. | 
|---|
| 18 | */ | 
|---|
| 19 |  | 
|---|
| 20 | #include "includes.h" | 
|---|
| 21 | #include "param/share.h" | 
|---|
| 22 | #include "param/param.h" | 
|---|
| 23 | #include "torture/torture.h" | 
|---|
| 24 |  | 
|---|
| 25 | static bool test_create(struct torture_context *tctx) | 
|---|
| 26 | { | 
|---|
| 27 | struct loadparm_context *lp_ctx = loadparm_init(tctx); | 
|---|
| 28 | torture_assert(tctx, lp_ctx != NULL, "lp_ctx"); | 
|---|
| 29 | return true; | 
|---|
| 30 | } | 
|---|
| 31 |  | 
|---|
| 32 | static bool test_set_option(struct torture_context *tctx) | 
|---|
| 33 | { | 
|---|
| 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"); | 
|---|
| 37 | return true; | 
|---|
| 38 | } | 
|---|
| 39 |  | 
|---|
| 40 | static bool test_set_cmdline(struct torture_context *tctx) | 
|---|
| 41 | { | 
|---|
| 42 | struct loadparm_context *lp_ctx = loadparm_init(tctx); | 
|---|
| 43 | torture_assert(tctx, lp_set_cmdline(lp_ctx, "workgroup", "werkgroep"), "lp_set_cmdline failed"); | 
|---|
| 44 | torture_assert(tctx, lp_do_global_parameter(lp_ctx, "workgroup", "barbla"), "lp_set_option failed"); | 
|---|
| 45 | torture_assert_str_equal(tctx, "WERKGROEP", lp_workgroup(lp_ctx), "workgroup"); | 
|---|
| 46 | return true; | 
|---|
| 47 | } | 
|---|
| 48 |  | 
|---|
| 49 | static bool test_do_global_parameter(struct torture_context *tctx) | 
|---|
| 50 | { | 
|---|
| 51 | struct loadparm_context *lp_ctx = loadparm_init(tctx); | 
|---|
| 52 | torture_assert(tctx, lp_do_global_parameter(lp_ctx, "workgroup", "werkgroep42"), | 
|---|
| 53 | "lp_set_cmdline failed"); | 
|---|
| 54 | torture_assert_str_equal(tctx, lp_workgroup(lp_ctx), "WERKGROEP42", "workgroup"); | 
|---|
| 55 | return true; | 
|---|
| 56 | } | 
|---|
| 57 |  | 
|---|
| 58 |  | 
|---|
| 59 | static bool test_do_global_parameter_var(struct torture_context *tctx) | 
|---|
| 60 | { | 
|---|
| 61 | struct loadparm_context *lp_ctx = loadparm_init(tctx); | 
|---|
| 62 | torture_assert(tctx, lp_do_global_parameter_var(lp_ctx, "workgroup", "werk%s%d", "groep", 42), | 
|---|
| 63 | "lp_set_cmdline failed"); | 
|---|
| 64 | torture_assert_str_equal(tctx, lp_workgroup(lp_ctx), "WERKGROEP42", "workgroup"); | 
|---|
| 65 | return true; | 
|---|
| 66 | } | 
|---|
| 67 |  | 
|---|
| 68 |  | 
|---|
| 69 | static bool test_set_option_invalid(struct torture_context *tctx) | 
|---|
| 70 | { | 
|---|
| 71 | struct loadparm_context *lp_ctx = loadparm_init(tctx); | 
|---|
| 72 | torture_assert(tctx, !lp_set_option(lp_ctx, "workgroup"), "lp_set_option succeeded"); | 
|---|
| 73 | return true; | 
|---|
| 74 | } | 
|---|
| 75 |  | 
|---|
| 76 | static bool test_set_option_parametric(struct torture_context *tctx) | 
|---|
| 77 | { | 
|---|
| 78 | struct loadparm_context *lp_ctx = loadparm_init(tctx); | 
|---|
| 79 | torture_assert(tctx, lp_set_option(lp_ctx, "some:thing=blaat"), "lp_set_option failed"); | 
|---|
| 80 | torture_assert_str_equal(tctx, lp_parm_string(lp_ctx, NULL, "some", "thing"), "blaat", | 
|---|
| 81 | "invalid parametric option"); | 
|---|
| 82 | return true; | 
|---|
| 83 | } | 
|---|
| 84 |  | 
|---|
| 85 | static bool test_lp_parm_double(struct torture_context *tctx) | 
|---|
| 86 | { | 
|---|
| 87 | struct loadparm_context *lp_ctx = loadparm_init(tctx); | 
|---|
| 88 | torture_assert(tctx, lp_set_option(lp_ctx, "some:thing=3.4"), "lp_set_option failed"); | 
|---|
| 89 | torture_assert(tctx, lp_parm_double(lp_ctx, NULL, "some", "thing", 2.0) == 3.4, | 
|---|
| 90 | "invalid parametric option"); | 
|---|
| 91 | torture_assert(tctx, lp_parm_double(lp_ctx, NULL, "some", "bla", 2.0) == 2.0, | 
|---|
| 92 | "invalid parametric option"); | 
|---|
| 93 | return true; | 
|---|
| 94 | } | 
|---|
| 95 |  | 
|---|
| 96 | static bool test_lp_parm_bool(struct torture_context *tctx) | 
|---|
| 97 | { | 
|---|
| 98 | struct loadparm_context *lp_ctx = loadparm_init(tctx); | 
|---|
| 99 | torture_assert(tctx, lp_set_option(lp_ctx, "some:thing=true"), "lp_set_option failed"); | 
|---|
| 100 | torture_assert(tctx, lp_parm_bool(lp_ctx, NULL, "some", "thing", false) == true, | 
|---|
| 101 | "invalid parametric option"); | 
|---|
| 102 | torture_assert(tctx, lp_parm_bool(lp_ctx, NULL, "some", "bla", true) == true, | 
|---|
| 103 | "invalid parametric option"); | 
|---|
| 104 | return true; | 
|---|
| 105 | } | 
|---|
| 106 |  | 
|---|
| 107 | static bool test_lp_parm_int(struct torture_context *tctx) | 
|---|
| 108 | { | 
|---|
| 109 | struct loadparm_context *lp_ctx = loadparm_init(tctx); | 
|---|
| 110 | torture_assert(tctx, lp_set_option(lp_ctx, "some:thing=34"), "lp_set_option failed"); | 
|---|
| 111 | torture_assert_int_equal(tctx, lp_parm_int(lp_ctx, NULL, "some", "thing", 20), 34, | 
|---|
| 112 | "invalid parametric option"); | 
|---|
| 113 | torture_assert_int_equal(tctx, lp_parm_int(lp_ctx, NULL, "some", "bla", 42), 42, | 
|---|
| 114 | "invalid parametric option"); | 
|---|
| 115 | return true; | 
|---|
| 116 | } | 
|---|
| 117 |  | 
|---|
| 118 | static bool test_lp_parm_bytes(struct torture_context *tctx) | 
|---|
| 119 | { | 
|---|
| 120 | struct loadparm_context *lp_ctx = loadparm_init(tctx); | 
|---|
| 121 | torture_assert(tctx, lp_set_option(lp_ctx, "some:thing=16K"), "lp_set_option failed"); | 
|---|
| 122 | torture_assert_int_equal(tctx, lp_parm_bytes(lp_ctx, NULL, "some", "thing", 20), 16 * 1024, | 
|---|
| 123 | "invalid parametric option"); | 
|---|
| 124 | torture_assert_int_equal(tctx, lp_parm_bytes(lp_ctx, NULL, "some", "bla", 42), 42, | 
|---|
| 125 | "invalid parametric option"); | 
|---|
| 126 | return true; | 
|---|
| 127 | } | 
|---|
| 128 |  | 
|---|
| 129 | static bool test_lp_do_service_parameter(struct torture_context *tctx) | 
|---|
| 130 | { | 
|---|
| 131 | struct loadparm_context *lp_ctx = loadparm_init(tctx); | 
|---|
| 132 | struct loadparm_service *service = lp_add_service(lp_ctx, lp_default_service(lp_ctx), "foo"); | 
|---|
| 133 | torture_assert(tctx, lp_do_service_parameter(lp_ctx, service, | 
|---|
| 134 | "some:thing", "foo"), "lp_set_option failed"); | 
|---|
| 135 | torture_assert_str_equal(tctx, lp_parm_string(lp_ctx, service, "some", "thing"), "foo", | 
|---|
| 136 | "invalid parametric option"); | 
|---|
| 137 | return true; | 
|---|
| 138 | } | 
|---|
| 139 |  | 
|---|
| 140 | static bool test_lp_service(struct torture_context *tctx) | 
|---|
| 141 | { | 
|---|
| 142 | struct loadparm_context *lp_ctx = loadparm_init(tctx); | 
|---|
| 143 | struct loadparm_service *service = lp_add_service(lp_ctx, lp_default_service(lp_ctx), "foo"); | 
|---|
| 144 | torture_assert(tctx, service == lp_service(lp_ctx, "foo"), "invalid service"); | 
|---|
| 145 | return true; | 
|---|
| 146 | } | 
|---|
| 147 |  | 
|---|
| 148 | struct torture_suite *torture_local_loadparm(TALLOC_CTX *mem_ctx) | 
|---|
| 149 | { | 
|---|
| 150 | struct torture_suite *suite = torture_suite_create(mem_ctx, "LOADPARM"); | 
|---|
| 151 |  | 
|---|
| 152 | torture_suite_add_simple_test(suite, "create", test_create); | 
|---|
| 153 | torture_suite_add_simple_test(suite, "set_option", test_set_option); | 
|---|
| 154 | torture_suite_add_simple_test(suite, "set_cmdline", test_set_cmdline); | 
|---|
| 155 | torture_suite_add_simple_test(suite, "set_option_invalid", test_set_option_invalid); | 
|---|
| 156 | torture_suite_add_simple_test(suite, "set_option_parametric", test_set_option_parametric); | 
|---|
| 157 | torture_suite_add_simple_test(suite, "set_lp_parm_double", test_lp_parm_double); | 
|---|
| 158 | torture_suite_add_simple_test(suite, "set_lp_parm_bool", test_lp_parm_bool); | 
|---|
| 159 | torture_suite_add_simple_test(suite, "set_lp_parm_int", test_lp_parm_int); | 
|---|
| 160 | torture_suite_add_simple_test(suite, "set_lp_parm_bytes", test_lp_parm_bytes); | 
|---|
| 161 | torture_suite_add_simple_test(suite, "service_parameter", test_lp_do_service_parameter); | 
|---|
| 162 | torture_suite_add_simple_test(suite, "lp_service", test_lp_service); | 
|---|
| 163 | torture_suite_add_simple_test(suite, "do_global_parameter_var", test_do_global_parameter_var); | 
|---|
| 164 | torture_suite_add_simple_test(suite, "do_global_parameter", test_do_global_parameter); | 
|---|
| 165 |  | 
|---|
| 166 | return suite; | 
|---|
| 167 | } | 
|---|