From 5f9aeca0d66c55896a0ab20cf73dda4ca4b22a39 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Dec 2007 23:32:13 +0100 Subject: r26347: More tests. (This used to be commit 5d927b5ca792c2c9da4a1c4f5c3ae880637895e3) --- source4/param/loadparm.c | 18 ++-------------- source4/param/tests/loadparm.c | 48 +++++++++++++++++++++++++++++++++++++++++ source4/selftest/env/Samba4.pm | 2 +- source4/smb_server/smb_server.c | 3 --- 4 files changed, 51 insertions(+), 20 deletions(-) (limited to 'source4') 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; } diff --git a/source4/selftest/env/Samba4.pm b/source4/selftest/env/Samba4.pm index 8a6d40f3ca..9e3c29b32b 100644 --- a/source4/selftest/env/Samba4.pm +++ b/source4/selftest/env/Samba4.pm @@ -619,7 +619,7 @@ nogroup:x:65534:nobody die("Failed to create a valid smb.conf configuration!"); } - (system("($self->{bindir}/testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global 2> /dev/null | grep -i \"^$netbiosname\" ) >/dev/null 2>&1") == 0) or die("Failed to create a valid smb.conf configuration!"); + (system("($self->{bindir}/testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global 2> /dev/null | grep -i \"^$netbiosname\" ) >/dev/null 2>&1") == 0) or die("Failed to create a valid smb.conf configuration! $self->{bindir}/testparm $configuration -v --suppress-prompt --parameter-name=\"netbios name\" --section-name=global"); my @provision_options = (); push (@provision_options, "NSS_WRAPPER_PASSWD=\"$nsswrap_passwd\""); diff --git a/source4/smb_server/smb_server.c b/source4/smb_server/smb_server.c index e7006a2cee..c91566e244 100644 --- a/source4/smb_server/smb_server.c +++ b/source4/smb_server/smb_server.c @@ -94,9 +94,6 @@ static void smbsrv_recv(struct stream_connection *conn, uint16_t flags) DEBUG(10,("smbsrv_recv\n")); packet_recv(smb_conn->packet); - - /* free up temporary memory */ - lp_talloc_free(); } /* -- cgit