diff options
Diffstat (limited to 'source4/param')
-rw-r--r-- | source4/param/loadparm.c | 18 | ||||
-rw-r--r-- | source4/param/tests/loadparm.c | 48 |
2 files changed, 50 insertions, 16 deletions
diff --git a/source4/param/loadparm.c b/source4/param/loadparm.c index c3f06512dc..32aaa13b87 100644 --- a/source4/param/loadparm.c +++ b/source4/param/loadparm.c @@ -554,20 +554,6 @@ struct parm_struct *lp_parm_table(void) return parm_table; } -static TALLOC_CTX *lp_talloc; - -/******************************************************************* a - Free up temporary memory - called from the main loop. -********************************************************************/ - -void lp_talloc_free(void) -{ - if (!lp_talloc) - return; - talloc_free(lp_talloc); - lp_talloc = NULL; -} - /******************************************************************* Convenience routine to grab string parameters into temporary memory and run standard_sub_basic on them. The buffers can be written to by @@ -975,7 +961,7 @@ double lp_parm_double(struct loadparm_context *lp_ctx, { const char *value = lp_get_parametric(lp_ctx, service, type, option); - if (value) + if (value != NULL) return lp_double(value); return default_v; @@ -990,7 +976,7 @@ bool lp_parm_bool(struct loadparm_context *lp_ctx, { const char *value = lp_get_parametric(lp_ctx, service, type, option); - if (value) + if (value != NULL) return lp_bool(value); return default_v; diff --git a/source4/param/tests/loadparm.c b/source4/param/tests/loadparm.c index d99bc0383c..fa7d7fe176 100644 --- a/source4/param/tests/loadparm.c +++ b/source4/param/tests/loadparm.c @@ -53,6 +53,50 @@ static bool test_set_option_parametric(struct torture_context *tctx) return true; } +static bool test_lp_parm_double(struct torture_context *tctx) +{ + struct loadparm_context *lp_ctx = loadparm_init(tctx); + torture_assert(tctx, lp_set_option(lp_ctx, "some:thing=3.4"), "lp_set_option failed"); + torture_assert(tctx, lp_parm_double(lp_ctx, NULL, "some", "thing", 2.0) == 3.4, + "invalid parametric option"); + torture_assert(tctx, lp_parm_double(lp_ctx, NULL, "some", "bla", 2.0) == 2.0, + "invalid parametric option"); + return true; +} + +static bool test_lp_parm_bool(struct torture_context *tctx) +{ + struct loadparm_context *lp_ctx = loadparm_init(tctx); + torture_assert(tctx, lp_set_option(lp_ctx, "some:thing=true"), "lp_set_option failed"); + torture_assert(tctx, lp_parm_bool(lp_ctx, NULL, "some", "thing", false) == true, + "invalid parametric option"); + torture_assert(tctx, lp_parm_bool(lp_ctx, NULL, "some", "bla", true) == true, + "invalid parametric option"); + return true; +} + +static bool test_lp_parm_int(struct torture_context *tctx) +{ + struct loadparm_context *lp_ctx = loadparm_init(tctx); + torture_assert(tctx, lp_set_option(lp_ctx, "some:thing=34"), "lp_set_option failed"); + torture_assert_int_equal(tctx, lp_parm_int(lp_ctx, NULL, "some", "thing", 20), 34, + "invalid parametric option"); + torture_assert_int_equal(tctx, lp_parm_int(lp_ctx, NULL, "some", "bla", 42), 42, + "invalid parametric option"); + return true; +} + +static bool test_lp_parm_bytes(struct torture_context *tctx) +{ + struct loadparm_context *lp_ctx = loadparm_init(tctx); + torture_assert(tctx, lp_set_option(lp_ctx, "some:thing=16K"), "lp_set_option failed"); + torture_assert_int_equal(tctx, lp_parm_bytes(lp_ctx, NULL, "some", "thing", 20), 16 * 1024, + "invalid parametric option"); + torture_assert_int_equal(tctx, lp_parm_bytes(lp_ctx, NULL, "some", "bla", 42), 42, + "invalid parametric option"); + return true; +} + struct torture_suite *torture_local_loadparm(TALLOC_CTX *mem_ctx) { struct torture_suite *suite = torture_suite_create(mem_ctx, "LOADPARM"); @@ -61,6 +105,10 @@ struct torture_suite *torture_local_loadparm(TALLOC_CTX *mem_ctx) torture_suite_add_simple_test(suite, "set_option", test_set_option); torture_suite_add_simple_test(suite, "set_option_invalid", test_set_option_invalid); torture_suite_add_simple_test(suite, "set_option_parametric", test_set_option_parametric); + torture_suite_add_simple_test(suite, "set_lp_parm_double", test_lp_parm_double); + torture_suite_add_simple_test(suite, "set_lp_parm_bool", test_lp_parm_bool); + torture_suite_add_simple_test(suite, "set_lp_parm_int", test_lp_parm_int); + torture_suite_add_simple_test(suite, "set_lp_parm_bytes", test_lp_parm_bytes); return suite; } |